NegativeArraySizeException from AffineTransformOp with shear

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P4
    • 26
    • Component/s: client-libs
    • None
    • 2d
    • behavioral
    • low
    • Hide
      Currently the app gets NegativeArraySizeException which potentially breaks rendering, so no longer getting an exception seems like an improvement.

      Falling back to the source image size is not so unusual since if an app supplies a destination it likely may use the same size anyway. This also allows rendering to happen without exceptions.

      AffineTransformOp.createCompatibleDestImage() and AffineTransformOp.createCompatibleDestRaster() will already throw exceptions, it is now just consistenty RasterFormatException.

      Note all of these are RuntimeExceptions.
      Show
      Currently the app gets NegativeArraySizeException which potentially breaks rendering, so no longer getting an exception seems like an improvement. Falling back to the source image size is not so unusual since if an app supplies a destination it likely may use the same size anyway. This also allows rendering to happen without exceptions. AffineTransformOp.createCompatibleDestImage() and AffineTransformOp.createCompatibleDestRaster() will already throw exceptions, it is now just consistenty RasterFormatException. Note all of these are RuntimeExceptions.
    • 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)
      
      

            Assignee:
            Philip Race
            Reporter:
            Ranjith Mandala (Inactive)
            Jayathirth D V, Prasanta Sadhukhan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: