Class RGBA

java.lang.Object
net.sourceforge.jiu.gui.awt.RGBA

public class RGBA extends Object
This class converts between the 32 bit RGBA int values (used throughout the AWT) and various standard pixel formats like 24 bits RGB, 8 bits gray, 16 bits gray, 1 bit black and white.

The conversion is done in a number of static methods. This class is not supposed to be instantiated.

The method names of this class can be interpreted as follows. If they contain fromXYZ (where XYZ is a pixel format type like Gray8, RGB24 etc.), a conversion from another pixel format to RGBA is done. If the names contains toXYZ, a conversion from RGBA to that pixel format will be performed.

Not all conversions are lossless or well-defined. If 48 bpp RGB truecolor is used as source, only the top eight bits of each 16 bit sample will be used (thus, the procedure is lossy). If RGBA data is to be converted to bilevel (black and white), the conversion is undefined if there are input RGBA pixels that are neither black nor white.

Author:
Marco Schmidt
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default value for the alpha part of RGBA.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    convertFromGray16(short[] src, int srcOffset, int alpha, int[] dest, int destOffset, int num)
    Convert a number of 16 bit grayscale pixels to RGBA type int pixels, adding the given alpha value.
    static void
    convertFromGray8(byte[] src, int srcOffset, int alpha, int[] dest, int destOffset, int num)
    Convert a number of 8 bit grayscale pixels, shades of gray between 0 (for black) and 255 (for white), given as bytes, to RGBA type int pixels, adding the given alpha value.
    static void
    convertFromPackedBilevel(byte[] src, int srcOffset, int alpha, int[] dest, int destOffset, int num)
    Converts pixels from bilevel packed bytes to RGBA format.
    static void
    convertFromPaletted8(byte[] src, int srcOffset, int alpha, int[] red, int[] green, int[] blue, int[] dest, int destOffset, int num)
    Converts a byte array of palette index values to an array of RGBA values, using palette color data.
    static void
    convertFromRGB24(byte[] srcRed, int srcRedOffset, byte[] srcGreen, int srcGreenOffset, byte[] srcBlue, int srcBlueOffset, int alpha, int[] dest, int destOffset, int num)
    Converts 24 bit RGB truecolor data to RGBA int values.
    static void
    convertFromRGB48(short[] srcRed, int srcRedOffset, short[] srcGreen, int srcGreenOffset, short[] srcBlue, int srcBlueOffset, int alpha, int[] dest, int destOffset, int num)
    Converts 48 bit RGB truecolor data to RGBA int values, dropping the least significant eight bits of each short sample.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_ALPHA

      public static final int DEFAULT_ALPHA
      The default value for the alpha part of RGBA. The alpha value is eight bits long left-shifted by 24. This default value is no transparency - the underlying image cannot be seen: 0xff000000.
      See Also:
  • Constructor Details

    • RGBA

      private RGBA()
  • Method Details

    • convertFromPackedBilevel

      public static void convertFromPackedBilevel(byte[] src, int srcOffset, int alpha, int[] dest, int destOffset, int num)
      Converts pixels from bilevel packed bytes to RGBA format. A byte is supposed to store eight pixels, the most significant bit being the leftmost pixel.
      Parameters:
      src - the array with the packed bytes
      srcOffset - the index of the first byte to be converted from src
      alpha - the alpha value to be used for the destination RGBA values
      dest - the array where the destination RGBA pixels will be stored
      destOffset - the index of the first destination pixel in the dest array; that array must be at least destOffset + ((num + 7) / 8) large
      num - the number of pixels (not bytes) to be converted
    • convertFromGray8

      public static void convertFromGray8(byte[] src, int srcOffset, int alpha, int[] dest, int destOffset, int num)
      Convert a number of 8 bit grayscale pixels, shades of gray between 0 (for black) and 255 (for white), given as bytes, to RGBA type int pixels, adding the given alpha value.
      Parameters:
      src - array with grayscale pixels
      srcOffset - index of first entry of src to be converted
      alpha - transparency value to be used in resulting RGBA array (only top eight bits can be set)
      dest - array to store resulting RGBA pixels
      destOffset - index of first entry in dest to be used
      num - number of pixels to be converted
    • convertFromGray16

      public static void convertFromGray16(short[] src, int srcOffset, int alpha, int[] dest, int destOffset, int num)
      Convert a number of 16 bit grayscale pixels to RGBA type int pixels, adding the given alpha value. Note that the lower 8 bits of each grayscale value are dropped.
      Parameters:
      src - array with grayscale pixels
      srcOffset - index of first entry of src to be converted
      alpha - transparency value to be used in resulting RGBA array (only top eight bits can be set)
      dest - array to store resulting RGBA pixels
      destOffset - index of first entry in dest to be used
      num - number of pixels to be converted
    • convertFromPaletted8

      public static void convertFromPaletted8(byte[] src, int srcOffset, int alpha, int[] red, int[] green, int[] blue, int[] dest, int destOffset, int num)
      Converts a byte array of palette index values to an array of RGBA values, using palette color data.
      Parameters:
      src - the byte array with the palette index values
      srcOffset - index of the first entry of src to be used
      alpha - transparency value to be used (only top eight bits should be set)
      red - the red palette values
      green - the green palette values
      blue - the blue palette values
      dest - the destination array to store the RGBA values
      destOffset - the first entry of dest to be used
      num - the number of pixels to be converted
    • convertFromRGB24

      public static void convertFromRGB24(byte[] srcRed, int srcRedOffset, byte[] srcGreen, int srcGreenOffset, byte[] srcBlue, int srcBlueOffset, int alpha, int[] dest, int destOffset, int num)
      Converts 24 bit RGB truecolor data to RGBA int values.
      Parameters:
      srcRed - the red pixel values
      srcRedOffset - the first entry of srcRed to be used
      srcGreen - the green pixel values
      srcGreenOffset - the first entry of srcGreen to be used
      srcBlue - the blue pixel values
      srcBlueOffset - the first entry of srcBlue to be used
      alpha - the transpancy value to be used in the destination RGBA array (only top 8 bits should be set)
      dest - array to store RGBA pixel values
      destOffset - first entry of dest to be used
      num - number of pixels to be converted
    • convertFromRGB48

      public static void convertFromRGB48(short[] srcRed, int srcRedOffset, short[] srcGreen, int srcGreenOffset, short[] srcBlue, int srcBlueOffset, int alpha, int[] dest, int destOffset, int num)
      Converts 48 bit RGB truecolor data to RGBA int values, dropping the least significant eight bits of each short sample.
      Parameters:
      srcRed - the red pixel values
      srcRedOffset - the first entry of srcRed to be used
      srcGreen - the green pixel values
      srcGreenOffset - the first entry of srcGreen to be used
      srcBlue - the blue pixel values
      srcBlueOffset - the first entry of srcBlue to be used
      alpha - the transpancy value to be used in the destination RGBA array (only top 8 bits should be set)
      dest - array to store RGBA pixel values
      destOffset - first entry of dest to be used
      num - number of pixels to be converted
      Since:
      0.12.0