Skip to content

Commit d9eb50c

Browse files
penneleecozdasdoug-walker
authored
Alpha channel should be 1 by default, rather than 0 (#2197)
* For CPU processor, when source has no alpha make it default to 1. Signed-off-by: pylee <penne.y.lee@intel.com> * Fix alpha channel for integer types. Signed-off-by: pylee <penne.y.lee@intel.com> * Fix max alpha value to be from input bitdepth not output. Signed-off-by: pylee <penne.y.lee@intel.com> * Forgot to update ImagePacking.h Signed-off-by: pylee <penne.y.lee@intel.com> * Remove the unused inputBitDepth name causing compiler error. Signed-off-by: pylee <penne.y.lee@intel.com> * Update src/OpenColorIO/ImagePacking.cpp Co-authored-by: Cuneyt Ozdas <github@cuneytozdas.com> Signed-off-by: PenneLee <pennelee@gmail.com> --------- Signed-off-by: pylee <penne.y.lee@intel.com> Signed-off-by: PenneLee <pennelee@gmail.com> Co-authored-by: Cuneyt Ozdas <github@cuneytozdas.com> Co-authored-by: Doug Walker <doug.walker@autodesk.com>
1 parent 0773c26 commit d9eb50c

4 files changed

Lines changed: 40 additions & 30 deletions

File tree

src/OpenColorIO/ImagePacking.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ void Generic<Type>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
2323
Type * inBitDepthBuffer,
2424
float * outputBuffer,
2525
int outputBufferSize,
26-
long imagePixelStartIndex)
26+
long imagePixelStartIndex,
27+
BitDepth inputBitDepth)
2728
{
2829
if(outputBuffer==nullptr)
2930
{
@@ -62,15 +63,21 @@ void Generic<Type>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
6263
aPtr = reinterpret_cast<Type*>(aRow + xStrideBytes*xIndex);
6364
}
6465

66+
float maxValue = static_cast<float>(GetBitDepthMaxValue(inputBitDepth));
67+
if (maxValue <= 0)
68+
{
69+
throw Exception("Invalid bit depth max value.");
70+
}
71+
6572
// Process one single, complete scanline.
6673
int pixelsCopied = 0;
6774
while(pixelsCopied < outputBufferSize)
68-
{
75+
{
6976
// Reorder channels from arbitrary channel ordering to RGBA 32-bit float.
7077
inBitDepthBuffer[4*pixelsCopied+0] = *rPtr;
7178
inBitDepthBuffer[4*pixelsCopied+1] = *gPtr;
7279
inBitDepthBuffer[4*pixelsCopied+2] = *bPtr;
73-
inBitDepthBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (Type)0.0f;
80+
inBitDepthBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (Type)(maxValue);
7481

7582
pixelsCopied++;
7683
xIndex++;
@@ -93,7 +100,8 @@ void Generic<float>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
93100
float * /*inBitDepthBuffer*/,
94101
float * outputBuffer,
95102
int outputBufferSize,
96-
long imagePixelStartIndex)
103+
long imagePixelStartIndex,
104+
BitDepth /*inputBitDepth*/)
97105
{
98106
if(outputBuffer==nullptr)
99107
{
@@ -140,7 +148,7 @@ void Generic<float>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg,
140148
outputBuffer[4*pixelsCopied+0] = *rPtr;
141149
outputBuffer[4*pixelsCopied+1] = *gPtr;
142150
outputBuffer[4*pixelsCopied+2] = *bPtr;
143-
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : 0.0f;
151+
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : 1.0f;
144152

145153
pixelsCopied++;
146154
xIndex++;

src/OpenColorIO/ImagePacking.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ struct Generic
5353
Type * inBitDepthBuffer,
5454
float * outputBuffer,
5555
int outputBufferSize,
56-
long imagePixelStartIndex);
56+
long imagePixelStartIndex,
57+
BitDepth inputBitDepth);
5758

5859
static void UnpackRGBAToImageDesc(GenericImageDesc & dstImg,
5960
float * inputBuffer,

src/OpenColorIO/ScanlineHelper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void GenericScanlineHelper<InType, OutType>::prepRGBAScanline(float** buffer, lo
143143
&m_inBitDepthBuffer[0],
144144
*buffer,
145145
m_dstImg.m_width,
146-
m_yIndex * m_dstImg.m_width);
146+
m_yIndex * m_dstImg.m_width,
147+
m_inputBitDepth);
147148
}
148149

