@@ -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
0 commit comments