Skip to content
Open
18 changes: 13 additions & 5 deletions src/OpenColorIO/ImagePacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void Generic<Type>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
Type * inBitDepthBuffer,
float * outputBuffer,
int outputBufferSize,
long imagePixelStartIndex)
long imagePixelStartIndex,
BitDepth inputBitDepth)
{
if(outputBuffer==nullptr)
{
Expand Down Expand Up @@ -62,15 +63,21 @@ void Generic<Type>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
aPtr = reinterpret_cast<Type*>(aRow + xStrideBytes*xIndex);
}

float maxValue = static_cast<float>(GetBitDepthMaxValue(inputBitDepth));
if (maxValue <= 0)
{
throw Exception("Invalid bit depth max value.");
}

// Process one single, complete scanline.
int pixelsCopied = 0;
while(pixelsCopied < outputBufferSize)
{
{
// Reorder channels from arbitrary channel ordering to RGBA 32-bit float.
inBitDepthBuffer[4*pixelsCopied+0] = *rPtr;
inBitDepthBuffer[4*pixelsCopied+1] = *gPtr;
inBitDepthBuffer[4*pixelsCopied+2] = *bPtr;
inBitDepthBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (Type)0.0f;
inBitDepthBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (Type)(maxValue);

pixelsCopied++;
xIndex++;
Expand All @@ -93,7 +100,8 @@ void Generic<float>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
float * /*inBitDepthBuffer*/,
float * outputBuffer,
int outputBufferSize,
long imagePixelStartIndex)
long imagePixelStartIndex,
BitDepth /*inputBitDepth*/)
{
if(outputBuffer==nullptr)
{
Expand Down Expand Up @@ -140,7 +148,7 @@ void Generic<float>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
outputBuffer[4*pixelsCopied+0] = *rPtr;
outputBuffer[4*pixelsCopied+1] = *gPtr;
outputBuffer[4*pixelsCopied+2] = *bPtr;
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : 0.0f;
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : 1.0f;

pixelsCopied++;
xIndex++;
Expand Down
3 changes: 2 additions & 1 deletion src/OpenColorIO/ImagePacking.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ struct Generic
Type * inBitDepthBuffer,
float * outputBuffer,
int outputBufferSize,
long imagePixelStartIndex);
long imagePixelStartIndex,
BitDepth inputBitDepth);

static void UnpackRGBAToImageDesc(GenericImageDesc & dstImg,
float * inputBuffer,
Expand Down
3 changes: 2 additions & 1 deletion src/OpenColorIO/ScanlineHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ void GenericScanlineHelper<InType, OutType>::prepRGBAScanline(float** buffer, lo
&m_inBitDepthBuffer[0],
*buffer,
m_dstImg.m_width,
m_yIndex * m_dstImg.m_width);
m_yIndex * m_dstImg.m_width,
m_inputBitDepth);
}

numPixels = m_dstImg.m_width;
Expand Down
46 changes: 23 additions & 23 deletions tests/cpu/CPUProcessor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ OCIO_ADD_TEST(CPUProcessor, with_one_matrix)
1.0000f, 1.2500f, 1.9900f };

const std::vector<float> resImg
= { -0.01929f, -0.3995f, 0.4002f, 0.5f,
1.58960f, 0.9050f, 1.5025f, 0.5f,
2.070699f, 1.6505f, 2.4002f, 0.5f };
= { -0.01929f, -0.3995f, 0.4002f, 1.5f,
1.58960f, 0.9050f, 1.5025f, 1.5f,
2.070699f, 1.6505f, 2.4002f, 1.5f };

ComputeValues<OCIO::BIT_DEPTH_F32, OCIO::BIT_DEPTH_F32>(
__LINE__, processor,
Expand Down Expand Up @@ -620,10 +620,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
5120, 20480, 65535 };

const std::vector<uint16_t> resImg
= { 95, 24, 0, 0,
268, 178, 123, 0,
955, 598, 394, 0,
65535, 8589, 1986, 0 };
= { 95, 24, 0, 65535,
268, 178, 123, 65535,
955, 598, 394, 65535,
65535, 8589, 1986, 65535 };

ComputeValues<OCIO::BIT_DEPTH_UINT16, OCIO::BIT_DEPTH_UINT16>(
__LINE__, processor,
Expand Down Expand Up @@ -656,10 +656,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
128, 1023, 640 };

const std::vector<uint16_t> ui10_resImg
= { 0, 6, 15, 0,
26, 48, 106, 0,
36, 106, 252, 0,
48, 1023, 384, 0 };
= { 0, 6, 15, 1023,
26, 48, 106, 1023,
36, 106, 252, 1023,
48, 1023, 384, 1023 };

ComputeValues<OCIO::BIT_DEPTH_UINT10, OCIO::BIT_DEPTH_UINT10>(
__LINE__, processor,
Expand All @@ -668,10 +668,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
NB_PIXELS);

const std::vector<uint16_t> ui16_resImg
= { 0, 394, 955, 0,
1656, 3092, 6794, 0,
2301, 6794, 16162, 0,
3092, 65535, 24593, 0 };
= { 0, 394, 955, 65535,
1656, 3092, 6794, 65535,
2301, 6794, 16162, 65535,
3092, 65535, 24593, 65535 };

ComputeValues<OCIO::BIT_DEPTH_UINT10, OCIO::BIT_DEPTH_UINT16>(
__LINE__, processor,
Expand Down Expand Up @@ -704,21 +704,21 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
1024, 2048, 4095 };

const std::vector<uint16_t> ui12_resImg
= { 0, 11, 25, 0,
37, 60, 103, 0,
49, 103, 193, 0,
424, 1009, 4095, 0 };
= { 0, 11, 25, 4095,
37, 60, 103, 4095,
49, 103, 193, 4095,
424, 1009, 4095, 4095 };

ComputeValues<OCIO::BIT_DEPTH_UINT12, OCIO::BIT_DEPTH_UINT12>(
__LINE__, processor,
&ui12_inImg[0], OCIO::CHANNEL_ORDERING_RGB,
&ui12_resImg[0], OCIO::CHANNEL_ORDERING_RGBA,
NB_PIXELS);
const std::vector<uint16_t> ui16_resImg
= { 0, 178, 394, 0,
598, 955, 1655, 0,
779, 1655, 3089, 0,
6789, 16143, 65535, 0 };
= { 0, 178, 394, 65535,
598, 955, 1655, 65535,
779, 1655, 3089, 65535,
6789, 16143, 65535, 65535 };

ComputeValues<OCIO::BIT_DEPTH_UINT12, OCIO::BIT_DEPTH_UINT16>(
__LINE__, processor,
Expand Down