mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
std/jpeg: decode RGB (not just YCbCr) JPEGs
The benchmarks don't exercise the RGB code paths per se, but it does affect the numbers. Especially for gcc, this essentially undoes the performance impact of the previous (trivial) commit. This is all presumably another code alignment coincidence per https://news.ycombinator.com/item?id=23633583 name old speed new speed delta wuffs_jpeg_decode_19k_8bpp/clang11 376MB/s ± 0% 376MB/s ± 0% ~ (p=1.000 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/clang11 338MB/s ± 0% 341MB/s ± 0% +0.98% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/clang11 1.01GB/s ± 0% 1.01GB/s ± 0% +0.35% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/clang11 841MB/s ± 0% 836MB/s ± 1% -0.65% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_420/clang11 913MB/s ± 0% 912MB/s ± 0% -0.18% (p=0.016 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/clang11 1.11GB/s ± 0% 1.10GB/s ± 0% -0.34% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/clang11 920MB/s ± 0% 916MB/s ± 0% -0.42% (p=0.008 n=5+5) wuffs_jpeg_decode_19k_8bpp/gcc10 349MB/s ± 0% 368MB/s ± 0% +5.60% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/gcc10 328MB/s ± 0% 279MB/s ± 0% -14.82% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/gcc10 925MB/s ± 0% 947MB/s ± 1% +2.33% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/gcc10 732MB/s ± 0% 770MB/s ± 0% +5.23% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_420/gcc10 798MB/s ± 0% 838MB/s ± 0% +4.99% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/gcc10 962MB/s ± 0% 996MB/s ± 0% +3.54% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/gcc10 806MB/s ± 0% 847MB/s ± 0% +5.19% (p=0.008 n=5+5)
This commit is contained in:
1 parent
748e44fe71
commit
72b9c23120
7 files changed
+429
-54
No files matched your search
@@ -69,6 +69,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v1,
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
bool is_rgb_or_cmyk,
|
||||
bool triangle_filter_for_2to1,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k);
|
||||
|
||||
|
||||
@@ -86,6 +86,24 @@ typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_func)(
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2);
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_rgb__convert_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = 0xFF000000 | //
|
||||
(((uint32_t)(*up0++)) << 16) | //
|
||||
(((uint32_t)(*up1++)) << 8) | //
|
||||
(((uint32_t)(*up2++)) << 0);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
@@ -778,6 +796,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v1,
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
bool is_rgb_or_cmyk,
|
||||
bool triangle_filter_for_2to1,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k) {
|
||||
if (!p) {
|
||||
@@ -879,34 +898,38 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_func convfunc = NULL;
|
||||
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
if (is_rgb_or_cmyk) {
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_rgb__convert_general;
|
||||
} else {
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx;
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx;
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx;
|
||||
break;
|
||||
default:
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_general;
|
||||
break;
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx;
|
||||
break;
|
||||
default:
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_general;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void (*func)(
|
||||
|
||||
@@ -675,6 +675,7 @@ var funcsOther = [...]string{
|
||||
"v1: u8[..= 4]," +
|
||||
"v2: u8[..= 4]," +
|
||||
"v3: u8[..= 4]," +
|
||||
"is_rgb_or_cmyk: bool," +
|
||||
"triangle_filter_for_2to1: bool," +
|
||||
"scratch_buffer_2k: slice u8) status",
|
||||
|
||||
|
||||
@@ -9123,6 +9123,9 @@ struct wuffs_jpeg__decoder__struct {
|
||||
uint32_t f_height_in_mcus;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_test_only_interrupt_decode_mcu;
|
||||
bool f_is_jfif;
|
||||
uint8_t f_is_adobe;
|
||||
bool f_is_rgb_or_cmyk;
|
||||
uint8_t f_sof_marker;
|
||||
uint8_t f_next_restart_marker;
|
||||
uint8_t f_max_incl_components_h;
|
||||
@@ -9192,6 +9195,7 @@ struct wuffs_jpeg__decoder__struct {
|
||||
uint32_t p_do_decode_image_config[1];
|
||||
uint32_t p_decode_dqt[1];
|
||||
uint32_t p_decode_dri[1];
|
||||
uint32_t p_decode_appn[1];
|
||||
uint32_t p_decode_sof[1];
|
||||
uint32_t p_decode_frame_config[1];
|
||||
uint32_t p_do_decode_frame_config[1];
|
||||
@@ -9234,6 +9238,9 @@ struct wuffs_jpeg__decoder__struct {
|
||||
struct {
|
||||
uint64_t scratch;
|
||||
} s_decode_dri[1];
|
||||
struct {
|
||||
uint64_t scratch;
|
||||
} s_decode_appn[1];
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint64_t scratch;
|
||||
@@ -13308,6 +13315,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v1,
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
bool is_rgb_or_cmyk,
|
||||
bool triangle_filter_for_2to1,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k);
|
||||
|
||||
@@ -23642,6 +23650,24 @@ typedef void (*wuffs_base__pixel_swizzler__swizzle_ycc__convert_func)(
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2);
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_rgb__convert_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2) {
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = 0xFF000000 | //
|
||||
(((uint32_t)(*up0++)) << 16) | //
|
||||
(((uint32_t)(*up1++)) << 8) | //
|
||||
(((uint32_t)(*up2++)) << 0);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
@@ -24334,6 +24360,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
uint8_t v1,
|
||||
uint8_t v2,
|
||||
uint8_t v3,
|
||||
bool is_rgb_or_cmyk,
|
||||
bool triangle_filter_for_2to1,
|
||||
wuffs_base__slice_u8 scratch_buffer_2k) {
|
||||
if (!p) {
|
||||
@@ -24435,34 +24462,38 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
|
||||
wuffs_base__pixel_swizzler__swizzle_ycc__convert_func convfunc = NULL;
|
||||
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
if (is_rgb_or_cmyk) {
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_rgb__convert_general;
|
||||
} else {
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx;
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_bgrx;
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
if (wuffs_base__cpu_arch__have_x86_avx2()) {
|
||||
convfunc =
|
||||
&wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx_x86_avx2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx;
|
||||
break;
|
||||
default:
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_general;
|
||||
break;
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_rgbx;
|
||||
break;
|
||||
default:
|
||||
convfunc = &wuffs_base__pixel_swizzler__swizzle_ycc__convert_general;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void (*func)(
|
||||
@@ -38817,6 +38848,13 @@ wuffs_jpeg__decoder__decode_dri(
|
||||
wuffs_jpeg__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_jpeg__decoder__decode_appn(
|
||||
wuffs_jpeg__decoder* self,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
uint8_t a_marker);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_jpeg__decoder__decode_sof(
|
||||
@@ -40953,6 +40991,18 @@ wuffs_jpeg__decoder__do_decode_image_config(
|
||||
goto exit;
|
||||
}
|
||||
} else if (v_marker < 240u) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
status = wuffs_jpeg__decoder__decode_appn(self, a_src, v_marker);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
if (v_marker == 254u) {
|
||||
} else {
|
||||
@@ -40961,7 +41011,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
|
||||
}
|
||||
}
|
||||
self->private_data.s_do_decode_image_config[0].scratch = self->private_impl.f_payload_length;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -41195,6 +41245,218 @@ wuffs_jpeg__decoder__decode_dri(
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func jpeg.decoder.decode_appn
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_jpeg__decoder__decode_appn(
|
||||
wuffs_jpeg__decoder* self,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
uint8_t a_marker) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_c8 = 0;
|
||||
uint32_t v_c32 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
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_appn[0];
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
do {
|
||||
if (a_marker == 224u) {
|
||||
if (self->private_impl.f_payload_length >= 5u) {
|
||||
self->private_impl.f_payload_length -= 5u;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint32_t t_0;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_appn[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_appn[0].scratch;
|
||||
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
|
||||
if (num_bits_0 == 24) {
|
||||
t_0 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_0 += 8u;
|
||||
*scratch |= ((uint64_t)(num_bits_0)) << 56;
|
||||
}
|
||||
}
|
||||
v_c32 = t_0;
|
||||
}
|
||||
if (v_c32 != 1179207242u) {
|
||||
self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 1u));
|
||||
break;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
v_c8 = t_1;
|
||||
}
|
||||
self->private_impl.f_is_jfif = (v_c8 == 0u);
|
||||
}
|
||||
} else if (a_marker == 238u) {
|
||||
if (self->private_impl.f_payload_length >= 12u) {
|
||||
self->private_impl.f_payload_length -= 12u;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
uint32_t t_2;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_appn[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_appn[0].scratch;
|
||||
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
|
||||
if (num_bits_2 == 24) {
|
||||
t_2 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_2 += 8u;
|
||||
*scratch |= ((uint64_t)(num_bits_2)) << 56;
|
||||
}
|
||||
}
|
||||
v_c32 = t_2;
|
||||
}
|
||||
if (v_c32 != 1651467329u) {
|
||||
self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 8u));
|
||||
break;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_appn[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_appn[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3;
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8u;
|
||||
*scratch |= ((uint64_t)(num_bits_3)) << 56;
|
||||
}
|
||||
}
|
||||
v_c32 = t_3;
|
||||
}
|
||||
if ((255u & v_c32) != 101u) {
|
||||
self->private_impl.f_payload_length = (65535u & (self->private_impl.f_payload_length + 4u));
|
||||
break;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
uint32_t t_4;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_4 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_appn[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_appn[0].scratch;
|
||||
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
|
||||
if (num_bits_4 == 24) {
|
||||
t_4 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_4 += 8u;
|
||||
*scratch |= ((uint64_t)(num_bits_4)) << 56;
|
||||
}
|
||||
}
|
||||
v_c32 = t_4;
|
||||
}
|
||||
if ((v_c32 >> 24u) == 0u) {
|
||||
self->private_impl.f_is_adobe = 1u;
|
||||
} else {
|
||||
self->private_impl.f_is_adobe = 2u;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
self->private_data.s_decode_appn[0].scratch = self->private_impl.f_payload_length;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_data.s_decode_appn[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_appn[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_decode_appn[0].scratch;
|
||||
self->private_impl.f_payload_length = 0u;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_appn[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_appn[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src && a_src->data.ptr) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func jpeg.decoder.decode_sof
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -41434,6 +41696,17 @@ wuffs_jpeg__decoder__decode_sof(
|
||||
status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_fractional_sampling);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_num_components == 4u) {
|
||||
self->private_impl.f_is_rgb_or_cmyk = (self->private_impl.f_is_adobe < 2u);
|
||||
} else {
|
||||
if (self->private_impl.f_is_jfif) {
|
||||
self->private_impl.f_is_rgb_or_cmyk = false;
|
||||
} else if (self->private_impl.f_is_adobe > 0u) {
|
||||
self->private_impl.f_is_rgb_or_cmyk = (self->private_impl.f_is_adobe == 1u);
|
||||
} else {
|
||||
self->private_impl.f_is_rgb_or_cmyk = ((self->private_impl.f_components_c[0u] == 82u) && (self->private_impl.f_components_c[1u] == 71u) && (self->private_impl.f_components_c[2u] == 66u));
|
||||
}
|
||||
}
|
||||
}
|
||||
self->private_impl.f_width_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_width, 1u, self->private_impl.f_max_incl_components_h);
|
||||
self->private_impl.f_height_in_mcus = wuffs_jpeg__decoder__quantize_dimension(self, self->private_impl.f_height, 1u, self->private_impl.f_max_incl_components_v);
|
||||
@@ -43182,6 +43455,7 @@ wuffs_jpeg__decoder__swizzle_colorful(
|
||||
self->private_impl.f_components_v[1u],
|
||||
self->private_impl.f_components_v[2u],
|
||||
self->private_impl.f_components_v[3u],
|
||||
self->private_impl.f_is_rgb_or_cmyk,
|
||||
true,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_swizzle_ycck_scratch_buffer_2k, 2048));
|
||||
return wuffs_base__status__ensure_not_a_suspension(v_status);
|
||||
|
||||
@@ -51,6 +51,10 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
test_only_interrupt_decode_mcu : base.bool,
|
||||
|
||||
is_jfif : base.bool,
|
||||
is_adobe : base.u8, // 0: no, 1: yes+RGB/CMYK, 2:yes+YCC/YCCK.
|
||||
is_rgb_or_cmyk : base.bool,
|
||||
|
||||
sof_marker : base.u8,
|
||||
next_restart_marker : base.u8[..= 7],
|
||||
|
||||
@@ -456,7 +460,8 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
}
|
||||
|
||||
} else if marker < 0xF0 { // APPn (Application specific).
|
||||
// No-op.
|
||||
this.decode_appn?(src: args.src, marker: marker)
|
||||
continue
|
||||
|
||||
} else {
|
||||
if marker == 0xFE { // COM (Comment).
|
||||
@@ -545,6 +550,60 @@ pri func decoder.decode_dri?(src: base.io_reader) {
|
||||
}
|
||||
}
|
||||
|
||||
// APPn tags are listed at https://exiftool.org/TagNames/JPEG.html
|
||||
pri func decoder.decode_appn?(src: base.io_reader, marker: base.u8) {
|
||||
var c8 : base.u8
|
||||
var c32 : base.u32
|
||||
|
||||
while.goto_done true {{
|
||||
if args.marker == 0xE0 { // APP0.
|
||||
if this.payload_length >= 5 {
|
||||
this.payload_length -= 5
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if c32 <> 'JFIF'le {
|
||||
this.payload_length = 0xFFFF & (this.payload_length + 1)
|
||||
break.goto_done
|
||||
}
|
||||
c8 = args.src.read_u8?()
|
||||
this.is_jfif = (c8 == 0)
|
||||
}
|
||||
|
||||
} else if args.marker == 0xEE { // APP14.
|
||||
if this.payload_length >= 12 {
|
||||
this.payload_length -= 12
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if c32 <> 'Adob'le {
|
||||
this.payload_length = 0xFFFF & (this.payload_length + 8)
|
||||
break.goto_done
|
||||
}
|
||||
c32 = args.src.read_u32le?()
|
||||
if (0xFF & c32) <> 'e' {
|
||||
this.payload_length = 0xFFFF & (this.payload_length + 4)
|
||||
break.goto_done
|
||||
}
|
||||
// After the 5 bytes of "Adobe" come 2 bytes of DCTEncodeVersion
|
||||
// and 4 bytes of flags. The 12th byte is the color transform.
|
||||
// Technically, 0=Unknown, 1=YCbCr and 2=YCbCrK. In practice, per
|
||||
// libjpeg-turbo, treat 0=RGB/CMYK and NonZero=YCbCr/YCbCrK.
|
||||
//
|
||||
// https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe
|
||||
c32 = args.src.read_u32le?()
|
||||
if (c32 >> 24) == 0 {
|
||||
this.is_adobe = 1
|
||||
} else {
|
||||
this.is_adobe = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
|
||||
args.src.skip_u32?(n: this.payload_length)
|
||||
this.payload_length = 0
|
||||
}
|
||||
|
||||
pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var comp_h : base.u8
|
||||
@@ -668,6 +727,22 @@ pri func decoder.decode_sof?(src: base.io_reader) {
|
||||
if (has_h24 and has_h3) or (has_v24 and has_v3) {
|
||||
return "#unsupported fractional sampling"
|
||||
}
|
||||
|
||||
// Match the behavior of libjpeg-turbo's jdapimin.c.
|
||||
if this.num_components == 4 {
|
||||
this.is_rgb_or_cmyk = this.is_adobe < 2
|
||||
} else { // this.num_components == 3
|
||||
if this.is_jfif {
|
||||
this.is_rgb_or_cmyk = false
|
||||
} else if this.is_adobe > 0 {
|
||||
this.is_rgb_or_cmyk = this.is_adobe == 1
|
||||
} else {
|
||||
this.is_rgb_or_cmyk =
|
||||
(this.components_c[0] == 'R') and
|
||||
(this.components_c[1] == 'G') and
|
||||
(this.components_c[2] == 'B')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.width_in_mcus = this.quantize_dimension(
|
||||
@@ -1903,6 +1978,7 @@ pri func decoder.swizzle_colorful!(dst: ptr base.pixel_buffer, workbuf: slice ba
|
||||
v1: this.components_v[1],
|
||||
v2: this.components_v[2],
|
||||
v3: this.components_v[3],
|
||||
is_rgb_or_cmyk: this.is_rgb_or_cmyk,
|
||||
triangle_filter_for_2to1: true,
|
||||
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
|
||||
return status
|
||||
|
||||
@@ -51,9 +51,9 @@ e00ca328 test/3pdata/blinksuite/cs-uma-cmyk-no-jfif-or-adobe-markers.jpg
|
||||
e00ca328 test/3pdata/blinksuite/cs-uma-cmyk-unknown-transform.jpg
|
||||
e00ca328 test/3pdata/blinksuite/cs-uma-cmyk.jpg
|
||||
1ec303fd test/3pdata/blinksuite/cs-uma-grayscale.jpg
|
||||
76f23a42 test/3pdata/blinksuite/cs-uma-rgb-non-interleaved.jpg
|
||||
c9eafb54 test/3pdata/blinksuite/cs-uma-rgb-non-interleaved.jpg
|
||||
528a67f1 test/3pdata/blinksuite/cs-uma-rgb-unknown-transform.jpg
|
||||
528a67f1 test/3pdata/blinksuite/cs-uma-rgb.jpg
|
||||
ebd487c5 test/3pdata/blinksuite/cs-uma-rgb.jpg
|
||||
984d8cc3 test/3pdata/blinksuite/cs-uma-ycbcr-410.jpg
|
||||
e43a491e test/3pdata/blinksuite/cs-uma-ycbcr-411.jpg
|
||||
358209c4 test/3pdata/blinksuite/cs-uma-ycbcr-420-both-jfif-adobe.jpg
|
||||
@@ -158,7 +158,7 @@ e68e3ee4 test/3pdata/blinksuite/red-half-stripe.png
|
||||
aa375741 test/3pdata/blinksuite/rgb-jpeg-blue.jpg
|
||||
724437c7 test/3pdata/blinksuite/rgb-jpeg-green.jpg
|
||||
bfebcca4 test/3pdata/blinksuite/rgb-jpeg-red.jpg
|
||||
a89ddd73 test/3pdata/blinksuite/rgb-jpeg-with-adobe-marker-only.jpg
|
||||
6ed3c2e7 test/3pdata/blinksuite/rgb-jpeg-with-adobe-marker-only.jpg
|
||||
cfb6f39d test/3pdata/blinksuite/rgb-png-with-cmyk-color-profile.png
|
||||
a3454fb7 test/3pdata/blinksuite/short-app-extension-string.gif
|
||||
2398258b test/3pdata/blinksuite/size-failure.gif
|
||||
|
||||
@@ -24,7 +24,7 @@ d8657741 test/3pdata/golangsuite/video-001.q50.422.progressive.jpeg
|
||||
2fdb8a91 test/3pdata/golangsuite/video-001.q50.440.progressive.jpeg
|
||||
efee4983 test/3pdata/golangsuite/video-001.q50.444.jpeg
|
||||
efee4983 test/3pdata/golangsuite/video-001.q50.444.progressive.jpeg
|
||||
253a7c64 test/3pdata/golangsuite/video-001.rgb.jpeg
|
||||
27869749 test/3pdata/golangsuite/video-001.rgb.jpeg
|
||||
67b4d82f test/3pdata/golangsuite/video-001.rgb.png
|
||||
f295069f test/3pdata/golangsuite/video-001.separate.dc.progression.jpeg
|
||||
f295069f test/3pdata/golangsuite/video-001.separate.dc.progression.progressive.jpeg
|
||||
|
||||
Reference in new issue
Block a user