Skip to content

Commit

Permalink
Merge pull request #1425 from johnhaddon/oiioDataFix
Browse files Browse the repository at this point in the history
OpenImageIOAlgo : Add missing array handlers to `data()`
  • Loading branch information
johnhaddon authored Jul 10, 2024
2 parents c296aa1 + fa90c5d commit 7de325a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
10.5.x.x (relative to 10.5.9.0)
========

Fixes
-----

- OpenImageIOAlgo : Fixed `data()` handling of arrays of type `TypeDesc::CHAR`, `TypeDesc::UCHAR`, `TypeDesc::USHORT`, `TypeDesc::SHORT`, `TypeDesc::UINT` and `TypeDesc::HALF`. Among other things, this fixes the round-tripping of ICC profiles in ImageReader/ImageWriter.

10.5.9.x (relative to 10.5.8.0)
========
Expand Down
68 changes: 28 additions & 40 deletions src/IECoreImage/OpenImageIOAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ OIIO::TypeDesc extractStringCharPointers( const std::vector<T> &strings, std::ve
return type;
}

template<typename T>
DataPtr extractScalarData( const OIIO::ParamValue &value )
{
const T *data = static_cast<const T *>( value.data() );
if( value.type().arraylen == 0 )
{
return new TypedData<T>( *data );
}
else if( value.type().arraylen > 0 )
{
using DataType = TypedData<std::vector<T>>;
typename DataType::Ptr result = new DataType;
result->writable().insert( result->writable().end(), data, data + value.type().arraylen );
return result;
}
return nullptr;
}

} // namespace

namespace IECoreImage
Expand Down Expand Up @@ -566,15 +584,15 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
{
if ( type.aggregate == TypeDesc::SCALAR )
{
return new CharData( *static_cast<const char *>( value.data() ) );
return extractScalarData<char>( value );
}
return nullptr;
}
case TypeDesc::UCHAR :
{
if ( type.aggregate == TypeDesc::SCALAR )
{
return new UCharData( *static_cast<const unsigned char *>( value.data() ) );
return extractScalarData<unsigned char>( value );
}
return nullptr;
}
Expand Down Expand Up @@ -606,30 +624,30 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
{
if ( type.aggregate == TypeDesc::SCALAR )
{
return new UShortData( *static_cast<const unsigned short *>( value.data() ) );
return extractScalarData<unsigned short>( value );
}
return nullptr;
}
case TypeDesc::SHORT :
{
if ( type.aggregate == TypeDesc::SCALAR )
{
return new ShortData( *static_cast<const short *>( value.data() ) );
return extractScalarData<short>( value );
}
return nullptr;
}
case TypeDesc::UINT :
{
if ( type.aggregate == TypeDesc::SCALAR )
{
const unsigned *typedData = static_cast<const unsigned *>( value.data() );
if ( type.vecsemantics == TypeDesc::TIMECODE )
{
const unsigned *typedData = static_cast<const unsigned *>( value.data() );
return new TimeCodeData( Imf::TimeCode( typedData[0], typedData[1] ) );
}
else
{
return new UIntData( *typedData );
return extractScalarData<unsigned int>( value );
}
}
return nullptr;
Expand All @@ -641,17 +659,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
{
case TypeDesc::SCALAR :
{
if( !type.arraylen )
{
return new IntData( *typedData );
}
else
{
IntVectorDataPtr vectorData = new IntVectorData();
vectorData->writable().resize( type.arraylen );
std::copy( &typedData[0], &typedData[type.arraylen], vectorData->writable().begin() );
return vectorData;
}
return extractScalarData<int>( value );
}
case TypeDesc::VEC2 :
{
Expand Down Expand Up @@ -696,7 +704,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
{
if ( type.aggregate == TypeDesc::SCALAR )
{
return new HalfData( *static_cast<const half *>( value.data() ) );
return extractScalarData<half>( value );
}
return nullptr;
}
Expand All @@ -707,17 +715,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
{
case TypeDesc::SCALAR :
{
if( !type.arraylen )
{
return new FloatData( *typedData );
}
else
{
FloatVectorDataPtr vectorData = new FloatVectorData();
vectorData->writable().resize( type.arraylen );
std::copy( &typedData[0], &typedData[type.arraylen], vectorData->writable().begin() );
return vectorData;
}
return extractScalarData<float>( value );
}
case TypeDesc::VEC2 :
{
Expand Down Expand Up @@ -764,17 +762,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
{
case TypeDesc::SCALAR :
{
if( !type.arraylen )
{
return new DoubleData( *typedData );
}
else
{
DoubleVectorDataPtr vectorData = new DoubleVectorData();
vectorData->writable().resize( type.arraylen );
std::copy( &typedData[0], &typedData[type.arraylen], vectorData->writable().begin() );
return vectorData;
}
return extractScalarData<double>( value );
}
case TypeDesc::VEC2 :
{
Expand Down

0 comments on commit 7de325a

Please sign in to comment.