cz.cuni.jagrlib.piece
Class HDRImage

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.DefaultRasterGraphics
              extended by cz.cuni.jagrlib.piece.HDRImage
All Implemented Interfaces:
Breakable, Property, RasterGraphics, Template

public class HDRImage
extends DefaultRasterGraphics

HDR raster image stored in memory.
Uses Java's BufferedImage class to hold raster data, one channel is stored as float number.

Since:
0.25
See Also:
HDRImage.java, RasterFactory

Field Summary
protected  float[] color
          Actual drawing color (MODE_RGB, MODE_RGBA, MODE_BAND).
protected  float[] data
          Raw data array in scanline order.
static float[] FOREGROUND
          Default foreground color.
protected  java.awt.image.BufferedImage im
          The working BufferedImage object.
static double[] INIT_COLOR
          Background color for image initialization.
static int MAX_VALUE
          Maximum gray/RGB value used in integer part of the RasterGraphics API.
static RegPiece reg
          Static registration instance for this class.
protected  float sColor
          Actual drawing scalar color (MODE_GRAY).
protected  double[] tmpColor
          Temporary array used for RGBA access.
 
Fields inherited from class cz.cuni.jagrlib.DefaultRasterGraphics
alpha, alphaOp, BACKGROUND, BACKGROUND_D, bands, binaryOp, CATEGORY, height, INV_255, mode, setBands, setColorMode, setHeight, setWidth, TEMPLATE_NAME, transferFunction, width
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.RasterGraphics
BANDS, COLORMODE, HEIGHT, MODE_BAND, MODE_COLORMAP, MODE_GRAY, MODE_RGB, MODE_RGBA, 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
HDRImage()
          Creates an empty image.
HDRImage(int _width, int _height, int _mode)
          Initializes the new image.
HDRImage(RasterGraphics gr, double scale, int _mode)
          Initializes the new image from an existing image.
 
Method Summary
 void downsample(int factor, boolean border)
          Downsample the image by the given integer factor.
 java.awt.image.BufferedImage getBufferedImage()
          Copies raster graphics to a BufferedImage object.
 int getGray(int x, int y)
          Returns the pixel's gray value (for all modes).
 double getGrayDouble(int x, int y)
          Returns the pixel's gray value (for all modes).
 int getMaxGray()
          Maximal gray value.
 int getMaxRGB()
          Maximal RGB[A] value.
 int getPixel(int x, int y)
          Returns the pixel's value (for MODE_GRAY).
 void getPixel(int x, int y, double[] _color)
          Returns the pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).
 void getPixel(int x, int y, int[] _color)
          Returns the pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).
 double getPixelDouble(int x, int y)
          Returns the pixel's value (for MODE_GRAY).
 void getRGB(int x, int y, double[] _color)
          Returns the pixel's RGB[A] values (for all graphic modes).
 void getRGB(int x, int y, int[] _color)
          Returns the pixel's RGB[A] values (for all graphic modes).
 void init()
          RasterImage re-initialization (keeps current bitmap size, mode, and colormap attributes, too).
 void init(int _width, int _height, int _mode, int _bands)
          RasterImage (re-)initialization.
 void putPixel(int x, int y, double _color)
          Sets the given pixel's value (for MODE_GRAY).
 void putPixel(int x, int y, double[] _color)
          Sets the given pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).
 void putPixel(int x, int y, int _color)
          Sets the given pixel's value (for MODE_GRAY).
 void putPixel(int x, int y, int[] _color)
          Sets the given pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).
 void setColor(double _color)
          Sets the current drawing color (for MODE_GRAY).
 void setColor(double[] _color)
          Sets the current drawing color (for MODE_RGB, MODE_RGBA or MODE_BAND).
 void setColor(int _color)
          Sets the current drawing color (for MODE_GRAY).
 void setColor(int[] _color)
          Sets the current drawing color (for MODE_RGB, MODE_RGBA or MODE_BAND).
 void setHLine(int x1, int x2, int y)
          Sets the horizontal line from [min(x1,x2),y] to [max(x1,x2)-1,y].
 void setPixel(int x, int y)
          Sets the given pixel's value.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 
