add support for encoding Index8 bitmaps into png

git-svn-id: http://skia.googlecode.com/svn/trunk@254 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2009-07-07 19:38:01 +00:00
parent 3d06a8c38d
commit 6189877c50

View File

@ -768,16 +768,17 @@ bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE); PNG_FILTER_TYPE_BASE);
#if 0 // need to support this some day // set our colortable/trans arrays if needed
/* set the palette if there is one. REQUIRED for indexed-color images */ png_color paletteColors[256];
palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH png_byte trans[256];
* png_sizeof (png_color)); if (SkBitmap::kIndex8_Config == config) {
/* ... set palette colors ... */ SkColorTable* ct = bitmap.getColorTable();
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); int numTrans = pack_palette(ct, paletteColors, trans, hasAlpha);
/* You must not free palette here, because png_set_PLTE only makes a link to png_set_PLTE(png_ptr, info_ptr, paletteColors, ct->count());
the palette that you malloced. Wait until you are about to destroy if (numTrans > 0) {
the png structure. */ png_set_tRNS(png_ptr, info_ptr, trans, numTrans, NULL);
#endif }
}
png_set_sBIT(png_ptr, info_ptr, &sig_bit); png_set_sBIT(png_ptr, info_ptr, &sig_bit);
png_write_info(png_ptr, info_ptr); png_write_info(png_ptr, info_ptr);