@@ -38,8 +38,8 @@
* @author Josef Zlomek, Pexeso Inc. <josef@pex.com>
* Animation
*
- * Unimplemented:
- * - XMP metadata
+ * @author Thilo Borgmann <thilo.borgmann _at_ mail.de>
+ * XMP metadata
*/
#include "libavutil/imgutils.h"
@@ -216,6 +216,7 @@ typedef struct WebPContext {
int alpha_data_size; /* alpha chunk data size */
int has_exif; /* set after an EXIF chunk has been processed */
int has_iccp; /* set after an ICCP chunk has been processed */
+ int has_xmp; /* set after an XMP chunk has been processed */
int width; /* image width */
int height; /* image height */
int vp8x_flags; /* global flags from VP8X chunk */
@@ -1463,6 +1464,7 @@ static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int si
// reset metadata bit for each packet
s->has_exif = 0;
s->has_iccp = 0;
+ s->has_xmp = 0;
while (bytestream2_get_bytes_left(&gb) > 8) {
char chunk_str[5] = { 0 };
@@ -1494,6 +1496,7 @@ static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int si
s->canvas_height = 0;
s->has_exif = 0;
s->has_iccp = 0;
+ s->has_xmp = 0;
ff_thread_release_ext_buffer(&s->canvas_frame);
break;
case MKTAG('V', 'P', '8', ' '):
@@ -1679,12 +1682,39 @@ exif_end:
}
s->vp8x_flags |= VP8X_FLAG_ANIMATION;
break;
- case MKTAG('X', 'M', 'P', ' '):
- AV_WL32(chunk_str, chunk_type);
- av_log(avctx, AV_LOG_WARNING, "skipping unsupported chunk: %s\n",
- chunk_str);
+ case MKTAG('X', 'M', 'P', ' '): {
+ GetByteContext xmp_gb;
+ AVDictionary **xmp_metadata = NULL;
+ uint8_t *buffer;
+ int xmp_offset = bytestream2_tell(&gb);
+
+ if (s->has_xmp) {
+ av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra XMP chunk\n");
+ goto xmp_end;
+ }
+ if (!(s->vp8x_flags & VP8X_FLAG_XMP_METADATA))
+ av_log(avctx, AV_LOG_WARNING,
+ "XMP chunk present, but XMP bit not set in the "
+ "VP8X header\n");
+
+ // there are at least chunk_size bytes left to read
+ buffer = av_malloc(chunk_size + 1);
+ if (!buffer) {
+ return AVERROR(ENOMEM);
+ }
+
+ s->has_xmp = 1;
+ bytestream2_init(&xmp_gb, data + xmp_offset, size - xmp_offset);
+ bytestream2_get_buffer(&xmp_gb, buffer, chunk_size);
+ buffer[chunk_size] = '\0';
+
+ xmp_metadata = (s->vp8x_flags & VP8X_FLAG_ANIMATION) ? &p->metadata : &s->frame->metadata;
+ av_dict_set(xmp_metadata, "xmp", buffer, AV_DICT_DONT_STRDUP_VAL);
+
+xmp_end:
bytestream2_skip(&gb, chunk_size);
break;
+ }
default:
AV_WL32(chunk_str, chunk_type);
av_log(avctx, AV_LOG_VERBOSE, "skipping unknown chunk: %s\n",