std/qoi: use PIXEL_FORMAT__BGRX

This commit is contained in:
Nigel Tao committed 2024-08-09 13:48:34 +10:00
1 parent d06700f00b
commit bd27cc0d9b
2 files changed
+34 -35

No files matched your search

+17 -17
View File
@@ -12917,10 +12917,10 @@ struct wuffs_qoi__decoder__struct {
wuffs_base__vtable vtable_for__wuffs_base__image_decoder; wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable; wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint32_t f_width; uint32_t f_width;
uint32_t f_height; uint32_t f_height;
uint64_t f_remaining_pixels_times_4; uint64_t f_remaining_pixels_times_4;
bool f_is_opaque;
uint8_t f_call_sequence; uint8_t f_call_sequence;
uint32_t f_buffer_index; uint32_t f_buffer_index;
uint32_t f_dst_x; uint32_t f_dst_x;
@@ -67570,9 +67570,9 @@ wuffs_qoi__decoder__do_decode_image_config(
v_a = t_3; v_a = t_3;
} }
if (v_a == 3u) { if (v_a == 3u) {
self->private_impl.f_is_opaque = true; self->private_impl.f_pixfmt = 2415954056u;
} else if (v_a == 4u) { } else if (v_a == 4u) {
self->private_impl.f_is_opaque = false; self->private_impl.f_pixfmt = 2164295816u;
} else { } else {
status = wuffs_base__make_status(wuffs_qoi__error__bad_header); status = wuffs_base__make_status(wuffs_qoi__error__bad_header);
goto exit; goto exit;
@@ -67586,12 +67586,12 @@ wuffs_qoi__decoder__do_decode_image_config(
if (a_dst != NULL) { if (a_dst != NULL) {
wuffs_base__image_config__set( wuffs_base__image_config__set(
a_dst, a_dst,
2701166728u, self->private_impl.f_pixfmt,
0u, 0u,
self->private_impl.f_width, self->private_impl.f_width,
self->private_impl.f_height, self->private_impl.f_height,
14u, 14u,
self->private_impl.f_is_opaque); (self->private_impl.f_pixfmt == 2415954056u));
} }
self->private_impl.f_call_sequence = 32u; self->private_impl.f_call_sequence = 32u;
@@ -67743,7 +67743,7 @@ wuffs_qoi__decoder__do_decode_frame_config(
0u, 0u,
14u, 14u,
0u, 0u,
self->private_impl.f_is_opaque, (self->private_impl.f_pixfmt == 2415954056u),
false, false,
0u); 0u);
} }
@@ -67892,7 +67892,7 @@ wuffs_qoi__decoder__do_decode_frame(
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler, v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
wuffs_base__pixel_buffer__pixel_format(a_dst), wuffs_base__pixel_buffer__pixel_format(a_dst),
wuffs_base__pixel_buffer__palette(a_dst), wuffs_base__pixel_buffer__palette(a_dst),
wuffs_base__utility__make_pixel_format(2701166728u), wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(), wuffs_base__utility__empty_slice_u8(),
a_blend); a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) { if ( ! wuffs_base__status__is_ok(&v_status)) {
@@ -68054,7 +68054,7 @@ wuffs_qoi__decoder__from_src_to_buffer(
goto suspend; goto suspend;
} }
uint8_t t_1 = *iop_a_src++; uint8_t t_1 = *iop_a_src++;
self->private_data.f_pixel[0u] = t_1; self->private_data.f_pixel[2u] = t_1;
} }
{ {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
@@ -68072,7 +68072,7 @@ wuffs_qoi__decoder__from_src_to_buffer(
goto suspend; goto suspend;
} }
uint8_t t_3 = *iop_a_src++; uint8_t t_3 = *iop_a_src++;
self->private_data.f_pixel[2u] = t_3; self->private_data.f_pixel[0u] = t_3;
} }
} else if (v_c8 == 255u) { } else if (v_c8 == 255u) {
{ {
@@ -68082,7 +68082,7 @@ wuffs_qoi__decoder__from_src_to_buffer(
goto suspend; goto suspend;
} }
uint8_t t_4 = *iop_a_src++; uint8_t t_4 = *iop_a_src++;
self->private_data.f_pixel[0u] = t_4; self->private_data.f_pixel[2u] = t_4;
} }
{ {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
@@ -68100,7 +68100,7 @@ wuffs_qoi__decoder__from_src_to_buffer(
goto suspend; goto suspend;
} }
uint8_t t_6 = *iop_a_src++; uint8_t t_6 = *iop_a_src++;
self->private_data.f_pixel[2u] = t_6; self->private_data.f_pixel[0u] = t_6;
} }
{ {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
@@ -68128,9 +68128,9 @@ wuffs_qoi__decoder__from_src_to_buffer(
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wconversion"
#endif #endif
self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 4u)) & 3u)) + 254u)); self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 4u)) & 3u)) + 254u));
self->private_data.f_pixel[1u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 2u)) & 3u)) + 254u)); self->private_data.f_pixel[1u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 2u)) & 3u)) + 254u));
self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 0u)) & 3u)) + 254u)); self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 0u)) & 3u)) + 254u));
#if defined(__GNUC__) #if defined(__GNUC__)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
@@ -68149,9 +68149,9 @@ wuffs_qoi__decoder__from_src_to_buffer(
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wconversion"
#endif #endif
self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 4u)))))); self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 4u))))));
self->private_data.f_pixel[1u] += v_dg; self->private_data.f_pixel[1u] += v_dg;
self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 0u)))))); self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 0u))))));
#if defined(__GNUC__) #if defined(__GNUC__)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
@@ -68166,9 +68166,9 @@ wuffs_qoi__decoder__from_src_to_buffer(
} }
continue; continue;
} }
v_hash4 = (4u * (63u & ((((uint32_t)(self->private_data.f_pixel[0u])) * 3u) + v_hash4 = (4u * (63u & ((((uint32_t)(self->private_data.f_pixel[2u])) * 3u) +
(((uint32_t)(self->private_data.f_pixel[1u])) * 5u) + (((uint32_t)(self->private_data.f_pixel[1u])) * 5u) +
(((uint32_t)(self->private_data.f_pixel[2u])) * 7u) + (((uint32_t)(self->private_data.f_pixel[0u])) * 7u) +
(((uint32_t)(self->private_data.f_pixel[3u])) * 11u)))); (((uint32_t)(self->private_data.f_pixel[3u])) * 11u))));
self->private_data.f_cache[(v_hash4 + 0u)] = self->private_data.f_pixel[0u]; self->private_data.f_cache[(v_hash4 + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_cache[(v_hash4 + 1u)] = self->private_data.f_pixel[1u]; self->private_data.f_cache[(v_hash4 + 1u)] = self->private_data.f_pixel[1u];
+17 -18
View File
@@ -15,13 +15,12 @@ pub status "#truncated input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0 pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder( pub struct decoder? implements base.image_decoder(
pixfmt : base.u32,
width : base.u32[..= 0xFF_FFFF], width : base.u32[..= 0xFF_FFFF],
height : base.u32[..= 0xFF_FFFF], height : base.u32[..= 0xFF_FFFF],
remaining_pixels_times_4 : base.u64, remaining_pixels_times_4 : base.u64,
is_opaque : base.bool,
// The call sequence state machine is discussed in // The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md). // (/doc/std/image-decoders-call-sequence.md).
call_sequence : base.u8, call_sequence : base.u8,
@@ -85,9 +84,9 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
a = args.src.read_u8_as_u32?() a = args.src.read_u8_as_u32?()
if a == 3 { if a == 3 {
this.is_opaque = true this.pixfmt = base.PIXEL_FORMAT__BGRX
} else if a == 4 { } else if a == 4 {
this.is_opaque = false this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
} else { } else {
return "#bad header" return "#bad header"
} }
@@ -96,12 +95,12 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
if args.dst <> nullptr { if args.dst <> nullptr {
args.dst.set!( args.dst.set!(
pixfmt: base.PIXEL_FORMAT__RGBA_NONPREMUL, pixfmt: this.pixfmt,
pixsub: 0, pixsub: 0,
width: this.width, width: this.width,
height: this.height, height: this.height,
first_frame_io_position: 14, first_frame_io_position: 14,
first_frame_is_opaque: this.is_opaque) first_frame_is_opaque: this.pixfmt == base.PIXEL_FORMAT__BGRX)
} }
this.call_sequence = 0x20 this.call_sequence = 0x20
@@ -145,7 +144,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
index: 0, index: 0,
io_position: 14, io_position: 14,
disposal: 0, disposal: 0,
opaque_within_bounds: this.is_opaque, opaque_within_bounds: this.pixfmt == base.PIXEL_FORMAT__BGRX,
overwrite_instead_of_blend: false, overwrite_instead_of_blend: false,
background_color: 0x0000_0000) background_color: 0x0000_0000)
} }
@@ -180,7 +179,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
status = this.swizzler.prepare!( status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(), dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette(), dst_palette: args.dst.palette(),
src_pixfmt: this.util.make_pixel_format(repr: base.PIXEL_FORMAT__RGBA_NONPREMUL), src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
src_palette: this.util.empty_slice_u8(), src_palette: this.util.empty_slice_u8(),
blend: args.blend) blend: args.blend)
if not status.is_ok() { if not status.is_ok() {
@@ -234,14 +233,14 @@ pri func decoder.from_src_to_buffer?(src: base.io_reader) {
assert bi < 7936 via "a < b: a < c; c <= b"(c: bk) assert bi < 7936 via "a < b: a < c; c <= b"(c: bk)
c8 = args.src.read_u8?() c8 = args.src.read_u8?()
if c8 == 0xFE { // QOI_OP_RGB. if c8 == 0xFE { // QOI_OP_RGB.
this.pixel[0] = args.src.read_u8?()
this.pixel[1] = args.src.read_u8?()
this.pixel[2] = args.src.read_u8?() this.pixel[2] = args.src.read_u8?()
this.pixel[1] = args.src.read_u8?()
this.pixel[0] = args.src.read_u8?()
} else if c8 == 0xFF { // QOI_OP_RGBA. } else if c8 == 0xFF { // QOI_OP_RGBA.
this.pixel[0] = args.src.read_u8?()
this.pixel[1] = args.src.read_u8?()
this.pixel[2] = args.src.read_u8?() this.pixel[2] = args.src.read_u8?()
this.pixel[1] = args.src.read_u8?()
this.pixel[0] = args.src.read_u8?()
this.pixel[3] = args.src.read_u8?() this.pixel[3] = args.src.read_u8?()
} else if (c8 >> 6) == 0 { // QOI_OP_INDEX. } else if (c8 >> 6) == 0 { // QOI_OP_INDEX.
@@ -258,16 +257,16 @@ pri func decoder.from_src_to_buffer?(src: base.io_reader) {
continue continue
} else if (c8 >> 6) == 1 { // QOI_OP_DIFF. } else if (c8 >> 6) == 1 { // QOI_OP_DIFF.
this.pixel[0] ~mod+= ((c8 >> 4) & 0x03) ~mod+ 0xFE this.pixel[2] ~mod+= ((c8 >> 4) & 0x03) ~mod+ 0xFE
this.pixel[1] ~mod+= ((c8 >> 2) & 0x03) ~mod+ 0xFE this.pixel[1] ~mod+= ((c8 >> 2) & 0x03) ~mod+ 0xFE
this.pixel[2] ~mod+= ((c8 >> 0) & 0x03) ~mod+ 0xFE this.pixel[0] ~mod+= ((c8 >> 0) & 0x03) ~mod+ 0xFE
} else if (c8 >> 6) == 2 { // QOI_OP_LUMA. } else if (c8 >> 6) == 2 { // QOI_OP_LUMA.
dg = (c8 & 0x3F) ~mod+ 0xE0 dg = (c8 & 0x3F) ~mod+ 0xE0
c8 = args.src.read_u8?() c8 = args.src.read_u8?()
this.pixel[0] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 4)) this.pixel[2] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 4))
this.pixel[1] ~mod+= dg this.pixel[1] ~mod+= dg
this.pixel[2] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 0)) this.pixel[0] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 0))
} else { // QOI_OP_RUN. } else { // QOI_OP_RUN.
bj = bi + (4 * (0x3F & (1 + (c8 as base.u32)))) bj = bi + (4 * (0x3F & (1 + (c8 as base.u32))))
@@ -283,9 +282,9 @@ pri func decoder.from_src_to_buffer?(src: base.io_reader) {
} }
hash4 = 4 * (63 & ( hash4 = 4 * (63 & (
((this.pixel[0] as base.u32) * 3) + ((this.pixel[2] as base.u32) * 3) +
((this.pixel[1] as base.u32) * 5) + ((this.pixel[1] as base.u32) * 5) +
((this.pixel[2] as base.u32) * 7) + ((this.pixel[0] as base.u32) * 7) +
((this.pixel[3] as base.u32) * 11))) ((this.pixel[3] as base.u32) * 11)))
this.cache[hash4 + 0] = this.pixel[0] this.cache[hash4 + 0] = this.pixel[0]
this.cache[hash4 + 1] = this.pixel[1] this.cache[hash4 + 1] = this.pixel[1]