mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 16:47:28 +01:00
std/jpeg: memoize Huffman table selectors
This commit is contained in:
1 parent
04344db374
commit
1f0f323414
6 files changed
+31
-14
No files matched your search
@@ -242,6 +242,9 @@ pub struct decoder? implements base.image_decoder(
|
||||
mcu_blocks_mx_mul : array[10] base.u32[..= 0x00_0020], // 8 * 4.
|
||||
mcu_blocks_my_mul : array[10] base.u32[..= 0x20_0100], // 8 * 4 * 0x1_0008.
|
||||
|
||||
mcu_blocks_dc_hselector : array[10] base.u8[..= 3],
|
||||
mcu_blocks_ac_hselector : array[10] base.u8[..= 7],
|
||||
|
||||
mcu_previous_dc_values : array[4] base.u16,
|
||||
|
||||
restart_interval : base.u16,
|
||||
@@ -1391,6 +1394,8 @@ pri func decoder.calculate_single_component_scan_fields!() {
|
||||
this.mcu_blocks_offset[0] = this.components_workbuf_offsets[csel]
|
||||
this.mcu_blocks_mx_mul[0] = 8
|
||||
this.mcu_blocks_my_mul[0] = 8 * this.components_workbuf_widths[csel]
|
||||
this.mcu_blocks_dc_hselector[0] = 0 | this.scan_comps_td[0]
|
||||
this.mcu_blocks_ac_hselector[0] = 4 | this.scan_comps_ta[0]
|
||||
|
||||
this.scan_width_in_mcus = this.quantize_dimension(
|
||||
width: this.width, h: this.components_h[csel], max_incl_h: this.max_incl_components_h)
|
||||
@@ -1407,6 +1412,7 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
var b : base.u32
|
||||
var bx_offset : base.u32
|
||||
var by_offset : base.u32
|
||||
var ssel : base.u8[..= 3]
|
||||
var csel : base.u8[..= 3]
|
||||
|
||||
total_hv = 0
|
||||
@@ -1450,12 +1456,15 @@ pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
b = 0
|
||||
while b < this.mcu_num_blocks {
|
||||
assert b < 10 via "a < b: a < c; c <= b"(c: this.mcu_num_blocks)
|
||||
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[b]]
|
||||
ssel = this.mcu_blocks_sselector[b]
|
||||
csel = this.scan_comps_cselector[ssel]
|
||||
this.mcu_blocks_offset[b] = this.components_workbuf_offsets[csel] +
|
||||
(8 * (this.scan_comps_bx_offset[b] as base.u64)) +
|
||||
(8 * (this.scan_comps_by_offset[b] as base.u64) * (this.components_workbuf_widths[csel] as base.u64))
|
||||
this.mcu_blocks_mx_mul[b] = 8 * (this.components_h[csel] as base.u32)
|
||||
this.mcu_blocks_my_mul[b] = 8 * (this.components_v[csel] as base.u32) * this.components_workbuf_widths[csel]
|
||||
this.mcu_blocks_dc_hselector[b] = 0 | this.scan_comps_td[ssel]
|
||||
this.mcu_blocks_ac_hselector[b] = 4 | this.scan_comps_ta[ssel]
|
||||
b += 1
|
||||
} endwhile
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
// etc_bl and etc_blm1 are the Huffman code's "bit length" and "bit length
|
||||
// minus 1" for the DC (first) and AC (later) components.
|
||||
|
||||
var dc_h : base.u8[..= 7]
|
||||
var dc_h : base.u8[..= 3]
|
||||
var dc_symbol : base.u32[..= 0x0F]
|
||||
var dc_ht_fast : base.u32
|
||||
var dc_bl : base.u32
|
||||
@@ -81,7 +81,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
n_bits |= 56
|
||||
|
||||
// Read the Huffman-encoded dc_symbol, up to 16 bits long.
|
||||
dc_h = 0 | this.scan_comps_td[this.mcu_blocks_sselector[this.mcu_current_block]]
|
||||
dc_h = this.mcu_blocks_dc_hselector[this.mcu_current_block]
|
||||
dc_ht_fast = this.huff_tables_fast[dc_h][bits >> 56] as base.u32
|
||||
dc_bl = dc_ht_fast >> 8
|
||||
if n_bits >= dc_bl {
|
||||
@@ -144,7 +144,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
n_bits |= 56
|
||||
|
||||
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
|
||||
ac_h = 4 | this.scan_comps_ta[this.mcu_blocks_sselector[this.mcu_current_block]]
|
||||
ac_h = this.mcu_blocks_ac_hselector[this.mcu_current_block]
|
||||
ac_ht_fast = this.huff_tables_fast[ac_h][bits >> 56] as base.u32
|
||||
ac_bl = ac_ht_fast >> 8
|
||||
if n_bits >= ac_bl {
|
||||
|
||||
@@ -61,7 +61,7 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
n_bits |= 56
|
||||
|
||||
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
|
||||
ac_h = 4 | this.scan_comps_ta[this.mcu_blocks_sselector[0]]
|
||||
ac_h = this.mcu_blocks_ac_hselector[0]
|
||||
ac_ht_fast = this.huff_tables_fast[ac_h][bits >> 56] as base.u32
|
||||
ac_bl = ac_ht_fast >> 8
|
||||
if n_bits >= ac_bl {
|
||||
|
||||
@@ -77,7 +77,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
|
||||
n_bits |= 56
|
||||
|
||||
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
|
||||
ac_h = 4 | this.scan_comps_ta[this.mcu_blocks_sselector[0]]
|
||||
ac_h = this.mcu_blocks_ac_hselector[0]
|
||||
ac_ht_fast = this.huff_tables_fast[ac_h][bits >> 56] as base.u32
|
||||
ac_bl = ac_ht_fast >> 8
|
||||
if n_bits >= ac_bl {
|
||||
|
||||
@@ -23,7 +23,7 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
|
||||
var r : base.io_reader
|
||||
var pos : base.u32
|
||||
|
||||
var dc_h : base.u8[..= 7]
|
||||
var dc_h : base.u8[..= 3]
|
||||
var dc_symbol : base.u32[..= 0x0F]
|
||||
var dc_ht_fast : base.u32
|
||||
var dc_bl : base.u32
|
||||
@@ -56,7 +56,7 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
|
||||
n_bits |= 56
|
||||
|
||||
// Read the Huffman-encoded dc_symbol, up to 16 bits long.
|
||||
dc_h = 0 | this.scan_comps_td[this.mcu_blocks_sselector[this.mcu_current_block]]
|
||||
dc_h = this.mcu_blocks_dc_hselector[this.mcu_current_block]
|
||||
dc_ht_fast = this.huff_tables_fast[dc_h][bits >> 56] as base.u32
|
||||
dc_bl = dc_ht_fast >> 8
|
||||
if n_bits >= dc_bl {
|
||||
|
||||
Reference in new issue
Block a user