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 4939286022a028a66c62ee082748384a908fed37 (commit) from 0d68cb863abf1ed7aef032d87f21a0e7193f2986 (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/4939286022a028a66c62ee082748384a908fe...
commit 4939286022a028a66c62ee082748384a908fed37 Author: Cyril Hrubis metan@ucw.cz Date: Mon May 28 15:43:10 2012 +0200
loaders: Start with meta-data support for JPEG.
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h index 7cbbd36..73113c4 100644 --- a/include/loaders/GP_JPG.h +++ b/include/loaders/GP_JPG.h @@ -32,6 +32,8 @@ #include "core/GP_Context.h" #include "core/GP_ProgressCallback.h"
+#include "GP_MetaData.h" + /* * Opens up file and checks signature. */ @@ -49,6 +51,12 @@ GP_Context *GP_ReadJPG(FILE *f, GP_ProgressCallback *callback); GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback);
/* + * Loads JPEG meta-data, called markers in JPEG terminology. + */ +int GP_ReadJPGMetaData(FILE *f, GP_MetaData *data); +int GP_LoadJPGMetaData(const char *src_path, GP_MetaData *data); + +/* * Saves JPG to a file. */ int GP_SaveJPG(const GP_Context *src, const char *dst_path, diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c index 6011b8f..f600b57 100644 --- a/libs/loaders/GP_JPG.c +++ b/libs/loaders/GP_JPG.c @@ -205,6 +205,103 @@ GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback) return res; }
+#define JPEG_COM_MAX 128 + +static void read_jpg_metadata(struct jpeg_decompress_struct *cinfo, + GP_MetaData *data) +{ + jpeg_saved_marker_ptr marker; + + for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { + switch (marker->marker) { + case JPEG_COM: { + char buf[JPEG_COM_MAX+1]; + + memcpy(buf, marker->data, marker->data_length); + buf[marker->data_length] = 0; + + /* Strip newline at the end of the commment */ + if (buf[marker->data_length-1] == 'n') + buf[marker->data_length-1] = 0; + + GP_MetaDataCreateString(data, "comment", buf, 1); + } + break; + case JPEG_APP0: + GP_DEBUG(0, "TODO: JFIF"); + break; + case JPEG_APP0 + 1: + GP_DEBUG(0, "TODO: EXIF"); + break; + } + } +} + +static void save_jpg_markers(struct jpeg_decompress_struct *cinfo) +{ + /* Comment marker */ + jpeg_save_markers(cinfo, JPEG_COM, JPEG_COM_MAX); + + /* APP0 marker = JFIF data */ + jpeg_save_markers(cinfo, JPEG_APP0 + 1, 0xffff); + + /* APP1 marker = Exif data */ + jpeg_save_markers(cinfo, JPEG_APP0 + 1, 0xffff); +} + +int GP_ReadJPGMetaData(FILE *f, GP_MetaData *data) +{ + struct jpeg_decompress_struct cinfo; + struct my_jpg_err my_err; + int err; + + cinfo.err = jpeg_std_error(&my_err.error_mgr); + my_err.error_mgr.error_exit = my_error_exit; + + if (setjmp(my_err.setjmp_buf)) { + err = EIO; + goto err1; + } + + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, f); + + save_jpg_markers(&cinfo); + + jpeg_read_header(&cinfo, TRUE); + + GP_DEBUG(1, "Have %s JPEG size %ux%u %i channels", + get_colorspace(cinfo.jpeg_color_space), + cinfo.image_width, cinfo.image_height, + cinfo.num_components); + + read_jpg_metadata(&cinfo, data); + +// jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + return 0; +err1: + jpeg_destroy_decompress(&cinfo); + errno = err; + return 1; +} + +int GP_LoadJPGMetaData(const char *src_path, GP_MetaData *data) +{ + FILE *f; + int ret; + + if (GP_OpenJPG(src_path, &f)) + return 1; + + ret = GP_ReadJPGMetaData(f, data); + + fclose(f); + + return ret; +} + int GP_SaveJPG(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { @@ -326,6 +423,19 @@ GP_Context *GP_LoadJPG(const char GP_UNUSED(*src_path), return NULL; }
+int GP_ReadJPGMetaData(FILE GP_UNUSED(*f), GP_MetaData GP_UNUSED(*data)) +{ + errno = ENOSYS; + return NULL; +} + +int GP_LoadJPGMetaData(const char GP_UNUSED(*src_path), + GP_MetaData GP_UNUSED(*data)) +{ + errno = ENOSYS; + return NULL; +} + int GP_SaveJPG(const GP_Context GP_UNUSED(*src), const char GP_UNUSED(*dst_path), GP_ProgressCallback GP_UNUSED(*callback))
-----------------------------------------------------------------------
Summary of changes: include/loaders/GP_JPG.h | 8 +++ libs/loaders/GP_JPG.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 0 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.