From 1ff4a219cb101b3f49083434aa6fc3306e673505 Mon Sep 17 00:00:00 2001 From: pylee Date: Thu, 25 Sep 2025 15:59:02 -0700 Subject: [PATCH 1/5] For CPU processor, when source has no alpha make it default to 1. Signed-off-by: pylee --- src/OpenColorIO/ImagePacking.cpp | 4 +-- tests/cpu/CPUProcessor_tests.cpp | 46 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/OpenColorIO/ImagePacking.cpp b/src/OpenColorIO/ImagePacking.cpp index 3c24c9a58..d8290da74 100644 --- a/src/OpenColorIO/ImagePacking.cpp +++ b/src/OpenColorIO/ImagePacking.cpp @@ -70,7 +70,7 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, 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)1.0f; pixelsCopied++; xIndex++; @@ -140,7 +140,7 @@ void Generic::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++; diff --git a/tests/cpu/CPUProcessor_tests.cpp b/tests/cpu/CPUProcessor_tests.cpp index 925a75397..f27654bbf 100644 --- a/tests/cpu/CPUProcessor_tests.cpp +++ b/tests/cpu/CPUProcessor_tests.cpp @@ -276,9 +276,9 @@ OCIO_ADD_TEST(CPUProcessor, with_one_matrix) 1.0000f, 1.2500f, 1.9900f }; const std::vector 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( __LINE__, processor, @@ -620,10 +620,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) 5120, 20480, 65535 }; const std::vector resImg - = { 95, 24, 0, 0, - 268, 178, 123, 0, - 955, 598, 394, 0, - 65535, 8589, 1986, 0 }; + = { 95, 24, 0, 1, + 268, 178, 123, 1, + 955, 598, 394, 1, + 65535, 8589, 1986, 1 }; ComputeValues( __LINE__, processor, @@ -656,10 +656,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) 128, 1023, 640 }; const std::vector ui10_resImg - = { 0, 6, 15, 0, - 26, 48, 106, 0, - 36, 106, 252, 0, - 48, 1023, 384, 0 }; + = { 0, 6, 15, 1, + 26, 48, 106, 1, + 36, 106, 252, 1, + 48, 1023, 384, 1 }; ComputeValues( __LINE__, processor, @@ -668,10 +668,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) NB_PIXELS); const std::vector ui16_resImg - = { 0, 394, 955, 0, - 1656, 3092, 6794, 0, - 2301, 6794, 16162, 0, - 3092, 65535, 24593, 0 }; + = { 0, 394, 955, 64, + 1656, 3092, 6794, 64, + 2301, 6794, 16162, 64, + 3092, 65535, 24593, 64 }; ComputeValues( __LINE__, processor, @@ -704,10 +704,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) 1024, 2048, 4095 }; const std::vector ui12_resImg - = { 0, 11, 25, 0, - 37, 60, 103, 0, - 49, 103, 193, 0, - 424, 1009, 4095, 0 }; + = { 0, 11, 25, 1, + 37, 60, 103, 1, + 49, 103, 193, 1, + 424, 1009, 4095, 1 }; ComputeValues( __LINE__, processor, @@ -715,10 +715,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) &ui12_resImg[0], OCIO::CHANNEL_ORDERING_RGBA, NB_PIXELS); const std::vector ui16_resImg - = { 0, 178, 394, 0, - 598, 955, 1655, 0, - 779, 1655, 3089, 0, - 6789, 16143, 65535, 0 }; + = { 0, 178, 394, 16, + 598, 955, 1655, 16, + 779, 1655, 3089, 16, + 6789, 16143, 65535, 16 }; ComputeValues( __LINE__, processor, From c7b025e9ede160a921def2ef2d4217fe2519b37d Mon Sep 17 00:00:00 2001 From: pylee Date: Sat, 31 Jan 2026 09:41:49 -0800 Subject: [PATCH 2/5] Fix alpha channel for integer types. Signed-off-by: pylee --- src/OpenColorIO/ImagePacking.cpp | 24 ++++++++++++++---- src/OpenColorIO/ImagePacking.h | 3 ++- src/OpenColorIO/ScanlineHelper.cpp | 3 ++- tests/cpu/CPUProcessor_tests.cpp | 40 +++++++++++++++--------------- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/OpenColorIO/ImagePacking.cpp b/src/OpenColorIO/ImagePacking.cpp index d8290da74..2a0c135fc 100644 --- a/src/OpenColorIO/ImagePacking.cpp +++ b/src/OpenColorIO/ImagePacking.cpp @@ -23,7 +23,8 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, Type * inBitDepthBuffer, float * outputBuffer, int outputBufferSize, - long imagePixelStartIndex) + long imagePixelStartIndex, + BitDepth outputBitDepth) { if(outputBuffer==nullptr) { @@ -62,15 +63,21 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, aPtr = reinterpret_cast(aRow + xStrideBytes*xIndex); } + float maxValue = static_cast(GetBitDepthMaxValue(outputBitDepth)); + 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)1.0f; + inBitDepthBuffer[4 * pixelsCopied + 3] = aPtr ? *aPtr : (Type)(maxValue); pixelsCopied++; xIndex++; @@ -93,7 +100,8 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, float * /*inBitDepthBuffer*/, float * outputBuffer, int outputBufferSize, - long imagePixelStartIndex) + long imagePixelStartIndex, + BitDepth outputBitDepth) { if(outputBuffer==nullptr) { @@ -132,6 +140,12 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, aPtr = reinterpret_cast(aRow + xStrideBytes*xIndex); } + double maxValue = GetBitDepthMaxValue(outputBitDepth); + if (maxValue <= 0) + { + throw Exception("Invalid bit depth max value."); + } + // Process one single, complete scanline. int pixelsCopied = 0; while(pixelsCopied < outputBufferSize) @@ -140,7 +154,7 @@ void Generic::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 : 1.0f; + outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (float)maxValue; pixelsCopied++; xIndex++; diff --git a/src/OpenColorIO/ImagePacking.h b/src/OpenColorIO/ImagePacking.h index 578bb997e..fe689306a 100644 --- a/src/OpenColorIO/ImagePacking.h +++ b/src/OpenColorIO/ImagePacking.h @@ -53,7 +53,8 @@ struct Generic Type * inBitDepthBuffer, float * outputBuffer, int outputBufferSize, - long imagePixelStartIndex); + long imagePixelStartIndex, + BitDepth outputBitDepth); static void UnpackRGBAToImageDesc(GenericImageDesc & dstImg, float * inputBuffer, diff --git a/src/OpenColorIO/ScanlineHelper.cpp b/src/OpenColorIO/ScanlineHelper.cpp index 59a0020a5..257bf8808 100644 --- a/src/OpenColorIO/ScanlineHelper.cpp +++ b/src/OpenColorIO/ScanlineHelper.cpp @@ -143,7 +143,8 @@ void GenericScanlineHelper::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_outputBitDepth); } numPixels = m_dstImg.m_width; diff --git a/tests/cpu/CPUProcessor_tests.cpp b/tests/cpu/CPUProcessor_tests.cpp index f27654bbf..e7f37912c 100644 --- a/tests/cpu/CPUProcessor_tests.cpp +++ b/tests/cpu/CPUProcessor_tests.cpp @@ -620,10 +620,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) 5120, 20480, 65535 }; const std::vector resImg - = { 95, 24, 0, 1, - 268, 178, 123, 1, - 955, 598, 394, 1, - 65535, 8589, 1986, 1 }; + = { 95, 24, 0, 65535, + 268, 178, 123, 65535, + 955, 598, 394, 65535, + 65535, 8589, 1986, 65535 }; ComputeValues( __LINE__, processor, @@ -656,10 +656,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) 128, 1023, 640 }; const std::vector ui10_resImg - = { 0, 6, 15, 1, - 26, 48, 106, 1, - 36, 106, 252, 1, - 48, 1023, 384, 1 }; + = { 0, 6, 15, 1023, + 26, 48, 106, 1023, + 36, 106, 252, 1023, + 48, 1023, 384, 1023 }; ComputeValues( __LINE__, processor, @@ -668,10 +668,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) NB_PIXELS); const std::vector ui16_resImg - = { 0, 394, 955, 64, - 1656, 3092, 6794, 64, - 2301, 6794, 16162, 64, - 3092, 65535, 24593, 64 }; + = { 0, 394, 955, 65535, + 1656, 3092, 6794, 65535, + 2301, 6794, 16162, 65535, + 3092, 65535, 24593, 65535 }; ComputeValues( __LINE__, processor, @@ -704,10 +704,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) 1024, 2048, 4095 }; const std::vector ui12_resImg - = { 0, 11, 25, 1, - 37, 60, 103, 1, - 49, 103, 193, 1, - 424, 1009, 4095, 1 }; + = { 0, 11, 25, 4095, + 37, 60, 103, 4095, + 49, 103, 193, 4095, + 424, 1009, 4095, 4095 }; ComputeValues( __LINE__, processor, @@ -715,10 +715,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut) &ui12_resImg[0], OCIO::CHANNEL_ORDERING_RGBA, NB_PIXELS); const std::vector ui16_resImg - = { 0, 178, 394, 16, - 598, 955, 1655, 16, - 779, 1655, 3089, 16, - 6789, 16143, 65535, 16 }; + = { 0, 178, 394, 65535, + 598, 955, 1655, 65535, + 779, 1655, 3089, 65535, + 6789, 16143, 65535, 65535 }; ComputeValues( __LINE__, processor, From 6ffa2594d021d3936af063d3244c01d058182d36 Mon Sep 17 00:00:00 2001 From: pylee Date: Mon, 2 Feb 2026 21:21:51 -0800 Subject: [PATCH 3/5] Fix max alpha value to be from input bitdepth not output. Signed-off-by: pylee --- src/OpenColorIO/ImagePacking.cpp | 16 +++++----------- src/OpenColorIO/ScanlineHelper.cpp | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/OpenColorIO/ImagePacking.cpp b/src/OpenColorIO/ImagePacking.cpp index 2a0c135fc..500b41568 100644 --- a/src/OpenColorIO/ImagePacking.cpp +++ b/src/OpenColorIO/ImagePacking.cpp @@ -24,7 +24,7 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, float * outputBuffer, int outputBufferSize, long imagePixelStartIndex, - BitDepth outputBitDepth) + BitDepth inputBitDepth) { if(outputBuffer==nullptr) { @@ -63,7 +63,7 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, aPtr = reinterpret_cast(aRow + xStrideBytes*xIndex); } - float maxValue = static_cast(GetBitDepthMaxValue(outputBitDepth)); + float maxValue = static_cast(GetBitDepthMaxValue(inputBitDepth)); if (maxValue <= 0) { throw Exception("Invalid bit depth max value."); @@ -77,7 +77,7 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, inBitDepthBuffer[4*pixelsCopied+0] = *rPtr; inBitDepthBuffer[4*pixelsCopied+1] = *gPtr; inBitDepthBuffer[4*pixelsCopied+2] = *bPtr; - inBitDepthBuffer[4 * pixelsCopied + 3] = aPtr ? *aPtr : (Type)(maxValue); + inBitDepthBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (Type)(maxValue); pixelsCopied++; xIndex++; @@ -101,7 +101,7 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, float * outputBuffer, int outputBufferSize, long imagePixelStartIndex, - BitDepth outputBitDepth) + BitDepth inputBitDepth) { if(outputBuffer==nullptr) { @@ -140,12 +140,6 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, aPtr = reinterpret_cast(aRow + xStrideBytes*xIndex); } - double maxValue = GetBitDepthMaxValue(outputBitDepth); - if (maxValue <= 0) - { - throw Exception("Invalid bit depth max value."); - } - // Process one single, complete scanline. int pixelsCopied = 0; while(pixelsCopied < outputBufferSize) @@ -154,7 +148,7 @@ void Generic::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 : (float)maxValue; + outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (float)1.0f; pixelsCopied++; xIndex++; diff --git a/src/OpenColorIO/ScanlineHelper.cpp b/src/OpenColorIO/ScanlineHelper.cpp index 257bf8808..aaa985fa3 100644 --- a/src/OpenColorIO/ScanlineHelper.cpp +++ b/src/OpenColorIO/ScanlineHelper.cpp @@ -144,7 +144,7 @@ void GenericScanlineHelper::prepRGBAScanline(float** buffer, lo *buffer, m_dstImg.m_width, m_yIndex * m_dstImg.m_width, - m_outputBitDepth); + m_inputBitDepth); } numPixels = m_dstImg.m_width; From fc66696933ff972042b64f0b0f3eb141f688af7e Mon Sep 17 00:00:00 2001 From: pylee Date: Mon, 2 Feb 2026 21:25:34 -0800 Subject: [PATCH 4/5] Forgot to update ImagePacking.h Signed-off-by: pylee --- src/OpenColorIO/ImagePacking.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenColorIO/ImagePacking.h b/src/OpenColorIO/ImagePacking.h index fe689306a..42c3db8dc 100644 --- a/src/OpenColorIO/ImagePacking.h +++ b/src/OpenColorIO/ImagePacking.h @@ -54,7 +54,7 @@ struct Generic float * outputBuffer, int outputBufferSize, long imagePixelStartIndex, - BitDepth outputBitDepth); + BitDepth inputBitDepth); static void UnpackRGBAToImageDesc(GenericImageDesc & dstImg, float * inputBuffer, From 5a4085b19fc009842f4fc500c3e74770ce3b7059 Mon Sep 17 00:00:00 2001 From: pylee Date: Mon, 2 Feb 2026 21:45:32 -0800 Subject: [PATCH 5/5] Remove the unused inputBitDepth name causing compiler error. Signed-off-by: pylee --- src/OpenColorIO/ImagePacking.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenColorIO/ImagePacking.cpp b/src/OpenColorIO/ImagePacking.cpp index 500b41568..2c4abf7f4 100644 --- a/src/OpenColorIO/ImagePacking.cpp +++ b/src/OpenColorIO/ImagePacking.cpp @@ -101,7 +101,7 @@ void Generic::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, float * outputBuffer, int outputBufferSize, long imagePixelStartIndex, - BitDepth inputBitDepth) + BitDepth /*inputBitDepth*/) { if(outputBuffer==nullptr) {