mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 17:01:35 +01:00
Implement bmp.decoder.skip_frame
This commit is contained in:
1 parent
f69f849f11
commit
8378d9f3b4
3 files changed
+130
-2
No files matched your search
@@ -3257,6 +3257,7 @@ struct wuffs_bmp__decoder__struct {
|
|||||||
uint32_t p_decode_image_config[1];
|
uint32_t p_decode_image_config[1];
|
||||||
uint32_t p_decode_frame_config[1];
|
uint32_t p_decode_frame_config[1];
|
||||||
uint32_t p_decode_frame[1];
|
uint32_t p_decode_frame[1];
|
||||||
|
uint32_t p_skip_frame[1];
|
||||||
} private_impl;
|
} private_impl;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@@ -3267,6 +3268,11 @@ struct wuffs_bmp__decoder__struct {
|
|||||||
struct {
|
struct {
|
||||||
uint64_t scratch;
|
uint64_t scratch;
|
||||||
} s_decode_frame[1];
|
} s_decode_frame[1];
|
||||||
|
struct {
|
||||||
|
uint64_t v_bytes_per_row;
|
||||||
|
uint32_t v_y;
|
||||||
|
uint64_t scratch;
|
||||||
|
} s_skip_frame[1];
|
||||||
} private_data;
|
} private_data;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -7366,6 +7372,8 @@ wuffs_adler32__hasher__update_u32(wuffs_adler32__hasher* self,
|
|||||||
const char* wuffs_bmp__error__bad_header = "#bmp: bad header";
|
const char* wuffs_bmp__error__bad_header = "#bmp: bad header";
|
||||||
const char* wuffs_bmp__error__unsupported_bmp_file =
|
const char* wuffs_bmp__error__unsupported_bmp_file =
|
||||||
"#bmp: unsupported BMP file";
|
"#bmp: unsupported BMP file";
|
||||||
|
const char* wuffs_bmp__error__internal_error_inconsistent_bpp =
|
||||||
|
"#bmp: internal error: inconsistent bpp";
|
||||||
|
|
||||||
// ---------------- Private Consts
|
// ---------------- Private Consts
|
||||||
|
|
||||||
@@ -8105,12 +8113,83 @@ wuffs_bmp__decoder__skip_frame(wuffs_bmp__decoder* self,
|
|||||||
wuffs_base__io_buffer* a_src) {
|
wuffs_base__io_buffer* a_src) {
|
||||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||||
|
|
||||||
|
uint64_t v_bytes_per_row = 0;
|
||||||
|
uint32_t v_y = 0;
|
||||||
|
|
||||||
|
uint8_t* iop_a_src = NULL;
|
||||||
|
uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||||
|
uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||||
|
uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||||
|
if (a_src) {
|
||||||
|
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_skip_frame[0];
|
||||||
|
if (coro_susp_point) {
|
||||||
|
v_bytes_per_row = self->private_data.s_skip_frame[0].v_bytes_per_row;
|
||||||
|
v_y = self->private_data.s_skip_frame[0].v_y;
|
||||||
|
}
|
||||||
|
switch (coro_susp_point) {
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
|
|
||||||
|
self->private_data.s_skip_frame[0].scratch = self->private_impl.f_padding;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||||
|
if (self->private_data.s_skip_frame[0].scratch >
|
||||||
|
((uint64_t)(io2_a_src - iop_a_src))) {
|
||||||
|
self->private_data.s_skip_frame[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_skip_frame[0].scratch;
|
||||||
|
if (self->private_impl.f_bits_per_pixel == 24) {
|
||||||
|
v_bytes_per_row =
|
||||||
|
((((((uint64_t)(self->private_impl.f_width)) * 3) + 3) >> 2) << 2);
|
||||||
|
} else {
|
||||||
|
status = wuffs_base__make_status(
|
||||||
|
wuffs_bmp__error__internal_error_inconsistent_bpp);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
v_y = self->private_impl.f_height;
|
||||||
|
while (v_y > 0) {
|
||||||
|
v_y -= 1;
|
||||||
|
self->private_data.s_skip_frame[0].scratch = v_bytes_per_row;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||||
|
if (self->private_data.s_skip_frame[0].scratch >
|
||||||
|
((uint64_t)(io2_a_src - iop_a_src))) {
|
||||||
|
self->private_data.s_skip_frame[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_skip_frame[0].scratch;
|
||||||
|
}
|
||||||
self->private_impl.f_call_sequence = 3;
|
self->private_impl.f_call_sequence = 3;
|
||||||
|
|
||||||
goto ok;
|
goto ok;
|
||||||
ok:
|
ok:
|
||||||
|
self->private_impl.p_skip_frame[0] = 0;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto suspend;
|
||||||
|
suspend:
|
||||||
|
self->private_impl.p_skip_frame[0] =
|
||||||
|
wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||||
|
self->private_data.s_skip_frame[0].v_bytes_per_row = v_bytes_per_row;
|
||||||
|
self->private_data.s_skip_frame[0].v_y = v_y;
|
||||||
|
|
||||||
goto exit;
|
goto exit;
|
||||||
exit:
|
exit:
|
||||||
|
if (a_src) {
|
||||||
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
pub status "#bad header"
|
pub status "#bad header"
|
||||||
pub status "#unsupported BMP file"
|
pub status "#unsupported BMP file"
|
||||||
|
|
||||||
|
pri status "#internal error: inconsistent bpp"
|
||||||
|
|
||||||
pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 0
|
pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 0
|
||||||
|
|
||||||
pub struct decoder? implements base.image_decoder(
|
pub struct decoder? implements base.image_decoder(
|
||||||
@@ -174,7 +176,24 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.skip_frame?(src: base.io_reader) {
|
pri func decoder.skip_frame?(src: base.io_reader) {
|
||||||
// TODO.
|
var bytes_per_row : base.u64
|
||||||
|
var y : base.u32
|
||||||
|
|
||||||
|
args.src.skip32?(n: this.padding)
|
||||||
|
|
||||||
|
if this.bits_per_pixel == 24 {
|
||||||
|
// 3 bytes per pixel. We add 3 and shift twice to round up to a
|
||||||
|
// multiple of 4.
|
||||||
|
bytes_per_row = ((((this.width as base.u64) * 3) + 3) >> 2) << 2
|
||||||
|
} else {
|
||||||
|
return "#internal error: inconsistent bpp"
|
||||||
|
}
|
||||||
|
|
||||||
|
y = this.height
|
||||||
|
while y > 0 {
|
||||||
|
y -= 1
|
||||||
|
args.src.skip?(n: bytes_per_row)
|
||||||
|
}
|
||||||
|
|
||||||
this.call_sequence = 3
|
this.call_sequence = 3
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,35 @@ const char* test_wuffs_bmp_decode_interface() {
|
|||||||
"test/data/hippopotamus.bmp", 0, SIZE_MAX, 36, 28, 0x00000000);
|
"test/data/hippopotamus.bmp", 0, SIZE_MAX, 36, 28, 0x00000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* test_wuffs_bmp_decode_frame_config() {
|
||||||
|
CHECK_FOCUS(__func__);
|
||||||
|
wuffs_bmp__decoder dec;
|
||||||
|
CHECK_STATUS("initialize",
|
||||||
|
wuffs_bmp__decoder__initialize(
|
||||||
|
&dec, sizeof dec, WUFFS_VERSION,
|
||||||
|
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||||
|
|
||||||
|
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
|
||||||
|
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||||
|
.data = global_src_slice,
|
||||||
|
});
|
||||||
|
CHECK_STRING(read_file(&src, "test/data/hat.bmp"));
|
||||||
|
CHECK_STATUS("decode_frame_config #0",
|
||||||
|
wuffs_bmp__decoder__decode_frame_config(&dec, &fc, &src));
|
||||||
|
|
||||||
|
wuffs_base__status status =
|
||||||
|
wuffs_bmp__decoder__decode_frame_config(&dec, &fc, &src);
|
||||||
|
if (status.repr != wuffs_base__note__end_of_data) {
|
||||||
|
RETURN_FAIL("decode_frame_config #1: got \"%s\", want \"%s\"", status.repr,
|
||||||
|
wuffs_base__note__end_of_data);
|
||||||
|
}
|
||||||
|
if (src.meta.ri != src.meta.wi) {
|
||||||
|
RETURN_FAIL("at end of data: ri (%zu) doesn't equal wi (%zu)", src.meta.ri,
|
||||||
|
src.meta.wi);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------- Mimic Tests
|
// ---------------- Mimic Tests
|
||||||
|
|
||||||
#ifdef WUFFS_MIMIC
|
#ifdef WUFFS_MIMIC
|
||||||
@@ -106,6 +135,7 @@ const char* test_wuffs_bmp_decode_interface() {
|
|||||||
// The empty comments forces clang-format to place one element per line.
|
// The empty comments forces clang-format to place one element per line.
|
||||||
proc tests[] = {
|
proc tests[] = {
|
||||||
|
|
||||||
|
test_wuffs_bmp_decode_frame_config, //
|
||||||
test_wuffs_bmp_decode_interface, //
|
test_wuffs_bmp_decode_interface, //
|
||||||
|
|
||||||
#ifdef WUFFS_MIMIC
|
#ifdef WUFFS_MIMIC
|
||||||
|
|||||||
Reference in new issue
Block a user