net.sourceforge.jiu.data

Class MemoryShortChannelImage

Implemented Interfaces:
IntegerImage, PixelImage, ShortChannelImage
Known Direct Subclasses:
MemoryGray16Image, MemoryRGB48Image

public abstract class MemoryShortChannelImage
extends java.lang.Object
implements ShortChannelImage

An implementation of ShortChannelImage that stores image channels as short[] arrays in memory. An image can have an arbitrary number of channels.

This class is abstract because it is merely a data container. It takes a subclass like MemoryGray16Image to give meaning to the values.

Author:
Marco Schmidt
Since:
0.11.0

Field Summary

private short[][]
data
private short[]
firstChannel
private int
height
private int
numChannels
private int
numPixels
private int
width

Constructor Summary

MemoryShortChannelImage(int numChannels, int width, int height)
Create an image of short channels.

Method Summary

protected void
checkPositionAndNumber(int channel, int x, int y, int w, int h)
Throws an exception if the arguments do not form a valid horizontal sequence of samples.
void
clear(int newValue)
void
clear(int channelIndex, int newValue)
void
clear(int channelIndex, short newValue)
Sets all samples of one channel to a new value.
void
clear(short newValue)
Sets all samples of the first channel to the argument short value.
abstract PixelImage
createCompatibleImage(int width, int height)
PixelImage
createCopy()
long
getAllocatedMemory()
int
getBitsPerPixel()
int
getHeight()
int
getMaxSample(int channel)
int
getNumChannels()
int
getSample(int x, int y)
int
getSample(int channel, int x, int y)
void
getSamples(int channel, int x, int y, int w, int h, int[] dest, int destOffs)
short
getShortSample(int x, int y)
Returns a single short sample from the first channel and the specified position.
short
getShortSample(int channel, int x, int y)
Returns a single short sample from the image.
void
getShortSamples(int channel, int x, int y, int w, int h, short[] dest, int destOffset)
Copies samples from this image to a short array.
int
getWidth()
void
putSample(int x, int y, int newValue)
void
putSample(int channel, int x, int y, int newValue)
void
putSamples(int channel, int x, int y, int w, int h, int[] src, int srcOffs)
void
putShortSample(int channel, int x, int y, short newValue)
Sets one short sample in one channel to a new value.
void
putShortSample(int x, int y, short newValue)
Sets one short sample in the first channel (index 0) to a new value.
void
putShortSamples(int channel, int x, int y, int w, int h, short[] src, int srcOffset)
Copies a number of samples from the argument array to this image.

Field Details

data

private final short[][] data

firstChannel

private final short[] firstChannel

height

private final int height

numChannels

private final int numChannels

numPixels

private final int numPixels

width

private final int width

Constructor Details

MemoryShortChannelImage

public MemoryShortChannelImage(int numChannels,
                               int width,
                               int height)
Create an image of short channels. Image data will be completely in memory, so memory requirements are width * height * numChannels * 2 bytes.
Parameters:
numChannels - the number of channels in this image, must be larger than zero
width - the horizontal resolution, must be larger than zero
height - the vertical resolution, must be larger than zero

Method Details

checkPositionAndNumber

protected void checkPositionAndNumber(int channel,
                                      int x,
                                      int y,
                                      int w,
                                      int h)
Throws an exception if the arguments do not form a valid horizontal sequence of samples. To be valid, all of the following requirements must be met:

clear

public void clear(int newValue)
Specified by:
clear in interface IntegerImage

clear

public void clear(int channelIndex,
                  int newValue)
Specified by:
clear in interface IntegerImage

clear

public void clear(int channelIndex,
                  short newValue)
