Skip to content

Conversation

@pennelee
Copy link
Contributor

Related to issue #1781.

For CPU processor, when source has no alpha (RGB) but dest does (RGBA) make it default to 1.
GPU Processors (new and legacy) did not seem to have this issue, alpha was already set to 1. Let me know if this is not the case.

Tested changes with ocioconvert and changed the output to force RGBA, since the default is to use inplace conversion (did not check in those changes).
Tested with all the ocioconvert test cases (basic, --lut, --view, --invertview --namedtransform, --invnamed transform), and various EXR file sizes.

Before the changes alpha would be 0, so image was not viewable. After the changes then images can be viewed and from inspection the alpha channel is now 1.0.

Also updated related CPU tests to reflect non zero alpha values.

@doug-walker
Copy link
Collaborator

Thanks for the contribution @pennelee !

Added the devdays25 label.

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

The idea is if the input image doesn't have an alpha channel, we need to consider the pixels as fully opaque instead of fully transparent (alpha=0). For floating point types fully opaque is represented as 1.0f but for integer types it needs to be the max value the type can hold (e.g. for 8-bit types it's 255)

Please check BithDepthUtils.h, the templated struct BitDepthInfo will be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I got you, thanks @cozdas! Let me take a look at that file and fix it, will comment if any questions.

@pennelee pennelee requested a review from cozdas February 1, 2026 06:44
@pennelee
Copy link
Contributor Author

pennelee commented Feb 1, 2026

Hi @cozdas ,
Finally I have made some update, could you please review again and let me know if you have any feedback. Thank you.

Copy link
Collaborator

@cozdas cozdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pennelee,
The unit test expected values are now making much more sense, thanks for the fix but the value that needs to be used should be derived from the input bit depth, not output, I added comments to some of the relevant lines.

I believe the tests will still pass when you use the input depth instead of the output.

int outputBufferSize,
long imagePixelStartIndex)
long imagePixelStartIndex,
BitDepth outputBitDepth)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function Packs the input image (3 or 4 channel, of type 'Type') into 4-channel f32 buffer, and thus the output bit depth should not be part of the conversion. What needs to be done is to fill the missing input alpha value as the max value the "input" type can represent.

Since the GenericImageDesc class is a simplified version of ImageDesc, it doesn't carry the bithDepth information in it like the ImageDesc does, so you are right to pass it as a separate parameter, but it needs to be the input image bit depth, not the output.

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the formatting consistent with the above lines

int outputBufferSize,
long imagePixelStartIndex)
long imagePixelStartIndex,
BitDepth outputBitDepth)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a specialization of the template function for float input type, so you can simplify this by using hard-coded 1.0f.

m_dstImg.m_width,
m_yIndex * m_dstImg.m_width);
m_yIndex * m_dstImg.m_width,
m_outputBitDepth);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as explained above, needs to be m_inputBitDepth

Copy link
Collaborator

@cozdas cozdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just added a minor suggestion.
Thanks for the fixes.

outputBuffer[4*pixelsCopied+1] = *gPtr;
outputBuffer[4*pixelsCopied+2] = *bPtr;
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : 0.0f;
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (float)1.0f;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : (float)1.0f;
outputBuffer[4*pixelsCopied+3] = aPtr ? *aPtr : 1.0f;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants