Skip to content

Commit fa90c5d

Browse files
committed
OpenImageIOAlgo : Add missing array handlers to data()
And consolidate the existing array handling to use the same templated function as everything else. This new version is preferable because it doesn't initialise the data twice (previously the `resize()` was doing a redundant initialisation prior to the `copy()`). This fixes the loading of ICCProfile metadata, which is the underlying problem reported in https://groups.google.com/g/gaffer-dev/c/qUSJ-r0XuYI/m/y4OMtrBUAAAJ.
1 parent c296aa1 commit fa90c5d

File tree

2 files changed

+31
-40
lines changed

2 files changed

+31
-40
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
10.5.x.x (relative to 10.5.9.0)
22
========
33

4+
Fixes
5+
-----
46

7+
- 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.
58

69
10.5.9.x (relative to 10.5.8.0)
710
========

src/IECoreImage/OpenImageIOAlgo.cpp

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ OIIO::TypeDesc extractStringCharPointers( const std::vector<T> &strings, std::ve
8383
return type;
8484
}
8585

86+
template<typename T>
87+
DataPtr extractScalarData( const OIIO::ParamValue &value )
88+
{
89+
const T *data = static_cast<const T *>( value.data() );
90+
if( value.type().arraylen == 0 )
91+
{
92+
return new TypedData<T>( *data );
93+
}
94+
else if( value.type().arraylen > 0 )
95+
{
96+
using DataType = TypedData<std::vector<T>>;
97+
typename DataType::Ptr result = new DataType;
98+
result->writable().insert( result->writable().end(), data, data + value.type().arraylen );
99+
return result;
100+
}
101+
return nullptr;
102+
}
103+
86104
} // namespace
87105

88106
namespace IECoreImage
@@ -566,15 +584,15 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
566584
{
567585
if ( type.aggregate == TypeDesc::SCALAR )
568586
{
569-
return new CharData( *static_cast<const char *>( value.data() ) );
587+
return extractScalarData<char>( value );
570588
}
571589
return nullptr;
572590
}
573591
case TypeDesc::UCHAR :
574592
{
575593
if ( type.aggregate == TypeDesc::SCALAR )
576594
{
577-
return new UCharData( *static_cast<const unsigned char *>( value.data() ) );
595+
return extractScalarData<unsigned char>( value );
578596
}
579597
return nullptr;
580598
}
@@ -606,30 +624,30 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
606624
{
607625
if ( type.aggregate == TypeDesc::SCALAR )
608626
{
609-
return new UShortData( *static_cast<const unsigned short *>( value.data() ) );
627+
return extractScalarData<unsigned short>( value );
610628
}
611629
return nullptr;
612630
}
613631
case TypeDesc::SHORT :
614632
{
615633
if ( type.aggregate == TypeDesc::SCALAR )
616634
{
617-
return new ShortData( *static_cast<const short *>( value.data() ) );
635+
return extractScalarData<short>( value );
618636
}
619637
return nullptr;
620638
}
621639
case TypeDesc::UINT :
622640
{
623641
if ( type.aggregate == TypeDesc::SCALAR )
624642
{
625-
const unsigned *typedData = static_cast<const unsigned *>( value.data() );
626643
if ( type.vecsemantics == TypeDesc::TIMECODE )
627644
{
645+
const unsigned *typedData = static_cast<const unsigned *>( value.data() );
628646
return new TimeCodeData( Imf::TimeCode( typedData[0], typedData[1] ) );
629647
}
630648
else
631649
{
632-
return new UIntData( *typedData );
650+
return extractScalarData<unsigned int>( value );
633651
}
634652
}
635653
return nullptr;
@@ -641,17 +659,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
641659
{
642660
case TypeDesc::SCALAR :
643661
{
644-
if( !type.arraylen )
645-
{
646-
return new IntData( *typedData );
647-
}
648-
else
649-
{
650-
IntVectorDataPtr vectorData = new IntVectorData();
651-
vectorData->writable().resize( type.arraylen );
652-
std::copy( &typedData[0], &typedData[type.arraylen], vectorData->writable().begin() );
653-
return vectorData;
654-
}
662+
return extractScalarData<int>( value );
655663
}
656664
case TypeDesc::VEC2 :
657665
{
@@ -696,7 +704,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
696704
{
697705
if ( type.aggregate == TypeDesc::SCALAR )
698706
{
699-
return new HalfData( *static_cast<const half *>( value.data() ) );
707+
return extractScalarData<half>( value );
700708
}
701709
return nullptr;
702710
}
@@ -707,17 +715,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
707715
{
708716
case TypeDesc::SCALAR :
709717
{
710-
if( !type.arraylen )
711-
{
712-
return new FloatData( *typedData );
713-
}
714-
else
715-
{
716-
FloatVectorDataPtr vectorData = new FloatVectorData();
717-
vectorData->writable().resize( type.arraylen );
718-
std::copy( &typedData[0], &typedData[type.arraylen], vectorData->writable().begin() );
719-
return vectorData;
720-
}
718+
return extractScalarData<float>( value );
721719
}
722720
case TypeDesc::VEC2 :
723721
{
@@ -764,17 +762,7 @@ IECore::DataPtr data( const OIIO::ParamValue &value )
764762
{
765763
case TypeDesc::SCALAR :
766764
{
767-
if( !type.arraylen )
768-
{
769-
return new DoubleData( *typedData );
770-
}
771-
else
772-
{
773-
DoubleVectorDataPtr vectorData = new DoubleVectorData();
774-
vectorData->writable().resize( type.arraylen );
775-
std::copy( &typedData[0], &typedData[type.arraylen], vectorData->writable().begin() );
776-
return vectorData;
777-
}
765+
return extractScalarData<double>( value );
778766
}
779767
case TypeDesc::VEC2 :
780768
{

0 commit comments

Comments
 (0)