add automatic YUVA/ARGB conversion during WebPEncode()

Adds new methods WebPPictureARGBToYUVA() and WebPPictureYUVAToARGB()
Depending on the value of picture->use_argb_input,
the main call WebPEncode() will convert appropriately.
Note that both conversions are lossy, so it's recommended to:
* use YUVA input for lossy compression (picture->use_argb_input=0)
* use ARGB input for lossless compression (picture->use_argb_input=1)

Change-Id: I8269d607723ee8a1136b9f4999f7ff4e657bbb04
This commit is contained in:
Pascal Massimino
2012-06-28 00:34:23 -07:00
parent 802e012a18
commit fcc69923b9
5 changed files with 378 additions and 137 deletions

View File

@ -349,15 +349,31 @@ WEBP_EXTERN(int) WebPPictureImportBGRA(
WEBP_EXTERN(int) WebPPictureImportBGRX(
WebPPicture* const picture, const uint8_t* const bgrx, int bgrx_stride);
// Converts picture->argb data to the YUVA format specified by 'colorspace'.
// Upon return, picture->use_argb_input is set to false. The presence of
// real non-opaque transparent values is detected, and 'colorspace' will be
// adjusted accordingly. Note that this method is lossy.
// Returns false in case of error.
WEBP_EXTERN(int) WebPPictureARGBToYUVA(WebPPicture* const picture,
WebPEncCSP colorspace);
// Converts picture->yuv to picture->argb and sets picture->use_argb_input
// to true. The input format must be YUV_420 or YUV_420A.
// Note that the use of this method is discouraged if one has access to the
// raw ARGB samples, since using YUV420 is comparatively lossy. Also, the
// conversion from YUV420 to ARGB incurs a small loss too.
// Returns false in case of error.
WEBP_EXTERN(int) WebPPictureYUVAToARGB(WebPPicture* const picture);
// Helper function: given a width x height plane of YUV(A) samples
// (with stride 'stride'), clean-up the YUV samples under fully transparent
// area, to help compressibility (no guarantee, though).
WEBP_EXTERN(void) WebPCleanupTransparentArea(WebPPicture* const picture);
// Scan the picture 'pic' for the presence of non fully opaque alpha values.
// Scan the picture 'picture' for the presence of non fully opaque alpha values.
// Returns true in such case. Otherwise returns false (indicating that the
// alpha plane can be ignored altogether e.g.).
WEBP_EXTERN(int) WebPPictureHasTransparency(const WebPPicture* const pic);
WEBP_EXTERN(int) WebPPictureHasTransparency(const WebPPicture* const picture);
//------------------------------------------------------------------------------
// Main call
@ -367,8 +383,13 @@ WEBP_EXTERN(int) WebPPictureHasTransparency(const WebPPicture* const pic);
// and the 'config' object must be a valid one.
// Returns false in case of error, true otherwise.
// In case of error, picture->error_code is updated accordingly.
WEBP_EXTERN(int) WebPEncode(
const WebPConfig* const config, WebPPicture* const picture);
// 'picture' can hold the source samples in both YUV(A) or ARGB input, depending
// on the value of 'picture->use_argb_input'. It is highly recommended to
// use the former for lossy encoding, and the latter for lossless encoding
// (when config.lossless is true). Automatic conversion from one format to
// another is provided but they both incur some loss.
WEBP_EXTERN(int) WebPEncode(const WebPConfig* const config,
WebPPicture* const picture);
//------------------------------------------------------------------------------