PNG: Fix tRNS handling.

This commit is contained in:
Jeroen van Rijn
2021-05-01 18:24:31 +02:00
parent 956b59d48c
commit 0659a11a1a
2 changed files with 16 additions and 19 deletions
+16 -18
View File
@@ -1049,28 +1049,25 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
}
for len(p) > 0 {
r := p[0];
r := p[0];
alpha := u8(1);
if seen_trns {
if r == key {
if seen_bkgd {
c := img.background.([3]u16);
r = u8(c[0]);
bc := img.background.([3]u16);
r = u8(bc[0]);
} else {
alpha = 0; // Keyed transparency
}
}
if premultiply {
o[0] = r * alpha;
o[1] = r * alpha;
o[2] = r * alpha;
r *= alpha;
}
} else {
o[0] = r;
o[1] = r;
o[2] = r;
}
o[0] = r;
o[1] = r;
o[2] = r;
if out_image_channels == 4 {
o[3] = alpha * 255;
@@ -1128,6 +1125,7 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
*/
key = []u8{trns.data[1], trns.data[3], trns.data[5]};
}
for len(p) > 0 {
r := p[0];
g := p[1];
@@ -1147,17 +1145,17 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c
}
}
if .alpha_premultiply in options || .blend_background in options {
o[0] = r * alpha;
o[1] = g * alpha;
o[2] = b * alpha;
if premultiply {
r *= alpha;
g *= alpha;
b *= alpha;
}
} else {
o[0] = r;
o[1] = g;
o[2] = b;
}
o[0] = r;
o[1] = g;
o[2] = b;
if out_image_channels == 4 {
o[3] = alpha * 255;
}
-1
View File
@@ -3,7 +3,6 @@ package testing
import "core:io"
import "core:os"
import "core:strings"
import "core:slice"
reset_t :: proc(t: ^T) {