add support for RGB565, ARGB4444 and ARGB colorspace (decoder)

RGB565 and ARGB4444 are only supported through the advanced decoding API.
ARGB being somewhat generic, there's an easy WebPDecodeARGB()
new function for convenience.

Patch by Vikas Arora (vikaas dot arora at gmail dot com)

Change-Id: Ic7b6f72bd70aca458d14e7fdd23679212430ebca
This commit is contained in:
Pascal Massimino
2011-07-13 09:08:58 -07:00
parent c915fb2aa7
commit 19db59f80f
7 changed files with 123 additions and 45 deletions

View File

@ -20,6 +20,9 @@ extern "C" {
//-----------------------------------------------------------------------------
// WebPDecBuffer
// Number of bytes per pixel for the different color-spaces.
static const int kModeBpp[MODE_LAST] = { 3, 4, 3, 4, 4, 2, 2, 1, 1 };
static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) {
int ok = 1;
WEBP_CSP_MODE mode = buffer->colorspace;
@ -44,11 +47,7 @@ static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) {
} else { // RGB checks
const WebPRGBABuffer* const buf = &buffer->u.RGBA;
ok &= (buf->stride * height <= buf->size);
if (mode == MODE_RGB || mode == MODE_BGR) {
ok &= (buf->stride >= width * 3);
} else if (mode == MODE_RGBA || mode == MODE_BGRA) {
ok &= (buf->stride >= width * 4);
}
ok &= (buf->stride >= width * kModeBpp[mode]);
}
return ok ? VP8_STATUS_OK : VP8_STATUS_INVALID_PARAM;
}
@ -70,9 +69,7 @@ static VP8StatusCode AllocateBuffer(WebPDecBuffer* const buffer) {
uint64_t size, a_size = 0, total_size;
// We need memory and it hasn't been allocated yet.
// => initialize output buffer, now that dimensions are known.
stride = (mode == MODE_RGB || mode == MODE_BGR) ? 3 * w
: (mode == MODE_RGBA || mode == MODE_BGRA) ? 4 * w
: w;
stride = w * kModeBpp[mode];
size = (uint64_t)stride * h;
if (mode >= MODE_YUV) {