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 80d1a231acdf63c758e84a257c20aaffca6550e3 (commit) via 21bb72c7f2b7a1dc55c551a9cafe65fab22fb899 (commit) via 697c44509ec28ec94d453c84be6d9292affd83f4 (commit) via 5afca4870b21f2204799a5a113637968cb98090e (commit) via a5f1f49a610ffd5f59cc3404d14efd03edd8be32 (commit) from 6793b01905a9072059080e70fa79c685e43a945c (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/80d1a231acdf63c758e84a257c20aaffca655...
commit 80d1a231acdf63c758e84a257c20aaffca6550e3 Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 10 14:01:00 2012 +0100
examples: Add loader registration example.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile index 8cc06a0..03c91c5 100644 --- a/demos/c_simple/Makefile +++ b/demos/c_simple/Makefile @@ -9,7 +9,7 @@ LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends` APPS=backend_example loaders_example loaders filters_symmetry gfx_koch virtual_backend_example meta_data meta_data_dump tmp_file showimage v4l2_show v4l2_grab convolution weighted_median shapetest koch input- fileview linetest randomshapetest fonttest + fileview linetest randomshapetest fonttest loaders_register
v4l2_show: LDLIBS+=-lGP_grabbers v4l2_grab: LDLIBS+=-lGP_grabbers diff --git a/demos/c_simple/loaders_register.c b/demos/c_simple/loaders_register.c new file mode 100644 index 0000000..2140af5 --- /dev/null +++ b/demos/c_simple/loaders_register.c @@ -0,0 +1,139 @@ +/***************************************************************************** + * 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-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + + /* + + Shows how to register custom image loader/saver. + + Feed it with small image (cca 60x60 pixels) to produce ascii art version. + + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <GP.h> + +/* + * Saves 2 bpp grayscale image as ASCII Art + */ +static int save(const GP_Context *img, const char *dst_path, + GP_ProgressCallback *callback) +{ + if (img->pixel_type != GP_PIXEL_G2) { + errno = ENOSYS; + return 1; + } + + FILE *f = fopen(dst_path, "w"); + + if (f == NULL) + return 1; + + unsigned int i, j; + + for (j = 0; j < img->h; j++) { + for (i = 0; i < img->w; i++) { + GP_Pixel p = GP_GetPixel_Raw(img, i, j); + + switch (p) { + case 0: + fprintf(f, " "); + break; + case 1: + fprintf(f, ".."); + break; + case 2: + fprintf(f, "()"); + break; + case 3: + fprintf(f, "OO"); + break; + } + } + + fprintf(f, "n"); + + if (GP_ProgressCallbackReport(callback, img->h, j, img->w)) { + fclose(f); + unlink(dst_path); + errno = ECANCELED; + return 1; + } + } + + if (fclose(f)) + return 1; + + GP_ProgressCallbackDone(callback); + + return 0; +} + +GP_Loader loader = { + .Load = NULL, + .Save = save, + .Match = NULL, + .fmt_name = "ASCII Art", + .extensions = {"txt", NULL}, +}; + +int main(int argc, char *argv[]) +{ + GP_Context *c, *gc; + + GP_LoaderRegister(&loader); + + /* List all loaders */ + GP_ListLoaders(); + printf("nn"); + + if (argc != 2) { + fprintf(stderr, "ERROR: Takes image as an argumentn"); + return 1; + } + + /* Now load image and save it using our loader */ + c = GP_LoadImage(argv[1], NULL); + + if (c == NULL) { + fprintf(stderr, "Failed to load image: %sn", strerror(errno)); + return 1; + } + + gc = GP_FilterFloydSteinberg_RGB888_Alloc(c, GP_PIXEL_G2, NULL); + + if (gc == NULL) { + fprintf(stderr, "FloydSteinberg: %sn", strerror(errno)); + return 1; + } + + printf("Saving to test.txtn"); + + if (GP_SaveImage(gc, "test.txt", NULL)) { + fprintf(stderr, "Failed to save image: %sn", strerror(errno)); + return 1; + } + + return 0; +}
http://repo.or.cz/w/gfxprim.git/commit/21bb72c7f2b7a1dc55c551a9cafe65fab22fb...
commit 21bb72c7f2b7a1dc55c551a9cafe65fab22fb899 Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 10 13:58:12 2012 +0100
loaders: Add the rest of loaders to GP_Loader list
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h index a5ef06b..ef7add1 100644 --- a/include/loaders/GP_Loader.h +++ b/include/loaders/GP_Loader.h @@ -106,4 +106,9 @@ void GP_LoaderRegister(GP_Loader *self);
void GP_LoaderUnregister(GP_Loader *self);
+/* + * List loaders into the stdout + */ +void GP_ListLoaders(void); + #endif /* LOADERS_GP_LOADER_H */ diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c index 597cfe9..0ef1024 100644 --- a/libs/loaders/GP_Loader.c +++ b/libs/loaders/GP_Loader.c @@ -45,12 +45,39 @@ static GP_Loader psp_loader = { .extensions = {"psp", "pspimage", NULL}, };
+static GP_Loader pbm_loader = { + .Load = GP_LoadPBM, + .Save = GP_SavePBM, + .Match = NULL, + .fmt_name = "Netpbm portable bitmap", + .next = &psp_loader, + .extensions = {"pbm", NULL}, +}; + +static GP_Loader pgm_loader = { + .Load = GP_LoadPGM, + .Save = GP_SavePGM, + .Match = NULL, + .fmt_name = "Netpbm portable graymap", + .next = &pbm_loader, + .extensions = {"pgm", NULL}, +}; + +static GP_Loader ppm_loader = { + .Load = GP_LoadPPM, + .Save = NULL, + .Match = NULL, + .fmt_name = "Netpbm portable pixmap", + .next = &pgm_loader, + .extensions = {"ppm", NULL}, +}; + static GP_Loader bmp_loader = { .Load = GP_LoadBMP, .Save = NULL, .Match = GP_MatchBMP, .fmt_name = "BMP", - .next = &psp_loader, + .next = &ppm_loader, .extensions = {"bmp", "dib", NULL}, };
@@ -115,6 +142,26 @@ void GP_LoaderUnregister(GP_Loader *self) i->next = self->next; }
+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("Load:t%sn", i->Load ? "Yes" : "No"); + printf("Save:t%sn", i->Save ? "Yes" : "No"); + printf("Match:t%sn", i->Match ? "Yes" : "No"); + printf("Extensions: "); + for (j = 0; i->extensions[j] != NULL; j++) + printf("%s ", i->extensions[j]); + printf("n"); + + if (i->next != NULL) + printf("n"); + } +} + static struct GP_Loader *loader_by_extension(const char *ext) { struct GP_Loader *i;
http://repo.or.cz/w/gfxprim.git/commit/697c44509ec28ec94d453c84be6d9292affd8...
commit 697c44509ec28ec94d453c84be6d9292affd83f4 Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 10 12:55:56 2012 +0100
doc: Fix Makefile, update .gitignore
diff --git a/doc/.gitignore b/doc/.gitignore index 2d19fc7..4b4703c 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -1 +1,11 @@ *.html +*.md5 + +discrete_linear_1D_convolution_alg1.png +discrete_linear_1D_convolution_alg2.png +discrete_linear_convolution.png +discrete_linear_convolution_alg1.png +discrete_linear_convolution_alg2.png +laplacian_edge_sharpening.png +laplacian_kernel.png + diff --git a/doc/Makefile b/doc/Makefile index 2b6df43..bda6964 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -2,6 +2,13 @@ SOURCES=general.txt context.txt loaders.txt filters.txt basic_types.txt drawing_api.txt backends.txt gamma.txt grabbers.txt environment_variables.txt debug.txt
+# +# Names of generated images for cleanup +# +GENIMAGES=discrete_linear_1D_convolution_alg1 discrete_linear_1D_convolution_alg2 + discrete_linear_convolution discrete_linear_convolution_alg1 + discrete_linear_convolution_alg2 laplacian_edge_sharpening laplacian_kernel + PAGES=$(subst .txt,.html,$(SOURCES))
@@ -30,6 +37,18 @@ api.pdf: api.txt xsltproc /usr/share/sgml/docbook/xsl-stylesheets/fo/docbook.xsl api.xml > api.fo fop api.fo -pdf api.pdf
+# +# Clean up generated images +# +CLEAN+=$(patsubst %,%.md5,$(GENIMAGES)) +CLEAN+=$(patsubst %,%.png,$(GENIMAGES)) + +# +# Clean up generated pages +# +CLEAN+=$(PAGES) + clean: - rm -f api.html examples.html + rm -f $(CLEAN) + rm -f api_links.html api.html examples.html rm -f api.xml api.fo api.pdf
http://repo.or.cz/w/gfxprim.git/commit/5afca4870b21f2204799a5a113637968cb980...
commit 5afca4870b21f2204799a5a113637968cb98090e Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 10 12:42:31 2012 +0100
loaders: Fix PBM and PGM loading API.
diff --git a/include/loaders/GP_PBM.h b/include/loaders/GP_PBM.h index 82cd45b..1603aff 100644 --- a/include/loaders/GP_PBM.h +++ b/include/loaders/GP_PBM.h @@ -43,7 +43,7 @@ GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback); * EINVAL - context pixel type was not 1 bit grayscale. * */ -int GP_SavePBM(const char *res_path, GP_Context *src, +int GP_SavePBM(const GP_Context *src, const char *res_path, GP_ProgressCallback *callback);
#endif /* LOADERS_GP_PBM_H */ diff --git a/include/loaders/GP_PGM.h b/include/loaders/GP_PGM.h index f949cde..7b930cd 100644 --- a/include/loaders/GP_PGM.h +++ b/include/loaders/GP_PGM.h @@ -31,7 +31,7 @@ GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback);
-int GP_SavePGM(const char *res_path, GP_Context *src, +int GP_SavePGM(const GP_Context *src, const char *res_path, GP_ProgressCallback *callback);
#endif /* LOADERS_GP_PGM_H */ diff --git a/libs/loaders/GP_PBM.c b/libs/loaders/GP_PBM.c index 2c11138..e481684 100644 --- a/libs/loaders/GP_PBM.c +++ b/libs/loaders/GP_PBM.c @@ -93,7 +93,7 @@ err1: return NULL; }
-int GP_SavePBM(const char *res_path, GP_Context *src, +int GP_SavePBM(const GP_Context *src, const char *res_path, GP_ProgressCallback *callback) { FILE *f; diff --git a/libs/loaders/GP_PGM.c b/libs/loaders/GP_PGM.c index 055df97..4a2321d 100644 --- a/libs/loaders/GP_PGM.c +++ b/libs/loaders/GP_PGM.c @@ -186,7 +186,7 @@ err0: return NULL; }
-int GP_SavePGM(const char *res_path, GP_Context *src, +int GP_SavePGM(const GP_Context *src, const char *res_path, GP_ProgressCallback *callback) { FILE *f; diff --git a/libs/loaders/GP_PXMCommon.c b/libs/loaders/GP_PXMCommon.c index 48bc361..e2738ab 100644 --- a/libs/loaders/GP_PXMCommon.c +++ b/libs/loaders/GP_PXMCommon.c @@ -238,7 +238,7 @@ int GP_PXMLoad8bpp(FILE *f, GP_Context *context)
#define BITMASK(byte, bit) (!!((byte)&(0x80>>(bit))))
-static int write_line_1bpp(FILE *f, const uint8_t *data, GP_Context *src) +static int write_line_1bpp(FILE *f, const uint8_t *data, const GP_Context *src) { uint32_t x, max = src->bytes_per_row; int ret; @@ -278,7 +278,7 @@ static int write_line_1bpp(FILE *f, const uint8_t *data, GP_Context *src) return 0; }
-int GP_PXMSave1bpp(FILE *f, GP_Context *context) +int GP_PXMSave1bpp(FILE *f, const GP_Context *context) { uint32_t y; int ret; @@ -296,7 +296,7 @@ int GP_PXMSave1bpp(FILE *f, GP_Context *context)
#define MASK_2BPP(byte, pix) (0x03 & (byte>>((3 - pix)<<1)))
-static int write_line_2bpp(FILE *f, const uint8_t *data, GP_Context *src) +static int write_line_2bpp(FILE *f, const uint8_t *data, const GP_Context *src) { uint32_t x, max = src->bytes_per_row; int ret; @@ -332,7 +332,7 @@ static int write_line_2bpp(FILE *f, const uint8_t *data, GP_Context *src) return EIO; }
-int GP_PXMSave2bpp(FILE *f, GP_Context *context) +int GP_PXMSave2bpp(FILE *f, const GP_Context *context) { uint32_t y; int ret; @@ -348,7 +348,7 @@ int GP_PXMSave2bpp(FILE *f, GP_Context *context) return EIO; }
-static int write_line_8bpp(FILE *f, const uint8_t *data, GP_Context *src) +static int write_line_8bpp(FILE *f, const uint8_t *data, const GP_Context *src) { uint32_t x; int ret; @@ -371,7 +371,7 @@ static int write_line_8bpp(FILE *f, const uint8_t *data, GP_Context *src) return 0; }
-int GP_PXMSave8bpp(FILE *f, GP_Context *context) +int GP_PXMSave8bpp(FILE *f, const GP_Context *context) { uint32_t y; int ret; diff --git a/libs/loaders/GP_PXMCommon.h b/libs/loaders/GP_PXMCommon.h index 7ed531e..1780eec 100644 --- a/libs/loaders/GP_PXMCommon.h +++ b/libs/loaders/GP_PXMCommon.h @@ -40,10 +40,10 @@ * * The pixel type is not checked here as these are internal funcitons. */ -int GP_PXMSave1bpp(FILE *f, GP_Context *context); -int GP_PXMSave2bpp(FILE *f, GP_Context *context); -int GP_PXMSave4bpp(FILE *f, GP_Context *context); -int GP_PXMSave8bpp(FILE *f, GP_Context *context); +int GP_PXMSave1bpp(FILE *f, const GP_Context *context); +int GP_PXMSave2bpp(FILE *f, const GP_Context *context); +int GP_PXMSave4bpp(FILE *f, const GP_Context *context); +int GP_PXMSave8bpp(FILE *f, const GP_Context *context);
/* * Load context from ascii file.
http://repo.or.cz/w/gfxprim.git/commit/a5f1f49a610ffd5f59cc3404d14efd03edd8b...
commit a5f1f49a610ffd5f59cc3404d14efd03edd8be32 Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 10 00:37:31 2012 +0100
loaders: More work on loaders, BMP signature.
diff --git a/include/loaders/GP_BMP.h b/include/loaders/GP_BMP.h index e44d787..63473ea 100644 --- a/include/loaders/GP_BMP.h +++ b/include/loaders/GP_BMP.h @@ -62,4 +62,9 @@ GP_Context *GP_ReadBMP(FILE *f, GP_ProgressCallback *callback); */ GP_Context *GP_LoadBMP(const char *src_path, GP_ProgressCallback *callback);
+/* + * Match BMP signature. + */ +int GP_MatchBMP(const void *buf); + #endif /* LOADERS_GP_BMP_H */ diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index 0b1f7f5..3ed5161 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -514,6 +514,11 @@ static int read_bitmap_pixels(FILE *f, struct bitmap_info_header *header, return ENOSYS; }
+int GP_MatchBMP(const void *buf) +{ + return !memcmp(buf, "BM", 2); +} + int GP_OpenBMP(const char *src_path, FILE **f, GP_Size *w, GP_Size *h, GP_PixelType *pixel_type) { diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c index 226d388..597cfe9 100644 --- a/libs/loaders/GP_Loader.c +++ b/libs/loaders/GP_Loader.c @@ -48,7 +48,7 @@ static GP_Loader psp_loader = { static GP_Loader bmp_loader = { .Load = GP_LoadBMP, .Save = NULL, - .Match = NULL, + .Match = GP_MatchBMP, .fmt_name = "BMP", .next = &psp_loader, .extensions = {"bmp", "dib", NULL}, @@ -142,6 +142,9 @@ static struct GP_Loader *loader_by_filename(const char *path) if (path[i] == '.') break;
+ if (path[i] != '.') + return NULL; + ext = path + i + 1;
GP_DEBUG(1, "Loading file by filename extension '%s'", ext); @@ -342,7 +345,6 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback) if (l != NULL) return l->Load(src_path, callback);
- //TODO file signature based check errno = ENOSYS; return NULL; } @@ -382,17 +384,15 @@ int GP_LoadMetaData(const char *src_path, GP_MetaData *data) int GP_SaveImage(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { - enum GP_ImageFmt fmt = filename_to_fmt(dst_path); - - switch (fmt) { - case GP_FMT_JPG: - return GP_SaveJPG(src, dst_path, callback); - case GP_FMT_PNG: - return GP_SavePNG(src, dst_path, callback); + struct GP_Loader *l = loader_by_filename(dst_path);
- default: - break; + if (l == NULL) { + errno = EINVAL; + return 1; } + + if (l->Save) + return l->Save(src, dst_path, callback);
errno = ENOSYS; return 1;
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/Makefile | 2 +- demos/c_simple/{tmp_file.c => loaders_register.c} | 129 +++++++++++++-------- doc/.gitignore | 10 ++ doc/Makefile | 21 +++- include/loaders/GP_BMP.h | 5 + include/loaders/GP_Loader.h | 5 + include/loaders/GP_PBM.h | 2 +- include/loaders/GP_PGM.h | 2 +- libs/loaders/GP_BMP.c | 5 + libs/loaders/GP_Loader.c | 71 ++++++++++-- libs/loaders/GP_PBM.c | 2 +- libs/loaders/GP_PGM.c | 2 +- libs/loaders/GP_PXMCommon.c | 12 +- libs/loaders/GP_PXMCommon.h | 8 +- 14 files changed, 198 insertions(+), 78 deletions(-) copy demos/c_simple/{tmp_file.c => loaders_register.c} (53%)
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.