Class ELMatrix

java.lang.Object
  |
  +--ELMatrix
All Implemented Interfaces:
javax.swing.Icon

public class ELMatrix
extends java.lang.Object
implements javax.swing.Icon

A rectangular grid of floating point triplets (e.g. an X x Y x 3 matrix). To avoid memory allocation and garbage collection, pooled memory is used for allocating. Call alloc() to allocate a new FloatImage and free() when you are done with it.

ELMatrix := ELVector*


Field Summary
(package private)  float[] blu
           
(package private)  float[][] channel
          An array for accessing channels by index instead of direct pointer.
static boolean debugNoisyAllocate
          When true, actual memory allocations (not ones that come from the memory pool) will print.
(package private)  float[] grn
           
(package private)  int numElements
           
(package private)  float[] red
           
 
Constructor Summary
ELMatrix(java.lang.String filename)
          Initializes an ELMatrix from an image.
 
Method Summary
static ELMatrix alloc(int width, int height)
          Allocates an image from a memory pool.
 void drawImage(java.awt.Graphics2D graphics, int x, int y, int width, int height)
           
 void forceClean()
          Causes the image to be cleaned, if dirty.
 ELMatrix free()
          Deallocates an image, placing it in the available memory pool.
 int getHeight()
          Returns the height of the matrix.
 int getIconHeight()
           
 int getIconWidth()
           
 int getWidth()
          Returns the width of the matrix.
 int memorySize()
          Number of bytes this object consumes.
 void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
           
 void set(ELMatrix other)
          Copies from other to this.
 void set(int x, int y, float r, float g, float b)
           
 void setAll(float r, float g, float b)
          Sets all values to (r, g, b)
 void setDirty()
          Marks this matrix's internal image as being dirty.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numElements

int numElements

red

float[] red

grn

float[] grn

blu

float[] blu

channel

float[][] channel
An array for accessing channels by index instead of direct pointer.

debugNoisyAllocate

public static boolean debugNoisyAllocate
When true, actual memory allocations (not ones that come from the memory pool) will print. It is normal for allocations to occur until the memory pool is full. If allocations are regularly occuring during animation, there is either a memory leak (unbalanced calls to alloc() and free()) or the memoryPool size is too small.
Constructor Detail

ELMatrix

public ELMatrix(java.lang.String filename)
Initializes an ELMatrix from an image. You may also want to call ELMatrix.alloc().
Method Detail

setAll

public void setAll(float r,
                   float g,
                   float b)
Sets all values to (r, g, b)

set

public void set(ELMatrix other)
Copies from other to this.

set

public void set(int x,
                int y,
                float r,
                float g,
                float b)

alloc

public static ELMatrix alloc(int width,
                             int height)
Allocates an image from a memory pool. Images are zeroed when returned.

free

public ELMatrix free()
Deallocates an image, placing it in the available memory pool. This returns null to encourage the idiom: im = im.free(), which allows garbage collection and tends to prevent accidental dangling pointers.

memorySize

public int memorySize()
Number of bytes this object consumes.

getWidth

public int getWidth()
Returns the width of the matrix.

getHeight

public int getHeight()
Returns the height of the matrix.

getIconWidth

public int getIconWidth()
Specified by:
getIconWidth in interface javax.swing.Icon

getIconHeight

public int getIconHeight()
Specified by:
getIconHeight in interface javax.swing.Icon

setDirty

public void setDirty()
Marks this matrix's internal image as being dirty. Set this when you want paintIcon to update the image it is displaying. You also need to call repaint on any components that are using this icon.

forceClean

public void forceClean()
Causes the image to be cleaned, if dirty. This is useful for preventing cleaning on one thread (i.e. swing) while rendering on another.

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Specified by:
paintIcon in interface javax.swing.Icon

drawImage

public void drawImage(java.awt.Graphics2D graphics,
                      int x,
                      int y,
                      int width,
                      int height)