Class IconExe.ImageData

  • Enclosing class:
    IconExe

    static class IconExe.ImageData
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int alpha
      The global alpha value to be used for every pixel.
      (package private) static int ALPHA_CHANNEL_SEPARATE
      Alpha mode, values 0 - 255 specify global alpha level
      (package private) static int ALPHA_CHANNEL_SOURCE
      Alpha mode, values 0 - 255 specify global alpha level
      (package private) static int ALPHA_MASK_INDEX
      Alpha mode, values 0 - 255 specify global alpha level
      (package private) static int ALPHA_MASK_PACKED
      Alpha mode, values 0 - 255 specify global alpha level
      (package private) static int ALPHA_MASK_RGB
      Alpha mode, values 0 - 255 specify global alpha level
      (package private) static int ALPHA_MASK_UNPACKED
      Alpha mode, values 0 - 255 specify global alpha level
      (package private) static int ALPHA_OPAQUE
      Alpha mode, values 0 - 255 specify global alpha level
      (package private) static int ALPHA_TRANSPARENT
      Alpha mode, values 0 - 255 specify global alpha level
      byte[] alphaData
      The alpha data of the image.
      (package private) static byte[][] ANY_TO_EIGHT
      Arbitrary channel width data to 8-bit conversion table.
      (package private) static int BLIT_ALPHA
      Blit operation bits to be OR'ed together to specify the desired operation.
      (package private) static int BLIT_DITHER
      Blit operation bits to be OR'ed together to specify the desired operation.
      (package private) static int BLIT_SRC
      Blit operation bits to be OR'ed together to specify the desired operation.
      int bytesPerLine
      The number of bytes per scanline.
      byte[] data
      The pixel data of the image.
      int delayTime
      The time to delay before displaying the next image in an animation (this field corresponds to the GIF89a Delay Time value).
      int depth
      The color depth of the image, in bits per pixel.
      int disposalMethod
      A description of how to dispose of the current image before displaying the next.
      (package private) static int[][] DITHER_MATRIX
      Scaled 8x8 Bayer dither matrix.
      int height
      The height of the image, in pixels.
      (package private) static int LSB_FIRST
      Byte and bit order constants.
      byte[] maskData
      An icon-specific field containing the data from the icon mask.
      int maskPad
      An icon-specific field containing the scanline pad of the mask.
      (package private) static int MSB_FIRST  
      (package private) static byte[] ONE_TO_ONE_MAPPING  
      IconExe.PaletteData palette
      The color table for the image.
      int scanlinePad
      The scanline padding.
      int transparentPixel
      The transparent pixel.
      int type
      The type of file from which the image was read.
      int width
      The width of the image, in pixels.
      int x
      The x coordinate of the top left corner of the image within the logical screen (this field corresponds to the GIF89a Image Left Position value).
      int y
      The y coordinate of the top left corner of the image within the logical screen (this field corresponds to the GIF89a Image Top Position value).
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageData()
      Prevents uninitialized instances from being created outside the package.
      ImageData​(int width, int height, int depth, IconExe.PaletteData palette)
      Constructs a new, empty ImageData with the given width, height, depth and palette.
      ImageData​(int width, int height, int depth, IconExe.PaletteData palette, int scanlinePad, byte[] data)
      Constructs a new, empty ImageData with the given width, height, depth, palette, scanlinePad and data.
      ImageData​(int width, int height, int depth, IconExe.PaletteData palette, int scanlinePad, byte[] data, int maskPad, byte[] maskData, byte[] alphaData, int alpha, int transparentPixel, int type, int x, int y, int disposalMethod, int delayTime)
      Constructs an image data by giving values for all non-computable fields.
      ImageData​(java.lang.String filename)
      Constructs an ImageData loaded from a file with the specified name.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static void buildDitheredGradientChannel​(int from, int to, int steps, int bandWidth, int bandHeight, boolean vertical, byte[] bitmapData, int dp, int bytesPerLine, int bits)  
      (package private) static IconExe.PaletteData bwPalette()
      Returns a palette with 2 colors: black & white.
      (package private) static byte[] checkData​(byte[] data)  
      (package private) static int closestMatch​(int depth, byte red, byte green, byte blue, int redMask, int greenMask, int blueMask, byte[] reds, byte[] greens, byte[] blues)
      Finds the closest match.
      (package private) IconExe.ImageData colorMaskImage​(int pixel)  
      (package private) static IconExe.ImageData convertMask​(IconExe.ImageData mask)  
      (package private) static byte[] convertPad​(byte[] data, int width, int height, int depth, int pad, int newPad)  
      (package private) int getByteOrder()
      Returns the byte order of the receiver.
      (package private) static byte getChannelField​(int data, int mask)
      Extracts a field from packed RGB data given a mask for that field.
      (package private) static int getChannelShift​(int mask)
      Computes the required channel shift from a mask.
      (package private) static int getChannelWidth​(int mask, int shift)
      Computes the required channel width (depth) from a mask.
      (package private) static int getMSBOffset​(int mask)
      Gets the offset of the most significant bit for the given mask.
      void getPixels​(int x, int y, int getWidth, byte[] pixels, int startIndex)
      Returns getWidth pixel values starting at offset x in scanline y in the receiver's data starting at startIndex.
      void getPixels​(int x, int y, int getWidth, int[] pixels, int startIndex)
      Returns getWidth pixel values starting at offset x in scanline y in the receiver's data starting at startIndex.
      IconExe.RGB[] getRGBs()
      Returns an array of RGBs which comprise the indexed color table of the receiver, or null if the receiver has a direct color model.
      IconExe.ImageData getTransparencyMask()
      Returns an ImageData which specifies the transparency mask information for the receiver, or null if the receiver has no transparency and is not an icon.
      int getTransparencyType()
      Returns the image transparency type.
      static IconExe.ImageData internal_new​(int width, int height, int depth, IconExe.PaletteData palette, int scanlinePad, byte[] data, int maskPad, byte[] maskData, byte[] alphaData, int alpha, int transparentPixel, int type, int x, int y, int disposalMethod, int delayTime)
      Invokes internal SWT functionality to create a new instance of this class.
      (package private) void setAllFields​(int width, int height, int depth, int scanlinePad, int bytesPerLine, byte[] data, IconExe.PaletteData palette, int transparentPixel, byte[] maskData, int maskPad, byte[] alphaData, int alpha, int type, int x, int y, int disposalMethod, int delayTime)
      Initializes all fields in the receiver.
      void setPixels​(int x, int y, int putWidth, byte[] pixels, int startIndex)
      Sets the pixel values starting at offset x in scanline y in the receiver's data to the values from the array pixels starting at startIndex.
      void setPixels​(int x, int y, int putWidth, int[] pixels, int startIndex)
      Sets the pixel values starting at offset x in scanline y in the receiver's data to the values from the array pixels starting at startIndex.
      • Methods inherited from class java.lang.Object

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

      • width

        public int width
        The width of the image, in pixels.
      • height

        public int height
        The height of the image, in pixels.
      • depth

        public int depth
        The color depth of the image, in bits per pixel.

        Note that a depth of 8 or less does not necessarily mean that the image is palette indexed, or conversely that a depth greater than 8 means that the image is direct color. Check the associated PaletteData's isDirect field for such determinations.

      • scanlinePad

        public int scanlinePad
        The scanline padding.

        If one scanline of the image is not a multiple of this number, it will be padded with zeros until it is.

      • bytesPerLine

        public int bytesPerLine
        The number of bytes per scanline.

        This is a multiple of the scanline padding.

      • data

        public byte[] data
        The pixel data of the image.

        Note that for 16 bit depth images the pixel data is stored in least significant byte order; however, for 24bit and 32bit depth images the pixel data is stored in most significant byte order.

      • transparentPixel

        public int transparentPixel
        The transparent pixel.

        Pixels with this value are transparent.

        The default is -1 which means 'no transparent pixel'.

      • maskData

        public byte[] maskData
        An icon-specific field containing the data from the icon mask.

        This is a 1 bit bitmap stored with the most significant bit first. The number of bytes per scanline is '((width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad'.

        The default is null which means 'no transparency mask'.

      • maskPad

        public int maskPad
        An icon-specific field containing the scanline pad of the mask.

        If one scanline of the transparency mask is not a multiple of this number, it will be padded with zeros until it is.

      • alphaData

        public byte[] alphaData
        The alpha data of the image.

        Every pixel can have an alpha blending value that varies from 0, meaning fully transparent, to 255 meaning fully opaque. The number of bytes per scanline is 'width'.

      • alpha

        public int alpha
        The global alpha value to be used for every pixel.

        If this value is set, the alphaData field is ignored and when the image is rendered each pixel will be blended with the background an amount proportional to this value.

        The default is -1 which means 'no global alpha value'

      • type

        public int type
        The type of file from which the image was read. It is expressed as one of the following values:
        IMAGE_BMP
        Windows BMP file format, no compression
        IMAGE_BMP_RLE
        Windows BMP file format, RLE compression if appropriate
        IMAGE_GIF
        GIF file format
        IMAGE_ICO
        Windows ICO file format
        IMAGE_JPEG
        JPEG file format
        IMAGE_PNG
        PNG file format
      • x

        public int x
        The x coordinate of the top left corner of the image within the logical screen (this field corresponds to the GIF89a Image Left Position value).
      • y

        public int y
        The y coordinate of the top left corner of the image within the logical screen (this field corresponds to the GIF89a Image Top Position value).
      • disposalMethod

        public int disposalMethod
        A description of how to dispose of the current image before displaying the next. It is expressed as one of the following values:
        DM_UNSPECIFIED
        disposal method not specified
        DM_FILL_NONE
        do nothing - leave the image in place
        DM_FILL_BACKGROUND
        fill with the background color
        DM_FILL_PREVIOUS
        restore the previous picture
        (this field corresponds to the GIF89a Disposal Method value)
      • delayTime

        public int delayTime
        The time to delay before displaying the next image in an animation (this field corresponds to the GIF89a Delay Time value).
      • ANY_TO_EIGHT

        static final byte[][] ANY_TO_EIGHT
        Arbitrary channel width data to 8-bit conversion table.
      • ONE_TO_ONE_MAPPING

        static final byte[] ONE_TO_ONE_MAPPING
      • DITHER_MATRIX

        static final int[][] DITHER_MATRIX
        Scaled 8x8 Bayer dither matrix.
      • BLIT_SRC

        static final int BLIT_SRC
        Blit operation bits to be OR'ed together to specify the desired operation.
        See Also:
        Constant Field Values
      • BLIT_ALPHA

        static final int BLIT_ALPHA
        Blit operation bits to be OR'ed together to specify the desired operation.
        See Also:
        Constant Field Values
      • BLIT_DITHER

        static final int BLIT_DITHER
        Blit operation bits to be OR'ed together to specify the desired operation.
        See Also:
        Constant Field Values
      • ALPHA_OPAQUE

        static final int ALPHA_OPAQUE
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
      • ALPHA_TRANSPARENT

        static final int ALPHA_TRANSPARENT
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
      • ALPHA_CHANNEL_SEPARATE

        static final int ALPHA_CHANNEL_SEPARATE
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
      • ALPHA_CHANNEL_SOURCE

        static final int ALPHA_CHANNEL_SOURCE
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
      • ALPHA_MASK_UNPACKED

        static final int ALPHA_MASK_UNPACKED
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
      • ALPHA_MASK_PACKED

        static final int ALPHA_MASK_PACKED
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
      • ALPHA_MASK_INDEX

        static final int ALPHA_MASK_INDEX
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
      • ALPHA_MASK_RGB

        static final int ALPHA_MASK_RGB
        Alpha mode, values 0 - 255 specify global alpha level
        See Also:
        Constant Field Values
    • Constructor Detail

      • ImageData

        public ImageData​(int width,
                         int height,
                         int depth,
                         IconExe.PaletteData palette)
        Constructs a new, empty ImageData with the given width, height, depth and palette. The data will be initialized to an (all zero) array of the appropriate size.
        Parameters:
        width - the width of the image
        height - the height of the image
        depth - the depth of the image
        palette - the palette of the image (must not be null)
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the width or height is negative, or if the depth is not one of 1, 2, 4, 8, 16, 24 or 32
        • ERROR_NULL_ARGUMENT - if the palette is null
      • ImageData

        public ImageData​(int width,
                         int height,
                         int depth,
                         IconExe.PaletteData palette,
                         int scanlinePad,
                         byte[] data)
        Constructs a new, empty ImageData with the given width, height, depth, palette, scanlinePad and data.
        Parameters:
        width - the width of the image
        height - the height of the image
        depth - the depth of the image
        palette - the palette of the image
        scanlinePad - the padding of each line, in bytes
        data - the data of the image
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the width or height is negative, or if the depth is not one of 1, 2, 4, 8, 16, 24 or 32
        • ERROR_NULL_ARGUMENT - if the palette or data is null
        • ERROR_CANNOT_BE_ZERO - if the scanlinePad is zero
      • ImageData

        public ImageData​(java.lang.String filename)
        Constructs an ImageData loaded from a file with the specified name. Throws an error if an error occurs loading the image, or if the image has an unsupported type.

        This constructor is provided for convenience when loading a single image only. If the file contains multiple images, only the first one will be loaded. To load multiple images, use ImageLoader.load().

        Parameters:
        filename - the name of the file to load the image from (must not be null)
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the file name is null
        java.lang.RuntimeException -
        • ERROR_INVALID_IMAGE - if the image file contains invalid data
        • ERROR_IO if an IO error occurs while reading data
        • ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
      • ImageData

        ImageData()
        Prevents uninitialized instances from being created outside the package.
      • ImageData

        ImageData​(int width,
                  int height,
                  int depth,
                  IconExe.PaletteData palette,
                  int scanlinePad,
                  byte[] data,
                  int maskPad,
                  byte[] maskData,
                  byte[] alphaData,
                  int alpha,
                  int transparentPixel,
                  int type,
                  int x,
                  int y,
                  int disposalMethod,
                  int delayTime)
        Constructs an image data by giving values for all non-computable fields.

        This method is for internal use, and is not described further.

    • Method Detail

      • setAllFields

        void setAllFields​(int width,
                          int height,
                          int depth,
                          int scanlinePad,
                          int bytesPerLine,
                          byte[] data,
                          IconExe.PaletteData palette,
                          int transparentPixel,
                          byte[] maskData,
                          int maskPad,
                          byte[] alphaData,
                          int alpha,
                          int type,
                          int x,
                          int y,
                          int disposalMethod,
                          int delayTime)
        Initializes all fields in the receiver. This method must be called by all public constructors to ensure that all fields are initialized for a new ImageData object. If a new field is added to the class, then it must be added to this method.

        This method is for internal use, and is not described further.

      • internal_new

        public static IconExe.ImageData internal_new​(int width,
                                                     int height,
                                                     int depth,
                                                     IconExe.PaletteData palette,
                                                     int scanlinePad,
                                                     byte[] data,
                                                     int maskPad,
                                                     byte[] maskData,
                                                     byte[] alphaData,
                                                     int alpha,
                                                     int transparentPixel,
                                                     int type,
                                                     int x,
                                                     int y,
                                                     int disposalMethod,
                                                     int delayTime)
        Invokes internal SWT functionality to create a new instance of this class.

        IMPORTANT: This method is not part of the public API for ImageData. It is marked public only so that it can be shared within the packages provided by SWT. It is subject to change without notice, and should never be called from application code.

        This method is for internal use, and is not described further.

      • checkData

        static byte[] checkData​(byte[] data)
      • getPixels

        public void getPixels​(int x,
                              int y,
                              int getWidth,
                              byte[] pixels,
                              int startIndex)
        Returns getWidth pixel values starting at offset x in scanline y in the receiver's data starting at startIndex.
        Parameters:
        x - the x position of the first pixel to get
        y - the y position of the first pixel to get
        getWidth - the width of the data to get
        pixels - the buffer in which to put the pixels
        startIndex - the offset into the byte array to begin storing pixels
        Throws:
        java.lang.IndexOutOfBoundsException - if getWidth is too large
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if pixels is null
        • ERROR_INVALID_ARGUMENT - if x or y is out of bounds
        • ERROR_INVALID_ARGUMENT - if getWidth is negative
        java.lang.RuntimeException -
        • ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4 or 8 (For higher depths, use the int[] version of this method.)
      • getPixels

        public void getPixels​(int x,
                              int y,
                              int getWidth,
                              int[] pixels,
                              int startIndex)
        Returns getWidth pixel values starting at offset x in scanline y in the receiver's data starting at startIndex.
        Parameters:
        x - the x position of the first pixel to get
        y - the y position of the first pixel to get
        getWidth - the width of the data to get
        pixels - the buffer in which to put the pixels
        startIndex - the offset into the buffer to begin storing pixels
        Throws:
        java.lang.IndexOutOfBoundsException - if getWidth is too large
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if pixels is null
        • ERROR_INVALID_ARGUMENT - if x or y is out of bounds
        • ERROR_INVALID_ARGUMENT - if getWidth is negative
        java.lang.RuntimeException -
        • ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4, 8, 16, 24 or 32
      • getRGBs

        public IconExe.RGB[] getRGBs()
        Returns an array of RGBs which comprise the indexed color table of the receiver, or null if the receiver has a direct color model.
        Returns:
        the RGB values for the image or null if direct color
        See Also:
        IconExe.PaletteData.getRGBs()
      • getTransparencyMask

        public IconExe.ImageData getTransparencyMask()
        Returns an ImageData which specifies the transparency mask information for the receiver, or null if the receiver has no transparency and is not an icon.
        Returns:
        the transparency mask or null if none exists
      • getTransparencyType

        public int getTransparencyType()
        Returns the image transparency type.
        Returns:
        the receiver's transparency type
      • getByteOrder

        int getByteOrder()
        Returns the byte order of the receiver.
        Returns:
        MSB_FIRST or LSB_FIRST
      • setPixels

        public void setPixels​(int x,
                              int y,
                              int putWidth,
                              byte[] pixels,
                              int startIndex)
        Sets the pixel values starting at offset x in scanline y in the receiver's data to the values from the array pixels starting at startIndex.
        Parameters:
        x - the x position of the pixel to set
        y - the y position of the pixel to set
        putWidth - the width of the pixels to set
        pixels - the pixels to set
        startIndex - the index at which to begin setting
        Throws:
        java.lang.IndexOutOfBoundsException - if putWidth is too large
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if pixels is null
        • ERROR_INVALID_ARGUMENT - if x or y is out of bounds
        • ERROR_INVALID_ARGUMENT - if putWidth is negative
        java.lang.RuntimeException -
        • ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8 (For higher depths, use the int[] version of this method.)
      • setPixels

        public void setPixels​(int x,
                              int y,
                              int putWidth,
                              int[] pixels,
                              int startIndex)
        Sets the pixel values starting at offset x in scanline y in the receiver's data to the values from the array pixels starting at startIndex.
        Parameters:
        x - the x position of the pixel to set
        y - the y position of the pixel to set
        putWidth - the width of the pixels to set
        pixels - the pixels to set
        startIndex - the index at which to begin setting
        Throws:
        java.lang.IndexOutOfBoundsException - if putWidth is too large
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if pixels is null
        • ERROR_INVALID_ARGUMENT - if x or y is out of bounds
        • ERROR_INVALID_ARGUMENT - if putWidth is negative
        java.lang.RuntimeException -
        • ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32
      • bwPalette

        static IconExe.PaletteData bwPalette()
        Returns a palette with 2 colors: black & white.
      • getMSBOffset

        static int getMSBOffset​(int mask)
        Gets the offset of the most significant bit for the given mask.
      • closestMatch

        static int closestMatch​(int depth,
                                byte red,
                                byte green,
                                byte blue,
                                int redMask,
                                int greenMask,
                                int blueMask,
                                byte[] reds,
                                byte[] greens,
                                byte[] blues)
        Finds the closest match.
      • convertPad

        static final byte[] convertPad​(byte[] data,
                                       int width,
                                       int height,
                                       int depth,
                                       int pad,
                                       int newPad)
      • getChannelShift

        static int getChannelShift​(int mask)
        Computes the required channel shift from a mask.
      • getChannelWidth

        static int getChannelWidth​(int mask,
                                   int shift)
        Computes the required channel width (depth) from a mask.
      • getChannelField

        static byte getChannelField​(int data,
                                    int mask)
        Extracts a field from packed RGB data given a mask for that field.
      • buildDitheredGradientChannel

        static final void buildDitheredGradientChannel​(int from,
                                                       int to,
                                                       int steps,
                                                       int bandWidth,
                                                       int bandHeight,
                                                       boolean vertical,
                                                       byte[] bitmapData,
                                                       int dp,
                                                       int bytesPerLine,
                                                       int bits)