mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 17:01:35 +01:00
std/jpeg: factor out calculate_multiple_competc
This commit is contained in:
1 parent
2f18dc61d0
commit
238aadd8eb
2 files changed
+106
-78
No files matched your search
@@ -36856,6 +36856,10 @@ static wuffs_base__empty_struct
|
||||
wuffs_jpeg__decoder__calculate_single_component_scan_fields(
|
||||
wuffs_jpeg__decoder* self);
|
||||
|
||||
static bool
|
||||
wuffs_jpeg__decoder__calculate_multiple_component_scan_fields(
|
||||
wuffs_jpeg__decoder* self);
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_jpeg__decoder__fill_bitstream(
|
||||
wuffs_jpeg__decoder* self,
|
||||
@@ -39618,14 +39622,7 @@ wuffs_jpeg__decoder__prepare_scan(
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_h = 0;
|
||||
uint32_t v_v = 0;
|
||||
uint32_t v_hv = 0;
|
||||
uint32_t v_total_hv = 0;
|
||||
uint32_t v_b = 0;
|
||||
uint32_t v_bx_offset = 0;
|
||||
uint32_t v_by_offset = 0;
|
||||
uint8_t v_csel = 0;
|
||||
bool v_failed = false;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
@@ -39826,48 +39823,11 @@ wuffs_jpeg__decoder__prepare_scan(
|
||||
if (self->private_impl.f_scan_num_components == 1) {
|
||||
wuffs_jpeg__decoder__calculate_single_component_scan_fields(self);
|
||||
} else {
|
||||
v_total_hv = 0;
|
||||
v_i = 0;
|
||||
v_b = 0;
|
||||
v_bx_offset = 0;
|
||||
v_by_offset = 0;
|
||||
while (v_i < self->private_impl.f_scan_num_components) {
|
||||
v_h = ((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]]));
|
||||
v_v = ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]]));
|
||||
v_hv = (((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]])) * ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]])));
|
||||
v_total_hv += v_hv;
|
||||
while (v_hv > 0) {
|
||||
self->private_impl.f_scan_comps_bx_offset[(v_b & 15)] = ((uint8_t)((v_bx_offset & 3)));
|
||||
self->private_impl.f_scan_comps_by_offset[(v_b & 15)] = ((uint8_t)((v_by_offset & 3)));
|
||||
self->private_impl.f_mcu_blocks_sselector[(v_b & 15)] = ((uint8_t)(v_i));
|
||||
v_b += 1;
|
||||
v_bx_offset += 1;
|
||||
if (v_bx_offset == v_h) {
|
||||
v_bx_offset = 0;
|
||||
v_by_offset += 1;
|
||||
if (v_by_offset == v_v) {
|
||||
v_by_offset = 0;
|
||||
}
|
||||
}
|
||||
v_hv -= 1;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_total_hv > 10) {
|
||||
v_failed = wuffs_jpeg__decoder__calculate_multiple_component_scan_fields(self);
|
||||
if (v_failed) {
|
||||
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_mcu_num_blocks = v_total_hv;
|
||||
v_b = 0;
|
||||
while (v_b < self->private_impl.f_mcu_num_blocks) {
|
||||
v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_b]];
|
||||
self->private_impl.f_mcu_blocks_offset[v_b] = (self->private_impl.f_components_workbuf_offsets[v_csel] + (8 * ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) + (8 * ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b])) * ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel]))));
|
||||
self->private_impl.f_mcu_blocks_mx_mul[v_b] = (8 * ((uint32_t)(self->private_impl.f_components_h[v_csel])));
|
||||
self->private_impl.f_mcu_blocks_my_mul[v_b] = (8 * ((uint32_t)(self->private_impl.f_components_v[v_csel])) * self->private_impl.f_components_workbuf_widths[v_csel]);
|
||||
v_b += 1;
|
||||
}
|
||||
self->private_impl.f_scan_width_in_mcus = self->private_impl.f_width_in_mcus;
|
||||
self->private_impl.f_scan_height_in_mcus = self->private_impl.f_height_in_mcus;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
@@ -39910,6 +39870,65 @@ wuffs_jpeg__decoder__calculate_single_component_scan_fields(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func jpeg.decoder.calculate_multiple_component_scan_fields
|
||||
|
||||
static bool
|
||||
wuffs_jpeg__decoder__calculate_multiple_component_scan_fields(
|
||||
wuffs_jpeg__decoder* self) {
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_h = 0;
|
||||
uint32_t v_v = 0;
|
||||
uint32_t v_hv = 0;
|
||||
uint32_t v_total_hv = 0;
|
||||
uint32_t v_b = 0;
|
||||
uint32_t v_bx_offset = 0;
|
||||
uint32_t v_by_offset = 0;
|
||||
uint8_t v_csel = 0;
|
||||
|
||||
v_total_hv = 0;
|
||||
v_i = 0;
|
||||
v_b = 0;
|
||||
v_bx_offset = 0;
|
||||
v_by_offset = 0;
|
||||
while (v_i < self->private_impl.f_scan_num_components) {
|
||||
v_h = ((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]]));
|
||||
v_v = ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]]));
|
||||
v_hv = (((uint32_t)(self->private_impl.f_components_h[self->private_impl.f_scan_comps_cselector[v_i]])) * ((uint32_t)(self->private_impl.f_components_v[self->private_impl.f_scan_comps_cselector[v_i]])));
|
||||
v_total_hv += v_hv;
|
||||
while (v_hv > 0) {
|
||||
self->private_impl.f_scan_comps_bx_offset[(v_b & 15)] = ((uint8_t)((v_bx_offset & 3)));
|
||||
self->private_impl.f_scan_comps_by_offset[(v_b & 15)] = ((uint8_t)((v_by_offset & 3)));
|
||||
self->private_impl.f_mcu_blocks_sselector[(v_b & 15)] = ((uint8_t)(v_i));
|
||||
v_b += 1;
|
||||
v_bx_offset += 1;
|
||||
if (v_bx_offset == v_h) {
|
||||
v_bx_offset = 0;
|
||||
v_by_offset += 1;
|
||||
if (v_by_offset == v_v) {
|
||||
v_by_offset = 0;
|
||||
}
|
||||
}
|
||||
v_hv -= 1;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_total_hv > 10) {
|
||||
return true;
|
||||
}
|
||||
self->private_impl.f_mcu_num_blocks = v_total_hv;
|
||||
v_b = 0;
|
||||
while (v_b < self->private_impl.f_mcu_num_blocks) {
|
||||
v_csel = self->private_impl.f_scan_comps_cselector[self->private_impl.f_mcu_blocks_sselector[v_b]];
|
||||
self->private_impl.f_mcu_blocks_offset[v_b] = (self->private_impl.f_components_workbuf_offsets[v_csel] + (8 * ((uint64_t)(self->private_impl.f_scan_comps_bx_offset[v_b]))) + (8 * ((uint64_t)(self->private_impl.f_scan_comps_by_offset[v_b])) * ((uint64_t)(self->private_impl.f_components_workbuf_widths[v_csel]))));
|
||||
self->private_impl.f_mcu_blocks_mx_mul[v_b] = (8 * ((uint32_t)(self->private_impl.f_components_h[v_csel])));
|
||||
self->private_impl.f_mcu_blocks_my_mul[v_b] = (8 * ((uint32_t)(self->private_impl.f_components_v[v_csel])) * self->private_impl.f_components_workbuf_widths[v_csel]);
|
||||
v_b += 1;
|
||||
}
|
||||
self->private_impl.f_scan_width_in_mcus = self->private_impl.f_width_in_mcus;
|
||||
self->private_impl.f_scan_height_in_mcus = self->private_impl.f_height_in_mcus;
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------- func jpeg.decoder.fill_bitstream
|
||||
|
||||
static wuffs_base__empty_struct
|
||||
|
||||
+40
-31
@@ -1259,14 +1259,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var i : base.u32
|
||||
var j : base.u32
|
||||
var h : base.u32[..= 4]
|
||||
var v : base.u32[..= 4]
|
||||
var hv : base.u32[..= 16]
|
||||
var total_hv : base.u32
|
||||
var b : base.u32
|
||||
var bx_offset : base.u32
|
||||
var by_offset : base.u32
|
||||
var csel : base.u8[..= 3]
|
||||
var failed : base.bool
|
||||
|
||||
if (this.payload_length < 6) or (this.payload_length > 12) {
|
||||
return "#bad SOS marker"
|
||||
@@ -1402,8 +1395,44 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
|
||||
if this.scan_num_components == 1 {
|
||||
this.calculate_single_component_scan_fields!()
|
||||
|
||||
} else {
|
||||
failed = this.calculate_multiple_component_scan_fields!()
|
||||
if failed {
|
||||
return "#bad SOS marker"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.calculate_single_component_scan_fields!() {
|
||||
var csel : base.u8[..= 3]
|
||||
|
||||
this.scan_comps_bx_offset[0] = 0
|
||||
this.scan_comps_by_offset[0] = 0
|
||||
this.mcu_num_blocks = 1
|
||||
this.mcu_blocks_sselector[0] = 0
|
||||
|
||||
csel = this.scan_comps_cselector[0]
|
||||
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.scan_width_in_mcus = this.quantize_dimension(
|
||||
width: this.width, h: this.components_h[csel], max_incl_h: this.max_incl_components_h)
|
||||
this.scan_height_in_mcus = this.quantize_dimension(
|
||||
width: this.height, h: this.components_v[csel], max_incl_h: this.max_incl_components_v)
|
||||
}
|
||||
|
||||
pri func decoder.calculate_multiple_component_scan_fields!() base.bool {
|
||||
var i : base.u32
|
||||
var h : base.u32[..= 4]
|
||||
var v : base.u32[..= 4]
|
||||
var hv : base.u32[..= 16]
|
||||
var total_hv : base.u32
|
||||
var b : base.u32
|
||||
var bx_offset : base.u32
|
||||
var by_offset : base.u32
|
||||
var csel : base.u8[..= 3]
|
||||
|
||||
total_hv = 0
|
||||
i = 0
|
||||
b = 0
|
||||
@@ -1438,7 +1467,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
i += 1
|
||||
} endwhile
|
||||
if total_hv > 10 {
|
||||
return "#bad SOS marker"
|
||||
return true
|
||||
}
|
||||
this.mcu_num_blocks = total_hv
|
||||
|
||||
@@ -1456,27 +1485,7 @@ pri func decoder.prepare_scan?(src: base.io_reader) {
|
||||
|
||||
this.scan_width_in_mcus = this.width_in_mcus
|
||||
this.scan_height_in_mcus = this.height_in_mcus
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.calculate_single_component_scan_fields!() {
|
||||
var csel : base.u8[..= 3]
|
||||
|
||||
this.scan_comps_bx_offset[0] = 0
|
||||
this.scan_comps_by_offset[0] = 0
|
||||
this.mcu_num_blocks = 1
|
||||
this.mcu_blocks_sselector[0] = 0
|
||||
|
||||
csel = this.scan_comps_cselector[0]
|
||||
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.scan_width_in_mcus = this.quantize_dimension(
|
||||
width: this.width, h: this.components_h[csel], max_incl_h: this.max_incl_components_h)
|
||||
this.scan_height_in_mcus = this.quantize_dimension(
|
||||
width: this.height, h: this.components_v[csel], max_incl_h: this.max_incl_components_v)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
pri func decoder.fill_bitstream!(src: base.io_reader) {
|
||||
|
||||
Reference in new issue
Block a user