Bug 43847 - [PATCH] PNG export: indexed option doesn't work
Summary: [PATCH] PNG export: indexed option doesn't work
Status: RESOLVED FIXED
Alias: None
Product: Batik - Now in Jira
Classification: Unclassified
Component: SVG Viewer (show other bugs)
Version: 1.8
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Batik Developer's Mailing list
URL:
Keywords: NeedsReleaseNote, PatchAvailable
Depends on:
Blocks:
 
Reported: 2007-11-12 11:41 UTC by x00000000
Modified: 2010-08-17 09:39 UTC (History)
0 users



Attachments
patch (617 bytes, patch)
2007-11-12 11:42 UTC, x00000000
Details | Diff
reduced testcase (222 bytes, image/svg+xml)
2007-11-12 11:44 UTC, x00000000
Details
exported testcase (indexed PNG with patch applied) (1.35 KB, image/png)
2007-11-12 11:45 UTC, x00000000
Details
real world example (PNG; background is a <rect/> as in the testcase) (27.02 KB, image/png)
2007-11-12 11:48 UTC, x00000000
Details
Patch v2 (2.12 KB, patch)
2009-03-27 10:28 UTC, Helder Magalhães
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description x00000000 2007-11-12 11:41:42 UTC
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.
Comment 1 x00000000 2007-11-12 11:42:22 UTC
Created attachment 21117 [details]
patch
Comment 2 x00000000 2007-11-12 11:44:01 UTC
Created attachment 21118 [details]
reduced testcase
Comment 3 x00000000 2007-11-12 11:45:02 UTC
Created attachment 21119 [details]
exported testcase (indexed PNG with patch applied)
Comment 4 x00000000 2007-11-12 11:48:49 UTC
Created attachment 21120 [details]
real world example (PNG; background is a <rect/> as in the testcase)
Comment 5 x00000000 2007-11-12 17:39:58 UTC
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)
Comment 6 Helder Magalhães 2009-03-27 10:28:56 UTC
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...
Comment 7 Helder Magalhães 2009-03-30 03:19:31 UTC
(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.
Comment 8 Helder Magalhães 2010-02-06 11:18:19 UTC
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
Comment 9 Helder Magalhães 2010-08-17 09:39:55 UTC
(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.