From 27519bc2b6bce7d5590b5f8b23ef554773aabe50 Mon Sep 17 00:00:00 2001 From: Noel Chromium Date: Tue, 5 Jun 2012 00:26:17 -0700 Subject: [PATCH] add WebPPictureImportRGBX() and WebPPictureImportBGRX() When importing BGRA or RGBA data for encoding, provide variants of the WEBPImportPicture API for RGBX and BRGX data meaning the alpha channel should be ignored. Author: noel@chromium.org from Chromium patch: https://chromiumcodereview.appspot.com/10496016/ Change-Id: I15fcaa4160c69a2b5549394204b6e6d7a1c5d333 --- src/enc/picture.c | 10 ++++++++++ src/webp/encode.h | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/enc/picture.c b/src/enc/picture.c index b177eef0..a2d1e439 100644 --- a/src/enc/picture.c +++ b/src/enc/picture.c @@ -604,6 +604,16 @@ int WebPPictureImportBGRA(WebPPicture* const picture, return Import(picture, rgba, rgba_stride, 4, 1, 1); } +int WebPPictureImportRGBX(WebPPicture* const picture, + const uint8_t* const rgba, int rgba_stride) { + return Import(picture, rgba, rgba_stride, 4, 0, 0); +} + +int WebPPictureImportBGRX(WebPPicture* const picture, + const uint8_t* const rgba, int rgba_stride) { + return Import(picture, rgba, rgba_stride, 4, 1, 0); +} + //------------------------------------------------------------------------------ // Helper: clean up fully transparent area to help compressibility. diff --git a/src/webp/encode.h b/src/webp/encode.h index 3b00bdc2..49e6b102 100644 --- a/src/webp/encode.h +++ b/src/webp/encode.h @@ -278,15 +278,22 @@ WEBP_EXTERN(int) WebPPictureRescale(WebPPicture* const pic, // Returns 0 in case of memory error. WEBP_EXTERN(int) WebPPictureImportRGB( WebPPicture* const picture, const uint8_t* const rgb, int rgb_stride); -// Same, but for RGBA buffer +// Same, but for RGBA buffer. WEBP_EXTERN(int) WebPPictureImportRGBA( WebPPicture* const picture, const uint8_t* const rgba, int rgba_stride); +// Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format +// input buffer ignoring the alpha channel. Avoids needing to copy the data +// to a temporary 24-bit RGB buffer to import the RGB only. +WEBP_EXTERN(int) WebPPictureImportRGBX( + WebPPicture* const picture, const uint8_t* const rgbx, int rgbx_stride); -// Variant of the above, but taking BGR(A) input: +// Variants of the above, but taking BGR(A|X) input. WEBP_EXTERN(int) WebPPictureImportBGR( WebPPicture* const picture, const uint8_t* const bgr, int bgr_stride); WEBP_EXTERN(int) WebPPictureImportBGRA( WebPPicture* const picture, const uint8_t* const bgra, int bgra_stride); +WEBP_EXTERN(int) WebPPictureImportBGRX( + WebPPicture* const picture, const uint8_t* const bgrx, int bgrx_stride); // Helper function: given a width x height plane of YUV(A) samples // (with stride 'stride'), clean-up the YUV samples under fully transparent