summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-02-23 16:11:00 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2022-02-23 16:13:14 +0000
commit9c08b7c139cb95be8b3fbf21c46c564bfaff8c56 (patch)
tree600bb0a2227eba28dc438447d582e1a1059ae145 /test
parent88a078653a15d157b7c6f3ba57211f11f9121dab (diff)
downloadlibnsgif-9c08b7c139cb95be8b3fbf21c46c564bfaff8c56.tar.gz
libnsgif-9c08b7c139cb95be8b3fbf21c46c564bfaff8c56.tar.bz2
Test: Decoder: Simplify logic.
Diffstat (limited to 'test')
-rw-r--r--test/decode_gif.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/test/decode_gif.c b/test/decode_gif.c
index 5789c41..5f5c377 100644
--- a/test/decode_gif.c
+++ b/test/decode_gif.c
@@ -101,7 +101,7 @@ static void warning(const char *context, nsgif_result gif_res)
fprintf(stderr, "\n");
}
-static void write_ppm(FILE* fh, const char *name, nsgif *gif, bool no_write)
+static void decode(FILE* fh, const char *name, nsgif *gif, bool write_ppm)
{
nsgif_result gif_res;
uint32_t frame_prev = 0;
@@ -109,7 +109,7 @@ static void write_ppm(FILE* fh, const char *name, nsgif *gif, bool no_write)
info = nsgif_get_info(gif);
- if (!no_write) {
+ if (write_ppm) {
fprintf(fh, "P3\n");
fprintf(fh, "# %s\n", name);
fprintf(fh, "# width %u \n", info->width);
@@ -148,7 +148,7 @@ static void write_ppm(FILE* fh, const char *name, nsgif *gif, bool no_write)
return;
}
- if (!no_write) {
+ if (write_ppm) {
fprintf(fh, "# frame %u:\n", frame_new);
image = (const uint8_t *) buffer;
for (uint32_t y = 0; y != info->height; y++) {
@@ -211,18 +211,16 @@ int main(int argc, char *argv[])
/* load file into memory */
data = load_file(argv[1], &size);
- /* begin decoding */
- do {
- gif_res = nsgif_data_scan(gif, size, data);
- if (gif_res != NSGIF_OK && gif_res != NSGIF_WORKING) {
- warning("nsgif_data_scan", gif_res);
- nsgif_destroy(gif);
- free(data);
- return 1;
- }
- } while (gif_res != NSGIF_OK);
+ /* Scan the raw data */
+ gif_res = nsgif_data_scan(gif, size, data);
+ if (gif_res != NSGIF_OK) {
+ warning("nsgif_data_scan", gif_res);
+ nsgif_destroy(gif);
+ free(data);
+ return 1;
+ }
- write_ppm(outf, argv[1], gif, no_write);
+ decode(outf, argv[1], gif, !no_write);
if (argc > 2 && !no_write) {
fclose(outf);