std/jpeg: calculate number of MCUs and blocks

Updates #42
This commit is contained in:
Nigel Tao committed 2023-04-30 14:17:27 +10:00
1 parent e9b537b516
commit 6fd9767b5d
2 files changed
+344 -57

No files matched your search

+180 -32
View File
@@ -8584,6 +8584,7 @@ extern const char wuffs_jpeg__error__missing_huffman_table[];
extern const char wuffs_jpeg__error__truncated_input[];
extern const char wuffs_jpeg__error__unsupported_dqt_after_sof_markers[];
extern const char wuffs_jpeg__error__unsupported_arithmetic_coding[];
extern const char wuffs_jpeg__error__unsupported_fractional_sampling[];
extern const char wuffs_jpeg__error__unsupported_hierarchical_coding[];
extern const char wuffs_jpeg__error__unsupported_implicit_height[];
extern const char wuffs_jpeg__error__unsupported_lossless_coding[];
@@ -8745,11 +8746,15 @@ struct wuffs_jpeg__decoder__struct {
uint32_t f_height;
uint8_t f_call_sequence;
uint8_t f_sof_marker;
uint8_t f_max_incl_components_h;
uint8_t f_max_incl_components_v;
uint32_t f_num_components;
uint8_t f_components_c[4];
uint8_t f_components_h[4];
uint8_t f_components_v[4];
uint8_t f_components_tq[4];
uint32_t f_components_width_in_blocks[4];
uint32_t f_components_height_in_blocks[4];
uint32_t f_scan_num_components;
uint8_t f_scan_comps_cselector[4];
uint8_t f_scan_comps_td[4];
@@ -8758,9 +8763,13 @@ struct wuffs_jpeg__decoder__struct {
uint8_t f_scan_se;
uint8_t f_scan_ah;
uint8_t f_scan_al;
uint32_t f_scan_width_in_mcus;
uint32_t f_scan_height_in_mcus;
uint32_t f_mcu_num_blocks;
uint8_t f_mcu_blocks_sselector[16];
uint32_t f_payload_length;
uint32_t f_restart_interval;
uint32_t f_saved_restart_interval;
uint16_t f_restart_interval;
uint16_t f_saved_restart_interval;
uint64_t f_frame_config_io_position;
bool f_seen_dqt[4];
bool f_seen_dht[8];
@@ -8781,6 +8790,7 @@ struct wuffs_jpeg__decoder__struct {
uint32_t p_do_decode_frame[1];
uint32_t p_decode_dht[1];
uint32_t p_decode_sos[1];
uint32_t p_prepare_scan[1];
} private_impl;
struct {
@@ -8815,7 +8825,7 @@ struct wuffs_jpeg__decoder__struct {
} s_decode_dht[1];
struct {
uint32_t v_i;
} s_decode_sos[1];
} s_prepare_scan[1];
} private_data;
#ifdef __cplusplus
@@ -35347,6 +35357,7 @@ const char wuffs_jpeg__error__missing_huffman_table[] = "#jpeg: missing Huffman
const char wuffs_jpeg__error__truncated_input[] = "#jpeg: truncated input";
const char wuffs_jpeg__error__unsupported_dqt_after_sof_markers[] = "#jpeg: unsupported DQT after SOF markers";
const char wuffs_jpeg__error__unsupported_arithmetic_coding[] = "#jpeg: unsupported arithmetic coding";
const char wuffs_jpeg__error__unsupported_fractional_sampling[] = "#jpeg: unsupported fractional sampling";
const char wuffs_jpeg__error__unsupported_hierarchical_coding[] = "#jpeg: unsupported hierarchical coding";
const char wuffs_jpeg__error__unsupported_implicit_height[] = "#jpeg: unsupported implicit height";
const char wuffs_jpeg__error__unsupported_lossless_coding[] = "#jpeg: unsupported lossless coding";
@@ -35427,6 +35438,11 @@ wuffs_jpeg__decoder__decode_sos(
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status
wuffs_jpeg__decoder__prepare_scan(
wuffs_jpeg__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_jpeg__decoder__swizzle(
wuffs_jpeg__decoder* self,
@@ -36006,9 +36022,9 @@ wuffs_jpeg__decoder__decode_dri(
self->private_impl.f_payload_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
uint16_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_0 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
t_0 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_decode_dri[0].scratch = 0;
@@ -36024,7 +36040,7 @@ wuffs_jpeg__decoder__decode_dri(
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 8) {
t_0 = ((uint32_t)(*scratch >> 48));
t_0 = ((uint16_t)(*scratch >> 48));
break;
}
num_bits_0 += 8;
@@ -36069,6 +36085,10 @@ wuffs_jpeg__decoder__decode_sof(
uint8_t v_comp_v = 0;
uint32_t v_i = 0;
uint32_t v_j = 0;
bool v_has_h24 = false;
bool v_has_h3 = false;
bool v_has_v24 = false;
bool v_has_v3 = false;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -36228,7 +36248,13 @@ wuffs_jpeg__decoder__decode_sof(
goto exit;
}
self->private_impl.f_components_h[v_i] = v_comp_h;
if (self->private_impl.f_max_incl_components_h < self->private_impl.f_components_h[v_i]) {
self->private_impl.f_max_incl_components_h = self->private_impl.f_components_h[v_i];
}
self->private_impl.f_components_v[v_i] = v_comp_v;
if (self->private_impl.f_max_incl_components_v < self->private_impl.f_components_v[v_i]) {
self->private_impl.f_max_incl_components_v = self->private_impl.f_components_v[v_i];
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
@@ -36253,6 +36279,44 @@ wuffs_jpeg__decoder__decode_sof(
}
v_i += 1;
}
v_has_h24 = false;
v_has_h3 = false;
v_has_v24 = false;
v_has_v3 = false;
v_i = 0;
while (v_i < self->private_impl.f_num_components) {
v_has_h24 = (v_has_h24 || (self->private_impl.f_components_h[v_i] == 2) || (self->private_impl.f_components_h[v_i] == 4));
v_has_h3 = (v_has_h3 || (self->private_impl.f_components_h[v_i] == 3));
v_has_v24 = (v_has_v24 || (self->private_impl.f_components_v[v_i] == 2) || (self->private_impl.f_components_v[v_i] == 4));
v_has_v3 = (v_has_v3 || (self->private_impl.f_components_v[v_i] == 3));
v_i += 1;
}
if ((v_has_h24 && v_has_h3) || (v_has_v24 && v_has_v3)) {
status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_fractional_sampling);
goto exit;
}
v_i = 0;
while (v_i < self->private_impl.f_num_components) {
if (self->private_impl.f_components_h[v_i] == 1) {
self->private_impl.f_components_width_in_blocks[v_i] = ((self->private_impl.f_width + 7) / 8);
} else if (self->private_impl.f_components_h[v_i] == 2) {
self->private_impl.f_components_width_in_blocks[v_i] = ((self->private_impl.f_width + 15) / 16);
} else if (self->private_impl.f_components_h[v_i] == 3) {
self->private_impl.f_components_width_in_blocks[v_i] = ((self->private_impl.f_width + 23) / 24);
} else {
self->private_impl.f_components_width_in_blocks[v_i] = ((self->private_impl.f_width + 31) / 32);
}
if (self->private_impl.f_components_v[v_i] == 1) {
self->private_impl.f_components_height_in_blocks[v_i] = ((self->private_impl.f_height + 7) / 8);
} else if (self->private_impl.f_components_v[v_i] == 2) {
self->private_impl.f_components_height_in_blocks[v_i] = ((self->private_impl.f_height + 15) / 16);
} else if (self->private_impl.f_components_v[v_i] == 3) {
self->private_impl.f_components_height_in_blocks[v_i] = ((self->private_impl.f_height + 23) / 24);
} else {
self->private_impl.f_components_height_in_blocks[v_i] = ((self->private_impl.f_height + 31) / 32);
}
v_i += 1;
}
goto ok;
ok:
@@ -37012,11 +37076,72 @@ wuffs_jpeg__decoder__decode_sos(
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_restarts = 0;
uint32_t v_my = 0;
uint32_t v_mx = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_sos[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_jpeg__decoder__prepare_scan(self, a_src);
if (status.repr) {
goto suspend;
}
v_restarts = ((uint32_t)(self->private_impl.f_restart_interval));
v_my = 0;
while (v_my < self->private_impl.f_scan_height_in_mcus) {
v_mx = 0;
while (v_mx < self->private_impl.f_scan_width_in_mcus) {
if (v_restarts > 0) {
v_restarts -= 1;
if (v_restarts == 0) {
}
}
v_mx += 1;
}
v_my += 1;
}
v_status = wuffs_jpeg__decoder__swizzle(self, a_dst);
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;
ok:
self->private_impl.p_decode_sos[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_sos[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
return status;
}
// -------- func jpeg.decoder.prepare_scan
static wuffs_base__status
wuffs_jpeg__decoder__prepare_scan(
wuffs_jpeg__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint32_t v_i = 0;
uint32_t v_j = 0;
uint32_t v_hv = 0;
uint32_t v_total_hv = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t v_b = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -37029,9 +37154,9 @@ wuffs_jpeg__decoder__decode_sos(
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_sos[0];
uint32_t coro_susp_point = self->private_impl.p_prepare_scan[0];
if (coro_susp_point) {
v_i = self->private_data.s_decode_sos[0].v_i;
v_i = self->private_data.s_prepare_scan[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -37118,18 +37243,6 @@ wuffs_jpeg__decoder__decode_sos(
}
v_i += 1;
}
if (self->private_impl.f_scan_num_components > 1) {
v_total_hv = 0;
v_i = 0;
while (v_i < self->private_impl.f_scan_num_components) {
v_total_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_i += 1;
}
if (v_total_hv > 10) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker);
goto exit;
}
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
@@ -37173,25 +37286,60 @@ wuffs_jpeg__decoder__decode_sos(
}
self->private_impl.f_scan_ah = (v_c >> 4);
self->private_impl.f_scan_al = (v_c & 15);
v_status = wuffs_jpeg__decoder__swizzle(self, a_dst);
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;
if (self->private_impl.f_scan_num_components == 1) {
self->private_impl.f_scan_width_in_mcus = self->private_impl.f_components_width_in_blocks[self->private_impl.f_scan_comps_cselector[0]];
self->private_impl.f_scan_height_in_mcus = self->private_impl.f_components_height_in_blocks[self->private_impl.f_scan_comps_cselector[0]];
self->private_impl.f_mcu_num_blocks = 1;
self->private_impl.f_mcu_blocks_sselector[0] = 0;
} else {
if (self->private_impl.f_max_incl_components_h == 1) {
self->private_impl.f_scan_width_in_mcus = ((self->private_impl.f_width + 7) / 8);
} else if (self->private_impl.f_max_incl_components_h == 2) {
self->private_impl.f_scan_width_in_mcus = ((self->private_impl.f_width + 15) / 16);
} else if (self->private_impl.f_max_incl_components_h == 3) {
self->private_impl.f_scan_width_in_mcus = ((self->private_impl.f_width + 23) / 24);
} else {
self->private_impl.f_scan_width_in_mcus = ((self->private_impl.f_width + 31) / 32);
}
if (self->private_impl.f_max_incl_components_v == 1) {
self->private_impl.f_scan_height_in_mcus = ((self->private_impl.f_height + 7) / 8);
} else if (self->private_impl.f_max_incl_components_v == 2) {
self->private_impl.f_scan_height_in_mcus = ((self->private_impl.f_height + 15) / 16);
} else if (self->private_impl.f_max_incl_components_v == 3) {
self->private_impl.f_scan_height_in_mcus = ((self->private_impl.f_height + 23) / 24);
} else {
self->private_impl.f_scan_height_in_mcus = ((self->private_impl.f_height + 31) / 32);
}
v_total_hv = 0;
v_i = 0;
v_b = 0;
while (v_i < self->private_impl.f_scan_num_components) {
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_mcu_blocks_sselector[(v_b & 15)] = ((uint8_t)(v_i));
v_b += 1;
v_hv -= 1;
}
v_i += 1;
}
if (v_total_hv > 10) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker);
goto exit;
}
self->private_impl.f_mcu_num_blocks = v_total_hv;
}
goto ok;
goto ok;
ok:
self->private_impl.p_decode_sos[0] = 0;
self->private_impl.p_prepare_scan[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_sos[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_sos[0].v_i = v_i;
self->private_impl.p_prepare_scan[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_prepare_scan[0].v_i = v_i;
goto exit;
exit:
+164 -25
View File
@@ -23,6 +23,7 @@ pub status "#missing Huffman table"
pub status "#truncated input"
pub status "#unsupported DQT after SOF markers"
pub status "#unsupported arithmetic coding"
pub status "#unsupported fractional sampling"
pub status "#unsupported hierarchical coding"
pub status "#unsupported implicit height"
pub status "#unsupported lossless coding"
@@ -43,12 +44,18 @@ pub struct decoder? implements base.image_decoder(
sof_marker : base.u8,
max_incl_components_h : base.u8[..= 4],
max_incl_components_v : base.u8[..= 4],
num_components : base.u32[..= 4],
components_c : array[4] base.u8,
components_h : array[4] base.u8[..= 4],
components_v : array[4] base.u8[..= 4],
components_tq : array[4] base.u8[..= 4],
components_width_in_blocks : array[4] base.u32[..= 0x2000],
components_height_in_blocks : array[4] base.u32[..= 0x2000],
scan_num_components : base.u32[..= 4],
scan_comps_cselector : array[4] base.u8[..= 3],
scan_comps_td : array[4] base.u8[..= 3],
@@ -59,10 +66,16 @@ pub struct decoder? implements base.image_decoder(
scan_ah : base.u8[..= 13],
scan_al : base.u8[..= 13],
scan_width_in_mcus : base.u32[..= 0x2000],
scan_height_in_mcus : base.u32[..= 0x2000],
mcu_num_blocks : base.u32[..= 10],
mcu_blocks_sselector : array[16] base.u8[..= 3],
payload_length : base.u32[..= 0xFFFF],
restart_interval : base.u32[..= 0xFFFF],
saved_restart_interval : base.u32[..= 0xFFFF],
restart_interval : base.u16,
saved_restart_interval : base.u16,
frame_config_io_position : base.u64,
@@ -293,18 +306,22 @@ pri func decoder.decode_dri?(src: base.io_reader) {
}
this.payload_length = 0
this.restart_interval = args.src.read_u16be_as_u32?()
this.restart_interval = args.src.read_u16be?()
if this.sof_marker == 0 {
this.saved_restart_interval = this.restart_interval
}
}
pri func decoder.decode_sof?(src: base.io_reader) {
var c : base.u8
var comp_h : base.u8
var comp_v : base.u8
var i : base.u32
var j : base.u32
var c : base.u8
var comp_h : base.u8
var comp_v : base.u8
var i : base.u32
var j : base.u32
var has_h24 : base.bool
var has_h3 : base.bool
var has_v24 : base.bool
var has_v3 : base.bool
if this.payload_length < 6 {
return "#bad SOF marker"
@@ -349,7 +366,13 @@ pri func decoder.decode_sof?(src: base.io_reader) {
return "#bad SOF marker"
}
this.components_h[i] = comp_h
if this.max_incl_components_h < this.components_h[i] {
this.max_incl_components_h = this.components_h[i]
}
this.components_v[i] = comp_v
if this.max_incl_components_v < this.components_v[i] {
this.max_incl_components_v = this.components_v[i]
}
c = args.src.read_u8?()
if c > 4 {
return "#bad SOF marker"
@@ -371,6 +394,50 @@ pri func decoder.decode_sof?(src: base.io_reader) {
i += 1
} endwhile
has_h24 = false
has_h3 = false
has_v24 = false
has_v3 = false
i = 0
while i < this.num_components {
assert i < 4 via "a < b: a < c; c <= b"(c: this.num_components)
has_h24 = has_h24 or (this.components_h[i] == 2) or (this.components_h[i] == 4)
has_h3 = has_h3 or (this.components_h[i] == 3)
has_v24 = has_v24 or (this.components_v[i] == 2) or (this.components_v[i] == 4)
has_v3 = has_v3 or (this.components_v[i] == 3)
i += 1
} endwhile
if (has_h24 and has_h3) or (has_v24 and has_v3) {
return "#unsupported fractional sampling"
}
i = 0
while i < this.num_components {
assert i < 4 via "a < b: a < c; c <= b"(c: this.num_components)
if this.components_h[i] == 1 {
this.components_width_in_blocks[i] = (this.width + 0x07) / 0x08
} else if this.components_h[i] == 2 {
this.components_width_in_blocks[i] = (this.width + 0x0F) / 0x10
} else if this.components_h[i] == 3 {
this.components_width_in_blocks[i] = (this.width + 0x17) / 0x18
} else {
this.components_width_in_blocks[i] = (this.width + 0x1F) / 0x20
}
if this.components_v[i] == 1 {
this.components_height_in_blocks[i] = (this.height + 0x07) / 0x08
} else if this.components_v[i] == 2 {
this.components_height_in_blocks[i] = (this.height + 0x0F) / 0x10
} else if this.components_v[i] == 3 {
this.components_height_in_blocks[i] = (this.height + 0x17) / 0x18
} else {
this.components_height_in_blocks[i] = (this.height + 0x1F) / 0x20
}
i += 1
} endwhile
}
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
@@ -753,11 +820,48 @@ pri func decoder.calculate_huff_tables!(tc4_th: base.u8[..= 7], total_count: bas
}
pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, workbuf: slice base.u8) {
var restarts : base.u32
var my : base.u32
var mx : base.u32
var status : base.status
this.prepare_scan?(src: args.src)
restarts = this.restart_interval as base.u32
my = 0
while my < this.scan_height_in_mcus {
assert my < 0x2000 via "a < b: a < c; c <= b"(c: this.scan_height_in_mcus)
mx = 0
while mx < this.scan_width_in_mcus,
inv my < 0x2000,
{
assert mx < 0x2000 via "a < b: a < c; c <= b"(c: this.scan_width_in_mcus)
// TODO: decode the MCU.
if restarts > 0 {
restarts -= 1
if restarts == 0 {
// TODO.
}
}
mx += 1
} endwhile
my += 1
} endwhile
status = this.swizzle!(dst: args.dst)
return status
}
pri func decoder.prepare_scan?(src: base.io_reader) {
var c : base.u8
var i : base.u32
var j : base.u32
var hv : base.u32[..= 16]
var total_hv : base.u32
var status : base.status
var b : base.u32
if (this.payload_length < 6) or (this.payload_length > 12) {
return "#bad SOS marker"
@@ -825,20 +929,6 @@ pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, wo
i += 1
} endwhile
if this.scan_num_components > 1 {
total_hv = 0
i = 0
while i < this.scan_num_components {
assert i < 4 via "a < b: a < c; c <= b"(c: this.scan_num_components)
total_hv ~mod+= ((this.components_h[this.scan_comps_cselector[i]] as base.u32) *
(this.components_v[this.scan_comps_cselector[i]] as base.u32))
i += 1
} endwhile
if total_hv > 10 {
return "#bad SOS marker"
}
}
c = args.src.read_u8?()
if c > 63 {
return "#bad SOS marker"
@@ -862,8 +952,57 @@ pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, wo
// that (Ss, Se, Ah, Al) is (0, 63, 0, 0) but libjpeg treats otherwise as a
// warning (JWRN_NOT_SEQUENTIAL), not an error.
status = this.swizzle!(dst: args.dst)
return status
if this.scan_num_components == 1 {
this.scan_width_in_mcus = this.components_width_in_blocks[this.scan_comps_cselector[0]]
this.scan_height_in_mcus = this.components_height_in_blocks[this.scan_comps_cselector[0]]
this.mcu_num_blocks = 1
this.mcu_blocks_sselector[0] = 0
} else {
if this.max_incl_components_h == 1 {
this.scan_width_in_mcus = (this.width + 0x07) / 0x08
} else if this.max_incl_components_h == 2 {
this.scan_width_in_mcus = (this.width + 0x0F) / 0x10
} else if this.max_incl_components_h == 3 {
this.scan_width_in_mcus = (this.width + 0x17) / 0x18
} else {
this.scan_width_in_mcus = (this.width + 0x1F) / 0x20
}
if this.max_incl_components_v == 1 {
this.scan_height_in_mcus = (this.height + 0x07) / 0x08
} else if this.max_incl_components_v == 2 {
this.scan_height_in_mcus = (this.height + 0x0F) / 0x10
} else if this.max_incl_components_v == 3 {
this.scan_height_in_mcus = (this.height + 0x17) / 0x18
} else {
this.scan_height_in_mcus = (this.height + 0x1F) / 0x20
}
total_hv = 0
i = 0
b = 0
while i < this.scan_num_components {
assert i < 4 via "a < b: a < c; c <= b"(c: this.scan_num_components)
hv = ((this.components_h[this.scan_comps_cselector[i]] as base.u32) *
(this.components_v[this.scan_comps_cselector[i]] as base.u32))
total_hv ~mod+= hv
while hv > 0,
inv i < 4,
{
this.mcu_blocks_sselector[b & 15] = i as base.u8
b ~mod+= 1
hv -= 1
} endwhile
i += 1
} endwhile
if total_hv > 10 {
return "#bad SOS marker"
}
this.mcu_num_blocks = total_hv
}
}
pri func decoder.swizzle!(dst: ptr base.pixel_buffer) base.status {