com.flagstone.transform
Class FSDefineJPEGImage3

java.lang.Object
  extended by com.flagstone.transform.FSTransformObject
      extended by com.flagstone.transform.FSMovieObject
          extended by com.flagstone.transform.FSDefineObject
              extended by com.flagstone.transform.FSDefineJPEGImage3
All Implemented Interfaces:
java.lang.Cloneable

public class FSDefineJPEGImage3
extends FSDefineObject

FSDefineJPEGImage3 is used to define a transparent JPEG encoded image.

It extends the FSDefineJPEGImage3 class by including a separate zlib compressed table of alpha channel values. This allows the transparency of existing JPEG encoded images to be changed without re-encoding the original image.

Attributes
type Identifies the data structure when it is encoded. The type attribute is read-only and may be used when iterating through the objects in an FSMovie object to identify the object class without using run-time type checking.
identifier A unique identifier, in the range 1..65535, that is used to reference the image from other objects.
image An array of bytes containing the JPEG compressed image.
encodingTable An array of bytes containing the encoding table.
alpha An array of bytes containing the zlib encoded alpha channel data for each pixel in the image.

Although the encoding table defines how the image is compressed it is not essential. If an FSDefineJPEGImage3 object is created with an empty encoding table then the Flash Player will still display the JPEG image correctly. The empty encoding table is not a null object. It contains four bytes: 0xFF, 0xD8, 0xFF, 0xD9. For convenience passing a null reference to any of the constructors or to the setEncodingTable method will create an empty table.

The simplest way to use the FSDefineJPEGImage3 class is to use the constructor that specifies the JPEG file to initialise the object:

 File aFile = new File(filename);
 byte[] bytes = new byte[(int) aFile.length()];
 byte[] alpha = new byte[width * height];
 byte[] compressedAlpha = null;
 
 try
 {
        FileInputStream imageContents = new FileInputStream(aFile);
        imageContents.read(bytes);
        imageContents.close();
 
        // Set the level of transparency;
 
        for (int i = 0; i < bytes.length; i++)
                alpha[i] = (byte) 128;
 
        Deflater deflater = new Deflater();
 
        byte[] tmp = new byte[alpha.length];
 
        deflater.setInput(alpha);
        deflater.finish();
 
        int bytesCompressed = deflater.deflate(tmp);
 
        compressedAlpha = new byte[bytesCompressed];
 
        for (int i = 0; i < bytesCompressed; i++)
                compressedAlpha[i] = tmp[i];
 } catch (FileNotFoundException e)
 {
        throw new FileNotFoundException(filename);
 } catch (IOException e)
 {
        throw new IOException(filename);
 }
 
 movie.add(new FSDefineJPEGImage3(movie.newIdentifier(), bytes, null,
                                compressedAlpha));
 

This generates an object with an empty encoding table, however the image will still be displayed correctly. The empty encoding table is not a null object. The alpha channel data is set so the image is completely opaque.

History

The FSDefineJPEGImage3 class represents the DefineBitsJPEG3 tag from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 3.


Field Summary
 
Fields inherited from class com.flagstone.transform.FSDefineObject
identifier
 
Fields inherited from class com.flagstone.transform.FSMovieObject
ButtonColorTransform, ButtonSound, DefineBitsPtr, DefineButton, DefineButton2, DefineFont, DefineFont2, DefineImage, DefineImage2, DefineJPEGImage, DefineJPEGImage2, DefineJPEGImage3, DefineMorphShape, DefineMovieClip, DefineShape, DefineShape2, DefineShape3, DefineSound, DefineText, DefineText2, DefineTextField, DefineVideo, DoAction, EnableDebugger, EnableDebugger2, Export, extendLength, FontInfo, FontInfo2, FrameLabel, Free, Import, Initialize, JPEGTables, length, LimitScript, PathsArePostscript, PlaceObject, PlaceObject2, Protect, QuicktimeMovie, RemoveObject, RemoveObject2, SerialNumber, SetBackgroundColor, ShowFrame, SoundStreamBlock, SoundStreamHead, SoundStreamHead2, StartSound, TabOrder, type, VideoFrame
 
Constructor Summary
FSDefineJPEGImage3(FSCoder coder)
          Construct an FSDefineJPEGImage3 object, initialising it with values decoded from an encoded object.
FSDefineJPEGImage3(FSDefineJPEGImage3 obj)
          Constructs an FSDefineJPEGImage object by copying values from an existing object.
FSDefineJPEGImage3(int anIdentifier, byte[] imageBytes, byte[] encodingBytes, byte[] alphaBytes)
          Constructs an FSDefineJPEGImage3 object with the specified image data, encoding table and alpha channel data.
 
