From 9acb17dea42411b27a5782cf842d962b3c0525dc Mon Sep 17 00:00:00 2001 From: James Zern Date: Sun, 17 Mar 2013 17:04:54 -0700 Subject: [PATCH 1/3] gif2webp: silence a unused param warning Change-Id: I694857fc6adb011f19d14780de4f8c71e2719707 --- examples/gif2webp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/gif2webp.c b/examples/gif2webp.c index 6bb954db..6cd8b3c4 100644 --- a/examples/gif2webp.c +++ b/examples/gif2webp.c @@ -142,10 +142,12 @@ static void DisplayGifError(const GifFileType* const gif) { const char* error_str = (const char*)GifErrorString(gif->Error); #else const char* error_str = (const char*)GifErrorString(); + (void)gif; #endif if (error_str == NULL) error_str = "Unknown error"; fprintf(stderr, "GIFLib Error: %s\n", error_str); #else + (void)gif; fprintf(stderr, "GIFLib Error: "); PrintGifError(); fprintf(stderr, "\n"); From 59423a24860e4dfbab09236545c5d097a8d12515 Mon Sep 17 00:00:00 2001 From: James Zern Date: Sun, 17 Mar 2013 18:06:39 -0700 Subject: [PATCH 2/3] gif2webp: fix crash on open failure with libgif5 output the current gif_error and use it instead of the NULL context to retrieve an error message. Change-Id: Ib761ebd36b3ddd6288375de46e671022d2381083 --- examples/gif2webp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/gif2webp.c b/examples/gif2webp.c index 6cd8b3c4..5f4d275c 100644 --- a/examples/gif2webp.c +++ b/examples/gif2webp.c @@ -132,23 +132,24 @@ static int GetColorFromIndex(const ColorMapObject* const color_map, GifWord idx, } } -static void DisplayGifError(const GifFileType* const gif) { +static void DisplayGifError(const GifFileType* const gif, int gif_error) { // GIFLIB_MAJOR is only defined in libgif >= 4.2.0. // libgif 4.2.0 has retired PrintGifError() and added GifErrorString(). #if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && \ ((GIFLIB_MAJOR == 4 && GIFLIB_MINOR >= 2) || GIFLIB_MAJOR > 4) #if GIFLIB_MAJOR >= 5 // Static string actually, hence the const char* cast. - const char* error_str = (const char*)GifErrorString(gif->Error); + const char* error_str = (const char*)GifErrorString( + (gif == NULL) ? gif_error : gif->Error); #else const char* error_str = (const char*)GifErrorString(); (void)gif; #endif if (error_str == NULL) error_str = "Unknown error"; - fprintf(stderr, "GIFLib Error: %s\n", error_str); + fprintf(stderr, "GIFLib Error %d: %s\n", gif_error, error_str); #else (void)gif; - fprintf(stderr, "GIFLib Error: "); + fprintf(stderr, "GIFLib Error %d: ", gif_error); PrintGifError(); fprintf(stderr, "\n"); #endif @@ -186,7 +187,7 @@ static void Help(void) { int main(int argc, const char *argv[]) { int verbose = 0; - int gif_error = -1; + int gif_error = GIF_ERROR; WebPMuxError err = WEBP_MUX_OK; int ok = 0; const char *in_file = NULL, *out_file = NULL; @@ -458,7 +459,7 @@ int main(int argc, const char *argv[]) { // All OK. ok = 1; - gif_error = 0; + gif_error = GIF_OK; End: WebPDataClear(&webp_data); @@ -466,8 +467,8 @@ int main(int argc, const char *argv[]) { WebPPictureFree(&picture); if (out != NULL && out_file != NULL) fclose(out); - if (gif_error != 0) { - DisplayGifError(gif); + if (gif_error != GIF_OK) { + DisplayGifError(gif, gif_error); } if (gif != NULL) { DGifCloseFile(gif); From 723847d5d71d891d8830a3171bc6eb68967bd683 Mon Sep 17 00:00:00 2001 From: James Zern Date: Sun, 17 Mar 2013 18:08:01 -0700 Subject: [PATCH 3/3] gif2webp: only write error messages to stderr also output something if -o is not given, but the process succeeded Change-Id: I466c377f0cbf8c9f45bb1839191b04dada9c5f0f --- examples/gif2webp.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/gif2webp.c b/examples/gif2webp.c index 5f4d275c..53694417 100644 --- a/examples/gif2webp.c +++ b/examples/gif2webp.c @@ -343,11 +343,11 @@ int main(int argc, const char *argv[]) { goto End; } if (verbose) { - fprintf(stderr, "Added frame %dx%d (offset:%d,%d duration:%d) ", - view.width, view.height, frame.x_offset, frame.y_offset, - frame.duration); - fprintf(stderr, "dispose:%d transparent index:%d\n", - frame.dispose_method, transparent_index); + printf("Added frame %dx%d (offset:%d,%d duration:%d) ", + view.width, view.height, frame.x_offset, frame.y_offset, + frame.duration); + printf("dispose:%d transparent index:%d\n", + frame.dispose_method, transparent_index); } WebPDataClear(&frame.bitstream); break; @@ -392,7 +392,7 @@ int main(int argc, const char *argv[]) { if (data == NULL) goto End; // Loop count sub-block missing. if (data[0] != 3 && data[1] != 1) break; // wrong size/marker anim.loop_count = data[2] | (data[3] << 8); - if (verbose) fprintf(stderr, "Loop count: %d\n", anim.loop_count); + if (verbose) printf("Loop count: %d\n", anim.loop_count); } else if (!memcmp(data + 1, "XMP dataXMP", 11)) { // Read XMP metadata. WebPData xmp; @@ -401,7 +401,7 @@ int main(int argc, const char *argv[]) { xmp.bytes = (uint8_t*)data; xmp.size = data[0] + 1; WebPMuxSetChunk(mux, "XMP ", &xmp, 1); - if (verbose) fprintf(stderr, "XMP size: %zu\n", xmp.size); + if (verbose) printf("XMP size: %zu\n", xmp.size); } else if (!memcmp(data + 1, "ICCRGBG1012", 11)) { // Read ICC profile. WebPData icc; @@ -410,7 +410,7 @@ int main(int argc, const char *argv[]) { icc.bytes = (uint8_t*)data; icc.size = data[0] + 1; WebPMuxSetChunk(mux, "ICCP", &icc, 1); - if (verbose) fprintf(stderr, "ICC size: %zu\n", icc.size); + if (verbose) printf("ICC size: %zu\n", icc.size); } break; } @@ -454,7 +454,13 @@ int main(int argc, const char *argv[]) { fprintf(stderr, "Error writing output file: %s\n", out_file); goto End; } - if (!quiet) fprintf(stderr, "Saved output file: %s\n", out_file); + if (!quiet) { + printf("Saved output file: %s\n", out_file); + } + } else { + if (!quiet) { + printf("Nothing written; use -o flag to save the result.\n"); + } } // All OK.