Skip to content

Commit

Permalink
fix(png): bug in associateAlpha botched alpha=0 pixels (AcademySoftwa…
Browse files Browse the repository at this point in the history
…reFoundation#4386)

In trying to avoid doing the color conversion pointlessly for pixels
with alpha=0, I accidentally also managed to skip the multiplication by
alpha for those pixels. Oops.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Aug 21, 2024
1 parent fac55fa commit 6b2d140
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/png.imageio/pnginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ PNGInput::associateAlpha(T* data, int size, int channels, int alpha_channel,
for (int x = 0; x < size; ++x, data += channels) {
DataArrayProxy<T, float> val(data);
float alpha = val[alpha_channel];
if (alpha != 0.0f && alpha != 1.0f) {
if (alpha != 1.0f) {
for (int c = 0; c < channels; c++) {
if (c != alpha_channel) {
float f = sRGB_to_linear(val[c]);
Expand All @@ -245,7 +245,7 @@ PNGInput::associateAlpha(T* data, int size, int channels, int alpha_channel,
for (int x = 0; x < size; ++x, data += channels) {
DataArrayProxy<T, float> val(data);
float alpha = val[alpha_channel];
if (alpha != 0.0f && alpha != 1.0f) {
if (alpha != 1.0f) {
for (int c = 0; c < channels; c++)
if (c != alpha_channel)
data[c] = data[c] * alpha;
Expand All @@ -256,7 +256,7 @@ PNGInput::associateAlpha(T* data, int size, int channels, int alpha_channel,
for (int x = 0; x < size; ++x, data += channels) {
DataArrayProxy<T, float> val(data);
float alpha = val[alpha_channel];
if (alpha != 0.0f && alpha != 1.0f) {
if (alpha != 1.0f) {
for (int c = 0; c < channels; c++)
if (c != alpha_channel)
val[c] = powf((powf(val[c], gamma)) * alpha, inv_gamma);
Expand Down
2 changes: 1 addition & 1 deletion testsuite/png/ref/out-libpng15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Comparing "../oiio-images/oiio-logo-no-alpha.png" and "oiio-logo-no-alpha.png"
PASS
Reading ../oiio-images/oiio-logo-with-alpha.png
../oiio-images/oiio-logo-with-alpha.png : 135 x 135, 4 channel, uint8 png
SHA-1: 9F3C517AC714A93C0FE93F8B4B40C68338504DC8
SHA-1: 8AED04DCCE8F83B068C537DC0982A42EFBE431B6
channel list: R, G, B, A
Comment: "Created with GIMP"
DateTime: "2009:03:26 18:44:26"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/png/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Comparing "../oiio-images/oiio-logo-no-alpha.png" and "oiio-logo-no-alpha.png"
PASS
Reading ../oiio-images/oiio-logo-with-alpha.png
../oiio-images/oiio-logo-with-alpha.png : 135 x 135, 4 channel, uint8 png
SHA-1: 9F3C517AC714A93C0FE93F8B4B40C68338504DC8
SHA-1: 8AED04DCCE8F83B068C537DC0982A42EFBE431B6
channel list: R, G, B, A
Comment: "Created with GIMP"
DateTime: "2009:03:26 18:44:26"
Expand Down

0 comments on commit 6b2d140

Please sign in to comment.