mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
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:
parent
207f89c0dc
commit
6bf208748c
@ -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 \
|
||||
|
||||
|
@ -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
|
||||
|
47
examples/metadata.c
Normal file
47
examples/metadata.c
Normal 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;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
@ -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"
|
||||
|
@ -126,6 +126,7 @@ ENC_OBJS = \
|
||||
|
||||
EX_FORMAT_DEC_OBJS = \
|
||||
examples/jpegdec.o \
|
||||
examples/metadata.o \
|
||||
examples/pngdec.o \
|
||||
examples/tiffdec.o \
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user