com.tensegrity.graphics.image
Class Raster

java.lang.Object
  extended bycom.tensegrity.graphics.image.Raster

public class Raster
extends java.lang.Object

The Raster class representation an image within the graphic API.

Version:
$Id: Raster.java,v 1.17 2005/04/01 15:42:39 MichaelKegel Exp $
Author:
MichaelKegel

Field Summary
static int A_AND_B
          constant that tells about a blitting code
protected  int alpha
          instance variable for the alpha value of each pixel
static int ARGB
          constant that tells about a type of the Raster
protected  int[] colors
          instance variable for the used colors (only used for indexed type)
protected  int height
          instance variable for the height of the Raster
static int INDEXED
          constant that tells about a type of the Raster
protected  int[][] rasterData
          instance variable for the pixels of the Raster
static int SRC_COPY
          constant that tells about a blitting code
protected  double transparency
          instance variable for the transparency level of the Raster
protected  int type
          instance variable for the type of the Raster
protected  int usedBitCount
          instance variable for the used bit count (integer based) of the Raster
protected  int width
          instance variable for the width of the Raster
 
Constructor Summary
Raster(int width, int height, int colors)
          Constructor specifying the width, the height and the number of colors.
Raster(int width, int height, int[] colors)
          Constructor specifying the width, the height and the colors to be used.
Raster(int width, int height, int[][] rasterData, int[] colors)
          Constructor specifying the width, the height, an array with the data for this Raster and the colors to be used.
 
Method Summary
 void blt(Raster raster, int bltCode)
          Performs a blit operation with the Raster given by raster.
static void blt(Raster dest, Raster sourceA, Raster sourceB, int bltCode)
          Performs a blit operation onto the two Rasters given by sourceA and sourceB.
 void clear()
          Clear the complete Raster.
 void create(int width, int height)
          (Re)Creates the Raster with the given width and height.
protected  void createRaster()
          Creates a two dimensional array that is large enough to keep all pixel values for the given with and height.
static Raster decode(java.lang.String encodedString)
          Decodes a string which has been previously create by the encode() method.
static Raster decode(java.lang.String encodedString, boolean compressed)
          Decodes a string which has been previously create by the encode() method.
 void dispose()
          Disposes all internally created data.
 java.lang.String encode()
          Encodes the internal raster data by using a base64 encoded zip stream.
 java.lang.String encode(boolean compress)
          Encodes the internal raster data by using a base64 encoded zip stream.
 boolean equals(java.lang.Object o)
           
 void fill(int rgb)
          Fills the complete Raster with pixels that have red-, green- and blue-values specified by the integer representation of a color given by RGB but have no alpha value.
 void fill(int r, int g, int b)
          Fills the complete Raster with pixels that have red-, green- and blue-values specified by r, g and b but have no alpha value.
 int get(int x, int y)
          Returns the integer representation of the pixel specified through the coordinate given by x and y
NOTICE: The alpha value for the specified pixel is omitted.
 int getAlpha()
          Returns the Alpha-value for this Raster.
 int getB(int x, int y)
          Returns the blue-value for the pixel specified through the coordinate given by x and y.
 int getColorIndex(int x, int y)
          Returns the index for the color of the pixel specified through the coordinate given by x and y.
protected  int getDivider()
          Returns the divider that is necessary to shift an integer such that one comes to the next pixel within an integer value.
 int getG(int x, int y)
          Returns the green-value for the pixel specified through the coordinate given by x and y.
 int getHeight()
          Returns the height of this Raster.
 int getIndexedColor(int index)
          Returns the integer representation of the color at the given index.
protected  int getMask(int position)
          Returns the bitmask that is necessary to bitmask a single pixel within an integer value.
 int getR(int x, int y)
          Returns the red-value for the pixel specified through the coordinate given by x and y.
 int getTransparency()
          Returns the transparency of this Raster.
