Skip to content

Commit ee32580

Browse files
Merge pull request #1466 from johnhaddon/oiioUpdate
OIIO 3.0 Update
2 parents 1516569 + 90661f3 commit ee32580

File tree

5 files changed

+59
-30
lines changed

5 files changed

+59
-30
lines changed

src/IECoreGL/TextureLoader.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@
5656

5757
using namespace IECoreGL;
5858

59+
#if OIIO_VERSION < 30000
60+
5961
namespace{
6062
void destroyImageCache( OIIO::ImageCache *cache )
6163
{
6264
OIIO::ImageCache::destroy( cache, /* teardown */ true );
6365
}
6466
}
6567

68+
#endif
69+
6670
TextureLoader::TextureLoader( const IECore::SearchPath &searchPaths )
6771
: m_searchPaths( searchPaths )
6872
{
@@ -92,7 +96,12 @@ TexturePtr TextureLoader::load( const std::string &name, int maximumResolution )
9296
// doesn't have mipmaps on disk ... but I'm keeping this consistent for now.
9397
// To set automip, we need to create an ImageCache - currently I just destroy it when this function exits:
9498
// we cache the GL texture ourselves, so dropping the OIIO cache should be OK.
99+
#if OIIO_VERSION >= 30000
100+
std::shared_ptr<OIIO::ImageCache> imageCache = OIIO::ImageCache::create( /* shared */ false );
101+
#else
95102
std::unique_ptr<OIIO::ImageCache, decltype(&destroyImageCache) > imageCache( OIIO::ImageCache::create( /* shared */ false ), &destroyImageCache );
103+
#endif
104+
96105
imageCache->attribute( "automip", 1 );
97106

98107
OIIO::ImageSpec mipSpec;
@@ -109,14 +118,25 @@ TexturePtr TextureLoader::load( const std::string &name, int maximumResolution )
109118
{
110119
while(
111120
std::max( mipSpec.full_width, mipSpec.full_height ) > maximumResolution &&
121+
#if OIIO_VERSION >= 30000
122+
imageCache->get_cache_dimensions( oiioPath, mipSpec, 0, miplevel + 1 )
123+
#else
112124
imageCache->get_imagespec( oiioPath, mipSpec, 0, miplevel + 1 )
125+
#endif
113126
)
114127
{
115128
miplevel++;
116129
}
117130
}
118131

119-
OIIO::ImageBuf imageBuf( oiioPath, 0, miplevel, imageCache.get() );
132+
OIIO::ImageBuf imageBuf(
133+
oiioPath, 0, miplevel,
134+
#if OIIO_VERSION >= 30000
135+
imageCache
136+
#else
137+
imageCache.get()
138+
#endif
139+
);
120140
if( imageBuf.spec().full_x != 0 || imageBuf.spec().full_y != 0 )
121141
{
122142
IECore::msg( IECore::Msg::Error, "IECoreGL::TextureLoader::load", boost::format( "Texture display window must start at origin for \"%s\"." ) % path.string() );

src/IECoreImage/ImageReader.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ImageReader::Implementation
118118

119119
public :
120120

121-
Implementation( const ImageReader *reader ) : m_reader( reader ), m_cache( nullptr, &destroyImageCache )
121+
Implementation( const ImageReader *reader ) : m_reader( reader )
122122
{
123123
}
124124

@@ -251,23 +251,33 @@ class ImageReader::Implementation
251251
Imath::Box2i dataWindow()
252252
{
253253
open( /* throwOnFailure */ true );
254-
const ImageSpec *spec = m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );
254+
255+
ImageSpec spec;
256+
#if OIIO_VERSION >= 30000
257+
m_cache->get_cache_dimensions( m_inputFileName, spec, /* subimage = */ 0, miplevel() );
258+
#else
259+
spec = *m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );
260+
#endif
255261

256262
return Imath::Box2i(
257-
Imath::V2i( spec->x, spec->y ),
258-
Imath::V2i( spec->width + spec->x - 1, spec->height + spec->y - 1 )
263+
Imath::V2i( spec.x, spec.y ),
264+
Imath::V2i( spec.width + spec.x - 1, spec.height + spec.y - 1 )
259265
);
260266
}
261267

262268
Imath::Box2i displayWindow()
263269
{
264270
open( /* throwOnFailure */ true );
265271

266-
const ImageSpec *spec = m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );
267-
272+
ImageSpec spec;
273+
#if OIIO_VERSION >= 30000
274+
m_cache->get_cache_dimensions( m_inputFileName, spec, /* subimage = */ 0, miplevel() );
275+
#else
276+
spec = *m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );
277+
#endif
268278
return Imath::Box2i(
269-
Imath::V2i( spec->full_x, spec->full_y ),
270-
Imath::V2i( spec->full_x + spec->full_width - 1, spec->full_y + spec->full_height - 1 )
279+
Imath::V2i( spec.full_x, spec.full_y ),
280+
Imath::V2i( spec.full_x + spec.full_width - 1, spec.full_y + spec.full_height - 1 )
271281
);
272282
}
273283

@@ -441,8 +451,11 @@ class ImageReader::Implementation
441451
}
442452

