AnimEncoder API: Support input frames in YUV(A) format.

We automatically convert them to ARGB format.

Change-Id: Ia21f07e08c746e16a318cb035af375c81d9af0de
This commit is contained in:
Urvang Joshi 2015-03-10 11:27:09 -07:00
parent 44bd95612e
commit 0873f85b54
2 changed files with 15 additions and 3 deletions

View File

@ -1058,14 +1058,25 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int duration,
return 0; return 0;
} }
if (frame->width != enc->canvas_width_ || if (frame->width != enc->canvas_width_ ||
frame->height != enc->canvas_height_ || !frame->use_argb || frame->height != enc->canvas_height_ || duration < 0) {
duration < 0) {
frame->error_code = VP8_ENC_ERROR_INVALID_CONFIGURATION; frame->error_code = VP8_ENC_ERROR_INVALID_CONFIGURATION;
if (enc->options_.verbose) { if (enc->options_.verbose) {
fprintf(stderr, "ERROR adding frame: Invalid input.\n"); fprintf(stderr, "ERROR adding frame: Invalid input.\n");
} }
return 0; 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) { if (encoder_config != NULL) {
config = *encoder_config; config = *encoder_config;
} else { } else {

View File

@ -473,7 +473,8 @@ static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew(
// WebPAnimEncoder object. // WebPAnimEncoder object.
// Parameters: // Parameters:
// enc - (in/out) object to which the frame is to be added. // 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 // duration - (in) frame duration
// config - (in) encoding options; can be passed NULL to pick // config - (in) encoding options; can be passed NULL to pick
// reasonable defaults. // reasonable defaults.