AI 143289: am: CL 143128 Use PNG instead of BMP for recovery image icons. This saves

about 60k from the recovery and system images.
  Original author: dougz
  Merged from: //branches/donutburger/...

Automated import of CL 143289
This commit is contained in:
Doug Zongker 2009-03-27 17:06:24 -07:00 committed by The Android Open Source Project
parent e6faba0580
commit 19faefad05
36 changed files with 68 additions and 101 deletions

View file

@ -30,7 +30,7 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_TAGS := eng LOCAL_MODULE_TAGS := eng
LOCAL_STATIC_LIBRARIES := libminzip libunz libamend libmtdutils libmincrypt LOCAL_STATIC_LIBRARIES := libminzip libunz libamend libmtdutils libmincrypt
LOCAL_STATIC_LIBRARIES += libminui libpixelflinger_static libcutils LOCAL_STATIC_LIBRARIES += libminui libpixelflinger_static libpng libcutils
LOCAL_STATIC_LIBRARIES += libstdc++ libc LOCAL_STATIC_LIBRARIES += libstdc++ libc
# Specify a C-includable file containing the OTA public keys. # Specify a C-includable file containing the OTA public keys.

View file

@ -29,97 +29,84 @@
#include <pixelflinger/pixelflinger.h> #include <pixelflinger/pixelflinger.h>
#include <png.h>
#include "minui.h" #include "minui.h"
// File signature for BMP files. // libpng gives "undefined reference to 'pow'" errors, and I have no
// The letters 'BM' as a little-endian unsigned short. // idea how to convince the build system to link with -lm. We don't
// need this functionality (it's used for gamma adjustment) so provide
#define BMP_SIGNATURE 0x4d42 // a dummy implementation to satisfy the linker.
double pow(double x, double y) {
typedef struct { return x;
// constant, value should equal BMP_SIGNATURE }
unsigned short bfType;
// size of the file in bytes.
unsigned long bfSize;
// must always be set to zero.
unsigned short bfReserved1;
// must always be set to zero.
unsigned short bfReserved2;
// offset from the beginning of the file to the bitmap data.
unsigned long bfOffBits;
// The BITMAPINFOHEADER:
// size of the BITMAPINFOHEADER structure, in bytes.
unsigned long biSize;
// width of the image, in pixels.
unsigned long biWidth;
// height of the image, in pixels.
unsigned long biHeight;
// number of planes of the target device, must be set to 1.
unsigned short biPlanes;
// number of bits per pixel.
unsigned short biBitCount;
// type of compression, zero means no compression.
unsigned long biCompression;
// size of the image data, in bytes. If there is no compression,
// it is valid to set this member to zero.
unsigned long biSizeImage;
// horizontal pixels per meter on the designated targer device,
// usually set to zero.
unsigned long biXPelsPerMeter;
// vertical pixels per meter on the designated targer device,
// usually set to zero.
unsigned long biYPelsPerMeter;
// number of colors used in the bitmap, if set to zero the
// number of colors is calculated using the biBitCount member.
unsigned long biClrUsed;
// number of color that are 'important' for the bitmap,
// if set to zero, all colors are important.
unsigned long biClrImportant;
} __attribute__((packed)) BitMapFileHeader;
int res_create_surface(const char* name, gr_surface* pSurface) { int res_create_surface(const char* name, gr_surface* pSurface) {
char resPath[256]; char resPath[256];
BitMapFileHeader header;
GGLSurface* surface = NULL; GGLSurface* surface = NULL;
int result = 0; int result = 0;
unsigned char header[8];
snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.bmp", name); png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
resPath[sizeof(resPath)-1] = '\0'; resPath[sizeof(resPath)-1] = '\0';
int fd = open(resPath, O_RDONLY); FILE* fp = fopen(resPath, "rb");
if (fd == -1) { if (fp == NULL) {
result = -1; result = -1;
goto exit; goto exit;
} }
size_t bytesRead = read(fd, &header, sizeof(header));
size_t bytesRead = fread(header, 1, sizeof(header), fp);
if (bytesRead != sizeof(header)) { if (bytesRead != sizeof(header)) {
result = -2; result = -2;
goto exit; goto exit;
} }
if (header.bfType != BMP_SIGNATURE) {
result = -3; // Not a legal header if (png_sig_cmp(header, 0, sizeof(header))) {
result = -3;
goto exit; goto exit;
} }
if (header.biPlanes != 1) {
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
result = -4; result = -4;
goto exit; goto exit;
} }
if (!(header.biBitCount == 24 || header.biBitCount == 32)) {
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
result = -5; result = -5;
goto exit; goto exit;
} }
if (header.biCompression != 0) {
if (setjmp(png_jmpbuf(png_ptr))) {
result = -6; result = -6;
goto exit; goto exit;
} }
size_t width = header.biWidth;
size_t height = header.biHeight; png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, sizeof(header));
png_read_info(png_ptr, info_ptr);
size_t width = info_ptr->width;
size_t height = info_ptr->height;
size_t stride = 4 * width; size_t stride = 4 * width;
size_t pixelSize = stride * height; size_t pixelSize = stride * height;
int color_type = info_ptr->color_type;
int bit_depth = info_ptr->bit_depth;
int channels = info_ptr->channels;
if (bit_depth != 8 || (channels != 3 && channels != 4) ||
(color_type != PNG_COLOR_TYPE_RGB &&
color_type != PNG_COLOR_TYPE_RGBA)) {
return -7;
goto exit;
}
surface = malloc(sizeof(GGLSurface) + pixelSize); surface = malloc(sizeof(GGLSurface) + pixelSize);
if (surface == NULL) { if (surface == NULL) {
result = -7; result = -8;
goto exit; goto exit;
} }
unsigned char* pData = (unsigned char*) (surface + 1); unsigned char* pData = (unsigned char*) (surface + 1);
@ -128,63 +115,43 @@ int res_create_surface(const char* name, gr_surface* pSurface) {
surface->height = height; surface->height = height;
surface->stride = width; /* Yes, pixels, not bytes */ surface->stride = width; /* Yes, pixels, not bytes */
surface->data = pData; surface->data = pData;
surface->format = (header.biBitCount == 24) ? surface->format = (channels == 3) ?
GGL_PIXEL_FORMAT_RGBX_8888 : GGL_PIXEL_FORMAT_RGBA_8888; GGL_PIXEL_FORMAT_RGBX_8888 : GGL_PIXEL_FORMAT_RGBA_8888;
// Source pixel bytes are stored B G R {A} int y;
if (channels == 3) {
lseek(fd, header.bfOffBits, SEEK_SET); for (y = 0; y < height; ++y) {
size_t y; unsigned char* pRow = pData + y * stride;
if (header.biBitCount == 24) { // RGB png_read_row(png_ptr, pRow, NULL);
size_t inputStride = (((3 * width + 3) >> 2) << 2);
for (y = 0; y < height; y++) {
unsigned char* pRow = pData + (height - (y + 1)) * stride;
bytesRead = read(fd, pRow, inputStride);
if (bytesRead != inputStride) {
result = -8;
goto exit;
}
int x; int x;
for(x = width - 1; x >= 0; x--) { for(x = width - 1; x >= 0; x--) {
int sx = x * 3; int sx = x * 3;
int dx = x * 4; int dx = x * 4;
unsigned char b = pRow[sx]; unsigned char r = pRow[sx];
unsigned char g = pRow[sx + 1]; unsigned char g = pRow[sx + 1];
unsigned char r = pRow[sx + 2]; unsigned char b = pRow[sx + 2];
unsigned char a = 0xff; unsigned char a = 0xff;
pRow[dx ] = r; // r pRow[dx ] = r; // r
pRow[dx + 1] = g; // g pRow[dx + 1] = g; // g
pRow[dx + 2] = b; // b; pRow[dx + 2] = b; // b
pRow[dx + 3] = a; pRow[dx + 3] = a;
} }
} }
} else { // RGBA } else {
for (y = 0; y < height; y++) { for (y = 0; y < height; ++y) {
unsigned char* pRow = pData + (height - (y + 1)) * stride; unsigned char* pRow = pData + y * stride;
bytesRead = read(fd, pRow, stride); png_read_row(png_ptr, pRow, NULL);
if (bytesRead != stride) {
result = -9;
goto exit;
}
size_t x;
for(x = 0; x < width; x++) {
size_t xx = x * 4;
unsigned char b = pRow[xx];
unsigned char g = pRow[xx + 1];
unsigned char r = pRow[xx + 2];
unsigned char a = pRow[xx + 3];
pRow[xx ] = r;
pRow[xx + 1] = g;
pRow[xx + 2] = b;
pRow[xx + 3] = a;
}
} }
} }
*pSurface = (gr_surface) surface; *pSurface = (gr_surface) surface;
exit: exit:
if (fd >= 0) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
close(fd);
if (fp != NULL) {
fclose(fp);
} }
if (result < 0) { if (result < 0) {
if (surface) { if (surface) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

BIN
res/images/icon_error.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B