mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Decode a GIF's width and height.
This commit is contained in:
1 parent
8d1bf15d70
commit
524d323992
4 files changed
+50
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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:;
|
||||
|
||||
Reference in new issue
Block a user