443453
m_inputFileName = "";
444-
m_cache.reset( ImageCache::create( /* shared */ false ) );
445-
454+
#if OIIO_VERSION >= 30000
455+
m_cache = ImageCache::create( /* shared */ false );
456+
#else
457+
m_cache.reset( ImageCache::create( /* shared */ false ), destroyImageCache );
458+
#endif
446459
// Autompip ensures that if a miplevel is requested that the file
447460
// doesn't contain, OIIO creates the respective level on the fly.
448461
m_cache->attribute( "automip", 1 );
@@ -453,16 +466,6 @@ class ImageReader::Implementation
453466
{
454467
m_inputFileName = m_reader->fileName();
455468

456-
// Store the miplevels that the file natively supports. We do
457-
// this as OIIO returns a different value once automip is turned
458-
// on.
459-
m_cache->get_image_info(
460-
m_inputFileName,
461-
0, 0, // subimage, miplevel
462-
ustring( "miplevels" ),
463-
TypeDesc::TypeInt, &m_miplevels
464-
);
465-
466469
// Get the fileFormat and store the current and linear color spaces
467470
// We do this so we can perform color conversion on the image after
468471
// loading the data.
@@ -471,7 +474,7 @@ class ImageReader::Implementation
471474
m_inputFileName,
472475
0, miplevel(), // subimage, miplevel
473476
ustring( "fileformat" ),
474-
TypeDesc::TypeString, &fileFormat
477+
OIIO::TypeString, &fileFormat
475478
);
476479

477480
if( strcmp( fileFormat, "png" ) == 0 )
@@ -512,17 +515,18 @@ class ImageReader::Implementation
512515
return p->getNumericValue();
513516
}
514517

518+
#if OIIO_VERSION < 30000
515519
static void destroyImageCache( ImageCache *cache )
516520
{
517521
ImageCache::destroy( cache, /* teardown */ true );
518522
}
523+
#endif
519524

520525
const ImageReader *m_reader;
521-
std::unique_ptr<ImageCache, decltype(&destroyImageCache) > m_cache;
526+
std::shared_ptr<ImageCache> m_cache;
522527
ustring m_inputFileName;
523528
std::string m_currentColorSpace;
524529
std::string m_linearColorSpace;
525-
int m_miplevels;
526530

527531
};
528532

src/IECoreImage/OpenImageIOAlgo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
318318
data = static_cast<const UCharData *>( d )->baseReadable();
319319
break;
320320
case StringDataTypeId :
321-
type = TypeDesc::TypeString;
321+
type = OIIO::TypeString;
322322
m_charPointers.resize(1);
323323
m_charPointers[0] = static_cast<const StringData *>( d )->readable().c_str();
324324
if( createUStrings )
@@ -344,7 +344,7 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
344344
data = static_cast<const HalfData *>( d )->baseReadable();
345345
break;
346346
case IntDataTypeId :
347-
type = TypeDesc::TypeInt;
347+
type = OIIO::TypeInt;
348348
data = static_cast<const IntData *>( d )->baseReadable();
349349
break;
350350
case UInt64DataTypeId :
@@ -356,7 +356,7 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
356356
data = static_cast<const Int64Data *>( d )->baseReadable();
357357
break;
358358
case FloatDataTypeId :
359-
type = TypeDesc::TypeFloat;
359+
type = OIIO::TypeFloat;
360360
data = static_cast<const FloatData *>( d )->baseReadable();
361361
break;
362362
case DoubleDataTypeId :
@@ -420,15 +420,15 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
420420
data = static_cast<const M44dData *>( d )->baseReadable();
421421
break;
422422
case Color3fDataTypeId :
423-
type = TypeDesc::TypeColor;
423+
type = OIIO::TypeColor;
424424
data = static_cast<const Color3fData *>( d )->baseReadable();
425425
break;
426426
case Color4fDataTypeId :
427427
type = TypeDesc( TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR );
428428
data = static_cast<const Color4fData *>( d )->baseReadable();
429429
break;
430430
case TimeCodeDataTypeId :
431-
type = TypeDesc::TypeTimeCode;
431+
type = OIIO::TypeTimeCode;
432432
data = static_cast<const TimeCodeData *>( d )->baseReadable();
433433
break;
434434

test/IECoreImage/ImageReaderTest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def testHeaderToBlindData( self ) :
218218

219219
dictHeader = {
220220
'channelNames': IECore.StringVectorData( [ "R", "G", "B" ] ),
221-
'oiio:ColorSpace': IECore.StringData( "Linear" ),
221+
'oiio:ColorSpace': IECore.StringData( "lin_rec709" if IECoreImage.OpenImageIOAlgo.version() >= 30000 else "Linear" ),
222222
'compression': IECore.StringData( "piz" ),
223223
'screenWindowCenter': IECore.V2fData( imath.V2f(0,0) ),
224224
'displayWindow': IECore.Box2iData( imath.Box2i( imath.V2i(0,0), imath.V2i(511,255) ) ),
@@ -229,6 +229,9 @@ def testHeaderToBlindData( self ) :
229229
}
230230
if IECoreImage.OpenImageIOAlgo.version() >= 20206 :
231231
dictHeader['oiio:subimages'] = IECore.IntData( 1 )
232+
if IECoreImage.OpenImageIOAlgo.version() >= 30000 :
233+
dictHeader["openexr:lineOrder"] = IECore.StringData( "increasingY" )
234+
dictHeader["screenWindowCenter"] = IECore.V2fData( imath.V2f( 0 ) )
232235

233236
r = IECore.Reader.create( os.path.join( "test", "IECoreImage", "data", "exr", "uvMap.512x256.exr" ) )
234237
header = r.readHeader()

test/IECoreImage/ImageWriterTest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ def testBlindDataToHeader( self ) :
418418
del imgBlindData['oiio:ColorSpace']
419419
if IECoreImage.OpenImageIOAlgo.version() >= 20206 :
420420
del imgBlindData['oiio:subimages']
421+
if IECoreImage.OpenImageIOAlgo.version() >= 30000 :
422+
del imgBlindData["openexr:lineOrder"]
421423
del imgBlindData['compression']
422424
del imgBlindData['PixelAspectRatio']
423425
del imgBlindData['displayWindow']

0 commit comments

Comments
 (0)