mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
std/jpeg: avoid unnecessary swizzles
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59540 name old speed new speed delta wuffs_jpeg_decode_30k_24bpp_progressive/clang11 32.4MB/s ± 0% 84.6MB/s ± 0% +160.78% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/gcc10 38.6MB/s ± 0% 93.8MB/s ± 0% +142.75% (p=0.008 n=5+5)
This commit is contained in:
1 parent
e5c92a0ce3
commit
442533f08c
2 files changed
+48
-37
No files matched your search
@@ -8812,6 +8812,7 @@ struct wuffs_jpeg__decoder__struct {
|
||||
uint32_t f_components_workbuf_widths[4];
|
||||
uint32_t f_components_workbuf_heights[4];
|
||||
uint64_t f_components_workbuf_offsets[9];
|
||||
uint32_t f_scan_count;
|
||||
uint32_t f_scan_num_components;
|
||||
uint8_t f_scan_comps_cselector[4];
|
||||
uint8_t f_scan_comps_td[4];
|
||||
@@ -38849,13 +38850,16 @@ wuffs_jpeg__decoder__decode_frame(
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
wuffs_base__status v_ddf_status = wuffs_base__make_status(NULL);
|
||||
wuffs_base__status v_swizzle_status = wuffs_base__make_status(NULL);
|
||||
uint32_t v_scan_count = 0;
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
while (true) {
|
||||
v_scan_count = self->private_impl.f_scan_count;
|
||||
{
|
||||
wuffs_base__status t_0 = wuffs_jpeg__decoder__do_decode_frame(self,
|
||||
a_dst,
|
||||
@@ -38863,13 +38867,27 @@ wuffs_jpeg__decoder__decode_frame(
|
||||
a_blend,
|
||||
a_workbuf,
|
||||
a_opts);
|
||||
v_status = t_0;
|
||||
v_ddf_status = t_0;
|
||||
}
|
||||
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
|
||||
if (wuffs_base__status__is_error(&v_ddf_status)) {
|
||||
status = v_ddf_status;
|
||||
goto exit;
|
||||
} else if (v_scan_count < self->private_impl.f_scan_count) {
|
||||
if (self->private_impl.f_num_components == 1) {
|
||||
v_swizzle_status = wuffs_jpeg__decoder__swizzle_gray(self, a_dst, a_workbuf);
|
||||
} else {
|
||||
v_swizzle_status = wuffs_jpeg__decoder__swizzle_colorful(self, a_dst, a_workbuf);
|
||||
}
|
||||
if (wuffs_base__status__is_error(&v_swizzle_status)) {
|
||||
status = v_swizzle_status;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
if ((v_ddf_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
|
||||
status = wuffs_base__make_status(wuffs_jpeg__error__truncated_input);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
status = v_ddf_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
@@ -39445,7 +39463,6 @@ wuffs_jpeg__decoder__decode_sos(
|
||||
uint8_t v_csel = 0;
|
||||
uint64_t v_stride = 0;
|
||||
uint64_t v_offset = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_sos[0];
|
||||
if (coro_susp_point) {
|
||||
@@ -39551,26 +39568,7 @@ wuffs_jpeg__decoder__decode_sos(
|
||||
}
|
||||
v_my += 1;
|
||||
}
|
||||
if (self->private_impl.f_num_components == 1) {
|
||||
v_status = wuffs_jpeg__decoder__swizzle_gray(self, a_dst, a_workbuf);
|
||||
status = v_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
v_status = wuffs_jpeg__decoder__swizzle_colorful(self, a_dst, a_workbuf);
|
||||
status = v_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_scan_count, 1);
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_sos[0] = 0;
|
||||
@@ -40342,6 +40340,7 @@ wuffs_jpeg__decoder__restart_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 40;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
self->private_impl.f_scan_count = 0;
|
||||
self->private_impl.f_restart_interval = self->private_impl.f_saved_restart_interval;
|
||||
while (v_i < 4) {
|
||||
self->private_impl.f_seen_dqt[v_i] = self->private_impl.f_saved_seen_dqt[v_i];
|
||||
|
||||
+24
-12
@@ -116,6 +116,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
components_workbuf_heights : array[4] base.u32[..= 0x1_0008],
|
||||
components_workbuf_offsets : array[9] base.u64[..= 0xC_00C0_0300], // 12 * 0x1_0008 * 0x1_0008.
|
||||
|
||||
scan_count : base.u32,
|
||||
scan_num_components : base.u32[..= 4],
|
||||
scan_comps_cselector : array[4] base.u8[..= 3],
|
||||
scan_comps_td : array[4] base.u8[..= 3],
|
||||
@@ -752,14 +753,31 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var status : base.status
|
||||
var ddf_status : base.status
|
||||
var swizzle_status : base.status
|
||||
var scan_count : base.u32
|
||||
|
||||
while true {
|
||||
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
if (status == base."$short read") and args.src.is_closed() {
|
||||
scan_count = this.scan_count
|
||||
ddf_status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
if ddf_status.is_error() {
|
||||
return ddf_status
|
||||
|
||||
} else if scan_count < this.scan_count {
|
||||
if this.num_components == 1 {
|
||||
swizzle_status = this.swizzle_gray!(dst: args.dst, workbuf: args.workbuf)
|
||||
} else {
|
||||
swizzle_status = this.swizzle_colorful!(dst: args.dst, workbuf: args.workbuf)
|
||||
}
|
||||
if swizzle_status.is_error() {
|
||||
return swizzle_status
|
||||
}
|
||||
}
|
||||
|
||||
if (ddf_status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
yield? ddf_status
|
||||
} endwhile
|
||||
}
|
||||
|
||||
@@ -1125,8 +1143,6 @@ pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, wo
|
||||
var stride : base.u64[..= 0x1_0008]
|
||||
var offset : base.u64
|
||||
|
||||
var status : base.status
|
||||
|
||||
this.prepare_scan?(src: args.src)
|
||||
|
||||
// Reset.
|
||||
@@ -1236,12 +1252,7 @@ pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, wo
|
||||
my += 1
|
||||
} endwhile
|
||||
|
||||
if this.num_components == 1 {
|
||||
status = this.swizzle_gray!(dst: args.dst, workbuf: args.workbuf)
|
||||
return status
|
||||
}
|
||||
status = this.swizzle_colorful!(dst: args.dst, workbuf: args.workbuf)
|
||||
return status
|
||||
this.scan_count ~sat+= 1
|
||||
}
|
||||
|
||||
pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
@@ -1809,6 +1820,7 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
}
|
||||
this.call_sequence = 0x28
|
||||
this.frame_config_io_position = args.io_position
|
||||
this.scan_count = 0
|
||||
this.restart_interval = this.saved_restart_interval
|
||||
while i < 4 {
|
||||
this.seen_dqt[i] = this.saved_seen_dqt[i]
|
||||
|
||||
Reference in new issue
Block a user