diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index da74f0e5..dd2443f5 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -110,6 +110,8 @@ typedef struct { struct { puffs_gif_status status; uint32_t magic; + uint32_t f_width; + uint32_t f_height; puffs_gif_lzw_decoder f_lzw; } private_impl; } puffs_gif_decoder; @@ -343,6 +345,28 @@ puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self, puffs_base_buf1* a_src) { puffs_gif_status status = self->private_impl.status; + uint8_t v_c[7]; + uint8_t v_i; + + for (size_t i = 0; i < 7; i++) { + v_c[i] = 0; + }; + v_i = 0; + while (v_i < 7) { + if (a_src->ri >= a_src->wi) { + status = a_src->closed ? puffs_gif_error_unexpected_eof + : puffs_gif_status_short_read; + return status; + } + uint8_t t_0 = a_src->ptr[a_src->ri++]; + v_c[v_i] = t_0; + v_i += 1; + } + self->private_impl.f_width = + (((uint32_t)(v_c[0])) | (((uint32_t)(v_c[1])) << 8)); + self->private_impl.f_height = + (((uint32_t)(v_c[2])) | (((uint32_t)(v_c[3])) << 8)); + return status; } diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index f3447892..1b16c869 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -110,6 +110,8 @@ typedef struct { struct { puffs_gif_status status; uint32_t magic; + uint32_t f_width; + uint32_t f_height; puffs_gif_lzw_decoder f_lzw; } private_impl; } puffs_gif_decoder; diff --git a/std/gif/decode_gif.puffs b/std/gif/decode_gif.puffs index 27933537..e10535e8 100644 --- a/std/gif/decode_gif.puffs +++ b/std/gif/decode_gif.puffs @@ -6,6 +6,8 @@ pub error "bad GIF header" pub struct decoder?( + width u32[..65535], + height u32[..65535], lzw lzw_decoder, ) @@ -34,4 +36,12 @@ pri func decoder.decode_header?(src ptr buf1)() { // // See the spec section 18 "Logical Screen Descriptor" on page 8. pri func decoder.decode_lsd?(src ptr buf1)() { + var c[7] u8 + var i u8 + while i < 7 { + c[i] = in.src.read_u8?() + i += 1 + } + this.width = (c[0] as u32) | ((c[1] as u32) << 8) + this.height = (c[2] as u32) | ((c[3] as u32) << 8) } diff --git a/test/c/std/gif.c b/test/c/std/gif.c index e164c265..e7c25b54 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -263,6 +263,20 @@ void test_gif_decode_input_is_a_xxx(const char* filename, goto cleanup1; } + if (want != puffs_gif_status_ok) { + goto cleanup1; + } + + // TODO: provide a public API for getting the width and height. + if (dec.private_impl.f_width != 160) { + FAIL("width: got %d, want %d", dec.private_impl.f_width, 160); + goto cleanup1; + } + if (dec.private_impl.f_height != 120) { + FAIL("height: got %d, want %d", dec.private_impl.f_height, 120); + goto cleanup1; + } + cleanup1: puffs_gif_decoder_destructor(&dec); cleanup0:;