protected  int getUsedBits(int colors)
          Returns an integer that indicates how many bit per an integer are used when using the number of color given by colors.
 int getWidth()
          Returns the width of this Raster.
 boolean hasColor(int rgb)
          Returns a boolean that indicates whether the color specified through the integer representation given by RGB is used in the Raster.
 int hashCode()
          No custom code for calculating a hash code is used here, rather System.identityHashCode(java.lang.Object) is called and returned.
 int indexOf(int rgb)
          Returns the index of the color specified through RGB.
 void set(int x, int y, int rgb)
          Sets the red-value, green-value and the blue-value of the pixel specified through the coordinate given by x and y to the integer representation given by RGB.
 void set(int x, int y, int r, int g, int b)
          Sets the red-value, green-value and the blue-value of the pixel specified through the coordinate given by x and y to the values given by r, g and b.
 void setB(int x, int y, int blue)
          Sets the blue-value for the pixel specified through the coordinate given by x and y to the blue-value given by blue.
 void setColorIndex(int x, int y, int index)
          Sets the index of the pixel specified through the coordinate given by x and y to the index given by index.
 void setG(int x, int y, int green)
          Sets the green-value for the pixel specified through the coordinate given by x and y to the green-value given by green.
 void setIndexedColor(int index, int rgb)
          Sets the integer representation of a color given by RGB at the index given by index.
 void setR(int x, int y, int red)
          Sets the red-value for the pixel specified through the coordinate given by x and y to the red-value given by red.
 void setTransparency(int transparency)
          Sets the transparency of this Raster.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INDEXED

public static final int INDEXED
constant that tells about a type of the Raster

See Also:
Constant Field Values

ARGB

public static final int ARGB
constant that tells about a type of the Raster

See Also:
Constant Field Values

A_AND_B

public static final int A_AND_B
constant that tells about a blitting code

See Also:
Constant Field Values

SRC_COPY

public static final int SRC_COPY
constant that tells about a blitting code

See Also:
Constant Field Values

width

protected int width
instance variable for the width of the Raster


height

protected int height
instance variable for the height of the Raster


type

protected int type
instance variable for the type of the Raster


usedBitCount

protected int usedBitCount
instance variable for the used bit count (integer based) of the Raster


colors

protected int[] colors
instance variable for the used colors (only used for indexed type)


rasterData

protected int[][] rasterData
instance variable for the pixels of the Raster


transparency

protected double transparency
instance variable for the transparency level of the Raster


alpha

protected int alpha
instance variable for the alpha value of each pixel

Constructor Detail

Raster

public Raster(int width,
              int height,
              int colors)
Constructor specifying the width, the height and the number of colors.

Parameters:
width - the width of this Raster.
height - the height of this Raster.
colors - the number of colors to use.

Raster

public Raster(int width,
              int height,
              int[] colors)
Constructor specifying the width, the height and the colors to be used.

Parameters:
width - the width of this Raster.
height - the height of this Raster.
colors - an array specifying the colors to be used.

Raster

public Raster(int width,
              int height,
              int[][] rasterData,
              int[] colors)
Constructor specifying the width, the height, an array with the data for this Raster and the colors to be used.

Parameters:
width - the width of this Raster.
height - the height of this Raster.
rasterData - a two-dimensional array holding the data for this Raster.
colors - an array specifying the colors to be used.
Method Detail

getWidth

public int getWidth()
Returns the width of this Raster.

Returns:
the width of this Raster.

getHeight

public int getHeight()
Returns the height of this Raster.

Returns:
the height of this Raster.

getTransparency

public int getTransparency()
Returns the transparency of this Raster.

Returns:
the transparency of this Raster.

setTransparency

public void setTransparency(int transparency)
Sets the transparency of this Raster.

Parameters:
transparency - the transparency of this Raster.

encode

public java.lang.String encode()
Encodes the internal raster data by using a base64 encoded zip stream. The resulting OutputStream will contain the width, height, color list and the raster data.

Returns:
a String containing the zipped base64 encoded data.

encode

public java.lang.String encode(boolean compress)
Encodes the internal raster data by using a base64 encoded zip stream. The resulting OutputStream will contain the width, height, color list and the raster data.

Parameters:
compress - true, to gzip the bytes before base64 encoding
Returns:
a String containing the zipped base64 encoded data.

