ImageData

Instances of this class are device-independent descriptions of images. They are typically used as an intermediate format between loading from or writing to streams and creating an <code>Image</code>. <p> Note that the public fields <code>x</code>, <code>y</code>, <code>disposalMethod</code> and <code>delayTime</code> are typically only used when the image is in a set of images used for animation. </p>

@see Image @see ImageLoader @see <a href="http://www.eclipse.org/swt/snippets/#image">ImageData snippets</a> @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ImageAnalyzer</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

final
class ImageData : CloneableCompatibility {
int MSB_FIRST;
}

Constructors

this
this(int width, int height, int depth, 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.

this
this(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data)

Constructs a new, empty ImageData with the given width, height, depth, palette, scanlinePad and data.

this
this(InputStream stream)

Constructs an <code>ImageData</code> loaded from the specified input stream. Throws an error if an error occurs while loading the image, or if the image has an unsupported type. Application code is still responsible for closing the input stream. <p> This constructor is provided for convenience when loading a single image only. If the stream contains multiple images, only the first one will be loaded. To load multiple images, use <code>ImageLoader.load()</code>. </p><p> This constructor may be used to load a resource as follows: </p> <pre> static ImageData loadImageData (Class clazz, String string) { InputStream stream = clazz.getResourceAsStream (string); if (stream is null) return null; ImageData imageData = null; try { imageData = new ImageData (stream); } catch (SWTException ex) { } finally { try { stream.close (); } catch (IOException ex) {} } return imageData; } </pre>

this
this(String filename)

Constructs an <code>ImageData</code> 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. <p> 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 <code>ImageLoader.load()</code>. </p>

this
this(int width, int height, int depth, 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. <p> This method is for internal use, and is not described further. </p>

Members

Functions

clone
Object clone()

Returns a new instance of the same class as the receiver, whose slots have been filled in with <em>copies</em> of the values in the slots of the receiver. That is, the returned object is a <em>deep copy</em> of the receiver.

getAlpha
int getAlpha(int x, int y)

Returns the alpha value at offset <code>x</code> in scanline <code>y</code> in the receiver's alpha data. The alpha value is between 0 (transparent) and 255 (opaque).

getAlphas
void getAlphas(int x, int y, int getWidth, byte[] alphas, int startIndex)

Returns <code>getWidth</code> alpha values starting at offset <code>x</code> in scanline <code>y</code> in the receiver's alpha data starting at <code>startIndex</code>. The alpha values are unsigned, between <code>(byte)0</code> (transparent) and <code>(byte)255</code> (opaque).

getByteOrder
int getByteOrder()

Returns the byte order of the receiver.

getPixel
int getPixel(int x, int y)

Returns the pixel value at offset <code>x</code> in scanline <code>y</code> in the receiver's data.

getPixels
void getPixels(int x, int y, int getWidth, byte[] pixels, int startIndex)

Returns <code>getWidth</code> pixel values starting at offset <code>x</code> in scanline <code>y</code> in the receiver's data starting at <code>startIndex</code>.

getPixels
void getPixels(int x, int y, int getWidth, int[] pixels, int startIndex)

Returns <code>getWidth</code> pixel values starting at offset <code>x</code> in scanline <code>y</code> in the receiver's data starting at <code>startIndex</code>.

getRGBs
RGB[] getRGBs()

Returns an array of <code>RGB</code>s which comprise the indexed color table of the receiver, or null if the receiver has a direct color model.

getTransparencyMask
ImageData getTransparencyMask()

Returns an <code>ImageData</code> which specifies the transparency mask information for the receiver. If the receiver has no transparency or is not an icon, returns an opaque mask.

getTransparencyType
int getTransparencyType()

Returns the image transparency type, which will be one of <code>SWT.TRANSPARENCY_NONE</code>, <code>SWT.TRANSPARENCY_MASK</code>, <code>SWT.TRANSPARENCY_PIXEL</code> or <code>SWT.TRANSPARENCY_ALPHA</code>.

scaledTo
ImageData scaledTo(int width, int height)

Returns a copy of the receiver which has been stretched or shrunk to the specified size. If either the width or height is negative, the resulting image will be inverted in the associated axis.

setAllFields
void setAllFields(int width, int height, int depth, int scanlinePad, int bytesPerLine, byte[] data, 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. <p> This method is for internal use, and is not described further. </p>

setAlpha
void setAlpha(int x, int y, int alpha)

Sets the alpha value at offset <code>x</code> in scanline <code>y</code> in the receiver's alpha data. The alpha value must be between 0 (transparent) and 255 (opaque).

setAlphas
void setAlphas(int x, int y, int putWidth, byte[] alphas, int startIndex)

Sets the alpha values starting at offset <code>x</code> in scanline <code>y</code> in the receiver's alpha data to the values from the array <code>alphas</code> starting at <code>startIndex</code>. The alpha values must be between <code>(byte)0</code> (transparent) and <code>(byte)255</code> (opaque)

setPixel
void setPixel(int x, int y, int pixelValue)

Sets the pixel value at offset <code>x</code> in scanline <code>y</code> in the receiver's data.

setPixels
void setPixels(int x, int y, int putWidth, byte[] pixels, int startIndex)

Sets the pixel values starting at offset <code>x</code> in scanline <code>y</code> in the receiver's data to the values from the array <code>pixels</code> starting at <code>startIndex</code>.

setPixels
void setPixels(int x, int y, int putWidth, int[] pixels, int startIndex)

Sets the pixel values starting at offset <code>x</code> in scanline <code>y</code> in the receiver's data to the values from the array <code>pixels</code> starting at <code>startIndex</code>.

Static functions

blit
void blit(int op, byte[] srcData, int srcDepth, int srcStride, int srcOrder, int srcX, int srcY, int srcWidth, int srcHeight, int srcRedMask, int srcGreenMask, int srcBlueMask, int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, byte[] destData, int destDepth, int destStride, int destOrder, int destX, int destY, int destWidth, int destHeight, int destRedMask, int destGreenMask, int destBlueMask, bool flipX, bool flipY)

Blits a direct palette image into a direct palette image. <p> Note: When the source and destination depth, order and masks are pairwise equal and the blitter operation is BLIT_SRC, the masks are ignored. Hence when not changing the image data format, 0 may be specified for the masks. </p>

blit
void blit(int op, byte[] srcData, int srcDepth, int srcStride, int srcOrder, int srcX, int srcY, int srcWidth, int srcHeight, byte[] srcReds, byte[] srcGreens, byte[] srcBlues, int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, byte[] destData, int destDepth, int destStride, int destOrder, int destX, int destY, int destWidth, int destHeight, byte[] destReds, byte[] destGreens, byte[] destBlues, bool flipX, bool flipY)

Blits an index palette image into an index palette image. <p> Note: The source and destination red, green, and blue arrays may be null if no alpha blending or dither is to be performed. </p>

blit
void blit(int op, byte[] srcData, int srcDepth, int srcStride, int srcOrder, int srcX, int srcY, int srcWidth, int srcHeight, byte[] srcReds, byte[] srcGreens, byte[] srcBlues, int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, byte[] destData, int destDepth, int destStride, int destOrder, int destX, int destY, int destWidth, int destHeight, int destRedMask, int destGreenMask, int destBlueMask, bool flipX, bool flipY)

Blits an index palette image into a direct palette image. <p> Note: The source and destination masks and palettes must always be fully specified. </p>

blit
void blit(int op, byte[] srcData, int srcDepth, int srcStride, int srcOrder, int srcX, int srcY, int srcWidth, int srcHeight, int srcRedMask, int srcGreenMask, int srcBlueMask, int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, byte[] destData, int destDepth, int destStride, int destOrder, int destX, int destY, int destWidth, int destHeight, byte[] destReds, byte[] destGreens, byte[] destBlues, bool flipX, bool flipY)

Blits a direct palette image into an index palette image. <p> Note: The source and destination masks and palettes must always be fully specified. </p>

bwPalette
PaletteData bwPalette()

Returns a palette with 2 colors: black & white.

closestMatch
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.

createGradientBand
ImageData createGradientBand(int width, int height, bool vertical, RGB fromRGB, RGB toRGB, int redBits, int greenBits, int blueBits)

Creates an ImageData containing one band's worth of a gradient filled block. If <code>vertical</code> is true, the band must be tiled horizontally to fill a region, otherwise it must be tiled vertically.

fillGradientRectangle
void fillGradientRectangle(GC gc, Device device, int x, int y, int width, int height, bool vertical, RGB fromRGB, RGB toRGB, int redBits, int greenBits, int blueBits)

Renders a gradient onto a GC. <p> This is a GC helper. </p>

getChannelField
byte getChannelField(int data, int mask)

Extracts a field from packed RGB data given a mask for that field.

getChannelShift
int getChannelShift(int mask)

Computes the required channel shift from a mask.

getChannelWidth
int getChannelWidth(int mask, int shift)

Computes the required channel width (depth) from a mask.

getMSBOffset
int getMSBOffset(int mask)

Gets the offset of the most significant bit for the given mask.

internal_new
ImageData internal_new(int width, int height, int depth, 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. <p> <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for <code>ImageData</code>. 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. </p> <p> This method is for internal use, and is not described further. </p>

Static variables

ALPHA_CHANNEL_SEPARATE
int ALPHA_CHANNEL_SEPARATE;

Alpha mode, values 0 - 255 specify global alpha level

ALPHA_CHANNEL_SOURCE
int ALPHA_CHANNEL_SOURCE;

Alpha mode, values 0 - 255 specify global alpha level

ALPHA_MASK_INDEX
int ALPHA_MASK_INDEX;

Alpha mode, values 0 - 255 specify global alpha level

ALPHA_MASK_PACKED
int ALPHA_MASK_PACKED;

Alpha mode, values 0 - 255 specify global alpha level

ALPHA_MASK_RGB
int ALPHA_MASK_RGB;

Alpha mode, values 0 - 255 specify global alpha level

ALPHA_MASK_UNPACKED
int ALPHA_MASK_UNPACKED;

Alpha mode, values 0 - 255 specify global alpha level

ALPHA_OPAQUE
int ALPHA_OPAQUE;

Alpha mode, values 0 - 255 specify global alpha level

ALPHA_TRANSPARENT
int ALPHA_TRANSPARENT;

Alpha mode, values 0 - 255 specify global alpha level

BLIT_ALPHA
int BLIT_ALPHA;

Blit operation bits to be OR'ed together to specify the desired operation.

BLIT_DITHER
int BLIT_DITHER;

Blit operation bits to be OR'ed together to specify the desired operation.

BLIT_SRC
int BLIT_SRC;

Blit operation bits to be OR'ed together to specify the desired operation.

DITHER_MATRIX
int[][] DITHER_MATRIX;

Scaled 8x8 Bayer dither matrix.

LSB_FIRST
int LSB_FIRST;

Byte and bit order constants.

Variables

alpha
int alpha;

The global alpha value to be used for every pixel. <p> If this value is set, the <code>alphaData</code> field is ignored and when the image is rendered each pixel will be blended with the background an amount proportional to this value. </p><p> The default is -1 which means 'no global alpha value' </p>

alphaData
byte[] alphaData;

The alpha data of the image. <p> Every pixel can have an <em>alpha blending</em> value that varies from 0, meaning fully transparent, to 255 meaning fully opaque. The number of bytes per scanline is 'width'. </p>

bytesPerLine
int bytesPerLine;

The number of bytes per scanline. <p> This is a multiple of the scanline padding. </p>

data
byte[] data;

The pixel data of the image. <p> 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. </p>

delayTime
int delayTime;

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

depth
int depth;

The color depth of the image, in bits per pixel. <p> 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.

disposalMethod
int disposalMethod;

A description of how to dispose of the current image before displaying the next.

height
int height;

The height of the image, in pixels.

maskData
byte[] maskData;

An icon-specific field containing the data from the icon mask. <p> 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'. </p><p> The default is null which means 'no transparency mask'. </p>

maskPad
int maskPad;

An icon-specific field containing the scanline pad of the mask. <p> If one scanline of the transparency mask is not a multiple of this number, it will be padded with zeros until it is. </p>

palette
PaletteData palette;

The color table for the image.

scanlinePad
int scanlinePad;

The scanline padding. <p> If one scanline of the image is not a multiple of this number, it will be padded with zeros until it is. </p>

transparentPixel
int transparentPixel;

The transparent pixel. <p> Pixels with this value are transparent. </p><p> The default is -1 which means 'no transparent pixel'. </p>

type
int type;

The type of file from which the image was read.

width
int width;

The width of the image, in pixels.

x
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
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).

Meta