Module javafx.graphics
Package javafx.scene.image

# Class PixelFormat<T extends Buffer>

java.lang.Object
javafx.scene.image.PixelFormat<T>

Type Parameters:
  `T` - the type of buffer that stores the pixel data. Only `ByteBuffer` and `IntBuffer` are used.

Direct Known Subclasses:
  `WritablePixelFormat`

    public abstract class PixelFormat<T extends Buffer>
    extends Object

A `PixelFormat` object defines the layout of data for a pixel of a given format.

Since:
  JavaFX 2.2

- ## Nested Class Summary

  Nested Classes
  Modifier and Type | Class | Description
  --- | --- | ---
  `static class` | `PixelFormat.Type` | An enum describing the in-array storage format of a single pixel managed by a `PixelFormat`.

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `static PixelFormat<ByteBuffer>` | `createByteIndexedInstance​(int[] colors)` | Creates a `PixelFormat` instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of non-premultiplied color values in the `INT_ARGB` format.
  `static PixelFormat<ByteBuffer>` | `createByteIndexedPremultipliedInstance​(int[] colors)` | Creates a `PixelFormat` instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of premultiplied color values in the `INT_ARGB_PRE` format.
  `abstract int` | `getArgb​(T buf, int x, int y, int scanlineStride)` | Reads pixel data from the buffer at the specified coordinates and converts it to a 32-bit integer representation of the color in the `INT_ARGB` format.
  `static WritablePixelFormat<ByteBuffer>` | `getByteBgraInstance()` | Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in adjacent bytes with the non-premultiplied components stored in order of increasing index: blue, green, red, alpha.
  `static WritablePixelFormat<ByteBuffer>` | `getByteBgraPreInstance()` | Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in adjacent bytes with the premultiplied components stored in order of increasing index: blue, green, red, alpha.
  `static PixelFormat<ByteBuffer>` | `getByteRgbInstance()` | Returns a `PixelFormat` instance describing a pixel layout with the pixels stored in adjacent bytes with the color components stored in order of increasing index: red, green, blue.
  `static WritablePixelFormat<IntBuffer>` | `getIntArgbInstance()` | Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in 32-bit integers with the non-premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.
  `static WritablePixelFormat<IntBuffer>` | `getIntArgbPreInstance()` | Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in 32-bit integers with the premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.
  `PixelFormat.Type` | `getType()` | Returns the enum representing the storage format of the pixels managed by this `PixelFormat` object.
  `abstract boolean` | `isPremultiplied()` | Returns true iff the color components decoded (or encoded) by this format are pre-multiplied by the alpha component for more efficient blending calculations.
  `abstract boolean` | `isWritable()` | Returns true iff this `PixelFormat` object can convert color information into a pixel representation.

  ### Methods declared in class java.lang.Object

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

