Gitweb links:
...log
http://git.netsurf-browser.org/libnsgif.git/shortlog/3832f7edc4cd117642ad...
...commit
http://git.netsurf-browser.org/libnsgif.git/commit/3832f7edc4cd117642ad78...
...tree
http://git.netsurf-browser.org/libnsgif.git/tree/3832f7edc4cd117642ad7890...
The branch, master has been updated
via 3832f7edc4cd117642ad7890eb1476d1f9d8e918 (commit)
via a83ed529003818e3f4ce70a68752a34c66461de2 (commit)
via fe39d4611ccce7cdb7be11edf7a819888b6319a4 (commit)
via e6be9591cfa6f901c6f4c421a9aeaa08da986eaf (commit)
via de3510f1215dd16b215bd34ffe2cc81a34f67985 (commit)
via 125cd0409ab9d2d13fc41fcfae2fe001e4241878 (commit)
from 032e62c80df60b5fcedcd75f3043e0a18e114b6e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=3832f7edc4cd117642...
commit 3832f7edc4cd117642ad7890eb1476d1f9d8e918
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
GIF: Reorder #includes.
diff --git a/src/libnsgif.c b/src/libnsgif.c
index dbc066a..ecddf78 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -8,14 +8,14 @@
*
http://www.opensource.org/licenses/mit-license.php
*/
-#include <stdbool.h>
+#include <assert.h>
#include <stdint.h>
-#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+#include <string.h>
+#include <stdbool.h>
-#include "libnsgif.h"
#include "lzw.h"
+#include "libnsgif.h"
/**
*
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=a83ed529003818e3f4...
commit a83ed529003818e3f4ce70a68752a34c66461de2
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
LOG: Remove unused logging code.
diff --git a/src/libnsgif.c b/src/libnsgif.c
index 38816f5..dbc066a 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -10,13 +10,11 @@
#include <stdbool.h>
#include <stdint.h>
-#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
-#include "libnsgif.h"
-#include "utils/log.h"
+#include "libnsgif.h"
#include "lzw.h"
/**
diff --git a/src/utils/log.h b/src/utils/log.h
deleted file mode 100644
index 1413374..0000000
--- a/src/utils/log.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2003 James Bursa <bursa(a)users.sourceforge.net>
- * Copyright 2004 John Tytgat <John.Tytgat(a)aaug.net>
- *
- * This file is part of NetSurf,
http://www.netsurf-browser.org/
- * Licenced under the MIT License,
- *
http://www.opensource.org/licenses/mit-license.php
- */
-
-#include <stdio.h>
-
-#ifndef _LIBNSGIF_LOG_H_
-#define _LIBNSGIF_LOG_H_
-
-#ifdef NDEBUG
-# define LOG(x) ((void) 0)
-#else
-# define LOG(x) do { fprintf(stderr, x), fputc('\n', stderr); } while (0)
-#endif /* NDEBUG */
-
-#endif /* _LIBNSGIF_LOG_H_ */
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=fe39d4611ccce7cdb7...
commit fe39d4611ccce7cdb7be11edf7a819888b6319a4
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
API: Use stdint types.
diff --git a/include/libnsgif.h b/include/libnsgif.h
index 309e2f0..b281034 100644
--- a/include/libnsgif.h
+++ b/include/libnsgif.h
@@ -37,12 +37,12 @@ typedef struct gif_frame {
/** whether the frame should be displayed/animated */
bool display;
/** delay (in cs) before animating the frame */
- unsigned int frame_delay;
+ uint32_t frame_delay;
/* Internal members are listed below */
/** offset (in bytes) to the GIF frame data */
- unsigned int frame_pointer;
+ uint32_t frame_pointer;
/** whether the frame has previously been used */
bool virgin;
/** whether the frame is totally opaque */
@@ -50,27 +50,27 @@ typedef struct gif_frame {
/** whether a full image redraw is required */
bool redraw_required;
/** how the previous frame should be disposed; affects plotting */
- unsigned char disposal_method;
+ uint8_t disposal_method;
/** whether we acknowledge transparency */
bool transparency;
/** the index designating a transparent pixel */
- unsigned int transparency_index;
+ uint32_t transparency_index;
/** x co-ordinate of redraw rectangle */
- unsigned int redraw_x;
+ uint32_t redraw_x;
/** y co-ordinate of redraw rectangle */
- unsigned int redraw_y;
+ uint32_t redraw_y;
/** width of redraw rectangle */
- unsigned int redraw_width;
+ uint32_t redraw_width;
/** height of redraw rectangle */
- unsigned int redraw_height;
+ uint32_t redraw_height;
/* Frame flags */
- unsigned int flags;
+ uint32_t flags;
} gif_frame;
/* API for Bitmap callbacks */
typedef void* (*gif_bitmap_cb_create)(int width, int height);
typedef void (*gif_bitmap_cb_destroy)(void *bitmap);
-typedef unsigned char* (*gif_bitmap_cb_get_buffer)(void *bitmap);
+typedef uint8_t* (*gif_bitmap_cb_get_buffer)(void *bitmap);
typedef void (*gif_bitmap_cb_set_opaque)(void *bitmap, bool opaque);
typedef bool (*gif_bitmap_cb_test_opaque)(void *bitmap);
typedef void (*gif_bitmap_cb_modified)(void *bitmap);
@@ -103,13 +103,13 @@ typedef struct gif_animation {
/** pointer to GIF data */
const uint8_t *gif_data;
/** width of GIF (may increase during decoding) */
- unsigned int width;
+ uint32_t width;
/** height of GIF (may increase during decoding) */
- unsigned int height;
+ uint32_t height;
/** number of frames decoded */
- unsigned int frame_count;
+ uint32_t frame_count;
/** number of frames partially decoded */
- unsigned int frame_count_partial;
+ uint32_t frame_count_partial;
/** decoded frames */
gif_frame *frames;
/** current frame decoded to bitmap */
@@ -122,27 +122,27 @@ typedef struct gif_animation {
/* Internal members are listed below */
/** current index into GIF data */
- unsigned int buffer_position;
+ uint32_t buffer_position;
/** total number of bytes of GIF data available */
- unsigned int buffer_size;
+ uint32_t buffer_size;
/** current number of frame holders */
- unsigned int frame_holders;
+ uint32_t frame_holders;
/** background index */
- unsigned int bg_index;
+ uint32_t bg_index;
/** background colour */
- unsigned int bg_colour;
+ uint32_t bg_colour;
/** image aspect ratio (ignored) */
- unsigned int aspect_ratio;
+ uint32_t aspect_ratio;
/** size of colour table (in entries) */
- unsigned int colour_table_size;
+ uint32_t colour_table_size;
/** whether the GIF has a global colour table */
bool global_colours;
/** global colour table */
- unsigned int *global_colour_table;
+ uint32_t *global_colour_table;
/** local colour table */
- unsigned int *local_colour_table;
+ uint32_t *local_colour_table;
/** current colour table */
- unsigned int *colour_table;
+ uint32_t *colour_table;
/** previous frame for GIF_FRAME_RESTORE */
void *prev_frame;
@@ -184,7 +184,7 @@ gif_result gif_initialise(gif_animation *gif, size_t size, const
uint8_t *data);
* - GIF_INSUFFICIENT_MEMORY for insufficient memory to process
* - GIF_OK for successful decoding
*/
-gif_result gif_decode_frame(gif_animation *gif, unsigned int frame);
+gif_result gif_decode_frame(gif_animation *gif, uint32_t frame);
/**
* Releases any workspace held by a gif
diff --git a/src/libnsgif.c b/src/libnsgif.c
index 5011683..38816f5 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -1353,7 +1353,7 @@ gif_result gif_initialise(gif_animation *gif, size_t size, const
uint8_t *data)
}
/* exported function documented in libnsgif.h */
-gif_result gif_decode_frame(gif_animation *gif, unsigned int frame)
+gif_result gif_decode_frame(gif_animation *gif, uint32_t frame)
{
return gif__process_frame(gif, frame, true);
}
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=e6be9591cfa6f901c6...
commit e6be9591cfa6f901c6f4c421a9aeaa08da986eaf
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
TEST: Style: Fix whitespace.
diff --git a/test/decode_gif.c b/test/decode_gif.c
index 52d73b6..dfc2b84 100644
--- a/test/decode_gif.c
+++ b/test/decode_gif.c
@@ -20,232 +20,224 @@
#define BYTES_PER_PIXEL 4
#define MAX_IMAGE_BYTES (48 * 1024 * 1024)
-
static void *bitmap_create(int width, int height)
{
- /* ensure a stupidly large bitmap is not created */
- if (((long long)width * (long long)height) >
(MAX_IMAGE_BYTES/BYTES_PER_PIXEL)) {
- return NULL;
- }
- return calloc(width * height, BYTES_PER_PIXEL);
+ /* ensure a stupidly large bitmap is not created */
+ if (((long long)width * (long long)height) > (MAX_IMAGE_BYTES/BYTES_PER_PIXEL)) {
+ return NULL;
+ }
+ return calloc(width * height, BYTES_PER_PIXEL);
}
-
static void bitmap_set_opaque(void *bitmap, bool opaque)
{
- (void) opaque; /* unused */
- (void) bitmap; /* unused */
- assert(bitmap);
+ (void) opaque; /* unused */
+ (void) bitmap; /* unused */
+ assert(bitmap);
}
-
static bool bitmap_test_opaque(void *bitmap)
{
- (void) bitmap; /* unused */
- assert(bitmap);
- return false;
+ (void) bitmap; /* unused */
+ assert(bitmap);
+ return false;
}
-
static unsigned char *bitmap_get_buffer(void *bitmap)
{
- assert(bitmap);
- return bitmap;
+ assert(bitmap);
+ return bitmap;
}
-
static void bitmap_destroy(void *bitmap)
{
- assert(bitmap);
- free(bitmap);
+ assert(bitmap);
+ free(bitmap);
}
-
static void bitmap_modified(void *bitmap)
{
- (void) bitmap; /* unused */
- assert(bitmap);
- return;
+ (void) bitmap; /* unused */
+ assert(bitmap);
+ return;
}
static unsigned char *load_file(const char *path, size_t *data_size)
{
- FILE *fd;
- struct stat sb;
- unsigned char *buffer;
- size_t size;
- size_t n;
-
- fd = fopen(path, "rb");
- if (!fd) {
- perror(path);
- exit(EXIT_FAILURE);
- }
-
- if (stat(path, &sb)) {
- perror(path);
- exit(EXIT_FAILURE);
- }
- size = sb.st_size;
-
- buffer = malloc(size);
- if (!buffer) {
- fprintf(stderr, "Unable to allocate %lld bytes\n",
- (long long) size);
- exit(EXIT_FAILURE);
- }
-
- n = fread(buffer, 1, size, fd);
- if (n != size) {
- perror(path);
- exit(EXIT_FAILURE);
- }
-
- fclose(fd);
-
- *data_size = size;
- return buffer;
+ FILE *fd;
+ struct stat sb;
+ unsigned char *buffer;
+ size_t size;
+ size_t n;
+
+ fd = fopen(path, "rb");
+ if (!fd) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ if (stat(path, &sb)) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+ size = sb.st_size;
+
+ buffer = malloc(size);
+ if (!buffer) {
+ fprintf(stderr, "Unable to allocate %lld bytes\n",
+ (long long) size);
+ exit(EXIT_FAILURE);
+ }
+
+ n = fread(buffer, 1, size, fd);
+ if (n != size) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ fclose(fd);
+
+ *data_size = size;
+ return buffer;
}
-
static void warning(const char *context, gif_result code)
{
- fprintf(stderr, "%s failed: ", context);
- switch (code)
- {
- case GIF_FRAME_DATA_ERROR:
- fprintf(stderr, "GIF_FRAME_DATA_ERROR");
- break;
- case GIF_INSUFFICIENT_DATA:
- fprintf(stderr, "GIF_INSUFFICIENT_DATA");
- break;
- case GIF_DATA_ERROR:
- fprintf(stderr, "GIF_DATA_ERROR");
- break;
- case GIF_INSUFFICIENT_MEMORY:
- fprintf(stderr, "GIF_INSUFFICIENT_MEMORY");
- break;
- default:
- fprintf(stderr, "unknown code %i", code);
- break;
- }
- fprintf(stderr, "\n");
+ fprintf(stderr, "%s failed: ", context);
+ switch (code)
+ {
+ case GIF_FRAME_DATA_ERROR:
+ fprintf(stderr, "GIF_FRAME_DATA_ERROR");
+ break;
+ case GIF_INSUFFICIENT_DATA:
+ fprintf(stderr, "GIF_INSUFFICIENT_DATA");
+ break;
+ case GIF_DATA_ERROR:
+ fprintf(stderr, "GIF_DATA_ERROR");
+ break;
+ case GIF_INSUFFICIENT_MEMORY:
+ fprintf(stderr, "GIF_INSUFFICIENT_MEMORY");
+ break;
+ default:
+ fprintf(stderr, "unknown code %i", code);
+ break;
+ }
+ fprintf(stderr, "\n");
}
static void write_ppm(FILE* fh, const char *name, gif_animation *gif,
- bool no_write)
+ bool no_write)
{
- unsigned int i;
- gif_result code;
-
- if (!no_write) {
- fprintf(fh, "P3\n");
- fprintf(fh, "# %s\n", name);
- fprintf(fh, "# width %u \n", gif->width);
- fprintf(fh, "# height %u \n", gif->height);
- fprintf(fh, "# frame_count %u \n",
gif->frame_count);
- fprintf(fh, "# frame_count_partial %u \n",
gif->frame_count_partial);
- fprintf(fh, "# loop_count %u \n",
gif->loop_count);
- fprintf(fh, "%u %u 256\n", gif->width, gif->height *
gif->frame_count);
- }
-
- /* decode the frames */
- for (i = 0; i != gif->frame_count; i++) {
- unsigned int row, col;
- unsigned char *image;
-
- code = gif_decode_frame(gif, i);
- if (code != GIF_OK)
- warning("gif_decode_frame", code);
-
- if (!gif->frames[i].display) {
- continue;
- }
-
- if (!no_write) {
- fprintf(fh, "# frame %u:\n", i);
- image = (unsigned char *) gif->frame_image;
- for (row = 0; row != gif->height; row++) {
- for (col = 0; col != gif->width; col++) {
- size_t z = (row * gif->width + col) * 4;
- fprintf(fh, "%u %u %u ",
- (unsigned char) image[z],
- (unsigned char) image[z + 1],
- (unsigned char) image[z + 2]);
- }
- fprintf(fh, "\n");
- }
- }
- }
-
+ unsigned int i;
+ gif_result code;
+
+ if (!no_write) {
+ fprintf(fh, "P3\n");
+ fprintf(fh, "# %s\n", name);
+ fprintf(fh, "# width %u \n", gif->width);
+ fprintf(fh, "# height %u \n", gif->height);
+ fprintf(fh, "# frame_count %u \n", gif->frame_count);
+ fprintf(fh, "# frame_count_partial %u \n", gif->frame_count_partial);
+ fprintf(fh, "# loop_count %u \n", gif->loop_count);
+ fprintf(fh, "%u %u 256\n", gif->width, gif->height *
gif->frame_count);
+ }
+
+ /* decode the frames */
+ for (i = 0; i != gif->frame_count; i++) {
+ unsigned int row, col;
+ unsigned char *image;
+
+ code = gif_decode_frame(gif, i);
+ if (code != GIF_OK)
+ warning("gif_decode_frame", code);
+
+ if (!gif->frames[i].display) {
+ continue;
+ }
+
+ if (!no_write) {
+ fprintf(fh, "# frame %u:\n", i);
+ image = (unsigned char *) gif->frame_image;
+ for (row = 0; row != gif->height; row++) {
+ for (col = 0; col != gif->width; col++) {
+ size_t z = (row * gif->width + col) * 4;
+ fprintf(fh, "%u %u %u ",
+ (unsigned char) image[z],
+ (unsigned char) image[z + 1],
+ (unsigned char) image[z + 2]);
+ }
+ fprintf(fh, "\n");
+ }
+ }
+ }
}
int main(int argc, char *argv[])
{
- gif_bitmap_callback_vt bitmap_callbacks = {
- bitmap_create,
- bitmap_destroy,
- bitmap_get_buffer,
- bitmap_set_opaque,
- bitmap_test_opaque,
- bitmap_modified
- };
- gif_animation gif;
- size_t size;
- gif_result code;
- unsigned char *data;
- FILE *outf = stdout;
- bool no_write = false;
-
- if (argc < 2) {
- fprintf(stderr, "Usage: %s image.gif [out]\n", argv[0]);
- fprintf(stderr, "\n");
- fprintf(stderr, "If [out] is NOWRITE, the gif will be docoded
"
- "but not output.\n");
- fprintf(stderr, "Otherwise [out] is an output filename.\n");
- fprintf(stderr, "When [out] is unset, output is to
stdout.\n");
-
- return 1;
- }
-
- if (argc > 2) {
- if (strcmp(argv[2], "NOWRITE") == 0) {
- no_write = true;
- } else {
- outf = fopen(argv[2], "w+");
- if (outf == NULL) {
- fprintf(stderr, "Unable to open %s for
writing\n", argv[2]);
- return 2;
- }
- }
- }
-
- /* create our gif animation */
- gif_create(&gif, &bitmap_callbacks);
-
- /* load file into memory */
- data = load_file(argv[1], &size);
-
- /* begin decoding */
- do {
- code = gif_initialise(&gif, size, data);
- if (code != GIF_OK && code != GIF_WORKING) {
- warning("gif_initialise", code);
- gif_finalise(&gif);
- free(data);
- return 1;
- }
- } while (code != GIF_OK);
-
- write_ppm(outf, argv[1], &gif, no_write);
-
- if (argc > 2 && !no_write) {
- fclose(outf);
- }
-
- /* clean up */
- gif_finalise(&gif);
- free(data);
-
- return 0;
+ gif_bitmap_callback_vt bitmap_callbacks = {
+ bitmap_create,
+ bitmap_destroy,
+ bitmap_get_buffer,
+ bitmap_set_opaque,
+ bitmap_test_opaque,
+ bitmap_modified
+ };
+ gif_animation gif;
+ size_t size;
+ gif_result code;
+ unsigned char *data;
+ FILE *outf = stdout;
+ bool no_write = false;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s image.gif [out]\n", argv[0]);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "If [out] is NOWRITE, the gif will be docoded "
+ "but not output.\n");
+ fprintf(stderr, "Otherwise [out] is an output filename.\n");
+ fprintf(stderr, "When [out] is unset, output is to stdout.\n");
+
+ return 1;
+ }
+
+ if (argc > 2) {
+ if (strcmp(argv[2], "NOWRITE") == 0) {
+ no_write = true;
+ } else {
+ outf = fopen(argv[2], "w+");
+ if (outf == NULL) {
+ fprintf(stderr, "Unable to open %s for writing\n", argv[2]);
+ return 2;
+ }
+ }
+ }
+
+ /* create our gif animation */
+ gif_create(&gif, &bitmap_callbacks);
+
+ /* load file into memory */
+ data = load_file(argv[1], &size);
+
+ /* begin decoding */
+ do {
+ code = gif_initialise(&gif, size, data);
+ if (code != GIF_OK && code != GIF_WORKING) {
+ warning("gif_initialise", code);
+ gif_finalise(&gif);
+ free(data);
+ return 1;
+ }
+ } while (code != GIF_OK);
+
+ write_ppm(outf, argv[1], &gif, no_write);
+
+ if (argc > 2 && !no_write) {
+ fclose(outf);
+ }
+
+ /* clean up */
+ gif_finalise(&gif);
+ free(data);
+
+ return 0;
}
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=de3510f1215dd16b21...
commit de3510f1215dd16b215bd34ffe2cc81a34f67985
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
GIF: Style: Use double underscore for remaining static functions.
diff --git a/src/libnsgif.c b/src/libnsgif.c
index 6f59b3a..5011683 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -67,7 +67,13 @@ enum gif_disposal {
#define GIF_BLOCK_TERMINATOR 0x00
#define GIF_TRAILER 0x3b
-static gif_result gif_error_from_lzw(lzw_result l_res)
+/**
+ * Convert an LZW result code to equivalent GIF result code.
+ *
+ * \param[in] l_res LZW response code.
+ * \return GIF result code.
+ */
+static gif_result gif__error_from_lzw(lzw_result l_res)
{
static const gif_result g_res[] = {
[LZW_OK] = GIF_OK,
@@ -91,7 +97,7 @@ static gif_result gif_error_from_lzw(lzw_result l_res)
* \param height The height of the sprite
* \return GIF_INSUFFICIENT_MEMORY for a memory error GIF_OK for success
*/
-static gif_result gif_initialise_sprite(
+static gif_result gif__initialise_sprite(
struct gif_animation *gif,
uint32_t width,
uint32_t height)
@@ -122,7 +128,7 @@ static inline uint32_t* gif__bitmap_get(
gif_result ret;
/* Make sure we have a buffer to decode to. */
- ret = gif_initialise_sprite(gif, gif->width, gif->height);
+ ret = gif__initialise_sprite(gif, gif->width, gif->height);
if (ret != GIF_OK) {
return NULL;
}
@@ -323,7 +329,7 @@ static gif_result gif__decode_complex(
gif->gif_data, gif->buffer_size,
data + 1 - gif->gif_data);
if (res != LZW_OK) {
- return gif_error_from_lzw(res);
+ return gif__error_from_lzw(res);
}
do {
@@ -343,7 +349,7 @@ static gif_result gif__decode_complex(
if (res == LZW_OK_EOD) {
ret = GIF_OK;
} else {
- ret = gif_error_from_lzw(res);
+ ret = gif__error_from_lzw(res);
}
break;
}
@@ -396,7 +402,7 @@ static gif_result gif__decode_simple(
gif->gif_data, gif->buffer_size,
data + 1 - gif->gif_data);
if (res != LZW_OK) {
- return gif_error_from_lzw(res);
+ return gif__error_from_lzw(res);
}
frame_data += (offset_y * gif->width);
@@ -411,7 +417,7 @@ static gif_result gif__decode_simple(
if (res == LZW_OK_EOD) {
ret = GIF_OK;
} else {
- ret = gif_error_from_lzw(res);
+ ret = gif__error_from_lzw(res);
}
break;
}
@@ -1334,7 +1340,7 @@ gif_result gif_initialise(gif_animation *gif, size_t size, const
uint8_t *data)
lzw_result res = lzw_context_create(
(struct lzw_ctx **)&gif->lzw_ctx);
if (res != LZW_OK) {
- return gif_error_from_lzw(res);
+ return gif__error_from_lzw(res);
}
}
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=125cd0409ab9d2d13f...
commit 125cd0409ab9d2d13fc41fcfae2fe001e4241878
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
GIF: Update code documentation.
diff --git a/src/libnsgif.c b/src/libnsgif.c
index 6c21a7c..6f59b3a 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -150,7 +150,7 @@ static inline void gif__bitmap_modified(
* Helper to tell the client that whether the bitmap is opaque.
*
* \param[in] gif The gif object we're decoding.
- * \param[in] frmae The frame that has been decoded.
+ * \param[in] frame The frame that has been decoded.
*/
static inline void gif__bitmap_set_opaque(
const struct gif_animation *gif,
@@ -646,6 +646,7 @@ static gif_result gif__parse_extension_application(
*
* \param[in] gif The gif object we're decoding.
* \param[in] frame The frame to parse extensions for.
+ * \param[in] pos Current position in data, updated on exit.
* \param[in] decode Whether to decode or skip over the extension.
* \return GIF_INSUFFICIENT_DATA if more data is needed,
* GIF_OK for success.
@@ -754,8 +755,10 @@ static gif_result gif__parse_frame_extensions(
* 2BITS Reserved
* 3BITS Size of Local Colour Table
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] frame The frame to parse an image descriptor for.
+ * \param[in] gif The gif object we're decoding.
+ * \param[in] frame The frame to parse an image descriptor for.
+ * \param[in] pos Current position in data, updated on exit.
+ * \param[in] decode Whether to decode the image descriptor.
* \return GIF_OK on success, appropriate error otherwise.
*/
static gif_result gif__parse_image_descriptor(
@@ -858,8 +861,10 @@ static gif_result gif__colour_table_extract(
*
* Sets up gif->colour_table for the frame.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] frame The frame to get the colour table for.
+ * \param[in] gif The gif object we're decoding.
+ * \param[in] frame The frame to get the colour table for.
+ * \param[in] pos Current position in data, updated on exit.
+ * \param[in] decode Whether to decode the colour table.
* \return GIF_OK on success, appropriate error otherwise.
*/
static gif_result gif__parse_colour_table(
@@ -894,8 +899,10 @@ static gif_result gif__parse_colour_table(
*
* Sets up gif->colour_table for the frame.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] frame The frame to get the colour table for.
+ * \param[in] gif The gif object we're decoding.
+ * \param[in] frame The frame to parse image data for.
+ * \param[in] pos Current position in data, updated on exit.
+ * \param[in] decode Whether to decode the image data.
* \return GIF_OK on success, appropriate error otherwise.
*/
static gif_result gif__parse_image_data(
-----------------------------------------------------------------------
Summary of changes:
include/libnsgif.h | 50 +++----
src/libnsgif.c | 55 ++++----
src/utils/log.h | 21 ---
test/decode_gif.c | 372 +++++++++++++++++++++++++---------------------------
4 files changed, 240 insertions(+), 258 deletions(-)
delete mode 100644 src/utils/log.h
diff --git a/include/libnsgif.h b/include/libnsgif.h
index 309e2f0..b281034 100644
--- a/include/libnsgif.h
+++ b/include/libnsgif.h
@@ -37,12 +37,12 @@ typedef struct gif_frame {
/** whether the frame should be displayed/animated */
bool display;
/** delay (in cs) before animating the frame */
- unsigned int frame_delay;
+ uint32_t frame_delay;
/* Internal members are listed below */
/** offset (in bytes) to the GIF frame data */
- unsigned int frame_pointer;
+ uint32_t frame_pointer;
/** whether the frame has previously been used */
bool virgin;
/** whether the frame is totally opaque */
@@ -50,27 +50,27 @@ typedef struct gif_frame {
/** whether a full image redraw is required */
bool redraw_required;
/** how the previous frame should be disposed; affects plotting */
- unsigned char disposal_method;
+ uint8_t disposal_method;
/** whether we acknowledge transparency */
bool transparency;
/** the index designating a transparent pixel */
- unsigned int transparency_index;
+ uint32_t transparency_index;
/** x co-ordinate of redraw rectangle */
- unsigned int redraw_x;
+ uint32_t redraw_x;
/** y co-ordinate of redraw rectangle */
- unsigned int redraw_y;
+ uint32_t redraw_y;
/** width of redraw rectangle */
- unsigned int redraw_width;
+ uint32_t redraw_width;
/** height of redraw rectangle */
- unsigned int redraw_height;
+ uint32_t redraw_height;
/* Frame flags */
- unsigned int flags;
+ uint32_t flags;
} gif_frame;
/* API for Bitmap callbacks */
typedef void* (*gif_bitmap_cb_create)(int width, int height);
typedef void (*gif_bitmap_cb_destroy)(void *bitmap);
-typedef unsigned char* (*gif_bitmap_cb_get_buffer)(void *bitmap);
+typedef uint8_t* (*gif_bitmap_cb_get_buffer)(void *bitmap);
typedef void (*gif_bitmap_cb_set_opaque)(void *bitmap, bool opaque);
typedef bool (*gif_bitmap_cb_test_opaque)(void *bitmap);
typedef void (*gif_bitmap_cb_modified)(void *bitmap);
@@ -103,13 +103,13 @@ typedef struct gif_animation {
/** pointer to GIF data */
const uint8_t *gif_data;
/** width of GIF (may increase during decoding) */
- unsigned int width;
+ uint32_t width;
/** height of GIF (may increase during decoding) */
- unsigned int height;
+ uint32_t height;
/** number of frames decoded */
- unsigned int frame_count;
+ uint32_t frame_count;
/** number of frames partially decoded */
- unsigned int frame_count_partial;
+ uint32_t frame_count_partial;
/** decoded frames */
gif_frame *frames;
/** current frame decoded to bitmap */
@@ -122,27 +122,27 @@ typedef struct gif_animation {
/* Internal members are listed below */
/** current index into GIF data */
- unsigned int buffer_position;
+ uint32_t buffer_position;
/** total number of bytes of GIF data available */
- unsigned int buffer_size;
+ uint32_t buffer_size;
/** current number of frame holders */
- unsigned int frame_holders;
+ uint32_t frame_holders;
/** background index */
- unsigned int bg_index;
+ uint32_t bg_index;
/** background colour */
- unsigned int bg_colour;
+ uint32_t bg_colour;
/** image aspect ratio (ignored) */
- unsigned int aspect_ratio;
+ uint32_t aspect_ratio;
/** size of colour table (in entries) */
- unsigned int colour_table_size;
+ uint32_t colour_table_size;
/** whether the GIF has a global colour table */
bool global_colours;
/** global colour table */
- unsigned int *global_colour_table;
+ uint32_t *global_colour_table;
/** local colour table */
- unsigned int *local_colour_table;
+ uint32_t *local_colour_table;
/** current colour table */
- unsigned int *colour_table;
+ uint32_t *colour_table;
/** previous frame for GIF_FRAME_RESTORE */
void *prev_frame;
@@ -184,7 +184,7 @@ gif_result gif_initialise(gif_animation *gif, size_t size, const
uint8_t *data);
* - GIF_INSUFFICIENT_MEMORY for insufficient memory to process
* - GIF_OK for successful decoding
*/
-gif_result gif_decode_frame(gif_animation *gif, unsigned int frame);
+gif_result gif_decode_frame(gif_animation *gif, uint32_t frame);
/**
* Releases any workspace held by a gif
diff --git a/src/libnsgif.c b/src/libnsgif.c
index 6c21a7c..ecddf78 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -8,16 +8,14 @@
*
http://www.opensource.org/licenses/mit-license.php
*/
-#include <stdbool.h>
+#include <assert.h>
#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-#include <assert.h>
-#include "libnsgif.h"
-#include "utils/log.h"
+#include <string.h>
+#include <stdbool.h>
#include "lzw.h"
+#include "libnsgif.h"
/**
*
@@ -67,7 +65,13 @@ enum gif_disposal {
#define GIF_BLOCK_TERMINATOR 0x00
#define GIF_TRAILER 0x3b
-static gif_result gif_error_from_lzw(lzw_result l_res)
+/**
+ * Convert an LZW result code to equivalent GIF result code.
+ *
+ * \param[in] l_res LZW response code.
+ * \return GIF result code.
+ */
+static gif_result gif__error_from_lzw(lzw_result l_res)
{
static const gif_result g_res[] = {
[LZW_OK] = GIF_OK,
@@ -91,7 +95,7 @@ static gif_result gif_error_from_lzw(lzw_result l_res)
* \param height The height of the sprite
* \return GIF_INSUFFICIENT_MEMORY for a memory error GIF_OK for success
*/
-static gif_result gif_initialise_sprite(
+static gif_result gif__initialise_sprite(
struct gif_animation *gif,
uint32_t width,
uint32_t height)
@@ -122,7 +126,7 @@ static inline uint32_t* gif__bitmap_get(
gif_result ret;
/* Make sure we have a buffer to decode to. */
- ret = gif_initialise_sprite(gif, gif->width, gif->height);
+ ret = gif__initialise_sprite(gif, gif->width, gif->height);
if (ret != GIF_OK) {
return NULL;
}
@@ -150,7 +154,7 @@ static inline void gif__bitmap_modified(
* Helper to tell the client that whether the bitmap is opaque.
*
* \param[in] gif The gif object we're decoding.
- * \param[in] frmae The frame that has been decoded.
+ * \param[in] frame The frame that has been decoded.
*/
static inline void gif__bitmap_set_opaque(
const struct gif_animation *gif,
@@ -323,7 +327,7 @@ static gif_result gif__decode_complex(
gif->gif_data, gif->buffer_size,
data + 1 - gif->gif_data);
if (res != LZW_OK) {
- return gif_error_from_lzw(res);
+ return gif__error_from_lzw(res);
}
do {
@@ -343,7 +347,7 @@ static gif_result gif__decode_complex(
if (res == LZW_OK_EOD) {
ret = GIF_OK;
} else {
- ret = gif_error_from_lzw(res);
+ ret = gif__error_from_lzw(res);
}
break;
}
@@ -396,7 +400,7 @@ static gif_result gif__decode_simple(
gif->gif_data, gif->buffer_size,
data + 1 - gif->gif_data);
if (res != LZW_OK) {
- return gif_error_from_lzw(res);
+ return gif__error_from_lzw(res);
}
frame_data += (offset_y * gif->width);
@@ -411,7 +415,7 @@ static gif_result gif__decode_simple(
if (res == LZW_OK_EOD) {
ret = GIF_OK;
} else {
- ret = gif_error_from_lzw(res);
+ ret = gif__error_from_lzw(res);
}
break;
}
@@ -646,6 +650,7 @@ static gif_result gif__parse_extension_application(
*
* \param[in] gif The gif object we're decoding.
* \param[in] frame The frame to parse extensions for.
+ * \param[in] pos Current position in data, updated on exit.
* \param[in] decode Whether to decode or skip over the extension.
* \return GIF_INSUFFICIENT_DATA if more data is needed,
* GIF_OK for success.
@@ -754,8 +759,10 @@ static gif_result gif__parse_frame_extensions(
* 2BITS Reserved
* 3BITS Size of Local Colour Table
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] frame The frame to parse an image descriptor for.
+ * \param[in] gif The gif object we're decoding.
+ * \param[in] frame The frame to parse an image descriptor for.
+ * \param[in] pos Current position in data, updated on exit.
+ * \param[in] decode Whether to decode the image descriptor.
* \return GIF_OK on success, appropriate error otherwise.
*/
static gif_result gif__parse_image_descriptor(
@@ -858,8 +865,10 @@ static gif_result gif__colour_table_extract(
*
* Sets up gif->colour_table for the frame.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] frame The frame to get the colour table for.
+ * \param[in] gif The gif object we're decoding.
+ * \param[in] frame The frame to get the colour table for.
+ * \param[in] pos Current position in data, updated on exit.
+ * \param[in] decode Whether to decode the colour table.
* \return GIF_OK on success, appropriate error otherwise.
*/
static gif_result gif__parse_colour_table(
@@ -894,8 +903,10 @@ static gif_result gif__parse_colour_table(
*
* Sets up gif->colour_table for the frame.
*
- * \param[in] gif The gif object we're decoding.
- * \param[in] frame The frame to get the colour table for.
+ * \param[in] gif The gif object we're decoding.
+ * \param[in] frame The frame to parse image data for.
+ * \param[in] pos Current position in data, updated on exit.
+ * \param[in] decode Whether to decode the image data.
* \return GIF_OK on success, appropriate error otherwise.
*/
static gif_result gif__parse_image_data(
@@ -1327,7 +1338,7 @@ gif_result gif_initialise(gif_animation *gif, size_t size, const
uint8_t *data)
lzw_result res = lzw_context_create(
(struct lzw_ctx **)&gif->lzw_ctx);
if (res != LZW_OK) {
- return gif_error_from_lzw(res);
+ return gif__error_from_lzw(res);
}
}
@@ -1340,7 +1351,7 @@ gif_result gif_initialise(gif_animation *gif, size_t size, const
uint8_t *data)
}
/* exported function documented in libnsgif.h */
-gif_result gif_decode_frame(gif_animation *gif, unsigned int frame)
+gif_result gif_decode_frame(gif_animation *gif, uint32_t frame)
{
return gif__process_frame(gif, frame, true);
}
diff --git a/src/utils/log.h b/src/utils/log.h
deleted file mode 100644
index 1413374..0000000
--- a/src/utils/log.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2003 James Bursa <bursa(a)users.sourceforge.net>
- * Copyright 2004 John Tytgat <John.Tytgat(a)aaug.net>
- *
- * This file is part of NetSurf,
http://www.netsurf-browser.org/
- * Licenced under the MIT License,
- *
http://www.opensource.org/licenses/mit-license.php
- */
-
-#include <stdio.h>
-
-#ifndef _LIBNSGIF_LOG_H_
-#define _LIBNSGIF_LOG_H_
-
-#ifdef NDEBUG
-# define LOG(x) ((void) 0)
-#else
-# define LOG(x) do { fprintf(stderr, x), fputc('\n', stderr); } while (0)
-#endif /* NDEBUG */
-
-#endif /* _LIBNSGIF_LOG_H_ */
diff --git a/test/decode_gif.c b/test/decode_gif.c
index 52d73b6..dfc2b84 100644
--- a/test/decode_gif.c
+++ b/test/decode_gif.c
@@ -20,232 +20,224 @@
#define BYTES_PER_PIXEL 4
#define MAX_IMAGE_BYTES (48 * 1024 * 1024)
-
static void *bitmap_create(int width, int height)
{
- /* ensure a stupidly large bitmap is not created */
- if (((long long)width * (long long)height) >
(MAX_IMAGE_BYTES/BYTES_PER_PIXEL)) {
- return NULL;
- }
- return calloc(width * height, BYTES_PER_PIXEL);
+ /* ensure a stupidly large bitmap is not created */
+ if (((long long)width * (long long)height) > (MAX_IMAGE_BYTES/BYTES_PER_PIXEL)) {
+ return NULL;
+ }
+ return calloc(width * height, BYTES_PER_PIXEL);
}
-
static void bitmap_set_opaque(void *bitmap, bool opaque)
{
- (void) opaque; /* unused */
- (void) bitmap; /* unused */
- assert(bitmap);
+ (void) opaque; /* unused */
+ (void) bitmap; /* unused */
+ assert(bitmap);
}
-
static bool bitmap_test_opaque(void *bitmap)
{
- (void) bitmap; /* unused */
- assert(bitmap);
- return false;
+ (void) bitmap; /* unused */
+ assert(bitmap);
+ return false;
}
-
static unsigned char *bitmap_get_buffer(void *bitmap)
{
- assert(bitmap);
- return bitmap;
+ assert(bitmap);
+ return bitmap;
}
-
static void bitmap_destroy(void *bitmap)
{
- assert(bitmap);
- free(bitmap);
+ assert(bitmap);
+ free(bitmap);
}
-
static void bitmap_modified(void *bitmap)
{
- (void) bitmap; /* unused */
- assert(bitmap);
- return;
+ (void) bitmap; /* unused */
+ assert(bitmap);
+ return;
}
static unsigned char *load_file(const char *path, size_t *data_size)
{
- FILE *fd;
- struct stat sb;
- unsigned char *buffer;
- size_t size;
- size_t n;
-
- fd = fopen(path, "rb");
- if (!fd) {
- perror(path);
- exit(EXIT_FAILURE);
- }
-
- if (stat(path, &sb)) {
- perror(path);
- exit(EXIT_FAILURE);
- }
- size = sb.st_size;
-
- buffer = malloc(size);
- if (!buffer) {
- fprintf(stderr, "Unable to allocate %lld bytes\n",
- (long long) size);
- exit(EXIT_FAILURE);
- }
-
- n = fread(buffer, 1, size, fd);
- if (n != size) {
- perror(path);
- exit(EXIT_FAILURE);
- }
-
- fclose(fd);
-
- *data_size = size;
- return buffer;
+ FILE *fd;
+ struct stat sb;
+ unsigned char *buffer;
+ size_t size;
+ size_t n;
+
+ fd = fopen(path, "rb");
+ if (!fd) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ if (stat(path, &sb)) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+ size = sb.st_size;
+
+ buffer = malloc(size);
+ if (!buffer) {
+ fprintf(stderr, "Unable to allocate %lld bytes\n",
+ (long long) size);
+ exit(EXIT_FAILURE);
+ }
+
+ n = fread(buffer, 1, size, fd);
+ if (n != size) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ fclose(fd);
+
+ *data_size = size;
+ return buffer;
}
-
static void warning(const char *context, gif_result code)
{
- fprintf(stderr, "%s failed: ", context);
- switch (code)
- {
- case GIF_FRAME_DATA_ERROR:
- fprintf(stderr, "GIF_FRAME_DATA_ERROR");
- break;
- case GIF_INSUFFICIENT_DATA:
- fprintf(stderr, "GIF_INSUFFICIENT_DATA");
- break;
- case GIF_DATA_ERROR:
- fprintf(stderr, "GIF_DATA_ERROR");
- break;
- case GIF_INSUFFICIENT_MEMORY:
- fprintf(stderr, "GIF_INSUFFICIENT_MEMORY");
- break;
- default:
- fprintf(stderr, "unknown code %i", code);
- break;
- }
- fprintf(stderr, "\n");
+ fprintf(stderr, "%s failed: ", context);
+ switch (code)
+ {
+ case GIF_FRAME_DATA_ERROR:
+ fprintf(stderr, "GIF_FRAME_DATA_ERROR");
+ break;
+ case GIF_INSUFFICIENT_DATA:
+ fprintf(stderr, "GIF_INSUFFICIENT_DATA");
+ break;
+ case GIF_DATA_ERROR:
+ fprintf(stderr, "GIF_DATA_ERROR");
+ break;
+ case GIF_INSUFFICIENT_MEMORY:
+ fprintf(stderr, "GIF_INSUFFICIENT_MEMORY");
+ break;
+ default:
+ fprintf(stderr, "unknown code %i", code);
+ break;
+ }
+ fprintf(stderr, "\n");
}
static void write_ppm(FILE* fh, const char *name, gif_animation *gif,
- bool no_write)
+ bool no_write)
{
- unsigned int i;
- gif_result code;
-
- if (!no_write) {
- fprintf(fh, "P3\n");
- fprintf(fh, "# %s\n", name);
- fprintf(fh, "# width %u \n", gif->width);
- fprintf(fh, "# height %u \n", gif->height);
- fprintf(fh, "# frame_count %u \n",
gif->frame_count);
- fprintf(fh, "# frame_count_partial %u \n",
gif->frame_count_partial);
- fprintf(fh, "# loop_count %u \n",
gif->loop_count);
- fprintf(fh, "%u %u 256\n", gif->width, gif->height *
gif->frame_count);
- }
-
- /* decode the frames */
- for (i = 0; i != gif->frame_count; i++) {
- unsigned int row, col;
- unsigned char *image;
-
- code = gif_decode_frame(gif, i);
- if (code != GIF_OK)
- warning("gif_decode_frame", code);
-
- if (!gif->frames[i].display) {
- continue;
- }
-
- if (!no_write) {
- fprintf(fh, "# frame %u:\n", i);
- image = (unsigned char *) gif->frame_image;
- for (row = 0; row != gif->height; row++) {
- for (col = 0; col != gif->width; col++) {
- size_t z = (row * gif->width + col) * 4;
- fprintf(fh, "%u %u %u ",
- (unsigned char) image[z],
- (unsigned char) image[z + 1],
- (unsigned char) image[z + 2]);
- }
- fprintf(fh, "\n");
- }
- }
- }
-
+ unsigned int i;
+ gif_result code;
+
+ if (!no_write) {
+ fprintf(fh, "P3\n");
+ fprintf(fh, "# %s\n", name);
+ fprintf(fh, "# width %u \n", gif->width);
+ fprintf(fh, "# height %u \n", gif->height);
+ fprintf(fh, "# frame_count %u \n", gif->frame_count);
+ fprintf(fh, "# frame_count_partial %u \n", gif->frame_count_partial);
+ fprintf(fh, "# loop_count %u \n", gif->loop_count);
+ fprintf(fh, "%u %u 256\n", gif->width, gif->height *
gif->frame_count);
+ }
+
+ /* decode the frames */
+ for (i = 0; i != gif->frame_count; i++) {
+ unsigned int row, col;
+ unsigned char *image;
+
+ code = gif_decode_frame(gif, i);
+ if (code != GIF_OK)
+ warning("gif_decode_frame", code);
+
+ if (!gif->frames[i].display) {
+ continue;
+ }
+
+ if (!no_write) {
+ fprintf(fh, "# frame %u:\n", i);
+ image = (unsigned char *) gif->frame_image;
+ for (row = 0; row != gif->height; row++) {
+ for (col = 0; col != gif->width; col++) {
+ size_t z = (row * gif->width + col) * 4;
+ fprintf(fh, "%u %u %u ",
+ (unsigned char) image[z],
+ (unsigned char) image[z + 1],
+ (unsigned char) image[z + 2]);
+ }
+ fprintf(fh, "\n");
+ }
+ }
+ }
}
int main(int argc, char *argv[])
{
- gif_bitmap_callback_vt bitmap_callbacks = {
- bitmap_create,
- bitmap_destroy,
- bitmap_get_buffer,
- bitmap_set_opaque,
- bitmap_test_opaque,
- bitmap_modified
- };
- gif_animation gif;
- size_t size;
- gif_result code;
- unsigned char *data;
- FILE *outf = stdout;
- bool no_write = false;
-
- if (argc < 2) {
- fprintf(stderr, "Usage: %s image.gif [out]\n", argv[0]);
- fprintf(stderr, "\n");
- fprintf(stderr, "If [out] is NOWRITE, the gif will be docoded
"
- "but not output.\n");
- fprintf(stderr, "Otherwise [out] is an output filename.\n");
- fprintf(stderr, "When [out] is unset, output is to
stdout.\n");
-
- return 1;
- }
-
- if (argc > 2) {
- if (strcmp(argv[2], "NOWRITE") == 0) {
- no_write = true;
- } else {
- outf = fopen(argv[2], "w+");
- if (outf == NULL) {
- fprintf(stderr, "Unable to open %s for
writing\n", argv[2]);
- return 2;
- }
- }
- }
-
- /* create our gif animation */
- gif_create(&gif, &bitmap_callbacks);
-
- /* load file into memory */
- data = load_file(argv[1], &size);
-
- /* begin decoding */
- do {
- code = gif_initialise(&gif, size, data);
- if (code != GIF_OK && code != GIF_WORKING) {
- warning("gif_initialise", code);
- gif_finalise(&gif);
- free(data);
- return 1;
- }
- } while (code != GIF_OK);
-
- write_ppm(outf, argv[1], &gif, no_write);
-
- if (argc > 2 && !no_write) {
- fclose(outf);
- }
-
- /* clean up */
- gif_finalise(&gif);
- free(data);
-
- return 0;
+ gif_bitmap_callback_vt bitmap_callbacks = {
+ bitmap_create,
+ bitmap_destroy,
+ bitmap_get_buffer,
+ bitmap_set_opaque,
+ bitmap_test_opaque,
+ bitmap_modified
+ };
+ gif_animation gif;
+ size_t size;
+ gif_result code;
+ unsigned char *data;
+ FILE *outf = stdout;
+ bool no_write = false;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s image.gif [out]\n", argv[0]);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "If [out] is NOWRITE, the gif will be docoded "
+ "but not output.\n");
+ fprintf(stderr, "Otherwise [out] is an output filename.\n");
+ fprintf(stderr, "When [out] is unset, output is to stdout.\n");
+
+ return 1;
+ }
+
+ if (argc > 2) {
+ if (strcmp(argv[2], "NOWRITE") == 0) {
+ no_write = true;
+ } else {
+ outf = fopen(argv[2], "w+");
+ if (outf == NULL) {
+ fprintf(stderr, "Unable to open %s for writing\n", argv[2]);
+ return 2;
+ }
+ }
+ }
+
+ /* create our gif animation */
+ gif_create(&gif, &bitmap_callbacks);
+
+ /* load file into memory */
+ data = load_file(argv[1], &size);
+
+ /* begin decoding */
+ do {
+ code = gif_initialise(&gif, size, data);
+ if (code != GIF_OK && code != GIF_WORKING) {
+ warning("gif_initialise", code);
+ gif_finalise(&gif);
+ free(data);
+ return 1;
+ }
+ } while (code != GIF_OK);
+
+ write_ppm(outf, argv[1], &gif, no_write);
+
+ if (argc > 2 && !no_write) {
+ fclose(outf);
+ }
+
+ /* clean up */
+ gif_finalise(&gif);
+ free(data);
+
+ return 0;
}
--
NetSurf GIF Decoder