The indexed option of the PNG export in the SVG viewer has no effect. This is because KEY_INDEXED is set to 256 while it seems to be expected to be 8 if the number of palette entries should be 256 = 2^8. A value of 256 will be ignored in sources/org/apache/batik/ext/awt/image/codec/png/PNGTranscoderInternalCodecWriteAdapter.java I'll post a simple patch, but the indexed option is still quite unusable because it dithers a white background, even if only one other color is used.
Created attachment 21117 [details] patch
Created attachment 21118 [details] reduced testcase
Created attachment 21119 [details] exported testcase (indexed PNG with patch applied)
Created attachment 21120 [details] real world example (PNG; background is a <rect/> as in the testcase)
The dithering of the white background seems to be a Java bug: http://bugs.sun.com/view_bug.do?bug_id=4258700 I tried to turn dithering off in sources/org/apache/batik/ext/awt/image/rendered/IndexImage.java , but that has no effect because of another Java bug: http://bugs.sun.com/view_bug.do?bug_id=6357416 ~ $ java -version java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-b105, mixed mode)
Created attachment 23423 [details] Patch v2 (In reply to comment #0) > This is because KEY_INDEXED is set to 256 while it seems to be expected > to be 8 if the number of palette entries should be 256 = 2^8. > A value of 256 will be ignored in > sources/org/apache/batik/ext/awt/image/codec/png/PNGTranscoderInternalCodecWriteAdapter.java I've (also) confirmed this in the source code (org.apache.batik.transcoder.image.PNGTranscoder.WriteAdapter#writeImage). The attachment is very similar to the current one, but additionally fixes a few indenting issues and removes some weird "By Jun Inamori" statements (which apparently shouldn't be there) and also some extraneous line breaks. > I'll post a simple patch, but the indexed option is still quite unusable > because it dithers a white background, even if only one other color is used. I haven't tried to improve this behavior...
(In reply to comment #6) > Created an attachment (id=23423) [details] > Patch v2 I haven't stated it but IMO it's ready for review. The changes are tiny and it should be quite safe to apply: it just limits to fix the bug. Nevertheless, it would also be interesting to center the dialog confirming the PNG indexed enabled (although not important in order for this to work). Changing platform to "All" and Batik version to 1.8, as I was able to reproduce in Windows XP SP3 with the trunk version.
I've committed a slightly modified version of the available patch in revision 907280. As stated in comment 6, the (somehow unexpected) dithering with a white background isn't addressed, it just fixes the indexed color option not being functional. FWIW, by taking a look at the documentation [1] and source code [2], it seems like that's the expected behavior... Also, given it's a user interface visible thing, I've added a small note in the CHANGES file. :-) [1] http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/transcoder/image/ImageTranscoder.html#KEY_FORCE_TRANSPARENT_WHITE [2] http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/transcoder/image/PNGTranscoder.java?view=annotate#l98
(In reply to comment #8) > Also, given it's a user interface visible thing, I've added a small note in the > CHANGES file. :-) Removing "NeedsReleaseNote" keyword as the changes were made visible in the commit.