add examples/metadata.c

relocates the static functions from metadata.h and adds MetadataCopy()
to the interface

Change-Id: I28bfa9233d3dd70dddf6b561fe0bf4be378db1ec
This commit is contained in:
James Zern 2012-12-11 13:55:31 -08:00
parent 207f89c0dc
commit 6bf208748c
5 changed files with 56 additions and 15 deletions

View File

@ -173,6 +173,7 @@ DSP_OBJS = \
EX_FORMAT_DEC_OBJS = \ EX_FORMAT_DEC_OBJS = \
$(DIROBJ)\examples/jpegdec.obj \ $(DIROBJ)\examples/jpegdec.obj \
$(DIROBJ)\examples/metadata.obj \
$(DIROBJ)\examples/pngdec.obj \ $(DIROBJ)\examples/pngdec.obj \
$(DIROBJ)\examples/tiffdec.obj \ $(DIROBJ)\examples/tiffdec.obj \

View File

@ -20,7 +20,7 @@ dwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
dwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES) dwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES)
dwebp_LDADD = libexampleutil.la ../src/libwebp.la $(PNG_LIBS) $(JPEG_LIBS) 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 += jpegdec.c jpegdec.h
cwebp_SOURCES += pngdec.c pngdec.h cwebp_SOURCES += pngdec.c pngdec.h
cwebp_SOURCES += tiffdec.c tiffdec.h cwebp_SOURCES += tiffdec.c tiffdec.h

47
examples/metadata.c Normal file
View File

@ -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 <stdlib.h>
#include <string.h>
#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;
}
// -----------------------------------------------------------------------------

View File

@ -30,21 +30,13 @@ typedef struct Metadata {
#define METADATA_OFFSET(x) offsetof(Metadata, x) #define METADATA_OFFSET(x) offsetof(Metadata, x)
static void MetadataInit(Metadata* const m) { void MetadataInit(Metadata* const metadata);
memset(m, 0, sizeof(*m)); void MetadataPayloadDelete(MetadataPayload* const payload);
} void MetadataFree(Metadata* const metadata);
static void MetadataPayloadDelete(MetadataPayload* const payload) { // Stores 'metadata' to 'payload->bytes', returns false on allocation error.
free(payload->bytes); int MetadataCopy(const char* metadata, size_t metadata_len,
payload->bytes = NULL; MetadataPayload* const payload);
payload->size = 0;
}
static void MetadataFree(Metadata* const m) {
MetadataPayloadDelete(&m->exif);
MetadataPayloadDelete(&m->iccp);
MetadataPayloadDelete(&m->xmp);
}
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
} // extern "C" } // extern "C"

View File

@ -126,6 +126,7 @@ ENC_OBJS = \
EX_FORMAT_DEC_OBJS = \ EX_FORMAT_DEC_OBJS = \
examples/jpegdec.o \ examples/jpegdec.o \
examples/metadata.o \
examples/pngdec.o \ examples/pngdec.o \
examples/tiffdec.o \ examples/tiffdec.o \