From 6bf208748cfabce3a06424cd03484232adb49e7e Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 11 Dec 2012 13:55:31 -0800 Subject: [PATCH] add examples/metadata.c relocates the static functions from metadata.h and adds MetadataCopy() to the interface Change-Id: I28bfa9233d3dd70dddf6b561fe0bf4be378db1ec --- Makefile.vc | 1 + examples/Makefile.am | 2 +- examples/metadata.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ examples/metadata.h | 20 ++++++------------- makefile.unix | 1 + 5 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 examples/metadata.c diff --git a/Makefile.vc b/Makefile.vc index 75a12ee4..a37febc2 100644 --- a/Makefile.vc +++ b/Makefile.vc @@ -173,6 +173,7 @@ DSP_OBJS = \ EX_FORMAT_DEC_OBJS = \ $(DIROBJ)\examples/jpegdec.obj \ + $(DIROBJ)\examples/metadata.obj \ $(DIROBJ)\examples/pngdec.obj \ $(DIROBJ)\examples/tiffdec.obj \ diff --git a/examples/Makefile.am b/examples/Makefile.am index b7988e85..5e71b112 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 metadata.h stopwatch.h +cwebp_SOURCES = cwebp.c metadata.c metadata.h stopwatch.h cwebp_SOURCES += jpegdec.c jpegdec.h cwebp_SOURCES += pngdec.c pngdec.h cwebp_SOURCES += tiffdec.c tiffdec.h diff --git a/examples/metadata.c b/examples/metadata.c new file mode 100644 index 00000000..38a3d8cc --- /dev/null +++ b/examples/metadata.c @@ -0,0 +1,47 @@ +// 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. +// + +#include "./metadata.h" + +#include +#include + +#include "webp/types.h" + +void MetadataInit(Metadata* const metadata) { + if (metadata == NULL) return; + memset(metadata, 0, sizeof(*metadata)); +} + +void MetadataPayloadDelete(MetadataPayload* const payload) { + if (payload == NULL) return; + free(payload->bytes); + payload->bytes = NULL; + payload->size = 0; +} + +void MetadataFree(Metadata* const metadata) { + if (metadata == NULL) return; + MetadataPayloadDelete(&metadata->exif); + MetadataPayloadDelete(&metadata->iccp); + MetadataPayloadDelete(&metadata->xmp); +} + +int MetadataCopy(const char* metadata, size_t metadata_len, + MetadataPayload* const payload) { + if (metadata == NULL || metadata_len == 0 || payload == NULL) return 0; + payload->bytes = (uint8_t*)malloc(metadata_len); + if (payload->bytes == NULL) return 0; + payload->size = metadata_len; + memcpy(payload->bytes, metadata, metadata_len); + return 1; +} + +// ----------------------------------------------------------------------------- diff --git a/examples/metadata.h b/examples/metadata.h index 3cbf5c95..641f7c73 100644 --- a/examples/metadata.h +++ b/examples/metadata.h @@ -30,21 +30,13 @@ typedef struct Metadata { #define METADATA_OFFSET(x) offsetof(Metadata, x) -static void MetadataInit(Metadata* const m) { - memset(m, 0, sizeof(*m)); -} +void MetadataInit(Metadata* const metadata); +void MetadataPayloadDelete(MetadataPayload* const payload); +void MetadataFree(Metadata* const metadata); -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); -} +// Stores 'metadata' to 'payload->bytes', returns false on allocation error. +int MetadataCopy(const char* metadata, size_t metadata_len, + MetadataPayload* const payload); #if defined(__cplusplus) || defined(c_plusplus) } // extern "C" diff --git a/makefile.unix b/makefile.unix index 7fcc6033..b027786f 100644 --- a/makefile.unix +++ b/makefile.unix @@ -126,6 +126,7 @@ ENC_OBJS = \ EX_FORMAT_DEC_OBJS = \ examples/jpegdec.o \ + examples/metadata.o \ examples/pngdec.o \ examples/tiffdec.o \