mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Add a call sequence concept
This commit is contained in:
1 parent
9a463d4675
commit
de9000cc70
10 files changed
+191
-72
No files matched your search
@@ -59,7 +59,11 @@ static const char* decode() {
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
wuffs_gif__status s =
|
||||
wuffs_gif__decoder__decode(&dec, dst_writer, src_reader);
|
||||
wuffs_gif__decoder__decode_config(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
s = wuffs_gif__decoder__decode_frame(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
|
||||
+5
-3
@@ -138,7 +138,8 @@ typedef int32_t wuffs_deflate__status;
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_DEFLATE__ERROR_CANNOT_RETURN_A_SUSPENSION \
|
||||
-2147483638 // 0x8000000A
|
||||
-2147483638 // 0x8000000A
|
||||
#define WUFFS_DEFLATE__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_DEFLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1278585856 // 0xB3CA5400
|
||||
@@ -623,7 +624,7 @@ static inline wuffs_base__empty_struct wuffs_base__writer1__mark(
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
static const char* wuffs_base__status__strings[11] = {
|
||||
static const char* wuffs_base__status__strings[12] = {
|
||||
"ok",
|
||||
"bad wuffs version",
|
||||
"bad receiver",
|
||||
@@ -635,6 +636,7 @@ static const char* wuffs_base__status__strings[11] = {
|
||||
"short read",
|
||||
"short write",
|
||||
"cannot return a suspension",
|
||||
"invalid call sequence",
|
||||
};
|
||||
|
||||
#endif // WUFFS_BASE_IMPL_H
|
||||
@@ -671,7 +673,7 @@ const char* wuffs_deflate__status__string(wuffs_deflate__status s) {
|
||||
switch ((s >> 10) & 0x1FFFFF) {
|
||||
case 0:
|
||||
a = wuffs_base__status__strings;
|
||||
n = 11;
|
||||
n = 12;
|
||||
break;
|
||||
case wuffs_deflate__packageid:
|
||||
a = wuffs_deflate__status__strings;
|
||||
|
||||
+83
-52
@@ -138,6 +138,7 @@ typedef int32_t wuffs_gif__status;
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_GIF__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000A
|
||||
#define WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xBE161800
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xBE161801
|
||||
@@ -206,14 +207,18 @@ typedef struct {
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
uint8_t f_background_color_index;
|
||||
uint8_t f_gct[768];
|
||||
wuffs_gif__lzw_decoder f_lzw;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
} c_decode_config[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint8_t v_c;
|
||||
} c_decode[1];
|
||||
} c_decode_frame[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint8_t v_c[6];
|
||||
@@ -256,9 +261,13 @@ void wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
wuffs_gif__status wuffs_gif__decoder__decode_config(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
wuffs_gif__status wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
@@ -611,7 +620,7 @@ static inline wuffs_base__empty_struct wuffs_base__writer1__mark(
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
static const char* wuffs_base__status__strings[11] = {
|
||||
static const char* wuffs_base__status__strings[12] = {
|
||||
"ok",
|
||||
"bad wuffs version",
|
||||
"bad receiver",
|
||||
@@ -623,6 +632,7 @@ static const char* wuffs_base__status__strings[11] = {
|
||||
"short read",
|
||||
"short write",
|
||||
"cannot return a suspension",
|
||||
"invalid call sequence",
|
||||
};
|
||||
|
||||
#endif // WUFFS_BASE_IMPL_H
|
||||
@@ -650,7 +660,7 @@ const char* wuffs_gif__status__string(wuffs_gif__status s) {
|
||||
switch ((s >> 10) & 0x1FFFFF) {
|
||||
case 0:
|
||||
a = wuffs_base__status__strings;
|
||||
n = 11;
|
||||
n = 12;
|
||||
break;
|
||||
case wuffs_gif__packageid:
|
||||
a = wuffs_gif__status__strings;
|
||||
@@ -736,9 +746,61 @@ void wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_gif__status wuffs_gif__decoder__decode_config(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return WUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint32_t coro_susp_point =
|
||||
self->private_impl.c_decode_config[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence >= 1) {
|
||||
status = WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE;
|
||||
goto exit;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_gif__decoder__decode_header(self, a_src);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_gif__decoder__decode_lsd(self, a_src);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.c_decode_config[0].coro_susp_point = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.c_decode_config[0].coro_susp_point = coro_susp_point;
|
||||
|
||||
exit:
|
||||
self->private_impl.status = status;
|
||||
return status;
|
||||
}
|
||||
|
||||
wuffs_gif__status wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return WUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
@@ -768,52 +830,21 @@ wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
b_rend_src = b_rptr_src + len;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
|
||||
uint32_t coro_susp_point =
|
||||
self->private_impl.c_decode_frame[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
v_c = self->private_impl.c_decode[0].v_c;
|
||||
v_c = self->private_impl.c_decode_frame[0].v_c;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = wuffs_gif__decoder__decode_header(self, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = wuffs_gif__decoder__decode_lsd(self, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
if (status) {
|
||||
goto suspend;
|
||||
if (self->private_impl.f_call_sequence < 1) {
|
||||
status = WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE;
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
@@ -821,7 +852,7 @@ wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
v_c = t_0;
|
||||
}
|
||||
if (v_c == 33) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
@@ -840,7 +871,7 @@ wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_c == 44) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
@@ -869,14 +900,14 @@ wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.c_decode[0].coro_susp_point = 0;
|
||||
self->private_impl.c_decode_frame[0].coro_susp_point = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.c_decode[0].coro_susp_point = coro_susp_point;
|
||||
self->private_impl.c_decode[0].v_c = v_c;
|
||||
self->private_impl.c_decode_frame[0].coro_susp_point = coro_susp_point;
|
||||
self->private_impl.c_decode_frame[0].v_c = v_c;
|
||||
|
||||
exit:
|
||||
if (a_src.buf) {
|
||||
|
||||
+6
-3
@@ -147,7 +147,8 @@ typedef int32_t wuffs_deflate__status;
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_DEFLATE__ERROR_CANNOT_RETURN_A_SUSPENSION \
|
||||
-2147483638 // 0x8000000A
|
||||
-2147483638 // 0x8000000A
|
||||
#define WUFFS_DEFLATE__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_DEFLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1278585856 // 0xB3CA5400
|
||||
@@ -318,6 +319,7 @@ typedef int32_t wuffs_zlib__status;
|
||||
#define WUFFS_ZLIB__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_ZLIB__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_ZLIB__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000A
|
||||
#define WUFFS_ZLIB__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_ZLIB__ERROR_CHECKSUM_MISMATCH -33692672 // 0xFDFDE400
|
||||
#define WUFFS_ZLIB__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
@@ -746,7 +748,7 @@ static inline wuffs_base__empty_struct wuffs_base__writer1__mark(
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
static const char* wuffs_base__status__strings[11] = {
|
||||
static const char* wuffs_base__status__strings[12] = {
|
||||
"ok",
|
||||
"bad wuffs version",
|
||||
"bad receiver",
|
||||
@@ -758,6 +760,7 @@ static const char* wuffs_base__status__strings[11] = {
|
||||
"short read",
|
||||
"short write",
|
||||
"cannot return a suspension",
|
||||
"invalid call sequence",
|
||||
};
|
||||
|
||||
#endif // WUFFS_BASE_IMPL_H
|
||||
@@ -782,7 +785,7 @@ const char* wuffs_zlib__status__string(wuffs_zlib__status s) {
|
||||
switch ((s >> 10) & 0x1FFFFF) {
|
||||
case 0:
|
||||
a = wuffs_base__status__strings;
|
||||
n = 11;
|
||||
n = 12;
|
||||
break;
|
||||
case wuffs_zlib__packageid:
|
||||
a = wuffs_zlib__status__strings;
|
||||
|
||||
+2
-1
@@ -138,7 +138,8 @@ typedef int32_t wuffs_deflate__status;
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_DEFLATE__ERROR_CANNOT_RETURN_A_SUSPENSION \
|
||||
-2147483638 // 0x8000000A
|
||||
-2147483638 // 0x8000000A
|
||||
#define WUFFS_DEFLATE__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_DEFLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1278585856 // 0xB3CA5400
|
||||
|
||||
+13
-4
@@ -138,6 +138,7 @@ typedef int32_t wuffs_gif__status;
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_GIF__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000A
|
||||
#define WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xBE161800
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xBE161801
|
||||
@@ -206,14 +207,18 @@ typedef struct {
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
uint8_t f_background_color_index;
|
||||
uint8_t f_gct[768];
|
||||
wuffs_gif__lzw_decoder f_lzw;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
} c_decode_config[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint8_t v_c;
|
||||
} c_decode[1];
|
||||
} c_decode_frame[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint8_t v_c[6];
|
||||
@@ -256,9 +261,13 @@ void wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
wuffs_gif__status wuffs_gif__decoder__decode_config(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
wuffs_gif__status wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
+3
-1
@@ -147,7 +147,8 @@ typedef int32_t wuffs_deflate__status;
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_DEFLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_DEFLATE__ERROR_CANNOT_RETURN_A_SUSPENSION \
|
||||
-2147483638 // 0x8000000A
|
||||
-2147483638 // 0x8000000A
|
||||
#define WUFFS_DEFLATE__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_DEFLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1278585856 // 0xB3CA5400
|
||||
@@ -318,6 +319,7 @@ typedef int32_t wuffs_zlib__status;
|
||||
#define WUFFS_ZLIB__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_ZLIB__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_ZLIB__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000A
|
||||
#define WUFFS_ZLIB__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
|
||||
|
||||
#define WUFFS_ZLIB__ERROR_CHECKSUM_MISMATCH -33692672 // 0xFDFDE400
|
||||
#define WUFFS_ZLIB__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
|
||||
@@ -48,6 +48,7 @@ var StatusList = [...]Status{
|
||||
{t.IDSuspension, "short read"}, // Used if reading when closed == false.
|
||||
{t.IDSuspension, "short write"},
|
||||
{t.IDError, "cannot return a suspension"},
|
||||
{t.IDError, "invalid call sequence"},
|
||||
}
|
||||
|
||||
var StatusMap = map[string]Status{}
|
||||
|
||||
@@ -26,23 +26,45 @@ pub error "TODO: unsupported Local Color Table"
|
||||
pub struct decoder?(
|
||||
width u32[..65535],
|
||||
height u32[..65535],
|
||||
|
||||
// Call sequence state transitions:
|
||||
// - 0 -> 1: via decode_config.
|
||||
// - 1 -> 1: via decode_frame.
|
||||
call_sequence u8,
|
||||
|
||||
background_color_index u8,
|
||||
|
||||
// gct is the Global Color Table: 256 (R, G, B) entries.
|
||||
//
|
||||
// TODO: 4 byte per pixel RGBA or BGRA instead of 3 bpp RGB?
|
||||
gct[3 * 256] u8,
|
||||
|
||||
lzw lzw_decoder,
|
||||
)
|
||||
|
||||
pub func decoder.decode?(dst writer1, src reader1)() {
|
||||
// TODO: dst should be an image_config, not a writer1.
|
||||
pub func decoder.decode_config?(dst writer1, src reader1)() {
|
||||
if this.call_sequence >= 1 {
|
||||
return error "invalid call sequence"
|
||||
}
|
||||
this.decode_header?(src:in.src)
|
||||
this.decode_lsd?(src:in.src)
|
||||
this.call_sequence = 1
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst writer1, src reader1)() {
|
||||
if this.call_sequence < 1 {
|
||||
return error "invalid call sequence"
|
||||
}
|
||||
while true {
|
||||
var c u8 = in.src.read_u8?()
|
||||
if c == 0x21 { // The spec calls 0x21 the "Extension Introducer".
|
||||
this.decode_extension?(src:in.src)
|
||||
} else if c == 0x2C { // The spec calls 0x2C the "Image Separator".
|
||||
// TODO: animated GIFs can have multiple Image Descriptors.
|
||||
// TODO: animated GIFs can have multiple Image Descriptors. What's
|
||||
// the API? Should the 0x3B Trailer byte result in a "no more
|
||||
// frames" suspension instead of ok? Do we need additional
|
||||
// destination arguments for timing and palette?
|
||||
//
|
||||
// TODO: reset this.lzw if it's not the first ID.
|
||||
this.decode_id?(dst:in.dst, src:in.src)
|
||||
|
||||
+49
-5
@@ -52,7 +52,7 @@ void test_basic_bad_receiver() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_base__writer1 dst = {0};
|
||||
wuffs_base__reader1 src = {0};
|
||||
wuffs_gif__status status = wuffs_gif__decoder__decode(NULL, dst, src);
|
||||
wuffs_gif__status status = wuffs_gif__decoder__decode_config(NULL, dst, src);
|
||||
if (status != WUFFS_GIF__ERROR_BAD_RECEIVER) {
|
||||
FAIL("status: got %d, want %d", status, WUFFS_GIF__ERROR_BAD_RECEIVER);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ void test_basic_initializer_not_called() {
|
||||
wuffs_gif__decoder dec = {{0}};
|
||||
wuffs_base__writer1 dst = {0};
|
||||
wuffs_base__reader1 src = {0};
|
||||
wuffs_gif__status status = wuffs_gif__decoder__decode(&dec, dst, src);
|
||||
wuffs_gif__status status = wuffs_gif__decoder__decode_config(&dec, dst, src);
|
||||
if (status != WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED) {
|
||||
FAIL("status: got %d, want %d", status,
|
||||
WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED);
|
||||
@@ -365,7 +365,11 @@ const char* wuffs_gif_decode(wuffs_base__buf1* dst, wuffs_base__buf1* src) {
|
||||
wuffs_base__writer1 dst_writer = {.buf = dst};
|
||||
wuffs_base__reader1 src_reader = {.buf = src};
|
||||
wuffs_gif__status s =
|
||||
wuffs_gif__decoder__decode(&dec, dst_writer, src_reader);
|
||||
wuffs_gif__decoder__decode_config(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
s = wuffs_gif__decoder__decode_frame(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
@@ -386,6 +390,19 @@ bool do_test_wuffs_gif_decode(const char* filename,
|
||||
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
|
||||
{
|
||||
wuffs_base__writer1 got_writer = {.buf = &got};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__decoder__decode_config(&dec, got_writer, src_reader);
|
||||
if (status != WUFFS_GIF__STATUS_OK) {
|
||||
FAIL("status: got %" PRIi32 " (%s)", status,
|
||||
wuffs_gif__status__string(status));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int num_iters = 0;
|
||||
uint64_t wlim = 0;
|
||||
uint64_t rlim = 0;
|
||||
@@ -405,7 +422,7 @@ bool do_test_wuffs_gif_decode(const char* filename,
|
||||
size_t old_ri = src.ri;
|
||||
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__decoder__decode(&dec, got_writer, src_reader);
|
||||
wuffs_gif__decoder__decode_frame(&dec, got_writer, src_reader);
|
||||
if (status == WUFFS_GIF__STATUS_OK) {
|
||||
if (src.ri != src.wi) {
|
||||
FAIL("decode returned ok but src was not exhausted");
|
||||
@@ -479,6 +496,32 @@ bool do_test_wuffs_gif_decode(const char* filename,
|
||||
return buf1s_equal("indexes ", &got, &ind_want);
|
||||
}
|
||||
|
||||
void test_wuffs_gif_call_sequence() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, "../../testdata/bricks-dither.gif")) {
|
||||
return;
|
||||
}
|
||||
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
|
||||
wuffs_base__writer1 got_writer = {.buf = &got};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__decoder__decode_frame(&dec, got_writer, src_reader);
|
||||
if (status != WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
|
||||
wuffs_gif__status__string(status),
|
||||
WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE,
|
||||
wuffs_gif__status__string(WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void test_wuffs_gif_decode_input_is_a_gif() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_wuffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
@@ -525,7 +568,7 @@ void test_wuffs_gif_decode_input_is_a_png() {
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__decoder__decode(&dec, got_writer, src_reader);
|
||||
wuffs_gif__decoder__decode_config(&dec, got_writer, src_reader);
|
||||
if (status != WUFFS_GIF__ERROR_BAD_GIF_HEADER) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
|
||||
wuffs_gif__status__string(status), WUFFS_GIF__ERROR_BAD_GIF_HEADER,
|
||||
@@ -706,6 +749,7 @@ proc tests[] = {
|
||||
test_wuffs_lzw_decode_bricks_nodither, //
|
||||
test_wuffs_lzw_decode_pi, //
|
||||
|
||||
test_wuffs_gif_call_sequence, //
|
||||
test_wuffs_gif_decode_input_is_a_gif, //
|
||||
test_wuffs_gif_decode_input_is_a_gif_many_big_reads, //
|
||||
test_wuffs_gif_decode_input_is_a_gif_many_medium_reads, //
|
||||
|
||||
Reference in new issue
Block a user