mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
1 parent
9323549eeb
commit
db5a407bab
3 files changed
+122
-9
No files matched your search
@@ -9267,6 +9267,7 @@ struct wuffs_png__decoder__struct {
|
|||||||
bool f_report_metadata_chrm;
|
bool f_report_metadata_chrm;
|
||||||
bool f_report_metadata_gama;
|
bool f_report_metadata_gama;
|
||||||
bool f_report_metadata_iccp;
|
bool f_report_metadata_iccp;
|
||||||
|
bool f_report_metadata_srgb;
|
||||||
bool f_ignore_checksum;
|
bool f_ignore_checksum;
|
||||||
uint8_t f_depth;
|
uint8_t f_depth;
|
||||||
uint8_t f_color_type;
|
uint8_t f_color_type;
|
||||||
@@ -9276,6 +9277,7 @@ struct wuffs_png__decoder__struct {
|
|||||||
bool f_seen_gama;
|
bool f_seen_gama;
|
||||||
bool f_seen_iccp;
|
bool f_seen_iccp;
|
||||||
bool f_seen_plte;
|
bool f_seen_plte;
|
||||||
|
bool f_seen_srgb;
|
||||||
bool f_seen_trns;
|
bool f_seen_trns;
|
||||||
uint32_t f_dst_pixfmt;
|
uint32_t f_dst_pixfmt;
|
||||||
uint32_t f_src_pixfmt;
|
uint32_t f_src_pixfmt;
|
||||||
@@ -9307,6 +9309,7 @@ struct wuffs_png__decoder__struct {
|
|||||||
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_plte[1];
|
uint32_t p_decode_plte[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];
|
||||||
@@ -35166,6 +35169,11 @@ wuffs_png__decoder__decode_plte(
|
|||||||
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_srgb(
|
||||||
|
wuffs_png__decoder* self,
|
||||||
|
wuffs_base__io_buffer* a_src);
|
||||||
|
|
||||||
static wuffs_base__status
|
static wuffs_base__status
|
||||||
wuffs_png__decoder__decode_trns(
|
wuffs_png__decoder__decode_trns(
|
||||||
wuffs_png__decoder* self,
|
wuffs_png__decoder* self,
|
||||||
@@ -37517,6 +37525,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 == 1111970419) && self->private_impl.f_report_metadata_srgb) {
|
||||||
|
if (self->private_impl.f_seen_srgb) {
|
||||||
|
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_srgb(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_srgb = true;
|
||||||
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
} else if (self->private_impl.f_chunk_type == 1397641844) {
|
||||||
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
|
||||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||||
@@ -37525,7 +37550,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_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;
|
||||||
@@ -37536,7 +37561,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(5);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||||
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;
|
||||||
@@ -38043,6 +38068,66 @@ wuffs_png__decoder__decode_plte(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------- func png.decoder.decode_srgb
|
||||||
|
|
||||||
|
static wuffs_base__status
|
||||||
|
wuffs_png__decoder__decode_srgb(
|
||||||
|
wuffs_png__decoder* self,
|
||||||
|
wuffs_base__io_buffer* a_src) {
|
||||||
|
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||||
|
|
||||||
|
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_srgb[0];
|
||||||
|
switch (coro_susp_point) {
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
|
|
||||||
|
if (self->private_impl.f_chunk_length != 1) {
|
||||||
|
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 = 1397901122;
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
uint64_t t_0 = *iop_a_src++;
|
||||||
|
self->private_impl.f_metadata_x = t_0;
|
||||||
|
}
|
||||||
|
self->private_impl.f_metadata_y = 0;
|
||||||
|
self->private_impl.f_metadata_z = 0;
|
||||||
|
|
||||||
|
goto ok;
|
||||||
|
ok:
|
||||||
|
self->private_impl.p_decode_srgb[0] = 0;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto suspend;
|
||||||
|
suspend:
|
||||||
|
self->private_impl.p_decode_srgb[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_trns
|
// -------- func png.decoder.decode_trns
|
||||||
|
|
||||||
static wuffs_base__status
|
static wuffs_base__status
|
||||||
@@ -38783,6 +38868,8 @@ wuffs_png__decoder__set_report_metadata(
|
|||||||
self->private_impl.f_report_metadata_gama = a_report;
|
self->private_impl.f_report_metadata_gama = a_report;
|
||||||
} else if (a_fourcc == 1229144912) {
|
} else if (a_fourcc == 1229144912) {
|
||||||
self->private_impl.f_report_metadata_iccp = a_report;
|
self->private_impl.f_report_metadata_iccp = a_report;
|
||||||
|
} else if (a_fourcc == 1397901122) {
|
||||||
|
self->private_impl.f_report_metadata_srgb = a_report;
|
||||||
}
|
}
|
||||||
return wuffs_base__make_empty_struct();
|
return wuffs_base__make_empty_struct();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ pub struct decoder? implements base.image_decoder(
|
|||||||
report_metadata_chrm : base.bool,
|
report_metadata_chrm : base.bool,
|
||||||
report_metadata_gama : base.bool,
|
report_metadata_gama : base.bool,
|
||||||
report_metadata_iccp : base.bool,
|
report_metadata_iccp : base.bool,
|
||||||
|
report_metadata_srgb : base.bool,
|
||||||
|
|
||||||
ignore_checksum : base.bool,
|
ignore_checksum : base.bool,
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ pub struct decoder? implements base.image_decoder(
|
|||||||
seen_gama : base.bool,
|
seen_gama : base.bool,
|
||||||
seen_iccp : base.bool,
|
seen_iccp : base.bool,
|
||||||
seen_plte : base.bool,
|
seen_plte : base.bool,
|
||||||
|
seen_srgb : base.bool,
|
||||||
seen_trns : base.bool,
|
seen_trns : base.bool,
|
||||||
|
|
||||||
dst_pixfmt : base.u32,
|
dst_pixfmt : base.u32,
|
||||||
@@ -446,6 +448,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 == 'sRGB'le) and this.report_metadata_srgb {
|
||||||
|
if this.seen_srgb {
|
||||||
|
return "#bad chunk"
|
||||||
|
}
|
||||||
|
this.decode_srgb?(src: args.src)
|
||||||
|
this.seen_srgb = true
|
||||||
|
|
||||||
} else if this.chunk_type == 'tRNS'le {
|
} else if this.chunk_type == 'tRNS'le {
|
||||||
if this.seen_trns or (this.color_type > 3) or
|
if this.seen_trns or (this.color_type > 3) or
|
||||||
((this.color_type == 3) and (not this.seen_plte)) {
|
((this.color_type == 3) and (not this.seen_plte)) {
|
||||||
@@ -539,6 +548,17 @@ pri func decoder.decode_plte?(src: base.io_reader) {
|
|||||||
} endwhile
|
} endwhile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pri func decoder.decode_srgb?(src: base.io_reader) {
|
||||||
|
if this.chunk_length <> 1 {
|
||||||
|
return "#bad chunk"
|
||||||
|
}
|
||||||
|
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
|
||||||
|
this.metadata_fourcc = 'SRGB'be
|
||||||
|
this.metadata_x = args.src.read_u8_as_u64?()
|
||||||
|
this.metadata_y = 0
|
||||||
|
this.metadata_z = 0
|
||||||
|
}
|
||||||
|
|
||||||
pri func decoder.decode_trns?(src: base.io_reader) {
|
pri func decoder.decode_trns?(src: base.io_reader) {
|
||||||
var num_entries : base.u32[..= 256]
|
var num_entries : base.u32[..= 256]
|
||||||
var i : base.u32
|
var i : base.u32
|
||||||
@@ -796,6 +816,8 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
|||||||
this.report_metadata_gama = args.report
|
this.report_metadata_gama = args.report
|
||||||
} else if args.fourcc == 'ICCP'be {
|
} else if args.fourcc == 'ICCP'be {
|
||||||
this.report_metadata_iccp = args.report
|
this.report_metadata_iccp = args.report
|
||||||
|
} else if args.fourcc == 'SRGB'be {
|
||||||
|
this.report_metadata_srgb = args.report
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-7
@@ -473,18 +473,16 @@ test_wuffs_png_decode_frame_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* //
|
const char* //
|
||||||
test_wuffs_png_decode_metadata_chrm_gama() {
|
test_wuffs_png_decode_metadata_chrm_gama_srgb() {
|
||||||
CHECK_FOCUS(__func__);
|
CHECK_FOCUS(__func__);
|
||||||
wuffs_png__decoder dec;
|
wuffs_png__decoder dec;
|
||||||
|
|
||||||
int q;
|
int q;
|
||||||
for (q = 0; q < 3; q++) {
|
for (q = 0; q < 4; q++) {
|
||||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||||
.data = g_src_slice_u8,
|
.data = g_src_slice_u8,
|
||||||
});
|
});
|
||||||
CHECK_STRING(read_file(
|
CHECK_STRING(read_file(&src, "test/data/bricks-dither.png"));
|
||||||
&src, (q == 1) ? "test/data/bricks-dither.png"
|
|
||||||
: "test/data/red-blue-gradient.gamma1dot8.png"));
|
|
||||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||||
|
|
||||||
CHECK_STATUS("initialize",
|
CHECK_STATUS("initialize",
|
||||||
@@ -507,7 +505,11 @@ test_wuffs_png_decode_metadata_chrm_gama() {
|
|||||||
want[7] = 6000;
|
want[7] = 6000;
|
||||||
} else if (q == 2) {
|
} else if (q == 2) {
|
||||||
want_fourcc = WUFFS_BASE__FOURCC__GAMA;
|
want_fourcc = WUFFS_BASE__FOURCC__GAMA;
|
||||||
want[0] = 55556;
|
want[0] = 45455;
|
||||||
|
} else if (q == 3) {
|
||||||
|
want_fourcc = WUFFS_BASE__FOURCC__SRGB;
|
||||||
|
want[0] = WUFFS_BASE__SRGB_RENDERING_INTENT__PERCEPTUAL;
|
||||||
|
have[0] = 123;
|
||||||
}
|
}
|
||||||
wuffs_png__decoder__set_report_metadata(&dec, want_fourcc, true);
|
wuffs_png__decoder__set_report_metadata(&dec, want_fourcc, true);
|
||||||
|
|
||||||
@@ -547,6 +549,8 @@ test_wuffs_png_decode_metadata_chrm_gama() {
|
|||||||
}
|
}
|
||||||
} else if (have_fourcc == WUFFS_BASE__FOURCC__GAMA) {
|
} else if (have_fourcc == WUFFS_BASE__FOURCC__GAMA) {
|
||||||
have[0] = wuffs_base__more_information__metadata_parsed__gama(&minfo);
|
have[0] = wuffs_base__more_information__metadata_parsed__gama(&minfo);
|
||||||
|
} else if (have_fourcc == WUFFS_BASE__FOURCC__SRGB) {
|
||||||
|
have[0] = wuffs_base__more_information__metadata_parsed__srgb(&minfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +897,7 @@ proc g_tests[] = {
|
|||||||
test_wuffs_png_decode_filters_round_trip,
|
test_wuffs_png_decode_filters_round_trip,
|
||||||
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,
|
test_wuffs_png_decode_metadata_chrm_gama_srgb,
|
||||||
|
|
||||||
#ifdef WUFFS_MIMIC
|
#ifdef WUFFS_MIMIC
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user