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 069262b67e2bd246c98f76a4f9ddbbf9bf3c992f (commit) via 2d816b6c01944b146c69c1db821eea6147e2b5cb (commit) via 4bec01e5af42cb68e680f3a6d452d543b8c4d004 (commit) via e341668ccad607f9843386e206105f086ae307d0 (commit) from 13195186d44e871af057bda262ddf8467ff8049c (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/069262b67e2bd246c98f76a4f9ddbbf9bf3c9...
commit 069262b67e2bd246c98f76a4f9ddbbf9bf3c992f Author: Cyril Hrubis metan@ucw.cz Date: Fri Jun 13 11:32:22 2014 +0200
loaders: GP_Loader: Get rid of unneeded members
This commit cleanups a few aspects of loaders implementation.
It creates GP_LoaderLoadImage() function that can be used to load image from path for a given loader pointer which allows us to.
* Get rid of the Load() callback from GP_Loader
* Unify GP_LoadFOO implementation
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h index 3860ac10..6f07d2ea 100644 --- a/include/loaders/GP_Loader.h +++ b/include/loaders/GP_Loader.h @@ -85,13 +85,6 @@ typedef struct GP_Loader { GP_Context *(*Read)(GP_IO *io, GP_ProgressCallback *callback);
/* - * Loads an image from a file. - * - * TODO: Remove due to Read - */ - GP_Context *(*Load)(const char *src_path, GP_ProgressCallback *callback); - - /* * Save an image. * * Returns zero on succes, non-zero on failure and errno must be set. @@ -109,9 +102,6 @@ typedef struct GP_Loader { */ const char *fmt_name;
- /* don't touch */ - struct GP_Loader *next; - /* * NULL terminated array of file extensions. */ @@ -146,6 +136,15 @@ int GP_LoaderRegister(GP_Loader *self); void GP_LoaderUnregister(GP_Loader *self);
/* + * Generic LoadImage for a given loader. + * + * The function prepares the IO from file, calls the loader Read() method, + * closes the IO and returns the context. + */ +GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path, + GP_ProgressCallback *callback); + +/* * List loaders into the stdout */ void GP_ListLoaders(void); diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index 9fcff422..4313e2de 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -703,21 +703,7 @@ err1:
GP_Context *GP_LoadBMP(const char *src_path, GP_ProgressCallback *callback) { - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadBMP(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; + return GP_LoaderLoadImage(&GP_BMP, src_path, callback); }
/* @@ -908,7 +894,6 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path,
struct GP_Loader GP_BMP = { .Read = GP_ReadBMP, - .Load = GP_LoadBMP, .Save = GP_SaveBMP, .Match = GP_MatchBMP,
diff --git a/libs/loaders/GP_GIF.c b/libs/loaders/GP_GIF.c index 6425d60a..a4f3afc0 100644 --- a/libs/loaders/GP_GIF.c +++ b/libs/loaders/GP_GIF.c @@ -358,25 +358,6 @@ err1: return NULL; }
-GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadGIF(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - #else
int GP_MatchGIF(const void GP_UNUSED(*buf)) @@ -392,20 +373,19 @@ GP_Context *GP_ReadGIF(GP_IO GP_UNUSED(*io), return NULL; }
-GP_Context *GP_LoadGIF(const char GP_UNUSED(*src_path), - GP_ProgressCallback GP_UNUSED(*callback)) +#endif /* HAVE_GIFLIB */ + +GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback) { - errno = ENOSYS; - return NULL; + return GP_LoaderLoadImage(&GP_GIF, src_path, callback); }
-#endif /* HAVE_GIFLIB */ - struct GP_Loader GP_GIF = { +#ifdef HAVE_GIFLIB .Read = GP_ReadGIF, - .Load = GP_LoadGIF, - .Save = NULL, +#endif .Match = GP_MatchGIF, + .fmt_name = "Graphics Interchange Format", .extensions = {"gif", NULL}, }; diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c index f451b6f1..941849b2 100644 --- a/libs/loaders/GP_JP2.c +++ b/libs/loaders/GP_JP2.c @@ -225,25 +225,6 @@ err0: return res; }
-GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadJP2(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - #else
GP_Context *GP_ReadJP2(GP_IO GP_UNUSED(*io), @@ -253,19 +234,17 @@ GP_Context *GP_ReadJP2(GP_IO GP_UNUSED(*io), return NULL; }
-GP_Context *GP_LoadJP2(const char GP_UNUSED(*src_path), - GP_ProgressCallback GP_UNUSED(*callback)) +#endif /* HAVE_OPENJPEG */ + +GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback) { - errno = ENOSYS; - return NULL; + return GP_LoaderLoadImage(&GP_JP2, src_path, callback); }
-#endif /* HAVE_OPENJPEG */ - struct GP_Loader GP_JP2 = { +#ifdef HAVE_OPENJPEG .Read = GP_ReadJP2, - .Load = GP_LoadJP2, - .Save = NULL, +#endif .Match = GP_MatchJP2,
.fmt_name = "JPEG 2000", diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c index ca14b180..ea891712 100644 --- a/libs/loaders/GP_JPG.c +++ b/libs/loaders/GP_JPG.c @@ -290,25 +290,6 @@ err1: return NULL; }
-GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadJPG(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - #define JPEG_COM_MAX 128
static void read_jpg_metadata(struct jpeg_decompress_struct *cinfo, @@ -564,13 +545,6 @@ GP_Context *GP_ReadJPG(GP_IO GP_UNUSED(*io), return NULL; }
-GP_Context *GP_LoadJPG(const char GP_UNUSED(*src_path), - GP_ProgressCallback GP_UNUSED(*callback)) -{ - errno = ENOSYS; - return NULL; -} - int GP_ReadJPGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data)) { errno = ENOSYS; @@ -594,10 +568,16 @@ int GP_SaveJPG(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_JPEG */
+GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImage(&GP_JPG, src_path, callback); +} + struct GP_Loader GP_JPG = { +#ifdef HAVE_JPEG .Read = GP_ReadJPG, - .Load = GP_LoadJPG, .Save = GP_SaveJPG, +#endif .Match = GP_MatchJPG,
.fmt_name = "JPEG", diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c index c3b74feb..763e819b 100644 --- a/libs/loaders/GP_Loader.c +++ b/libs/loaders/GP_Loader.c @@ -126,7 +126,6 @@ void GP_ListLoaders(void) for (i = 0; loaders[i]; i++) { printf("Format: %sn", loaders[i]->fmt_name); printf("Read:t%sn", loaders[i]->Read ? "Yes" : "No"); - printf("Load:t%sn", loaders[i]->Load ? "Yes" : "No"); printf("Save:t%sn", loaders[i]->Save ? "Yes" : "No"); printf("Match:t%sn", loaders[i]->Match ? "Yes" : "No"); printf("Extensions: "); @@ -268,6 +267,31 @@ GP_Context *GP_ReadImage(GP_IO *io, GP_ProgressCallback *callback) return loader->Read(io, callback); }
+GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path, + GP_ProgressCallback *callback) +{ + GP_IO *io; + GP_Context *res; + int err; + + if (!self->Read) { + errno = ENOSYS; + return NULL; + } + + io = GP_IOFile(src_path, GP_IO_RDONLY); + if (!io) + return NULL; + + res = self->Read(io, callback); + + err = errno; + GP_IOClose(io); + errno = err; + + return res; +} + GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback) { int err; @@ -295,8 +319,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
ext_load = loader_by_filename(src_path);
- if (ext_load != NULL && ext_load->Load != NULL) { - img = ext_load->Load(src_path, callback); + if (ext_load) { + img = GP_LoaderLoadImage(ext_load, src_path, callback);
if (img) return img; @@ -316,8 +340,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback) src_path, ext_load->fmt_name, sig_load->fmt_name); }
- if (sig_load && sig_load->Load != NULL) - return sig_load->Load(src_path, callback); + if (sig_load) + return GP_LoaderLoadImage(sig_load, src_path, callback);
errno = ENOSYS; return NULL; diff --git a/libs/loaders/GP_PCX.c b/libs/loaders/GP_PCX.c index b04dc41b..330b0a7f 100644 --- a/libs/loaders/GP_PCX.c +++ b/libs/loaders/GP_PCX.c @@ -549,27 +549,11 @@ err0:
GP_Context *GP_LoadPCX(const char *src_path, GP_ProgressCallback *callback) { - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPCX(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; + return GP_LoaderLoadImage(&GP_PCX, src_path, callback); }
struct GP_Loader GP_PCX = { .Read = GP_ReadPCX, - .Load = GP_LoadPCX, - .Save = NULL, .Match = GP_MatchPCX,
.fmt_name = "ZSoft PCX", diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c index 2da8bcef..1a73c9a8 100644 --- a/libs/loaders/GP_PNG.c +++ b/libs/loaders/GP_PNG.c @@ -264,25 +264,6 @@ err1: return NULL; }
-GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPNG(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - static void load_meta_data(png_structp png, png_infop png_info, GP_MetaData *data) { double gamma; @@ -625,13 +606,6 @@ GP_Context *GP_ReadPNG(GP_IO GP_UNUSED(*io), return NULL; }
-GP_Context *GP_LoadPNG(const char GP_UNUSED(*src_path), - GP_ProgressCallback GP_UNUSED(*callback)) -{ - errno = ENOSYS; - return NULL; -} - int GP_ReadPNGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data)) { errno = ENOSYS; @@ -654,10 +628,16 @@ int GP_SavePNG(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_LIBPNG */
+GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImage(&GP_PNG, src_path, callback); +} + GP_Loader GP_PNG = { +#ifdef HAVE_LIBPNG .Read = GP_ReadPNG, - .Load = GP_LoadPNG, .Save = GP_SavePNG, +#endif .Match = GP_MatchPNG,
.fmt_name = "Portable Network Graphics", diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c index 63bb5361..93bc1b68 100644 --- a/libs/loaders/GP_PNM.c +++ b/libs/loaders/GP_PNM.c @@ -712,25 +712,6 @@ GP_Context *GP_ReadPBM(GP_IO *io, GP_ProgressCallback *callback) return read_bitmap(&buf, &header, callback); }
-GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPBM(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - int GP_SavePBM(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { @@ -882,25 +863,6 @@ GP_Context *GP_ReadPGM(GP_IO *io, GP_ProgressCallback *callback) return read_graymap(&buf, &header, callback); }
-GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPGM(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - static int pixel_to_depth(GP_Pixel pixel) { switch (pixel) { @@ -1026,25 +988,6 @@ GP_Context *GP_ReadPPM(GP_IO *io, GP_ProgressCallback *callback) return read_pixmap(&buf, &header, callback); }
-GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPPM(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - static int write_binary_ppm(FILE *f, GP_Context *src) { uint32_t x, y; @@ -1188,25 +1131,6 @@ GP_Context *GP_ReadPNM(GP_IO *io, GP_ProgressCallback *callback) return ret; }
-GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPNM(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - int GP_SavePNM(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { @@ -1227,9 +1151,28 @@ int GP_SavePNM(const GP_Context *src, const char *dst_path, } }
+GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImage(&GP_PBM, src_path, callback); +} + +GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImage(&GP_PGM, src_path, callback); +} + +GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImage(&GP_PPM, src_path, callback); +} + +GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImage(&GP_PNM, src_path, callback); +} + struct GP_Loader GP_PBM = { .Read = GP_ReadPBM, - .Load = GP_LoadPBM, .Save = GP_SavePBM, .Match = GP_MatchPBM,
@@ -1239,7 +1182,6 @@ struct GP_Loader GP_PBM = {
struct GP_Loader GP_PGM = { .Read = GP_ReadPGM, - .Load = GP_LoadPGM, .Save = GP_SavePGM, .Match = GP_MatchPGM,
@@ -1249,7 +1191,6 @@ struct GP_Loader GP_PGM = {
struct GP_Loader GP_PPM = { .Read = GP_ReadPPM, - .Load = GP_LoadPPM, .Save = GP_SavePPM, .Match = GP_MatchPPM,
@@ -1259,7 +1200,6 @@ struct GP_Loader GP_PPM = {
struct GP_Loader GP_PNM = { .Read = GP_ReadPNM, - .Load = GP_LoadPNM, .Save = GP_SavePNM, /* * Avoid double Match diff --git a/libs/loaders/GP_PSD.c b/libs/loaders/GP_PSD.c index 5ef73f11..ba86cb4e 100644 --- a/libs/loaders/GP_PSD.c +++ b/libs/loaders/GP_PSD.c @@ -813,27 +813,11 @@ err:
GP_Context *GP_LoadPSD(const char *src_path, GP_ProgressCallback *callback) { - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPSD(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; + return GP_LoaderLoadImage(&GP_PSD, src_path, callback); }
struct GP_Loader GP_PSD = { .Read = GP_ReadPSD, - .Load = GP_LoadPSD, - .Save = NULL, .Match = GP_MatchPSD,
.fmt_name = "Adobe Photoshop Image", diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c index bacd4b9b..64cdeaa6 100644 --- a/libs/loaders/GP_PSP.c +++ b/libs/loaders/GP_PSP.c @@ -491,27 +491,11 @@ err0:
GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback) { - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadPSP(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; + return GP_LoaderLoadImage(&GP_PSP, src_path, callback); }
struct GP_Loader GP_PSP = { .Read = GP_ReadPSP, - .Load = GP_LoadPSP, - .Save = NULL, .Match = GP_MatchPSP, .fmt_name = "Paint Shop Pro Image", .extensions = {"psp", "pspimage", NULL}, diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c index 1ea06554..bcc23b21 100644 --- a/libs/loaders/GP_TIFF.c +++ b/libs/loaders/GP_TIFF.c @@ -536,25 +536,6 @@ err0: return NULL; }
-GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback) -{ - GP_IO *io; - GP_Context *res; - int err; - - io = GP_IOFile(src_path, GP_IO_RDONLY); - if (!io) - return NULL; - - res = GP_ReadTIFF(io, callback); - - err = errno; - GP_IOClose(io); - errno = err; - - return res; -} - static int save_grayscale(TIFF *tiff, const GP_Context *src, GP_ProgressCallback *callback) { @@ -746,13 +727,6 @@ GP_Context *GP_ReadTIFF(GP_IO GP_UNUSED(*io), return NULL; }
-GP_Context *GP_LoadTIFF(const char GP_UNUSED(*src_path), - GP_ProgressCallback GP_UNUSED(*callback)) -{ - errno = ENOSYS; - return NULL; -} - int GP_SaveTIFF(const GP_Context GP_UNUSED(*src), const char GP_UNUSED(*dst_path), GP_ProgressCallback GP_UNUSED(*callback)) @@ -763,10 +737,16 @@ int GP_SaveTIFF(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_TIFF */
+GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback) +{ + return GP_LoaderLoadImage(&GP_TIFF, src_path, callback); +} + struct GP_Loader GP_TIFF = { +#ifdef HAVE_TIFF .Read = GP_ReadTIFF, - .Load = GP_LoadTIFF, .Save = GP_SaveTIFF, +#endif .Match = GP_MatchTIFF,
.fmt_name = "Tag Image File Format",
http://repo.or.cz/w/gfxprim.git/commit/2d816b6c01944b146c69c1db821eea6147e2b...
commit 2d816b6c01944b146c69c1db821eea6147e2b5cb Author: Cyril Hrubis metan@ucw.cz Date: Fri Jun 13 00:47:44 2014 +0200
loaders: Move GP_Loader structures to loaders
This commit moves the GP_Loader structures from GP_Loader.c to respecitive loaders which is preparation for additional members that will be added to GP_Loader structure.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt index b73506dd..20b54d9d 100644 --- a/build/syms/Loaders_symbols.txt +++ b/build/syms/Loaders_symbols.txt @@ -6,6 +6,7 @@ GP_LoadJPG GP_SaveJPG GP_ReadJPGMetaData GP_LoadJPGMetaData +GP_JPG
GP_MatchPNG GP_ReadPNG @@ -13,57 +14,69 @@ GP_LoadPNG GP_ReadPNGMetaData GP_LoadPNGMetaData GP_SavePNG +GP_PNG
GP_MatchBMP GP_WriteBMP GP_LoadBMP GP_ReadBMP GP_SaveBMP +GP_BMP
GP_MatchPSP GP_ReadPSP GP_LoadPSP +GP_PSP
GP_MatchGIF GP_LoadGIF GP_ReadGIF +GP_GIF
GP_MatchTIFF GP_ReadTIFF GP_LoadTIFF GP_SaveTIFF +GP_TIFF
GP_ReadPBM GP_LoadPBM GP_SavePBM GP_MatchPBM +GP_PBM
GP_ReadPGM GP_LoadPGM GP_SavePGM GP_MatchPGM +GP_PGM
GP_ReadPPM GP_LoadPPM GP_SavePPM GP_MatchPPM +GP_PPM
GP_ReadPNM GP_LoadPNM GP_SavePNM GP_MatchPNM +GP_PNM
GP_ReadJP2 GP_LoadJP2 GP_MatchJP2 +GP_JP2
GP_ReadPCX GP_LoadPCX GP_MatchPCX +GP_PCX
GP_ReadPSD GP_LoadPSD GP_MatchPSD +GP_PSD
GP_SaveTmpFile GP_LoadTmpFile diff --git a/include/loaders/GP_BMP.h b/include/loaders/GP_BMP.h index 047d7733..982de158 100644 --- a/include/loaders/GP_BMP.h +++ b/include/loaders/GP_BMP.h @@ -23,9 +23,7 @@ #ifndef LOADERS_GP_BMP_H #define LOADERS_GP_BMP_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * Reads a BMP from an IO stream. @@ -60,4 +58,7 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path, */ int GP_MatchBMP(const void *buf);
+ +extern GP_Loader GP_BMP; + #endif /* LOADERS_GP_BMP_H */ diff --git a/include/loaders/GP_GIF.h b/include/loaders/GP_GIF.h index 23405e20..989259f4 100644 --- a/include/loaders/GP_GIF.h +++ b/include/loaders/GP_GIF.h @@ -29,9 +29,7 @@ #ifndef LOADERS_GP_GIF_H #define LOADERS_GP_GIF_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * Reads first image found in GIF container from an IO stream. @@ -51,4 +49,6 @@ GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback); */ int GP_MatchGIF(const void *buf);
+extern GP_Loader GP_GIF; + #endif /* LOADERS_GP_GIF_H */ diff --git a/include/loaders/GP_JP2.h b/include/loaders/GP_JP2.h index 574cfbc5..ca2a029e 100644 --- a/include/loaders/GP_JP2.h +++ b/include/loaders/GP_JP2.h @@ -29,9 +29,7 @@ #ifndef LOADERS_GP_JP2_H #define LOADERS_GP_JP2_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * Reads a JPEG2000 from an IO stream. @@ -51,4 +49,6 @@ GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback); */ int GP_MatchJP2(const void *buf);
+extern GP_Loader GP_JP2; + #endif /* LOADERS_GP_JP2_H */ diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h index 93cd2df2..381c084c 100644 --- a/include/loaders/GP_JPG.h +++ b/include/loaders/GP_JPG.h @@ -29,10 +29,7 @@ #ifndef LOADERS_GP_JPG_H #define LOADERS_GP_JPG_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" -#include "loaders/GP_MetaData.h" +#include "loaders/GP_Loader.h"
/* * Reads a JPEG from an IO stream. @@ -64,4 +61,6 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path, */ int GP_MatchJPG(const void *buf);
+extern GP_Loader GP_JPG; + #endif /* LOADERS_GP_JPG_H */ diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h index 3b5bc8f0..3860ac10 100644 --- a/include/loaders/GP_Loader.h +++ b/include/loaders/GP_Loader.h @@ -129,8 +129,20 @@ const GP_Loader *GP_MatchSignature(const void *buf); */ const GP_Loader *GP_MatchExtension(const char *path);
-void GP_LoaderRegister(GP_Loader *self); +/* + * Registers additional loader. + * + * Returns zero on success, non-zero if table of loaders was is full. + */ +int GP_LoaderRegister(GP_Loader *self);
+/* + * Unregisters a loader. + * + * All library loaders are registered by default. + * + * You can unregister them using this function if you want. + */ void GP_LoaderUnregister(GP_Loader *self);
/* diff --git a/include/loaders/GP_PCX.h b/include/loaders/GP_PCX.h index f5ce05c1..bb57233a 100644 --- a/include/loaders/GP_PCX.h +++ b/include/loaders/GP_PCX.h @@ -29,9 +29,7 @@ #ifndef LOADERS_GP_PCX_H #define LOADERS_GP_PCX_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * Reads a PCX from an IO stream. @@ -51,4 +49,6 @@ GP_Context *GP_LoadPCX(const char *src_path, GP_ProgressCallback *callback); */ int GP_MatchPCX(const void *buf);
+extern GP_Loader GP_PCX; + #endif /* LOADERS_GP_PCX_H */ diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h index b99e7280..eb607010 100644 --- a/include/loaders/GP_PNG.h +++ b/include/loaders/GP_PNG.h @@ -29,10 +29,7 @@ #ifndef LOADERS_GP_PNG_H #define LOADERS_GP_PNG_H
-#include "core/GP_ProgressCallback.h" -#include "core/GP_Context.h" -#include "loaders/GP_IO.h" -#include "loaders/GP_MetaData.h" +#include "loaders/GP_Loader.h"
/* * Reads a PNG from an IO stream. @@ -65,4 +62,6 @@ int GP_SavePNG(const GP_Context *src, const char *dst_path, */ int GP_MatchPNG(const void *buf);
+extern GP_Loader GP_PNG; + #endif /* LOADERS_GP_PNG_H */ diff --git a/include/loaders/GP_PNM.h b/include/loaders/GP_PNM.h index 4f2dd11d..13d5f4b4 100644 --- a/include/loaders/GP_PNM.h +++ b/include/loaders/GP_PNM.h @@ -23,9 +23,7 @@ #ifndef LOADERS_GP_PNM_H #define LOADERS_GP_PNM_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * PBM Bitmap @@ -88,4 +86,9 @@ int GP_MatchPPM(const void *buf); */ int GP_MatchPNM(const void *buf);
+extern GP_Loader GP_PBM; +extern GP_Loader GP_PGM; +extern GP_Loader GP_PPM; +extern GP_Loader GP_PNM; + #endif /* LOADERS_GP_PNM_H */ diff --git a/include/loaders/GP_PSD.h b/include/loaders/GP_PSD.h index d8cd2213..7c4bcf6c 100644 --- a/include/loaders/GP_PSD.h +++ b/include/loaders/GP_PSD.h @@ -29,9 +29,7 @@ #ifndef LOADERS_GP_PSD_H #define LOADERS_GP_PSD_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * Reads a PSD from an IO stream. @@ -55,4 +53,6 @@ GP_Context *GP_LoadPSD(const char *src_path, GP_ProgressCallback *callback); */ int GP_MatchPSD(const void *buf);
+extern GP_Loader GP_PSD; + #endif /* LOADERS_GP_PSD_H */ diff --git a/include/loaders/GP_PSP.h b/include/loaders/GP_PSP.h index 1109bd9e..9cf6c058 100644 --- a/include/loaders/GP_PSP.h +++ b/include/loaders/GP_PSP.h @@ -31,9 +31,7 @@ #ifndef LOADERS_GP_PSP_H #define LOADERS_GP_PSP_H
-#include "core/GP_ProgressCallback.h" -#include "core/GP_Context.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * Reads a BMP from an IO stream. @@ -53,4 +51,6 @@ GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback); */ int GP_MatchPSP(const void *buf);
+extern GP_Loader GP_PSP; + #endif /* LOADERS_GP_PSP_H */ diff --git a/include/loaders/GP_TIFF.h b/include/loaders/GP_TIFF.h index 8c7c45fd..ef5e4f33 100644 --- a/include/loaders/GP_TIFF.h +++ b/include/loaders/GP_TIFF.h @@ -23,9 +23,7 @@ #ifndef LOADERS_GP_TIFF_H #define LOADERS_GP_TIFF_H
-#include "core/GP_Context.h" -#include "core/GP_ProgressCallback.h" -#include "loaders/GP_IO.h" +#include "loaders/GP_Loader.h"
/* * Reads first image in TIFF from an IO stream. @@ -51,4 +49,6 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path, */ int GP_MatchTIFF(const void *buf);
+extern GP_Loader GP_TIFF; + #endif /* LOADERS_GP_TIFF_H */ diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index 1d9e9c20..9fcff422 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -905,3 +905,13 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path,
return 0; } + +struct GP_Loader GP_BMP = { + .Read = GP_ReadBMP, + .Load = GP_LoadBMP, + .Save = GP_SaveBMP, + .Match = GP_MatchBMP, + + .fmt_name = "BMP", + .extensions = {"bmp", "dib", NULL}, +}; diff --git a/libs/loaders/GP_GIF.c b/libs/loaders/GP_GIF.c index 0c286b97..6425d60a 100644 --- a/libs/loaders/GP_GIF.c +++ b/libs/loaders/GP_GIF.c @@ -400,3 +400,12 @@ GP_Context *GP_LoadGIF(const char GP_UNUSED(*src_path), }
#endif /* HAVE_GIFLIB */ + +struct GP_Loader GP_GIF = { + .Read = GP_ReadGIF, + .Load = GP_LoadGIF, + .Save = NULL, + .Match = GP_MatchGIF, + .fmt_name = "Graphics Interchange Format", + .extensions = {"gif", NULL}, +}; diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c index ef412ca8..f451b6f1 100644 --- a/libs/loaders/GP_JP2.c +++ b/libs/loaders/GP_JP2.c @@ -261,3 +261,13 @@ GP_Context *GP_LoadJP2(const char GP_UNUSED(*src_path), }
#endif /* HAVE_OPENJPEG */ + +struct GP_Loader GP_JP2 = { + .Read = GP_ReadJP2, + .Load = GP_LoadJP2, + .Save = NULL, + .Match = GP_MatchJP2, + + .fmt_name = "JPEG 2000", + .extensions = {"jp2", "jpx", NULL}, +}; diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c index 6fd5dd28..ca14b180 100644 --- a/libs/loaders/GP_JPG.c +++ b/libs/loaders/GP_JPG.c @@ -593,3 +593,13 @@ int GP_SaveJPG(const GP_Context GP_UNUSED(*src), }
#endif /* HAVE_JPEG */ + +struct GP_Loader GP_JPG = { + .Read = GP_ReadJPG, + .Load = GP_LoadJPG, + .Save = GP_SaveJPG, + .Match = GP_MatchJPG, + + .fmt_name = "JPEG", + .extensions = {"jpg", "jpeg", NULL}, +}; diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c index d88bf5f6..c3b74feb 100644 --- a/libs/loaders/GP_Loader.c +++ b/libs/loaders/GP_Loader.c @@ -39,205 +39,116 @@ #include "loaders/GP_Loaders.h" #include "loaders/GP_Loader.h"
-static GP_Loader psd_loader = { - .Read = GP_ReadPSD, - .Load = GP_LoadPSD, - .Save = NULL, - .Match = GP_MatchPSD, - .fmt_name = "Adobe Photoshop Image", - .next = NULL, - .extensions = {"psd", NULL}, +#define MAX_LOADERS 64 + +static GP_Loader *loaders[MAX_LOADERS] = { + &GP_JPG, + &GP_PNG, + &GP_TIFF, + &GP_GIF, + &GP_BMP, + &GP_PBM, + &GP_PNM, + &GP_PPM, + &GP_PNM, + &GP_JP2, + &GP_PCX, + &GP_PSP, + &GP_PSD, };
-static GP_Loader psp_loader = { - .Read = GP_ReadPSP, - .Load = GP_LoadPSP, - .Save = NULL, - .Match = GP_MatchPSP, - .fmt_name = "Paint Shop Pro Image", - .next = &psd_loader, - .extensions = {"psp", "pspimage", NULL}, -}; - -static GP_Loader pcx_loader = { - .Read = GP_ReadPCX, - .Load = GP_LoadPCX, - .Save = NULL, - .Match = GP_MatchPCX, - .fmt_name = "ZSoft PCX", - .next = &psp_loader, - .extensions = {"pcx", NULL}, -}; - -static GP_Loader pbm_loader = { - .Read = GP_ReadPBM, - .Load = GP_LoadPBM, - .Save = GP_SavePBM, - .Match = GP_MatchPBM, - .fmt_name = "Netpbm portable Bitmap", - .next = &pcx_loader, - .extensions = {"pbm", NULL}, -}; - -static GP_Loader pgm_loader = { - .Read = GP_ReadPGM, - .Load = GP_LoadPGM, - .Save = GP_SavePGM, - .Match = GP_MatchPGM, - .fmt_name = "Netpbm portable Graymap", - .next = &pbm_loader, - .extensions = {"pgm", NULL}, -}; - -static GP_Loader ppm_loader = { - .Read = GP_ReadPPM, - .Load = GP_LoadPPM, - .Save = GP_SavePPM, - .Match = GP_MatchPPM, - .fmt_name = "Netpbm portable Pixmap", - .next = &pgm_loader, - .extensions = {"ppm", NULL}, -}; - -static GP_Loader pnm_loader = { - .Read = GP_ReadPNM, - .Load = GP_LoadPNM, - .Save = GP_SavePNM, - /* - * Avoid double Match - * This format is covered by PBM, PGM and PPM - */ - .Match = NULL, - .fmt_name = "Netpbm portable Anymap", - .next = &ppm_loader, - .extensions = {"pnm", NULL}, -}; +static unsigned int get_last_loader(void) +{ + unsigned int i;
-static GP_Loader jp2_loader = { - .Read = GP_ReadJP2, - .Load = GP_LoadJP2, - .Save = NULL, - .Match = GP_MatchJP2, - .fmt_name = "JPEG 2000", - .next = &pnm_loader, - .extensions = {"jp2", "jpx", NULL}, -}; + for (i = 0; i < MAX_LOADERS; i++) { + if (!loaders[i]) + return i ? i - 1 : 0; + }
-static GP_Loader bmp_loader = { - .Read = GP_ReadBMP, - .Load = GP_LoadBMP, - .Save = GP_SaveBMP, - .Match = GP_MatchBMP, - .fmt_name = "BMP", - .next = &jp2_loader, - .extensions = {"bmp", "dib", NULL}, -}; + return i - 1; +}
-static GP_Loader gif_loader = { - .Read = GP_ReadGIF, - .Load = GP_LoadGIF, - .Save = NULL, - .Match = GP_MatchGIF, - .fmt_name = "Graphics Interchange Format", - .next = &bmp_loader, - .extensions = {"gif", NULL}, -}; +int GP_LoaderRegister(GP_Loader *self) +{ + unsigned int i;
-static GP_Loader tiff_loader = { - .Read = GP_ReadTIFF, - .Load = GP_LoadTIFF, - .Save = GP_SaveTIFF, - .Match = GP_MatchTIFF, - .fmt_name = "Tag Image File Format", - .next = &gif_loader, - .extensions = {"tif", "tiff", NULL}, -}; + GP_DEBUG(1, "Registering loader for '%s'", self->fmt_name);
-static GP_Loader png_loader = { - .Read = GP_ReadPNG, - .Load = GP_LoadPNG, - .Save = GP_SavePNG, - .Match = GP_MatchPNG, - .fmt_name = "Portable Network Graphics", - .next = &tiff_loader, - .extensions = {"png", NULL}, -}; + /* We have to keep the last terminating NULL */ + for (i = 0; i < MAX_LOADERS - 2; i++) { + if (loaders[i] == self) { + GP_DEBUG(1, "Loader '%s' allready registered", + self->fmt_name); + errno = EEXIST; + return 1; + }
-static GP_Loader jpeg_loader = { - .Read = GP_ReadJPG, - .Load = GP_LoadJPG, - .Save = GP_SaveJPG, - .Match = GP_MatchJPG, - .fmt_name = "JPEG", - .next = &png_loader, - .extensions = {"jpg", "jpeg", NULL}, -}; + if (!loaders[i]) + break; + }
-static GP_Loader *loaders = &jpeg_loader; -static GP_Loader *loaders_last = &psp_loader; + if (loaders[i]) { + GP_DEBUG(1, "Loaders table is full"); + errno = ENOSPC; + return 1; + }
-void GP_LoaderRegister(GP_Loader *self) -{ - GP_DEBUG(1, "Registering loader for '%s'", self->fmt_name); + loaders[i] = self;
- self->next = NULL; - loaders_last->next = self; + return 0; }
void GP_LoaderUnregister(GP_Loader *self) { - struct GP_Loader *i; + unsigned int i, last = get_last_loader();
if (self == NULL) return;
GP_DEBUG(1, "Unregistering loader for '%s'", self->fmt_name);
- for (i = loaders; i != NULL; i = i->next) { - if (i->next == self) - break; - } - - if (i == NULL) { - GP_WARN("Loader '%s' (%p) wasn't registered", - self->fmt_name, self); - return; + for (i = 0; loaders[i]; i++) { + if (loaders[i] == self) { + loaders[i] = loaders[last]; + loaders[last] = NULL; + return; + } }
- i->next = self->next; + GP_WARN("Loader '%s' (%p) wasn't registered", self->fmt_name, self); }
void GP_ListLoaders(void) { - struct GP_Loader *i; - int j; - - for (i = loaders; i != NULL; i = i->next) { - printf("Format: %sn", i->fmt_name); - printf("Read:t%sn", i->Read ? "Yes" : "No"); - printf("Load:t%sn", i->Load ? "Yes" : "No"); - printf("Save:t%sn", i->Save ? "Yes" : "No"); - printf("Match:t%sn", i->Match ? "Yes" : "No"); + unsigned int i, j; + + for (i = 0; loaders[i]; i++) { + printf("Format: %sn", loaders[i]->fmt_name); + printf("Read:t%sn", loaders[i]->Read ? "Yes" : "No"); + printf("Load:t%sn", loaders[i]->Load ? "Yes" : "No"); + printf("Save:t%sn", loaders[i]->Save ? "Yes" : "No"); + printf("Match:t%sn", loaders[i]->Match ? "Yes" : "No"); printf("Extensions: "); - for (j = 0; i->extensions[j] != NULL; j++) - printf("%s ", i->extensions[j]); + for (j = 0; loaders[i]->extensions[j] != NULL; j++) + printf("%s ", loaders[i]->extensions[j]); printf("n");
- if (i->next != NULL) + if (loaders[i+1] != NULL) printf("n"); } }
static struct GP_Loader *loader_by_extension(const char *ext) { - struct GP_Loader *i; - int j; - - for (i = loaders; i != NULL; i = i->next) { - for (j = 0; i->extensions[j] != NULL; j++) { - if (!strcasecmp(ext, i->extensions[j])) { - GP_DEBUG(1, "Found loader '%s'", i->fmt_name); - return i; + unsigned int i, j; + + for (i = 0; loaders[i]; i++) { + for (j = 0; loaders[i]->extensions[j] != NULL; j++) { + if (!strcasecmp(ext, loaders[i]->extensions[j])) { + GP_DEBUG(1, "Found loader '%s'", + loaders[i]->fmt_name); + return loaders[i]; } } } @@ -460,12 +371,12 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path,
const GP_Loader *GP_MatchSignature(const void *buf) { - struct GP_Loader *i; + unsigned int i;
- for (i = loaders; i != NULL; i = i->next) { - if (i->Match && i->Match(buf) == 1) { - GP_DEBUG(1, "Found loader '%s'", i->fmt_name); - return i; + for (i = 0; loaders[i]; i++) { + if (loaders[i]->Match && loaders[i]->Match(buf) == 1) { + GP_DEBUG(1, "Found loader '%s'", loaders[i]->fmt_name); + return loaders[i]; } }
diff --git a/libs/loaders/GP_PCX.c b/libs/loaders/GP_PCX.c index 8d92c0f2..b04dc41b 100644 --- a/libs/loaders/GP_PCX.c +++ b/libs/loaders/GP_PCX.c @@ -565,3 +565,13 @@ GP_Context *GP_LoadPCX(const char *src_path, GP_ProgressCallback *callback)
return res; } + +struct GP_Loader GP_PCX = { + .Read = GP_ReadPCX, + .Load = GP_LoadPCX, + .Save = NULL, + .Match = GP_MatchPCX, + + .fmt_name = "ZSoft PCX", + .extensions = {"pcx", NULL}, +}; diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c index 50f5fcdf..2da8bcef 100644 --- a/libs/loaders/GP_PNG.c +++ b/libs/loaders/GP_PNG.c @@ -653,3 +653,13 @@ int GP_SavePNG(const GP_Context GP_UNUSED(*src), }
#endif /* HAVE_LIBPNG */ + +GP_Loader GP_PNG = { + .Read = GP_ReadPNG, + .Load = GP_LoadPNG, + .Save = GP_SavePNG, + .Match = GP_MatchPNG, + + .fmt_name = "Portable Network Graphics", + .extensions = {"png", NULL}, +}; diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c index 1a17e530..63bb5361 100644 --- a/libs/loaders/GP_PNM.c +++ b/libs/loaders/GP_PNM.c @@ -1226,3 +1226,47 @@ int GP_SavePNM(const GP_Context *src, const char *dst_path, return 1; } } + +struct GP_Loader GP_PBM = { + .Read = GP_ReadPBM, + .Load = GP_LoadPBM, + .Save = GP_SavePBM, + .Match = GP_MatchPBM, + + .fmt_name = "Netpbm portable Bitmap", + .extensions = {"pbm", NULL}, +}; + +struct GP_Loader GP_PGM = { + .Read = GP_ReadPGM, + .Load = GP_LoadPGM, + .Save = GP_SavePGM, + .Match = GP_MatchPGM, + + .fmt_name = "Netpbm portable Graymap", + .extensions = {"pgm", NULL}, +}; + +struct GP_Loader GP_PPM = { + .Read = GP_ReadPPM, + .Load = GP_LoadPPM, + .Save = GP_SavePPM, + .Match = GP_MatchPPM, + + .fmt_name = "Netpbm portable Pixmap", + .extensions = {"ppm", NULL}, +}; + +struct GP_Loader GP_PNM = { + .Read = GP_ReadPNM, + .Load = GP_LoadPNM, + .Save = GP_SavePNM, + /* + * Avoid double Match + * This format is covered by PBM, PGM and PPM + */ + .Match = NULL, + + .fmt_name = "Netpbm portable Anymap", + .extensions = {"pnm", NULL}, +}; diff --git a/libs/loaders/GP_PSD.c b/libs/loaders/GP_PSD.c index a3e5030d..5ef73f11 100644 --- a/libs/loaders/GP_PSD.c +++ b/libs/loaders/GP_PSD.c @@ -829,3 +829,13 @@ GP_Context *GP_LoadPSD(const char *src_path, GP_ProgressCallback *callback)
return res; } + +struct GP_Loader GP_PSD = { + .Read = GP_ReadPSD, + .Load = GP_LoadPSD, + .Save = NULL, + .Match = GP_MatchPSD, + + .fmt_name = "Adobe Photoshop Image", + .extensions = {"psd", NULL}, +}; diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c index d99ca03d..bacd4b9b 100644 --- a/libs/loaders/GP_PSP.c +++ b/libs/loaders/GP_PSP.c @@ -507,3 +507,12 @@ GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback)
return res; } + +struct GP_Loader GP_PSP = { + .Read = GP_ReadPSP, + .Load = GP_LoadPSP, + .Save = NULL, + .Match = GP_MatchPSP, + .fmt_name = "Paint Shop Pro Image", + .extensions = {"psp", "pspimage", NULL}, +}; diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c index 65513c77..1ea06554 100644 --- a/libs/loaders/GP_TIFF.c +++ b/libs/loaders/GP_TIFF.c @@ -762,3 +762,13 @@ int GP_SaveTIFF(const GP_Context GP_UNUSED(*src), }
#endif /* HAVE_TIFF */ + +struct GP_Loader GP_TIFF = { + .Read = GP_ReadTIFF, + .Load = GP_LoadTIFF, + .Save = GP_SaveTIFF, + .Match = GP_MatchTIFF, + + .fmt_name = "Tag Image File Format", + .extensions = {"tif", "tiff", NULL}, +}; diff --git a/tests/loaders/Loader.c b/tests/loaders/Loader.c new file mode 100644 index 00000000..4494825e --- /dev/null +++ b/tests/loaders/Loader.c @@ -0,0 +1,164 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <errno.h> +#include <core/GP_Common.h> +#include <loaders/GP_Loaders.h> + +#include "tst_test.h" + +static GP_Loader dummy_loaders[1000]; + +static int register_max_loaders(void) +{ + unsigned int cnt = 0, i; + + for (;;) { + if (GP_LoaderRegister(&dummy_loaders[cnt])) { + if (errno != ENOSPC) { + tst_msg("Wrong errno %s (%i), expected ENOSPC", + tst_strerr(errno), errno); + return TST_FAILED; + } + break; + } + cnt++; + + if (cnt >= GP_ARRAY_SIZE(dummy_loaders)) { + tst_msg("Failed to reach the max after %u", cnt); + return TST_FAILED; + } + } + + tst_msg("Registered %u loaders", cnt); + + /* Let's provoke SEGFAULT by walking the loaders list */ + GP_ListLoaders(); + + for (i = 0; i < cnt; i++) + GP_LoaderUnregister(&dummy_loaders[i]); + + for (i = 0; i < cnt; i++) { + if (GP_LoaderRegister(&dummy_loaders[i])) { + tst_msg("Failed to register %u loader (max=%u)", + i, cnt); + return TST_FAILED; + } + } + + for (i = 0; i < cnt; i++) + GP_LoaderUnregister(&dummy_loaders[cnt - i - 1]); + + return TST_SUCCESS; +} + +static int register_loader_twice(void) +{ + int ret; + + if (GP_LoaderRegister(dummy_loaders)) { + tst_msg("Failed to register loader %s (%i)", + tst_strerr(errno), errno); + return TST_FAILED; + } + + if (GP_LoaderRegister(dummy_loaders)) { + if (errno != EEXIST) { + tst_msg("Loader failed but errno %s (%i)", + tst_strerr(errno), errno); + ret = TST_FAILED; + goto exit; + } + + tst_msg("Second attempt to register loader fails with EEXIST"); + ret = TST_SUCCESS; + goto exit; + } + + tst_msg("Second attempt to register loader succeded"); + ret = TST_FAILED; +exit: + GP_LoaderUnregister(dummy_loaders); + return ret; +} + +static GP_Loader test_loader = { + .fmt_name = "TEST", + .extensions = {"test", NULL}, +}; + +static int loader_by_extension(void) +{ + const GP_Loader *loader; + int err = 0; + + if (GP_LoaderRegister(&test_loader)) { + tst_msg("Failed to register loader %s (%i)", + tst_strerr(errno), errno); + return TST_FAILED; + } + + loader = GP_MatchExtension("file.jpg"); + + if (loader != &GP_JPG) { + tst_msg("Failed to get JPEG loader"); + err++; + } else { + tst_msg("Succeded to get JPEG loader"); + } + + loader = GP_MatchExtension("file.test"); + + if (loader != &test_loader) { + tst_msg("Failed to get registered TEST loader"); + err++; + } else { + tst_msg("Succeded to get TEST loader"); + } + + GP_LoaderUnregister(&test_loader); + + if (err) + return TST_FAILED; + + return TST_SUCCESS; +} + +const struct tst_suite tst_suite = { + .suite_name = "Loader", + .tests = { + /* Loader Register tests */ + {.name = "LoaderRegister() max", + .tst_fn = register_max_loaders, + .flags = TST_CHECK_MALLOC}, + + {.name = "LoaderRegister() twice", + .tst_fn = register_loader_twice, + .flags = TST_CHECK_MALLOC}, + + {.name = "MatchExtension()", + .tst_fn = loader_by_extension, + .flags = TST_CHECK_MALLOC}, + + {.name = NULL}, + } +}; diff --git a/tests/loaders/Makefile b/tests/loaders/Makefile index fb56086d..c483d412 100644 --- a/tests/loaders/Makefile +++ b/tests/loaders/Makefile @@ -2,11 +2,11 @@ TOPDIR=../.. include $(TOPDIR)/pre.mk
CSOURCES=loaders_suite.c PNG.c PBM.c PGM.c PPM.c ZIP.c GIF.c IO.c PNM.c PCX.c- JPG.c + JPG.c Loader.c GENSOURCES=SaveLoad.gen.c SaveAbort.gen.c
APPS=loaders_suite PNG PBM PGM PPM PNM SaveLoad.gen SaveAbort.gen ZIP GIF PCX- IO JPG + IO JPG Loader
include ../tests.mk
diff --git a/tests/loaders/test_list.txt b/tests/loaders/test_list.txt index adf857ea..dacb0f56 100644 --- a/tests/loaders/test_list.txt +++ b/tests/loaders/test_list.txt @@ -10,5 +10,6 @@ PNM PCX ZIP IO +Loader SaveLoad.gen SaveAbort.gen
http://repo.or.cz/w/gfxprim.git/commit/4bec01e5af42cb68e680f3a6d452d543b8c4d...
commit 4bec01e5af42cb68e680f3a6d452d543b8c4d004 Author: Cyril Hrubis metan@ucw.cz Date: Fri Jun 13 10:51:41 2014 +0200
tests: filters: Fix Makefile.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/filters/Makefile b/tests/filters/Makefile index 8834428e..75889b5b 100644 --- a/tests/filters/Makefile +++ b/tests/filters/Makefile @@ -1,7 +1,7 @@ TOPDIR=../.. include $(TOPDIR)/pre.mk
-CSOURCES=FilterMirrorH.c +CSOURCES=FilterMirrorH.c common.c
GENSOURCES=APICoverage.gen.c FiltersCompare.gen.c
@@ -11,8 +11,6 @@ include ../tests.mk
FilterMirrorH: common.o
-CLEAN+=common.o - include $(TOPDIR)/gen.mk include $(TOPDIR)/app.mk include $(TOPDIR)/post.mk
http://repo.or.cz/w/gfxprim.git/commit/e341668ccad607f9843386e206105f086ae30...
commit e341668ccad607f9843386e206105f086ae307d0 Author: Cyril Hrubis metan@ucw.cz Date: Fri Jun 13 10:43:37 2014 +0200
tests: framework add tst_strerr()
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/framework/tst_msg.c b/tests/framework/tst_msg.c index b4f150fb..e3fd07f5 100644 --- a/tests/framework/tst_msg.c +++ b/tests/framework/tst_msg.c @@ -92,3 +92,58 @@ void tst_msg_print(const struct tst_msg_store *self) for (msg = self->first; msg != NULL; msg = msg->next) fprintf(stderr, "%c: %sn", type_to_char(msg->type), msg->msg); } + +#define ERR(err) + case err: + return #err + +const char *tst_strerr(int err) +{ + switch (err) { + case 0: + return "SUCCESS"; + /* asm-generic/errno-base.h */ + ERR(EPERM); + ERR(ENOENT); + ERR(ESRCH); + ERR(EINTR); + ERR(EIO); + ERR(ENXIO); + ERR(E2BIG); + ERR(ENOEXEC); + ERR(EBADF); + ERR(ECHILD); + ERR(EAGAIN); + ERR(ENOMEM); + ERR(EACCES); + ERR(EFAULT); + ERR(ENOTBLK); + ERR(EBUSY); + ERR(EEXIST); + ERR(EXDEV); + ERR(ENODEV); + ERR(ENOTDIR); + ERR(EISDIR); + ERR(EINVAL); + ERR(ENFILE); + ERR(EMFILE); + ERR(ENOTTY); + ERR(ETXTBSY); + ERR(EFBIG); + ERR(ENOSPC); + ERR(ESPIPE); + ERR(EROFS); + ERR(EMLINK); + ERR(EPIPE); + ERR(EDOM); + ERR(ERANGE); + + /* a few from asm-generic/errno.h */ + ERR(EDEADLK); + ERR(ENAMETOOLONG); + ERR(ENOSYS); + ERR(ECANCELED); + default: + return "???"; + } +} diff --git a/tests/framework/tst_test.h b/tests/framework/tst_test.h index 4d65b1b6..182d96f5 100644 --- a/tests/framework/tst_test.h +++ b/tests/framework/tst_test.h @@ -130,4 +130,9 @@ int tst_warn(const char *fmt, ...) int tst_err(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
+/* + * Translates errno number into short string, i.e. EFOO + */ +const char *tst_strerr(int err); + #endif /* TST_TEST_H */
-----------------------------------------------------------------------
Summary of changes: build/syms/Loaders_symbols.txt | 13 ++ include/loaders/GP_BMP.h | 7 +- include/loaders/GP_GIF.h | 6 +- include/loaders/GP_JP2.h | 6 +- include/loaders/GP_JPG.h | 7 +- include/loaders/GP_Loader.h | 33 +++-- include/loaders/GP_PCX.h | 6 +- include/loaders/GP_PNG.h | 7 +- include/loaders/GP_PNM.h | 9 +- include/loaders/GP_PSD.h | 6 +- include/loaders/GP_PSP.h | 6 +- include/loaders/GP_TIFF.h | 6 +- libs/loaders/GP_BMP.c | 25 ++-- libs/loaders/GP_GIF.c | 37 ++---- libs/loaders/GP_JP2.c | 37 ++---- libs/loaders/GP_JPG.c | 42 +++---- libs/loaders/GP_Loader.c | 279 +++++++++++++++------------------------ libs/loaders/GP_PCX.c | 22 +-- libs/loaders/GP_PNG.c | 42 +++---- libs/loaders/GP_PNM.c | 136 +++++++++----------- libs/loaders/GP_PSD.c | 22 +-- libs/loaders/GP_PSP.c | 23 +-- libs/loaders/GP_TIFF.c | 42 +++---- tests/filters/Makefile | 4 +- tests/framework/tst_msg.c | 55 ++++++++ tests/framework/tst_test.h | 5 + tests/loaders/Loader.c | 164 +++++++++++++++++++++++ tests/loaders/Makefile | 4 +- tests/loaders/test_list.txt | 1 + 29 files changed, 572 insertions(+), 480 deletions(-) create mode 100644 tests/loaders/Loader.c
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.