diff options
author | 2009-07-07 19:38:01 +0000 | |
---|---|---|
committer | 2009-07-07 19:38:01 +0000 | |
commit | 6189877c50166f58f09c6583a9aa37c735310779 (patch) | |
tree | 1c9c6506273c156da843fee2135905727506965e /src/images | |
parent | 3d06a8c38d1f629a3a012c20395e425c4fca5cf3 (diff) |
add support for encoding Index8 bitmaps into png
git-svn-id: http://skia.googlecode.com/svn/trunk@254 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images')
-rw-r--r-- | src/images/SkImageDecoder_libpng.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index 9c0b48d98f..81e73ef854 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -768,16 +768,17 @@ bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); -#if 0 // need to support this some day - /* set the palette if there is one. REQUIRED for indexed-color images */ - palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH - * png_sizeof (png_color)); - /* ... set palette colors ... */ - png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); - /* You must not free palette here, because png_set_PLTE only makes a link to - the palette that you malloced. Wait until you are about to destroy - the png structure. */ -#endif + // set our colortable/trans arrays if needed + png_color paletteColors[256]; + png_byte trans[256]; + if (SkBitmap::kIndex8_Config == config) { + SkColorTable* ct = bitmap.getColorTable(); + int numTrans = pack_palette(ct, paletteColors, trans, hasAlpha); + png_set_PLTE(png_ptr, info_ptr, paletteColors, ct->count()); + if (numTrans > 0) { + png_set_tRNS(png_ptr, info_ptr, trans, numTrans, NULL); + } + } png_set_sBIT(png_ptr, info_ptr, &sig_bit); png_write_info(png_ptr, info_ptr); |