This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 05551ed06488f6e537a0705980630f2d36b47c40 (commit) via c793286d79acf527139becc2b6ba847193cad08d (commit) from a2f97569d98cda1ac080fbe73de4fa58fa5ae10b (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 ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/05551ed06488f6e537a0705980630f2d36b47...
commit 05551ed06488f6e537a0705980630f2d36b47c40 Author: Cyril Hrubis metan@ucw.cz Date: Fri Nov 4 13:43:15 2011 +0100
Add progress callback to JPG and PNG loaders.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c index 260e821..ead85bf 100644 --- a/demos/fbshow/fbshow.c +++ b/demos/fbshow/fbshow.c @@ -69,6 +69,7 @@ static float calc_img_size(uint32_t img_w, uint32_t img_h, static void *image_loader(void *ptr) { struct loader_params *params = ptr; + GP_ProgressCallback callback = {.callback = image_loader_callback};
fprintf(stderr, "Loading '%s'n", params->img_path);
@@ -83,7 +84,7 @@ static void *image_loader(void *ptr)
GP_Context *img = NULL;
- if (GP_LoadImage(params->img_path, &img) != 0) { + if (GP_LoadImage(params->img_path, &img, &callback) != 0) { GP_BoxCenteredText(&fb->context, NULL, 0, 0, fb->context.w, fb->context.h, "Failed to load image", white_pixel); @@ -115,7 +116,6 @@ static void *image_loader(void *ptr) img = tmp; } - GP_ProgressCallback callback = {.callback = image_loader_callback}; GP_Context *ret;
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c index 2854ac3..9833ea1 100644 --- a/demos/grinder/grinder.c +++ b/demos/grinder/grinder.c @@ -549,7 +549,7 @@ int main(int argc, char *argv[]) snprintf(buf, sizeof(buf), "out_%i.ppm", i - optind + 1); fprintf(stderr, "Processing '%s' -> '%s'n", argv[i], buf);
- if ((ret = GP_LoadImage(argv[i], &bitmap))) { + if ((ret = GP_LoadImage(argv[i], &bitmap, NULL))) { fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret)); return 1; diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h index bef6e10..fddac6e 100644 --- a/include/loaders/GP_JPG.h +++ b/include/loaders/GP_JPG.h @@ -26,10 +26,11 @@
*/
-#ifndef GP_JPG_H -#define GP_JPG_H +#ifndef LOADERS_GP_JPG_H +#define LOADERS_GP_JPG_H
#include "core/GP_Context.h" +#include "core/GP_ProgressCallback.h"
/* * Opens up file and checks signature. Upon successful return the file @@ -41,11 +42,13 @@ GP_RetCode GP_OpenJPG(const char *src_path, FILE **f); * Reads PNG from an open FILE. Expects the file possition set after the eight * bytes PNG signature. */ -GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res); +GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res, + GP_ProgressCallback *callback);
/* * Loads a PNG file into GP_Context. The Context is newly allocated. */ -GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res); +GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res, + GP_ProgressCallback *callback);
-#endif /* GP_JPG_H */ +#endif /* LOADERS_GP_JPG_H */ diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h index e3ff703..b327744 100644 --- a/include/loaders/GP_Loaders.h +++ b/include/loaders/GP_Loaders.h @@ -29,10 +29,11 @@
*/
-#ifndef GP_LOADERS_H -#define GP_LOADERS_H +#ifndef LOADERS_GP_LOADERS_H +#define LOADERS_GP_LOADERS_H
#include "core/GP_Context.h" +#include "core/GP_ProgressCallback.h"
#include "GP_PBM.h" #include "GP_PGM.h" @@ -45,6 +46,7 @@ /* * Tries to load image accordingly to extension. */ -GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res); +GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res, + GP_ProgressCallback *callback);
-#endif /* GP_LOADERS_H */ +#endif /* LOADERS_GP_LOADERS_H */ diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h index 2b02deb..cfa9438 100644 --- a/include/loaders/GP_PNG.h +++ b/include/loaders/GP_PNG.h @@ -26,9 +26,10 @@
*/
-#ifndef GP_PNG_H -#define GP_PNG_H +#ifndef LOADERS_GP_PNG_H +#define LOADERS_GP_PNG_H
+#include "core/GP_ProgressCallback.h" #include "core/GP_Context.h"
/* @@ -41,11 +42,13 @@ GP_RetCode GP_OpenPNG(const char *src_path, FILE **f); * Reads PNG from an open FILE. Expects the file possition set after the eight * bytes PNG signature. */ -GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res); +GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res, + GP_ProgressCallback *callback);
/* * Loads a PNG file into GP_Context. The Context is newly allocated. */ -GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res); +GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res, + GP_ProgressCallback *callback);
#endif /* GP_PNG_H */ diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c index 5958dab..be0b67c 100644 --- a/libs/loaders/GP_JPG.c +++ b/libs/loaders/GP_JPG.c @@ -36,8 +36,8 @@
#include <jpeglib.h>
-#include <GP_Context.h> -#include <GP_Debug.h> +#include "GP_JPG.h" +#include "core/GP_Debug.h"
GP_RetCode GP_OpenJPG(const char *src_path, FILE **f) { @@ -87,7 +87,8 @@ static const char *get_colorspace(J_COLOR_SPACE color_space) }; }
-GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res) +GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res, + GP_ProgressCallback *callback) { struct jpeg_decompress_struct cinfo; struct my_jpg_err my_err; @@ -163,17 +164,27 @@ GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res) uint8_t *pix = GP_PIXEL_ADDR(ret, i, y); GP_SWAP(pix[0], pix[2]); } + + if (GP_ProgressCallbackReport(callback, y, ret->h, ret->w)) { + GP_DEBUG(1, "Operation aborted"); + jpeg_destroy_decompress(&cinfo); + fclose(f); + GP_ContextFree(ret); + return GP_EINTR; + } }
jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); fclose(f); *res = ret; - + + GP_ProgressCallbackDone(callback); return GP_ESUCCESS; }
-GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res) +GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res, + GP_ProgressCallback *callback) { FILE *f; GP_RetCode ret; @@ -181,5 +192,5 @@ GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res) if ((ret = GP_OpenJPG(src_path, &f))) return ret;
- return GP_ReadJPG(f, res); + return GP_ReadJPG(f, res, callback); } diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c index 8f69d03..8a57c59 100644 --- a/libs/loaders/GP_Loaders.c +++ b/libs/loaders/GP_Loaders.c @@ -30,11 +30,12 @@ #include <unistd.h> #include <errno.h>
-#include <GP_Debug.h> +#include "core/GP_Debug.h"
#include "GP_Loaders.h"
-GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res) +GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res, + GP_ProgressCallback *callback) { int len = strlen(src_path); GP_RetCode ret = GP_ENOIMPL; @@ -54,13 +55,13 @@ GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res) case 'N': if (src_path[len - 3] == 'p' || src_path[len - 3] == 'P') - ret = GP_LoadPNG(src_path, res); + ret = GP_LoadPNG(src_path, res, callback); break; case 'p': case 'P': if (src_path[len - 3] == 'j' || src_path[len - 3] == 'J') - ret = GP_LoadJPG(src_path, res); + ret = GP_LoadJPG(src_path, res, callback); break; case 'e': case 'E': @@ -68,7 +69,7 @@ GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res) src_path[len - 3] == 'P') && (src_path[len - 4] == 'j' || src_path[len - 4] == 'J')) - ret = GP_LoadJPG(src_path, res); + ret = GP_LoadJPG(src_path, res, callback); break; } break; diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c index dae8120..b013c42 100644 --- a/libs/loaders/GP_PNG.c +++ b/libs/loaders/GP_PNG.c @@ -34,8 +34,8 @@
#include <png.h>
-#include <GP_Context.h> -#include <GP_Debug.h> +#include "GP_PNG.h" +#include "core/GP_Debug.h"
GP_RetCode GP_OpenPNG(const char *src_path, FILE **f) { @@ -70,7 +70,8 @@ err: return GP_EBADFILE; }
-GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res) +GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res, + GP_ProgressCallback *callback) { png_structp png; png_infop png_info = NULL; @@ -171,8 +172,19 @@ GP_RetCode GP_ReadPNG(FILE *f, GP_Context **res) for (y = 0; y < h; y++) { png_bytep addr = GP_PIXEL_ADDR(*res, 0, y); png_read_rows(png, &addr, NULL, 1); + + if (GP_ProgressCallbackReport(callback, y, h, w)) { + GP_DEBUG(1, "Operation aborted"); + png_destroy_read_struct(&png, &png_info, NULL); + fclose(f); + GP_ContextFree(*res); + return GP_EINTR; + } + }
+ GP_ProgressCallbackDone(callback); + ret = GP_ESUCCESS; err2: png_destroy_read_struct(&png, png_info ? &png_info : NULL, NULL); @@ -181,7 +193,8 @@ err1: return ret; }
-GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res) +GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res, + GP_ProgressCallback *callback) { FILE *f; GP_RetCode ret; @@ -189,5 +202,5 @@ GP_RetCode GP_LoadPNG(const char *src_path, GP_Context **res) if ((ret = GP_OpenPNG(src_path, &f))) return ret;
- return GP_ReadPNG(f, res); + return GP_ReadPNG(f, res, callback); } diff --git a/tests/SDL/showimage.c b/tests/SDL/showimage.c index 134f8f9..9df416d 100644 --- a/tests/SDL/showimage.c +++ b/tests/SDL/showimage.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[])
GP_RetCode ret;
- if ((ret = GP_LoadImage(argv[1], &bitmap))) { + if ((ret = GP_LoadImage(argv[1], &bitmap, NULL))) { fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret)); return 1; }
http://repo.or.cz/w/gfxprim.git/commit/c793286d79acf527139becc2b6ba847193cad...
commit c793286d79acf527139becc2b6ba847193cad08d Author: Cyril Hrubis metan@ucw.cz Date: Fri Nov 4 13:26:56 2011 +0100
Added GP_EINTR ret code.
diff --git a/include/core/GP_RetCode.h b/include/core/GP_RetCode.h index 9241a26..ce875fd 100644 --- a/include/core/GP_RetCode.h +++ b/include/core/GP_RetCode.h @@ -19,12 +19,12 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
-#ifndef GP_RETCODE_H -#define GP_RETCODE_H +#ifndef CORE_GP_RETCODE_H +#define CORE_GP_RETCODE_H
typedef enum GP_RetCode { GP_ESUCCESS, @@ -38,9 +38,10 @@ typedef enum GP_RetCode { GP_EBADFILE, /* error in file, or bad file format */ GP_ENOENT, /* no such file or another object */ GP_ENOMEM, /* not enough memory */ + GP_EINTR, /* operation interrupted by user */ GP_EMAX, } GP_RetCode;
const char *GP_RetCodeName(GP_RetCode code);
-#endif /* GP_RETCODE_H */ +#endif /* CORE_GP_RETCODE_H */ diff --git a/libs/core/GP_RetCode.c b/libs/core/GP_RetCode.c index a4069c5..f14b5cc 100644 --- a/libs/core/GP_RetCode.c +++ b/libs/core/GP_RetCode.c @@ -19,7 +19,7 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -37,10 +37,10 @@ static char *ret_code_names[] = { "Bad context", "Bad file", "Not found", - "Not enough memory" + "Not enough memory", + "Operation interrupted" };
- const char *GP_RetCodeName(GP_RetCode code) { if (code >= GP_EMAX)
-----------------------------------------------------------------------
Summary of changes: demos/fbshow/fbshow.c | 4 ++-- demos/grinder/grinder.c | 2 +- include/core/GP_RetCode.h | 9 +++++---- include/loaders/GP_JPG.h | 13 ++++++++----- include/loaders/GP_Loaders.h | 10 ++++++---- include/loaders/GP_PNG.h | 11 +++++++---- libs/core/GP_RetCode.c | 6 +++--- libs/loaders/GP_JPG.c | 23 +++++++++++++++++------ libs/loaders/GP_Loaders.c | 11 ++++++----- libs/loaders/GP_PNG.c | 23 ++++++++++++++++++----- tests/SDL/showimage.c | 2 +- 11 files changed, 74 insertions(+), 40 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.