- ## Method Details

  - ### getIntArgbInstance

    public static WritablePixelFormat<IntBuffer> getIntArgbInstance()
    Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in 32-bit integers with the non-premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.

    Pixels in this format can be decoded using the following sample code:

             int pixel = array[rowstart + x];

             int alpha = ((pixel >> 24) & 0xff);
             int red   = ((pixel >> 16) & 0xff);
             int green = ((pixel >>  8) & 0xff);
             int blue  = ((pixel >>   ) & 0xff);

    Returns:
      a `WritabelPixelFormat<IntBuffer>` describing the indicated pixel format

  - ### getIntArgbPreInstance

    public static WritablePixelFormat<IntBuffer> getIntArgbPreInstance()
    Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in 32-bit integers with the premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.

    Pixels in this format can be decoded using the following sample code:

             int pixel = array[rowstart + x];

             int alpha = ((pixel >> 24) & 0xff);
             int red   = ((pixel >> 16) & 0xff);
             int green = ((pixel >>  8) & 0xff);
             int blue  = ((pixel >>   ) & 0xff);

    Returns:
      a `WritabelPixelFormat<IntBuffer>` describing the indicated pixel format

  - ### getByteBgraInstance

    public static WritablePixelFormat<ByteBuffer> getByteBgraInstance()
    Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in adjacent bytes with the non-premultiplied components stored in order of increasing index: blue, green, red, alpha.

    Pixels in this format can be decoded using the following sample code:

             int i = rowstart + x * 4;

             int blue  = (array[i+0] & 0xff);
             int green = (array[i+1] & 0xff);
             int red   = (array[i+2] & 0xff);
             int alpha = (array[i+3] & 0xff);

    Returns:
      a `WritablePixelFormat<ByteBuffer>` describing the indicated pixel format

  - ### getByteBgraPreInstance

    public static WritablePixelFormat<ByteBuffer> getByteBgraPreInstance()
    Returns a `WritablePixelFormat` instance describing a pixel layout with the pixels stored in adjacent bytes with the premultiplied components stored in order of increasing index: blue, green, red, alpha.

    Pixels in this format can be decoded using the following sample code:

             int i = rowstart + x * 4;

             int blue  = (array[i+0] & 0xff);
             int green = (array[i+1] & 0xff);
             int red   = (array[i+2] & 0xff);
             int alpha = (array[i+3] & 0xff);

    Returns:
      a `WritablePixelFormat<ByteBuffer>` describing the indicated pixel format

  - ### getByteRgbInstance

    public static PixelFormat<ByteBuffer> getByteRgbInstance()
    Returns a `PixelFormat` instance describing a pixel layout with the pixels stored in adjacent bytes with the color components stored in order of increasing index: red, green, blue.

    Pixels in this format can be decoded using the following sample code:

             int i = rowstart + x * 3;

             int red   = (array[i+0] & 0xff);
             int green = (array[i+1] & 0xff);
             int blue  = (array[i+2] & 0xff);

    Returns:
      a `PixelFormat<ByteBuffer>` describing the indicated pixel format

  - ### createByteIndexedPremultipliedInstance

    public static PixelFormat<ByteBuffer> createByteIndexedPremultipliedInstance​(int[] colors)
    Creates a `PixelFormat` instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of premultiplied color values in the `INT_ARGB_PRE` format.

    Pixels in this format can be decoded using the following sample code:

             int pixel = array[rowstart + x] & 0xff;
             int argb  = colors[pixel];

             int alpha = ((argb >> 24) & 0xff);
             int red   = ((argb >> 16) & 0xff);
             int green = ((argb >>  8) & 0xff);
             int blue  = ((argb      ) & 0xff);

    Parameters:
      `colors` - an `int[]` array of 32-bit color values in the `INT_ARGB_PRE` format
    Returns:
      a `PixelFormat<ByteBuffer>` describing the indicated pixel format with the specified list of premultiplied colors

  - ### createByteIndexedInstance

    public static PixelFormat<ByteBuffer> createByteIndexedInstance​(int[] colors)
    Creates a `PixelFormat` instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of non-premultiplied color values in the `INT_ARGB` format.

    Pixels in this format can be decoded using the following sample code:

             int pixel = array[rowstart + x] & 0xff;
             int argb  = colors[pixel];

             int alpha = ((argb >> 24) & 0xff);
             int red   = ((argb >> 16) & 0xff);
             int green = ((argb >>  8) & 0xff);
             int blue  = ((argb      ) & 0xff);

    Parameters:
      `colors` - an `int[]` array of 32-bit color values in the `INT_ARGB` format
    Returns:
      a `PixelFormat<ByteBuffer>` describing the indicated pixel format with the specified list of non-premultiplied colors

  - ### getType

    public PixelFormat.Type getType()
    Returns the enum representing the storage format of the pixels managed by this `PixelFormat` object.
    Returns:
      the `Type` enum of the pixels

  - ### isWritable

    public abstract boolean isWritable()
    Returns true iff this `PixelFormat` object can convert color information into a pixel representation.
    Returns:
      true iff this `PixelFormat` can convert colors to pixel data

  - ### isPremultiplied

    public abstract boolean isPremultiplied()
    Returns true iff the color components decoded (or encoded) by this format are pre-multiplied by the alpha component for more efficient blending calculations.
    Returns:
      true iff the managed color components are premultiplied by alpha

  - ### getArgb

    public abstract int getArgb​(T buf, int x, int y, int scanlineStride)
    Reads pixel data from the buffer at the specified coordinates and converts it to a 32-bit integer representation of the color in the `INT_ARGB` format. The 32-bit integer will contain the 4 color components in separate 8-bit fields in ARGB order from the most significant byte to the least significant byte. The buffer should be positioned to the start of the pixel data such that `buf.get(0)` would return the pixel information for the pixel at coordinates `(0, 0)`. The `scanlineStride` parameter defines the distance from the pixel data at the start of one row to the pixel data at the start of the immediately following row at the next higher Y coordinate. Usually, `scanlineStride` is the same as the width of the image multiplied by the number of data elements per pixel (1 for the case of the integer and indexed formats, or 3 or 4 in the case of the byte formats), but some images may have further padding between rows for alignment or other purposes.

    The color components can be extracted from the returned integer using the following sample code:

             int alpha = ((retval >> 24) & 0xff);
             int red   = ((retval >> 16) & 0xff);
             int green = ((retval >>  8) & 0xff);
             int blue  = ((retval      ) & 0xff);

    Parameters:
      `buf` - the buffer of pixel data
      `x` - the X coordinate of the pixel to be read
      `y` - the Y coordinate of the pixel to be read
      `scanlineStride` - the number of buffer elements between the start of adjacent pixel rows in the buffer
    Returns:
      a 32-bit value with the color of the pixel in a format similar to the `INT_ARGB` pixel format