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

"Simon Steiner (Jira)" <[email protected]> Fri, 18 Oct 2019 08:48:00 +0000 (UTC)
Newsgroups gmane.text.xml.batik.devel
Message-ID <[email protected]>
     [ https://issues.apache.org/jira/browse/BATIK-1269?page=3Dcom.atlassia=
n.jira.plugin.system.issuetabpanels:all-tabpanel ]

Simon Steiner updated BATIK-1269:
---------------------------------
    Summary: [PATCH] AbstractGraphics2D drawImage(img, dx1,dy1,dx2,dy2, sx1=
,sy1,sx2, sy2, obs) causes RasterFormatException when flipping source coord=
inates updside down  (was: AbstractGraphics2D drawImage(img, dx1,dy1,dx2,dy=
2, sx1,sy1,sx2, sy2, obs) causes RasterFormatException when flipping source=
 coordinates updside down)

> [PATCH] AbstractGraphics2D drawImage(img, dx1,dy1,dx2,dy2, sx1,sy1,sx2, s=
y2, obs) causes RasterFormatException when flipping source coordinates upds=
ide down
> -------------------------------------------------------------------------=
---------------------------------------------------------------------------=
--------
>
>                 Key: BATIK-1269
>                 URL: https://issues.apache.org/jira/browse/BATIK-1269
>             Project: Batik
>          Issue Type: Bug
>          Components: SVGGraphics2D
>    Affects Versions: 1.7, 1.8, 1.9, 1.10, 1.11
>            Reporter: David H=C3=A4gele
>            Priority: Major
>         Attachments: AbstractGraphics2D.diff, AbstractGraphics2D.diff
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The AbstractGraphics2D class (org.apache.batik.ext.awt.g2d.AbstractGraphi=
cs2D) is extended by SVGGraphics2D and implements the following {{drawImage=
}} method which allows to specify start and end corners of a rectangle in t=
he destination space as well as within the image source:
> {{public boolean drawImage(}}{{Image img,}}
>  {{=C2=A0=C2=A0 int dx1, int dy1, int dx2, int dy2,}}
>  {{=C2=A0=C2=A0 int sx1, int sy1, int sx2, int sy2,}}
>  {{=C2=A0=C2=A0 ImageObserver observer)}}
> The implementation uses the BufferedImage.getSubimage() method to extract=
 the specified source pixels, See here: [github src|https://github.com/apac=
he/xmlgraphics-batik/blob/9de3c8ea26ad7b91fec1ea00eac39236e000cfdb/batik-aw=
t-util/src/main/java/org/apache/batik/ext/awt/g2d/AbstractGraphics2D.java#L=
774]. This causes a=C2=A0RasterFormatException in case the specified source=
 rectangle is not from upper left corner to lower right corner but for exam=
ple upside down (e.g. in order to flip the image).
> =C2=A0
> 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.
> =C2=A0
> Here is a proposal for a fix:
> =C2=A0
> {{public boolean drawImage(Image img,}}
> {{=C2=A0=C2=A0 int dx1, int dy1, int dx2, int dy2,}}
> {{=C2=A0=C2=A0 int sx1, int sy1, int sx2, int sy2,}}
> {{=C2=A0=C2=A0 ImageObserver observer)}}
> {{ {}}
> {{=C2=A0 if(dx2 < dx1){}}
> {{=C2=A0=C2=A0=C2=A0 return drawImage(img, }}
> {{=C2=A0=C2=A0=C2=A0 dx2, dy1, dx1, dy2,}}
> {{=C2=A0=C2=A0=C2=A0 sx2, sy1, sx1, sy2,}}
> {{=C2=A0=C2=A0=C2=A0 observer);}}
> {{=C2=A0 }}}
> {{=C2=A0 if(dy2 < dy1){}}
> {{=C2=A0=C2=A0=C2=A0 return drawImage(img, }}
> {{=C2=A0=C2=A0=C2=A0 dx1, dy2, dx2, dy1,}}
> {{=C2=A0=C2=A0=C2=A0 sx1, sy2, sx2, sy1,}}
> {{=C2=A0=C2=A0=C2=A0 observer);}}
> {{=C2=A0 }}}
> {{=C2=A0 int srcW =3D Math.abs(sx2-sx1);}}
> {{=C2=A0 int srcH =3D Math.abs(sy2-sy1);}}
> {{=C2=A0 BufferedImage src =3D new BufferedImage(srcW, srcH, BufferedImag=
e.TYPE_INT_ARGB);}}
> {{=C2=A0 Graphics2D g =3D src.createGraphics();}}
> {{=C2=A0 g.drawImage(img, 0,0, srcW,srcH, sx1,sy1, sx2,sy2, null);}}
> {{=C2=A0 g.dispose();}}
> {{=C2=A0 return drawImage(src, dx1, dy1, dx2-dx1, dy2-dy1, observer);}}
> {{ }}}
> =C2=A0



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