Me again,

I should first try then talk. I managed to get the results I wanted but there are some small issues.

(a) it might be better to use transcoding hints instead of the extra contructor. If I understand the code right it would be consistent to set a mapping from something like KEY_PNG_ENCODING_PARAMETERS to the parameter object.
(b) there is actually a KEY_GAMMA used in the code. It just doesn't work since the transcoder always declares sRGB as intentional and that has the consequence of turning gamma on. Somehow this combination of offering KEY_GAMMA as hint and _always_ assuming sRGB is intentional seems inconsistent to me


Apart from these two potential issues I found a solution that works for me and shouldn't hurt anyone else. Here is the diff -- it looks bigger than it is since I moved a chunk of code into an if-statement, thus increasing indentation:

=========================
Index: PNGTranscoder.java
===================================================================
RCS file: /home/cvspublic/xml-batik/sources/org/apache/batik/transcoder/image/PNGTranscoder.java,v
retrieving revision 1.18
diff -u -r1.18 PNGTranscoder.java
--- PNGTranscoder.java 8 Aug 2003 11:39:25 -0000 1.18
+++ PNGTranscoder.java 12 Sep 2003 12:45:43 -0000
@@ -73,6 +73,10 @@
* @version $Id: PNGTranscoder.java,v 1.18 2003/08/08 11:39:25 vhardy Exp $
*/
public class PNGTranscoder extends ImageTranscoder {
+ /**
+ * Stores the encoding parameters if fixed parameters are used.
+ */
+ private PNGEncodeParam encodeParams = null;


/**
* Constructs a new transcoder that produces png images.
@@ -80,6 +84,14 @@
public PNGTranscoder() {
hints.put(KEY_FORCE_TRANSPARENT_WHITE, Boolean.FALSE);
}
+ + /**
+ * Constructs a transcoder using a fixed parameter set.
+ */
+ public PNGTranscoder(PNGEncodeParam parameters) {
+ this();
+ this.encodeParams = parameters;
+ }


