mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
1 parent
3642d73714
commit
6737565c20
8 files changed
+708
-87
No files matched your search
@@ -386,6 +386,9 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_ICCP) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ struct DecodeImageArgFlags {
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, SRGB and XMP.
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
@@ -222,16 +222,19 @@ struct DecodeImageArgFlags {
|
||||
static constexpr uint64_t REPORT_METADATA_GAMA = 0x0008;
|
||||
// International Color Consortium Profile.
|
||||
static constexpr uint64_t REPORT_METADATA_ICCP = 0x0010;
|
||||
// Key-Value Pair.
|
||||
//
|
||||
// For PNG files, this includes iTXt, tEXt and zTXt chunks. In the
|
||||
// HandleMetadata callback, the raw argument contains UTF-8 strings.
|
||||
static constexpr uint64_t REPORT_METADATA_KVP = 0x0020;
|
||||
// Modification Time.
|
||||
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0020;
|
||||
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0040;
|
||||
// Offset (2-Dimensional).
|
||||
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0040;
|
||||
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0080;
|
||||
// Physical Dimensions.
|
||||
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0080;
|
||||
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0100;
|
||||
// Standard Red Green Blue (Rendering Intent).
|
||||
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0100;
|
||||
// Text.
|
||||
static constexpr uint64_t REPORT_METADATA_TEXT = 0x0200;
|
||||
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0200;
|
||||
// Extensible Metadata Platform.
|
||||
static constexpr uint64_t REPORT_METADATA_XMP = 0x0400;
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ var FourCCs = [...][2]string{
|
||||
{"JS ", "JavaScript"},
|
||||
{"JSON", "JavaScript Object Notation"},
|
||||
{"JWCC", "JSON With Commas and Comments"},
|
||||
{"KVP ", "Key-Value Pair"},
|
||||
{"KVPK", "Key-Value Pair (Key)"},
|
||||
{"KVPV", "Key-Value Pair (Value)"},
|
||||
{"LZ4 ", "Lempel–Ziv 4"},
|
||||
{"MD ", "Markdown"},
|
||||
{"MTIM", "Modification Time"},
|
||||
|
||||
@@ -641,6 +641,15 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// JSON With Commas and Comments.
|
||||
#define WUFFS_BASE__FOURCC__JWCC 0x4A574343
|
||||
|
||||
// Key-Value Pair.
|
||||
#define WUFFS_BASE__FOURCC__KVP 0x4B565020
|
||||
|
||||
// Key-Value Pair (Key).
|
||||
#define WUFFS_BASE__FOURCC__KVPK 0x4B56504B
|
||||
|
||||
// Key-Value Pair (Value).
|
||||
#define WUFFS_BASE__FOURCC__KVPV 0x4B565056
|
||||
|
||||
// Lempel–Ziv 4.
|
||||
#define WUFFS_BASE__FOURCC__LZ4 0x4C5A3420
|
||||
|
||||
@@ -9321,6 +9330,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_report_metadata_chrm;
|
||||
bool f_report_metadata_gama;
|
||||
bool f_report_metadata_iccp;
|
||||
bool f_report_metadata_kvp;
|
||||
bool f_report_metadata_srgb;
|
||||
bool f_ignore_checksum;
|
||||
uint8_t f_depth;
|
||||
@@ -9336,6 +9346,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_plte;
|
||||
bool f_seen_srgb;
|
||||
bool f_seen_trns;
|
||||
bool f_metadata_is_zlib_compressed;
|
||||
bool f_zlib_is_dirty;
|
||||
uint32_t f_chunk_type;
|
||||
uint8_t f_chunk_type_array[4];
|
||||
@@ -9458,6 +9469,7 @@ struct wuffs_png__decoder__struct {
|
||||
uint64_t scratch;
|
||||
} s_decode_pass[1];
|
||||
struct {
|
||||
uint8_t v_c;
|
||||
uint64_t scratch;
|
||||
} s_tell_me_more[1];
|
||||
} private_data;
|
||||
@@ -10350,7 +10362,7 @@ struct DecodeImageArgFlags {
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, SRGB and XMP.
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
@@ -10362,16 +10374,19 @@ struct DecodeImageArgFlags {
|
||||
static constexpr uint64_t REPORT_METADATA_GAMA = 0x0008;
|
||||
// International Color Consortium Profile.
|
||||
static constexpr uint64_t REPORT_METADATA_ICCP = 0x0010;
|
||||
// Key-Value Pair.
|
||||
//
|
||||
// For PNG files, this includes iTXt, tEXt and zTXt chunks. In the
|
||||
// HandleMetadata callback, the raw argument contains UTF-8 strings.
|
||||
static constexpr uint64_t REPORT_METADATA_KVP = 0x0020;
|
||||
// Modification Time.
|
||||
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0020;
|
||||
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0040;
|
||||
// Offset (2-Dimensional).
|
||||
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0040;
|
||||
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0080;
|
||||
// Physical Dimensions.
|
||||
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0080;
|
||||
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0100;
|
||||
// Standard Red Green Blue (Rendering Intent).
|
||||
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0100;
|
||||
// Text.
|
||||
static constexpr uint64_t REPORT_METADATA_TEXT = 0x0200;
|
||||
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0200;
|
||||
// Extensible Metadata Platform.
|
||||
static constexpr uint64_t REPORT_METADATA_XMP = 0x0400;
|
||||
|
||||
@@ -35309,6 +35324,7 @@ const char wuffs_png__error__bad_filter[] = "#png: bad filter";
|
||||
const char wuffs_png__error__bad_header[] = "#png: bad header";
|
||||
const char wuffs_png__error__missing_palette[] = "#png: missing palette";
|
||||
const char wuffs_png__error__unsupported_png_file[] = "#png: unsupported PNG file";
|
||||
const char wuffs_png__error__internal_error_inconsistent_chunk_type[] = "#png: internal error: inconsistent chunk type";
|
||||
const char wuffs_png__error__internal_error_inconsistent_frame_bounds[] = "#png: internal error: inconsistent frame bounds";
|
||||
const char wuffs_png__error__internal_error_inconsistent_workbuf_length[] = "#png: internal error: inconsistent workbuf length";
|
||||
const char wuffs_png__error__internal_error_zlib_decoder_did_not_exhaust_its_input[] = "#png: internal error: zlib decoder did not exhaust its input";
|
||||
@@ -37186,6 +37202,11 @@ wuffs_png__decoder__decode_image_config(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence == 2) {
|
||||
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;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
@@ -37982,6 +38003,14 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_trns = true;
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) || (self->private_impl.f_chunk_type == 1951942004) || (self->private_impl.f_chunk_type == 1951945850)) {
|
||||
if (self->private_impl.f_report_metadata_kvp) {
|
||||
self->private_impl.f_metadata_flavor = 4;
|
||||
self->private_impl.f_metadata_fourcc = 1263947851;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
}
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||
@@ -38905,6 +38934,7 @@ wuffs_png__decoder__decode_iccp(
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
self->private_impl.f_metadata_flavor = 4;
|
||||
self->private_impl.f_metadata_fourcc = 1229144912;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
@@ -40381,6 +40411,8 @@ wuffs_png__decoder__set_report_metadata(
|
||||
self->private_impl.f_report_metadata_gama = a_report;
|
||||
} else if (a_fourcc == 1229144912) {
|
||||
self->private_impl.f_report_metadata_iccp = a_report;
|
||||
} else if (a_fourcc == 1263947808) {
|
||||
self->private_impl.f_report_metadata_kvp = a_report;
|
||||
} else if (a_fourcc == 1397901122) {
|
||||
self->private_impl.f_report_metadata_srgb = a_report;
|
||||
}
|
||||
@@ -40416,9 +40448,23 @@ wuffs_png__decoder__tell_me_more(
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint64_t v_r_mark = 0;
|
||||
wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
io2_a_dst = io0_a_dst + a_dst->data.len;
|
||||
if (a_dst->meta.closed) {
|
||||
io2_a_dst = iop_a_dst;
|
||||
}
|
||||
}
|
||||
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;
|
||||
@@ -40431,6 +40477,9 @@ wuffs_png__decoder__tell_me_more(
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
|
||||
if (coro_susp_point) {
|
||||
v_c = self->private_data.s_tell_me_more[0].v_c;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
@@ -40442,7 +40491,7 @@ wuffs_png__decoder__tell_me_more(
|
||||
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_metadata_is_zlib_compressed) {
|
||||
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, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
@@ -40464,65 +40513,287 @@ wuffs_png__decoder__tell_me_more(
|
||||
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,
|
||||
((uint64_t)(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));
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(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_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
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_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_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;
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
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);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(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_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_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)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
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(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
{
|
||||
const uint8_t *o_2_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(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_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_2_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)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
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(3);
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
} else {
|
||||
label__1__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
goto label__1__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label__1__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__1__break;
|
||||
}
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
goto label__1__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
label__1__break:;
|
||||
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;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
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_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
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_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
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(8);
|
||||
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_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__2__break;
|
||||
}
|
||||
}
|
||||
label__2__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
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(9);
|
||||
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_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
}
|
||||
} else {
|
||||
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(10);
|
||||
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_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;
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -40535,9 +40806,13 @@ wuffs_png__decoder__tell_me_more(
|
||||
suspend:
|
||||
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
|
||||
self->private_data.s_tell_me_more[0].v_c = v_c;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
@@ -42682,6 +42957,9 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_ICCP) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
|
||||
}
|
||||
|
||||
+173
-22
@@ -23,6 +23,7 @@ pub status "#bad header"
|
||||
pub status "#missing palette"
|
||||
pub status "#unsupported PNG file"
|
||||
|
||||
pri status "#internal error: inconsistent chunk type"
|
||||
pri status "#internal error: inconsistent frame bounds"
|
||||
pri status "#internal error: inconsistent workbuf length"
|
||||
pri status "#internal error: zlib decoder did not exhaust its input"
|
||||
@@ -99,6 +100,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
report_metadata_chrm : base.bool,
|
||||
report_metadata_gama : base.bool,
|
||||
report_metadata_iccp : base.bool,
|
||||
report_metadata_kvp : base.bool,
|
||||
report_metadata_srgb : base.bool,
|
||||
|
||||
ignore_checksum : base.bool,
|
||||
@@ -118,6 +120,8 @@ pub struct decoder? implements base.image_decoder(
|
||||
seen_srgb : base.bool,
|
||||
seen_trns : base.bool,
|
||||
|
||||
metadata_is_zlib_compressed : base.bool,
|
||||
|
||||
zlib_is_dirty : base.bool,
|
||||
|
||||
chunk_type : base.u32,
|
||||
@@ -210,7 +214,10 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence == 2 {
|
||||
// No-op.
|
||||
if this.metadata_fourcc <> 0 {
|
||||
this.call_sequence = 1
|
||||
return base."@metadata reported"
|
||||
}
|
||||
} else if this.call_sequence <> 0 {
|
||||
return base."#bad call sequence"
|
||||
} else {
|
||||
@@ -606,6 +613,17 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
}
|
||||
this.decode_trns?(src: args.src)
|
||||
this.seen_trns = true
|
||||
|
||||
} else if (this.chunk_type == 'iTXt'le) or
|
||||
(this.chunk_type == 'tEXt'le) or
|
||||
(this.chunk_type == 'zTXt'le) {
|
||||
if this.report_metadata_kvp {
|
||||
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM
|
||||
this.metadata_fourcc = 'KVPK'be
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
}
|
||||
}
|
||||
|
||||
if this.metadata_fourcc == 0 {
|
||||
@@ -783,6 +801,7 @@ pri func decoder.decode_iccp?(src: base.io_reader) {
|
||||
return "#bad chunk"
|
||||
}
|
||||
|
||||
this.metadata_is_zlib_compressed = true
|
||||
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM
|
||||
this.metadata_fourcc = 'ICCP'be
|
||||
this.metadata_x = 0
|
||||
@@ -1319,12 +1338,15 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
this.report_metadata_gama = args.report
|
||||
} else if args.fourcc == 'ICCP'be {
|
||||
this.report_metadata_iccp = args.report
|
||||
} else if args.fourcc == 'KVP 'be {
|
||||
this.report_metadata_kvp = args.report
|
||||
} else if args.fourcc == 'SRGB'be {
|
||||
this.report_metadata_srgb = args.report
|
||||
}
|
||||
}
|
||||
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var r_mark : base.u64
|
||||
var zlib_status : base.status
|
||||
|
||||
@@ -1335,7 +1357,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
if this.metadata_flavor == base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM {
|
||||
if this.metadata_is_zlib_compressed {
|
||||
if this.zlib_is_dirty {
|
||||
this.zlib.reset!()
|
||||
if this.ignore_checksum {
|
||||
@@ -1359,34 +1381,163 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
break
|
||||
}
|
||||
|
||||
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
|
||||
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) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
if this.metadata_is_zlib_compressed {
|
||||
if this.chunk_type == 'iCCP'le {
|
||||
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
|
||||
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) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
|
||||
if zlib_status.is_ok() {
|
||||
if zlib_status.is_ok() {
|
||||
this.metadata_is_zlib_compressed = false
|
||||
break
|
||||
} else if not zlib_status.is_suspension() {
|
||||
return zlib_status
|
||||
}
|
||||
yield? zlib_status
|
||||
|
||||
} else if this.chunk_type == 'iTXt'le {
|
||||
// TODO: verify uncompressed data is UTF-8.
|
||||
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
|
||||
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) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
|
||||
if zlib_status.is_ok() {
|
||||
this.metadata_is_zlib_compressed = false
|
||||
break
|
||||
} else if not zlib_status.is_suspension() {
|
||||
return zlib_status
|
||||
}
|
||||
yield? zlib_status
|
||||
|
||||
} else if this.chunk_type == 'zTXt'le {
|
||||
// TODO: Convert uncompressed data from Latin-1 to UTF-8.
|
||||
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
|
||||
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) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
|
||||
if zlib_status.is_ok() {
|
||||
this.metadata_is_zlib_compressed = false
|
||||
break
|
||||
} else if not zlib_status.is_suspension() {
|
||||
return zlib_status
|
||||
}
|
||||
yield? zlib_status
|
||||
|
||||
} else {
|
||||
return "#internal error: inconsistent chunk type"
|
||||
}
|
||||
|
||||
} else {
|
||||
while true {
|
||||
if this.chunk_length <= 0 {
|
||||
// Keys are NUL-terminated but values are not.
|
||||
if this.metadata_fourcc == 'KVPK'be {
|
||||
return "#bad chunk"
|
||||
}
|
||||
break
|
||||
} else if args.src.length() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue
|
||||
}
|
||||
c = args.src.peek_u8()
|
||||
if c == 0 {
|
||||
this.chunk_length -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
break
|
||||
}
|
||||
// TODO: Convert from Latin-1 to UTF-8.
|
||||
if args.dst.length() <= 0 {
|
||||
yield? base."$short write"
|
||||
continue
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_u8_fast!(a: c)
|
||||
} endwhile
|
||||
break
|
||||
} else if not zlib_status.is_suspension() {
|
||||
return zlib_status
|
||||
}
|
||||
yield? zlib_status
|
||||
} endwhile
|
||||
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
// Key-value pairs come in... pairs.
|
||||
if this.metadata_fourcc == 'KVPK'be {
|
||||
this.metadata_fourcc = 'KVPV'be
|
||||
if this.chunk_type == 'iTXt'le {
|
||||
// Compression flag, compression method.
|
||||
if this.chunk_length <= 1 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.chunk_length -= 2
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
this.metadata_is_zlib_compressed = false
|
||||
} else if c == 1 {
|
||||
this.metadata_is_zlib_compressed = true
|
||||
} else {
|
||||
return "#bad chunk"
|
||||
}
|
||||
c = args.src.read_u8?()
|
||||
if (c <> 0) and this.metadata_is_zlib_compressed {
|
||||
return "#bad chunk"
|
||||
}
|
||||
|
||||
// Skip the language tag and translated keyword: two iterations
|
||||
// looking for a NUL terminator.
|
||||
this.metadata_fourcc ~mod-= 2
|
||||
while this.metadata_fourcc <> 'KVPV'be {
|
||||
this.metadata_fourcc ~mod+= 1
|
||||
while true {
|
||||
if this.chunk_length <= 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.chunk_length -= 1
|
||||
c = args.src.read_u8?()
|
||||
if c == 0 {
|
||||
break
|
||||
}
|
||||
} endwhile
|
||||
} endwhile
|
||||
|
||||
} else if this.chunk_type == 'zTXt'le {
|
||||
// Compression method.
|
||||
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_is_zlib_compressed = true
|
||||
}
|
||||
|
||||
} else {
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
|
||||
// Skip the ancillary chunk's CRC-32 checksum.
|
||||
args.src.skip?(n: 4)
|
||||
|
||||
this.metadata_flavor = 0
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
}
|
||||
|
||||
// Skip the ancillary chunk's CRC-32 checksum.
|
||||
args.src.skip?(n: 4)
|
||||
|
||||
this.call_sequence = 2
|
||||
this.metadata_flavor = 0
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
return ok
|
||||
}
|
||||
|
||||
|
||||
+85
-1
@@ -685,7 +685,7 @@ test_wuffs_png_decode_metadata_iccp() {
|
||||
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,
|
||||
RETURN_FAIL("tell_me_more: fourcc: have %" PRIX32 ", want %" PRIX32,
|
||||
wuffs_base__more_information__metadata__fourcc(&minfo),
|
||||
WUFFS_BASE__FOURCC__ICCP);
|
||||
}
|
||||
@@ -726,6 +726,89 @@ test_wuffs_png_decode_metadata_iccp() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_png_decode_metadata_kvp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/artificial-png/key-value-pairs.png"));
|
||||
|
||||
const char* wants[] = {
|
||||
// TODO: the callee should produce UTF-8, not Latin-1.
|
||||
"Key", //
|
||||
"English", //
|
||||
"Cl\xE9", //
|
||||
"Fran\xE7\x61is", //
|
||||
"zl\xEF\x62K", //
|
||||
"zl\xEF\x62V", //
|
||||
"U-Key", //
|
||||
"U-значение", //
|
||||
"Z-K\xEBy", //
|
||||
"Z-значение", //
|
||||
};
|
||||
|
||||
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__KVP, true);
|
||||
|
||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
|
||||
|
||||
size_t i = 0;
|
||||
for (;; i++) {
|
||||
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 i=%zu: %s", i, status.repr);
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
status = wuffs_png__decoder__tell_me_more(&dec, &have, &minfo, &src);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
RETURN_FAIL("tell_me_more i=%zu: \"%s\"", i, status.repr);
|
||||
} else if (minfo.flavor !=
|
||||
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM) {
|
||||
RETURN_FAIL("tell_me_more i=%zu: flavor: have %" PRIu32 ", want %" PRIu32,
|
||||
i, minfo.flavor,
|
||||
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM);
|
||||
}
|
||||
|
||||
uint32_t have_fourcc =
|
||||
wuffs_base__more_information__metadata__fourcc(&minfo);
|
||||
uint32_t want_fourcc =
|
||||
(i & 1) ? WUFFS_BASE__FOURCC__KVPV : WUFFS_BASE__FOURCC__KVPK;
|
||||
if (have_fourcc != want_fourcc) {
|
||||
RETURN_FAIL("tell_me_more i=%zu: fourcc: have %" PRIX32 ", want %" PRIX32,
|
||||
i, have_fourcc, want_fourcc);
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
if (i < WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
|
||||
size_t n = strlen(wants[i]);
|
||||
if (n < want.data.len) {
|
||||
memcpy(want.data.ptr, wants[i], n);
|
||||
want.meta.wi = n;
|
||||
}
|
||||
}
|
||||
CHECK_STRING(check_io_buffers_equal("", &have, &want));
|
||||
}
|
||||
|
||||
if (i != WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
|
||||
RETURN_FAIL("i: have %zu, want %zu", i, WUFFS_TESTLIB_ARRAY_SIZE(wants));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_png_decode_restart_frame() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -1120,6 +1203,7 @@ proc g_tests[] = {
|
||||
test_wuffs_png_decode_interface,
|
||||
test_wuffs_png_decode_metadata_chrm_gama_srgb,
|
||||
test_wuffs_png_decode_metadata_iccp,
|
||||
test_wuffs_png_decode_metadata_kvp,
|
||||
test_wuffs_png_decode_restart_frame,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 272 B |
@@ -0,0 +1,99 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make png
|
||||
|
||||
magic
|
||||
|
||||
IHDR {
|
||||
raw {
|
||||
# Width, height.
|
||||
0x00 0x00 0x00 0x01
|
||||
0x00 0x00 0x00 0x01
|
||||
# Depth, color, compression, filter, interlace.
|
||||
0x08 0x00 0x00 0x00 0x00
|
||||
}
|
||||
}
|
||||
|
||||
# Basic key-value pair.
|
||||
tEXt {
|
||||
raw {
|
||||
# "Key\x00".
|
||||
0x4B 0x65 0x79 0x00
|
||||
# "English".
|
||||
0x45 0x6E 0x67 0x6C 0x69 0x73 0x68
|
||||
}
|
||||
}
|
||||
|
||||
# Latin-1 (not UTF-8) uncompressed key-value pair.
|
||||
tEXt {
|
||||
raw {
|
||||
# asLatin1("Clé\x00").
|
||||
0x43 0x6C 0xE9 0x00
|
||||
# asLatin1("Français").
|
||||
0x46 0x72 0x61 0x6E 0xE7 0x61 0x69 0x73
|
||||
}
|
||||
}
|
||||
|
||||
# Latin-1 (not UTF-8) zlib-compressed key-value pair.
|
||||
zTXt {
|
||||
raw {
|
||||
# asLatin1("zlïbK\x00").
|
||||
0x7A 0x6C 0xEF 0x62 0x4B 0x00
|
||||
# Compression method.
|
||||
0x00
|
||||
}
|
||||
zlib {
|
||||
# asLatin1("zlïbV").
|
||||
0x7A 0x6C 0xEF 0x62 0x56
|
||||
}
|
||||
}
|
||||
|
||||
# UTF-8 uncompressed key-value pair.
|
||||
iTXt {
|
||||
raw {
|
||||
# "U-Key\x00".
|
||||
0x55 0x2D 0x4B 0x65 0x79 0x00
|
||||
# Compression flag, compression method.
|
||||
0x00 0x00
|
||||
# Language tag: "ru\x00".
|
||||
0x72 0x75 0x00
|
||||
# Translated key: "U-ключ\x00".
|
||||
0x55 0x2D 0xD0 0xBA 0xD0 0xBB 0xD1 0x8E
|
||||
0xD1 0x87 0x00
|
||||
# "U-значение".
|
||||
0x55 0x2D 0xD0 0xB7 0xD0 0xBD 0xD0 0xB0
|
||||
0xD1 0x87 0xD0 0xB5 0xD0 0xBD 0xD0 0xB8
|
||||
0xD0 0xB5
|
||||
}
|
||||
}
|
||||
|
||||
# Latin-1 / UTF-8 zlib-compressed key-value pair.
|
||||
iTXt {
|
||||
raw {
|
||||
# asLatin1("Z-Këy\x00").
|
||||
0x5A 0x2D 0x4B 0xEB 0x79 0x00
|
||||
# Compression flag, compression method.
|
||||
0x01 0x00
|
||||
# Language tag: "ru\x00".
|
||||
0x72 0x75 0x00
|
||||
# Translated key: "Z-ключ\x00".
|
||||
0x5A 0x2D 0xD0 0xBA 0xD0 0xBB 0xD1 0x8E
|
||||
0xD1 0x87 0x00
|
||||
}
|
||||
zlib {
|
||||
# "Z-значение".
|
||||
0x5A 0x2D 0xD0 0xB7 0xD0 0xBD 0xD0 0xB0
|
||||
0xD1 0x87 0xD0 0xB5 0xD0 0xBD 0xD0 0xB8
|
||||
0xD0 0xB5
|
||||
}
|
||||
}
|
||||
|
||||
IDAT {
|
||||
zlib {
|
||||
# 1x1 gray pixels (with filter bytes).
|
||||
0x00 0x80
|
||||
}
|
||||
}
|
||||
|
||||
IEND {
|
||||
}
|
||||
Reference in new issue
Block a user