Package net.sourceforge.jiu.data
Class MemoryShortChannelImage
java.lang.Object
net.sourceforge.jiu.data.MemoryShortChannelImage
- All Implemented Interfaces:
IntegerImage
,PixelImage
,ShortChannelImage
- Direct Known Subclasses:
MemoryGray16Image
,MemoryRGB48Image
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.
- Since:
- 0.11.0
- Author:
- Marco Schmidt
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final short[][]
private final short[]
private final int
private final int
private final int
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionMemoryShortChannelImage
(int numChannels, int width, int height) Create an image of short channels. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 thechannelIndex
'th channel tonewValue
.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) Creates an instance of the same class as this one, with width and height given by the arguments.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
Returns the number of bytes that were dynamically allocated for this image object.int
Returns the number of bits per pixel of this image.final int
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
Returns the number of channels in this image.final int
getSample
(int x, int y) Returns one sample of the first channel (index 0).final 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 anint[]
object.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.final int
getWidth()
Returns the horizontal resolution of the image in pixels.final void
putSample
(int x, int y, int newValue) This method sets one sample of the first channel (index 0) to a new value.final 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 anint[]
array to this image.final void
putShortSample
(int channel, int x, int y, short newValue) Sets one short sample in one channel to a new value.final void
putShortSample
(int x, int y, short newValue) Sets one short sample in the first channel (index0
) 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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.sourceforge.jiu.data.PixelImage
getImageType
-
Field Details
-
data
private final short[][] data -
firstChannel
private final short[] firstChannel -
numChannels
private final int numChannels -
width
private final int width -
height
private final int height -
numPixels
private final int numPixels
-
-
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 arewidth * height * numChannels * 2
bytes.- Parameters:
numChannels
- the number of channels in this image, must be larger than zerowidth
- the horizontal resolution, must be larger than zeroheight
- 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(short newValue) Description copied from interface:ShortChannelImage
Sets all samples of the first channel to the argument short value. Equal toclear(0, newValue);
.- Specified by:
clear
in interfaceShortChannelImage
- Parameters:
newValue
- all samples in the first channel are set to this value- See Also:
-
clear
public void clear(int channelIndex, short newValue) Description copied from interface:ShortChannelImage
Sets all samples of one channel to a new value.- Specified by:
clear
in interfaceShortChannelImage
- Parameters:
channelIndex
- zero-based index of the channel to be cleared (must be smaller thanPixelImage.getNumChannels()
newValue
- all samples in the channel will be set to this value
-
clear
public void clear(int newValue) Description copied from interface:IntegerImage
Sets all samples in the first channel to the argument value. Equal toclear(0, newValue);
:- Specified by:
clear
in interfaceIntegerImage
-
clear
public void clear(int channelIndex, int newValue) Description copied from interface:IntegerImage
Sets all samples of thechannelIndex
'th channel tonewValue
.- Specified by:
clear
in interfaceIntegerImage
-
createCompatibleImage
Description copied from interface:PixelImage
Creates an instance of the same class as this one, with width and height given by the arguments.- Specified by:
createCompatibleImage
in interfacePixelImage
- Parameters:
width
- the horizontal resolution of the new imageheight
- the vertical resolution of the new image- Returns:
- the new image
-
createCopy
Description copied from interface:PixelImage
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 interfacePixelImage
- Returns:
- the new image object
-
getAllocatedMemory
public long getAllocatedMemory()Description copied from interface:PixelImage
Returns the number of bytes that were dynamically allocated for this image object.- Specified by:
getAllocatedMemory
in interfacePixelImage
- Returns:
- allocated memory in bytes
-
getBitsPerPixel
public int getBitsPerPixel()Description copied from interface:PixelImage
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 interfacePixelImage
-
getShortSample
public short getShortSample(int channel, int x, int y) Description copied from interface:ShortChannelImage
Returns a single short sample from the image. When possible, try copying several samples at a time for higher speed (ShortChannelImage.getShortSamples(int, int, int, int, int, short[], int)
).- Specified by:
getShortSample
in interfaceShortChannelImage
- Parameters:
channel
- the number of the channel of the sample; must be from0
toPixelImage.getNumChannels()
- 1x
- the column of the sample to be returned; must be from0
toPixelImage.getWidth()
- 1y
- the row of the sample; must be from0
toPixelImage.getHeight()
- 1- Returns:
- the sample, a single short value
- See Also:
-
getShortSample
public short getShortSample(int x, int y) Description copied from interface:ShortChannelImage
Returns a single short sample from the first channel and the specified position. A call to this method is the same asgetShortSample(0, x, y)
.- Specified by:
getShortSample
in interfaceShortChannelImage
- Parameters:
x
- horizontal position of the sample to be returned (must be between0
andPixelImage.getWidth()
- 1
y
- vertical position of the sample to be returned (must be between0
andPixelImage.getHeight()
- 1
- Returns:
- the requested short sample
-
getShortSamples
public void getShortSamples(int channel, int x, int y, int w, int h, short[] dest, int destOffset) Description copied from interface:ShortChannelImage
Copies samples from this image to a short array. Copiesnum
samples in rowy
of channelchannel
, starting at horizontal offsetx
. Data will be written to thedest
array, starting at offsetdestOffset
. Data will be copied from one row only, so a maximum ofgetWidth()
samples can be copied with a call to this method.- Specified by:
getShortSamples
in interfaceShortChannelImage
- Parameters:
channel
- the index of the channel to be copied from; must be from0
togetNumChannels() - 1
x
- the horizontal offset where copying will start; must be from0
togetWidth() - 1
y
- the row from which will be copied; must be from0
togetHeight() - 1
w
- number of columns to be copiedh
- number of rows to be copieddest
- the array where the data will be copied to; must have a length of at leastdestOffset + num
destOffset
- the offset intodest
where this method will start copying data
-
getHeight
public final int getHeight()Description copied from interface:PixelImage
Returns the vertical resolution of the image in pixels. Must be one or larger.- Specified by:
getHeight
in interfacePixelImage
- Returns:
- height in pixels
-
getMaxSample
public int getMaxSample(int channel) Description copied from interface:IntegerImage
Returns the maximum value for one of the image's channels. The minimum value is always0
.- Specified by:
getMaxSample
in interfaceIntegerImage
- Parameters:
channel
- zero-based index of the channel, from0
toPixelImage.getNumChannels()
- 1
- Returns:
- maximum allowed sample value
-
getNumChannels
public int getNumChannels()Description copied from interface:PixelImage
Returns the number of channels in this image. Must be one or larger.- Specified by:
getNumChannels
in interfacePixelImage
- Returns:
- the number of channels
-
getSample
public final int getSample(int x, int y) Description copied from interface:IntegerImage
Returns one sample of the first channel (index 0). A call to this method must have the same result as the callgetSample(0, x, y);
.- Specified by:
getSample
in interfaceIntegerImage
- Parameters:
x
- the horizontal position of the sample, from0
toPixelImage.getWidth()
- 1
y
- the vertical position of the sample, from0
toPixelImage.getHeight()
- 1
- Returns:
- the desired sample
-
getSample
public final int getSample(int channel, int x, int y) Description copied from interface:IntegerImage
Returns one sample, specified by its channel index and location.- Specified by:
getSample
in interfaceIntegerImage
- Parameters:
channel
- the number of the channel, from0
toPixelImage.getNumChannels()
- 1
x
- the horizontal position of the sample, from0
toPixelImage.getWidth()
- 1
y
- the vertical position of the sample, from0
toPixelImage.getHeight()
- 1
- Returns:
- the desired sample
-
getSamples
public void getSamples(int channel, int x, int y, int w, int h, int[] dest, int destOffs) Description copied from interface:IntegerImage
Copies a number of samples from this image to anint[]
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 oneint
value dest, starting at index destOffs.- Specified by:
getSamples
in interfaceIntegerImage
- Parameters:
channel
- zero-based index of the channel from which data is to be copied (valid values: 0 toPixelImage.getNumChannels()
- 1)x
- horizontal position of upper left corner of the rectangle to be copiedy
- vertical position of upper left corner of the rectangle to be copiedw
- width of rectangle to be copiedh
- height of rectangle to be copieddest
- int array to which the samples will be copieddestOffs
- int index into the dest array for the position to which the samples will be copied
-
getWidth
public final int getWidth()Description copied from interface:PixelImage
Returns the horizontal resolution of the image in pixels. Must be one or larger.- Specified by:
getWidth
in interfacePixelImage
- Returns:
- width in pixels
-
putShortSample
public final void putShortSample(int channel, int x, int y, short newValue) Description copied from interface:ShortChannelImage
Sets one short sample in one channel to a new value.- Specified by:
putShortSample
in interfaceShortChannelImage
-
putShortSample
public final void putShortSample(int x, int y, short newValue) Description copied from interface:ShortChannelImage
Sets one short sample in the first channel (index0
) to a new value. Result is equal toputShortSample(0, x, y, newValue);
.- Specified by:
putShortSample
in interfaceShortChannelImage
-
putShortSamples
public void putShortSamples(int channel, int x, int y, int w, int h, short[] src, int srcOffset) Description copied from interface:ShortChannelImage
Copies a number of samples from the argument array to this image.- Specified by:
putShortSamples
in interfaceShortChannelImage
-
putSamples
public void putSamples(int channel, int x, int y, int w, int h, int[] src, int srcOffs) Description copied from interface:IntegerImage
Copies a number of samples from anint[]
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 oneint
value src, starting at index srcOffset.- Specified by:
putSamples
in interfaceIntegerImage
- Parameters:
channel
- int (from 0 to getNumChannels() - 1) to indicate the channel to which data is copiedx
- horizontal position of upper left corner of the rectangle to be copiedy
- vertical position of upper left corner of the rectangle to be copiedw
- width of rectangle to be copiedh
- height of rectangle to be copiedsrc
- int array from which the samples will be copiedsrcOffs
- int index into the src array for the position from which the samples will be copied
-
putSample
public final void putSample(int x, int y, int newValue) Description copied from interface:IntegerImage
This method sets one sample of the first channel (index 0) to a new value. This call must have the same result as the callputSample(0, x, y)
. The sample location is given by the spatial coordinates, x and y.- Specified by:
putSample
in interfaceIntegerImage
- Parameters:
x
- the horizontal position of the sample, from0
toPixelImage.getWidth()
- 1
y
- the vertical position of the sample, from0
toPixelImage.getHeight()
- 1
newValue
- the new value of the sample
-
putSample
public final void putSample(int channel, int x, int y, int newValue) Description copied from interface:IntegerImage
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 interfaceIntegerImage
- Parameters:
channel
- the number of the channel, from0
toPixelImage.getNumChannels()
- 1
x
- the horizontal position of the sample, from0
toPixelImage.getWidth()
- 1
y
- the vertical position of the sample, from0
toPixelImage.getHeight()
- 1
newValue
- the new value of the sample
-