decode

public static Raster decode(java.lang.String encodedString)
Decodes a string which has been previously create by the encode() method.

Parameters:
encodedString - an encoded String
Returns:
an instance of class Raster

decode

public static Raster decode(java.lang.String encodedString,
                            boolean compressed)
Decodes a string which has been previously create by the encode() method.

Parameters:
encodedString - an encoded String
compressed - true, if the given encoded data is compressed
Returns:
an instance of class Raster

getAlpha

public int getAlpha()
Returns the Alpha-value for this Raster.

Returns:
the Alpha-value for this Raster.

getR

public int getR(int x,
                int y)
Returns the red-value for the pixel specified through the coordinate given by x and y.

Parameters:
x - x component of the pixel to return the red-value for
y - y component of the pixel to return the red-value for
Returns:
int the red-value of the specified pixel

setR

public void setR(int x,
                 int y,
                 int red)
Sets the red-value for the pixel specified through the coordinate given by x and y to the red-value given by red.

Parameters:
x - x component of the pixel to return the red-value for
y - y component of the pixel to return the red-value for
red - the new red-value for the specified pixel

getG

public int getG(int x,
                int y)
Returns the green-value for the pixel specified through the coordinate given by x and y.

Parameters:
x - x component of the pixel to return the red-value for
y - y component of the pixel to return the red-value for
Returns:
int the green-value of the specified pixel

setG

public void setG(int x,
                 int y,
                 int green)
Sets the green-value for the pixel specified through the coordinate given by x and y to the green-value given by green.

Parameters:
x - x component of the pixel to return the green-value for
y - y component of the pixel to return the green-value for
green - the new green-value for the specified pixel

getB

public int getB(int x,
                int y)
Returns the blue-value for the pixel specified through the coordinate given by x and y.

Parameters:
x - x component of the pixel to return the blue-value for
y - y component of the pixel to return the blue-value for
Returns:
int the blue-value of the specified pixel

setB

public void setB(int x,
                 int y,
                 int blue)
Sets the blue-value for the pixel specified through the coordinate given by x and y to the blue-value given by blue.

Parameters:
x - x component of the pixel to return the blue-value for
y - y component of the pixel to return the blue-value for
blue - the new blue-value for the specified pixel

get

public int get(int x,
               int y)
Returns the integer representation of the pixel specified through the coordinate given by x and y
NOTICE: The alpha value for the specified pixel is omitted.

Parameters:
x - x component of the pixel to return the integer representation for
y - y component of the pixel to return the integer representation for
Returns:
int the integer representation of the specified pixel

set

public void set(int x,
                int y,
                int r,
                int g,
                int b)
Sets the red-value, green-value and the blue-value of the pixel specified through the coordinate given by x and y to the values given by r, g and b.

Parameters:
x - x component of the pixel to set the new values to
y - y component of the pixel to set the new values to
r - the new red-value for the specified pixel
g - the new green-value for the specified pixel
b - the new blue-value for the specified pixel

set

public void set(int x,
                int y,
                int rgb)
Sets the red-value, green-value and the blue-value of the pixel specified through the coordinate given by x and y to the integer representation given by RGB.
NOTICE: Alpha values are allowed.

Parameters:
x - x component of the pixel to set the new values to
y - y component of the pixel to set the new values to
rgb - the new integer representation of the specified pixel

indexOf

public int indexOf(int rgb)
Returns the index of the color specified through RGB.
NOTICE:This method belongs to an indexed Raster

Parameters:
rgb - the integer representation of the color to return the index for
Returns:
int the index of the specified color

hasColor

public boolean hasColor(int rgb)
Returns a boolean that indicates whether the color specified through the integer representation given by RGB is used in the Raster.
NOTICE:This method belongs to an indexed Raster

Parameters:
rgb - the integer representation of the color to check usage for
Returns:
boolean flag that indicates the usage of the specified color in the Raster

getColorIndex

public int getColorIndex(int x,
                         int y)
Returns the index for the color of the pixel specified through the coordinate given by x and y.
NOTICE:This method belongs to an indexed Raster

