loci.formats.gui

## Class AWTImageTools

- java.lang.Object
- - loci.formats.gui.AWTImageTools

-     public final class AWTImageTools
      extends java.lang.Object

  A utility class with convenience methods for manipulating images in `BufferedImage` form. To work with images in primitive array form, use the `ImageTools` class. Much code was stolen and adapted from DrLaszloJamf's posts on the Java forums.
  Author:
    Curtis Rueden ctrueden at wisc.edu

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static org.slf4j.Logger` | `LOGGER`
    `protected static java.awt.Component` | `OBS` ImageObserver for working with AWT images.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `private` | `AWTImageTools()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.awt.image.BufferedImage` | `autoscale(java.awt.image.BufferedImage img)` Perform autoscaling on the given BufferedImage.
    `static java.awt.image.BufferedImage` | `autoscale(java.awt.image.BufferedImage img, int min, int max)` Perform autoscaling on the given BufferedImage; map min to 0 and max to 255.
    `static java.awt.image.BufferedImage` | `blankImage(int w, int h, int c, int type)` Creates a blank image with the given dimensions and transfer type.
    `private static boolean` | `canUseBankDataDirectly(java.awt.image.WritableRaster r, int transferType, java.lang.Class<? extends java.awt.image.DataBuffer> dataBufferClass)` Whether we can return the data buffer's bank data without performing any copy or conversion operations.
    `static java.awt.image.BufferedImage` | `constructImage(int c, int type, int w, int h, boolean interleaved, boolean banded, java.awt.image.DataBuffer buffer)` Creates an image with the given DataBuffer.
    `static java.awt.image.BufferedImage` | `constructImage(int c, int type, int w, int h, boolean interleaved, boolean banded, java.awt.image.DataBuffer buffer, java.awt.image.ColorModel colorModel)` Creates an image with the given DataBuffer.
    `static java.awt.image.BufferedImage` | `convertRenderedImage(java.awt.image.RenderedImage img)` Converts a java.awt.image.RenderedImage into a java.awt.image.BufferedImage.
    `static java.awt.image.BufferedImage` | `copyScaled(java.awt.image.BufferedImage source, java.awt.image.BufferedImage target, java.lang.Object hint)` Copies the source image into the target, applying scaling.
    `static byte[][]` | `get8BitLookupTable(java.awt.image.ColorModel model)` Converts an IndexColorModel to a 2D byte array.
    `static byte[][]` | `getBytes(java.awt.image.BufferedImage image)` Extracts pixel data as arrays of unsigned bytes, one per channel.
    `static byte[]` | `getBytes(java.awt.image.BufferedImage img, boolean separated)` Get the bytes from an image, merging the channels as necessary.
    `static byte[][]` | `getBytes(java.awt.image.WritableRaster r)` Extracts pixel data as arrays of unsigned bytes, one per channel.
    `static byte[][]` | `getBytes(java.awt.image.WritableRaster r, int x, int y, int w, int h)` Extracts pixel data as arrays of unsigned bytes, one per channel.
    `static java.awt.GraphicsConfiguration` | `getDefaultConfiguration()` Gets the default graphics configuration for the environment.
    `static double[][]` | `getDoubles(java.awt.image.BufferedImage image)` Extracts pixel data as arrays of doubles, one per channel.
    `static double[][]` | `getDoubles(java.awt.image.WritableRaster r)` Extracts pixel data as arrays of doubles, one per channel.
    `static double[][]` | `getDoubles(java.awt.image.WritableRaster r, int x, int y, int w, int h)` Extracts pixel data as arrays of doubles, one per channel.
    `static float[][]` | `getFloats(java.awt.image.BufferedImage image)` Extracts pixel data as arrays of floats, one per channel.
    `static float[][]` | `getFloats(java.awt.image.WritableRaster r)` Extracts pixel data as arrays of floats, one per channel.
    `static float[][]` | `getFloats(java.awt.image.WritableRaster r, int x, int y, int w, int h)` Extracts pixel data as arrays of floats, one per channel.
    `static int[][]` | `getInts(java.awt.image.BufferedImage image)` Extracts pixel data as arrays of signed integers, one per channel.
    `static int[][]` | `getInts(java.awt.image.WritableRaster r)` Extracts pixel data as arrays of signed integers, one per channel.
    `static int[][]` | `getInts(java.awt.image.WritableRaster r, int x, int y, int w, int h)` Extracts pixel data as arrays of signed integers, one per channel.
    `static short[][]` | `getLookupTable(java.awt.image.ColorModel model)` Convers an Index16ColorModel to a 2D short array.
    `static byte[][]` | `getPixelBytes(java.awt.image.BufferedImage img, boolean little)` Return a 2D array of bytes representing the image.
    `static byte[][]` | `getPixelBytes(java.awt.image.BufferedImage img, boolean little, int x, int y, int w, int h)` Return a 2D array of bytes representing the image.
    `static byte[][]` | `getPixelBytes(java.awt.image.WritableRaster r, boolean little)` Return a 2D array of bytes representing the image.
    `static byte[][]` | `getPixelBytes(java.awt.image.WritableRaster r, boolean little, int x, int y, int w, int h)` Return a 2D array of bytes representing the image.
    `static java.lang.Object` | `getPixels(java.awt.image.BufferedImage image)` Gets the image's pixel data as arrays of primitives, one per channel.
    `static java.lang.Object` | `getPixels(java.awt.image.BufferedImage image, int x, int y, int w, int h)` Gets the image's pixel data as arrays of primitives, one per channel.
    `static java.lang.Object` | `getPixels(java.awt.image.WritableRaster raster)` Gets the raster's pixel data as arrays of primitives, one per channel.
    `static java.lang.Object` | `getPixels(java.awt.image.WritableRaster raster, int x, int y, int w, int h)` Gets the raster's pixel data as arrays of primitives, one per channel.
    `static int` | `getPixelType(java.awt.image.BufferedImage image)` Gets the pixel type of the given image.
    `static short[][]` | `getShorts(java.awt.image.BufferedImage image)` Extracts pixel data as arrays of unsigned shorts, one per channel.
    `static short[][]` | `getShorts(java.awt.image.WritableRaster r)` Extracts pixel data as arrays of unsigned shorts, one per channel.
    `static short[][]` | `getShorts(java.awt.image.WritableRaster r, int x, int y, int w, int h)` Extracts pixel data as arrays of unsigned shorts, one per channel.
    `static java.awt.Dimension` | `getSize(java.awt.Image image)` Gets the width and height of the given AWT image, waiting for it to finish loading if necessary.
    `static java.awt.image.BufferedImage` | `getSubimage(java.awt.image.BufferedImage image, boolean littleEndian, int x, int y, int w, int h)` Returns a subimage of the specified image.
    `static java.awt.image.BufferedImage` | `indexedToRGB(java.awt.image.BufferedImage img, boolean le)` Converts an indexed color BufferedImage to an RGB BufferedImage.
    `static boolean` | `loadImage(java.awt.Image image)` Ensures the given AWT image is fully loaded.
    `static java.awt.image.BufferedImage` | `makeBuffered(java.awt.Image image)` Creates a buffered image from the given AWT image object.
    `static java.awt.image.BufferedImage` | `makeBuffered(java.awt.Image image, java.awt.image.ColorModel cm)` Creates a buffered image possessing the given color model, from the specified AWT image object.
    `static java.awt.image.ColorModel` | `makeColorModel(int c, int dataType)` Gets a color model for the given number of color components.
    `static java.awt.color.ColorSpace` | `makeColorSpace(int c)` Gets a color space for the given number of color components.
    `static java.awt.image.BufferedImage` | `makeCompatible(java.awt.image.BufferedImage image, java.awt.GraphicsConfiguration gc)` Creates a buffered image compatible with the given graphics configuration, using the given buffered image as a source.
    `static java.awt.image.BufferedImage` | `makeImage(byte[][] data, int w, int h, boolean signed)` Creates an image from the given byte data.
    `static java.awt.image.BufferedImage` | `makeImage(byte[][] data, int w, int h, int bpp, boolean fp, boolean little, boolean signed)` Creates an image from the given raw byte array, performing any necessary type conversions.
    `static java.awt.image.BufferedImage` | `makeImage(byte[] data, boolean interleaved, MetadataRetrieve meta, int series)` Creates an image from the given raw byte array, obtaining the dimensional parameters from the specified metadata object.
    `static java.awt.image.BufferedImage` | `makeImage(byte[] data, int w, int h, boolean signed)` Creates an image from the given single-channel byte data.
    `static java.awt.image.BufferedImage` | `makeImage(byte[] data, int w, int h, int c, boolean interleaved, boolean signed)` Creates an image from the given byte data.
    `static java.awt.image.BufferedImage` | `makeImage(byte[] data, int w, int h, int c, boolean interleaved, int bpp, boolean fp, boolean little, boolean signed)` Creates an image from the given raw byte array, performing any necessary type conversions.
    `static java.awt.image.BufferedImage` | `makeImage(double[][] data, int w, int h)` Creates an image from the given double-precision floating point data.
    `static java.awt.image.BufferedImage` | `makeImage(double[] data, int w, int h)` Creates an image from the given single-channel double data.
    `static java.awt.image.BufferedImage` | `makeImage(double[] data, int w, int h, int c, boolean interleaved)` Creates an image from the given double data.
    `static java.awt.image.BufferedImage` | `makeImage(float[][] data, int w, int h)` Creates an image from the given single-precision floating point data.
    `static java.awt.image.BufferedImage` | `makeImage(float[] data, int w, int h)` Creates an image from the given single-channel float data.
    `static java.awt.image.BufferedImage` | `makeImage(float[] data, int w, int h, int c, boolean interleaved)` Creates an image from the given float data.
    `static java.awt.image.BufferedImage` | `makeImage(int[][] data, int w, int h, boolean signed)` Creates an image from the given int data.
    `static java.awt.image.BufferedImage` | `makeImage(int[] data, int w, int h, boolean signed)` Creates an image from the given single-channel int data.
    `static java.awt.image.BufferedImage` | `makeImage(int[] data, int w, int h, int c, boolean interleaved, boolean signed)` Creates an image from the given int data.
    `static java.awt.image.BufferedImage` | `makeImage(short[][] data, int w, int h, boolean signed)` Creates an image from the given short data.
    `static java.awt.image.BufferedImage` | `makeImage(short[] data, int w, int h, boolean signed)` Creates an image from the given single-channel short data.
    `static java.awt.image.BufferedImage` | `makeImage(short[] data, int w, int h, int c, boolean interleaved, boolean signed)` Creates an image from the given short data.
    `static java.awt.image.BufferedImage` | `makeRGBImage(byte[][] data, int w, int h)`
    `static java.awt.image.BufferedImage` | `makeRGBImage(byte[] data, int c, int w, int h, boolean interleaved)`
    `static java.awt.image.BufferedImage` | `makeUnsigned(java.awt.image.BufferedImage img)` Converts the given BufferedImage into an image with unsigned pixel data.
    `static java.awt.image.BufferedImage` | `mergeChannels(java.awt.image.BufferedImage[] images)` Merges the given images into a single multi-channel image.
    `static java.awt.image.BufferedImage` | `openImage(byte[] buf, IFormatReader r, int w, int h)` Creates an image from the given byte array, using the given IFormatReader to retrieve additional information.
    `static java.awt.image.BufferedImage` | `openImage(byte[] buf, IFormatReader r, int w, int h, boolean normal)` Creates an image from the given byte array, using the given IFormatReader to retrieve additional information.
    `static java.awt.image.BufferedImage` | `padImage(java.awt.image.BufferedImage img, int width, int height)` Pads (or crops) the image to the given width and height.
    `static java.awt.image.BufferedImage` | `scale(java.awt.image.BufferedImage source, int width, int height, boolean pad)` Scales the image using the most appropriate API, with the resultant image having the same color model as the original image.
    `static java.awt.image.BufferedImage` | `scale2D(java.awt.image.BufferedImage image, int width, int height, java.lang.Object hint, java.awt.image.ColorModel cm)` Scales the image using the Java2D API, with the resultant image having the given color model.
    `static java.awt.image.BufferedImage` | `scale2D(java.awt.image.BufferedImage image, int width, int height, java.lang.Object hint, java.awt.GraphicsConfiguration gc)` Scales the image using the Java2D API, with the resultant image optimized for the given graphics configuration.
    `static java.awt.Image` | `scaleAWT(java.awt.image.BufferedImage source, int width, int height, int hint)` Scales the image using the AWT Image API.
    `static java.awt.image.BufferedImage[]` | `splitChannels(java.awt.image.BufferedImage image)` Splits the given multi-channel image into single-channel images.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### OBS

          protected static final java.awt.Component OBS

      ImageObserver for working with AWT images.

    - #### LOGGER

          private static final org.slf4j.Logger LOGGER

  - ### Constructor Detail

    - #### AWTImageTools

          private AWTImageTools()

  - ### Method Detail

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(byte[] data,
                                                               int w,
                                                               int h,
                                                               boolean signed)

      Creates an image from the given single-channel byte data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `signed` - Whether the byte values should be treated as signed (-128 to 127) instead of unsigned (0 to 255).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(short[] data,
                                                               int w,
                                                               int h,
                                                               boolean signed)

      Creates an image from the given single-channel short data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `signed` - Whether the short values should be treated as signed (-32768 to 32767) instead of unsigned (0 to 65535).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(int[] data,
                                                               int w,
                                                               int h,
                                                               boolean signed)

      Creates an image from the given single-channel int data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `signed` - Whether the int values should be treated as signed (-2^31 to 2^31-1) instead of unsigned (0 to 2^32-1).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(float[] data,
                                                               int w,
                                                               int h)

      Creates an image from the given single-channel float data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(double[] data,
                                                               int w,
                                                               int h)

      Creates an image from the given single-channel double data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(byte[] data,
                                                               int w,
                                                               int h,
                                                               int c,
                                                               boolean interleaved,
                                                               boolean signed)

      Creates an image from the given byte data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `c` - Number of channels.
        `interleaved` - If set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.
        `signed` - Whether the byte values should be treated as signed (-128 to 127) instead of unsigned (0 to 255).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(short[] data,
                                                               int w,
                                                               int h,
                                                               int c,
                                                               boolean interleaved,
                                                               boolean signed)

      Creates an image from the given short data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `c` - Number of channels.
        `interleaved` - If set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.
        `signed` - Whether the short values should be treated as signed (-32768 to 32767) instead of unsigned (0 to 65535).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(int[] data,
                                                               int w,
                                                               int h,
                                                               int c,
                                                               boolean interleaved,
                                                               boolean signed)

      Creates an image from the given int data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `c` - Number of channels.
        `interleaved` - If set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.
        `signed` - Whether the int values should be treated as signed (-2^31 to 2^31-1) instead of unsigned (0 to 2^32-1).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(float[] data,
                                                               int w,
                                                               int h,
                                                               int c,
                                                               boolean interleaved)

      Creates an image from the given float data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `c` - Number of channels.
        `interleaved` - If set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(double[] data,
                                                               int w,
                                                               int h,
                                                               int c,
                                                               boolean interleaved)

      Creates an image from the given double data.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `c` - Number of channels.
        `interleaved` - If set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(byte[][] data,
                                                               int w,
                                                               int h,
                                                               boolean signed)

      Creates an image from the given byte data.
      Parameters:
        `data` - Array containing image data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `signed` - Whether the byte values should be treated as signed (-128 to 127) instead of unsigned (0 to 255).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(short[][] data,
                                                               int w,
                                                               int h,
                                                               boolean signed)

      Creates an image from the given short data.
      Parameters:
        `data` - Array containing image data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `signed` - Whether the short values should be treated as signed (-32768 to 32767) instead of unsigned (0 to 65535).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(int[][] data,
                                                               int w,
                                                               int h,
                                                               boolean signed)

      Creates an image from the given int data.
      Parameters:
        `data` - Array containing image data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `signed` - Whether the int values should be treated as signed (-2^31 to 2^31-1) instead of unsigned (0 to 2^32-1).

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(float[][] data,
                                                               int w,
                                                               int h)

      Creates an image from the given single-precision floating point data.
      Parameters:
        `data` - Array containing image data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.
        `w` - Width of image plane.
        `h` - Height of image plane.

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(double[][] data,
                                                               int w,
                                                               int h)

      Creates an image from the given double-precision floating point data.
      Parameters:
        `data` - Array containing image data. It is assumed that each channel corresponds to one element of the array. For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B.
        `w` - Width of image plane.
        `h` - Height of image plane.

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(byte[] data,
                                                               boolean interleaved,
                                                               MetadataRetrieve meta,
                                                               int series)
                                                        throws FormatException

      Creates an image from the given raw byte array, obtaining the dimensional parameters from the specified metadata object.
      Parameters:
        `data` - Array containing image data.
        `interleaved` - If set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.
        `meta` - Metadata object containing dimensional parameters.
        `series` - Relevant image series number of metadata object.
      Throws:
        `FormatException`

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(byte[] data,
                                                               int w,
                                                               int h,
                                                               int c,
                                                               boolean interleaved,
                                                               int bpp,
                                                               boolean fp,
                                                               boolean little,
                                                               boolean signed)

      Creates an image from the given raw byte array, performing any necessary type conversions.
      Parameters:
        `data` - Array containing image data.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `c` - Number of channels.
        `interleaved` - If set, the channels are assumed to be interleaved; otherwise they are assumed to be sequential. For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, while "RRR...GGG...BBB..." is sequential.
        `bpp` - Denotes the number of bytes in the returned primitive type (e.g. if bpp == 2, we should return an array of type short).
        `fp` - If set and bpp == 4 or bpp == 8, then return floats or doubles.
        `little` - Whether byte array is in little-endian order.
        `signed` - Whether the data values should be treated as signed instead of unsigned.

    - #### makeImage

          public static java.awt.image.BufferedImage makeImage(byte[][] data,
                                                               int w,
                                                               int h,
                                                               int bpp,
                                                               boolean fp,
                                                               boolean little,
                                                               boolean signed)

      Creates an image from the given raw byte array, performing any necessary type conversions.
      Parameters:
        `data` - Array containing image data, one channel per element.
        `w` - Width of image plane.
        `h` - Height of image plane.
        `bpp` - Denotes the number of bytes in the returned primitive type (e.g. if bpp == 2, we should return an array of type short).
        `fp` - If set and bpp == 4 or bpp == 8, then return floats or doubles.
        `little` - Whether byte array is in little-endian order.
        `signed` - Whether the data values should be treated as signed instead of unsigned.

    - #### makeRGBImage

          public static java.awt.image.BufferedImage makeRGBImage(byte[] data,
                                                                  int c,
                                                                  int w,
                                                                  int h,
                                                                  boolean interleaved)

    - #### makeRGBImage

          public static java.awt.image.BufferedImage makeRGBImage(byte[][] data,
                                                                  int w,
                                                                  int h)

    - #### blankImage

          public static java.awt.image.BufferedImage blankImage(int w,
                                                                int h,
                                                                int c,
                                                                int type)

      Creates a blank image with the given dimensions and transfer type.
      Parameters:
        `w` - Width of image plane.
        `h` - Height of image plane.
        `c` - Number of channels.
        `type` - One of the following types:
        - FormatTools.INT8 ** unsupported for now **
        - FormatTools.UINT8
        - FormatTools.INT16
        - FormatTools.UINT16
        - FormatTools.INT32
        - FormatTools.UINT32 ** unsupported for now **
        - FormatTools.FLOAT
        - FormatTools.DOUBLE

    - #### constructImage

          public static java.awt.image.BufferedImage constructImage(int c,
                                                                    int type,
                                                                    int w,
                                                                    int h,
                                                                    boolean interleaved,
                                                                    boolean banded,
                                                                    java.awt.image.DataBuffer buffer)

      Creates an image with the given DataBuffer.

    - #### constructImage

          public static java.awt.image.BufferedImage constructImage(int c,
                                                                    int type,
                                                                    int w,
                                                                    int h,
                                                                    boolean interleaved,
                                                                    boolean banded,
                                                                    java.awt.image.DataBuffer buffer,
                                                                    java.awt.image.ColorModel colorModel)

      Creates an image with the given DataBuffer.

    - #### openImage

          public static java.awt.image.BufferedImage openImage(byte[] buf,
                                                               IFormatReader r,
                                                               int w,
                                                               int h)
                                                        throws FormatException,
                                                               java.io.IOException

      Creates an image from the given byte array, using the given IFormatReader to retrieve additional information.
      Throws:
        `FormatException`
        `java.io.IOException`

    - #### openImage

          public static java.awt.image.BufferedImage openImage(byte[] buf,
                                                               IFormatReader r,
                                                               int w,
                                                               int h,
                                                               boolean normal)
                                                        throws FormatException,
                                                               java.io.IOException

      Creates an image from the given byte array, using the given IFormatReader to retrieve additional information. The floating point normalization setting is specified by 'normal', which allows the reader's normalization setting to be overridden.
      Throws:
        `FormatException`
        `java.io.IOException`

    - #### getPixels

          public static java.lang.Object getPixels(java.awt.image.BufferedImage image)

      Gets the image's pixel data as arrays of primitives, one per channel. The returned type will be either byte[][], short[][], int[][], float[][] or double[][], depending on the image's transfer type.

    - #### getPixels

          public static java.lang.Object getPixels(java.awt.image.BufferedImage image,
                                                   int x,
                                                   int y,
                                                   int w,
                                                   int h)

      Gets the image's pixel data as arrays of primitives, one per channel. The returned type will be either byte[][], short[][], int[][], float[][] or double[][], depending on the image's transfer type.

    - #### getPixels

          public static java.lang.Object getPixels(java.awt.image.WritableRaster raster)

      Gets the raster's pixel data as arrays of primitives, one per channel. The returned type will be either byte[][], short[][], int[][], float[][] or double[][], depending on the raster's transfer type.

    - #### getPixels

          public static java.lang.Object getPixels(java.awt.image.WritableRaster raster,
                                                   int x,
                                                   int y,
                                                   int w,
                                                   int h)

      Gets the raster's pixel data as arrays of primitives, one per channel. The returned type will be either byte[][], short[][], int[][], float[][] or double[][], depending on the raster's transfer type.

    - #### getBytes

          public static byte[][] getBytes(java.awt.image.BufferedImage image)

      Extracts pixel data as arrays of unsigned bytes, one per channel.

    - #### getBytes

          public static byte[][] getBytes(java.awt.image.WritableRaster r)

      Extracts pixel data as arrays of unsigned bytes, one per channel.

    - #### getBytes

          public static byte[][] getBytes(java.awt.image.WritableRaster r,
                                          int x,
                                          int y,
                                          int w,
                                          int h)

      Extracts pixel data as arrays of unsigned bytes, one per channel.

    - #### getShorts

          public static short[][] getShorts(java.awt.image.BufferedImage image)

      Extracts pixel data as arrays of unsigned shorts, one per channel.

    - #### getShorts

          public static short[][] getShorts(java.awt.image.WritableRaster r)

      Extracts pixel data as arrays of unsigned shorts, one per channel.

    - #### getShorts

          public static short[][] getShorts(java.awt.image.WritableRaster r,
                                            int x,
                                            int y,
                                            int w,
                                            int h)

      Extracts pixel data as arrays of unsigned shorts, one per channel.

    - #### getInts

          public static int[][] getInts(java.awt.image.BufferedImage image)

      Extracts pixel data as arrays of signed integers, one per channel.

    - #### getInts

          public static int[][] getInts(java.awt.image.WritableRaster r)

      Extracts pixel data as arrays of signed integers, one per channel.

    - #### getInts

          public static int[][] getInts(java.awt.image.WritableRaster r,
                                        int x,
                                        int y,
                                        int w,
                                        int h)

      Extracts pixel data as arrays of signed integers, one per channel.

    - #### getFloats

          public static float[][] getFloats(java.awt.image.BufferedImage image)

      Extracts pixel data as arrays of floats, one per channel.

    - #### getFloats

          public static float[][] getFloats(java.awt.image.WritableRaster r)

      Extracts pixel data as arrays of floats, one per channel.

    - #### getFloats

          public static float[][] getFloats(java.awt.image.WritableRaster r,
                                            int x,
                                            int y,
                                            int w,
                                            int h)

      Extracts pixel data as arrays of floats, one per channel.

    - #### getDoubles

          public static double[][] getDoubles(java.awt.image.BufferedImage image)

      Extracts pixel data as arrays of doubles, one per channel.

    - #### getDoubles

          public static double[][] getDoubles(java.awt.image.WritableRaster r)

      Extracts pixel data as arrays of doubles, one per channel.

    - #### getDoubles

          public static double[][] getDoubles(java.awt.image.WritableRaster r,
                                              int x,
                                              int y,
                                              int w,
                                              int h)

      Extracts pixel data as arrays of doubles, one per channel.

    - #### canUseBankDataDirectly

          private static boolean canUseBankDataDirectly(java.awt.image.WritableRaster r,
                                                        int transferType,
                                                        java.lang.Class<? extends java.awt.image.DataBuffer> dataBufferClass)

      Whether we can return the data buffer's bank data without performing any copy or conversion operations.

    - #### getPixelBytes

          public static byte[][] getPixelBytes(java.awt.image.BufferedImage img,
                                               boolean little)

      Return a 2D array of bytes representing the image. If the transfer type is something other than DataBuffer.TYPE_BYTE, then each pixel value is converted to the appropriate number of bytes. In other words, if we are given an image with 16-bit data, each channel of the resulting array will have width * height * 2 bytes.

    - #### getPixelBytes

          public static byte[][] getPixelBytes(java.awt.image.WritableRaster r,
                                               boolean little)

      Return a 2D array of bytes representing the image. If the transfer type is something other than DataBuffer.TYPE_BYTE, then each pixel value is converted to the appropriate number of bytes. In other words, if we are given an image with 16-bit data, each channel of the resulting array will have width * height * 2 bytes.

    - #### getPixelBytes

          public static byte[][] getPixelBytes(java.awt.image.BufferedImage img,
                                               boolean little,
                                               int x,
                                               int y,
                                               int w,
                                               int h)

      Return a 2D array of bytes representing the image. If the transfer type is something other than DataBuffer.TYPE_BYTE, then each pixel value is converted to the appropriate number of bytes. In other words, if we are given an image with 16-bit data, each channel of the resulting array will have width * height * 2 bytes.

    - #### getPixelBytes

          public static byte[][] getPixelBytes(java.awt.image.WritableRaster r,
                                               boolean little,
                                               int x,
                                               int y,
                                               int w,
                                               int h)

      Return a 2D array of bytes representing the image. If the transfer type is something other than DataBuffer.TYPE_BYTE, then each pixel value is converted to the appropriate number of bytes. In other words, if we are given an image with 16-bit data, each channel of the resulting array will have width * height * 2 bytes.

    - #### getPixelType

          public static int getPixelType(java.awt.image.BufferedImage image)

      Gets the pixel type of the given image.
      Returns:
        One of the following types:
        - FormatReader.INT8
        - FormatReader.UINT8
        - FormatReader.INT16
        - FormatReader.UINT16
        - FormatReader.INT32
        - FormatReader.UINT32
        - FormatReader.FLOAT
        - FormatReader.DOUBLE
        - -1 (unknown type)

    - #### convertRenderedImage

          public static java.awt.image.BufferedImage convertRenderedImage(java.awt.image.RenderedImage img)

      Converts a java.awt.image.RenderedImage into a java.awt.image.BufferedImage. This code was adapted from a jGuru post.

    - #### getBytes

          public static byte[] getBytes(java.awt.image.BufferedImage img,
                                        boolean separated)

      Get the bytes from an image, merging the channels as necessary.

    - #### makeUnsigned

          public static java.awt.image.BufferedImage makeUnsigned(java.awt.image.BufferedImage img)

      Converts the given BufferedImage into an image with unsigned pixel data.

    - #### getSubimage

          public static java.awt.image.BufferedImage getSubimage(java.awt.image.BufferedImage image,
                                                                 boolean littleEndian,
                                                                 int x,
                                                                 int y,
                                                                 int w,
                                                                 int h)

      Returns a subimage of the specified image.

    - #### splitChannels

          public static java.awt.image.BufferedImage[] splitChannels(java.awt.image.BufferedImage image)

      Splits the given multi-channel image into single-channel images.

    - #### mergeChannels

          public static java.awt.image.BufferedImage mergeChannels(java.awt.image.BufferedImage[] images)

      Merges the given images into a single multi-channel image.

    - #### padImage

          public static java.awt.image.BufferedImage padImage(java.awt.image.BufferedImage img,
                                                              int width,
                                                              int height)

      Pads (or crops) the image to the given width and height. The image will be centered within the new bounds.

    - #### autoscale

          public static java.awt.image.BufferedImage autoscale(java.awt.image.BufferedImage img)

      Perform autoscaling on the given BufferedImage.

    - #### autoscale

          public static java.awt.image.BufferedImage autoscale(java.awt.image.BufferedImage img,
                                                               int min,
                                                               int max)

      Perform autoscaling on the given BufferedImage; map min to 0 and max to 255. If the BufferedImage has 8 bit data, then nothing happens.

    - #### copyScaled

          public static java.awt.image.BufferedImage copyScaled(java.awt.image.BufferedImage source,
                                                                java.awt.image.BufferedImage target,
                                                                java.lang.Object hint)

      Copies the source image into the target, applying scaling.

    - #### scale2D

          public static java.awt.image.BufferedImage scale2D(java.awt.image.BufferedImage image,
                                                             int width,
                                                             int height,
                                                             java.lang.Object hint,
                                                             java.awt.GraphicsConfiguration gc)

      Scales the image using the Java2D API, with the resultant image optimized for the given graphics configuration.

    - #### scale2D

          public static java.awt.image.BufferedImage scale2D(java.awt.image.BufferedImage image,
                                                             int width,
                                                             int height,
                                                             java.lang.Object hint,
                                                             java.awt.image.ColorModel cm)

      Scales the image using the Java2D API, with the resultant image having the given color model.

    - #### scaleAWT

          public static java.awt.Image scaleAWT(java.awt.image.BufferedImage source,
                                                int width,
                                                int height,
                                                int hint)

      Scales the image using the AWT Image API.

    - #### scale

          public static java.awt.image.BufferedImage scale(java.awt.image.BufferedImage source,
                                                           int width,
                                                           int height,
                                                           boolean pad)

      Scales the image using the most appropriate API, with the resultant image having the same color model as the original image.

    - #### makeBuffered

          public static java.awt.image.BufferedImage makeBuffered(java.awt.Image image)

      Creates a buffered image from the given AWT image object. If the AWT image is already a buffered image, no new object is created.

    - #### makeBuffered

          public static java.awt.image.BufferedImage makeBuffered(java.awt.Image image,
                                                                  java.awt.image.ColorModel cm)

      Creates a buffered image possessing the given color model, from the specified AWT image object. If the AWT image is already a buffered image with the given color model, no new object is created.

    - #### loadImage

          public static boolean loadImage(java.awt.Image image)

      Ensures the given AWT image is fully loaded.

    - #### getSize

          public static java.awt.Dimension getSize(java.awt.Image image)

      Gets the width and height of the given AWT image, waiting for it to finish loading if necessary.

    - #### makeCompatible

          public static java.awt.image.BufferedImage makeCompatible(java.awt.image.BufferedImage image,
                                                                    java.awt.GraphicsConfiguration gc)

      Creates a buffered image compatible with the given graphics configuration, using the given buffered image as a source. If gc is null, the default graphics configuration is used.

    - #### getDefaultConfiguration

          public static java.awt.GraphicsConfiguration getDefaultConfiguration()

      Gets the default graphics configuration for the environment.

    - #### makeColorSpace

          public static java.awt.color.ColorSpace makeColorSpace(int c)

      Gets a color space for the given number of color components.

    - #### makeColorModel

          public static java.awt.image.ColorModel makeColorModel(int c,
                                                                 int dataType)

      Gets a color model for the given number of color components.

    - #### indexedToRGB

          public static java.awt.image.BufferedImage indexedToRGB(java.awt.image.BufferedImage img,
                                                                  boolean le)

      Converts an indexed color BufferedImage to an RGB BufferedImage.

    - #### get8BitLookupTable

          public static byte[][] get8BitLookupTable(java.awt.image.ColorModel model)

      Converts an IndexColorModel to a 2D byte array.

    - #### getLookupTable

          public static short[][] getLookupTable(java.awt.image.ColorModel model)

      Convers an Index16ColorModel to a 2D short array.

Copyright © 2026 Open Microscopy Environment