Skip to content

OIIO 3.0 Update #1466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/IECoreGL/TextureLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@

using namespace IECoreGL;

#if OIIO_VERSION < 30000

namespace{
void destroyImageCache( OIIO::ImageCache *cache )
{
OIIO::ImageCache::destroy( cache, /* teardown */ true );
}
}

#endif

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

imageCache->attribute( "automip", 1 );

OIIO::ImageSpec mipSpec;
Expand All @@ -109,14 +118,25 @@ TexturePtr TextureLoader::load( const std::string &name, int maximumResolution )
{
while(
std::max( mipSpec.full_width, mipSpec.full_height ) > maximumResolution &&
#if OIIO_VERSION >= 30000
imageCache->get_cache_dimensions( oiioPath, mipSpec, 0, miplevel + 1 )
#else
imageCache->get_imagespec( oiioPath, mipSpec, 0, miplevel + 1 )
#endif
)
{
miplevel++;
}
}

OIIO::ImageBuf imageBuf( oiioPath, 0, miplevel, imageCache.get() );
OIIO::ImageBuf imageBuf(
oiioPath, 0, miplevel,
#if OIIO_VERSION >= 30000
imageCache
#else
imageCache.get()
#endif
);
if( imageBuf.spec().full_x != 0 || imageBuf.spec().full_y != 0 )
{
IECore::msg( IECore::Msg::Error, "IECoreGL::TextureLoader::load", boost::format( "Texture display window must start at origin for \"%s\"." ) % path.string() );
Expand Down
50 changes: 27 additions & 23 deletions src/IECoreImage/ImageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ImageReader::Implementation

public :

Implementation( const ImageReader *reader ) : m_reader( reader ), m_cache( nullptr, &destroyImageCache )
Implementation( const ImageReader *reader ) : m_reader( reader )
{
}

Expand Down Expand Up @@ -251,23 +251,33 @@ class ImageReader::Implementation
Imath::Box2i dataWindow()
{
open( /* throwOnFailure */ true );
const ImageSpec *spec = m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );

ImageSpec spec;
#if OIIO_VERSION >= 30000
m_cache->get_cache_dimensions( m_inputFileName, spec, /* subimage = */ 0, miplevel() );
#else
spec = *m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );
#endif

return Imath::Box2i(
Imath::V2i( spec->x, spec->y ),
Imath::V2i( spec->width + spec->x - 1, spec->height + spec->y - 1 )
Imath::V2i( spec.x, spec.y ),
Imath::V2i( spec.width + spec.x - 1, spec.height + spec.y - 1 )
);
}

Imath::Box2i displayWindow()
{
open( /* throwOnFailure */ true );

const ImageSpec *spec = m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );

ImageSpec spec;
#if OIIO_VERSION >= 30000
m_cache->get_cache_dimensions( m_inputFileName, spec, /* subimage = */ 0, miplevel() );
#else
spec = *m_cache->imagespec( m_inputFileName, /* subimage = */ 0, miplevel() );
#endif
return Imath::Box2i(
Imath::V2i( spec->full_x, spec->full_y ),
Imath::V2i( spec->full_x + spec->full_width - 1, spec->full_y + spec->full_height - 1 )
Imath::V2i( spec.full_x, spec.full_y ),
Imath::V2i( spec.full_x + spec.full_width - 1, spec.full_y + spec.full_height - 1 )
);
}

Expand Down Expand Up @@ -441,8 +451,11 @@ class ImageReader::Implementation
}

m_inputFileName = "";
m_cache.reset( ImageCache::create( /* shared */ false ) );

