From 63aba3aef1bed05ee2a82526a40b1ccea8f44135 Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 3 Dec 2012 18:20:00 -0800 Subject: [PATCH] cwebp: add metadata framework unused currently, but the intent is to allow each format to populate exif/xmp/icc with cwebp then transferring it to the webp file. Change-Id: I0514f62de52fa7f89c595ee7ef2ad7dced910a41 --- examples/Makefile.am | 2 +- examples/cwebp.c | 12 +++++++--- examples/metadata.h | 53 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 examples/metadata.h diff --git a/examples/Makefile.am b/examples/Makefile.am index 140b654e..6fd7fc06 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -20,7 +20,7 @@ dwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) dwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES) dwebp_LDADD = libexampleutil.la ../src/libwebp.la $(PNG_LIBS) $(JPEG_LIBS) -cwebp_SOURCES = cwebp.c stopwatch.h +cwebp_SOURCES = cwebp.c metadata.h stopwatch.h cwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) cwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES) cwebp_LDADD = ../src/libwebp.la $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS) diff --git a/examples/cwebp.c b/examples/cwebp.c index 538d71e8..c99e9395 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -46,6 +46,7 @@ #include "webp/encode.h" +#include "./metadata.h" #include "./stopwatch.h" #ifndef WEBP_DLL #if defined(__cplusplus) || defined(c_plusplus) @@ -270,8 +271,9 @@ static HRESULT ReadPictureWithWIC(const char* filename, } static int ReadPicture(const char* const filename, WebPPicture* const pic, - int keep_alpha) { + int keep_alpha, Metadata* const metadata) { int ok; + (void)metadata; // TODO(jzern): add metadata extraction using WIC if (pic->width != 0 && pic->height != 0) { // If image size is specified, infer it as YUV format. FILE* in_file = fopen(filename, "rb"); @@ -578,9 +580,10 @@ static InputFileFormat GetImageType(FILE* in_file) { } static int ReadPicture(const char* const filename, WebPPicture* const pic, - int keep_alpha) { + int keep_alpha, Metadata* const metadata) { int ok = 0; FILE* in_file = fopen(filename, "rb"); + (void)metadata; // TODO(jzern): add metadata extraction to the formats below. if (in_file == NULL) { fprintf(stderr, "Error! Cannot open input file '%s'\n", filename); return ok; @@ -934,8 +937,10 @@ int main(int argc, const char *argv[]) { WebPPicture original_picture; // when PSNR or SSIM is requested WebPConfig config; WebPAuxStats stats; + Metadata metadata; Stopwatch stop_watch; + MetadataInit(&metadata); if (!WebPPictureInit(&picture) || !WebPPictureInit(&original_picture) || !WebPConfigInit(&config)) { @@ -1128,7 +1133,7 @@ int main(int argc, const char *argv[]) { if (verbose) { StopwatchReadAndReset(&stop_watch); } - if (!ReadPicture(in_file, &picture, keep_alpha)) { + if (!ReadPicture(in_file, &picture, keep_alpha, &metadata)) { fprintf(stderr, "Error! Cannot read input picture file '%s'\n", in_file); goto Error; } @@ -1227,6 +1232,7 @@ int main(int argc, const char *argv[]) { Error: free(picture.extra_info); + MetadataFree(&metadata); WebPPictureFree(&picture); WebPPictureFree(&original_picture); if (out != NULL) { diff --git a/examples/metadata.h b/examples/metadata.h new file mode 100644 index 00000000..3cbf5c95 --- /dev/null +++ b/examples/metadata.h @@ -0,0 +1,53 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// This code is licensed under the same terms as WebM: +// Software License Agreement: http://www.webmproject.org/license/software/ +// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// ----------------------------------------------------------------------------- +// +// Metadata types and functions. +// + +#ifndef WEBP_EXAMPLES_METADATA_H_ +#define WEBP_EXAMPLES_METADATA_H_ + +#include "webp/types.h" + +#if defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif + +typedef struct MetadataPayload { + uint8_t* bytes; + size_t size; +} MetadataPayload; + +typedef struct Metadata { + MetadataPayload exif; + MetadataPayload iccp; + MetadataPayload xmp; +} Metadata; + +#define METADATA_OFFSET(x) offsetof(Metadata, x) + +static void MetadataInit(Metadata* const m) { + memset(m, 0, sizeof(*m)); +} + +static void MetadataPayloadDelete(MetadataPayload* const payload) { + free(payload->bytes); + payload->bytes = NULL; + payload->size = 0; +} + +static void MetadataFree(Metadata* const m) { + MetadataPayloadDelete(&m->exif); + MetadataPayloadDelete(&m->iccp); + MetadataPayloadDelete(&m->xmp); +} + +#if defined(__cplusplus) || defined(c_plusplus) +} // extern "C" +#endif + +#endif // WEBP_EXAMPLES_METADATA_H_