xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Hartle <mhar...@hartle-klug.de>
Subject [PATCH] Bug in JPEGTranscoder, made visible throu Java 1.4.0
Date Sun, 03 Mar 2002 13:54:06 GMT
Hello all,

I have been using Batik 1.1.1 via Cocoon extensively for some while, and 
I am considering Batik to be a really valuable component. After 
switching to Java 1.4.0, the library refused to produce the correct 
images as JPEGs via the JPEGTranscoder. The bug shows whenever there is 
a KEY_BACKGROUND_COLOR hint set and the JPEGTranscoder is used under 
Java 1.4.0, the result is a plain image with the specificed background 
color. I already filed it as a bug at 
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6775

The problem traces back to a seemingly now enforced semantic of Graphics 
and subsequently Graphics2D in Java 1.4.0; according to 
http://java.sun.com/j2se/1.4/docs/api/java/awt/Graphics.html#dispose(), 
after disposing a Graphics object,

> Disposes of this graphics context and releases any system resources 
> that it is using. A |Graphics| object cannot be used after |dispose| 
> has been called.

In org.apache.batik.transcoder.image.ImageTranscoder.transcode(), find 
the following section

            BufferedImage dest = createImage(w, h);

            Graphics2D g2d = GraphicsUtil.createGraphics(dest);
            if (hints.containsKey(KEY_BACKGROUND_COLOR)) {
                Paint bgcolor = (Paint)hints.get(KEY_BACKGROUND_COLOR);
                g2d.setComposite(AlphaComposite.SrcOver);
                g2d.setPaint(bgcolor);
                g2d.fillRect(0, 0, w, h);
                g2d.dispose();
            }
            if (rend != null) { // might be null if the svg document is empty
                g2d.drawRenderedImage(rend, new AffineTransform());
            }
            rend = null; // We're done with it...
            writeImage(dest, output);


and have a look at the g2d.dispose() call and the following call to 
g2d.drawRenderedImage(rend, new AffineTransform()); a move of the 
g2d.dispose() call after the next if-block, looking like this

            BufferedImage dest = createImage(w, h);

            Graphics2D g2d = GraphicsUtil.createGraphics(dest);
            if (hints.containsKey(KEY_BACKGROUND_COLOR)) {
                Paint bgcolor = (Paint)hints.get(KEY_BACKGROUND_COLOR);
                g2d.setComposite(AlphaComposite.SrcOver);
                g2d.setPaint(bgcolor);
                g2d.fillRect(0, 0, w, h);
            }
            if (rend != null) { // might be null if the svg document is empty
                g2d.drawRenderedImage(rend, new AffineTransform());
            }
            g2d.dispose();
            rend = null; // We're done with it...
            writeImage(dest, output);


does the trick; I am now able to use Batik 1.1.1 in Cocoon 2.0.2-dev 
with Tomcat 4.0.1 and Suns JDK 1.4.0 to turn SVG into JPEG images again.

Best regards,

Michael Hartle,
Hartle & Klug GbR


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Mime
View raw message