cz.cuni.jagrlib.piece
Class AlphaMatrix

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.AlphaMatrix
All Implemented Interfaces:
Breakable, AlphaMask, BitMask, BitMaskCore, Property, Template

public class AlphaMatrix
extends Piece
implements AlphaMask

Alpha-mask represented by simple rectangular matrix.

Since:
0.06
See Also:
AlphaMatrix.java

Nested Class Summary
 class AlphaMatrix.AlphaMatrixEnumerator
          Special Enumerator for AlphaMatrix.
 
Field Summary
protected  byte ALPHA_MAX
          Maximum alpha-value (total opaqueness).
protected  int ALPHA_RANGE
          Alpha-value range.
protected  byte ALPHA_ZERO
          Minimum alpha-value (total transparency).
protected  int alphaOp
          Actual alpha-channel operation (not used yet).
protected  int binaryOp
          Actual binary set operation (not used yet).
protected static java.lang.String CATEGORY
          Object category.
protected  byte currentAlpha
          Current alpha-value (for BitMask-inherited routines.
protected  byte[][] data
          2D array of alpha-values.
static RegPiece reg
          Static registration instance for this class.
protected  int setHeight
          Height of the domain in pixels.
protected  int setWidth
          Width of the domain in pixels.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
protected  int xMax
          Maximum x-coordinate + 1.
protected  int xMin
          Minimum x-coordinate.
protected  int yMax
          Maximum scanline coordinate + 1.
protected  int yMin
          Minimum scanline coordinate.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.BitMask
HEIGHT, WIDTH
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
AlphaMatrix()
           
 
Method Summary
protected  void assertXY(int x, int y)
          Asserts that the given point [x,y] is included in the set.
 void bitBlt(int dx, int dy, int sx, int sy, int width, int height)
          Bit-block-transfer routine: copies the source rectangle [sx,sy,width,height] to the new location [dx,dy].
 void commit()
          Commits all previous changes to the internal object state.
protected  byte composeAlpha(int A, int B)
          Realizes the alpha-channel composition.
 BitMaskEnumerator enumerator()
          BitMask enumeration.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 double getAlpha(int x, int y)
          Returns the pixel's value.
 void getHLine(int x1, int x2, int y, boolean[] values)
          Returns the pixels' values for the given horizontal line.
 void getHLine(int x1, int x2, int y, double[] alpha)
          Returns the pixels' values for the given horizontal line.
 boolean getPixel(int x, int y)
          Returns the pixel's value.
 void getRectangle(int x1, int y1, int x2, int y2, boolean[][] values)
          Returns the pixels' values for the given rectangle.
 void getRectangle(int x1, int y1, int x2, int y2, double[][] alpha)
          Returns the pixels' values for the given rectangle.
 void init()
          AlphaMatrix re-initialization (keeps current bitmask size - if the size is relevant).
 void init(int x, int y)
          AlphaMatrix (re-)initialization.
protected  void initMatrix()
          (Re-)initializes the whole "data" matrix.
 void putHLine(int x1, int x2, int y, boolean[] values)
          Sets the horizontal line'a values.
 void putHLine(int x1, int x2, int y, double[] alpha)
          Sets the horizontal line's values.
 void putPixel(int x, int y, boolean value)
          Sets the given pixel's value.
 void putPixel(int x, int y, double alpha)
          Sets the given pixel's value to alpha.
 void putRectangle(int x1, int y1, int x2, int y2, boolean[][] values)
          Sets the rectangle's values.
 void putRectangle(int x1, int y1, int x2, int y2, double[][] alpha)
          Sets the rectangle's values.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
 void setAlpha(double alpha)
          Sets the current default alpha - for inherited methods.
 int setAlphaOperation(int _op)
          Sets the alpha-channel operation (used in all set*() methods).
 void setHLine(int x1, int x2, int y)
          Sets the horizontal line from [min(x1,x2),y] to [max(x1,x2)-1,y].
 void setHLine(int x1, int x2, int y, double alpha)
          Sets the horizontal line from [min(x1,x2),y] to [max(x1,x2)-1,y].
 int setOperation(int _op)
          Sets the binary set operation (used in all set*() methods).
 void setPixel(int x, int y)
          Sets the given pixel's value to true = "painted".
 void setRectangle(int x1, int y1, int x2, int y2)
          Sets the rectangle from [min(x1,x2),min(y1,y2)] to [max(x1,x2)-1,max(y1,y2)-1].
 void setRectangle(int x1, int y1, int x2, int y2, double alpha)
          Sets the rectangle from [min(x1,x2),min(y1,y2)] to [max(x1,x2)-1,max(y1,y2)-1].
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALPHA_ZERO

protected final byte ALPHA_ZERO
Minimum alpha-value (total transparency).

See Also:
Constant Field Values

ALPHA_MAX

protected final byte ALPHA_MAX
Maximum alpha-value (total opaqueness).

See Also:
Constant Field Values

ALPHA_RANGE

protected final int ALPHA_RANGE
Alpha-value range.

See Also:
Constant Field Values

setWidth

protected int setWidth
Width of the domain in pixels.


setHeight

protected int setHeight
Height of the domain in pixels.


xMin

protected int xMin
Minimum x-coordinate.


xMax

protected int xMax
Maximum x-coordinate + 1.


yMin

protected int yMin
Minimum scanline coordinate.


yMax

protected int yMax
Maximum scanline coordinate + 1.


data

protected byte[][] data
2D array of alpha-values.


currentAlpha

protected byte currentAlpha
Current alpha-value (for BitMask-inherited routines.


binaryOp

protected int binaryOp
Actual binary set operation (not used yet).


alphaOp

protected int alphaOp
Actual alpha-channel operation (not used yet).


TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

AlphaMatrix

public AlphaMatrix()
Method Detail

initMatrix

protected void initMatrix()
(Re-)initializes the whole "data" matrix.


assertXY

protected void assertXY(int x,
                        int y)
Asserts that the given point [x,y] is included in the set.

Parameters:
x - X coordinate to be included.
y - Y coordinate to be included.

composeAlpha

protected final byte composeAlpha(int A,
                                  int B)
Realizes the alpha-channel composition. Uses the current alpha-value.

Parameters:
A - Original (old) alpha-value.
B - Assigned (new) alpha-value.
Returns:
The compound (result) alpha-value.

init

public void init(int x,
                 int y)
AlphaMatrix (re-)initialization.

Specified by:
init in interface BitMaskCore
Parameters:
x - Width of a new bitmask.
y - Height of a new bitmask.

init

public void init()
AlphaMatrix re-initialization (keeps current bitmask size - if the size is relevant).

Specified by:
init in interface BitMaskCore

setOperation

public int setOperation(int _op)
Sets the binary set operation (used in all set*() methods).

Specified by:
setOperation in interface BitMask
Parameters:
_op - Binary set operation (BinaryOperation.BIN_OP_* constant).
Returns:
The old binary set operation.
See Also:
Binary operations

setAlphaOperation

public int setAlphaOperation(int _op)
Sets the alpha-channel operation (used in all set*() methods).

Specified by:
setAlphaOperation in interface AlphaMask
Parameters:
_op - Alpha-channel operation (AlphaOperation.ALPHA_* constant).
Returns:
The old alpha-channel operation.
See Also:
Alpha-channel operations

setPixel

public void setPixel(int x,
                     int y)
Sets the given pixel's value to true = "painted".

Specified by:
setPixel in interface BitMaskCore
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.

putPixel

public void putPixel(int x,
                     int y,
                     boolean value)
Sets the given pixel's value.

Specified by:
putPixel in interface BitMask
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
value - New pixel's value.

getPixel

public boolean getPixel(int x,
                        int y)
Returns the pixel's value.

Specified by:
getPixel in interface BitMaskCore
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
Returns:
Pixel value (false for off-canvas access).

setHLine

public void setHLine(int x1,
                     int x2,
                     int y)
Sets the horizontal line from [min(x1,x2),y] to [max(x1,x2)-1,y].

Specified by:
setHLine in interface BitMaskCore
Parameters:
x1 - X coordinate of the starting pixel.
x2 - X coordinate of the first pixel after the line.
y - Common Y coordinate of the line.

putHLine

public void putHLine(int x1,
                     int x2,
                     int y,
                     boolean[] values)
Sets the horizontal line'a values.

Specified by:
putHLine in interface BitMask
Parameters:
x1 - X coordinate of the starting pixel.
x2 - X coordinate of the first pixel after the line.
y - Common Y coordinate of the line.
values - New pixels' values.

getHLine

public void getHLine(int x1,
                     int x2,
                     int y,
                     boolean[] values)
Returns the pixels' values for the given horizontal line.

Specified by:
getHLine in interface BitMask
Parameters:
x1 - X coordinate of the starting pixel.
x2 - X coordinate of the first pixel after the line.
y - Common Y coordinate of the line.
values - Returned values in boolean[] array (false for off-canvas access).

setRectangle

public void setRectangle(int x1,
                         int y1,
                         int x2,
                         int y2)
Sets the rectangle from [min(x1,x2),min(y1,y2)] to [max(x1,x2)-1,max(y1,y2)-1].

Specified by:
setRectangle in interface BitMask
Parameters:
x1 - X coordinate of the upper left corner.
y1 - Y coordinate of the upper left corner.
x2 - X coordinate of the lower right corner (outside pixel).
y2 - Y coordinate of the upper left corner (outside pixel).

putRectangle

public void putRectangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         boolean[][] values)
Sets the rectangle's values.

Specified by:
putRectangle in interface BitMask
Parameters:
x1 - X coordinate of the upper left corner.
y1 - Y coordinate of the upper left corner.
x2 - X coordinate of the lower right corner (outside pixel).
y2 - Y coordinate of the upper left corner (outside pixel).
values - New pixels' values.

getRectangle

public void getRectangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         boolean[][] values)
Returns the pixels' values for the given rectangle.

