mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Add save_code to std/gif/decode_lzw.puffs.
This commit is contained in:
1 parent
3863427127
commit
0b034d7f6e
2 files changed
+20
-7
No files matched your search
+10
-4
@@ -215,18 +215,20 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t v_bits;
|
|
||||||
uint32_t v_n_bits;
|
|
||||||
uint32_t v_clear_code;
|
uint32_t v_clear_code;
|
||||||
uint32_t v_end_code;
|
uint32_t v_end_code;
|
||||||
|
uint32_t v_save_code;
|
||||||
uint32_t v_width;
|
uint32_t v_width;
|
||||||
|
uint32_t v_bits;
|
||||||
|
uint32_t v_n_bits;
|
||||||
uint32_t v_code;
|
uint32_t v_code;
|
||||||
|
|
||||||
v_bits = 0;
|
|
||||||
v_n_bits = 0;
|
|
||||||
v_clear_code = (((uint32_t)(1)) << self->f_literal_width);
|
v_clear_code = (((uint32_t)(1)) << self->f_literal_width);
|
||||||
v_end_code = (v_clear_code + 1);
|
v_end_code = (v_clear_code + 1);
|
||||||
|
v_save_code = v_end_code;
|
||||||
v_width = (self->f_literal_width + 1);
|
v_width = (self->f_literal_width + 1);
|
||||||
|
v_bits = 0;
|
||||||
|
v_n_bits = 0;
|
||||||
label_0_continue:;
|
label_0_continue:;
|
||||||
while (1) {
|
while (1) {
|
||||||
while (v_n_bits < v_width) {
|
while (v_n_bits < v_width) {
|
||||||
@@ -244,11 +246,15 @@ label_0_continue:;
|
|||||||
if (v_code < v_clear_code) {
|
if (v_code < v_clear_code) {
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
} else if (v_code == v_clear_code) {
|
} else if (v_code == v_clear_code) {
|
||||||
|
v_save_code = v_end_code;
|
||||||
v_width = (self->f_literal_width + 1);
|
v_width = (self->f_literal_width + 1);
|
||||||
goto label_0_continue;
|
goto label_0_continue;
|
||||||
} else if (v_code == v_end_code) {
|
} else if (v_code == v_end_code) {
|
||||||
status = puffs_gif_status_ok;
|
status = puffs_gif_status_ok;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
|
} else if (v_code <= v_save_code) {
|
||||||
|
status = puffs_gif_status_ok;
|
||||||
|
goto cleanup0;
|
||||||
} else {
|
} else {
|
||||||
status = puffs_gif_error_bad_gif_image;
|
status = puffs_gif_error_bad_gif_image;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
|
|||||||
@@ -13,13 +13,17 @@ pub struct lzw_decoder?(
|
|||||||
)
|
)
|
||||||
|
|
||||||
pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
||||||
var bits u32
|
// These variables don't change over the lifetime of this func.
|
||||||
var n_bits u32
|
|
||||||
var clear_code u32[4..256] = (1 as u32) << this.literal_width
|
var clear_code u32[4..256] = (1 as u32) << this.literal_width
|
||||||
var end_code u32[5..257] = clear_code + 1
|
var end_code u32[5..257] = clear_code + 1
|
||||||
|
|
||||||
|
// These variables do change.
|
||||||
|
var save_code u32[..4095] = end_code
|
||||||
var width u32[..12] = this.literal_width + 1
|
var width u32[..12] = this.literal_width + 1
|
||||||
|
|
||||||
// TODO: implement.
|
// These variables yield src's bits in Least Significant Bits order.
|
||||||
|
var bits u32
|
||||||
|
var n_bits u32
|
||||||
|
|
||||||
while true,
|
while true,
|
||||||
pre n_bits < 8,
|
pre n_bits < 8,
|
||||||
@@ -40,10 +44,13 @@ pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
|||||||
if code < clear_code {
|
if code < clear_code {
|
||||||
break
|
break
|
||||||
} else if code == clear_code {
|
} else if code == clear_code {
|
||||||
|
save_code = end_code
|
||||||
width = this.literal_width + 1
|
width = this.literal_width + 1
|
||||||
continue
|
continue
|
||||||
} else if code == end_code {
|
} else if code == end_code {
|
||||||
return
|
return
|
||||||
|
} else if code <= save_code {
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
return error "bad GIF image"
|
return error "bad GIF image"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user