Add a image_config.first_frame_is_opaque method

This commit is contained in:
Nigel Tao committed 2018-06-11 11:07:14 +10:00
1 parent 26ce04ab64
commit 1ee2152785
20 files changed
+306 -141

No files matched your search

+9 -1
View File
@@ -947,6 +947,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -957,7 +958,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -970,6 +972,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1024,6 +1027,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+4 -3
View File
@@ -77,9 +77,10 @@ const basePublicH = "" +
"SUBSAMPLING__440 \\\n ((wuffs_base__pixel_subsampling)0x010100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__422 \\\n ((wuffs_base__pixel_subsampling)0x101000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__420 \\\n ((wuffs_base__pixel_subsampling)0x111100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__411 \\\n ((wuffs_base__pixel_subsampling)0x202000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__410 \\\n ((wuffs_base__pixel_subsampling)0x212100)\n\nstatic inline uint32_t wuffs_base__pixel_subsampling__bias_x(\n wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 6;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t wuffs_base__pixel_subsampling__shift_x(\n wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 4;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t wuffs_base__pixel_subsampling__bias_y(\n wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 2;\n return (s >> shift) & 0x03;\n}\n\nstatic" +
" inline uint32_t wuffs_base__pixel_subsampling__shift_y(\n wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 0;\n return (s >> shift) & 0x03;\n}\n\n" +
"" +
"// --------\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__pixel_format pixfmt;\n wuffs_base__pixel_subsampling pixsub;\n uint32_t width;\n uint32_t height;\n uint32_t num_loops;\n } private_impl;\n} wuffs_base__image_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void wuffs_base__image_config__initialize(\n wuffs_base__image_config* c,\n wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint32_t num_loops) {\n if (!c) {\n return;\n }\n if (pixfmt) {\n uint64_t wh = ((uint64_t)width) * ((uint64_t)height);\n // TODO: handle things other than 1 byte per pixel.\n if (wh <= ((uint64_t)SIZE_MAX)) {\n c->private_impl.pixfmt = pixfmt;\n c->private_impl.pixsub = pixsub;\n c->private_impl.width = width;\n c->private_impl.height = height;\n c->private_imp" +
"l.num_loops = num_loops;\n return;\n }\n }\n *c = ((wuffs_base__image_config){});\n}\n\nstatic inline void wuffs_base__image_config__invalidate(\n wuffs_base__image_config* c) {\n if (c) {\n *c = ((wuffs_base__image_config){});\n }\n}\n\nstatic inline bool wuffs_base__image_config__is_valid(\n wuffs_base__image_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format wuffs_base__image_config__pixel_format(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.pixfmt : 0;\n}\n\nstatic inline wuffs_base__pixel_subsampling\nwuffs_base__image_config__pixel_subsampling(wuffs_base__image_config* c) {\n return c ? c->private_impl.pixsub : 0;\n}\n\nstatic inline wuffs_base__rect_ie_u32 wuffs_base__image_config__bounds(\n wuffs_base__image_config* c) {\n return c ? ((wuffs_base__rect_ie_u32){\n .min_incl_x = 0,\n .min_incl_y = 0,\n .max_excl_x = c->private_impl.width,\n .max_excl_y = c->private_impl.height,\n " +
" })\n : ((wuffs_base__rect_ie_u32){});\n}\n\nstatic inline uint32_t wuffs_base__image_config__width(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.width : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__height(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.height : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__num_loops(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.num_loops : 0;\n}\n\n// TODO: this is the right API for planar (not packed) pixbufs? Should it allow\n// decoding into a color model different from the format's intrinsic one? For\n// example, decoding a JPEG image straight to RGBA instead of to YCbCr?\nstatic inline size_t wuffs_base__image_config__pixbuf_size(\n wuffs_base__image_config* c) {\n if (c) {\n uint64_t wh =\n ((uint64_t)c->private_impl.width) * ((uint64_t)c->private_impl.height);\n // TODO: handle things other than 1 byte per pixel.\n return (size_t)wh;\n }\n return 0;\n}\n\n" +
"// --------\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__pixel_format pixfmt;\n wuffs_base__pixel_subsampling pixsub;\n uint32_t width;\n uint32_t height;\n uint32_t num_loops;\n bool first_frame_is_opaque;\n } private_impl;\n} wuffs_base__image_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void wuffs_base__image_config__initialize(\n wuffs_base__image_config* c,\n wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint32_t num_loops,\n bool first_frame_is_opaque) {\n if (!c) {\n return;\n }\n if (pixfmt) {\n uint64_t wh = ((uint64_t)width) * ((uint64_t)height);\n // TODO: handle things other than 1 byte per pixel.\n if (wh <= ((uint64_t)SIZE_MAX)) {\n c->private_impl.pixfmt = pixfmt;\n c->private_impl.pixsub = pixsub;\n c->private_impl.width = wi" +
"dth;\n c->private_impl.height = height;\n c->private_impl.num_loops = num_loops;\n c->private_impl.first_frame_is_opaque = first_frame_is_opaque;\n return;\n }\n }\n *c = ((wuffs_base__image_config){});\n}\n\nstatic inline void wuffs_base__image_config__invalidate(\n wuffs_base__image_config* c) {\n if (c) {\n *c = ((wuffs_base__image_config){});\n }\n}\n\nstatic inline bool wuffs_base__image_config__is_valid(\n wuffs_base__image_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format wuffs_base__image_config__pixel_format(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.pixfmt : 0;\n}\n\nstatic inline wuffs_base__pixel_subsampling\nwuffs_base__image_config__pixel_subsampling(wuffs_base__image_config* c) {\n return c ? c->private_impl.pixsub : 0;\n}\n\nstatic inline wuffs_base__rect_ie_u32 wuffs_base__image_config__bounds(\n wuffs_base__image_config* c) {\n return c ? ((wuffs_base__rect_ie_u32){\n .min_incl_x = 0,\n " +
" .min_incl_y = 0,\n .max_excl_x = c->private_impl.width,\n .max_excl_y = c->private_impl.height,\n })\n : ((wuffs_base__rect_ie_u32){});\n}\n\nstatic inline uint32_t wuffs_base__image_config__width(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.width : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__height(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.height : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__num_loops(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.num_loops : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__first_frame_is_opaque(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.first_frame_is_opaque : false;\n}\n\n// TODO: this is the right API for planar (not packed) pixbufs? Should it allow\n// decoding into a color model different from the format's intrinsic one? For\n// example, decoding a JPEG image straight to RGBA instead of to YCbCr?\nstatic inline size_t " +
"wuffs_base__image_config__pixbuf_size(\n wuffs_base__image_config* c) {\n if (c) {\n uint64_t wh =\n ((uint64_t)c->private_impl.width) * ((uint64_t)c->private_impl.height);\n // TODO: handle things other than 1 byte per pixel.\n return (size_t)wh;\n }\n return 0;\n}\n\n" +
"" +
"// --------\n\n// wuffs_base__animation_disposal encodes, for an animated image, how to\n// dispose of a frame after displaying it:\n// - None means to draw the next frame on top of this one.\n// - Restore Background means to clear the frame's dirty rectangle to \"the\n// background color\" (in practice, this means transparent black) before\n// drawing the next frame.\n// - Restore Previous means to undo the current frame, so that the next frame\n// is drawn on top of the previous one.\ntypedef uint8_t wuffs_base__animation_disposal;\n\n#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \\\n ((wuffs_base__animation_disposal)1)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \\\n ((wuffs_base__animation_disposal)2)\n\n" +
"" +
+9 -1
View File
@@ -978,6 +978,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -988,7 +989,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -1001,6 +1003,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1055,6 +1058,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+129 -107
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
@@ -1376,6 +1384,9 @@ typedef struct {
bool f_previous_lzw_decode_ended_abruptly;
bool f_previous_use_global_palette;
uint8_t f_background_color_index;
bool f_has_full_global_palette;
bool f_has_full_palette;
bool f_use_local_palette;
uint8_t f_interlace;
bool f_seen_num_loops;
uint32_t f_num_loops;
@@ -1401,6 +1412,7 @@ typedef struct {
struct {
uint32_t coro_susp_point;
uint32_t v_num_loops;
bool v_ffio;
} c_decode_config[1];
struct {
uint32_t coro_susp_point;
@@ -1447,19 +1459,17 @@ typedef struct {
} c_decode_gc[1];
struct {
uint32_t coro_susp_point;
uint8_t v_flags;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint32_t v_argb;
uint64_t scratch;
} c_decode_id_part0[1];
struct {
uint32_t coro_susp_point;
uint8_t v_flags;
bool v_use_local_palette;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint32_t v_argb;
uint8_t v_lw;
uint64_t v_block_size;
wuffs_base__status v_z;
uint64_t scratch;
} c_decode_id_part1[1];
} private_impl;
} wuffs_gif__decoder;
@@ -2250,12 +2260,15 @@ wuffs_base__status wuffs_gif__decoder__decode_config(
wuffs_base__status status = WUFFS_BASE__STATUS_OK;
uint32_t v_num_loops;
bool v_ffio;
uint32_t coro_susp_point =
self->private_impl.c_decode_config[0].coro_susp_point;
if (coro_susp_point) {
v_num_loops = self->private_impl.c_decode_config[0].v_num_loops;
v_ffio = self->private_impl.c_decode_config[0].v_ffio;
} else {
v_ffio = false;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -2283,9 +2296,16 @@ wuffs_base__status wuffs_gif__decoder__decode_config(
if (self->private_impl.f_seen_num_loops) {
v_num_loops = self->private_impl.f_num_loops;
}
v_ffio =
(!self->private_impl.f_gc_has_transparent_index &&
(self->private_impl.f_frame_rect_x0 == 0) &&
(self->private_impl.f_frame_rect_y0 == 0) &&
(self->private_impl.f_frame_rect_x1 == self->private_impl.f_width) &&
(self->private_impl.f_frame_rect_y1 == self->private_impl.f_height) &&
self->private_impl.f_has_full_palette);
wuffs_base__image_config__initialize(
a_dst, 570984584, 0, self->private_impl.f_width,
self->private_impl.f_height, v_num_loops);
self->private_impl.f_height, v_num_loops, v_ffio);
self->private_impl.f_call_sequence = 1;
goto ok;
@@ -2298,6 +2318,7 @@ wuffs_base__status wuffs_gif__decoder__decode_config(
suspend:
self->private_impl.c_decode_config[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode_config[0].v_num_loops = v_num_loops;
self->private_impl.c_decode_config[0].v_ffio = v_ffio;
goto exit;
exit:
@@ -2722,6 +2743,7 @@ static wuffs_base__status wuffs_gif__decoder__decode_lsd(
((uint8_t)(((v_argb >> 24) & 255)));
v_i += 1;
}
self->private_impl.f_has_full_global_palette = (v_i == 256);
while (v_i < 256) {
self->private_impl.f_palettes[0][((4 * v_i) + 0)] = 0;
self->private_impl.f_palettes[0][((4 * v_i) + 1)] = 0;
@@ -3321,6 +3343,11 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0(
wuffs_base__io_reader a_src) {
wuffs_base__status status = WUFFS_BASE__STATUS_OK;
uint8_t v_flags;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint32_t v_argb;
uint8_t* ioptr_src = NULL;
uint8_t* iobounds0orig_src = NULL;
uint8_t* iobounds1_src = NULL;
@@ -3340,6 +3367,11 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0(
uint32_t coro_susp_point =
self->private_impl.c_decode_id_part0[0].coro_susp_point;
if (coro_susp_point) {
v_flags = self->private_impl.c_decode_id_part0[0].v_flags;
v_num_palette_entries =
self->private_impl.c_decode_id_part0[0].v_num_palette_entries;
v_i = self->private_impl.c_decode_id_part0[0].v_i;
v_argb = self->private_impl.c_decode_id_part0[0].v_argb;
} else {
}
switch (coro_susp_point) {
@@ -3467,6 +3499,74 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0(
self->private_impl.f_height = wuffs_base__u32__max(
self->private_impl.f_height, self->private_impl.f_frame_rect_y1);
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) {
goto short_read_src;
}
uint8_t t_8 = *ioptr_src++;
v_flags = t_8;
}
if ((v_flags & 64) != 0) {
self->private_impl.f_interlace = 4;
} else {
self->private_impl.f_interlace = 0;
}
self->private_impl.f_has_full_palette =
self->private_impl.f_has_full_global_palette;
self->private_impl.f_use_local_palette = ((v_flags & 128) != 0);
if (self->private_impl.f_use_local_palette) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_flags & 7)));
v_i = 0;
while (v_i < v_num_palette_entries) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
uint32_t t_10;
if (WUFFS_BASE__LIKELY(iobounds1_src - ioptr_src >= 3)) {
t_10 = wuffs_base__load_u24be(ioptr_src);
ioptr_src += 3;
} else {
self->private_impl.c_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
while (true) {
if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) {
goto short_read_src;
}
uint64_t* scratch =
&self->private_impl.c_decode_id_part0[0].scratch;
uint32_t t_9 = *scratch & 0xFF;
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*ioptr_src++)) << (56 - t_9);
if (t_9 == 16) {
t_10 = *scratch >> (64 - 24);
break;
}
t_9 += 8;
*scratch |= ((uint64_t)(t_9));
}
}
v_argb = (t_10 | 4278190080);
}
self->private_impl.f_palettes[1][((4 * v_i) + 0)] =
((uint8_t)(((v_argb >> 0) & 255)));
self->private_impl.f_palettes[1][((4 * v_i) + 1)] =
((uint8_t)(((v_argb >> 8) & 255)));
self->private_impl.f_palettes[1][((4 * v_i) + 2)] =
((uint8_t)(((v_argb >> 16) & 255)));
self->private_impl.f_palettes[1][((4 * v_i) + 3)] =
((uint8_t)(((v_argb >> 24) & 255)));
v_i += 1;
}
self->private_impl.f_has_full_palette = (v_i == 256);
while (v_i < 256) {
self->private_impl.f_palettes[1][((4 * v_i) + 0)] = 0;
self->private_impl.f_palettes[1][((4 * v_i) + 1)] = 0;
self->private_impl.f_palettes[1][((4 * v_i) + 2)] = 0;
self->private_impl.f_palettes[1][((4 * v_i) + 3)] = 0;
v_i += 1;
}
}
goto ok;
ok:
@@ -3477,6 +3577,11 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0(
goto suspend;
suspend:
self->private_impl.c_decode_id_part0[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode_id_part0[0].v_flags = v_flags;
self->private_impl.c_decode_id_part0[0].v_num_palette_entries =
v_num_palette_entries;
self->private_impl.c_decode_id_part0[0].v_i = v_i;
self->private_impl.c_decode_id_part0[0].v_argb = v_argb;
goto exit;
exit:
@@ -3503,11 +3608,6 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
wuffs_base__io_reader a_src) {
wuffs_base__status status = WUFFS_BASE__STATUS_OK;
uint8_t v_flags;
bool v_use_local_palette;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint32_t v_argb;
uint8_t v_lw;
uint64_t v_block_size;
wuffs_base__io_writer v_w;
@@ -3539,93 +3639,20 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
uint32_t coro_susp_point =
self->private_impl.c_decode_id_part1[0].coro_susp_point;
if (coro_susp_point) {
v_flags = self->private_impl.c_decode_id_part1[0].v_flags;
v_use_local_palette =
self->private_impl.c_decode_id_part1[0].v_use_local_palette;
v_num_palette_entries =
self->private_impl.c_decode_id_part1[0].v_num_palette_entries;
v_i = self->private_impl.c_decode_id_part1[0].v_i;
v_argb = self->private_impl.c_decode_id_part1[0].v_argb;
v_lw = self->private_impl.c_decode_id_part1[0].v_lw;
v_block_size = self->private_impl.c_decode_id_part1[0].v_block_size;
v_w = ((wuffs_base__io_writer){});
v_z = self->private_impl.c_decode_id_part1[0].v_z;
v_palette = ((wuffs_base__slice_u8){});
} else {
v_use_local_palette = false;
v_w = ((wuffs_base__io_writer){});
v_palette = ((wuffs_base__slice_u8){});
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) {
goto short_read_src;
}
uint8_t t_0 = *ioptr_src++;
v_flags = t_0;
}
if ((v_flags & 64) != 0) {
self->private_impl.f_interlace = 4;
} else {
self->private_impl.f_interlace = 0;
}
v_use_local_palette = ((v_flags & 128) != 0);
if (v_use_local_palette) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_flags & 7)));
v_i = 0;
while (v_i < v_num_palette_entries) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
uint32_t t_2;
if (WUFFS_BASE__LIKELY(iobounds1_src - ioptr_src >= 3)) {
t_2 = wuffs_base__load_u24be(ioptr_src);
ioptr_src += 3;
} else {
self->private_impl.c_decode_id_part1[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
while (true) {
if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) {
goto short_read_src;
}
uint64_t* scratch =
&self->private_impl.c_decode_id_part1[0].scratch;
uint32_t t_1 = *scratch & 0xFF;
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*ioptr_src++)) << (56 - t_1);
if (t_1 == 16) {
t_2 = *scratch >> (64 - 24);
break;
}
t_1 += 8;
*scratch |= ((uint64_t)(t_1));
}
}
v_argb = (t_2 | 4278190080);
}
self->private_impl.f_palettes[1][((4 * v_i) + 0)] =
((uint8_t)(((v_argb >> 0) & 255)));
self->private_impl.f_palettes[1][((4 * v_i) + 1)] =
((uint8_t)(((v_argb >> 8) & 255)));
self->private_impl.f_palettes[1][((4 * v_i) + 2)] =
((uint8_t)(((v_argb >> 16) & 255)));
self->private_impl.f_palettes[1][((4 * v_i) + 3)] =
((uint8_t)(((v_argb >> 24) & 255)));
v_i += 1;
}
while (v_i < 256) {
self->private_impl.f_palettes[1][((4 * v_i) + 0)] = 0;
self->private_impl.f_palettes[1][((4 * v_i) + 1)] = 0;
self->private_impl.f_palettes[1][((4 * v_i) + 2)] = 0;
self->private_impl.f_palettes[1][((4 * v_i) + 3)] = 0;
v_i += 1;
}
}
if (self->private_impl.f_gc_has_transparent_index) {
if (!v_use_local_palette) {
if (!self->private_impl.f_use_local_palette) {
wuffs_base__slice_u8__copy_from_slice(
((wuffs_base__slice_u8){.ptr = self->private_impl.f_palettes[1],
.len = 1024}),
@@ -3653,12 +3680,12 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
wuffs_base__return_empty_struct());
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) {
goto short_read_src;
}
uint8_t t_3 = *ioptr_src++;
v_lw = t_3;
uint8_t t_0 = *ioptr_src++;
v_lw = t_0;
}
if ((v_lw < 2) || (8 < v_lw)) {
status = WUFFS_GIF__ERROR_BAD_LITERAL_WIDTH;
@@ -3669,12 +3696,12 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
while (true) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) {
goto short_read_src;
}
uint8_t t_4 = *ioptr_src++;
v_block_size = ((uint64_t)(t_4));
uint8_t t_1 = *ioptr_src++;
v_block_size = ((uint64_t)(t_1));
}
if (v_block_size == 0) {
goto label_0_break;
@@ -3702,14 +3729,14 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
a_src.private_impl.buf->ri =
ioptr_src - a_src.private_impl.buf->ptr;
}
wuffs_base__status t_5 = wuffs_lzw__decoder__decode(
wuffs_base__status t_2 = wuffs_lzw__decoder__decode(
&self->private_impl.f_lzw, v_w, a_src);
ioptr_w = u_w.ptr + u_w.wi;
if (a_src.private_impl.buf) {
ioptr_src =
a_src.private_impl.buf->ptr + a_src.private_impl.buf->ri;
}
v_z = t_5;
v_z = t_2;
}
self->private_impl.f_uncompressed_wi =
(4096 - ((uint32_t)(wuffs_base__u64__min(
@@ -3728,7 +3755,7 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
a_src = o_0_a_src;
}
if ((v_z == 0) || (v_z == WUFFS_BASE__SUSPENSION_SHORT_WRITE)) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst);
if (status) {
goto suspend;
@@ -3743,21 +3770,22 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
goto label_1_break;
}
status = v_z;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
}
label_1_break:;
}
label_0_break:;
if (self->private_impl.f_uncompressed_ri !=
self->private_impl.f_uncompressed_wi) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
status = wuffs_gif__decoder__copy_to_image_buffer(self, a_dst);
if (status) {
goto suspend;
}
}
v_palette = ((wuffs_base__slice_u8){});
if (v_use_local_palette || self->private_impl.f_gc_has_transparent_index) {
if (self->private_impl.f_use_local_palette ||
self->private_impl.f_gc_has_transparent_index) {
v_palette = ((wuffs_base__slice_u8){
.ptr = self->private_impl.f_palettes[1], .len = 1024});
} else if (!self->private_impl.f_previous_use_global_palette) {
@@ -3774,7 +3802,8 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
self->private_impl.f_gc_duration, true,
self->private_impl.f_gc_disposal, v_palette);
self->private_impl.f_previous_use_global_palette =
!(v_use_local_palette || self->private_impl.f_gc_has_transparent_index);
!(self->private_impl.f_use_local_palette ||
self->private_impl.f_gc_has_transparent_index);
self->private_impl.f_seen_graphic_control = false;
self->private_impl.f_gc_has_transparent_index = false;
self->private_impl.f_gc_transparent_index = 0;
@@ -3790,13 +3819,6 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1(
goto suspend;
suspend:
self->private_impl.c_decode_id_part1[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode_id_part1[0].v_flags = v_flags;
self->private_impl.c_decode_id_part1[0].v_use_local_palette =
v_use_local_palette;
self->private_impl.c_decode_id_part1[0].v_num_palette_entries =
v_num_palette_entries;
self->private_impl.c_decode_id_part1[0].v_i = v_i;
self->private_impl.c_decode_id_part1[0].v_argb = v_argb;
self->private_impl.c_decode_id_part1[0].v_lw = v_lw;
self->private_impl.c_decode_id_part1[0].v_block_size = v_block_size;
self->private_impl.c_decode_id_part1[0].v_z = v_z;
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+17 -7
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
@@ -1376,6 +1384,9 @@ typedef struct {
bool f_previous_lzw_decode_ended_abruptly;
bool f_previous_use_global_palette;
uint8_t f_background_color_index;
bool f_has_full_global_palette;
bool f_has_full_palette;
bool f_use_local_palette;
uint8_t f_interlace;
bool f_seen_num_loops;
uint32_t f_num_loops;
@@ -1401,6 +1412,7 @@ typedef struct {
struct {
uint32_t coro_susp_point;
uint32_t v_num_loops;
bool v_ffio;
} c_decode_config[1];
struct {
uint32_t coro_susp_point;
@@ -1447,19 +1459,17 @@ typedef struct {
} c_decode_gc[1];
struct {
uint32_t coro_susp_point;
uint8_t v_flags;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint32_t v_argb;
uint64_t scratch;
} c_decode_id_part0[1];
struct {
uint32_t coro_susp_point;
uint8_t v_flags;
bool v_use_local_palette;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint32_t v_argb;
uint8_t v_lw;
uint64_t v_block_size;
wuffs_base__status v_z;
uint64_t scratch;
} c_decode_id_part1[1];
} private_impl;
} wuffs_gif__decoder;
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+9 -1
View File
@@ -967,6 +967,7 @@ typedef struct {
uint32_t width;
uint32_t height;
uint32_t num_loops;
bool first_frame_is_opaque;
} private_impl;
} wuffs_base__image_config;
@@ -977,7 +978,8 @@ static inline void wuffs_base__image_config__initialize(
wuffs_base__pixel_subsampling pixsub,
uint32_t width,
uint32_t height,
uint32_t num_loops) {
uint32_t num_loops,
bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -990,6 +992,7 @@ static inline void wuffs_base__image_config__initialize(
c->private_impl.width = width;
c->private_impl.height = height;
c->private_impl.num_loops = num_loops;
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
}
@@ -1044,6 +1047,11 @@ static inline uint32_t wuffs_base__image_config__num_loops(
return c ? c->private_impl.num_loops : 0;
}
static inline uint32_t wuffs_base__image_config__first_frame_is_opaque(
wuffs_base__image_config* c) {
return c ? c->private_impl.first_frame_is_opaque : false;
}
// TODO: this is the right API for planar (not packed) pixbufs? Should it allow
// decoding into a color model different from the format's intrinsic one? For
// example, decoding a JPEG image straight to RGBA instead of to YCbCr?
+2 -1
View File
@@ -135,7 +135,8 @@ var Funcs = []string{
// ---- image_config
"image_config.initialize!(pixfmt u32, pixsub u32, width u32, height u32, num_loops u32)()",
"image_config.initialize!(pixfmt u32, pixsub u32, width u32, height u32, " +
"num_loops u32, first_frame_is_opaque bool)()",
// ---- io_reader
+23 -8
View File
@@ -64,6 +64,10 @@ pub struct decoder?(
background_color_index base.u8,
has_full_global_palette base.bool,
has_full_palette base.bool,
use_local_palette base.bool,
// interlace indexes the interlace_start and interlace_delta arrays.
interlace base.u8[..4],
@@ -117,12 +121,19 @@ pub func decoder.decode_config?(dst ptr base.image_config, src base.io_reader)()
num_loops = this.num_loops
}
var ffio base.bool = (not this.gc_has_transparent_index) and
(this.frame_rect_x0 == 0) and
(this.frame_rect_y0 == 0) and
(this.frame_rect_x1 == this.width) and
(this.frame_rect_y1 == this.height) and
(this.has_full_palette)
// TODO: rename initialize to set?
//
// TODO: a Wuffs (not just C) name for the
// WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED magic pixfmt constant.
in.dst.initialize!(pixfmt:0x22088888, pixsub:0,
width:this.width, height:this.height, num_loops:num_loops)
width:this.width, height:this.height, num_loops:num_loops, first_frame_is_opaque:ffio)
this.call_sequence = 1
}
@@ -225,6 +236,7 @@ pri func decoder.decode_lsd?(src base.io_reader)() {
this.palettes[0][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
i += 1
}
this.has_full_global_palette = i == 256
// Set the remaining palette entries to transparent black.
while i < 256 {
this.palettes[0][(4 * i) + 0] = 0x00
@@ -409,9 +421,7 @@ pri func decoder.decode_id_part0?(src base.io_reader)() {
this.width = this.width.max(x:this.frame_rect_x1)
this.height = this.height.max(x:this.frame_rect_y1)
}
}
pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)() {
var flags base.u8 = in.src.read_u8?()
if (flags & 0x40) != 0 {
this.interlace = 4
@@ -419,9 +429,11 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
this.interlace = 0
}
this.has_full_palette = this.has_full_global_palette
// Read the optional Local Color Table.
var use_local_palette base.bool = (flags & 0x80) != 0
if use_local_palette {
this.use_local_palette = (flags & 0x80) != 0
if this.use_local_palette {
var num_palette_entries base.u32[..256] = (1 as base.u32) << (1 + (flags & 0x07))
var i base.u32
while i < num_palette_entries {
@@ -435,6 +447,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
this.palettes[1][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
i += 1
}
this.has_full_palette = i == 256
// Set the remaining palette entries to transparent black.
while i < 256 {
this.palettes[1][(4 * i) + 0] = 0x00
@@ -444,9 +457,11 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
i += 1
}
}
}
pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)() {
if this.gc_has_transparent_index {
if not use_local_palette {
if not this.use_local_palette {
this.palettes[1][:].copy_from_slice(s:this.palettes[0][:])
}
@@ -531,7 +546,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
// TODO: check for "not enough pixel data".
var palette slice base.u8
if use_local_palette or this.gc_has_transparent_index {
if this.use_local_palette or this.gc_has_transparent_index {
palette = this.palettes[1][:]
} else if not this.previous_use_global_palette {
// This frame uses the global palette but the previous one didn't.
@@ -547,7 +562,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
max_excl_y:this.frame_rect_y1),
duration:this.gc_duration, blend:true, disposal:this.gc_disposal, palette:palette)
this.previous_use_global_palette = not (use_local_palette or this.gc_has_transparent_index)
this.previous_use_global_palette = not (this.use_local_palette or this.gc_has_transparent_index)
// The Image Descriptor is mandatory, but the Graphic Control extension is
// optional. Reset the GC related fields for the next decode_frame call.
+5 -1
View File
@@ -266,7 +266,7 @@ bool do_test_wuffs_gif_decode(const char* filename,
return false;
}
// bricks-dither.gif is a 160 × 120 still (not animated) GIF.
// bricks-dither.gif is a 160 × 120, opaque, still (not animated) GIF.
if (wuffs_base__image_config__width(&ic) != 160) {
FAIL("width: got %" PRIu32 ", want 160",
wuffs_base__image_config__width(&ic));
@@ -282,6 +282,10 @@ bool do_test_wuffs_gif_decode(const char* filename,
wuffs_base__image_config__num_loops(&ic));
return false;
}
if (!wuffs_base__image_config__first_frame_is_opaque(&ic)) {
FAIL("first_frame_is_opaque: got false, want true");
return false;
}
status = wuffs_base__image_buffer__set_from_slice(
&ib, ic,
((wuffs_base__slice_u8){