Sets all samples of one channel to a new value.
Specified by:
clear in interface ShortChannelImage
Parameters:
channelIndex - zero-based index of the channel to be cleared (must be smaller than getNumChannels()
newValue - all samples in the channel will be set to this value

clear

public void clear(short newValue)
Sets all samples of the first channel to the argument short value. Equal to clear(0, newValue);.
Specified by:
clear in interface ShortChannelImage
Parameters:
newValue - all samples in the first channel are set to this value
See Also:
ShortChannelImage.clear(int,short), clear(int), clear(int, int)

createCompatibleImage

public abstract PixelImage createCompatibleImage(int width,
                                                 int height)
Specified by:
createCompatibleImage in interface PixelImage

createCopy

public PixelImage createCopy()
Specified by:
createCopy in interface PixelImage

getAllocatedMemory

public long getAllocatedMemory()
Specified by:
getAllocatedMemory in interface PixelImage

getBitsPerPixel

public int getBitsPerPixel()
Specified by:
getBitsPerPixel in interface PixelImage

getHeight

public final int getHeight()
Specified by:
getHeight in interface PixelImage

getMaxSample

public int getMaxSample(int channel)
Specified by:
getMaxSample in interface IntegerImage

getNumChannels

public int getNumChannels()
Specified by:
getNumChannels in interface PixelImage

getSample

public final int getSample(int x,
                           int y)
Specified by:
getSample in interface IntegerImage

getSample

public final int getSample(int channel,
                           int x,
                           int y)
Specified by:
getSample in interface IntegerImage

getSamples

public void getSamples(int channel,
                       int x,
                       int y,
                       int w,
                       int h,
                       int[] dest,
                       int destOffs)
Specified by:
getSamples in interface IntegerImage

getShortSample

public short getShortSample(int x,
                            int y)
Returns a single short sample from the first channel and the specified position. A call to this method is the same as getShortSample(0, x, y).
Specified by:
getShortSample in interface ShortChannelImage
Parameters:
x - horizontal position of the sample to be returned (must be between 0 and getWidth() - 1
y - vertical position of the sample to be returned (must be between 0 and getHeight() - 1
Returns:
the requested short sample

getShortSample

public short getShortSample(int channel,
                            int x,
                            int y)
Specified by:
getShortSample in interface ShortChannelImage
Parameters:
channel - the number of the channel of the sample; must be from 0 to getNumChannels() - 1
x - the column of the sample to be returned; must be from 0 to getWidth() - 1
y - the row of the sample; must be from 0 to getHeight() - 1
Returns:
the sample, a single short value

getShortSamples

public void getShortSamples(int channel,
                            int x,
                            int y,
                            int w,
                            int h,
                            short[] dest,
                            int destOffset)
Copies samples from this image to a short array. Copies num samples in row y of channel channel, starting at horizontal offset x. Data will be written to the dest array, starting at offset destOffset. Data will be copied from one row only, so a maximum of getWidth() samples can be copied with a call to this method.
Specified by:
getShortSamples in interface ShortChannelImage
Parameters:
x - the horizontal offset where copying will start; must be from 0 to getWidth() - 1
y - the row from which will be copied; must be from 0 to getHeight() - 1
w - number of columns to be copied
h - number of rows to be copied
dest - the array where the data will be copied to; must have a length of at least destOffset + num
destOffset - the offset into dest where this method will start copying data

getWidth

public final int getWidth()
Specified by:
getWidth in interface PixelImage

putSample

public final void putSample(int x,
                            int y,
                            int newValue)
Specified by:
putSample in interface IntegerImage

putSample

public final void putSample(int channel,
                            int x,
                            int y,
                            int newValue)
Specified by:
putSample in interface IntegerImage

putSamples

public void putSamples(int channel,
                       int x,
                       int y,
                       int w,
                       int h,
                       int[] src,
                       int srcOffs)
Specified by:
putSamples in interface IntegerImage

putShortSample

public final void putShortSample(int channel,
                                 int x,
                                 int y,
                                 short newValue)
Sets one short sample in one channel to a new value.
Specified by:
putShortSample in interface ShortChannelImage

putShortSample

public final void putShortSample(int x,
                                 int y,
                                 short newValue)
Sets one short sample in the first channel (index 0) to a new value. Result is equal to putShortSample(0, x, y, newValue);.
Specified by:
putShortSample in interface ShortChannelImage

putShortSamples

public void putShortSamples(int channel,
                            int x,
                            int y,
                            int w,
                            int h,
                            short[] src,
                            int srcOffset)
Copies a number of samples from the argument array to this image.
Specified by:
putShortSamples in interface ShortChannelImage