mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
std/handsum: fix frame config background color
This commit is contained in:
1 parent
40cf8c0ad1
commit
3ad22468ce
4 files changed
+46
-18
No files matched your search
+12
-3
@@ -59,6 +59,9 @@
|
||||
// Chroma blocks' bytes are all 0x88, and the color=Gray payload is just the 4
|
||||
// Luma blocks without explicitly recording the 2 Chroma blocks.
|
||||
//
|
||||
// The color=RGBA payload extends the color=RGB payload with one more 8×8 Alpha
|
||||
// block. That seventh block is always encoded in 24 bytes (as if quality=3).
|
||||
//
|
||||
// Each 8×8 block is sub-divided into 8×8 (for q0), 4×4 (for q1 and q2) or 2×2
|
||||
// (for q3) tiles. DCT (Discrete Cosine Transform) is applied to each tile,
|
||||
// producing 64, 16, 16 or 4 DCT coefficients (depending on the quality). Only
|
||||
@@ -72,12 +75,15 @@
|
||||
// Each DCT coefficient is encoded as one nibble (4 bits) with fixed bias and
|
||||
// quantization factors.
|
||||
//
|
||||
// All Handsum images use the sRGB color profile.
|
||||
// All Handsum images use the sRGB color profile and non-premultiplied alpha.
|
||||
//
|
||||
// The "Handsum" name was inspired by the "Thumbhash" image file format, which
|
||||
// is also designed for very small thumbnails (or very compact representations
|
||||
// of image placeholders). Handsum files are bigger (but better quality) than
|
||||
// Thumbhash. "Handsum" also sounds like "handsome", meaning "good looking".
|
||||
//
|
||||
// Other techniques and image formats, similar to Thumbhash, can be found by
|
||||
// search for "LQIP" or "Low Quality Image Placeholders".
|
||||
package handsum
|
||||
|
||||
// When decoding, each nibble produces a DCT coefficient according to a simple
|
||||
@@ -121,8 +127,8 @@ package handsum
|
||||
// are rare in practice. The latter range has a slight bias (not centred on the
|
||||
// neutral 0x80) so that the Chroma DC components of a neutral gray image can
|
||||
// round-trip losslessly (in the 0x8 bucket). Chroma is narrowed (after Inverse
|
||||
// DCT) on decode and so is widened (before Forward DCT) on encode. Luma and
|
||||
// wide-Chroma then use the same DCT buckets.
|
||||
// DCT) on decode and so is widened (before Forward DCT) on encode. Luma,
|
||||
// wide-Chroma and Alpha then use the same DCT buckets.
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -212,6 +218,9 @@ func MakeOptionColor(c Color) OptionColor {
|
||||
}
|
||||
|
||||
// Quality is a Handsum image's quality setting, from 0 (worst) to 3 (best).
|
||||
//
|
||||
// "Best" is relative to the other settings. In absolute terms, Handsum's image
|
||||
// quality ranges from "potato" (best) to "extremely potato" (worst).
|
||||
type Quality uint8
|
||||
|
||||
const (
|
||||
|
||||
@@ -50650,7 +50650,7 @@ wuffs_handsum__decoder__scale_and_bias_chroma_down(
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_handsum__decoder__upsample_chroma(
|
||||
wuffs_handsum__decoder__upsample_chroma_and_alpha(
|
||||
wuffs_handsum__decoder* self);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -51086,6 +51086,9 @@ wuffs_handsum__decoder__do_decode_frame_config(
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
bool v_opaque_within_bounds = false;
|
||||
uint32_t v_background_color = 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;
|
||||
@@ -51128,6 +51131,12 @@ wuffs_handsum__decoder__do_decode_frame_config(
|
||||
goto ok;
|
||||
}
|
||||
if (a_dst != NULL) {
|
||||
v_opaque_within_bounds = false;
|
||||
v_background_color = 0u;
|
||||
if (self->private_impl.f_color < 3u) {
|
||||
v_opaque_within_bounds = true;
|
||||
v_background_color = 4278190080u;
|
||||
}
|
||||
wuffs_base__frame_config__set(
|
||||
a_dst,
|
||||
wuffs_base__utility__make_rect_ie_u32(
|
||||
@@ -51139,9 +51148,9 @@ wuffs_handsum__decoder__do_decode_frame_config(
|
||||
0u,
|
||||
3u,
|
||||
0u,
|
||||
true,
|
||||
v_opaque_within_bounds,
|
||||
false,
|
||||
4278190080u);
|
||||
v_background_color);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 64u;
|
||||
|
||||
@@ -51362,7 +51371,7 @@ wuffs_handsum__decoder__do_decode_frame(
|
||||
wuffs_handsum__decoder__smooth_seams_16x16(self);
|
||||
if (self->private_impl.f_color != 0u) {
|
||||
wuffs_handsum__decoder__scale_and_bias_chroma_down(self);
|
||||
wuffs_handsum__decoder__upsample_chroma(self);
|
||||
wuffs_handsum__decoder__upsample_chroma_and_alpha(self);
|
||||
wuffs_handsum__decoder__convert_ycca_to_bgra(self);
|
||||
}
|
||||
v_which = 0u;
|
||||
@@ -51862,11 +51871,11 @@ wuffs_handsum__decoder__scale_and_bias_chroma_down(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func handsum.decoder.upsample_chroma
|
||||
// -------- func handsum.decoder.upsample_chroma_and_alpha
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_handsum__decoder__upsample_chroma(
|
||||
wuffs_handsum__decoder__upsample_chroma_and_alpha(
|
||||
wuffs_handsum__decoder* self) {
|
||||
uint32_t v_y = 0;
|
||||
uint32_t v_dy = 0;
|
||||
|
||||
@@ -119,6 +119,9 @@ 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 opaque_within_bounds : base.bool
|
||||
var background_color : base.u32
|
||||
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
@@ -135,6 +138,13 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
opaque_within_bounds = false
|
||||
background_color = 0x0000_0000
|
||||
if this.color < 3 {
|
||||
opaque_within_bounds = true
|
||||
background_color = 0xFF00_0000
|
||||
}
|
||||
|
||||
args.dst.set!(bounds: this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
@@ -144,9 +154,9 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
index: 0,
|
||||
io_position: 3,
|
||||
disposal: 0,
|
||||
opaque_within_bounds: true,
|
||||
opaque_within_bounds: opaque_within_bounds,
|
||||
overwrite_instead_of_blend: false,
|
||||
background_color: 0xFF00_0000)
|
||||
background_color: background_color)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x40
|
||||
@@ -253,7 +263,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
|
||||
if this.color <> 0 {
|
||||
this.scale_and_bias_chroma_down!()
|
||||
this.upsample_chroma!()
|
||||
this.upsample_chroma_and_alpha!()
|
||||
this.convert_ycca_to_bgra!()
|
||||
}
|
||||
|
||||
@@ -782,10 +792,10 @@ pri func decoder.scale_and_bias_chroma_down!() {
|
||||
}
|
||||
}
|
||||
|
||||
// upsample_chroma converts the 8×8 Chroma samples in this.buffers[1] to 16×16
|
||||
// Chroma samples in this.buffers[0], adjacent to the existing 16×16 Luma
|
||||
// samples in this.buffers[0].
|
||||
pri func decoder.upsample_chroma!() {
|
||||
// upsample_chroma_and_alpha converts the 8×8 Chroma and Alpha samples in
|
||||
// this.buffers[1] to 16×16 samples in this.buffers[0], adjacent to the
|
||||
// existing 16×16 Luma samples in this.buffers[0].
|
||||
pri func decoder.upsample_chroma_and_alpha!() {
|
||||
var y : base.u32
|
||||
var dy : base.u32
|
||||
var y0 : base.u32[..= 7]
|
||||
|
||||
@@ -6,8 +6,8 @@ OK. e3bae566 test/data/49.bp4.nie
|
||||
OK. c3528d19 test/data/49.bp8.nie
|
||||
OK. bf3fd567 test/data/49.c3q1.handsum
|
||||
OK. 7cac72e5 test/data/49.c3q3.handsum
|
||||
OK. 2d906dc0 test/data/49.c4q1.handsum
|
||||
OK. dcf12bd3 test/data/49.c4q3.handsum
|
||||
OK. 44e9cb76 test/data/49.c4q1.handsum
|
||||
OK. d55478dd test/data/49.c4q3.handsum
|
||||
OK. f2a0a3f6 test/data/49.png
|
||||
OK. d3bb0beb test/data/DCI-P3-D65.icc
|
||||
OK. 646e081a test/data/animated-red-blue.000000.nie
|
||||
|
||||
Reference in new issue
Block a user