mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Prepare for introducing copy_from_slice.
This commit is contained in:
1 parent
36ba4b866c
commit
66f712039b
3 files changed
+37
-16
No files matched your search
+24
-12
@@ -1298,6 +1298,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
uint32_t v_code;
|
||||
uint32_t v_s;
|
||||
uint32_t v_c;
|
||||
puffs_base_slice_u8 v_expansion;
|
||||
|
||||
uint8_t* b_wptr_dst = NULL;
|
||||
uint8_t* b_wstart_dst = NULL;
|
||||
@@ -1342,6 +1343,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
v_code = self->private_impl.c_decode[0].v_code;
|
||||
v_s = self->private_impl.c_decode[0].v_s;
|
||||
v_c = self->private_impl.c_decode[0].v_c;
|
||||
v_expansion = ((puffs_base_slice_u8){});
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
@@ -1407,19 +1409,29 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
if (v_code == v_save_code) {
|
||||
self->private_impl.f_stack[4095] = ((uint8_t)(v_c));
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
if (a_dst.buf && a_dst.buf->closed) {
|
||||
status = PUFFS_GIF_ERROR_CLOSED_FOR_WRITES;
|
||||
goto exit;
|
||||
while (true) {
|
||||
v_expansion = puffs_base_slice_u8_subslice_i(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_stack,
|
||||
.len = 4096}),
|
||||
v_s);
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
if (a_dst.buf && a_dst.buf->closed) {
|
||||
status = PUFFS_GIF_ERROR_CLOSED_FOR_WRITES;
|
||||
goto exit;
|
||||
}
|
||||
if ((b_wend_dst - b_wptr_dst) <
|
||||
(sizeof(self->private_impl.f_stack) - v_s)) {
|
||||
status = PUFFS_GIF_SUSPENSION_SHORT_WRITE;
|
||||
goto suspend;
|
||||
}
|
||||
memmove(b_wptr_dst, self->private_impl.f_stack + v_s,
|
||||
sizeof(self->private_impl.f_stack) - v_s);
|
||||
b_wptr_dst += sizeof(self->private_impl.f_stack) - v_s;
|
||||
if (((uint64_t)(v_expansion.len)) == 0) {
|
||||
}
|
||||
goto label_1_break;
|
||||
}
|
||||
if ((b_wend_dst - b_wptr_dst) <
|
||||
(sizeof(self->private_impl.f_stack) - v_s)) {
|
||||
status = PUFFS_GIF_SUSPENSION_SHORT_WRITE;
|
||||
goto suspend;
|
||||
}
|
||||
memmove(b_wptr_dst, self->private_impl.f_stack + v_s,
|
||||
sizeof(self->private_impl.f_stack) - v_s);
|
||||
b_wptr_dst += sizeof(self->private_impl.f_stack) - v_s;
|
||||
label_1_break:;
|
||||
if (v_save_code <= 4095) {
|
||||
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_c));
|
||||
self->private_impl.f_prefixes[v_save_code] =
|
||||
|
||||
@@ -218,6 +218,7 @@ pri func decoder.decode_uncompressed?(dst writer1, src reader1)() {
|
||||
}
|
||||
length -= n
|
||||
if in.dst.available() == 0 {
|
||||
// TODO: "closed for writes" instead?
|
||||
return suspension "short write"
|
||||
} else {
|
||||
return suspension "short read"
|
||||
@@ -401,6 +402,7 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
length -= n
|
||||
// TODO: "closed for writes" instead?
|
||||
return suspension "short write"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,10 +105,17 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
||||
this.stack[4095] = c as u8
|
||||
}
|
||||
|
||||
// TODO: the "x:s" arg is a placeholder, and should be something
|
||||
// like (this.stack[s:]), which means defining a slice type (and
|
||||
// type checking, bounds checking and code generation for it).
|
||||
in.dst.write?(x:s)
|
||||
while true,
|
||||
inv n_bits < 8,
|
||||
inv c < 256,
|
||||
{
|
||||
var expansion[] u8 = this.stack[s:]
|
||||
// TODO: change write to copy_from_slice.
|
||||
in.dst.write?(x:expansion)
|
||||
if expansion.length() == 0 { // Avoid "unused variable" C compiler warning.
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if save_code <= 4095 {
|
||||
this.suffixes[save_code] = c as u8
|
||||
|
||||
Reference in new issue
Block a user