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 e0c2b6aa02d3f2341c971399623c5b69cb409c88 (commit) via 40ae90ef29c62be007c9fc936fc470cc5db4f20d (commit) via d59d05961f56e9ef30a5cc60083dcbb32017a2ae (commit) via 147509697f74c62af9d861653379d474783b5f3d (commit) from 130a8dec38dc497519345e822c1ff20a31844868 (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/e0c2b6aa02d3f2341c971399623c5b69cb409...
commit e0c2b6aa02d3f2341c971399623c5b69cb409c88 Author: Cyril Hrubis metan@ucw.cz Date: Wed Aug 14 22:32:42 2013 +0200
core: Pixel: Fix the double const warning.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index 8c060f0..bfe7d7f 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -122,7 +122,7 @@ typedef struct GP_PixelTypeDescription { /* * Array of size GP_PIXEL_MAX describing known pixel types */ -extern const GP_PixelTypeDescription const GP_PixelTypes[GP_PIXEL_MAX]; +extern const GP_PixelTypeDescription GP_PixelTypes[GP_PIXEL_MAX];
#define GP_VALID_PIXELTYPE(type) (((type) > 0) && ((type) < GP_PIXEL_MAX))
diff --git a/libs/core/GP_Pixel.gen.c.t b/libs/core/GP_Pixel.gen.c.t index 96ba421..302655f 100644 --- a/libs/core/GP_Pixel.gen.c.t +++ b/libs/core/GP_Pixel.gen.c.t @@ -43,7 +43,7 @@ Pixel type definitions and functions /* * Description of all known pixel types */ -const GP_PixelTypeDescription const GP_PixelTypes [GP_PIXEL_MAX] = { +const GP_PixelTypeDescription GP_PixelTypes [GP_PIXEL_MAX] = { %% for pt in pixeltypes /* GP_PIXEL_{{ pt.name }} */ { .type = GP_PIXEL_{{ pt.name }},
http://repo.or.cz/w/gfxprim.git/commit/40ae90ef29c62be007c9fc936fc470cc5db4f...
commit 40ae90ef29c62be007c9fc936fc470cc5db4f20d Author: Cyril Hrubis metan@ucw.cz Date: Wed Aug 14 22:23:40 2013 +0200
loaders: TmpFile: Fix potentionaly unitialized err
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_TmpFile.c b/libs/loaders/GP_TmpFile.c index 3704946..0dbb5ad 100644 --- a/libs/loaders/GP_TmpFile.c +++ b/libs/loaders/GP_TmpFile.c @@ -166,8 +166,10 @@ int GP_SaveTmpFile(const GP_Context *src, const char *dst_path, GP_ProgressCallbackReport(callback, y, src->h, src->w); }
- if (fclose(f)) + if (fclose(f)) { + err = errno; goto err0; + }
GP_ProgressCallbackDone(callback);
http://repo.or.cz/w/gfxprim.git/commit/d59d05961f56e9ef30a5cc60083dcbb32017a...
commit d59d05961f56e9ef30a5cc60083dcbb32017a2ae Author: Cyril Hrubis metan@ucw.cz Date: Wed Aug 14 21:09:38 2013 +0200
loaders: Experimental JPEG 2000 support.
Add experimental JPEG 2000 support using openjpeg library.
You need at least openjpeg 2.0.0, previous APIs are not usable and even 2.0.0 doesn't seem to be finished...
But here it is, enjoy!
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/configure b/configure index 2d41ff4..c7b7409 100755 --- a/configure +++ b/configure @@ -315,6 +315,9 @@ if __name__ == '__main__': ["jpeg", "Library to load, handle and manipulate images in the JPEG format", [header_exists, "jpeglib.h"], "", "-ljpeg", ["loaders"]], + ["openjpeg", + "An open-source JPEG 2000 library", + [header_exists, "openjpeg-2.0/openjpeg.h"], "", "-lopenjp2", ["loaders"]], ["giflib", "Library to handle, display and manipulate GIF images", [header_exists, "gif_lib.h"], "", "-lgif", ["loaders"]], diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_JP2.h similarity index 70% copy from include/loaders/GP_Loaders.h copy to include/loaders/GP_JP2.h index c9e9c49..7068a46 100644 --- a/include/loaders/GP_Loaders.h +++ b/include/loaders/GP_JP2.h @@ -16,40 +16,40 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
/*
- Core include file for loaders API. + JPEG 2000 support using openjpeg library.
*/
-#ifndef LOADERS_GP_LOADERS_H -#define LOADERS_GP_LOADERS_H +#ifndef LOADERS_GP_JP2_H +#define LOADERS_GP_JP2_H
#include "core/GP_Context.h" #include "core/GP_ProgressCallback.h"
-#include "loaders/GP_PNM.h" -#include "loaders/GP_BMP.h" -#include "loaders/GP_PNG.h" -#include "loaders/GP_JPG.h" -#include "loaders/GP_GIF.h" -#include "loaders/GP_TIFF.h" -#include "loaders/GP_PSP.h" - -#include "loaders/GP_TmpFile.h" +/* + * Opens up file and checks signature. + */ +int GP_OpenJP2(const char *src_path, FILE **f);
-#include "loaders/GP_MetaData.h" +/* + * Reads JP2 from an open FILE. + */ +GP_Context *GP_ReadJP2(FILE *f, GP_ProgressCallback *callback);
-#include "loaders/GP_Loader.h" +/* + * Loads a JP2 file into GP_Context. The Context is newly allocated. + */ +GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback);
-#include "loaders/GP_Container.h" -#include "loaders/GP_ZIP.h" +/* + * Match JP2 signature. + */ +int GP_MatchJP2(const void *buf);
-#endif /* LOADERS_GP_LOADERS_H */ +#endif /* LOADERS_GP_JP2_H */ diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h index c9e9c49..0ed72af 100644 --- a/include/loaders/GP_Loaders.h +++ b/include/loaders/GP_Loaders.h @@ -39,6 +39,7 @@ #include "loaders/GP_BMP.h" #include "loaders/GP_PNG.h" #include "loaders/GP_JPG.h" +#include "loaders/GP_JP2.h" #include "loaders/GP_GIF.h" #include "loaders/GP_TIFF.h" #include "loaders/GP_PSP.h" diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c new file mode 100644 index 0000000..7c7070b --- /dev/null +++ b/libs/loaders/GP_JP2.c @@ -0,0 +1,275 @@ +/***************************************************************************** + * 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-2013 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +/* + + JPEG 2000 image support using openjpeg library. + + */ + +#include <errno.h> +#include <string.h> +#include <stdio.h> + +#include "../../config.h" +#include "core/GP_Debug.h" +#include "core/GP_GetPutPixel.h" + +#include "GP_JP2.h" + +#ifdef HAVE_OPENJPEG + +#include <openjpeg-2.0/openjpeg.h> + +#define JP2_SIG "x00x00x00x0cjPx20x20x0dx0ax87x0a" +#define JP2_SIG_LEN 12 + +int GP_MatchJP2(const void *buf) +{ + return !memcmp(buf, JP2_SIG, JP2_SIG_LEN); +} + +int GP_OpenJP2(const char *src_path, FILE **f) +{ + int err; + + *f = fopen(src_path, "rb"); + + if (*f == NULL) { + err = errno; + GP_DEBUG(1, "Failed to open '%s' : %s", + src_path, strerror(errno)); + errno = err; + return 1; + } + + //TODO: check signature and rewind the stream + + return 0; +} + +static void jp2_err_callback(const char *msg, void *priv) +{ + (void) priv; + GP_WARN("openjpeg: %s", msg); +} + +static void jp2_warn_callback(const char *msg, void *priv) +{ + (void) priv; + GP_WARN("openjpeg: %s", msg); +} + +static void jp2_info_callback(const char *msg, void *priv) +{ + GP_ProgressCallback *callback = priv; + + GP_DEBUG(1, "openjpeg: %s", msg); + + GP_ProgressCallbackReport(callback, 100, 100, 100); +} + +static const char *color_space_name(OPJ_COLOR_SPACE color_space) +{ + switch (color_space) { + case OPJ_CLRSPC_UNKNOWN: + return "Unknown"; + case OPJ_CLRSPC_UNSPECIFIED: + return "Unspecified"; + case OPJ_CLRSPC_SRGB: + return "sRGB"; + case OPJ_CLRSPC_GRAY: + return "Grayscale"; + case OPJ_CLRSPC_SYCC: + return "YUV"; + default: + return "Invalid"; + } +} + +GP_Context *GP_ReadJP2(FILE *f, GP_ProgressCallback *callback) +{ + opj_dparameters_t params; + opj_codec_t *codec; + opj_stream_t *stream; + opj_image_t *img; + + GP_Context *res = NULL; + GP_PixelType pixel_type; + unsigned int i, x, y; + int err = 0; + + opj_set_default_decoder_parameters(¶ms); + + codec = opj_create_decompress(OPJ_CODEC_JP2); + + if (!codec) { + GP_DEBUG(1, "opj_create_decompress failed"); + err = ENOMEM; + goto err0; + } + + opj_set_error_handler(codec, jp2_err_callback, NULL); + opj_set_warning_handler(codec, jp2_warn_callback, NULL); + opj_set_info_handler(codec, jp2_info_callback, callback); + + if (!opj_setup_decoder(codec, ¶ms)) { + GP_DEBUG(1, "opj_setup_decoder failed"); + err = ENOMEM; + goto err1; + } + + stream = opj_stream_create_default_file_stream(f, OPJ_TRUE); + + if (!stream) { + GP_DEBUG(1, "opj_stream_create_default_file_stream faled"); + err = ENOMEM; + goto err1; + } + + if (!opj_read_header(stream, codec, &img)) { + GP_DEBUG(1, "opj_read_header failed"); + err = EINVAL; + goto err2; + } + + GP_DEBUG(1, "Have image %ux%u-%ux%u colorspace=%s numcomps=%u", + img->x0, img->y0, img->x1, img->y1, + color_space_name(img->color_space), img->numcomps); + + /* + * Try to match the image information into pixel type. + * + * Unfortunately the images I had have color_space set + * to unspecified yet they were RGB888. + */ + for (i = 0; i < img->numcomps; i++) { + opj_image_comp_t *comp = &img->comps[i]; + + GP_DEBUG(2, "Component %u %ux%u bpp=%u", + i, comp->w, comp->h, comp->prec); + + if (comp->w != img->comps[0].w || + comp->h != img->comps[0].h) { + GP_DEBUG(1, "Component %u has different size", 1); + err = ENOSYS; + goto err3; + } + + if (comp->prec != 8) { + GP_DEBUG(1, "Component %u has different bpp", 1); + err = ENOSYS; + goto err3; + } + } + + switch (img->color_space) { + case OPJ_CLRSPC_UNSPECIFIED: + if (img->numcomps != 3) { + GP_DEBUG(1, "Unexpected number of components"); + err = ENOSYS; + goto err3; + } + pixel_type = GP_PIXEL_RGB888; + break; + default: + GP_DEBUG(1, "Unsupported colorspace"); + err = ENOSYS; + goto err3; + } + + if (!opj_decode(codec, stream, img)) { + GP_DEBUG(1, "opj_decode failed"); + err = EINVAL; + goto err3; + } + + res = GP_ContextAlloc(img->comps[0].w, img->comps[0].h, pixel_type); + + if (!res) { + GP_DEBUG(1, "Malloc failed :("); + err = ENOMEM; + goto err3; + } + + for (y = 0; y < res->h; y++) { + for (x = 0; x < res->w; x++) { + i = y * res->w + x; + + GP_Pixel p = img->comps[0].data[i] << 16| + img->comps[1].data[i] << 8 | + img->comps[2].data[i]; + + GP_PutPixel_Raw_24BPP(res, x, y, p); + } + } + + GP_ProgressCallbackDone(callback); +err3: + opj_image_destroy(img); +err2: + opj_stream_destroy(stream); +err1: + opj_destroy_codec(codec); +err0: + if (err) + errno = err; + return res; +} + +GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback) +{ + FILE *f; + GP_Context *res; + + if (GP_OpenJP2(src_path, &f)) + return NULL; + + res = GP_ReadJP2(f, callback); + + fclose(f); + + return res; +} + +#else + +int GP_MatchJP2(const void GP_UNUSED(*buf)) +{ + errno = ENOSYS; + return -1; +} + +int GP_OpenJP2(const char GP_UNUSED(*src_path), FILE GP_UNUSED(**f)) +{ + errno = ENOSYS; + return 1; +} + +GP_Context *GP_ReadJP2(FILE GP_UNUSED(*f), + GP_ProgressCallback GP_UNUSED(*callback)) +{ + errno = ENOSYS; + return NULL; +} + +#endif /* HAVE_OPENJPEG */ diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c index 4f93c3e..0abd6d5 100644 --- a/libs/loaders/GP_Loader.c +++ b/libs/loaders/GP_Loader.c @@ -88,12 +88,21 @@ static GP_Loader pnm_loader = { .extensions = {"pnm", NULL}, };
+static GP_Loader jp2_loader = { + .Load = GP_LoadJP2, + .Save = NULL, + .Match = GP_MatchJP2, + .fmt_name = "JPEG 2000", + .next = &pnm_loader, + .extensions = {"jp2", "jpx", NULL}, +}; + static GP_Loader bmp_loader = { .Load = GP_LoadBMP, .Save = GP_SaveBMP, .Match = GP_MatchBMP, .fmt_name = "BMP", - .next = &pnm_loader, + .next = &jp2_loader, .extensions = {"bmp", "dib", NULL}, };
http://repo.or.cz/w/gfxprim.git/commit/147509697f74c62af9d861653379d474783b5...
commit 147509697f74c62af9d861653379d474783b5f3d Author: Cyril Hrubis metan@ucw.cz Date: Tue Aug 13 22:37:59 2013 +0200
loaders: ZIP: Fix errno vs err typo.
This fixes segfault on corrupted zip files.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_ZIP.c b/libs/loaders/GP_ZIP.c index c9064b8..42d08d5 100644 --- a/libs/loaders/GP_ZIP.c +++ b/libs/loaders/GP_ZIP.c @@ -242,7 +242,7 @@ static int read_deflate(FILE *f, struct zip_local_header *header, FILE **res_f)
if (ret != Z_STREAM_END) { GP_DEBUG(1, "Failed to inflate stream %i", ret); - errno = EINVAL; + err = EINVAL; goto err2; }
-----------------------------------------------------------------------
Summary of changes: configure | 3 + include/core/GP_Pixel.h | 2 +- include/loaders/{GP_ZIP.h => GP_JP2.h} | 28 +++- include/loaders/GP_Loaders.h | 1 + libs/core/GP_Pixel.gen.c.t | 2 +- libs/loaders/GP_JP2.c | 275 ++++++++++++++++++++++++++++++++ libs/loaders/GP_Loader.c | 11 ++- libs/loaders/GP_TmpFile.c | 4 +- libs/loaders/GP_ZIP.c | 2 +- 9 files changed, 316 insertions(+), 12 deletions(-) copy include/loaders/{GP_ZIP.h => GP_JP2.h} (76%) create mode 100644 libs/loaders/GP_JP2.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.