std: fix frame config background_color re alpha

This commit is contained in:
Nigel Tao committed 2024-09-20 13:38:26 +09:30
1 parent b76af12139
commit b369d233ce
14 files changed
+97 -24

No files matched your search

+13
View File
@@ -399,6 +399,7 @@ typedef struct wuffs_base__pixel_format__struct {
#ifdef __cplusplus
inline bool is_valid() const;
inline uint32_t bits_per_pixel() const;
inline uint32_t default_background_color() const;
inline bool is_direct() const;
inline bool is_indexed() const;
inline bool is_interleaved() const;
@@ -491,6 +492,13 @@ wuffs_base__pixel_format__bits_per_pixel(const wuffs_base__pixel_format* f) {
(f->repr >> 12)];
}
static inline uint32_t //
wuffs_base__pixel_format__default_background_color(
const wuffs_base__pixel_format* f) {
return ((f->repr & 0x03000000) == 0) ? 0xFF000000 // Opaque black.
: 0x00000000; // Transparent black.
}
static inline bool //
wuffs_base__pixel_format__is_direct(const wuffs_base__pixel_format* f) {
return ((f->repr >> 18) & 0x01) == 0;
@@ -539,6 +547,11 @@ wuffs_base__pixel_format::bits_per_pixel() const {
return wuffs_base__pixel_format__bits_per_pixel(this);
}
inline uint32_t //
wuffs_base__pixel_format::default_background_color() const {
return wuffs_base__pixel_format__default_background_color(this);
}
inline bool //
wuffs_base__pixel_format::is_direct() const {
return wuffs_base__pixel_format__is_direct(this);
+1
View File
@@ -684,6 +684,7 @@ var funcsOther = [...]string{
// ---- pixel_format
"pixel_format.bits_per_pixel() u32[..= 256]",
"pixel_format.default_background_color() u32",
// ---- pixel_swizzler
+46 -10
View File
@@ -4438,6 +4438,7 @@ typedef struct wuffs_base__pixel_format__struct {
#ifdef __cplusplus
inline bool is_valid() const;
inline uint32_t bits_per_pixel() const;
inline uint32_t default_background_color() const;
inline bool is_direct() const;
inline bool is_indexed() const;
inline bool is_interleaved() const;
@@ -4530,6 +4531,13 @@ wuffs_base__pixel_format__bits_per_pixel(const wuffs_base__pixel_format* f) {
(f->repr >> 12)];
}
static inline uint32_t //
wuffs_base__pixel_format__default_background_color(
const wuffs_base__pixel_format* f) {
return ((f->repr & 0x03000000) == 0) ? 0xFF000000 // Opaque black.
: 0x00000000; // Transparent black.
}
static inline bool //
wuffs_base__pixel_format__is_direct(const wuffs_base__pixel_format* f) {
return ((f->repr >> 18) & 0x01) == 0;
@@ -4578,6 +4586,11 @@ wuffs_base__pixel_format::bits_per_pixel() const {
return wuffs_base__pixel_format__bits_per_pixel(this);
}
inline uint32_t //
wuffs_base__pixel_format::default_background_color() const {
return wuffs_base__pixel_format__default_background_color(this);
}
inline bool //
wuffs_base__pixel_format::is_direct() const {
return wuffs_base__pixel_format__is_direct(this);
@@ -34636,6 +34649,8 @@ wuffs_bmp__decoder__do_decode_frame_config(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -34678,6 +34693,7 @@ wuffs_bmp__decoder__do_decode_frame_config(
goto ok;
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -34691,7 +34707,7 @@ wuffs_bmp__decoder__do_decode_frame_config(
0u,
true,
false,
4278190080u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
self->private_impl.f_call_sequence = 64u;
@@ -43549,6 +43565,8 @@ wuffs_etc2__decoder__do_decode_frame_config(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -43591,6 +43609,7 @@ wuffs_etc2__decoder__do_decode_frame_config(
goto ok;
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -43604,7 +43623,7 @@ wuffs_etc2__decoder__do_decode_frame_config(
0u,
(self->private_impl.f_pixfmt == 2415954056u),
false,
4278190080u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
self->private_impl.f_call_sequence = 64u;
@@ -62544,7 +62563,7 @@ wuffs_netpbm__decoder__do_decode_frame_config(
0u,
false,
false,
0u);
4278190080u);
}
self->private_impl.f_call_sequence = 64u;
@@ -63549,6 +63568,8 @@ wuffs_nie__decoder__do_decode_frame_config(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -63591,6 +63612,7 @@ wuffs_nie__decoder__do_decode_frame_config(
goto ok;
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -63604,7 +63626,7 @@ wuffs_nie__decoder__do_decode_frame_config(
0u,
false,
false,
0u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
self->private_impl.f_call_sequence = 64u;
@@ -69002,6 +69024,7 @@ wuffs_png__decoder__do_decode_frame_config(
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_checksum_have = 0;
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -69226,6 +69249,7 @@ wuffs_png__decoder__do_decode_frame_config(
}
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -69239,7 +69263,7 @@ wuffs_png__decoder__do_decode_frame_config(
self->private_impl.f_frame_disposal,
((self->private_impl.f_color_type <= 3u) && ! self->private_impl.f_seen_trns),
self->private_impl.f_frame_overwrite_instead_of_blend,
0u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
wuffs_private_impl__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1u);
self->private_impl.f_call_sequence = 64u;
@@ -71685,6 +71709,8 @@ wuffs_qoi__decoder__do_decode_frame_config(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -71727,6 +71753,7 @@ wuffs_qoi__decoder__do_decode_frame_config(
goto ok;
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -71740,7 +71767,7 @@ wuffs_qoi__decoder__do_decode_frame_config(
0u,
(self->private_impl.f_pixfmt == 2415954056u),
false,
0u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
self->private_impl.f_call_sequence = 64u;
@@ -73822,6 +73849,8 @@ wuffs_targa__decoder__do_decode_frame_config(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -73864,6 +73893,7 @@ wuffs_targa__decoder__do_decode_frame_config(
goto ok;
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -73877,7 +73907,7 @@ wuffs_targa__decoder__do_decode_frame_config(
0u,
self->private_impl.f_opaque,
false,
4278190080u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
self->private_impl.f_call_sequence = 64u;
@@ -75412,6 +75442,8 @@ wuffs_thumbhash__decoder__do_decode_frame_config(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -75454,6 +75486,7 @@ wuffs_thumbhash__decoder__do_decode_frame_config(
goto ok;
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -75467,7 +75500,7 @@ wuffs_thumbhash__decoder__do_decode_frame_config(
0u,
(self->private_impl.f_has_alpha == 0u),
false,
0u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
self->private_impl.f_call_sequence = 64u;
@@ -76739,7 +76772,7 @@ wuffs_vp8__decoder__do_decode_frame_config(
0u,
false,
false,
0u);
4278190080u);
}
self->private_impl.f_call_sequence = 64u;
@@ -80855,6 +80888,8 @@ wuffs_webp__decoder__do_decode_frame_config(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_pixfmt = {0};
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -80897,6 +80932,7 @@ wuffs_webp__decoder__do_decode_frame_config(
goto ok;
}
if (a_dst != NULL) {
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt);
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
@@ -80910,7 +80946,7 @@ wuffs_webp__decoder__do_decode_frame_config(
0u,
false,
false,
0u);
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
}
self->private_impl.f_call_sequence = 64u;
+4 -1
View File
@@ -417,6 +417,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var pixfmt : base.pixel_format
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
@@ -433,6 +435,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.src_pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
@@ -444,7 +447,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: true,
overwrite_instead_of_blend: false,
background_color: 0xFF00_0000)
background_color: pixfmt.default_background_color())
}
this.call_sequence = 0x40
+4 -1
View File
@@ -164,6 +164,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var pixfmt : base.pixel_format
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
@@ -180,6 +182,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
@@ -191,7 +194,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: this.pixfmt == base.PIXEL_FORMAT__BGRX,
overwrite_instead_of_blend: false,
background_color: 0xFF00_0000)
background_color: pixfmt.default_background_color())
}
this.call_sequence = 0x40
+1 -1
View File
@@ -250,7 +250,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: false,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
background_color: 0xFF00_0000)
}
this.call_sequence = 0x40
+4 -1
View File
@@ -119,6 +119,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var pixfmt : base.pixel_format
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
@@ -135,6 +137,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
@@ -146,7 +149,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: false,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
background_color: pixfmt.default_background_color())
}
this.call_sequence = 0x40
+3 -1
View File
@@ -966,6 +966,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var checksum_have : base.u32
var pixfmt : base.pixel_format
if (this.call_sequence & 0x10) <> 0 {
return base."#bad call sequence"
@@ -1033,6 +1034,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.src_pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: this.frame_rect_x0,
min_incl_y: this.frame_rect_y0,
@@ -1044,7 +1046,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: this.frame_disposal,
opaque_within_bounds: (this.color_type <= 3) and (not this.seen_trns),
overwrite_instead_of_blend: this.frame_overwrite_instead_of_blend,
background_color: 0x0000_0000)
background_color: pixfmt.default_background_color())
}
this.num_decoded_frame_configs_value ~sat+= 1
+4 -1
View File
@@ -119,6 +119,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var pixfmt : base.pixel_format
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
@@ -135,6 +137,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
@@ -146,7 +149,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: this.pixfmt == base.PIXEL_FORMAT__BGRX,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
background_color: pixfmt.default_background_color())
}
this.call_sequence = 0x40
+4 -1
View File
@@ -252,6 +252,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var pixfmt : base.pixel_format
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
@@ -268,6 +270,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.src_pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
@@ -279,7 +282,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: this.opaque,
overwrite_instead_of_blend: false,
background_color: 0xFF00_0000)
background_color: pixfmt.default_background_color())
}
this.call_sequence = 0x40
+4 -1
View File
@@ -301,6 +301,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var pixfmt : base.pixel_format
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
@@ -317,6 +319,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
@@ -328,7 +331,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: this.has_alpha == 0,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
background_color: pixfmt.default_background_color())
}
this.call_sequence = 0x40
+1 -1
View File
@@ -128,7 +128,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: false,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
background_color: 0xFF00_0000)
}
this.call_sequence = 0x40
+4 -1
View File
@@ -308,6 +308,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var pixfmt : base.pixel_format
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
@@ -324,6 +326,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}
if args.dst <> nullptr {
pixfmt = this.util.make_pixel_format(repr: this.pixfmt)
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
@@ -335,7 +338,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
disposal: 0,
opaque_within_bounds: false,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
background_color: pixfmt.default_background_color())
}
this.call_sequence = 0x40
+4 -4
View File
@@ -106,12 +106,12 @@ OK. dcbb225a test/data/hippopotamus.bmp
OK. ed4b78fc test/data/hippopotamus.interlaced.gif
OK. dcbb225a test/data/hippopotamus.interlaced.png
BAD c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
BAD 7c6a771b test/data/hippopotamus.interlaced.truncated.png
BAD 3feec847 test/data/hippopotamus.interlaced.truncated.png
OK. 96bdbbb3 test/data/hippopotamus.jpeg
OK. dcbb225a test/data/hippopotamus.lossless.webp
OK. d5577434 test/data/hippopotamus.lossy.webp
OK. 45979d1b test/data/hippopotamus.masked-with-muybridge.etc2.bgra-binary.pkm
OK. b51ed7e8 test/data/hippopotamus.masked-with-muybridge.etc2.bgra-nonpremul.pkm
OK. 2535637e test/data/hippopotamus.masked-with-muybridge.etc2.bgra-binary.pkm
OK. 720180ee test/data/hippopotamus.masked-with-muybridge.etc2.bgra-nonpremul.pkm
OK. d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
OK. 7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
OK. dcbb225a test/data/hippopotamus.nie
@@ -119,7 +119,7 @@ OK. 57d9a4dd test/data/hippopotamus.pgm
OK. dcbb225a test/data/hippopotamus.ppm
OK. ed4b78fc test/data/hippopotamus.regular.gif
OK. dcbb225a test/data/hippopotamus.regular.png
BAD 888b1c04 test/data/hippopotamus.regular.truncated.png
BAD e4c5926b test/data/hippopotamus.regular.truncated.png
OK. f6bb81e2 test/data/mona-lisa.21x32.etc2.pkm
OK. 012ce4cf test/data/mona-lisa.21x32.png
OK. 0a22e689 test/data/mona-lisa.21x32.q50.jpeg