mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
Merge "cwebp: add metadata framework"
This commit is contained in:
commit
4679db006c
@ -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)
|
||||
|
@ -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) {
|
||||
|
53
examples/metadata.h
Normal file
53
examples/metadata.h
Normal 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_
|
Loading…
Reference in New Issue
Block a user