Parameters:
x - x component of the pixel to return the color index for
y - y component of the pixel to return the color index for
Returns:
int the index for the color of the pixel at the given coordinate

setColorIndex

public void setColorIndex(int x,
                          int y,
                          int index)
Sets the index of the pixel specified through the coordinate given by x and y to the index given by index.
NOTICE:The index is the index of a color for the Raster
NOTICE:This method belongs to an indexed Raster

Parameters:
x - x component of the pixel to set the color index for
y - y component of the pixel to set the color index for
index - the new color index for the pixel at the given coordinate

getIndexedColor

public int getIndexedColor(int index)
Returns the integer representation of the color at the given index.
NOTICE:This method belongs to an indexed Raster

Parameters:
index - the index to return the color for
Returns:
int the integer representation of the color

setIndexedColor

public void setIndexedColor(int index,
                            int rgb)
Sets the integer representation of a color given by RGB at the index given by index.
NOTICE:This method belongs to an indexed Raster

Parameters:
index - the index to set the integer representation of a color at
rgb - the new integer representation of a color to set

clear

public void clear()
Clear the complete Raster. This means the complete Raster is filled up with black pixels that have no alpha value.


fill

public void fill(int r,
                 int g,
                 int b)
Fills the complete Raster with pixels that have red-, green- and blue-values specified by r, g and b but have no alpha value.

Parameters:
r - the red-value for the pixels to fill the Raster with
g - the green-value for the pixels to fill the Raster with
b - the blue-value for the pixels to fill the Raster with

fill

public void fill(int rgb)
Fills the complete Raster with pixels that have red-, green- and blue-values specified by the integer representation of a color given by RGB but have no alpha value.

Parameters:
rgb - the new integer representation of a color for the pixels to fill the Raster with

blt

public void blt(Raster raster,
                int bltCode)
Performs a blit operation with the Raster given by raster. The two Rasters are combined with respect to the blit mode given by bltCode. The different blit modes Raster supports are defines through constants in this class.

Parameters:
raster - the Raster to combine this raster with
bltCode - the blit mode to use

create

public void create(int width,
                   int height)
(Re)Creates the Raster with the given width and height.

Parameters:
width - the new width for the Raster
height - the new height for the Raster

dispose

public void dispose()
Disposes all internally created data.


toString

public java.lang.String toString()

hashCode

public int hashCode()
No custom code for calculating a hash code is used here, rather System.identityHashCode(java.lang.Object) is called and returned.


equals

public boolean equals(java.lang.Object o)

createRaster

protected void createRaster()
Creates a two dimensional array that is large enough to keep all pixel values for the given with and height.
NOTICE:The size of the two dimensional array depends on the used raster model. For a ARGB raster it is exactly the width multiplied by the height. For an INDEXED raster the size depends an the with, height and the count of used colors.


getUsedBits

protected int getUsedBits(int colors)
Returns an integer that indicates how many bit per an integer are used when using the number of color given by colors.

Parameters:
colors - the number of used colors
Returns:
int the number of used bits to represent the given number of colors

getDivider

protected int getDivider()
Returns the divider that is necessary to shift an integer such that one comes to the next pixel within an integer value. This method is only used for an INDEXED raster.

Returns:
int the divider

getMask

protected int getMask(int position)
Returns the bitmask that is necessary to bitmask a single pixel within an integer value. This method is only used for an INDEXED raster. This given position indicates for what pixel to create the bitmask.

Parameters:
position - the pixel within an integer value the bitmask should be created for
Returns:
int the corresponding bitmask

blt

public static void blt(Raster dest,
                       Raster sourceA,
                       Raster sourceB,
                       int bltCode)
Performs a blit operation onto the two Rasters given by sourceA and sourceB. The two Rasters are combined with respect to the blit mode given by bltCode. The different blit modes Raster supports are defines through constants in this class.

Parameters:
sourceA - the Raster to combine the second Raster with (destination)
sourceB - the Raster to combine the first Raster with (source only)
bltCode - the blit mode to use


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.