From 42324623c88a68fd689a4c0294f14936adebf0ef Mon Sep 17 00:00:00 2001 From: avolkov Date: Tue, 8 Feb 2005 22:31:55 +0000 Subject: [PATCH] Transparency fixed git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1524 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/ani/unani.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/ani/unani.c b/tools/ani/unani.c index c9bcdcb74..c1a0452d3 100644 --- a/tools/ani/unani.c +++ b/tools/ani/unani.c @@ -595,11 +595,16 @@ writePacked(const char *filename, const frame_desc *f, sig_bit.blue = 8; png_set_sBIT(png_ptr, info_ptr, &sig_bit); png_set_PLTE(png_ptr, info_ptr, palettes[f->plut], 256); - if (transparentPixel >= 0) { + if (transparentPixel >= 0) + { // generate transparency chunk + // for indexed PNGs, tRNS chunk contains an array of + // alpha values corresponding to palette entries png_byte trans[256]; - memset(trans, 0x0, 256 * sizeof (png_byte)); - trans[transparentPixel] = 0xff; - png_set_tRNS(png_ptr, info_ptr, trans, 1, NULL); + // set all palette alpha values to 0xff (fully opaque) initially + memset(trans, 0xff, 256 * sizeof (png_byte)); + trans[transparentPixel] = 0; // the only one + // only need to write out upto and including transparentPixel + png_set_tRNS(png_ptr, info_ptr, trans, transparentPixel + 1, NULL); } png_write_info(png_ptr, info_ptr); png_write_image(png_ptr, (png_byte **) lines);