mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
1 parent
0854344580
commit
744fbdd732
3 files changed
+454
-42
No files matched your search
@@ -9311,6 +9311,7 @@ struct wuffs_png__decoder__struct {
|
|||||||
bool f_seen_plte;
|
bool f_seen_plte;
|
||||||
bool f_seen_srgb;
|
bool f_seen_srgb;
|
||||||
bool f_seen_trns;
|
bool f_seen_trns;
|
||||||
|
bool f_zlib_is_dirty;
|
||||||
uint32_t f_dst_pixfmt;
|
uint32_t f_dst_pixfmt;
|
||||||
uint32_t f_src_pixfmt;
|
uint32_t f_src_pixfmt;
|
||||||
uint32_t f_chunk_type;
|
uint32_t f_chunk_type;
|
||||||
@@ -9340,12 +9341,14 @@ struct wuffs_png__decoder__struct {
|
|||||||
uint32_t p_decode_other_chunk[1];
|
uint32_t p_decode_other_chunk[1];
|
||||||
uint32_t p_decode_chrm[1];
|
uint32_t p_decode_chrm[1];
|
||||||
uint32_t p_decode_gama[1];
|
uint32_t p_decode_gama[1];
|
||||||
|
uint32_t p_decode_iccp[1];
|
||||||
uint32_t p_decode_plte[1];
|
uint32_t p_decode_plte[1];
|
||||||
uint32_t p_decode_srgb[1];
|
uint32_t p_decode_srgb[1];
|
||||||
uint32_t p_decode_trns[1];
|
uint32_t p_decode_trns[1];
|
||||||
uint32_t p_decode_frame_config[1];
|
uint32_t p_decode_frame_config[1];
|
||||||
uint32_t p_decode_frame[1];
|
uint32_t p_decode_frame[1];
|
||||||
uint32_t p_decode_pass[1];
|
uint32_t p_decode_pass[1];
|
||||||
|
uint32_t p_tell_me_more[1];
|
||||||
wuffs_base__status (*choosy_filter_and_swizzle)(
|
wuffs_base__status (*choosy_filter_and_swizzle)(
|
||||||
wuffs_png__decoder* self,
|
wuffs_png__decoder* self,
|
||||||
wuffs_base__pixel_buffer* a_dst,
|
wuffs_base__pixel_buffer* a_dst,
|
||||||
@@ -9387,6 +9390,9 @@ struct wuffs_png__decoder__struct {
|
|||||||
uint32_t v_checksum_have;
|
uint32_t v_checksum_have;
|
||||||
uint64_t scratch;
|
uint64_t scratch;
|
||||||
} s_decode_pass[1];
|
} s_decode_pass[1];
|
||||||
|
struct {
|
||||||
|
uint64_t scratch;
|
||||||
|
} s_tell_me_more[1];
|
||||||
} private_data;
|
} private_data;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -35448,6 +35454,11 @@ wuffs_png__decoder__decode_gama(
|
|||||||
wuffs_png__decoder* self,
|
wuffs_png__decoder* self,
|
||||||
wuffs_base__io_buffer* a_src);
|
wuffs_base__io_buffer* a_src);
|
||||||
|
|
||||||
|
static wuffs_base__status
|
||||||
|
wuffs_png__decoder__decode_iccp(
|
||||||
|
wuffs_png__decoder* self,
|
||||||
|
wuffs_base__io_buffer* a_src);
|
||||||
|
|
||||||
static wuffs_base__status
|
static wuffs_base__status
|
||||||
wuffs_png__decoder__decode_plte(
|
wuffs_png__decoder__decode_plte(
|
||||||
wuffs_png__decoder* self,
|
wuffs_png__decoder* self,
|
||||||
@@ -37312,6 +37323,11 @@ wuffs_png__decoder__decode_image_config(
|
|||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
|
||||||
}
|
}
|
||||||
label__2__break:;
|
label__2__break:;
|
||||||
|
if (self->private_impl.f_metadata_fourcc != 0) {
|
||||||
|
self->private_impl.f_call_sequence = 1;
|
||||||
|
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||||
uint32_t t_7;
|
uint32_t t_7;
|
||||||
@@ -37345,11 +37361,6 @@ wuffs_png__decoder__decode_image_config(
|
|||||||
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
|
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (self->private_impl.f_metadata_fourcc != 0) {
|
|
||||||
self->private_impl.f_call_sequence = 1;
|
|
||||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
label__1__break:;
|
label__1__break:;
|
||||||
if ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte) {
|
if ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte) {
|
||||||
@@ -37809,6 +37820,23 @@ wuffs_png__decoder__decode_other_chunk(
|
|||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
self->private_impl.f_seen_gama = true;
|
self->private_impl.f_seen_gama = true;
|
||||||
|
} else if ((self->private_impl.f_chunk_type == 1346585449) && self->private_impl.f_report_metadata_iccp) {
|
||||||
|
if (self->private_impl.f_seen_iccp) {
|
||||||
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (a_src) {
|
||||||
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
|
}
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||||
|
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||||
|
if (a_src) {
|
||||||
|
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||||
|
}
|
||||||
|
if (status.repr) {
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
self->private_impl.f_seen_iccp = true;
|
||||||
} else if ((self->private_impl.f_chunk_type == 1111970419) && self->private_impl.f_report_metadata_srgb) {
|
} else if ((self->private_impl.f_chunk_type == 1111970419) && self->private_impl.f_report_metadata_srgb) {
|
||||||
if (self->private_impl.f_seen_srgb) {
|
if (self->private_impl.f_seen_srgb) {
|
||||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
@@ -37817,7 +37845,7 @@ wuffs_png__decoder__decode_other_chunk(
|
|||||||
if (a_src) {
|
if (a_src) {
|
||||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
}
|
}
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||||
if (a_src) {
|
if (a_src) {
|
||||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||||
@@ -37834,7 +37862,7 @@ wuffs_png__decoder__decode_other_chunk(
|
|||||||
if (a_src) {
|
if (a_src) {
|
||||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
}
|
}
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||||
if (a_src) {
|
if (a_src) {
|
||||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||||
@@ -37845,7 +37873,7 @@ wuffs_png__decoder__decode_other_chunk(
|
|||||||
self->private_impl.f_seen_trns = true;
|
self->private_impl.f_seen_trns = true;
|
||||||
} else {
|
} else {
|
||||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||||
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||||
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||||
iop_a_src = io2_a_src;
|
iop_a_src = io2_a_src;
|
||||||
@@ -37903,6 +37931,7 @@ wuffs_png__decoder__decode_chrm(
|
|||||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
self->private_impl.f_chunk_length = 0;
|
||||||
self->private_impl.f_metadata_flavor = 5;
|
self->private_impl.f_metadata_flavor = 5;
|
||||||
self->private_impl.f_metadata_fourcc = 1128813133;
|
self->private_impl.f_metadata_fourcc = 1128813133;
|
||||||
self->private_impl.f_metadata_x = 0;
|
self->private_impl.f_metadata_x = 0;
|
||||||
@@ -38197,6 +38226,7 @@ wuffs_png__decoder__decode_gama(
|
|||||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
self->private_impl.f_chunk_length = 0;
|
||||||
self->private_impl.f_metadata_flavor = 5;
|
self->private_impl.f_metadata_flavor = 5;
|
||||||
self->private_impl.f_metadata_fourcc = 1195461953;
|
self->private_impl.f_metadata_fourcc = 1195461953;
|
||||||
{
|
{
|
||||||
@@ -38250,6 +38280,94 @@ wuffs_png__decoder__decode_gama(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------- func png.decoder.decode_iccp
|
||||||
|
|
||||||
|
static wuffs_base__status
|
||||||
|
wuffs_png__decoder__decode_iccp(
|
||||||
|
wuffs_png__decoder* self,
|
||||||
|
wuffs_base__io_buffer* a_src) {
|
||||||
|
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||||
|
|
||||||
|
uint8_t v_c = 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;
|
||||||
|
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||||
|
if (a_src) {
|
||||||
|
io0_a_src = a_src->data.ptr;
|
||||||
|
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||||
|
iop_a_src = io1_a_src;
|
||||||
|
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t coro_susp_point = self->private_impl.p_decode_iccp[0];
|
||||||
|
switch (coro_susp_point) {
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (self->private_impl.f_chunk_length <= 0) {
|
||||||
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
self->private_impl.f_chunk_length -= 1;
|
||||||
|
{
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||||
|
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
uint8_t t_0 = *iop_a_src++;
|
||||||
|
v_c = t_0;
|
||||||
|
}
|
||||||
|
if (v_c == 0) {
|
||||||
|
goto label__0__break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
label__0__break:;
|
||||||
|
if (self->private_impl.f_chunk_length <= 0) {
|
||||||
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
self->private_impl.f_chunk_length -= 1;
|
||||||
|
{
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||||
|
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
uint8_t t_1 = *iop_a_src++;
|
||||||
|
v_c = t_1;
|
||||||
|
}
|
||||||
|
if (v_c != 0) {
|
||||||
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
self->private_impl.f_metadata_flavor = 4;
|
||||||
|
self->private_impl.f_metadata_fourcc = 1229144912;
|
||||||
|
self->private_impl.f_metadata_x = 0;
|
||||||
|
self->private_impl.f_metadata_y = 0;
|
||||||
|
self->private_impl.f_metadata_z = 0;
|
||||||
|
|
||||||
|
goto ok;
|
||||||
|
ok:
|
||||||
|
self->private_impl.p_decode_iccp[0] = 0;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto suspend;
|
||||||
|
suspend:
|
||||||
|
self->private_impl.p_decode_iccp[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||||
|
|
||||||
|
goto exit;
|
||||||
|
exit:
|
||||||
|
if (a_src) {
|
||||||
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
// -------- func png.decoder.decode_plte
|
// -------- func png.decoder.decode_plte
|
||||||
|
|
||||||
static wuffs_base__status
|
static wuffs_base__status
|
||||||
@@ -38379,6 +38497,7 @@ wuffs_png__decoder__decode_srgb(
|
|||||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
self->private_impl.f_chunk_length = 0;
|
||||||
self->private_impl.f_metadata_flavor = 5;
|
self->private_impl.f_metadata_flavor = 5;
|
||||||
self->private_impl.f_metadata_fourcc = 1397901122;
|
self->private_impl.f_metadata_fourcc = 1397901122;
|
||||||
{
|
{
|
||||||
@@ -38653,6 +38772,13 @@ wuffs_png__decoder__decode_frame(
|
|||||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
|
if (self->private_impl.f_zlib_is_dirty) {
|
||||||
|
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib, sizeof (wuffs_zlib__decoder), WUFFS_VERSION, 0));
|
||||||
|
if (self->private_impl.f_ignore_checksum) {
|
||||||
|
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self->private_impl.f_zlib_is_dirty = true;
|
||||||
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_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
|
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
|
||||||
@@ -39187,34 +39313,131 @@ wuffs_png__decoder__tell_me_more(
|
|||||||
self->private_impl.active_coroutine = 0;
|
self->private_impl.active_coroutine = 0;
|
||||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||||
|
|
||||||
if (self->private_impl.f_call_sequence != 1) {
|
uint64_t v_r_mark = 0;
|
||||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL);
|
||||||
goto exit;
|
|
||||||
|
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;
|
||||||
|
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||||
|
if (a_src) {
|
||||||
|
io0_a_src = a_src->data.ptr;
|
||||||
|
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||||
|
iop_a_src = io1_a_src;
|
||||||
|
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||||
}
|
}
|
||||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
|
||||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
|
||||||
|
switch (coro_susp_point) {
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
|
|
||||||
|
if (self->private_impl.f_call_sequence != 1) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (self->private_impl.f_metadata_flavor == 4) {
|
||||||
|
if (self->private_impl.f_zlib_is_dirty) {
|
||||||
|
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib, sizeof (wuffs_zlib__decoder), WUFFS_VERSION, 0));
|
||||||
|
if (self->private_impl.f_ignore_checksum) {
|
||||||
|
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self->private_impl.f_zlib_is_dirty = true;
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
if (a_minfo != NULL) {
|
||||||
|
wuffs_base__more_information__set(a_minfo,
|
||||||
|
self->private_impl.f_metadata_flavor,
|
||||||
|
self->private_impl.f_metadata_fourcc,
|
||||||
|
self->private_impl.f_metadata_x,
|
||||||
|
self->private_impl.f_metadata_y,
|
||||||
|
self->private_impl.f_metadata_z);
|
||||||
|
}
|
||||||
|
if (self->private_impl.f_metadata_flavor != 4) {
|
||||||
|
goto label__0__break;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||||
|
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||||
|
self->private_impl.f_chunk_length);
|
||||||
|
if (a_src) {
|
||||||
|
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||||
|
}
|
||||||
|
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||||
|
{
|
||||||
|
if (a_src) {
|
||||||
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
|
}
|
||||||
|
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||||
|
v_zlib_status = t_0;
|
||||||
|
if (a_src) {
|
||||||
|
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wuffs_base__u64__sat_sub_indirect(&self->private_impl.f_chunk_length, wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))));
|
||||||
|
io2_a_src = o_0_io2_a_src;
|
||||||
|
if (a_src) {
|
||||||
|
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||||
|
goto label__0__break;
|
||||||
|
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||||
|
status = v_zlib_status;
|
||||||
|
if (wuffs_base__status__is_error(&status)) {
|
||||||
|
goto exit;
|
||||||
|
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
|
status = v_zlib_status;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||||
|
}
|
||||||
|
label__0__break:;
|
||||||
|
if (self->private_impl.f_chunk_length != 0) {
|
||||||
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||||
|
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||||
|
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||||
|
iop_a_src = io2_a_src;
|
||||||
|
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
|
||||||
|
self->private_impl.f_call_sequence = 2;
|
||||||
|
self->private_impl.f_metadata_flavor = 0;
|
||||||
|
self->private_impl.f_metadata_fourcc = 0;
|
||||||
|
self->private_impl.f_metadata_x = 0;
|
||||||
|
self->private_impl.f_metadata_y = 0;
|
||||||
|
self->private_impl.f_metadata_z = 0;
|
||||||
|
status = wuffs_base__make_status(NULL);
|
||||||
|
goto ok;
|
||||||
|
|
||||||
|
ok:
|
||||||
|
self->private_impl.p_tell_me_more[0] = 0;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
|
||||||
if (a_minfo != NULL) {
|
|
||||||
wuffs_base__more_information__set(a_minfo,
|
|
||||||
self->private_impl.f_metadata_flavor,
|
|
||||||
self->private_impl.f_metadata_fourcc,
|
|
||||||
self->private_impl.f_metadata_x,
|
|
||||||
self->private_impl.f_metadata_y,
|
|
||||||
self->private_impl.f_metadata_z);
|
|
||||||
}
|
}
|
||||||
self->private_impl.f_call_sequence = 2;
|
|
||||||
self->private_impl.f_metadata_flavor = 0;
|
goto suspend;
|
||||||
self->private_impl.f_metadata_fourcc = 0;
|
suspend:
|
||||||
self->private_impl.f_metadata_x = 0;
|
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||||
self->private_impl.f_metadata_y = 0;
|
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
|
||||||
self->private_impl.f_metadata_z = 0;
|
|
||||||
status = wuffs_base__make_status(NULL);
|
|
||||||
goto ok;
|
|
||||||
|
|
||||||
ok:
|
|
||||||
goto exit;
|
goto exit;
|
||||||
exit:
|
exit:
|
||||||
|
if (a_src) {
|
||||||
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
|
}
|
||||||
|
|
||||||
if (wuffs_base__status__is_error(&status)) {
|
if (wuffs_base__status__is_error(&status)) {
|
||||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||||
}
|
}
|
||||||
|
|||||||
+109
-12
@@ -96,6 +96,8 @@ pub struct decoder? implements base.image_decoder(
|
|||||||
seen_srgb : base.bool,
|
seen_srgb : base.bool,
|
||||||
seen_trns : base.bool,
|
seen_trns : base.bool,
|
||||||
|
|
||||||
|
zlib_is_dirty : base.bool,
|
||||||
|
|
||||||
dst_pixfmt : base.u32,
|
dst_pixfmt : base.u32,
|
||||||
src_pixfmt : base.u32,
|
src_pixfmt : base.u32,
|
||||||
|
|
||||||
@@ -214,16 +216,19 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
|||||||
}
|
}
|
||||||
yield? status
|
yield? status
|
||||||
} endwhile
|
} endwhile
|
||||||
|
|
||||||
|
// If we have metadata, delay reading (skipping) the ancillary chunk's
|
||||||
|
// CRC-32 checksum until the end of tell_me_more.
|
||||||
|
if this.metadata_fourcc <> 0 {
|
||||||
|
this.call_sequence = 1
|
||||||
|
return base."@metadata reported"
|
||||||
|
}
|
||||||
|
|
||||||
checksum_want = args.src.read_u32be?()
|
checksum_want = args.src.read_u32be?()
|
||||||
if (not this.ignore_checksum) and (this.chunk_type == 'PLTE'le) and
|
if (not this.ignore_checksum) and (this.chunk_type == 'PLTE'le) and
|
||||||
(checksum_have <> checksum_want) {
|
(checksum_have <> checksum_want) {
|
||||||
return "#bad checksum"
|
return "#bad checksum"
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.metadata_fourcc <> 0 {
|
|
||||||
this.call_sequence = 1
|
|
||||||
return base."@metadata reported"
|
|
||||||
}
|
|
||||||
} endwhile
|
} endwhile
|
||||||
|
|
||||||
if (this.color_type == 3) and (not this.seen_plte) {
|
if (this.color_type == 3) and (not this.seen_plte) {
|
||||||
@@ -448,6 +453,13 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
|||||||
this.decode_gama?(src: args.src)
|
this.decode_gama?(src: args.src)
|
||||||
this.seen_gama = true
|
this.seen_gama = true
|
||||||
|
|
||||||
|
} else if (this.chunk_type == 'iCCP'le) and this.report_metadata_iccp {
|
||||||
|
if this.seen_iccp {
|
||||||
|
return "#bad chunk"
|
||||||
|
}
|
||||||
|
this.decode_iccp?(src: args.src)
|
||||||
|
this.seen_iccp = true
|
||||||
|
|
||||||
} else if (this.chunk_type == 'sRGB'le) and this.report_metadata_srgb {
|
} else if (this.chunk_type == 'sRGB'le) and this.report_metadata_srgb {
|
||||||
if this.seen_srgb {
|
if this.seen_srgb {
|
||||||
return "#bad chunk"
|
return "#bad chunk"
|
||||||
@@ -474,6 +486,7 @@ pri func decoder.decode_chrm?(src: base.io_reader) {
|
|||||||
if this.chunk_length <> 32 {
|
if this.chunk_length <> 32 {
|
||||||
return "#bad chunk"
|
return "#bad chunk"
|
||||||
}
|
}
|
||||||
|
this.chunk_length = 0
|
||||||
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
|
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
|
||||||
this.metadata_fourcc = 'CHRM'be
|
this.metadata_fourcc = 'CHRM'be
|
||||||
this.metadata_x = 0
|
this.metadata_x = 0
|
||||||
@@ -508,6 +521,7 @@ pri func decoder.decode_gama?(src: base.io_reader) {
|
|||||||
if this.chunk_length <> 4 {
|
if this.chunk_length <> 4 {
|
||||||
return "#bad chunk"
|
return "#bad chunk"
|
||||||
}
|
}
|
||||||
|
this.chunk_length = 0
|
||||||
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
|
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
|
||||||
this.metadata_fourcc = 'GAMA'be
|
this.metadata_fourcc = 'GAMA'be
|
||||||
this.metadata_x = args.src.read_u32be_as_u64?()
|
this.metadata_x = args.src.read_u32be_as_u64?()
|
||||||
@@ -515,6 +529,38 @@ pri func decoder.decode_gama?(src: base.io_reader) {
|
|||||||
this.metadata_z = 0
|
this.metadata_z = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pri func decoder.decode_iccp?(src: base.io_reader) {
|
||||||
|
var c : base.u8
|
||||||
|
|
||||||
|
// Skip the NUL-terminated color profile name.
|
||||||
|
while true {
|
||||||
|
if this.chunk_length <= 0 {
|
||||||
|
return "#bad chunk"
|
||||||
|
}
|
||||||
|
this.chunk_length -= 1
|
||||||
|
c = args.src.read_u8?()
|
||||||
|
if c == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} endwhile
|
||||||
|
|
||||||
|
// The compression method byte must be zero.
|
||||||
|
if this.chunk_length <= 0 {
|
||||||
|
return "#bad chunk"
|
||||||
|
}
|
||||||
|
this.chunk_length -= 1
|
||||||
|
c = args.src.read_u8?()
|
||||||
|
if c <> 0 {
|
||||||
|
return "#bad chunk"
|
||||||
|
}
|
||||||
|
|
||||||
|
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM
|
||||||
|
this.metadata_fourcc = 'ICCP'be
|
||||||
|
this.metadata_x = 0
|
||||||
|
this.metadata_y = 0
|
||||||
|
this.metadata_z = 0
|
||||||
|
}
|
||||||
|
|
||||||
pri func decoder.decode_plte?(src: base.io_reader) {
|
pri func decoder.decode_plte?(src: base.io_reader) {
|
||||||
var num_entries : base.u32[..= 256]
|
var num_entries : base.u32[..= 256]
|
||||||
var i : base.u32
|
var i : base.u32
|
||||||
@@ -552,6 +598,7 @@ pri func decoder.decode_srgb?(src: base.io_reader) {
|
|||||||
if this.chunk_length <> 1 {
|
if this.chunk_length <> 1 {
|
||||||
return "#bad chunk"
|
return "#bad chunk"
|
||||||
}
|
}
|
||||||
|
this.chunk_length = 0
|
||||||
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
|
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
|
||||||
this.metadata_fourcc = 'SRGB'be
|
this.metadata_fourcc = 'SRGB'be
|
||||||
this.metadata_x = args.src.read_u8_as_u64?()
|
this.metadata_x = args.src.read_u8_as_u64?()
|
||||||
@@ -635,6 +682,14 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
|||||||
return base."@end of data"
|
return base."@end of data"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if this.zlib_is_dirty {
|
||||||
|
this.zlib.reset!()
|
||||||
|
if this.ignore_checksum {
|
||||||
|
this.zlib.set_quirk_enabled!(quirk: base.QUIRK_IGNORE_CHECKSUM, enabled: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.zlib_is_dirty = true
|
||||||
|
|
||||||
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_or_else(fallback: this.dst_palette[..]),
|
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
|
||||||
@@ -822,20 +877,62 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||||
|
var r_mark : base.u64
|
||||||
|
var zlib_status : base.status
|
||||||
|
|
||||||
if this.call_sequence <> 1 {
|
if this.call_sequence <> 1 {
|
||||||
return base."#bad call sequence"
|
return base."#bad call sequence"
|
||||||
}
|
}
|
||||||
if this.metadata_fourcc == 0 {
|
if this.metadata_fourcc == 0 {
|
||||||
return base."#no more information"
|
return base."#no more information"
|
||||||
}
|
}
|
||||||
if args.minfo <> nullptr {
|
|
||||||
args.minfo.set!(
|
if this.metadata_flavor == base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM {
|
||||||
flavor: this.metadata_flavor,
|
if this.zlib_is_dirty {
|
||||||
w: this.metadata_fourcc,
|
this.zlib.reset!()
|
||||||
x: this.metadata_x,
|
if this.ignore_checksum {
|
||||||
y: this.metadata_y,
|
this.zlib.set_quirk_enabled!(quirk: base.QUIRK_IGNORE_CHECKSUM, enabled: true)
|
||||||
z: this.metadata_z)
|
}
|
||||||
|
}
|
||||||
|
this.zlib_is_dirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while true {
|
||||||
|
if args.minfo <> nullptr {
|
||||||
|
args.minfo.set!(
|
||||||
|
flavor: this.metadata_flavor,
|
||||||
|
w: this.metadata_fourcc,
|
||||||
|
x: this.metadata_x,
|
||||||
|
y: this.metadata_y,
|
||||||
|
z: this.metadata_z)
|
||||||
|
}
|
||||||
|
|
||||||
|
if this.metadata_flavor <> base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
io_limit (io: args.src, limit: this.chunk_length) {
|
||||||
|
r_mark = args.src.mark()
|
||||||
|
zlib_status =? this.zlib.transform_io?(
|
||||||
|
dst: args.dst, src: args.src, workbuf: this.util.empty_slice_u8())
|
||||||
|
this.chunk_length ~sat-= args.src.count_since(mark: r_mark)
|
||||||
|
}
|
||||||
|
|
||||||
|
if zlib_status.is_ok() {
|
||||||
|
break
|
||||||
|
} else if not zlib_status.is_suspension() {
|
||||||
|
return zlib_status
|
||||||
|
}
|
||||||
|
yield? zlib_status
|
||||||
|
} endwhile
|
||||||
|
|
||||||
|
if this.chunk_length <> 0 {
|
||||||
|
return "#bad chunk"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip the ancillary chunk's CRC-32 checksum.
|
||||||
|
args.src.skip?(n: 4)
|
||||||
|
|
||||||
this.call_sequence = 2
|
this.call_sequence = 2
|
||||||
this.metadata_flavor = 0
|
this.metadata_flavor = 0
|
||||||
this.metadata_fourcc = 0
|
this.metadata_fourcc = 0
|
||||||
|
|||||||
@@ -560,6 +560,97 @@ test_wuffs_png_decode_metadata_chrm_gama_srgb() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* //
|
||||||
|
test_wuffs_png_decode_metadata_iccp() {
|
||||||
|
CHECK_FOCUS(__func__);
|
||||||
|
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||||
|
.data = g_have_slice_u8,
|
||||||
|
});
|
||||||
|
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||||
|
.data = g_want_slice_u8,
|
||||||
|
});
|
||||||
|
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||||
|
.data = g_src_slice_u8,
|
||||||
|
});
|
||||||
|
CHECK_STRING(read_file(&want, "test/data/DCI-P3-D65.icc"));
|
||||||
|
CHECK_STRING(read_file(
|
||||||
|
&src, "test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png"));
|
||||||
|
|
||||||
|
bool seen_iccp = false;
|
||||||
|
|
||||||
|
wuffs_png__decoder dec;
|
||||||
|
CHECK_STATUS("initialize",
|
||||||
|
wuffs_png__decoder__initialize(
|
||||||
|
&dec, sizeof dec, WUFFS_VERSION,
|
||||||
|
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||||
|
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__ICCP, true);
|
||||||
|
|
||||||
|
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
wuffs_base__status status =
|
||||||
|
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
|
||||||
|
if (wuffs_base__status__is_ok(&status)) {
|
||||||
|
break;
|
||||||
|
} else if (status.repr != wuffs_base__note__metadata_reported) {
|
||||||
|
RETURN_FAIL("decode_image_config: have \"%s\", want \"%s\"", status.repr,
|
||||||
|
wuffs_base__note__metadata_reported);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
|
||||||
|
wuffs_base__status status =
|
||||||
|
wuffs_png__decoder__tell_me_more(&dec, &have, &minfo, &src);
|
||||||
|
if (!wuffs_base__status__is_ok(&status)) {
|
||||||
|
RETURN_FAIL("tell_me_more: \"%s\"", status.repr);
|
||||||
|
} else if (minfo.flavor !=
|
||||||
|
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM) {
|
||||||
|
RETURN_FAIL(
|
||||||
|
"tell_me_more: flavor: have %" PRIu32 ", want %" PRIu32,
|
||||||
|
minfo.flavor,
|
||||||
|
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM);
|
||||||
|
} else if (wuffs_base__more_information__metadata__fourcc(&minfo) !=
|
||||||
|
WUFFS_BASE__FOURCC__ICCP) {
|
||||||
|
RETURN_FAIL("tell_me_more: fourcc: have %" PRIu32 ", want %" PRIu32,
|
||||||
|
wuffs_base__more_information__metadata__fourcc(&minfo),
|
||||||
|
WUFFS_BASE__FOURCC__ICCP);
|
||||||
|
}
|
||||||
|
CHECK_STRING(check_io_buffers_equal("", &have, &want));
|
||||||
|
seen_iccp = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!seen_iccp) {
|
||||||
|
RETURN_FAIL("seen_iccp: have %d, want %d", seen_iccp, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
uint64_t have = wuffs_base__image_config__first_frame_io_position(&ic);
|
||||||
|
uint64_t want = 431;
|
||||||
|
if (have != want) {
|
||||||
|
RETURN_FAIL("first_frame_io_position: have %" PRIu64 ", want %" PRIu64,
|
||||||
|
have, want);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
|
||||||
|
wuffs_base__status status =
|
||||||
|
wuffs_png__decoder__decode_frame_config(&dec, &fc, &src);
|
||||||
|
if (!wuffs_base__status__is_ok(&status)) {
|
||||||
|
RETURN_FAIL("decode_frame_config: %s", status.repr);
|
||||||
|
}
|
||||||
|
uint32_t have = wuffs_base__frame_config__width(&fc);
|
||||||
|
uint32_t want = 256;
|
||||||
|
if (have != want) {
|
||||||
|
RETURN_FAIL("decode_frame_config: width: have %" PRIu32 ", want %" PRIu32,
|
||||||
|
have, want);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------- Mimic Tests
|
// ---------------- Mimic Tests
|
||||||
|
|
||||||
#ifdef WUFFS_MIMIC
|
#ifdef WUFFS_MIMIC
|
||||||
@@ -890,6 +981,7 @@ proc g_tests[] = {
|
|||||||
test_wuffs_png_decode_frame_config,
|
test_wuffs_png_decode_frame_config,
|
||||||
test_wuffs_png_decode_interface,
|
test_wuffs_png_decode_interface,
|
||||||
test_wuffs_png_decode_metadata_chrm_gama_srgb,
|
test_wuffs_png_decode_metadata_chrm_gama_srgb,
|
||||||
|
test_wuffs_png_decode_metadata_iccp,
|
||||||
|
|
||||||
#ifdef WUFFS_MIMIC
|
#ifdef WUFFS_MIMIC
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user