com.flagstone.transform.image
Class DefineImage2

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

public final class DefineImage2
extends Object
implements ImageTag

DefineImage2 is used to define a transparent 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. It extends DefineImage by including alpha channel information for the colour table and pixels in the image.

For colour-mapped images the colour table contains up to 256, 32-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 32 bit colour values.

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.

See Also:
DefineImage

Constructor Summary
DefineImage2(DefineImage2 object)
          Creates and initialises a DefineImage2 object using the values copied from another DefineImage2 object.
DefineImage2(int uid, int imgWidth, int imgHeight, byte[] data)
          Creates a DefineImage object defining a true-colour image.
DefineImage2(int uid, int imgWidth, int imgHeight, int size, byte[] data)
          Creates a DefineImage2 object defining a colour-mapped image.
DefineImage2(SWFDecoder coder)
          Creates and initialises an DefineImage2 object using values encoded in the Flash binary format.
 
Method Summary
 DefineImage2 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()
          Get 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 for colour-mapped images, 32 for direct images.
 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

DefineImage2

public DefineImage2(SWFDecoder coder)
             throws IOException
Creates and initialises an DefineImage2 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.

DefineImage2

public DefineImage2(int uid,
                    int imgWidth,
                    int imgHeight,
                    int size,
                    byte[] data)
Creates a DefineImage2 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 32 bits. Must be in the range 1..256.
data - the zlib compressed colour table and image data. Must not be null.

DefineImage2

public DefineImage2(int uid,
                    int imgWidth,
                    int imgHeight,
                    byte[] data)
Creates a DefineImage object defining a true-colour image. Each pixel in the image is 32 bits - 8 bits for the red, green, blue and alpha colour channels.

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. Must not be null.

DefineImage2

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

Parameters:
object - a DefineImage2 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()
Get the number of bits used to represent each pixel. Either 8 or 32 bits. The pixel size is 8-bits for colour-mapped images and 32 bits for images where the colour is specified directly.

Returns:
the number of bits for each pixel.

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 of 0..65535.

setHeight

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

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

setPixelSize

public void setPixelSize(int size)
Sets the size of the pixel in bits: 8 for colour-mapped images, 32 for direct images.

Parameters:
size - the size of each pixel in bits: must be either 8 or 32.

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. Must be 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 DefineImage2 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.