public class Slice extends Object
This is simply a transfer object, it does NOT check any field for correctness or even coherence. Other classes which use slices will be responsible of verifying that a slice is valid.
Memory layout: the address of pixel (x,y)
, relative to the
current buffer.position()
is:
baseOffset + (xp / xSampling) * xStride + (yp / ySampling) * yStrideWhere
xp
and yp
are computed as follows:
xp = x yp = y
(xt,yt)
:
if xTileCoords is true then xp = x - xt, else xp = x if yTileCoords is true then yp = y - yt, else yp = y
baseOffset
appropriately according to the file layout is more
important than it seems at first sight. Pixels in OpenEXR files may have
negative coordinates, thus baseOffset
must compensate for that so
that the memory location of a pixel maps to a valid position within the
buffer. Other use of this parameter is when reading/writing only a fragment
of a frame buffer: it allows to map only a subset of the image data into
an appropriate region of the buffer.
Subsampling: pixel (x,y)
is present in the slice only if
x % xSampling == 0 && y % ySampling == 0
Note on terminology: as a part of a file, a component of an image (e.g. red, green, blue, depth, etc.) is called a channel. As part of a frame buffer is called a slice.
Modifier and Type | Class and Description |
---|---|
static class |
Slice.SliceBuilder
Helper class to provide a fluent-style interface for creating slices.
|
Modifier and Type | Field and Description |
---|---|
int |
baseOffset
Offset within the buffer, used when calculating the address of a pixel.
|
ByteBuffer |
buffer
Buffer containing the actual slice data
|
double |
fillValue
Default value, used to fill the slice when a file without a channel that
corresponds to this slice is read.
|
PixelType |
type
Data type
|
int |
xSampling
Pixel sampling interval along
x (the image width.) |
int |
xStride
Distance in bytes between pixels
(x,y) and (x+1,y) . |
boolean |
xTileCoords
x absolute/relative addressing flag for tiled files. |
int |
ySampling
Pixel sampling interval along
y (the image height.) |
int |
yStride
Distance in bytes between pixels
(x,y) and (x,y+1) . |
boolean |
yTileCoords
y absolute/relative addressing flag for tiled files. |
Modifier and Type | Method and Description |
---|---|
static Slice.SliceBuilder |
build()
Returns a
SliceBuilder to configure a new Slice instance. |
boolean |
equals(Object obj)
Tells whether or not this slice is equal to another object.
|
int |
hashCode()
Returns the current hash code of this slice.
|
String |
toString() |
public PixelType type
public ByteBuffer buffer
public int baseOffset
public int xStride
(x,y)
and (x+1,y)
. It
may be a negative number.public int yStride
(x,y)
and (x,y+1)
. It
may be a negative number.public int xSampling
x
(the image width.)public int ySampling
y
(the image height.)public double fillValue
public boolean xTileCoords
x
absolute/relative addressing flag for tiled files.
For tiled files, if true
pixel addressing is performed using
absolute coordinates for x
. If false
, x
coordinates are relative to the tile's upper left corner.
For scanline-based files this flag has no effect; pixel addressing is
always done using absolute coordinates.
public boolean yTileCoords
y
absolute/relative addressing flag for tiled files.
For tiled files, if true
pixel addressing is performed using
absolute coordinates for y
. If false
, y
coordinates are relative to the tile's upper left corner.
For scanline-based files this flag has no effect; pixel addressing is
always done using absolute coordinates.
public Slice(Slice other)
public static Slice.SliceBuilder build()
SliceBuilder
to configure a new Slice
instance.SliceBuilder
to configure a new Slice
instance.public int hashCode()
The hash code of a slice uses all of its components in the standard
way except for the buffer: for two slices to have the same hash code
they must reference the same buffer object, and the buffer's position and
limit must remain unchanged between calls to hashCode
. The
actual contents of the buffer are ignored.
Because of the weak conditions for equality, slices should not be used as keys in hash maps or similar structures.
public boolean equals(Object obj)
Two slices are equal if, and only if,
this.buffer == ((Slice)obj).buffer
will
be true
.Note that even if two slices are equal, their hash codes may change depending on their buffer's current position and limit.
equals
in class Object
obj
- the object to which this slice is to be comparedtrue
if, and only if, this slice is equal to the
given objecthashCode()