From 0873f85b54b8b82757b0e74826363cb44796e6e6 Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Tue, 10 Mar 2015 11:27:09 -0700 Subject: [PATCH] AnimEncoder API: Support input frames in YUV(A) format. We automatically convert them to ARGB format. Change-Id: Ia21f07e08c746e16a318cb035af375c81d9af0de --- src/mux/anim_encode.c | 15 +++++++++++++-- src/webp/mux.h | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mux/anim_encode.c b/src/mux/anim_encode.c index 68374f0b..9fd50b00 100644 --- a/src/mux/anim_encode.c +++ b/src/mux/anim_encode.c @@ -1058,14 +1058,25 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int duration, return 0; } if (frame->width != enc->canvas_width_ || - frame->height != enc->canvas_height_ || !frame->use_argb || - duration < 0) { + frame->height != enc->canvas_height_ || duration < 0) { frame->error_code = VP8_ENC_ERROR_INVALID_CONFIGURATION; if (enc->options_.verbose) { fprintf(stderr, "ERROR adding frame: Invalid input.\n"); } return 0; } + + if (!frame->use_argb) { // Convert frame from YUV(A) to ARGB. + if (enc->options_.verbose) { + fprintf(stderr, "WARNING: Converting frame from YUV(A) to ARGB format; " + "this incurs a small loss.\n"); + } + if (!WebPPictureYUVAToARGB(frame)) { + fprintf(stderr, "ERROR converting frame from YUV(A) to ARGB\n"); + return 0; + } + } + if (encoder_config != NULL) { config = *encoder_config; } else { diff --git a/src/webp/mux.h b/src/webp/mux.h index dbedbffa..26a58711 100644 --- a/src/webp/mux.h +++ b/src/webp/mux.h @@ -473,7 +473,8 @@ static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew( // WebPAnimEncoder object. // Parameters: // enc - (in/out) object to which the frame is to be added. -// frame - (in/out) frame data in ARGB or YUVA format. +// frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A) +// format, it will be converted to ARGB, which incurs a small loss. // duration - (in) frame duration // config - (in) encoding options; can be passed NULL to pick // reasonable defaults.