mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Fill in a GIF image_config
This commit is contained in:
1 parent
d750ea7653
commit
7e90967717
8 files changed
+79
-35
No files matched your search
@@ -358,6 +358,18 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
".len = v_r.private_impl.mark ? (size_t)(b_rptr_src - v_r.private_impl.mark) : 0, })")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, g.tm.ByName("initialize").Key(), 3) {
|
||||
// TODO: don't hard-code a_dst.
|
||||
b.printf("wuffs_base__image_config__initialize(a_dst")
|
||||
for _, o := range n.Args() {
|
||||
b.writeb(',')
|
||||
if err := g.writeExpr(b, o.Arg().Value(), rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
b.printf(")")
|
||||
return nil
|
||||
}
|
||||
// TODO.
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
|
||||
@@ -37,10 +37,7 @@ for a C compiler $cc, such as clang or gcc.
|
||||
#endif
|
||||
|
||||
#define DST_BUFFER_SIZE (1024 * 1024)
|
||||
|
||||
// TODO: provide API to get the width and height. Don't hard code 32/32.
|
||||
#define WIDTH 32
|
||||
#define HEIGHT 32
|
||||
#define PRINT_BUFFER_SIZE (1024)
|
||||
|
||||
uint8_t pjw_ptr[];
|
||||
size_t pjw_len;
|
||||
@@ -51,37 +48,42 @@ static void ignore_return_value(int ignored) {}
|
||||
static const char* decode() {
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
wuffs_base__image_config ic = {{0}};
|
||||
uint8_t dst_buffer[DST_BUFFER_SIZE];
|
||||
wuffs_base__buf1 dst = {.ptr = dst_buffer, .len = DST_BUFFER_SIZE};
|
||||
|
||||
wuffs_base__buf1 src = {
|
||||
.ptr = pjw_ptr, .len = pjw_len, .wi = pjw_len, .closed = true};
|
||||
wuffs_base__writer1 dst_writer = {.buf = &dst};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
wuffs_base__image_config ic = {{0}};
|
||||
wuffs_gif__status s =
|
||||
wuffs_gif__decoder__decode_config(&dec, &ic, src_reader);
|
||||
if (s) {
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
uint32_t width = wuffs_base__image_config__width(&ic);
|
||||
uint32_t height = wuffs_base__image_config__height(&ic);
|
||||
if ((width > PRINT_BUFFER_SIZE - 1) ||
|
||||
(wuffs_base__image_config__pixbuf_size(&ic) > DST_BUFFER_SIZE)) {
|
||||
return "image is too large";
|
||||
}
|
||||
|
||||
uint8_t dst_buffer[DST_BUFFER_SIZE];
|
||||
wuffs_base__buf1 dst = {.ptr = dst_buffer, .len = DST_BUFFER_SIZE};
|
||||
wuffs_base__writer1 dst_writer = {.buf = &dst};
|
||||
s = wuffs_gif__decoder__decode_frame(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
|
||||
if (dst.wi != WIDTH * HEIGHT) {
|
||||
return "image dimensions not 32x32";
|
||||
}
|
||||
uint8_t buf[PRINT_BUFFER_SIZE];
|
||||
uint8_t* p = dst.ptr;
|
||||
int y;
|
||||
for (y = 0; y < HEIGHT; y++) {
|
||||
uint8_t buf[WIDTH + 1];
|
||||
int x;
|
||||
for (x = 0; x < WIDTH; x++) {
|
||||
uint32_t y;
|
||||
for (y = 0; y < height; y++) {
|
||||
uint32_t x;
|
||||
for (x = 0; x < width; x++) {
|
||||
buf[x] = *p++ ? '-' : '8';
|
||||
}
|
||||
buf[WIDTH] = '\n';
|
||||
ignore_return_value(write(1, buf, WIDTH + 1));
|
||||
buf[width] = '\n';
|
||||
ignore_return_value(write(1, buf, width + 1));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -857,6 +857,8 @@ wuffs_gif__status wuffs_gif__decoder__decode_config(
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
wuffs_base__image_config__initialize(a_dst, self->private_impl.f_width,
|
||||
self->private_impl.f_height, 0);
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
|
||||
goto ok;
|
||||
|
||||
+23
-3
@@ -99,9 +99,13 @@ const (
|
||||
FlagsGlobalIdent = Flags(0x00000100)
|
||||
)
|
||||
|
||||
// flagsThatMatterForEq is the bitwise or of all flags that matter for the
|
||||
// Expr.Eq method.
|
||||
const flagsThatMatterForEq = Flags(0x0000FFFF)
|
||||
const (
|
||||
flagEffect = FlagsImpure | FlagsSuspendible
|
||||
|
||||
// flagsThatMatterForEq is the bitwise or of all flags that matter for the
|
||||
// Expr.Eq method.
|
||||
flagsThatMatterForEq = Flags(0x0000FFFF)
|
||||
)
|
||||
|
||||
// These flags are set by the bounds checker to generate optimized code.
|
||||
const (
|
||||
@@ -121,6 +125,20 @@ const (
|
||||
FlagsBoundsCheckOptimized = Flags(0x00020000)
|
||||
)
|
||||
|
||||
type Effect uint32
|
||||
|
||||
func (e Effect) String() string {
|
||||
switch e {
|
||||
case Effect(0):
|
||||
return ""
|
||||
case Effect(FlagsImpure):
|
||||
return "!"
|
||||
case Effect(FlagsImpure | FlagsSuspendible):
|
||||
return "?"
|
||||
}
|
||||
return "INVALID_EFFECT"
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
kind Kind
|
||||
flags Flags
|
||||
@@ -303,6 +321,7 @@ const MaxExprDepth = 255
|
||||
type Expr Node
|
||||
|
||||
func (n *Expr) Node() *Node { return (*Node)(n) }
|
||||
func (n *Expr) Effect() Effect { return Effect(n.flags & flagEffect) }
|
||||
func (n *Expr) Pure() bool { return n.flags&FlagsImpure == 0 }
|
||||
func (n *Expr) Impure() bool { return n.flags&FlagsImpure != 0 }
|
||||
func (n *Expr) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||
@@ -733,6 +752,7 @@ const MaxBodyDepth = 255
|
||||
type Func Node
|
||||
|
||||
func (n *Func) Node() *Node { return (*Node)(n) }
|
||||
func (n *Func) Effect() Effect { return Effect(n.flags & flagEffect) }
|
||||
func (n *Func) Pure() bool { return n.flags&FlagsImpure == 0 }
|
||||
func (n *Func) Impure() bool { return n.flags&FlagsImpure != 0 }
|
||||
func (n *Func) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||
|
||||
@@ -127,6 +127,8 @@ var Funcs = []string{
|
||||
"writer1.limit(l u64)(ret writer1)",
|
||||
"writer1.mark()()",
|
||||
"writer1.since_mark()(ret[] u8)",
|
||||
|
||||
"image_config.initialize!(width u32, height u32, color_model u32)()",
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -564,6 +564,10 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ne, fe := n.Effect(), f.Effect(); ne != fe {
|
||||
return fmt.Errorf("check: %q has effect %q but %q has effect %q",
|
||||
n.Str(q.tm), ne, f.QQID().Str(q.tm), fe)
|
||||
}
|
||||
|
||||
genericType := (*a.TypeExpr)(nil)
|
||||
if f.Receiver() == (t.QID{0, t.IDDiamond}) {
|
||||
|
||||
@@ -49,7 +49,7 @@ pub func decoder.decode_config?(dst ptr image_config, src reader1)() {
|
||||
}
|
||||
this.decode_header?(src:in.src)
|
||||
this.decode_lsd?(src:in.src)
|
||||
// TODO: fill in dst.
|
||||
in.dst.initialize!(width:this.width, height:this.height, color_model:0)
|
||||
this.call_sequence = 1
|
||||
}
|
||||
|
||||
|
||||
+15
-13
@@ -402,6 +402,16 @@ bool do_test_wuffs_gif_decode(const char* filename,
|
||||
wuffs_gif__status__string(status));
|
||||
return false;
|
||||
}
|
||||
if (wuffs_base__image_config__width(&ic) != 160) {
|
||||
FAIL("width: got %" PRIu32 ", want 160",
|
||||
wuffs_base__image_config__width(&ic));
|
||||
return false;
|
||||
}
|
||||
if (wuffs_base__image_config__height(&ic) != 120) {
|
||||
FAIL("height: got %" PRIu32 ", want 120",
|
||||
wuffs_base__image_config__height(&ic));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int num_iters = 0;
|
||||
@@ -469,16 +479,6 @@ bool do_test_wuffs_gif_decode(const char* filename,
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
return false;
|
||||
}
|
||||
if (dec.private_impl.f_height != 120) {
|
||||
FAIL("height: got %d, want %d", dec.private_impl.f_height, 120);
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: provide a public API for getting the palette.
|
||||
wuffs_base__buf1 pal_got = {.ptr = dec.private_impl.f_gct, .len = 3 * 256};
|
||||
wuffs_base__buf1 pal_want = {.ptr = global_palette_buffer, .len = 3 * 256};
|
||||
@@ -541,9 +541,11 @@ void test_wuffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_wuffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 0,
|
||||
787); // 787 tickles being in the middle of a
|
||||
// decode_extension skip32 call.
|
||||
"../../testdata/bricks-dither.indexes", 0, 787);
|
||||
// The magic 787 tickles being in the middle of a decode_extension skip32
|
||||
// call.
|
||||
//
|
||||
// TODO: has 787 changed since we decode the image_config separately?
|
||||
}
|
||||
|
||||
void test_wuffs_gif_decode_input_is_a_gif_many_small_writes_reads() {
|
||||
|
||||
Reference in new issue
Block a user