-
Notifications
You must be signed in to change notification settings - Fork 486
Alpha channel should be 1 by default, rather than 0 #2197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,8 @@ void Generic<Type>::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<Type>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, | |
| aPtr = reinterpret_cast<Type*>(aRow + xStrideBytes*xIndex); | ||
| } | ||
|
|
||
| float maxValue = static_cast<float>(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)0.0f; | ||
| inBitDepthBuffer[4 * pixelsCopied + 3] = aPtr ? *aPtr : (Type)(maxValue); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep the formatting consistent with the above lines |
||
|
|
||
| pixelsCopied++; | ||
| xIndex++; | ||
|
|
@@ -93,7 +100,8 @@ void Generic<float>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, | |
| float * /*inBitDepthBuffer*/, | ||
| float * outputBuffer, | ||
| int outputBufferSize, | ||
| long imagePixelStartIndex) | ||
| long imagePixelStartIndex, | ||
| BitDepth outputBitDepth) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| { | ||
| if(outputBuffer==nullptr) | ||
| { | ||
|
|
@@ -132,6 +140,12 @@ void Generic<float>::PackRGBAFromImageDesc(const GenericImageDesc & srcImg, | |
| aPtr = reinterpret_cast<float*>(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<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 : (float)maxValue; | ||
|
|
||
| pixelsCopied++; | ||
| xIndex++; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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_outputBitDepth); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as explained above, needs to be m_inputBitDepth |
||
| } | ||
|
|
||
| numPixels = m_dstImg.m_width; | ||
|
|
||
There was a problem hiding this comment.
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.