#if OIIO_VERSION >= 30000
m_cache = ImageCache::create( /* shared */ false );
#else
m_cache.reset( ImageCache::create( /* shared */ false ), destroyImageCache );
#endif
// Autompip ensures that if a miplevel is requested that the file
// doesn't contain, OIIO creates the respective level on the fly.
m_cache->attribute( "automip", 1 );
Expand All @@ -453,16 +466,6 @@ class ImageReader::Implementation
{
m_inputFileName = m_reader->fileName();

// Store the miplevels that the file natively supports. We do
// this as OIIO returns a different value once automip is turned
// on.
m_cache->get_image_info(
m_inputFileName,
0, 0, // subimage, miplevel
ustring( "miplevels" ),
TypeDesc::TypeInt, &m_miplevels
);

// Get the fileFormat and store the current and linear color spaces
// We do this so we can perform color conversion on the image after
// loading the data.
Expand All @@ -471,7 +474,7 @@ class ImageReader::Implementation
m_inputFileName,
0, miplevel(), // subimage, miplevel
ustring( "fileformat" ),
TypeDesc::TypeString, &fileFormat
OIIO::TypeString, &fileFormat
);

if( strcmp( fileFormat, "png" ) == 0 )
Expand Down Expand Up @@ -512,17 +515,18 @@ class ImageReader::Implementation
return p->getNumericValue();
}

#if OIIO_VERSION < 30000
static void destroyImageCache( ImageCache *cache )
{
ImageCache::destroy( cache, /* teardown */ true );
}
#endif

const ImageReader *m_reader;
std::unique_ptr<ImageCache, decltype(&destroyImageCache) > m_cache;
std::shared_ptr<ImageCache> m_cache;
ustring m_inputFileName;
std::string m_currentColorSpace;
std::string m_linearColorSpace;
int m_miplevels;

};

Expand Down
10 changes: 5 additions & 5 deletions src/IECoreImage/OpenImageIOAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
data = static_cast<const UCharData *>( d )->baseReadable();
break;
case StringDataTypeId :
type = TypeDesc::TypeString;
type = OIIO::TypeString;
m_charPointers.resize(1);
m_charPointers[0] = static_cast<const StringData *>( d )->readable().c_str();
if( createUStrings )
Expand All @@ -344,7 +344,7 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
data = static_cast<const HalfData *>( d )->baseReadable();
break;
case IntDataTypeId :
type = TypeDesc::TypeInt;
type = OIIO::TypeInt;
data = static_cast<const IntData *>( d )->baseReadable();
break;
case UInt64DataTypeId :
Expand All @@ -356,7 +356,7 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
data = static_cast<const Int64Data *>( d )->baseReadable();
break;
case FloatDataTypeId :
type = TypeDesc::TypeFloat;
type = OIIO::TypeFloat;
data = static_cast<const FloatData *>( d )->baseReadable();
break;
case DoubleDataTypeId :
Expand Down Expand Up @@ -420,15 +420,15 @@ DataView::DataView( const IECore::Data *d, bool createUStrings )
data = static_cast<const M44dData *>( d )->baseReadable();
break;
case Color3fDataTypeId :
type = TypeDesc::TypeColor;
type = OIIO::TypeColor;
data = static_cast<const Color3fData *>( d )->baseReadable();
break;
case Color4fDataTypeId :
type = TypeDesc( TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR );
data = static_cast<const Color4fData *>( d )->baseReadable();
break;
case TimeCodeDataTypeId :
type = TypeDesc::TypeTimeCode;
type = OIIO::TypeTimeCode;
data = static_cast<const TimeCodeData *>( d )->baseReadable();
break;

Expand Down
5 changes: 4 additions & 1 deletion test/IECoreImage/ImageReaderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def testHeaderToBlindData( self ) :

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

r = IECore.Reader.create( os.path.join( "test", "IECoreImage", "data", "exr", "uvMap.512x256.exr" ) )
header = r.readHeader()
Expand Down
2 changes: 2 additions & 0 deletions test/IECoreImage/ImageWriterTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ def testBlindDataToHeader( self ) :
del imgBlindData['oiio:ColorSpace']
if IECoreImage.OpenImageIOAlgo.version() >= 20206 :
del imgBlindData['oiio:subimages']
if IECoreImage.OpenImageIOAlgo.version() >= 30000 :
del imgBlindData["openexr:lineOrder"]
del imgBlindData['compression']
del imgBlindData['PixelAspectRatio']
del imgBlindData['displayWindow']
Expand Down