Bug 1155797 - P1: extract format BPP util function. r=mwu

This commit is contained in:
JerryShih 2015-05-17 18:09:00 +02:00
parent 4d8d1c5a32
commit 006bc11fce

View File

@ -286,6 +286,31 @@ TransformTo565(png_structp png_ptr, png_row_infop row_info, png_bytep data)
} }
} }
static uint16_t
GetFormatBPP(int aFormat)
{
uint16_t bpp = 0;
switch (aFormat) {
case HAL_PIXEL_FORMAT_BGRA_8888:
case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_RGBX_8888:
bpp = 4;
break;
case HAL_PIXEL_FORMAT_RGB_888:
bpp = 3;
break;
default:
LOGW("Unknown pixel format %d. Assuming RGB 565.", aFormat);
// FALL THROUGH
case HAL_PIXEL_FORMAT_RGB_565:
bpp = 2;
break;
}
return bpp;
}
void void
AnimationFrame::ReadPngFrame(int outputFormat) AnimationFrame::ReadPngFrame(int outputFormat)
{ {
@ -358,24 +383,23 @@ AnimationFrame::ReadPngFrame(int outputFormat)
path, width, height, has_bgcolor ? "yes" : "no", path, width, height, has_bgcolor ? "yes" : "no",
bgcolor.red, bgcolor.green, bgcolor.blue, bgcolor.gray); bgcolor.red, bgcolor.green, bgcolor.blue, bgcolor.gray);
bytepp = GetFormatBPP(outputFormat);
switch (outputFormat) { switch (outputFormat) {
case HAL_PIXEL_FORMAT_BGRA_8888: case HAL_PIXEL_FORMAT_BGRA_8888:
png_set_bgr(pngread); png_set_bgr(pngread);
// FALL THROUGH // FALL THROUGH
case HAL_PIXEL_FORMAT_RGBA_8888: case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_RGBX_8888: case HAL_PIXEL_FORMAT_RGBX_8888:
bytepp = 4;
png_set_filler(pngread, 0xFF, PNG_FILLER_AFTER); png_set_filler(pngread, 0xFF, PNG_FILLER_AFTER);
break; break;
case HAL_PIXEL_FORMAT_RGB_888: case HAL_PIXEL_FORMAT_RGB_888:
bytepp = 3;
png_set_strip_alpha(pngread); png_set_strip_alpha(pngread);
break; break;
default: default:
LOGW("Unknown pixel format %d. Assuming RGB 565.", outputFormat); LOGW("Unknown pixel format %d. Assuming RGB 565.", outputFormat);
// FALL THROUGH // FALL THROUGH
case HAL_PIXEL_FORMAT_RGB_565: case HAL_PIXEL_FORMAT_RGB_565:
bytepp = 2;
png_set_strip_alpha(pngread); png_set_strip_alpha(pngread);
png_set_read_user_transform_fn(pngread, TransformTo565); png_set_read_user_transform_fn(pngread, TransformTo565);
break; break;