Methods inherited from class cz.cuni.jagrlib.DefaultRasterGraphics
commit, drawFrame, drawLine, get, getBands, getColormap, getColormap, getColormapType, getHeight, getHLine, getHLine, getHLine, getHLine, getMaxColormap, getMode, getWidth, putHLine, putHLine, putHLine, putHLine, set, setAlpha, setAlphaOperation, setBufferedImage, setColormap, setColormap, setColormapType, setHLine, setHLine, setHLine, setHLine, setOperation, setRectangle, setRectangle, setRectangle, setRectangle, setRectangle, setTransferFunction
 
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

MAX_VALUE

public static final int MAX_VALUE
Maximum gray/RGB value used in integer part of the RasterGraphics API.

See Also:
Constant Field Values

INIT_COLOR

public static final double[] INIT_COLOR
Background color for image initialization.


FOREGROUND

public static final float[] FOREGROUND
Default foreground color.


im

protected java.awt.image.BufferedImage im
The working BufferedImage object.


data

protected float[] data
Raw data array in scanline order. Back-buffer of associated DataBufferFloat instance (accelerator). data[0] .. R[0,0], data[1] .. G[0,0], data[2] .. B[0,0], data[3] .. A[0,0], ..


sColor

protected float sColor
Actual drawing scalar color (MODE_GRAY).


color

protected float[] color
Actual drawing color (MODE_RGB, MODE_RGBA, MODE_BAND).


tmpColor

protected double[] tmpColor
Temporary array used for RGBA access.


reg

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

Constructor Detail

HDRImage

public HDRImage()
Creates an empty image. init(int,int,int,int) should be called to initialize image size/content.


HDRImage

public HDRImage(int _width,
                int _height,
                int _mode)
Initializes the new image.

Parameters:
_width - Width of a new bitmap.
_height - Height of a new bitmap.
_mode - Pixel value type (RasterGraphics.MODE_* constant).

HDRImage

public HDRImage(RasterGraphics gr,
                double scale,
                int _mode)
Initializes the new image from an existing image.

Parameters:
gr - Existing raster image.
scale - Scale coefficient (1.0 for no scaling}).
_mode - Pixel value type (RasterGraphics.MODE_* constant).
Method Detail

downsample

public void downsample(int factor,
                       boolean border)
Downsample the image by the given integer factor. Uses simple arithmetic averaging.

Parameters:
border - Set border color (to background color)?

init

public void init(int _width,
                 int _height,
                 int _mode,
                 int _bands)
RasterImage (re-)initialization.

Specified by:
init in interface RasterGraphics
Overrides:
init in class DefaultRasterGraphics
Parameters:
_width - Width of a new bitmap.
_height - Height of a new bitmap.
_mode - Pixel value type (RasterGraphics.MODE_* constant).
_bands - Number of bands (for MODE_BAND).
See Also:
DefaultRasterGraphics.setColormapType(int, int)

init

public void init()
RasterImage re-initialization (keeps current bitmap size, mode, and colormap attributes, too).

Specified by:
init in interface RasterGraphics
Overrides:
init in class DefaultRasterGraphics

getMaxGray

public int getMaxGray()
Maximal gray value.

Specified by:
getMaxGray in interface RasterGraphics
Overrides:
getMaxGray in class DefaultRasterGraphics
Returns:
Maximal acceptable gray value.

getMaxRGB

public int getMaxRGB()
Maximal RGB[A] value. Also used in multi-band mode.

Specified by:
getMaxRGB in interface RasterGraphics
Overrides:
getMaxRGB in class DefaultRasterGraphics
Returns:
Maximal value for R,G,B,A and other bands.

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Copies raster graphics to a BufferedImage object.

Specified by:
getBufferedImage in interface RasterGraphics
Overrides:
getBufferedImage in class DefaultRasterGraphics
Returns:
BufferedImage object.
See Also:
DefaultRasterGraphics.setBufferedImage(java.awt.image.BufferedImage)

setColor

public void setColor(int _color)
Sets the current drawing color (for MODE_GRAY).

Specified by:
setColor in interface RasterGraphics
Overrides:
setColor in class DefaultRasterGraphics
Parameters:
_color - Current drawing color (0 to getMaxGray()).
See Also:
RasterGraphics

setColor

public void setColor(double _color)
Sets the current drawing color (for MODE_GRAY).

Specified by:
setColor in interface RasterGraphics
Overrides:
setColor in class DefaultRasterGraphics
Parameters:
_color - Current drawing color (0.0 to 1.0).
See Also:
RasterGraphics

setColor

public void setColor(int[] _color)
Sets the current drawing color (for MODE_RGB, MODE_RGBA or MODE_BAND).

