Class Java2DUtils

java.lang.Object
is.galia.processor.Java2DUtils

public final class Java2DUtils extends Object

Collection of methods for operating on BufferedImages.

  • Method Details

    • convertIndexedToARGB

      public static BufferedImage convertIndexedToARGB(BufferedImage inImage)
      Parameters:
      inImage - Image to convert.
      Returns:
      New image of type BufferedImage.TYPE_4BYTE_ABGR, or the input image if it is not indexed.
    • convertCMYKToRGB

      public static BufferedImage convertCMYKToRGB(BufferedImage image) throws IOException
      Parameters:
      image - CMYK image.
      Returns:
      New RGB instance.
      Throws:
      IOException
    • convertCMYKToRGB

      public static BufferedImage convertCMYKToRGB(Raster cmykRaster, ICC_Profile cmykProfile) throws IOException
      Parameters:
      cmykRaster - CMYK image raster.
      cmykProfile - If null, a default CMYK profile will be used.
      Throws:
      IOException
    • convertYCCKToCMYK

      public static void convertYCCKToCMYK(WritableRaster raster)
    • convertToSRGB

      public static BufferedImage convertToSRGB(BufferedImage image, ICC_Profile profile)
      Converts an image to sRGB color space using its embedded ICC profile.
      Parameters:
      image - Image to apply the profile to.
      profile - The image's embedded profile.
      Returns:
      New image with profile applied.
    • crop

      public static BufferedImage crop(BufferedImage inImage, Crop crop, ReductionFactor rf, ScaleConstraint scaleConstraint)

      Crops the given image taking into account a reduction factor. (In other words, the dimensions of the input image have already been halved reductionFactor times but the given region is relative to the full-sized image.

      This method should only be invoked if Crop.hasEffect(Size, OperationList) returns true.

      Parameters:
      inImage - Image to crop.
      crop - Crop operation. Clients should call Operation.hasEffect(Size, OperationList) before invoking.
      rf - Number of times the dimensions of inImage have already been halved relative to the full- sized version.
      scaleConstraint - Scale constraint.
      Returns:
      Cropped image, or the input image if the given region is a no-op. Note that the image is simply a wrapper around the same data buffer.
    • invertColor

      public static void invertColor(WritableRaster raster)
    • newImage

      public static BufferedImage newImage(int width, int height, byte[] samples, ComponentOrder componentOrder)
      Creates a new image backed by the given samples.
      Parameters:
      width - Width of the image.
      height - Height of the image.
      samples - Array of samples (one byte per sample).
      componentOrder - Order of the samples in the given array.
      Returns:
      New image backed by the given samples with no copying.
    • newTestPatternImage

      public static BufferedImage newTestPatternImage(int width, int height, int type)
      Generates a new test pattern image consisting of red, green, blue, and alpha (if supported by the given type) bars of equal width.
      Parameters:
      width - Width.
      height - Height.
      type - One of the BufferedImage.getType() constant values.
      Returns:
      New image.
    • removeAlpha

      public static BufferedImage removeAlpha(BufferedImage inImage, Color bgColor)
      Creates a new image without alpha, paints the given background color into it, draws the RGB channels of the given image into it, and returns it.
      Parameters:
      inImage - Image with alpha.
      Returns:
      Flattened image, or the input image if it has no alpha.
    • removeAlpha

      public static RenderedImage removeAlpha(RenderedImage inImage, Color bgColor)
      Creates a new image without alpha, paints the given background color into it, draws the RGB channels of the given image into it, and returns it.
      Parameters:
      inImage - Image with alpha.
      Returns:
      Flattened image, or the input image if it has no alpha.
    • scale

      public static BufferedImage scale(BufferedImage inImage, Scale scale, ScaleConstraint scaleConstraint, ReductionFactor reductionFactor, boolean isLinear)

      Scales an image, taking an already-applied reduction factor into account. In other words, the dimensions of the input image have already been halved ReductionFactor.factor times but the given scale is relative to the full-sized image.

      If one or both target dimensions would end up being less than three pixels, an empty image (with the correct dimensions) is returned.

      Parameters:
      inImage - Image to scale.
      scale - Requested size ignoring any reduction factor. If no resample filter is set, a default will be used. Operation.hasEffect(Size, OperationList) should be called before invoking.
      scaleConstraint - Scale constraint.
      reductionFactor - Reduction factor that has already been applied to inImage.
      isLinear - Whether the provided image is in a linear color space.
      Returns:
      Scaled image, or the input image if the given arguments would result in a no-op.