mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d910658bce | ||
|
|
00d5e35865 | ||
|
|
05f0172b93 | ||
|
|
57bd11bf39 | ||
|
|
67d9a68c49 | ||
|
|
17f7613262 | ||
|
|
baac49dca7 | ||
|
|
a12a807d0e | ||
|
|
000b0a3445 |
No files matched your search
+14
-2
@@ -1,7 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
|
||||
## Work In Progress
|
||||
## 2023-04-08 version 0.3.3
|
||||
|
||||
The `wuffs_base__parse_number_f64` function has been further optimized.
|
||||
|
||||
|
||||
## 2023-04-07 version 0.3.2
|
||||
|
||||
The `std/bmp` and `std/nie` image decoders' `decode_frame` method now allow
|
||||
decoding to a pixel buffer that's smaller than the source image. This makes
|
||||
these two image decoders consistent with the other ones in `std`.
|
||||
|
||||
|
||||
## 2023-03-04 version 0.3.1
|
||||
|
||||
For a *closed* `io_reader`, the standard library now returns `"#truncated
|
||||
input"` instead of `"$short read"`. Importantly, this is an error, not a
|
||||
@@ -175,4 +187,4 @@ Wuffs version 0.1.
|
||||
|
||||
---
|
||||
|
||||
Updated on January 2023.
|
||||
Updated on April 2023.
|
||||
@@ -1304,24 +1304,41 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
|
||||
// for the common cases (e.g. assuming no underscores or a leading '+'
|
||||
// sign) rather than the full set of cases allowed by the Wuffs API.
|
||||
if (h->num_digits <= 19) {
|
||||
//
|
||||
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
|
||||
// for an exact result). When we have more than 19 mantissa digits, run it
|
||||
// twice to get a lower and upper bound. We still have an exact result
|
||||
// (within f64's rounding margin) if both bounds are equal (and valid).
|
||||
uint32_t i_max = h->num_digits;
|
||||
if (i_max > 19) {
|
||||
i_max = 19;
|
||||
}
|
||||
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
|
||||
if ((-307 <= exp10) && (exp10 <= 288)) {
|
||||
uint64_t man = 0;
|
||||
uint32_t i;
|
||||
for (i = 0; i < h->num_digits; i++) {
|
||||
for (i = 0; i < i_max; i++) {
|
||||
man = (10 * man) + h->digits[i];
|
||||
}
|
||||
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
|
||||
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
|
||||
int64_t r =
|
||||
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
|
||||
int64_t r0 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man, exp10);
|
||||
if (r >= 0) {
|
||||
wuffs_base__result_f64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
|
||||
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
|
||||
return ret;
|
||||
man + 0, exp10);
|
||||
if (r0 < 0) {
|
||||
break;
|
||||
} else if (h->num_digits > 19) {
|
||||
int64_t r1 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man + 1, exp10);
|
||||
if (r1 != r0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
wuffs_base__result_f64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
|
||||
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14821,24 +14821,41 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
|
||||
// for the common cases (e.g. assuming no underscores or a leading '+'
|
||||
// sign) rather than the full set of cases allowed by the Wuffs API.
|
||||
if (h->num_digits <= 19) {
|
||||
//
|
||||
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
|
||||
// for an exact result). When we have more than 19 mantissa digits, run it
|
||||
// twice to get a lower and upper bound. We still have an exact result
|
||||
// (within f64's rounding margin) if both bounds are equal (and valid).
|
||||
uint32_t i_max = h->num_digits;
|
||||
if (i_max > 19) {
|
||||
i_max = 19;
|
||||
}
|
||||
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
|
||||
if ((-307 <= exp10) && (exp10 <= 288)) {
|
||||
uint64_t man = 0;
|
||||
uint32_t i;
|
||||
for (i = 0; i < h->num_digits; i++) {
|
||||
for (i = 0; i < i_max; i++) {
|
||||
man = (10 * man) + h->digits[i];
|
||||
}
|
||||
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
|
||||
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
|
||||
int64_t r =
|
||||
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
|
||||
int64_t r0 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man, exp10);
|
||||
if (r >= 0) {
|
||||
wuffs_base__result_f64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
|
||||
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
|
||||
return ret;
|
||||
man + 0, exp10);
|
||||
if (r0 < 0) {
|
||||
break;
|
||||
} else if (h->num_digits > 19) {
|
||||
int64_t r1 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man + 1, exp10);
|
||||
if (r1 != r0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
wuffs_base__result_f64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
|
||||
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24195,10 +24212,12 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_row = 0;
|
||||
uint32_t v_src_bytes_per_pixel = 0;
|
||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_i = 0;
|
||||
uint64_t v_j = 0;
|
||||
uint64_t v_n = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -24232,7 +24251,6 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
self->private_impl.f_pending_pad -= 1;
|
||||
iop_a_src += 1;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
||||
self->private_impl.f_dst_x = 0;
|
||||
@@ -24253,14 +24271,38 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__inner__continue;
|
||||
if (self->private_impl.f_bits_per_pixel > 32) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
|
||||
goto exit;
|
||||
}
|
||||
v_src_bytes_per_pixel = (self->private_impl.f_bits_per_pixel / 8);
|
||||
if (v_src_bytes_per_pixel == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
|
||||
goto exit;
|
||||
}
|
||||
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
|
||||
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
|
||||
v_j = v_n;
|
||||
while (v_j >= 8) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 8);
|
||||
}
|
||||
v_j -= 8;
|
||||
}
|
||||
while (v_j > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 1);
|
||||
}
|
||||
v_j -= 1;
|
||||
}
|
||||
} else {
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
v_dst_palette,
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
v_dst_palette,
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -24601,7 +24643,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
self->private_impl.f_pending_pad -= 1;
|
||||
iop_a_src += 1;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
||||
self->private_impl.f_dst_x = 0;
|
||||
@@ -24660,9 +24701,10 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__inner__continue;
|
||||
v_n = ((uint64_t)(v_p0));
|
||||
} else {
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -24705,6 +24747,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
uint32_t v_p0 = 0;
|
||||
uint32_t v_chunk_bits = 0;
|
||||
uint32_t v_chunk_count = 0;
|
||||
uint32_t v_pixels_per_chunk = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
@@ -24742,6 +24785,35 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
if (self->private_impl.f_bits_per_pixel == 1) {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
|
||||
v_pixels_per_chunk = 32;
|
||||
} else if (self->private_impl.f_bits_per_pixel == 2) {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 15) / 16);
|
||||
v_pixels_per_chunk = 16;
|
||||
} else {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
|
||||
v_pixels_per_chunk = 8;
|
||||
}
|
||||
while ((v_chunk_count >= 64) && (((uint64_t)(io2_a_src - iop_a_src)) >= 256)) {
|
||||
iop_a_src += 256;
|
||||
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 64))));
|
||||
v_chunk_count -= 64;
|
||||
}
|
||||
while ((v_chunk_count >= 8) && (((uint64_t)(io2_a_src - iop_a_src)) >= 32)) {
|
||||
iop_a_src += 32;
|
||||
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 8))));
|
||||
v_chunk_count -= 8;
|
||||
}
|
||||
while (v_chunk_count > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 4;
|
||||
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 1))));
|
||||
v_chunk_count -= 1;
|
||||
}
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i);
|
||||
@@ -24812,7 +24884,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
v_p0 = ((v_p0 & 511) + 16);
|
||||
v_chunk_count -= 1;
|
||||
}
|
||||
} else if (self->private_impl.f_bits_per_pixel == 4) {
|
||||
} else {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
|
||||
v_chunk_count = wuffs_base__u32__min(v_chunk_count, 64);
|
||||
while ((v_chunk_count > 0) && (((uint64_t)(io2_a_src - iop_a_src)) >= 4)) {
|
||||
@@ -37894,9 +37966,11 @@ wuffs_nie__decoder__swizzle(
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_row = 0;
|
||||
uint32_t v_src_bytes_per_pixel = 0;
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_i = 0;
|
||||
uint64_t v_j = 0;
|
||||
uint64_t v_n = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -37919,7 +37993,6 @@ wuffs_nie__decoder__swizzle(
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
||||
self->private_impl.f_dst_x = 0;
|
||||
@@ -37934,14 +38007,33 @@ wuffs_nie__decoder__swizzle(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__0__continue;
|
||||
v_src_bytes_per_pixel = 4;
|
||||
if (self->private_impl.f_pixfmt == 2164308923) {
|
||||
v_src_bytes_per_pixel = 8;
|
||||
}
|
||||
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
|
||||
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
|
||||
v_j = v_n;
|
||||
while (v_j >= 8) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 8);
|
||||
}
|
||||
v_j -= 8;
|
||||
}
|
||||
while (v_j > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 1);
|
||||
}
|
||||
v_j -= 1;
|
||||
}
|
||||
} else {
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
wuffs_base__pixel_buffer__palette(a_dst),
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
wuffs_base__pixel_buffer__palette(a_dst),
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_nie__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -40795,14 +40887,12 @@ wuffs_png__decoder__do_decode_image_config(
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
label__1__continue:;
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__1__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
|
||||
@@ -43201,13 +43291,10 @@ wuffs_png__decoder__skip_frame(
|
||||
self->private_impl.f_chunk_type_array[3] = 0;
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
goto label__0__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
|
||||
@@ -43446,14 +43533,12 @@ wuffs_png__decoder__do_decode_frame(
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
goto label__0__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
|
||||
@@ -43588,14 +43673,12 @@ wuffs_png__decoder__do_decode_frame(
|
||||
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
|
||||
}
|
||||
if (v_status.repr == wuffs_base__suspension__short_read) {
|
||||
while (true) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
label__1__break:;
|
||||
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
|
||||
|
||||
+141
-58
@@ -85,15 +85,15 @@ extern "C" {
|
||||
// each major.minor branch, the commit count should increase monotonically.
|
||||
//
|
||||
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
|
||||
// 02844cdca44276c1838ab15f5b73f901345d5ead committed on 2023-02-23.
|
||||
#define WUFFS_VERSION 0x000030001
|
||||
// 00d5e35865a2f2718f4bb2596adaaa54bd639bbe committed on 2023-04-08.
|
||||
#define WUFFS_VERSION 0x000030003
|
||||
#define WUFFS_VERSION_MAJOR 0
|
||||
#define WUFFS_VERSION_MINOR 3
|
||||
#define WUFFS_VERSION_PATCH 1
|
||||
#define WUFFS_VERSION_PATCH 3
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL ""
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3390
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20230223
|
||||
#define WUFFS_VERSION_STRING "0.3.1+3390.20230223"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3399
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20230408
|
||||
#define WUFFS_VERSION_STRING "0.3.3+3399.20230408"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -14822,24 +14822,41 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
|
||||
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
|
||||
// for the common cases (e.g. assuming no underscores or a leading '+'
|
||||
// sign) rather than the full set of cases allowed by the Wuffs API.
|
||||
if (h->num_digits <= 19) {
|
||||
//
|
||||
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
|
||||
// for an exact result). When we have more than 19 mantissa digits, run it
|
||||
// twice to get a lower and upper bound. We still have an exact result
|
||||
// (within f64's rounding margin) if both bounds are equal (and valid).
|
||||
uint32_t i_max = h->num_digits;
|
||||
if (i_max > 19) {
|
||||
i_max = 19;
|
||||
}
|
||||
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
|
||||
if ((-307 <= exp10) && (exp10 <= 288)) {
|
||||
uint64_t man = 0;
|
||||
uint32_t i;
|
||||
for (i = 0; i < h->num_digits; i++) {
|
||||
for (i = 0; i < i_max; i++) {
|
||||
man = (10 * man) + h->digits[i];
|
||||
}
|
||||
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
|
||||
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
|
||||
int64_t r =
|
||||
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
|
||||
int64_t r0 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man, exp10);
|
||||
if (r >= 0) {
|
||||
wuffs_base__result_f64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
|
||||
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
|
||||
return ret;
|
||||
man + 0, exp10);
|
||||
if (r0 < 0) {
|
||||
break;
|
||||
} else if (h->num_digits > 19) {
|
||||
int64_t r1 =
|
||||
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
|
||||
man + 1, exp10);
|
||||
if (r1 != r0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
wuffs_base__result_f64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
|
||||
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24196,10 +24213,12 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_row = 0;
|
||||
uint32_t v_src_bytes_per_pixel = 0;
|
||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_i = 0;
|
||||
uint64_t v_j = 0;
|
||||
uint64_t v_n = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -24233,7 +24252,6 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
self->private_impl.f_pending_pad -= 1;
|
||||
iop_a_src += 1;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
||||
self->private_impl.f_dst_x = 0;
|
||||
@@ -24254,14 +24272,38 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__inner__continue;
|
||||
if (self->private_impl.f_bits_per_pixel > 32) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
|
||||
goto exit;
|
||||
}
|
||||
v_src_bytes_per_pixel = (self->private_impl.f_bits_per_pixel / 8);
|
||||
if (v_src_bytes_per_pixel == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
|
||||
goto exit;
|
||||
}
|
||||
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
|
||||
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
|
||||
v_j = v_n;
|
||||
while (v_j >= 8) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 8);
|
||||
}
|
||||
v_j -= 8;
|
||||
}
|
||||
while (v_j > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 1);
|
||||
}
|
||||
v_j -= 1;
|
||||
}
|
||||
} else {
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
v_dst_palette,
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
v_dst_palette,
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -24602,7 +24644,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
self->private_impl.f_pending_pad -= 1;
|
||||
iop_a_src += 1;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
||||
self->private_impl.f_dst_x = 0;
|
||||
@@ -24661,9 +24702,10 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__inner__continue;
|
||||
v_n = ((uint64_t)(v_p0));
|
||||
} else {
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -24706,6 +24748,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
uint32_t v_p0 = 0;
|
||||
uint32_t v_chunk_bits = 0;
|
||||
uint32_t v_chunk_count = 0;
|
||||
uint32_t v_pixels_per_chunk = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
@@ -24743,6 +24786,35 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
if (self->private_impl.f_bits_per_pixel == 1) {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
|
||||
v_pixels_per_chunk = 32;
|
||||
} else if (self->private_impl.f_bits_per_pixel == 2) {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 15) / 16);
|
||||
v_pixels_per_chunk = 16;
|
||||
} else {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
|
||||
v_pixels_per_chunk = 8;
|
||||
}
|
||||
while ((v_chunk_count >= 64) && (((uint64_t)(io2_a_src - iop_a_src)) >= 256)) {
|
||||
iop_a_src += 256;
|
||||
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 64))));
|
||||
v_chunk_count -= 64;
|
||||
}
|
||||
while ((v_chunk_count >= 8) && (((uint64_t)(io2_a_src - iop_a_src)) >= 32)) {
|
||||
iop_a_src += 32;
|
||||
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 8))));
|
||||
v_chunk_count -= 8;
|
||||
}
|
||||
while (v_chunk_count > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
|
||||
goto ok;
|
||||
}
|
||||
iop_a_src += 4;
|
||||
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 1))));
|
||||
v_chunk_count -= 1;
|
||||
}
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i);
|
||||
@@ -24813,7 +24885,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
v_p0 = ((v_p0 & 511) + 16);
|
||||
v_chunk_count -= 1;
|
||||
}
|
||||
} else if (self->private_impl.f_bits_per_pixel == 4) {
|
||||
} else {
|
||||
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
|
||||
v_chunk_count = wuffs_base__u32__min(v_chunk_count, 64);
|
||||
while ((v_chunk_count > 0) && (((uint64_t)(io2_a_src - iop_a_src)) >= 4)) {
|
||||
@@ -37895,9 +37967,11 @@ wuffs_nie__decoder__swizzle(
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_row = 0;
|
||||
uint32_t v_src_bytes_per_pixel = 0;
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_i = 0;
|
||||
uint64_t v_j = 0;
|
||||
uint64_t v_n = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -37920,7 +37994,6 @@ wuffs_nie__decoder__swizzle(
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
|
||||
self->private_impl.f_dst_x = 0;
|
||||
@@ -37935,14 +38008,33 @@ wuffs_nie__decoder__swizzle(
|
||||
}
|
||||
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i >= ((uint64_t)(v_dst.len))) {
|
||||
goto label__0__continue;
|
||||
v_src_bytes_per_pixel = 4;
|
||||
if (self->private_impl.f_pixfmt == 2164308923) {
|
||||
v_src_bytes_per_pixel = 8;
|
||||
}
|
||||
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
|
||||
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
|
||||
v_j = v_n;
|
||||
while (v_j >= 8) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 8);
|
||||
}
|
||||
v_j -= 8;
|
||||
}
|
||||
while (v_j > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
|
||||
iop_a_src += (v_src_bytes_per_pixel * 1);
|
||||
}
|
||||
v_j -= 1;
|
||||
}
|
||||
} else {
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
wuffs_base__pixel_buffer__palette(a_dst),
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
}
|
||||
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
|
||||
&self->private_impl.f_swizzler,
|
||||
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
|
||||
wuffs_base__pixel_buffer__palette(a_dst),
|
||||
&iop_a_src,
|
||||
io2_a_src);
|
||||
if (v_n == 0) {
|
||||
status = wuffs_base__make_status(wuffs_nie__note__internal_note_short_read);
|
||||
goto ok;
|
||||
@@ -40796,14 +40888,12 @@ wuffs_png__decoder__do_decode_image_config(
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
}
|
||||
label__1__continue:;
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__1__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
|
||||
@@ -43202,13 +43292,10 @@ wuffs_png__decoder__skip_frame(
|
||||
self->private_impl.f_chunk_type_array[3] = 0;
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
goto label__0__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
|
||||
@@ -43447,14 +43534,12 @@ wuffs_png__decoder__do_decode_frame(
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
goto label__0__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
|
||||
@@ -43589,14 +43674,12 @@ wuffs_png__decoder__do_decode_frame(
|
||||
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
|
||||
}
|
||||
if (v_status.repr == wuffs_base__suspension__short_read) {
|
||||
while (true) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
label__1__break:;
|
||||
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
|
||||
|
||||
@@ -0,0 +1,441 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
// manual-test-truncated-input tests that decoding truncated versions of
|
||||
// well-formed files produces a "truncated input" error.
|
||||
//
|
||||
// It tests every M-byte prefix of a valid N-byte file, for every positive M
|
||||
// that satisfies (M < 65536) or ((N - M) <= 1024). The truncation point is
|
||||
// either within 64 KiB of the start or 1 KiB of the end. It does not test
|
||||
// every potential M in between, as that would take O(N**2) time.
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||
// functions have static storage.
|
||||
//
|
||||
// This can help the compiler ignore or discard unused code, which can produce
|
||||
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__ADLER32
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__BMP
|
||||
#define WUFFS_CONFIG__MODULE__BZIP2
|
||||
#define WUFFS_CONFIG__MODULE__CRC32
|
||||
#define WUFFS_CONFIG__MODULE__DEFLATE
|
||||
#define WUFFS_CONFIG__MODULE__GIF
|
||||
#define WUFFS_CONFIG__MODULE__GZIP
|
||||
#define WUFFS_CONFIG__MODULE__LZW
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../release/c/wuffs-unsupported-snapshot.c"
|
||||
|
||||
// ----
|
||||
|
||||
#ifndef DST_BUFFER_ARRAY_SIZE
|
||||
#define DST_BUFFER_ARRAY_SIZE (64 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef WORKBUF_ARRAY_SIZE
|
||||
#define WORKBUF_ARRAY_SIZE (256 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE] = {0};
|
||||
uint8_t g_workbuf_array[WORKBUF_ARRAY_SIZE] = {0};
|
||||
|
||||
static int g_num_files_processed;
|
||||
|
||||
static struct {
|
||||
char buf[PATH_MAX];
|
||||
size_t len;
|
||||
} g_relative_cwd;
|
||||
|
||||
// ----
|
||||
|
||||
static const char skipped[] = "skipped";
|
||||
static const char unsupported_file_format[] = "unsupported file format";
|
||||
|
||||
static const char* //
|
||||
handle_image_decoder(wuffs_base__io_buffer src,
|
||||
int32_t fourcc,
|
||||
bool full_decode) {
|
||||
wuffs_base__image_decoder::unique_ptr dec(nullptr, &free);
|
||||
switch (fourcc) {
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__GIF:
|
||||
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__NIE:
|
||||
dec = wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__PNG:
|
||||
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
break;
|
||||
default:
|
||||
return unsupported_file_format;
|
||||
}
|
||||
|
||||
if (!full_decode) {
|
||||
while (true) {
|
||||
auto dfc_status = dec->decode_frame_config(nullptr, &src);
|
||||
if (dfc_status.is_ok()) {
|
||||
// No-op.
|
||||
} else if (dfc_status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else {
|
||||
return dfc_status.message();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wuffs_base__pixel_config pixcfg = {0};
|
||||
pixcfg.set(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL,
|
||||
WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, 0, 0);
|
||||
|
||||
wuffs_base__pixel_buffer pixbuf = {0};
|
||||
auto sfs_status =
|
||||
pixbuf.set_from_slice(&pixcfg, wuffs_base__make_slice_u8(nullptr, 0));
|
||||
if (!sfs_status.is_ok()) {
|
||||
return sfs_status.message();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
auto df_status = dec->decode_frame(
|
||||
&pixbuf, &src, WUFFS_BASE__PIXEL_BLEND__SRC,
|
||||
wuffs_base__make_slice_u8(g_workbuf_array, WORKBUF_ARRAY_SIZE),
|
||||
nullptr);
|
||||
if (df_status.is_ok()) {
|
||||
// No-op.
|
||||
} else if (df_status.repr == wuffs_base__note__end_of_data) {
|
||||
break;
|
||||
} else {
|
||||
return df_status.message();
|
||||
}
|
||||
}
|
||||
if (src.meta.ri != src.meta.wi) {
|
||||
return skipped;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const char* //
|
||||
handle_io_transformer(wuffs_base__io_buffer src, int32_t fourcc) {
|
||||
wuffs_base__io_transformer::unique_ptr dec(nullptr, &free);
|
||||
switch (fourcc) {
|
||||
case WUFFS_BASE__FOURCC__BZ2:
|
||||
dec = wuffs_bzip2__decoder::alloc_as__wuffs_base__io_transformer();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__GZ:
|
||||
dec = wuffs_gzip__decoder::alloc_as__wuffs_base__io_transformer();
|
||||
break;
|
||||
case WUFFS_BASE__FOURCC__ZLIB:
|
||||
dec = wuffs_zlib__decoder::alloc_as__wuffs_base__io_transformer();
|
||||
break;
|
||||
default:
|
||||
return unsupported_file_format;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
auto dst = wuffs_base__ptr_u8__writer(&g_dst_buffer_array[0],
|
||||
DST_BUFFER_ARRAY_SIZE);
|
||||
auto df_status = dec->transform_io(
|
||||
&dst, &src,
|
||||
wuffs_base__make_slice_u8(g_workbuf_array, WORKBUF_ARRAY_SIZE));
|
||||
if (df_status.is_ok()) {
|
||||
break;
|
||||
} else if (df_status.repr == wuffs_base__suspension__short_write) {
|
||||
// No-op.
|
||||
} else {
|
||||
return df_status.message();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const char* //
|
||||
handle_various(wuffs_base__io_buffer src, int32_t fourcc) {
|
||||
const char* status_msg;
|
||||
|
||||
status_msg = handle_image_decoder(src, fourcc, false);
|
||||
if (status_msg != unsupported_file_format) {
|
||||
if ((status_msg != nullptr) && !strstr(status_msg, "truncated input")) {
|
||||
return status_msg;
|
||||
}
|
||||
return handle_image_decoder(src, fourcc, true);
|
||||
}
|
||||
|
||||
status_msg = handle_io_transformer(src, fourcc);
|
||||
if (status_msg != unsupported_file_format) {
|
||||
return status_msg;
|
||||
}
|
||||
|
||||
return unsupported_file_format;
|
||||
}
|
||||
|
||||
static const char* //
|
||||
handle_range(wuffs_base__io_buffer src,
|
||||
int32_t fourcc,
|
||||
size_t wi_min_incl,
|
||||
size_t wi_max_excl) {
|
||||
for (size_t wi = wi_min_incl; wi < wi_max_excl; wi++) {
|
||||
src.meta.wi = wi;
|
||||
const char* status_msg = handle_various(src, fourcc);
|
||||
if ((status_msg != nullptr) && strstr(status_msg, "truncated input")) {
|
||||
continue;
|
||||
}
|
||||
printf("when truncated to %zu bytes: ", wi);
|
||||
if (status_msg) {
|
||||
return status_msg;
|
||||
}
|
||||
return "have ok; want \"truncated input\"";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const char* //
|
||||
handle(const uint8_t* ptr, size_t len) {
|
||||
auto src = wuffs_base__ptr_u8__reader(const_cast<uint8_t*>(ptr), len, true);
|
||||
int32_t fourcc = wuffs_base__magic_number_guess_fourcc(src.reader_slice(),
|
||||
src.meta.closed);
|
||||
if (fourcc <= 0) {
|
||||
return skipped;
|
||||
}
|
||||
|
||||
// Skip any invalid or unsupported input (when decoded in its entirety).
|
||||
//
|
||||
// Unsupported includes ignoring wuffs_base__note__i_o_redirect. We don't
|
||||
// bother testing truncated PNGs-embedded-in-BMPs because we presumably
|
||||
// already test truncated PNGs.
|
||||
const char* status_msg = handle_various(src, fourcc);
|
||||
if (status_msg) {
|
||||
return skipped;
|
||||
}
|
||||
|
||||
size_t file_len = src.meta.wi;
|
||||
if (file_len <= (65536 + 1024)) {
|
||||
return handle_range(src, fourcc, 1, file_len);
|
||||
}
|
||||
|
||||
status_msg = handle_range(src, fourcc, 1, 65536);
|
||||
if (status_msg) {
|
||||
return status_msg;
|
||||
}
|
||||
return handle_range(src, fourcc, file_len - 1024, file_len);
|
||||
}
|
||||
|
||||
// ----
|
||||
|
||||
static int //
|
||||
visit(char* filename);
|
||||
|
||||
static int //
|
||||
visit_dir(int fd) {
|
||||
int cwd_fd = open(".", O_RDONLY, 0);
|
||||
if (fchdir(fd)) {
|
||||
printf("failed\n");
|
||||
fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
DIR* d = fdopendir(fd);
|
||||
if (!d) {
|
||||
printf("failed\n");
|
||||
fprintf(stderr, "FAIL: fdopendir: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("dir\n");
|
||||
while (true) {
|
||||
struct dirent* e = readdir(d);
|
||||
if (!e) {
|
||||
break;
|
||||
}
|
||||
if ((e->d_name[0] == '\x00') || (e->d_name[0] == '.')) {
|
||||
continue;
|
||||
}
|
||||
int v = visit(e->d_name);
|
||||
if (v) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
if (closedir(d)) {
|
||||
fprintf(stderr, "FAIL: closedir: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
if (fchdir(cwd_fd)) {
|
||||
fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
if (close(cwd_fd)) {
|
||||
fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int //
|
||||
visit_reg(int fd, off_t size) {
|
||||
if ((size < 0) || (0x7FFFFFFF < size)) {
|
||||
printf("failed\n");
|
||||
fprintf(stderr, "FAIL: file size out of bounds");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void* data = NULL;
|
||||
if (size > 0) {
|
||||
data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (data == MAP_FAILED) {
|
||||
printf("failed\n");
|
||||
fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const char* msg = handle((const uint8_t*)(data), size);
|
||||
if (msg) {
|
||||
printf("%s\n", msg);
|
||||
} else {
|
||||
printf("ok\n");
|
||||
}
|
||||
|
||||
if ((size > 0) && munmap(data, size)) {
|
||||
fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
if (close(fd)) {
|
||||
fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
return (msg && (msg != skipped)) ? 1 : 0;
|
||||
}
|
||||
|
||||
static int //
|
||||
visit(char* filename) {
|
||||
g_num_files_processed++;
|
||||
if (!filename || (filename[0] == '\x00')) {
|
||||
fprintf(stderr, "FAIL: invalid filename\n");
|
||||
return 1;
|
||||
}
|
||||
int n = printf("- %s%s", g_relative_cwd.buf, filename);
|
||||
printf("%*s", (60 > n) ? (60 - n) : 1, "");
|
||||
fflush(stdout);
|
||||
|
||||
struct stat z;
|
||||
int fd = open(filename, O_RDONLY, 0);
|
||||
if (fd == -1) {
|
||||
printf("failed\n");
|
||||
fprintf(stderr, "FAIL: open: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
if (fstat(fd, &z)) {
|
||||
printf("failed\n");
|
||||
fprintf(stderr, "FAIL: fstat: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (S_ISREG(z.st_mode)) {
|
||||
return visit_reg(fd, z.st_size);
|
||||
} else if (!S_ISDIR(z.st_mode)) {
|
||||
printf("skipped\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t old_len = g_relative_cwd.len;
|
||||
size_t filename_len = strlen(filename);
|
||||
size_t new_len = old_len + strlen(filename);
|
||||
bool slash = filename[filename_len - 1] != '/';
|
||||
if (slash) {
|
||||
new_len++;
|
||||
}
|
||||
if ((filename_len >= PATH_MAX) || (new_len >= PATH_MAX)) {
|
||||
printf("failed\n");
|
||||
fprintf(stderr, "FAIL: path is too long\n");
|
||||
return 1;
|
||||
}
|
||||
memcpy(g_relative_cwd.buf + old_len, filename, filename_len);
|
||||
|
||||
if (slash) {
|
||||
g_relative_cwd.buf[new_len - 1] = '/';
|
||||
}
|
||||
g_relative_cwd.buf[new_len] = '\x00';
|
||||
g_relative_cwd.len = new_len;
|
||||
|
||||
int v = visit_dir(fd);
|
||||
|
||||
g_relative_cwd.buf[old_len] = '\x00';
|
||||
g_relative_cwd.len = old_len;
|
||||
return v;
|
||||
}
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_num_files_processed = 0;
|
||||
g_relative_cwd.len = 0;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
int v = visit(argv[i]);
|
||||
if (v) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
printf("PASS: %d files processed\n", g_num_files_processed);
|
||||
return 0;
|
||||
}
|
||||
@@ -229,6 +229,10 @@ print_raw_passthrough(wuffs_base__io_buffer* src,
|
||||
break;
|
||||
}
|
||||
uint64_t n1 = src->reader_length();
|
||||
while (n1 == 0) {
|
||||
TRY(read_buffer_from_file(src, f));
|
||||
n1 = src->reader_length();
|
||||
}
|
||||
uint64_t n = wuffs_base__u64__min(n0, n1);
|
||||
print_hex_dump(src->reader_pointer(), n);
|
||||
src->meta.ri += n;
|
||||
|
||||
@@ -182,6 +182,7 @@ var u64TestCases = []uint64{
|
||||
0x44B52D02C7E14AF6,
|
||||
0x46293E5939A08CEA,
|
||||
0x54B249AD2594C37D,
|
||||
0x54B2987670ADB613,
|
||||
0x7BBA44DF832B8D46,
|
||||
0x7BF06B0BB1FB384C,
|
||||
0x7C2485CE9E7A065F,
|
||||
|
||||
+72
-21
@@ -50,7 +50,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
bitmap_info_len : base.u32,
|
||||
padding : base.u32,
|
||||
|
||||
bits_per_pixel : base.u32,
|
||||
bits_per_pixel : base.u32[..= 0xFFFF],
|
||||
compression : base.u32,
|
||||
|
||||
// channel_etc's indexes are: B, G, R, A. This is in Wuffs' default order,
|
||||
@@ -504,10 +504,12 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
||||
var dst_bytes_per_row : base.u64
|
||||
var src_bytes_per_pixel : base.u32[..= 4]
|
||||
var dst_palette : slice base.u8
|
||||
var tab : table base.u8
|
||||
var dst : slice base.u8
|
||||
var i : base.u64
|
||||
var j : base.u64
|
||||
var n : base.u64
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
@@ -552,14 +554,38 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
|
||||
}
|
||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
||||
if i >= dst.length() {
|
||||
// TODO: advance args.src if the dst pixel_buffer bounds is
|
||||
// smaller than this BMP's image bounds?
|
||||
continue.inner
|
||||
if this.bits_per_pixel > 32 {
|
||||
return "#unsupported BMP file"
|
||||
}
|
||||
src_bytes_per_pixel = this.bits_per_pixel / 8
|
||||
if src_bytes_per_pixel == 0 {
|
||||
return "#unsupported BMP file"
|
||||
}
|
||||
n = args.src.length() / (src_bytes_per_pixel as base.u64)
|
||||
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
|
||||
j = n
|
||||
while j >= 8 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
actual: src_bytes_per_pixel * 8,
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
actual: src_bytes_per_pixel * 1,
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: args.src)
|
||||
}
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: args.src)
|
||||
if n == 0 {
|
||||
return "@internal note: short read"
|
||||
}
|
||||
@@ -943,15 +969,13 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
|
||||
}
|
||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
||||
if i >= dst.length() {
|
||||
// TODO: advance args.src if the dst pixel_buffer bounds is
|
||||
// smaller than this BMP's image bounds?
|
||||
continue.inner
|
||||
n = p0 as base.u64
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. 8 * p0])
|
||||
}
|
||||
|
||||
n = this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. 8 * p0])
|
||||
if n == 0 {
|
||||
return "@internal note: short read"
|
||||
}
|
||||
@@ -975,8 +999,9 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
|
||||
var p0 : base.u32[..= 543]
|
||||
|
||||
var chunk_bits : base.u32
|
||||
var chunk_count : base.u32
|
||||
var chunk_bits : base.u32
|
||||
var chunk_count : base.u32
|
||||
var pixels_per_chunk : base.u32[..= 32]
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
@@ -1005,8 +1030,34 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
}
|
||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
||||
if i >= dst.length() {
|
||||
// TODO: advance args.src if the dst pixel_buffer bounds is
|
||||
// smaller than this BMP's image bounds?
|
||||
if this.bits_per_pixel == 1 {
|
||||
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
|
||||
pixels_per_chunk = 32
|
||||
} else if this.bits_per_pixel == 2 {
|
||||
chunk_count = ((this.width ~sat- this.dst_x) + 15) / 16
|
||||
pixels_per_chunk = 16
|
||||
} else {
|
||||
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
|
||||
pixels_per_chunk = 8
|
||||
}
|
||||
while (chunk_count >= 64) and (args.src.length() >= 256) {
|
||||
args.src.skip_u32_fast!(actual: 256, worst_case: 256)
|
||||
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 64))
|
||||
chunk_count -= 64
|
||||
} endwhile
|
||||
while (chunk_count >= 8) and (args.src.length() >= 32) {
|
||||
args.src.skip_u32_fast!(actual: 32, worst_case: 32)
|
||||
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 8))
|
||||
chunk_count -= 8
|
||||
} endwhile
|
||||
while chunk_count > 0 {
|
||||
if args.src.length() < 4 {
|
||||
return "@internal note: short read"
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 1))
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
continue.loop
|
||||
}
|
||||
dst = dst[i ..]
|
||||
@@ -1084,7 +1135,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
|
||||
chunk_count -= 1
|
||||
} endwhile
|
||||
|
||||
} else if this.bits_per_pixel == 4 {
|
||||
} else {
|
||||
// Calculate the remaining number of 32-bit chunks. At 4 bits per
|
||||
// pixel there are 8 pixels per chunk. Division rounds up.
|
||||
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
|
||||
|
||||
@@ -201,9 +201,11 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
||||
var dst_bytes_per_row : base.u64
|
||||
var src_bytes_per_pixel : base.u32[..= 8]
|
||||
var tab : table base.u8
|
||||
var dst : slice base.u8
|
||||
var i : base.u64
|
||||
var j : base.u64
|
||||
var n : base.u64
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
@@ -232,14 +234,37 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
|
||||
}
|
||||
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
|
||||
if i >= dst.length() {
|
||||
// TODO: advance args.src if the dst pixel_buffer bounds is
|
||||
// smaller than this NIE's image bounds?
|
||||
continue
|
||||
src_bytes_per_pixel = 4
|
||||
assert src_bytes_per_pixel > 0
|
||||
if this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE {
|
||||
src_bytes_per_pixel = 8
|
||||
assert src_bytes_per_pixel > 0
|
||||
}
|
||||
n = args.src.length() / (src_bytes_per_pixel as base.u64)
|
||||
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
|
||||
j = n
|
||||
while j >= 8 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
actual: src_bytes_per_pixel * 8,
|
||||
worst_case: src_bytes_per_pixel * 8)
|
||||
}
|
||||
j -= 8
|
||||
} endwhile
|
||||
while j > 0 {
|
||||
if args.src.length() >= ((src_bytes_per_pixel * 1) as base.u64) {
|
||||
args.src.skip_u32_fast!(
|
||||
actual: src_bytes_per_pixel * 1,
|
||||
worst_case: src_bytes_per_pixel * 1)
|
||||
}
|
||||
j -= 1
|
||||
} endwhile
|
||||
} else {
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: args.dst.palette(),
|
||||
src: args.src)
|
||||
}
|
||||
n = this.swizzler.swizzle_interleaved_from_reader!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: args.dst.palette(),
|
||||
src: args.src)
|
||||
if n == 0 {
|
||||
return "@internal note: short read"
|
||||
}
|
||||
|
||||
+12
-27
@@ -241,14 +241,10 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
// IDAT chunk breaks the loop. The only other possible critical chunk is a
|
||||
// PLTE chunk. We verify PLTE checksums here but ignore other checksums.
|
||||
while true {
|
||||
while args.src.length() < 8,
|
||||
post args.src.length() >= 8,
|
||||
{
|
||||
if args.src.is_closed() {
|
||||
return "#bad chunk"
|
||||
}
|
||||
if args.src.length() < 8 {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
continue
|
||||
}
|
||||
|
||||
this.chunk_length = args.src.peek_u32be()
|
||||
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
|
||||
@@ -1053,14 +1049,10 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
||||
this.chunk_type_array[3] = 0
|
||||
|
||||
while true {
|
||||
while args.src.length() < 8,
|
||||
post args.src.length() >= 8,
|
||||
{
|
||||
if args.src.is_closed() {
|
||||
return "#bad chunk"
|
||||
}
|
||||
if args.src.length() < 8 {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
continue
|
||||
}
|
||||
|
||||
this.chunk_length = args.src.peek_u32be()
|
||||
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
|
||||
@@ -1141,14 +1133,10 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
}
|
||||
|
||||
while true {
|
||||
while args.src.length() < 8,
|
||||
post args.src.length() >= 8,
|
||||
{
|
||||
if args.src.is_closed() {
|
||||
return "#bad chunk"
|
||||
}
|
||||
if args.src.length() < 8 {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
continue
|
||||
}
|
||||
|
||||
this.chunk_length = args.src.peek_u32be()
|
||||
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
|
||||
@@ -1234,9 +1222,8 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
break
|
||||
} else if status.is_error() or
|
||||
((status == base."$short read") and args.src.is_closed()) {
|
||||
// The input was truncated or invalid. Produce whatever
|
||||
// pixels we can and then, if truncated, generate "$short
|
||||
// read" forever.
|
||||
// The input was invalid or truncated. Produce whatever
|
||||
// pixels we can.
|
||||
if this.workbuf_wi <= args.workbuf.length() {
|
||||
// This might return "#internal error: inconsistent
|
||||
// workbuf length" because of the ".. this.workbuf_wi".
|
||||
@@ -1244,9 +1231,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf[.. this.workbuf_wi])
|
||||
}
|
||||
if status == base."$short read" {
|
||||
while true {
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
return "#truncated input"
|
||||
}
|
||||
}
|
||||
yield? status
|
||||
|
||||
@@ -1026,6 +1026,7 @@ test_wuffs_strconv_parse_number_f64_regular() {
|
||||
{.want = 0x46293E5939A08CEA, .str = "1e30"},
|
||||
{.want = 0x54B249AD2594C37D, .str = "+1E+100"},
|
||||
{.want = 0x54B249AD2594C37D, .str = "+_1_E_+_1_0_0_"},
|
||||
{.want = 0x54B2987670ADB613, .str = "1.0168286519992372611942638e+100"},
|
||||
{.want = 0x7BBA44DF832B8D46, .str = "1e+288"},
|
||||
{.want = 0x7BF06B0BB1FB384C, .str = "1e+289"},
|
||||
{.want = 0x7C2485CE9E7A065F, .str = "1e+290"},
|
||||
@@ -1943,6 +1944,19 @@ test_wuffs_strconv_render_number_f64() {
|
||||
"4.000",
|
||||
.want_4g = "1e+100",
|
||||
},
|
||||
{
|
||||
.x = 0x54B2987670ADB613,
|
||||
.want__e = "1.0168286519992373e+100",
|
||||
.want__f = "10168286519992373000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000"
|
||||
"0",
|
||||
.want_0g = "1e+100",
|
||||
.want_2e = "1.02e+100",
|
||||
.want_3f = "10168286519992372611942638135241625267907715220891"
|
||||
"31363562982164291689352904657807934098133246961254"
|
||||
"4.000",
|
||||
.want_4g = "1.017e+100",
|
||||
},
|
||||
{
|
||||
.x = 0x7BBA44DF832B8D46,
|
||||
.want__e = "1e+288",
|
||||
|
||||
Reference in new issue
Block a user