Specified by:
getRectangle in interface BitMask
Parameters:
x1 - X coordinate of the upper left corner.
y1 - Y coordinate of the upper left corner.
x2 - X coordinate of the lower right corner (outside pixel).
y2 - Y coordinate of the upper left corner (outside pixel).
values - Returned values in boolean[][] array (false for off-canvas access).

bitBlt

public void bitBlt(int dx,
                   int dy,
                   int sx,
                   int sy,
                   int width,
                   int height)
Bit-block-transfer routine: copies the source rectangle [sx,sy,width,height] to the new location [dx,dy]. Binary set operation is ignored.

Specified by:
bitBlt in interface BitMask
Parameters:
dx - X coordinate of the upper left destination corner.
dy - Y coordinate of the upper left destination corner.
sx - X coordinate of the upper left source corner.
sy - Y coordinate of the upper left source corner.
width - Rectangle width.
height - Rectangle height.

enumerator

public BitMaskEnumerator enumerator()
BitMask enumeration.

Specified by:
enumerator in interface BitMaskCore
Returns:
The BitMaskEnumerator object instance.

setAlpha

public void setAlpha(double alpha)
Sets the current default alpha - for inherited methods.

Specified by:
setAlpha in interface AlphaMask
Parameters:
alpha - Opacity factor (between 0.0 and 1.0).

