rebuild.graphics
Class ImageEncoder

java.lang.Object
  extended by rebuild.graphics.ImageEncoder
Direct Known Subclasses:
JPEGEncoder, PNGEncoder, TIFFEncoder, WBMPEncoder

public abstract class ImageEncoder
extends java.lang.Object

The base abstract class that represents an image encoder.

Since:
BBX 1.0.1

Field Summary
protected  int compressionLevel
          The compression level.
protected  byte[] dataBytes
          The encoded bytes.
protected  boolean encodeAlpha
          Encode alpha?
protected  int height
          The height of the image.
protected  Bitmap image
          The image.
protected  int scaleX
          The scale of the image in the horizontal orientation.
protected  int scaleY
          The scale of the image in the vertical orientation.
protected  int width
          The width of the image.
protected  int xOffset
          The offset of the x origin point of the image.
protected  int yOffset
          The offset of the y origin point of the image.
 
Constructor Summary
protected ImageEncoder(Bitmap image, boolean encodeAlpha)
          Class constructor specifying Bitmap to encode, and whether to encode alpha.
protected ImageEncoder(Bitmap image, boolean encodeAlpha, int compressionLevel)
          Class constructor specifying Bitmap to encode, and whether to encode alpha.
protected ImageEncoder(Bitmap image, java.lang.String mime)
          Class constructor specifying Bitmap to encode, with no alpha channel encoding.
protected ImageEncoder(java.lang.String mime)
          Class constructor
 
Method Summary
 byte[] encode()
          Encode an image in a specific format.
 byte[] encode(boolean encodeAlpha)
          Encode an image in a specific format.
protected  byte[] getARGBByte(int offset, int stride, XYRect source)
          Get the ARGB data of the image in a byte array.
protected  int[] getARGBInt(int offset, int stride, XYRect source)
          Get the ARGB data of the image in a int array.
 int getCompressionLevel()
          Retrieve compression level.
 boolean getEncodeAlpha()
          Retrieve alpha encoding status.
protected  int getIndex(int x, int y, int offset)
          Get index into the int array in getARGBInt(int, int, XYRect).
protected static int getIndex(int x, int y, int width, int height, int offset)
          Get index into the int array in getARGBInt(int, int, XYRect).
abstract  java.lang.String getMime()
          Get the MIME type of the image encoder.
protected abstract  byte[] inEncode(boolean encodeAlpha)
          Encode an image in a specific format.
 void setCompressionLevel(int level)
          Set the compression level to use.
 void setEncodeAlpha(boolean encodeAlpha)
          Set the alpha encoding on or off.
 void setImage(Bitmap image)
          Set the image to be encoded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataBytes

protected byte[] dataBytes
The encoded bytes.


image

protected Bitmap image
The image.


width

protected int width
The width of the image.


height

protected int height
The height of the image.


encodeAlpha

protected boolean encodeAlpha
Encode alpha?


compressionLevel

protected int compressionLevel
The compression level.


scaleX

protected int scaleX
The scale of the image in the horizontal orientation. Scale is defined as an int where 1 is the same width well 2 is two times the width.


scaleY

protected int scaleY
The scale of the image in the vertical orientation. Scale is defined as an int where 1 is the same height well 2 is two times the height.


xOffset

protected int xOffset
The offset of the x origin point of the image.


yOffset

protected int yOffset
The offset of the y origin point of the image.

Constructor Detail

ImageEncoder

protected ImageEncoder(java.lang.String mime)
Class constructor


ImageEncoder

protected ImageEncoder(Bitmap image,
                       java.lang.String mime)
Class constructor specifying Bitmap to encode, with no alpha channel encoding.

Parameters:
image - A Java Image object which uses the DirectColorModel.

ImageEncoder

protected ImageEncoder(Bitmap image,
                       boolean encodeAlpha)
Class constructor specifying Bitmap to encode, and whether to encode alpha.

Parameters:
image - A Java Image object which uses the DirectColorModel
encodeAlpha - Encode the alpha channel? false = no; true = yes

ImageEncoder

protected ImageEncoder(Bitmap image,
                       boolean encodeAlpha,
                       int compressionLevel)
Class constructor specifying Bitmap to encode, and whether to encode alpha.

Parameters:
image - A Java Image object which uses the DirectColorModel
encodeAlpha - Encode the alpha channel? false = no; true = yes
compressionLevel - The compression level of the image encoder.
Method Detail

getMime

public abstract java.lang.String getMime()
Get the MIME type of the image encoder.

Returns:
The MIME type of the image encoder.

encode

public final byte[] encode(boolean encodeAlpha)
                    throws java.io.IOException
Encode an image in a specific format.

Parameters:
encodeAlpha - True if alpha should be encoded.
Returns:
The encoded data.
Throws:
java.io.IOException - If an error occurs.

inEncode

protected abstract byte[] inEncode(boolean encodeAlpha)
                            throws java.io.IOException
Encode an image in a specific format.

Parameters:
encodeAlpha - True if alpha should be encoded.
Returns:
The encoded data.
Throws:
java.io.IOException - If an error occurs.

setImage

public final void setImage(Bitmap image)
Set the image to be encoded.

Parameters:
image - A Java Image object which uses the DirectColorModel.

setEncodeAlpha

public final void setEncodeAlpha(boolean encodeAlpha)
Set the alpha encoding on or off.

Parameters:
encodeAlpha - false = no, true = yes

getEncodeAlpha

public final boolean getEncodeAlpha()
Retrieve alpha encoding status.

Returns:
boolean false = no, true = yes

encode

public final byte[] encode()
                    throws java.io.IOException
Encode an image in a specific format.

Returns:
The encoded data.
Throws:
java.io.IOException - If an error occurs.

getCompressionLevel

public final int getCompressionLevel()
Retrieve compression level.

Returns:
int representing the compression level.

setCompressionLevel

public void setCompressionLevel(int level)
Set the compression level to use.

Parameters:
The - compression level to set.

getARGBInt

protected int[] getARGBInt(int offset,
                           int stride,
                           XYRect source)
Get the ARGB data of the image in a int array.

Parameters:
offset - The offset into the array to save the data.
stride - The stride to save the image, should be at least the width of the image.
source - The source size of the image.
Returns:
The array of ARGB data.

getIndex

protected int getIndex(int x,
                       int y,
                       int offset)
Get index into the int array in getARGBInt(int, int, XYRect).

Parameters:
x - The X location of the image.
y - The Y location of the image.
offset - The offset for the array.
Returns:
The zero based index into the int array.
See Also:
getARGBInt(int, int, XYRect), getIndex(int, int, int, int, int)

getIndex

protected static int getIndex(int x,
                              int y,
                              int width,
                              int height,
                              int offset)
Get index into the int array in getARGBInt(int, int, XYRect).

Parameters:
x - The X location of the image.
y - The Y location of the image.
width - The width of the image.
height - The height of the image.
offset - The offset for the array.
Returns:
The zero based index into the int array.
See Also:
getARGBInt(int, int, XYRect), getIndex(int, int, int)

getARGBByte

protected byte[] getARGBByte(int offset,
                             int stride,
                             XYRect source)
Get the ARGB data of the image in a byte array.

Parameters:
offset - The offset into the array to save the data.
stride - The stride to save the image, should be at least the width of the image.
source - The source size of the image.
Returns:
The array of ARGB data.