mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Remove the write_to_ib_instead_of_w hack
This commit is contained in:
1 parent
47cf248e57
commit
c5362d6413
4 files changed
+17
-112
No files matched your search
+8
-70
@@ -1334,10 +1334,8 @@ typedef struct {
|
||||
uint32_t v_num_palette_entries;
|
||||
uint32_t v_i;
|
||||
uint8_t v_lw;
|
||||
bool v_write_to_ib_instead_of_w;
|
||||
uint64_t v_block_size;
|
||||
wuffs_gif__status v_z;
|
||||
uint64_t v_n_copied;
|
||||
} c_decode_id_part1[1];
|
||||
} private_impl;
|
||||
} wuffs_gif__decoder;
|
||||
@@ -3283,7 +3281,6 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
||||
uint32_t v_num_palette_entries;
|
||||
uint32_t v_i;
|
||||
uint8_t v_lw;
|
||||
bool v_write_to_ib_instead_of_w;
|
||||
uint64_t v_block_size;
|
||||
wuffs_base__io_writer v_w;
|
||||
wuffs_base__io_buffer u_w;
|
||||
@@ -3293,28 +3290,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(ioptr_w);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(iobounds1_w);
|
||||
wuffs_gif__status v_z;
|
||||
wuffs_base__slice_u8 v_pass_through;
|
||||
uint64_t v_n_copied;
|
||||
wuffs_base__slice_u8 v_palette;
|
||||
|
||||
uint8_t* ioptr_dst = NULL;
|
||||
uint8_t* iobounds0orig_dst = NULL;
|
||||
uint8_t* iobounds1_dst = NULL;
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(iobounds0orig_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(iobounds1_dst);
|
||||
if (a_dst.private_impl.buf) {
|
||||
ioptr_dst = a_dst.private_impl.buf->ptr + a_dst.private_impl.buf->wi;
|
||||
if (!a_dst.private_impl.bounds[0]) {
|
||||
a_dst.private_impl.bounds[0] = ioptr_dst;
|
||||
a_dst.private_impl.bounds[1] =
|
||||
a_dst.private_impl.buf->ptr + a_dst.private_impl.buf->len;
|
||||
}
|
||||
if (a_dst.private_impl.buf->closed) {
|
||||
a_dst.private_impl.bounds[1] = ioptr_dst;
|
||||
}
|
||||
iobounds0orig_dst = a_dst.private_impl.bounds[0];
|
||||
iobounds1_dst = a_dst.private_impl.bounds[1];
|
||||
}
|
||||
uint8_t* ioptr_src = NULL;
|
||||
uint8_t* iobounds0orig_src = NULL;
|
||||
uint8_t* iobounds1_src = NULL;
|
||||
@@ -3341,19 +3318,13 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
||||
self->private_impl.c_decode_id_part1[0].v_num_palette_entries;
|
||||
v_i = self->private_impl.c_decode_id_part1[0].v_i;
|
||||
v_lw = self->private_impl.c_decode_id_part1[0].v_lw;
|
||||
v_write_to_ib_instead_of_w =
|
||||
self->private_impl.c_decode_id_part1[0].v_write_to_ib_instead_of_w;
|
||||
v_block_size = self->private_impl.c_decode_id_part1[0].v_block_size;
|
||||
v_w = ((wuffs_base__io_writer){});
|
||||
v_z = self->private_impl.c_decode_id_part1[0].v_z;
|
||||
v_pass_through = ((wuffs_base__slice_u8){});
|
||||
v_n_copied = self->private_impl.c_decode_id_part1[0].v_n_copied;
|
||||
v_palette = ((wuffs_base__slice_u8){});
|
||||
} else {
|
||||
v_use_local_palette = false;
|
||||
v_write_to_ib_instead_of_w = false;
|
||||
v_w = ((wuffs_base__io_writer){});
|
||||
v_pass_through = ((wuffs_base__slice_u8){});
|
||||
v_palette = ((wuffs_base__slice_u8){});
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
@@ -3426,7 +3397,6 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
||||
}
|
||||
wuffs_gif__lzw_decoder__set_literal_width(&self->private_impl.f_lzw,
|
||||
((uint32_t)(v_lw)));
|
||||
v_write_to_ib_instead_of_w = true;
|
||||
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
|
||||
while (true) {
|
||||
{
|
||||
@@ -3489,35 +3459,10 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
||||
a_src = o_0_a_src;
|
||||
}
|
||||
if ((v_z == 0) || (v_z == WUFFS_GIF__SUSPENSION_SHORT_WRITE)) {
|
||||
if (!v_write_to_ib_instead_of_w) {
|
||||
while (self->private_impl.f_uncompressed_ri <
|
||||
self->private_impl.f_uncompressed_wi) {
|
||||
v_pass_through = wuffs_base__slice_u8__subslice_ij(
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = self->private_impl.f_uncompressed, .len = 4096}),
|
||||
self->private_impl.f_uncompressed_ri,
|
||||
self->private_impl.f_uncompressed_wi);
|
||||
v_n_copied = wuffs_base__io_writer__copy_from_slice(
|
||||
&ioptr_dst, iobounds1_dst, v_pass_through);
|
||||
if (v_n_copied == ((uint64_t)(v_pass_through.len))) {
|
||||
self->private_impl.f_uncompressed_ri = 0;
|
||||
self->private_impl.f_uncompressed_wi = 0;
|
||||
goto label_2_break;
|
||||
}
|
||||
self->private_impl.f_uncompressed_ri =
|
||||
((self->private_impl.f_uncompressed_ri +
|
||||
((uint32_t)((v_n_copied & 4095)))) &
|
||||
4095);
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_WRITE;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
}
|
||||
label_2_break:;
|
||||
} else {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_gif__decoder__copy_to_image_buffer(self, a_ib);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_gif__decoder__copy_to_image_buffer(self, a_ib);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
if (v_z == WUFFS_GIF__SUSPENSION_SHORT_WRITE) {
|
||||
goto label_1_continue;
|
||||
@@ -3529,15 +3474,14 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
||||
goto label_1_break;
|
||||
}
|
||||
status = v_z;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
}
|
||||
label_1_break:;
|
||||
}
|
||||
label_0_break:;
|
||||
if ((self->private_impl.f_uncompressed_ri !=
|
||||
self->private_impl.f_uncompressed_wi) &&
|
||||
v_write_to_ib_instead_of_w) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_impl.f_uncompressed_ri !=
|
||||
self->private_impl.f_uncompressed_wi) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_gif__decoder__copy_to_image_buffer(self, a_ib);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
@@ -3577,17 +3521,11 @@ suspend:
|
||||
v_num_palette_entries;
|
||||
self->private_impl.c_decode_id_part1[0].v_i = v_i;
|
||||
self->private_impl.c_decode_id_part1[0].v_lw = v_lw;
|
||||
self->private_impl.c_decode_id_part1[0].v_write_to_ib_instead_of_w =
|
||||
v_write_to_ib_instead_of_w;
|
||||
self->private_impl.c_decode_id_part1[0].v_block_size = v_block_size;
|
||||
self->private_impl.c_decode_id_part1[0].v_z = v_z;
|
||||
self->private_impl.c_decode_id_part1[0].v_n_copied = v_n_copied;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst.private_impl.buf) {
|
||||
a_dst.private_impl.buf->wi = ioptr_dst - a_dst.private_impl.buf->ptr;
|
||||
}
|
||||
if (a_src.private_impl.buf) {
|
||||
a_src.private_impl.buf->ri = ioptr_src - a_src.private_impl.buf->ptr;
|
||||
}
|
||||
|
||||
@@ -1334,10 +1334,8 @@ typedef struct {
|
||||
uint32_t v_num_palette_entries;
|
||||
uint32_t v_i;
|
||||
uint8_t v_lw;
|
||||
bool v_write_to_ib_instead_of_w;
|
||||
uint64_t v_block_size;
|
||||
wuffs_gif__status v_z;
|
||||
uint64_t v_n_copied;
|
||||
} c_decode_id_part1[1];
|
||||
} private_impl;
|
||||
} wuffs_gif__decoder;
|
||||
|
||||
@@ -420,10 +420,6 @@ pri func decoder.decode_id_part1?(ib ptr base.image_buffer, dst base.io_writer,
|
||||
}
|
||||
this.lzw.set_literal_width!(lw:lw as base.u32)
|
||||
|
||||
// TODO: delete the write_to_ib_instead_of_w hack. It should always be
|
||||
// true.
|
||||
var write_to_ib_instead_of_w base.bool = true
|
||||
|
||||
this.previous_lzw_decode_ended_abruptly = true
|
||||
while true {
|
||||
var block_size base.u64 = in.src.read_u8?() as base.u64
|
||||
@@ -450,27 +446,7 @@ pri func decoder.decode_id_part1?(ib ptr base.image_buffer, dst base.io_writer,
|
||||
}
|
||||
|
||||
if z.is_ok() or (z == suspension "short write") {
|
||||
// Pass through the uncompressed bytes to in.dst.
|
||||
//
|
||||
// TODO: in.dst should be a ptr base.image_buffer and we should
|
||||
// composite the pixels instead of just copying them.
|
||||
if not write_to_ib_instead_of_w {
|
||||
while this.uncompressed_ri < this.uncompressed_wi {
|
||||
var pass_through slice base.u8 = this.uncompressed[this.uncompressed_ri:this.uncompressed_wi]
|
||||
var n_copied base.u64 = in.dst.copy_from_slice!(s:pass_through)
|
||||
if n_copied == pass_through.length() {
|
||||
this.uncompressed_ri = 0
|
||||
this.uncompressed_wi = 0
|
||||
break
|
||||
}
|
||||
this.uncompressed_ri = (this.uncompressed_ri + ((n_copied & 4095) as base.u32)) & 4095
|
||||
// TODO: "closed for writes" instead?
|
||||
yield suspension "short write"
|
||||
}
|
||||
|
||||
} else {
|
||||
this.copy_to_image_buffer?(ib:in.ib)
|
||||
}
|
||||
this.copy_to_image_buffer?(ib:in.ib)
|
||||
|
||||
if z == suspension "short write" {
|
||||
continue:inner
|
||||
@@ -486,7 +462,7 @@ pri func decoder.decode_id_part1?(ib ptr base.image_buffer, dst base.io_writer,
|
||||
}
|
||||
}
|
||||
|
||||
if (this.uncompressed_ri != this.uncompressed_wi) and write_to_ib_instead_of_w {
|
||||
if this.uncompressed_ri != this.uncompressed_wi {
|
||||
this.copy_to_image_buffer?(ib:in.ib)
|
||||
}
|
||||
|
||||
|
||||
+7
-14
@@ -355,9 +355,6 @@ void bench_wuffs_lzw_decode_100k() {
|
||||
|
||||
// ---------------- GIF Tests
|
||||
|
||||
// TODO: delete this.
|
||||
const bool write_to_ib_instead_of_w = true;
|
||||
|
||||
const char* wuffs_gif_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src) {
|
||||
wuffs_gif__decoder dec;
|
||||
@@ -386,11 +383,9 @@ const char* wuffs_gif_decode(wuffs_base__io_buffer* dst,
|
||||
if (s) {
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
if (write_to_ib_instead_of_w) {
|
||||
const char* msg = copy_to_io_buffer_from_image_buffer(dst, &ib);
|
||||
if (msg) {
|
||||
return msg;
|
||||
}
|
||||
const char* msg = copy_to_io_buffer_from_image_buffer(dst, &ib);
|
||||
if (msg) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -472,12 +467,10 @@ bool do_test_wuffs_gif_decode(const char* filename,
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__decoder__decode_frame(&dec, &ib, got_writer, src_reader);
|
||||
if (status == WUFFS_GIF__STATUS_OK) {
|
||||
if (write_to_ib_instead_of_w) {
|
||||
const char* msg = copy_to_io_buffer_from_image_buffer(&got, &ib);
|
||||
if (msg) {
|
||||
FAIL("%s", msg);
|
||||
return false;
|
||||
}
|
||||
const char* msg = copy_to_io_buffer_from_image_buffer(&got, &ib);
|
||||
if (msg) {
|
||||
FAIL("%s", msg);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user