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
This commit is contained in:
James Zern 2012-12-03 18:20:00 -08:00
parent d65ec6786a
commit 63aba3aef1
3 changed files with 63 additions and 4 deletions

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 stopwatch.h cwebp_SOURCES = cwebp.c metadata.h stopwatch.h
cwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) cwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
cwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES) cwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES)
cwebp_LDADD = ../src/libwebp.la $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS) cwebp_LDADD = ../src/libwebp.la $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS)

View File

@ -46,6 +46,7 @@
#include "webp/encode.h" #include "webp/encode.h"
#include "./metadata.h"
#include "./stopwatch.h" #include "./stopwatch.h"
#ifndef WEBP_DLL #ifndef WEBP_DLL
#if defined(__cplusplus) || defined(c_plusplus) #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, static int ReadPicture(const char* const filename, WebPPicture* const pic,
int keep_alpha) { int keep_alpha, Metadata* const metadata) {
int ok; int ok;
(void)metadata; // TODO(jzern): add metadata extraction using WIC
if (pic->width != 0 && pic->height != 0) { if (pic->width != 0 && pic->height != 0) {
// If image size is specified, infer it as YUV format. // If image size is specified, infer it as YUV format.
FILE* in_file = fopen(filename, "rb"); 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, static int ReadPicture(const char* const filename, WebPPicture* const pic,
int keep_alpha) { int keep_alpha, Metadata* const metadata) {
int ok = 0; int ok = 0;
FILE* in_file = fopen(filename, "rb"); FILE* in_file = fopen(filename, "rb");
(void)metadata; // TODO(jzern): add metadata extraction to the formats below.
if (in_file == NULL) { if (in_file == NULL) {
fprintf(stderr, "Error! Cannot open input file '%s'\n", filename); fprintf(stderr, "Error! Cannot open input file '%s'\n", filename);
return ok; return ok;
@ -934,8 +937,10 @@ int main(int argc, const char *argv[]) {
WebPPicture original_picture; // when PSNR or SSIM is requested WebPPicture original_picture; // when PSNR or SSIM is requested
WebPConfig config; WebPConfig config;
WebPAuxStats stats; WebPAuxStats stats;
Metadata metadata;
Stopwatch stop_watch; Stopwatch stop_watch;
MetadataInit(&metadata);
if (!WebPPictureInit(&picture) || if (!WebPPictureInit(&picture) ||
!WebPPictureInit(&original_picture) || !WebPPictureInit(&original_picture) ||
!WebPConfigInit(&config)) { !WebPConfigInit(&config)) {
@ -1128,7 +1133,7 @@ int main(int argc, const char *argv[]) {
if (verbose) { if (verbose) {
StopwatchReadAndReset(&stop_watch); 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); fprintf(stderr, "Error! Cannot read input picture file '%s'\n", in_file);
goto Error; goto Error;
} }
@ -1227,6 +1232,7 @@ int main(int argc, const char *argv[]) {
Error: Error:
free(picture.extra_info); free(picture.extra_info);
MetadataFree(&metadata);
WebPPictureFree(&picture); WebPPictureFree(&picture);
WebPPictureFree(&original_picture); WebPPictureFree(&original_picture);
if (out != NULL) { if (out != NULL) {

53
examples/metadata.h Normal file
View File

@ -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_