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)
Sets all samples in the first channel to the argument value.
void
clear(int channelIndex, int newValue)
Sets all samples of the channelIndex'th channel to newValue.
void
clear(int channelIndex, short newValue)
void
clear(short newValue)
abstract PixelImage
createCompatibleImage(int width, int height)
Creates an instance of the same class as this one, with width and height given by the arguments.
PixelImage
createCopy()
Creates an new image object that will be of the same type as this one, with the same image data, using entirely new resources.
long
getAllocatedMemory()
Returns the number of bytes that were dynamically allocated for this image object.
int
getBitsPerPixel()
Returns the number of bits per pixel of this image.
int
getHeight()
Returns the vertical resolution of the image in pixels.
int
getMaxSample(int channel)
Returns the maximum value for one of the image's channels.
int
getNumChannels()
Returns the number of channels in this image.
int
getSample(int x, int y)
Returns one sample of the first channel (index 0).
int
getSample(int channel, int x, int y)
Returns one sample, specified by its channel index and location.
void
getSamples(int channel, int x, int y, int w, int h, int[] dest, int destOffs)
Copies a number of samples from this image to an int[] object.
short
getShortSample(int x, int y)
short
getShortSample(int channel, int x, int y)
void
getShortSamples(int channel, int x, int y, int w, int h, short[] dest, int destOffset)
int
getWidth()
Returns the horizontal resolution of the image in pixels.
void
putSample(int x, int y, int newValue)
This method sets one sample of the first channel (index 0) to a new value.
void
putSample(int channel, int x, int y, int newValue)
This method sets one sample to a new value.
void
putSamples(int channel, int x, int y, int w, int h, int[] src, int srcOffs)
Copies a number of samples from an int[] array to this image.
void
putShortSample(int channel, int x, int y, short newValue)
void
putShortSample(int x, int y, short newValue)
void
putShortSamples(int channel, int x, int y, int w, int h, short[] src, int srcOffset)

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)
Sets all samples in the first channel to the argument value. Equal to clear(0, newValue);:
Specified by:
clear in interface IntegerImage

clear

public void clear(int channelIndex,
                  int newValue)
Sets all samples of the channelIndex'th channel to newValue.
Specified by:
clear in interface IntegerImage

clear

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

clear

public void clear(short newValue)
Specified by:
clear in interface ShortChannelImage

createCompatibleImage

public abstract PixelImage createCompatibleImage(int width,
                                                 int height)
Creates an instance of the same class as this one, with width and height given by the arguments.
Specified by:
createCompatibleImage in interface PixelImage
Parameters:
width - the horizontal resolution of the new image
height - the vertical resolution of the new image
Returns:
the new image

createCopy

public PixelImage createCopy()
Creates an new image object that will be of the same type as this one, with the same image data, using entirely new resources.
Specified by:
createCopy in interface PixelImage
Returns:
the new image object

getAllocatedMemory

public long getAllocatedMemory()
Returns the number of bytes that were dynamically allocated for this image object.
Specified by:
getAllocatedMemory in interface PixelImage
Returns:
allocated memory in bytes

getBitsPerPixel

public int getBitsPerPixel()
Returns the number of bits per pixel of this image. That is the number of bits per sample for all channels of this image. Does not include any transparency channels.
Specified by:
getBitsPerPixel in interface PixelImage

getHeight

public final int getHeight()
Returns the vertical resolution of the image in pixels. Must be one or larger.
Specified by:
getHeight in interface PixelImage
Returns:
height in pixels

getMaxSample

public int getMaxSample(int channel)
Returns the maximum value for one of the image's channels. The minimum value is always 0.
Specified by:
getMaxSample in interface IntegerImage
Parameters:
channel - zero-based index of the channel, from 0 to getNumChannels() - 1
Returns:
maximum allowed sample value

getNumChannels

public int getNumChannels()
Returns the number of channels in this image. Must be one or larger.
Specified by:
getNumChannels in interface PixelImage
Returns:
the number of channels

getSample

public final int getSample(int x,
                           int y)
Returns one sample of the first channel (index 0). A call to this method must have the same result as the call getSample(0, x, y);.
Specified by:
getSample in interface IntegerImage
Parameters:
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
Returns:
the desired sample

getSample

public final int getSample(int channel,
                           int x,
                           int y)
Returns one sample, specified by its channel index and location.
Specified by:
getSample in interface IntegerImage
Parameters:
channel - the number of the channel, from 0 to IntegerImage - 1
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
Returns:
the desired sample

getSamples

public void getSamples(int channel,
                       int x,
                       int y,
                       int w,
                       int h,
                       int[] dest,
                       int destOffs)
Copies a number of samples from this image to an int[] object. A rectangular part of one channel is copied. The channel index is given by - the upper left corner of that rectangle is given by the point x / y. Width and height of that rectangle are given by w and h. Each sample will be stored as one int value dest, starting at index destOffs.
Specified by:
getSamples in interface IntegerImage
Parameters:
x - horizontal position of upper left corner of the rectangle to be copied
y - vertical position of upper left corner of the rectangle to be copied
w - width of rectangle to be copied
h - height of rectangle to be copied
dest - int array to which the samples will be copied
destOffs - int index into the dest array for the position to which the samples will be copied

getShortSample

public short getShortSample(int x,
                            int y)
Specified by:
getShortSample in interface ShortChannelImage

getShortSample

public short getShortSample(int channel,
                            int x,
                            int y)
Specified by:
getShortSample in interface ShortChannelImage

getShortSamples

public void getShortSamples(int channel,
                            int x,
                            int y,
                            int w,
                            int h,
                            short[] dest,
                            int destOffset)
Specified by:
getShortSamples in interface ShortChannelImage

getWidth

public final int getWidth()
Returns the horizontal resolution of the image in pixels. Must be one or larger.
Specified by:
getWidth in interface PixelImage
Returns:
width in pixels

putSample

public final void putSample(int x,
                            int y,
                            int newValue)
This method sets one sample of the first channel (index 0) to a new value. This call must have the same result as the call putSample(0, x, y). The sample location is given by the spatial coordinates, x and y.
Specified by:
putSample in interface IntegerImage
Parameters:
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
newValue - the new value of the sample

putSample

public final void putSample(int channel,
                            int x,
                            int y,
                            int newValue)
This method sets one sample to a new value. The sample location is given by the channel index and the spatial coordinates, x and y.
Specified by:
putSample in interface IntegerImage
Parameters:
channel - the number of the channel, from 0 to IntegerImage - 1
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
newValue - the new value of the sample

putSamples

public void putSamples(int channel,
                       int x,
                       int y,
                       int w,
                       int h,
                       int[] src,
                       int srcOffs)
Copies a number of samples from an int[] array to this image. A rectangular part of one channel is copied - the upper left corner of that rectangle is given by the point x / y. Width and height of that rectangle are given by w and h. Each sample will be stored as one int value src, starting at index srcOffset.
Specified by:
putSamples in interface IntegerImage
Parameters:
channel - int (from 0 to getNumChannels() - 1) to indicate the channel to which data is copied
x - horizontal position of upper left corner of the rectangle to be copied
y - vertical position of upper left corner of the rectangle to be copied
w - width of rectangle to be copied
h - height of rectangle to be copied
src - int array from which the samples will be copied

putShortSample

public final void putShortSample(int channel,
                                 int x,
                                 int y,
                                 short newValue)
Specified by:
putShortSample in interface ShortChannelImage

putShortSample

public final void putShortSample(int x,
                                 int y,
                                 short 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)
Specified by:
putShortSamples in interface ShortChannelImage