Method Summary
 void appendDescription(java.lang.StringBuffer buffer, int depth)
          AppendDescription is used to present a string description of the object including all nested objects up to a specified depth.
 java.lang.Object clone()
          Creates a deep copy of the entire object.
 void decode(FSCoder coder)
           
 void encode(FSCoder coder)
           
 boolean equals(java.lang.Object anObject)
          Returns true if anObject is equal to this one.
 byte[] getCompressedAlpha()
          Gets the alpha channel data.
 byte[] getEncodingTable()
          Gets the encoding table.
 int getHeight()
          Gets the height of the image in pixels.
 byte[] getImage()
          Gets the image data.
 int getWidth()
          Gets the width of the image in pixels.
 int length(FSCoder coder)
           
 void setCompressedAlpha(byte[] bytes)
          Sets the alpha channel data with the zlib compressed data.
 void setEncodingTable(byte[] bytes)
          Sets the encoding table.
 void setImage(byte[] bytes)
          Sets the image data.
 
Methods inherited from class com.flagstone.transform.FSDefineObject
getIdentifier, setIdentifier
 
Methods inherited from class com.flagstone.transform.FSMovieObject
getType
 
Methods inherited from class com.flagstone.transform.FSTransformObject
name, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FSDefineJPEGImage3

public FSDefineJPEGImage3(FSCoder coder)
Construct an FSDefineJPEGImage3 object, initialising it with values decoded from an encoded object.

Parameters:
coder - an FSCoder containing the binary data.

FSDefineJPEGImage3

public FSDefineJPEGImage3(int anIdentifier,
                          byte[] imageBytes,
                          byte[] encodingBytes,
                          byte[] alphaBytes)
Constructs an FSDefineJPEGImage3 object with the specified image data, encoding table and alpha channel data.

Parameters:
anIdentifier - the unique identifier for this object
imageBytes - byte array containing the image data
encodingBytes - byte array containing the encoding table
alphaBytes - byte array containing the zlib compressed alpha channel data

FSDefineJPEGImage3

public FSDefineJPEGImage3(FSDefineJPEGImage3 obj)
Constructs an FSDefineJPEGImage object by copying values from an existing object.

Parameters:
obj - an FSDefineJPEGImage object.
Method Detail

getEncodingTable

public byte[] getEncodingTable()
Gets the encoding table.

Returns:
the array of bytes containing the encoding table.

getWidth

public int getWidth()
Gets the width of the image in pixels.

Returns:
the width of the image.

getHeight

public int getHeight()
Gets the height of the image in pixels.

Returns:
the height of the image in pixels.

getImage

public byte[] getImage()
Gets the image data.

Returns:
the array of bytes containing the image data.

getCompressedAlpha

public byte[] getCompressedAlpha()
Gets the alpha channel data.

Returns:
the array of bytes containing the zlib compressed alpha data.

setEncodingTable

public void setEncodingTable(byte[] bytes)
Sets the encoding table.

Parameters:
bytes - byte array containing the encoding table.

setImage

public void setImage(byte[] bytes)
Sets the image data.

Parameters:
bytes - an array of bytes containing the image table.

setCompressedAlpha

public void setCompressedAlpha(byte[] bytes)
Sets the alpha channel data with the zlib compressed data.

Parameters:
bytes - array of bytes containing zlib encoded alpha channel.

clone

public java.lang.Object clone()
Description copied from class: FSTransformObject
Creates a deep copy of the entire object.

Overrides:
clone in class FSTransformObject
Returns:
a copy of the object.

equals

public boolean equals(java.lang.Object anObject)
Description copied from class: FSMovieObject
Returns true if anObject is equal to this one. Objects are considered equal if they would generate identical binary data when they are encoded to a Flash file.

Overrides:
equals in class FSMovieObject
Returns:
true if this object would be identical to anObject when encoded.

appendDescription

public void appendDescription(java.lang.StringBuffer buffer,
                              int depth)
Description copied from class: FSTransformObject
AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. This method provide a more controlled way of creating a string representation of an object since large objects such as font or shape definitions can contain dozens of nested objects. The representation of the object is appended to the StringBuffer, showing the name of the class and values of the attributes it contains. If the object contains any attributes that are objects then the object graph will be traversed up to the specified depth. If objects are nested at a level less than specified depth then the full string representation of the object is displayed. For objects at the specified depth only the name of the class is displayed. Any objects below this depth are not displayed.

Overrides:
appendDescription in class FSDefineObject
Parameters:
buffer - a StringBuffer to which the description of each object is appended.
depth - the maximum level of nesting up to which objects will be displayed.

length

public int length(FSCoder coder)
Overrides:
length in class FSDefineObject

encode

public void encode(FSCoder coder)
Overrides:
encode in class FSDefineObject

decode

public void decode(FSCoder coder)
Overrides:
decode in class FSDefineObject