    /**
     * Creates a new ARGB image with the specified dimension.
@@ -155,26 +167,32 @@
                img = IndexImage.getIndexedImage(img,1<<n);
        }

-        PNGEncodeParam params = PNGEncodeParam.getDefaultEncodeParam(img);
-        if (params instanceof PNGEncodeParam.RGB) {
-            ((PNGEncodeParam.RGB)params).setBackgroundRGB
-                (new int [] { 255, 255, 255 });
-        }
+        PNGEncodeParam params;
+        if(this.encodeParams == null) {
+            params = PNGEncodeParam.getDefaultEncodeParam(img);
+
+            if (params instanceof PNGEncodeParam.RGB) {
+                ((PNGEncodeParam.RGB)params).setBackgroundRGB
+                    (new int [] { 255, 255, 255 });
+            }

- // If they specify GAMMA key then use it otherwise don't
- // write a gAMA chunk, (default Gamma=2.2).
- if (hints.containsKey(KEY_GAMMA)) {
- params.setGamma(((Float)hints.get(KEY_GAMMA)).floatValue());
- }
-
- // We always want an sRGB chunk and Our encoding intent is
- // perceptual
- params.setSRGBIntent(PNGEncodeParam.INTENT_PERCEPTUAL);
-
- float PixSzMM = userAgent.getPixelUnitToMillimeter();
- // num Pixs in 1 Meter
- int numPix = (int)((1000/PixSzMM)+0.5);
- params.setPhysicalDimension(numPix, numPix, 1); // 1 means 'pix/meter'
+ // If they specify GAMMA key then use it otherwise don't
+ // write a gAMA chunk, (default Gamma=2.2).
+ if (hints.containsKey(KEY_GAMMA)) {
+ params.setGamma(((Float)hints.get(KEY_GAMMA)).floatValue());
+ }
+
+ // We always want an sRGB chunk and Our encoding intent is
+ // perceptual
+ params.setSRGBIntent(PNGEncodeParam.INTENT_PERCEPTUAL);
+
+ float PixSzMM = userAgent.getPixelUnitToMillimeter();
+ // num Pixs in 1 Meter
+ int numPix = (int)((1000/PixSzMM)+0.5);
+ params.setPhysicalDimension(numPix, numPix, 1); // 1 means 'pix/meter'
+ } else {
+ params = this.encodeParams;
+ }


try {
PNGImageEncoder pngEncoder = new PNGImageEncoder(ostream, params);
======================================


I'm happy to adjust this in case you don't like it.

Peter



Peter Becker wrote:

[was: Re: Text rendering changes after upgrade to 1.5]

Thomas DeWeese wrote:

[...]

BTW: it still seems the gamma problem I have is still around. If you look at http://tockit.sf.net with Internet Explorer you will notice that the navigation PNGs are of a slightly different colour than the surrounding bits and pieces. I tracked that down once to the gamma value in the PNGs which seems to be ignored by most software but IE (e.g. the site looks good in Mozilla). Is there any new insight on how to avoid that problem?



From what you have said so far I would say it is a bug in what ever
other software you used to generate PNG files that they do not include
a gama chunk. You could hack Batik so it doesn't generate one but I
don't think this would be the right approach to take.



Hmmm... look at this page in IE: http://www.itee.uq.edu.au/~pbecker/batik/testColor.html


This is the Batik-rendered PNG on top of HTML background with exactly the same RGB values. And it is clearly rendered differently while Mozilla produces the same color. As does Adobe's viewer from the SVG.



If you think that Batik should remove the Gama chunk from the PNG files
that it creates than I strongly disagree, quoting from the PNG specification:


        If the encoder does not know the image's gamma value,
        it should not write a gAMA chunk; the absence of a gAMA
        chunk indicates that the gamma is unknown.

  In this case we know exactly what the gAMA is (all SVG output is
in standard sRGB colorspace with a gama of 2.2) so we provide that
information as the PNG standard says we should.

There was a bug reported that Batik produces a gamma value that is
off by one code value. I put in the code to fix this but didn't
'turn it on' because it causes all our test images to fail compairison
and it was a bad time to do that. However you might try turning that
on, xml-batik/sources/org/apache/batik/ext/awt/image/codec/PNGImageEncoder.java


line 556. This should not produce a visably different result, but
perhaps it does in IE. I would be interested in knowing if this fixes it.


  There is also a gamma transcoding hint that you could try using.
See batik.transcoder.image.PNGTranscoder line 214.  This is not
currently exposed from the application.

  Aside from those options if you actually want to remove the generation
of Gamma chunks for Batik you will have to hack it yourself (it is not
something I will spend time on).  If done well (i.e. made a comand line
parameter etc, and you are willing to sign a contributors agreement) it
would probably be accepted into Batik.


Hi Thomas,

I had a look at the code and so far I am up to this:

- org.apache.batik.ext.awt.image.codec.PNGEncodeParam does include the information on the gAMA value to use and if any is to use at all
- but in org.apache.batik.transcoder.image.PNGTranscoder, line 158 an instance of this class is create by a factory method getDefaultEncodeParam(Image), which is then used for the PNGImageEncoder


What I'd tend to do if this would be my code and I would be sure I grok it would be having a second constructor on the transcoder class that takes an intialized parameter object and stores it as member. A transcoder created this way would use the given parameters instead of the default ones. The major drawback of this approach is that the transcoder created would be insensitive to the image processed -- as opposed to the default version. But it seems reasonable to assume that if the caller created a particular parameter setting they know what they are doing.

Another option would be having a boolean member to toggle just the gAMA. More specific, but it would keep the sensitivity for the color depth. I don't know if there are other things one might want to tweak in the params object.

I'd tend to the first version: add member of PNGEncodeParam, add second constructor to set it and behave as before if member is null.

Comments? Shall I just try and send a patch if it works for me? Any prefered patch format?

Peter


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to