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.