149150
numPixels = m_dstImg.m_width;

tests/cpu/CPUProcessor_tests.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ OCIO_ADD_TEST(CPUProcessor, with_one_matrix)
276276
1.0000f, 1.2500f, 1.9900f };
277277

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

283283
ComputeValues<OCIO::BIT_DEPTH_F32, OCIO::BIT_DEPTH_F32>(
284284
__LINE__, processor,
@@ -620,10 +620,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
620620
5120, 20480, 65535 };
621621

622622
const std::vector<uint16_t> resImg
623-
= { 95, 24, 0, 0,
624-
268, 178, 123, 0,
625-
955, 598, 394, 0,
626-
65535, 8589, 1986, 0 };
623+
= { 95, 24, 0, 65535,
624+
268, 178, 123, 65535,
625+
955, 598, 394, 65535,
626+
65535, 8589, 1986, 65535 };
627627

628628
ComputeValues<OCIO::BIT_DEPTH_UINT16, OCIO::BIT_DEPTH_UINT16>(
629629
__LINE__, processor,
@@ -656,10 +656,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
656656
128, 1023, 640 };
657657

658658
const std::vector<uint16_t> ui10_resImg
659-
= { 0, 6, 15, 0,
660-
26, 48, 106, 0,
661-
36, 106, 252, 0,
662-
48, 1023, 384, 0 };
659+
= { 0, 6, 15, 1023,
660+
26, 48, 106, 1023,
661+
36, 106, 252, 1023,
662+
48, 1023, 384, 1023 };
663663

664664
ComputeValues<OCIO::BIT_DEPTH_UINT10, OCIO::BIT_DEPTH_UINT10>(
665665
__LINE__, processor,
@@ -668,10 +668,10 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
668668
NB_PIXELS);
669669

670670
const std::vector<uint16_t> ui16_resImg
671-
= { 0, 394, 955, 0,
672-
1656, 3092, 6794, 0,
673-
2301, 6794, 16162, 0,
674-
3092, 65535, 24593, 0 };
671+
= { 0, 394, 955, 65535,
672+
1656, 3092, 6794, 65535,
673+
2301, 6794, 16162, 65535,
674+
3092, 65535, 24593, 65535 };
675675

676676
ComputeValues<OCIO::BIT_DEPTH_UINT10, OCIO::BIT_DEPTH_UINT16>(
677677
__LINE__, processor,
@@ -704,21 +704,21 @@ OCIO_ADD_TEST(CPUProcessor, with_one_1d_lut)
704704
1024, 2048, 4095 };
705705

706706
const std::vector<uint16_t> ui12_resImg
707-
= { 0, 11, 25, 0,
708-
37, 60, 103, 0,
709-
49, 103, 193, 0,
710-
424, 1009, 4095, 0 };
707+
= { 0, 11, 25, 4095,
708+
37, 60, 103, 4095,
709+
49, 103, 193, 4095,
710+
424, 1009, 4095, 4095 };
711711

712712
ComputeValues<OCIO::BIT_DEPTH_UINT12, OCIO::BIT_DEPTH_UINT12>(
713713
__LINE__, processor,
714714
&ui12_inImg[0], OCIO::CHANNEL_ORDERING_RGB,
715715
&ui12_resImg[0], OCIO::CHANNEL_ORDERING_RGBA,
716716
NB_PIXELS);
717717
const std::vector<uint16_t> ui16_resImg
718-
= { 0, 178, 394, 0,
719-
598, 955, 1655, 0,
720-
779, 1655, 3089, 0,
721-
6789, 16143, 65535, 0 };
718+
= { 0, 178, 394, 65535,
719+
598, 955, 1655, 65535,
720+
779, 1655, 3089, 65535,
721+
6789, 16143, 65535, 65535 };
722722

723723
ComputeValues<OCIO::BIT_DEPTH_UINT12, OCIO::BIT_DEPTH_UINT16>(
724724
__LINE__, processor,

0 commit comments

Comments
 (0)