putPixel

public void putPixel(int x,
                     int y,
                     double alpha)
Sets the given pixel's value to alpha.

Specified by:
putPixel in interface AlphaMask
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
alpha - Opacity factor (between 0.0 and 1.0).

getAlpha

public double getAlpha(int x,
                       int y)
Returns the pixel's value.

Specified by:
getAlpha in interface AlphaMask
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
Returns:
Pixel opacity (0.0 for off-canvas access).

setHLine

public void setHLine(int x1,
                     int x2,
                     int y,
                     double alpha)
Sets the horizontal line from [min(x1,x2),y] to [max(x1,x2)-1,y].

Specified by:
setHLine in interface AlphaMask
Parameters:
x1 - X coordinate of the starting pixel.
x2 - X coordinate of the first pixel after the line.
y - Common Y coordinate of the line.
alpha - Opacity factor (between 0.0 and 1.0).

putHLine

public void putHLine(int x1,
                     int x2,
                     int y,
                     double[] alpha)
Sets the horizontal line's values.

Specified by:
putHLine in interface AlphaMask
Parameters:
x1 - X coordinate of the starting pixel.
x2 - X coordinate of the first pixel after the line.
y - Common Y coordinate of the line.
alpha - Opacity factors (between 0.0 and 1.0).

getHLine

public void getHLine(int x1,
                     int x2,
                     int y,
                     double[] alpha)
Returns the pixels' values for the given horizontal line.

Specified by:
getHLine in interface AlphaMask
Parameters:
x1 - X coordinate of the starting pixel.
x2 - X coordinate of the first pixel after the line.
y - Common Y coordinate of the line.
alpha - Returned values in double[] array (0.0 for off-canvas access).

setRectangle

public void setRectangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         double alpha)
Sets the rectangle from [min(x1,x2),min(y1,y2)] to [max(x1,x2)-1,max(y1,y2)-1].

Specified by:
setRectangle in interface AlphaMask
Parameters:
x1 - X coordinate of the upper left corner.
y1 - Y coordinate of the upper left corner.
x2 - X coordinate of the lower right corner (outside pixel).
y2 - Y coordinate of the upper left corner (outside pixel).
alpha - Opacity factor (between 0.0 and 1.0).

putRectangle

public void putRectangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         double[][] alpha)
Sets the rectangle's values.

Specified by:
putRectangle in interface AlphaMask
Parameters:
x1 - X coordinate of the upper left corner.
y1 - Y coordinate of the upper left corner.
x2 - X coordinate of the lower right corner (outside pixel).
y2 - Y coordinate of the upper left corner (outside pixel).
alpha - Opacity factors (between 0.0 and 1.0).

getRectangle

public void getRectangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         double[][] alpha)
Returns the pixels' values for the given rectangle.

Specified by:
getRectangle in interface AlphaMask
Parameters:
x1 - X coordinate of the upper left corner.
y1 - Y coordinate of the upper left corner.
x2 - X coordinate of the lower right corner (outside pixel).
y2 - Y coordinate of the upper left corner (outside pixel).
alpha - Returned values in double[][] array (0.0 for off-canvas access).

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

commit

public void commit()
Commits all previous changes to the internal object state. Non-mandatory.

Specified by:
commit in interface Property
Overrides:
commit in class DefaultProperty

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.