Skip to content

Commit fa3e654

Browse files
committed
IECoreImage : Adapt to OIIO 3 ImageCache changes
There are two changes that affect us : - `ImageCache::create()` returns a `shared_ptr`. - `ImageCache::imagespec()` completely ignores the `miplevel` parameter, and we have to use `get_cache_dimensions()` instead.
1 parent f91a37b commit fa3e654

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/IECoreGL/TextureLoader.cpp

Lines changed: 17 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;
@@ -116,7 +125,14 @@ TexturePtr TextureLoader::load( const std::string &name, int maximumResolution )
116125
}
117126
}
118127

119-
OIIO::ImageBuf imageBuf( oiioPath, 0, miplevel, imageCache.get() );
128+
OIIO::ImageBuf imageBuf(
129+
oiioPath, 0, miplevel,
130+
#if OIIO_VERSION >= 30000
131+
imageCache
132+
#else
133+
imageCache.get()
134+
#endif
135+
);
120136
if( imageBuf.spec().full_x != 0 || imageBuf.spec().full_y != 0 )
121137
{
122138
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: 26 additions & 11 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 );
@@ -502,13 +515,15 @@ class ImageReader::Implementation
502515
return p->getNumericValue();
503516
}
504517

518+
#if OIIO_VERSION < 30000
505519
static void destroyImageCache( ImageCache *cache )
506520
{
507521
ImageCache::destroy( cache, /* teardown */ true );
508522
}
523+
#endif
509524

510525
const ImageReader *m_reader;
511-
std::unique_ptr<ImageCache, decltype(&destroyImageCache) > m_cache;
526+
std::shared_ptr<ImageCache> m_cache;
512527
ustring m_inputFileName;
513528
std::string m_currentColorSpace;
514529
std::string m_linearColorSpace;

0 commit comments

Comments
 (0)