Specified by:
setColor in interface RasterGraphics
Overrides:
setColor in class DefaultRasterGraphics
Parameters:
_color - Current drawing color (channel values between 0 and getMaxRGB()).
See Also:
RasterGraphics

setColor

public void setColor(double[] _color)
Sets the current drawing color (for MODE_RGB, MODE_RGBA or MODE_BAND).

Specified by:
setColor in interface RasterGraphics
Overrides:
setColor in class DefaultRasterGraphics
Parameters:
_color - Current drawing color (channel values between 0.0 and 1.0).
See Also:
RasterGraphics

setPixel

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

Ignores any off-canvas access.

Specified by:
setPixel in interface RasterGraphics
Overrides:
setPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
See Also:
setColor(int), setColor(double), setColor(int[]), setColor(double[]), RasterGraphics

getPixel

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

Specified by:
getPixel in interface RasterGraphics
Overrides:
getPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
Returns:
Pixel value (0 for off-canvas access).
See Also:
RasterGraphics

getPixelDouble

public double getPixelDouble(int x,
                             int y)
Returns the pixel's value (for MODE_GRAY).

Specified by:
getPixelDouble in interface RasterGraphics
Overrides:
getPixelDouble in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
Returns:
Pixel value (0.0 for off-canvas access).
See Also:
RasterGraphics

getPixel

public void getPixel(int x,
                     int y,
                     int[] _color)
Returns the pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).

Specified by:
getPixel in interface RasterGraphics
Overrides:
getPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Current pixel RGB[A] value.
See Also:
RasterGraphics

getPixel

public void getPixel(int x,
                     int y,
                     double[] _color)
Returns the pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).

Specified by:
getPixel in interface RasterGraphics
Overrides:
getPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Current pixel RGB[A] value.
See Also:
RasterGraphics

getRGB

public void getRGB(int x,
                   int y,
                   int[] _color)
Returns the pixel's RGB[A] values (for all graphic modes).

Specified by:
getRGB in interface RasterGraphics
Overrides:
getRGB in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Current pixel RGB[A] value (if the array's length is at least 4, alpha will be returned).

getRGB

public void getRGB(int x,
                   int y,
                   double[] _color)
Returns the pixel's RGB[A] values (for all graphic modes).

Specified by:
getRGB in interface RasterGraphics
Overrides:
getRGB in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Current pixel RGB[A] value (if the array's length is at least 4, alpha will be returned).

getGray

public int getGray(int x,
                   int y)
Returns the pixel's gray value (for all modes).

Specified by:
getGray in interface RasterGraphics
Overrides:
getGray in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
Returns:
Pixel value (0 for off-canvas access).

getGrayDouble

public double getGrayDouble(int x,
                            int y)
Returns the pixel's gray value (for all modes).

Specified by:
getGrayDouble in interface RasterGraphics
Overrides:
getGrayDouble in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
Returns:
Pixel value (0.0 for off-canvas access).

putPixel

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

Ignores any off-canvas access.

Specified by:
putPixel in interface RasterGraphics
Overrides:
putPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Pixel color (between 0 and getMaxGray()).

putPixel

public void putPixel(int x,
                     int y,
                     double _color)
Sets the given pixel's value (for MODE_GRAY).

Ignores any off-canvas access.

Specified by:
putPixel in interface RasterGraphics
Overrides:
putPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Pixel color (between 0.0 and 1.0).

putPixel

public void putPixel(int x,
                     int y,
                     int[] _color)
Sets the given pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).

Ignores any off-canvas access.

Specified by:
putPixel in interface RasterGraphics
Overrides:
putPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Pixel color (between 0 and getMaxRGB()).

putPixel

public void putPixel(int x,
                     int y,
                     double[] _color)
Sets the given pixel's value (for MODE_RGB, MODE_RGBA or MODE_BAND).

Ignores any off-canvas access.

Specified by:
putPixel in interface RasterGraphics
Overrides:
putPixel in class DefaultRasterGraphics
Parameters:
x - X coordinate of a pixel.
y - Y coordinate of a pixel.
_color - Pixel color (between 0.0 and 1.0).

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].

Ignores any off-canvas access.

Specified by:
setHLine in interface RasterGraphics
Overrides:
setHLine in class DefaultRasterGraphics
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.
See Also:
setColor(int), setColor(double), setColor(int[]), setColor(double[]), RasterGraphics

setTemplate

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