public class EXRSimpleImage extends Object implements Serializable
Simple base class which represents either RGB or RGBA images whose pixels are stored in the half format. This interface receives and returns 32-bit floating point values: the half representation is internal to the exr files.
This class provides relatively low level access to the underlying structure so that it can easily adapt to various circumstances where other class will actually interact with the user.
Modifier and Type | Class and Description |
---|---|
static class |
EXRSimpleImage.Channels
As a simple image the only supported channel configurations
are RGB, RGBA and Y (single channel luminance)
|
Constructor and Description |
---|
EXRSimpleImage(File file,
EXRSimpleImage.Channels channels)
Creates a new instance of the image by reading the OpenEXR file at
the location referenced by
file ,
which is read as a simple RGB/RGBA file. |
EXRSimpleImage(int width,
int height,
EXRSimpleImage.Channels channels)
Basic constructor, meant to write an image to disk.
|
EXRSimpleImage(String filename,
EXRSimpleImage.Channels channels)
Creates a new instance of the image by reading the OpenEXR file at
filename , which is read as a simple RGB/RGBA file. |
Modifier and Type | Method and Description |
---|---|
void |
allocateBuffer()
Sets the pixel buffer of this image to a new buffer.
|
Attributes |
getAttributes()
Returns a reference to the attributes of the image,
or
null if the image does not contain any. |
float[] |
getBuffer()
Returns a reference to the pixel buffer.
|
EXRSimpleImage.Channels |
getChannels()
Returns the channel configuration of the image.
|
int |
getHeight()
Returns the height of the image.
|
int |
getIndex(int x,
int y)
Returns the index in the data buffer where the first element
of the pixel at (x,y) is found.
|
int |
getIndexFast(int x,
int y)
The same as
getIndex(int, int) but without
bounds checking, use at your own risk. |
int |
getNumChannels()
Get the number of channels per pixel.
|
float[] |
getPixel(int x,
int y)
Returns a newly allocated array with the data of
the pixel at (x,y).
|
void |
getPixel(int x,
int y,
float[] destPixel)
Sugar method, it is equivalent to
getPixel(x,y,destPixel,0) . |
void |
getPixel(int x,
int y,
float[] destBuffer,
int destPos)
Copies the (x,y) pixel elements starting at the location
destPos (0-based) in the destBuffer . |
float |
getPixelElement(int x,
int y,
int channelIndex)
Retrieves a single element from the (x,y) pixel.
|
int |
getWidth()
Returns the width of the image.
|
void |
setAttributes(Attributes attrib)
Sets the additional attributes of this image or
null . |
void |
setBuffer(float[] buffer)
Sets the buffer containing the pixels of the image.
|
void |
setPixel(int x,
int y,
float... elements)
Sets the value of the (x,y) pixel's channels.
|
void |
setPixelElement(int x,
int y,
int channelIndex,
float val)
Sets the value of the channelIndex-th component
(0 based indexing) of the (x,y) pixel.
|
void |
write(File file,
Compression compression)
Writes the current image to disk as an OpenEXR file using
the specified
file , which should have the suffix
.exr . |
void |
write(String filename,
Compression compression)
Utility method, it is the same as calling
write(File, Compression) , constructing
the file with the given filename. |
public EXRSimpleImage(int width, int height, EXRSimpleImage.Channels channels)
width
- the desired width of the image, greater than zero.height
- the desired height of the image, greater than zero.channels
- the channels configuration of the image, non null.allocateBuffer()
public EXRSimpleImage(File file, EXRSimpleImage.Channels channels) throws EXRIOException
file
,
which is read as a simple RGB/RGBA file.file
- the path of the image to be read.channels
- the desired channel configuration for the file.EXRIOException
- if an error occurs while reading.public EXRSimpleImage(String filename, EXRSimpleImage.Channels channels) throws EXRIOException
filename
, which is read as a simple RGB/RGBA file.filename
- path to file to read from.channels
- the desired channel configuration for the file.EXRIOException
- if an error occurs while reading.EXRSimpleImage(File, Channels)
public void setBuffer(float[] buffer)
Sets the buffer containing the pixels of the image. The buffer
contains width*height
interleaved pixels stored in
scanline order, where (0,0) is the top-left corner and
(width-1,height-1) is the bottom-right
corner. Therefore the size of the buffer must be at least
width*height*(number of channels).
This method just does a shallow copy (ie only copies the reference) to the input buffer for efficiency.
buffer
- a non null array holding the interleaved
pixels of the image.public void allocateBuffer()
public float[] getBuffer()
public EXRSimpleImage.Channels getChannels()
public int getNumChannels()
getChannels()
public Attributes getAttributes()
null
if the image does not contain any.
This reference may be used to edit the attributes of the image.null
.public void setAttributes(Attributes attrib)
null
.attrib
- the new set of attributes.public int getWidth()
public int getHeight()
public int getIndex(int x, int y)
x
- width coordinate in the range [0,width-1];y
- height coordinate in the range [0,height-1];public int getIndexFast(int x, int y)
getIndex(int, int)
but without
bounds checking, use at your own risk.x
- width coordinate in the range [0,width-1];y
- height coordinate in the range [0,height-1];public float[] getPixel(int x, int y)
x
- x-coordinate of the pixel.y
- y-coordinate of the pixel.public void getPixel(int x, int y, float[] destBuffer, int destPos)
destPos
(0-based) in the destBuffer
. So it
will use the destination buffer at the array indices
[destPost, destPos+getNumChannels()-1]
.x
- x-coordinate of the pixel.y
- y-coordinate of the pixel.destBuffer
- array where the pixel values will be written.destPos
- starting index in the array for the copied pixel data.public void getPixel(int x, int y, float[] destPixel)
getPixel(x,y,destPixel,0)
. This is, the pixel
data is copied to the beginning of destPixel
.x
- x-coordinate of the pixel.y
- y-coordinate of the pixel.destPixel
- array where the pixel values will be written.getPixel(int, int, float[], int)
public float getPixelElement(int x, int y, int channelIndex)
channelIndex
is in the range
[0, getNumChannels()-1]
x
- x-coordinate of the pixel.y
- y-coordinate of the pixel.channelIndex
- index of the pixel element to return.public void setPixel(int x, int y, float... elements)
elements
sets the n-th value of the pixel.
All the pixel elements must be set, but if there are more elements
than pixel channels, the extra data is simply ignored. Hence
the length of elements
must be at least
the same getNumChannels()
.x
- x-coordinate of the pixel.y
- y-coordinate of the pixel.elements
- the new values for pixel (x,y).public void setPixelElement(int x, int y, int channelIndex, float val)
x
- x-coordinate of the pixel.y
- y-coordinate of the pixel.channelIndex
- which pixel channel to choose.val
- the new value to set.public void write(File file, Compression compression) throws EXRIOException
file
, which should have the suffix
.exr
. Before calling this method the buffer must
have been set to meaningful values.file
- path where the file will be saved.compression
- the type of compression used when creating the file.EXRIOException
- if an error occur during writing.public void write(String filename, Compression compression) throws EXRIOException
write(File, Compression)
, constructing
the file with the given filename.filename
- path where the file will be saved.compression
- the type of compression used when creating the file.EXRIOException
- if an error occur during writing.