Package net.sourceforge.jiu.data
Class MemoryByteChannelImage
- java.lang.Object
-
- net.sourceforge.jiu.data.MemoryByteChannelImage
-
- All Implemented Interfaces:
ByteChannelImage,IntegerImage,PixelImage
- Direct Known Subclasses:
MemoryGray8Image,MemoryPaletted8Image,MemoryRGB24Image
public abstract class MemoryByteChannelImage extends Object implements ByteChannelImage
An implementation ofByteChannelImagethat stores image channels asbyte[]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
MemoryGray8Imageto give meaning to the values.- Author:
- Marco Schmidt
-
-
Field Summary
Fields Modifier and Type Field Description private byte[][]dataprivate byte[]firstChannelprivate intheightprivate intnumChannelsprivate intnumPixelsprivate intwidth
-
Constructor Summary
Constructors Constructor Description MemoryByteChannelImage(int numChannels, int width, int height)Create an image of byte channels.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckPositionAndNumber(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.voidclear(byte newValue)Sets all samples of the first channel to the argument byte value.voidclear(int newValue)Sets all samples in the first channel to the argument value.voidclear(int channelIndex, byte newValue)Sets all samples of one channel to a new value.voidclear(int channelIndex, int newValue)Sets all samples of thechannelIndex'th channel tonewValue.abstract PixelImagecreateCompatibleImage(int width, int height)Creates an instance of the same class as this one, with width and height given by the arguments.PixelImagecreateCopy()Creates an new image object that will be of the same type as this one, with the same image data, using entirely new resources.longgetAllocatedMemory()Returns the number of bytes that were dynamically allocated for this image object.intgetBitsPerPixel()Returns the number of bits per pixel of this image.bytegetByteSample(int x, int y)Returns a single byte sample from the first channel and the specified position.bytegetByteSample(int channel, int x, int y)Returns a single byte sample from the image.voidgetByteSamples(int channel, int x, int y, int w, int h, byte[] dest, int destOffset)Copies samples from this image to a byte array.intgetHeight()Returns the vertical resolution of the image in pixels.intgetMaxSample(int channel)Returns the maximum value for one of the image's channels.intgetNumChannels()Returns the number of channels in this image.intgetSample(int x, int y)Returns one sample of the first channel (index 0).intgetSample(int channel, int x, int y)Returns one sample, specified by its channel index and location.voidgetSamples(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.intgetWidth()Returns the horizontal resolution of the image in pixels.voidputByteSample(int x, int y, byte newValue)Sets one byte sample in the first channel (index0) to a new value.voidputByteSample(int channel, int x, int y, byte newValue)Sets one byte sample in one channel to a new value.voidputByteSamples(int channel, int x, int y, int w, int h, byte[] src, int srcOffset)Copies a number of samples from the argument array to this image.voidputSample(int x, int y, int newValue)This method sets one sample of the first channel (index 0) to a new value.voidputSample(int channel, int x, int y, int newValue)This method sets one sample to a new value.voidputSamples(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.-
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
-
-
-
-
Constructor Detail
-
MemoryByteChannelImage
public MemoryByteChannelImage(int numChannels, int width, int height)Create an image of byte channels. Image data will be completely in memory, so memory requirements arewidth * height * numChannelsbytes. Note that the data will not be initialized, so you should not assume anything about its content.- Parameters:
numChannels- the number of channels in this image, must be non-zero and positivewidth- the horizontal resolution, must be non-zero and positiveheight- the vertical resolution, must be non-zero and positive- Throws:
IllegalArgumentException- if any of the parameters are invalid or if width times height exceeds two GBOutOfMemoryException- if there is not enough free memory for the specified resolution
-
-
Method Detail
-
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(byte newValue)
Description copied from interface:ByteChannelImageSets all samples of the first channel to the argument byte value. Equal toclear(0, newValue);.- Specified by:
clearin interfaceByteChannelImage- Parameters:
newValue- all samples in the first channel are set to this value- See Also:
ByteChannelImage.clear(int, byte),IntegerImage.clear(int),IntegerImage.clear(int, int)
-
clear
public void clear(int channelIndex, byte newValue)Description copied from interface:ByteChannelImageSets all samples of one channel to a new value.- Specified by:
clearin interfaceByteChannelImage- 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:IntegerImageSets all samples in the first channel to the argument value. Equal toclear(0, newValue);:- Specified by:
clearin interfaceIntegerImage
-
clear
public void clear(int channelIndex, int newValue)Description copied from interface:IntegerImageSets all samples of thechannelIndex'th channel tonewValue.- Specified by:
clearin interfaceIntegerImage
-
createCompatibleImage
public abstract PixelImage createCompatibleImage(int width, int height)
Description copied from interface:PixelImageCreates an instance of the same class as this one, with width and height given by the arguments.- Specified by:
createCompatibleImagein interfacePixelImage- Parameters:
width- the horizontal resolution of the new imageheight- the vertical resolution of the new image- Returns:
- the new image
-
createCopy
public PixelImage createCopy()
Description copied from interface:PixelImageCreates 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:
createCopyin interfacePixelImage- Returns:
- the new image object
-
getAllocatedMemory
public long getAllocatedMemory()
Description copied from interface:PixelImageReturns the number of bytes that were dynamically allocated for this image object.- Specified by:
getAllocatedMemoryin interfacePixelImage- Returns:
- allocated memory in bytes
-
getBitsPerPixel
public int getBitsPerPixel()
Description copied from interface:PixelImageReturns 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:
getBitsPerPixelin interfacePixelImage
-
getByteSample
public byte getByteSample(int channel, int x, int y)Description copied from interface:ByteChannelImageReturns a single byte sample from the image. When possible, try copying several samples at a time for higher speed (ByteChannelImage.getByteSamples(int, int, int, int, int, byte[], int)).- Specified by:
getByteSamplein interfaceByteChannelImage- Parameters:
channel- the number of the channel of the sample; must be from0toPixelImage.getNumChannels()- 1x- the column of the sample to be returned; must be from0toPixelImage.getWidth()- 1y- the row of the sample; must be from0toPixelImage.getHeight()- 1- Returns:
- the sample, a single byte value
- See Also:
ByteChannelImage.getByteSamples(int, int, int, int, int, byte[], int)
-
getByteSample
public byte getByteSample(int x, int y)Description copied from interface:ByteChannelImageReturns a single byte sample from the first channel and the specified position. A call to this method is the same asgetByteSample(0, x, y).- Specified by:
getByteSamplein interfaceByteChannelImage- Parameters:
x- horizontal position of the sample to be returned (must be between0andPixelImage.getWidth()- 1y- vertical position of the sample to be returned (must be between0andPixelImage.getHeight()- 1- Returns:
- the requested byte sample
-
getByteSamples
public void getByteSamples(int channel, int x, int y, int w, int h, byte[] dest, int destOffset)Description copied from interface:ByteChannelImageCopies samples from this image to a byte array. Copiesnumsamples in rowyof channelchannel, starting at horizontal offsetx. Data will be written to thedestarray, 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:
getByteSamplesin interfaceByteChannelImage- Parameters:
channel- the index of the channel to be copied from; must be from0togetNumChannels() - 1x- the horizontal offset where copying will start; must be from0togetWidth() - 1y- the row from which will be copied; must be from0togetHeight() - 1w- the number of columns to be copiedh- the number of rows to be copieddest- the array where the data will be copied to; must have a length of at leastdestOffset + numdestOffset- the offset intodestwhere this method will start copying data
-
getHeight
public final int getHeight()
Description copied from interface:PixelImageReturns the vertical resolution of the image in pixels. Must be one or larger.- Specified by:
getHeightin interfacePixelImage- Returns:
- height in pixels
-
getMaxSample
public int getMaxSample(int channel)
Description copied from interface:IntegerImageReturns the maximum value for one of the image's channels. The minimum value is always0.- Specified by:
getMaxSamplein interfaceIntegerImage- Parameters:
channel- zero-based index of the channel, from0toPixelImage.getNumChannels()- 1- Returns:
- maximum allowed sample value
-
getNumChannels
public int getNumChannels()
Description copied from interface:PixelImageReturns the number of channels in this image. Must be one or larger.- Specified by:
getNumChannelsin interfacePixelImage- Returns:
- the number of channels
-
getSample
public final int getSample(int x, int y)Description copied from interface:IntegerImageReturns 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:
getSamplein interfaceIntegerImage- Parameters:
x- the horizontal position of the sample, from0toPixelImage.getWidth()- 1y- the vertical position of the sample, from0toPixelImage.getHeight()- 1- Returns:
- the desired sample
-
getSample
public final int getSample(int channel, int x, int y)Description copied from interface:IntegerImageReturns one sample, specified by its channel index and location.- Specified by:
getSamplein interfaceIntegerImage- Parameters:
channel- the number of the channel, from0toPixelImage.getNumChannels()- 1x- the horizontal position of the sample, from0toPixelImage.getWidth()- 1y- the vertical position of the sample, from0toPixelImage.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:IntegerImageCopies 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 oneintvalue dest, starting at index destOffs.- Specified by:
getSamplesin 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:PixelImageReturns the horizontal resolution of the image in pixels. Must be one or larger.- Specified by:
getWidthin interfacePixelImage- Returns:
- width in pixels
-
putByteSample
public final void putByteSample(int channel, int x, int y, byte newValue)Description copied from interface:ByteChannelImageSets one byte sample in one channel to a new value.- Specified by:
putByteSamplein interfaceByteChannelImage
-
putByteSample
public final void putByteSample(int x, int y, byte newValue)Description copied from interface:ByteChannelImageSets one byte sample in the first channel (index0) to a new value. Result is equal toputByteSample(0, x, y, newValue);.- Specified by:
putByteSamplein interfaceByteChannelImage
-
putByteSamples
public void putByteSamples(int channel, int x, int y, int w, int h, byte[] src, int srcOffset)Description copied from interface:ByteChannelImageCopies a number of samples from the argument array to this image.- Specified by:
putByteSamplesin interfaceByteChannelImage
-
putSamples
public void putSamples(int channel, int x, int y, int w, int h, int[] src, int srcOffs)Description copied from interface:IntegerImageCopies 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 oneintvalue src, starting at index srcOffset.- Specified by:
putSamplesin 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:IntegerImageThis 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:
putSamplein interfaceIntegerImage- Parameters:
x- the horizontal position of the sample, from0toPixelImage.getWidth()- 1y- the vertical position of the sample, from0toPixelImage.getHeight()- 1newValue- the new value of the sample
-
putSample
public final void putSample(int channel, int x, int y, int newValue)Description copied from interface:IntegerImageThis 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:
putSamplein interfaceIntegerImage- Parameters:
channel- the number of the channel, from0toPixelImage.getNumChannels()- 1x- the horizontal position of the sample, from0toPixelImage.getWidth()- 1y- the vertical position of the sample, from0toPixelImage.getHeight()- 1newValue- the new value of the sample
-
-