You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by "David Hägele (Jira)" <ji...@apache.org> on 2019/10/10 15:22:00 UTC

[jira] [Created] (BATIK-1269) AbstractGraphics2D drawImage(img, dx1,dy1,dx2,dy2, sx1,sy1,sx2, sy2, obs) causes RasterFormatException when flipping source coordinates updside down

David Hägele created BATIK-1269:
-----------------------------------

             Summary: AbstractGraphics2D drawImage(img, dx1,dy1,dx2,dy2, sx1,sy1,sx2, sy2, obs) causes RasterFormatException when flipping source coordinates updside down
                 Key: BATIK-1269
                 URL: https://issues.apache.org/jira/browse/BATIK-1269
             Project: Batik
          Issue Type: Bug
          Components: SVGGraphics2D
    Affects Versions: 1.11, 1.10, 1.9, 1.8, 1.7
            Reporter: David Hägele


The AbstractGraphics2D class (org.apache.batik.ext.awt.g2d.AbstractGraphics2D) is extended by SVGGraphics2D and implements the following {{drawImage}} method which allows to specify start and end corners of a rectangle in the destination space as well as within the image source:

{{public boolean drawImage(}}{{Image img,}}
 {{   int dx1, int dy1, int dx2, int dy2,}}
 {{   int sx1, int sy1, int sx2, int sy2,}}
 {{   ImageObserver observer)}}

The implementation uses the BufferedImage.getSubimage() method to extract the specified source pixels, See here: [github src|https://github.com/apache/xmlgraphics-batik/blob/9de3c8ea26ad7b91fec1ea00eac39236e000cfdb/batik-awt-util/src/main/java/org/apache/batik/ext/awt/g2d/AbstractGraphics2D.java#L774]. This causes a RasterFormatException in case the specified source rectangle is not from upper left corner to lower right corner but for example upside down (e.g. in order to flip the image).

 

Also the implementation assumes that the destination coordinates are from top left to bottom right as well, which may not be the case and results in the image not appearing in the dom.

 

Here is a proposal for a fix:

 

{{public boolean drawImage(Image img,}}
{{   int dx1, int dy1, int dx2, int dy2,}}
{{   int sx1, int sy1, int sx2, int sy2,}}
{{   ImageObserver observer)}}
{{ {}}

{{  if(dx2 < dx1){}}

{{    return drawImage(img, }}
{{    dx2, dy1, dx1, dy2,}}
{{    sx2, sy1, sx1, sy2,}}
{{    observer);}}
{{  }}}
{{  if(dy2 < dy1){}}
{{    return drawImage(img, }}
{{    dx1, dy2, dx2, dy1,}}
{{    sx1, sy2, sx2, sy1,}}
{{    observer);}}
{{  }}}

{{  int srcW = Math.abs(sx2-sx1);}}
{{  int srcH = Math.abs(sy2-sy1);}}
{{  BufferedImage src = new BufferedImage(srcW, srcH, BufferedImage.TYPE_INT_ARGB);}}
{{  Graphics2D g = src.createGraphics();}}
{{  g.drawImage(img, 0,0, srcW,srcH, sx1,sy1, sx2,sy2, null);}}
{{  g.dispose();}}

{{  return drawImage(src, dx1, dy1, dx2-dx1, dy2-dy1, observer);}}
{{ }}}

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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