com.flagstone.transform.image
Class DefineImage

java.lang.Object
  extended by com.flagstone.transform.image.DefineImage
All Implemented Interfaces:
Copyable<MovieTag>, SWFEncodeable, DefineTag, ImageTag, MovieTag

public final class DefineImage
extends Object
implements ImageTag

DefineImage is used to define an image compressed using the lossless zlib compression algorithm.

The class supports colour-mapped images where the image data contains an index into a colour table or direct-mapped images where the colour is specified directly.

For colour-mapped images the colour table contains up to 256, 24-bit colours. The image contains one byte for each pixel which is an index into the table to specify the colour for that pixel. The colour table and the image data are compressed as a single block, with the colour table placed before the image.

For images where the colour is specified directly, the image data contains either 16 or 24 bit colour values. For 16-bit colour values the most significant bit is zero followed by three, 5-bit fields for the red, green and blue channels:

  +-+--------+--------+--------+
  |0|   Red  |  Green |  Blue  |
  +-+--------+--------+--------+
  15                            0
 

Four bytes are used to represent 24-bit colours. The first byte is always set to zero and the following bytes contain the colour values for the red, green and blue colour channels.

The number of bytes in each row of an image must be aligned to a 32-bit word boundary. For example if an image if an icon is 25 pixels wide, then for an 8-bit colour mapped image an additional three bytes (0x00) must be used to pad each row; for a 16-bit direct mapped colour image an additional two bytes must be used as padding.

The image data is stored in zlib compressed form within the object. For colour-mapped images the compressed data contains the colour table followed by the image data. The colour table is omitted for direct-mapped images.

See Also:
DefineImage2

Constructor Summary
DefineImage(DefineImage object)
          Creates and initialises a DefineImage object using the values copied from another DefineImage object.
DefineImage(int uid, int imgWidth, int imgHeight, byte[] data, int size)
          Creates a DefineImage object defining an true-colour image.
DefineImage(int uid, int imgWidth, int imgHeight, int size, byte[] data)
          Creates a DefineImage object defining a colour-mapped image.
DefineImage(SWFDecoder coder)
          Creates and initialises a DefineImage object using values encoded in the Flash binary format.
 
Method Summary
 DefineImage copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 int getHeight()
          Get the height of the image in pixels (not twips).
 int getIdentifier()
          Get the unique identifier assigned to this object.
 byte[] getImage()
          Get a copy of the compressed colour table and image.
 int getPixelSize()
          Returns the number of bits used to represent each pixel.
 int getTableSize()
          Get the number of entries in the colour table encoded the compressed image.
 int getWidth()
          Get the width of the image in pixels (not twips).
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setHeight(int aNumber)
          Sets the height of the image in pixels.
 void setIdentifier(int uid)
          Sets the unique identifier for an object within a given Movie.
 void setImage(byte[] bytes)
          Sets the data containing the compressed image and colour table.
 void setPixelSize(int size)
          Sets the size of the pixel in bits: 8, 16 or 32.
 void setTableSize(int size)
          Sets the number of entries in the colour table in the compressed image.
 void setWidth(int aNumber)
          Sets the width of the image in pixels.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefineImage

public DefineImage(SWFDecoder coder)
            throws IOException
Creates and initialises a DefineImage object using values encoded in the Flash binary format.

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

DefineImage

public DefineImage(int uid,
                   int imgWidth,
                   int imgHeight,
                   int size,
                   byte[] data)
Creates a DefineImage object defining a colour-mapped image.

Parameters:
uid - the unique identifier for this object. Must be in the range 1..65535.
imgWidth - the width of the image. Must be in the range 0..65535.
imgHeight - the height of the image. Must be in the range 0..65535.
size - the number of entries in the colour table in the compressed data. Each entry is 24 bits. Must be in the range 1..256.
data - the zlib compressed colour table and image data.

DefineImage

public DefineImage(int uid,
                   int imgWidth,
                   int imgHeight,
                   byte[] data,
                   int size)
Creates a DefineImage object defining an true-colour image.

Parameters:
uid - the unique identifier for this object. Must be in the range 1..65535.
imgWidth - the width of the image. Must be in the range 0..65535.
imgHeight - the height of the image. Must be in the range 0..65535.
data - the zlib compressed image data.
size - the size of each pixel, either 16 or 24 bits.

DefineImage

public DefineImage(DefineImage object)
Creates and initialises a DefineImage object using the values copied from another DefineImage object.

Parameters:
object - a DefineImage object from which the values will be copied.
Method Detail

getIdentifier

public int getIdentifier()
Get the unique identifier assigned to this object.

Specified by:
getIdentifier in interface DefineTag
Returns:
the unique identifier used by the Flash Player to reference this definition.

setIdentifier

public void setIdentifier(int uid)
Sets the unique identifier for an object within a given Movie.

Specified by:
setIdentifier in interface DefineTag
Parameters:
uid - a unique identifier for the object. Must be in the range 1..65535.

getWidth

public int getWidth()
Get the width of the image in pixels (not twips).

Specified by:
getWidth in interface ImageTag
Returns:
the width of the image.

getHeight

public int getHeight()
Get the height of the image in pixels (not twips).

Specified by:
getHeight in interface ImageTag
Returns:
the height of the image.

getPixelSize

public int getPixelSize()
Returns the number of bits used to represent each pixel. Either 8, 16 or 24 bits. The pixel size is 8-bits for colour-mapped images and 16 or 24 bits for images where the colour is specified directly.

Returns:
the number of bits per pixel: 8, 16 or 24.

getTableSize

public int getTableSize()
Get the number of entries in the colour table encoded the compressed image. For images where the colour is specified directly in the image then the table size is zero.

Returns:
the number of entries in the colour table.

getImage

public byte[] getImage()
Get a copy of the compressed colour table and image.

Returns:
a copy of the data.

setWidth

public void setWidth(int aNumber)
Sets the width of the image in pixels.

Parameters:
aNumber - the width of the image. Must be in the range 0..65535.

setHeight

public void setHeight(int aNumber)
Sets the height of the image in pixels.

Parameters:
aNumber - the height of the image in pixels. Must be in the range 0..65535.

setPixelSize

public void setPixelSize(int size)
Sets the size of the pixel in bits: 8, 16 or 32. The pixel size is 8-bits for colour-mapped images and 16 or 24 bits for images where the colour is specified directly.

Parameters:
size - the size of each pixel in bits. Must be either 8, 16 or 24.

setTableSize

public void setTableSize(int size)
Sets the number of entries in the colour table in the compressed image. For images where the colour is specified directly in the image then the table size should be zero.

Parameters:
size - the number of entries in the colour table in the compressed image, in the range 1..256.

setImage

public void setImage(byte[] bytes)
Sets the data containing the compressed image and colour table.

Parameters:
bytes - byte array containing zlib compressed colour table and image. Must not be null.

copy

public DefineImage copy()
Creates a complete copy of this object.

Specified by:
copy in interface Copyable<MovieTag>
Returns:
a deep-copy of this object. New instances of mutable objects are copied and immutable instances are shared.

toString

public String toString()

Overrides:
toString in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.