Skip to content

Commit

Permalink
fix foolishness
Browse files Browse the repository at this point in the history
Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Jun 27, 2024
1 parent 9c4d882 commit ddf61cd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
26 changes: 15 additions & 11 deletions src/png.imageio/pnginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,31 @@ PNGInput::associateAlpha(T* data, int size, int channels, int alpha_channel,
for (int c = 0; c < channels; c++) {
if (c != alpha_channel) {
float f = sRGB_to_linear(val[c]);
val[c] = linear_to_sRGB(f * alpha);
val[c] = linear_to_sRGB(f * alpha);
}
}
}
}
} else if (gamma == 1.0f) {
T max = std::numeric_limits<T>::max();
for (int x = 0; x < size; ++x, data += channels)
for (int c = 0; c < channels; c++)
if (c != alpha_channel) {
unsigned int f = data[c];
data[c] = (f * data[alpha_channel]) / max;
}
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) {
for (int c = 0; c < channels; c++)
if (c != alpha_channel)
data[c] = data[c] * alpha;
}
}
} else { // With gamma correction
float inv_gamma = 1.0f / gamma;
for (int x = 0; x < size; ++x, data += channels) {
DataArrayProxy<T, float> val(data);
float alpha = val[alpha_channel];
for (int c = 0; c < channels; c++)
if (c != alpha_channel)
val[c] = powf((powf(data[c], inv_gamma)) * alpha, gamma);
if (alpha != 0.0f && 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
8 changes: 4 additions & 4 deletions testsuite/png/ref/out-libpng15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ exif.png : 64 x 64, 3 channel, uint8 png
Exif:ImageHistory: "oiiotool -no-autopremult SLEEP_MM.png -cut 1x1+227+1211 -o kaka.png"
oiio:ColorSpace: "Gamma2.2"
oiio:Gamma: 2.2
Stats Min: 185 185 185 127 (of 255)
Stats Max: 185 185 185 127 (of 255)
Stats Avg: 185.00 185.00 185.00 127.00 (of 255)
Stats Min: 186 186 186 127 (of 255)
Stats Max: 186 186 186 127 (of 255)
Stats Avg: 186.00 186.00 186.00 127.00 (of 255)
Stats StdDev: 0.00 0.00 0.00 0.00 (of 255)
Stats NanCount: 0 0 0 0
Stats InfCount: 0 0 0 0
Stats FiniteCount: 1 1 1 1
Constant: Yes
Constant Color: 185.00 185.00 185.00 127.00 (of 255)
Constant Color: 186.00 186.00 186.00 127.00 (of 255)
Monochrome: No
smallalpha.png : 1 x 1, 4 channel, uint8 png
Pixel (0, 0): 240 108 119 1 (0.94117653 0.42352945 0.4666667 0.003921569)
Expand Down
8 changes: 4 additions & 4 deletions testsuite/png/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ exif.png : 64 x 64, 3 channel, uint8 png
Exif:ImageHistory: "oiiotool -no-autopremult SLEEP_MM.png -cut 1x1+227+1211 -o kaka.png"
oiio:ColorSpace: "Gamma2.2"
oiio:Gamma: 2.2
Stats Min: 185 185 185 127 (of 255)
Stats Max: 185 185 185 127 (of 255)
Stats Avg: 185.00 185.00 185.00 127.00 (of 255)
Stats Min: 186 186 186 127 (of 255)
Stats Max: 186 186 186 127 (of 255)
Stats Avg: 186.00 186.00 186.00 127.00 (of 255)
Stats StdDev: 0.00 0.00 0.00 0.00 (of 255)
Stats NanCount: 0 0 0 0
Stats InfCount: 0 0 0 0
Stats FiniteCount: 1 1 1 1
Constant: Yes
Constant Color: 185.00 185.00 185.00 127.00 (of 255)
Constant Color: 186.00 186.00 186.00 127.00 (of 255)
Monochrome: No
smallalpha.png : 1 x 1, 4 channel, uint8 png
Pixel (0, 0): 240 108 119 1 (0.94117653 0.42352945 0.4666667 0.003921569)
Expand Down

0 comments on commit ddf61cd

Please sign in to comment.