-
Type:
CSR
-
Resolution: Unresolved
-
Priority:
P4
-
Component/s: client-libs
-
None
-
behavioral
-
low
-
-
Java API
-
SE
Summary
If AffineTransformOp.filter cannot create a destination raster or image which is too large to be created it will instead create one the size of the source. AffineTransformOp.createCompatibleDestImage() and AffineTransformOp.createCompatibleDestRaster() will however throw RasterFormatException in such a case.
Problem
AffineTransformOp applies a transform to a source image or raster and renders it to a destination. Optionally null can be passed as the destination in which case the implementation will create a destination. In this case it will attempt to create an image or raster corresponding to the transform of this op. For example suppose the transform is a scale of 50_000 in both x and y applied to a 1_000 x 1_000 source image, this clearly would require a huge destination image and that cannot be created. Currently the implementation will typically throw NegativeArraySizeException in such a case, which itself indicates a problem.
Solution
Detect such a scenario and fall back to creating a destination the same size as the source. Specify on AffineTransformOp.createCompatibleDestImage() and AffineTransformOp.createCompatibleDestRaster() that they throw RasterFormatException if the transformed size is too large. Apps can call these to determine if the filter operation would be able to create a destination and in fact can use the result directly.
Specification
class java.awt.image.AffineTransformOp
+ * If {@code dst} is {@code null} and a destination {code BufferedImage}
+ * with the transformed dimensions cannot be created, the {@code src}
+ * dimensions may be substituted.
public final BufferedImage filter(BufferedImage src, BufferedImage dst)
+ * If {@code dst} is {@code null} and a destination {code Raster}
+ * with the transformed dimensions cannot be created, the {@code src}
+ * dimensions may be substituted.
public final WritableRaster filter(Raster src, WritableRaster dst)
/**
* Creates a zeroed destination image with the correct size and number of
* bands. A {@code RasterFormatException} may be thrown if the
- * transformed width or height is equal to 0.
+ * transformed width or height is less than or equal to 0, or too large.
public BufferedImage createCompatibleDestImage (BufferedImage src, ColorModel destCM)
/**
* Creates a zeroed destination {@code Raster} with the correct size
* and number of bands. A {@code RasterFormatException} may be thrown
- * if the transformed width or height is equal to 0.
+ * if the transformed width or height is less than or equal to 0, or too large.
public WritableRaster createCompatibleDestRaster (Raster src)
- csr of
-
JDK-4690476 NegativeArraySizeException from AffineTransformOp with shear
-
- Open
-