Package net.sourceforge.jiu.data
Class MemoryBilevelImage
java.lang.Object
net.sourceforge.jiu.data.MemoryBilevelImage
- All Implemented Interfaces:
BilevelImage,GrayImage,GrayIntegerImage,IntegerImage,PixelImage
An implementation of the
BilevelImage interface that stores image
data in a byte array in memory.
An image of width times height pixels will require
(width + 7) / 8 * height bytes of memory.- Author:
- Marco Schmidt
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final byte[]private final intprivate final intFields inherited from interface net.sourceforge.jiu.data.BilevelImage
BLACK, WHITE -
Constructor Summary
ConstructorsConstructorDescriptionMemoryBilevelImage(int width, int height) Create a new MemoryBilevelImage object with the specified resolution. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckBitOffset(int bitOffset) private voidcheckPositionAndNumber(int x, int y, int w, int h) private voidcheckValue(int value) voidclear(int newValue) Sets all samples in the first channel to the argument value.voidclear(int channelIndex, int newValue) Sets all samples of thechannelIndex'th channel tonewValue.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.longReturns the number of bytes that were dynamically allocated for this image object.intReturns the number of bits per pixel of this image.intReturns the vertical resolution of the image in pixels.If there is a single interface or class that describes the image data type of this class, theClassobject associated with that interface (or class) is returned (ornullotherwise).intgetMaxSample(int channelIndex) Returns the maximum value for one of the image's channels.intReturns the number of channels in this image.voidgetPackedBytes(int x, int y, int numSamples, byte[] dest, int destOffset, int destBitOffset) Sets a number of samples in the argument array from this image.intgetSample(int x, int y) Returns one sample of the first channel (index 0).intgetSample(int channelIndex, int x, int y) Returns one sample, specified by its channel index and location.voidgetSamples(int channelIndex, int x, int y, int w, int h, int[] dest, int destOffset) Copies a number of samples from this image to anint[]object.intgetWidth()Returns the horizontal resolution of the image in pixels.booleanisBlack(int x, int y) Returns if the pixel specified by the location in the arguments is black.booleanisWhite(int x, int y) Returns if the pixel specified by the location in the arguments is white.voidputBlack(int x, int y) Sets a pixel to black (minimum intensity value).voidputPackedBytes(int x, int y, int numSamples, byte[] src, int srcOffset, int srcBitOffset) Sets a number of samples in the image from the argument array data.voidputSample(int x, int y, int newValue) This method sets one sample of the first channel (index 0) to a new value.voidputSample(int channelIndex, int x, int y, int newValue) This method sets one sample to a new value.voidputSamples(int channelIndex, int x, int y, int w, int h, int[] src, int srcOffset) Copies a number of samples from anint[]array to this image.voidputWhite(int x, int y) Sets a pixel to white (maximum intensity value).
-
Field Details
-
BYTES_PER_ROW
private final int BYTES_PER_ROW -
data
private final byte[] data -
HEIGHT
private final int HEIGHT -
WIDTH
private final int WIDTH
-
-
Constructor Details
-
MemoryBilevelImage
public MemoryBilevelImage(int width, int height) Create a new MemoryBilevelImage object with the specified resolution.- Parameters:
width- the horizontal resolution of the new image, must be larger than zeroheight- the vertical resolution of the new image, must be larger than zero- Throws:
IllegalArgumentException- if any of the two parameters is smaller than one
-
-
Method Details
-
checkBitOffset
private void checkBitOffset(int bitOffset) -
checkPositionAndNumber
private void checkPositionAndNumber(int x, int y, int w, int h) -
checkValue
private void checkValue(int 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
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
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
-
getHeight
public 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
-
getImageType
Description copied from interface:PixelImageIf there is a single interface or class that describes the image data type of this class, theClassobject associated with that interface (or class) is returned (ornullotherwise). ThisClassobject, if available for two image objects, can be used to find out if they are compatible. Example:MemoryGray8Imagereturnsnet.sourceforge.jiu.data.Gray8Image.class.- Specified by:
getImageTypein interfacePixelImage
-
getMaxSample
public int getMaxSample(int channelIndex) 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:
channelIndex- 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
-
getPackedBytes
public void getPackedBytes(int x, int y, int numSamples, byte[] dest, int destOffset, int destBitOffset) Description copied from interface:BilevelImageSets a number of samples in the argument array from this image.- Specified by:
getPackedBytesin interfaceBilevelImage- Parameters:
x- horizontal position of first sample of this image to ready- vertical position of samples to be read from this imagenumSamples- number of samples to be setdest- array with packed pixels to which samples are copieddestOffset- index into dest array of the first byte value to write sample values todestBitOffset- index of first bit ofdest[destOffset]to write a sample to (0 is leftmost, 1 is second-leftmost up to 7, which is the rightmost)
-
getSample
public 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 int getSample(int channelIndex, int x, int y) Description copied from interface:IntegerImageReturns one sample, specified by its channel index and location.- Specified by:
getSamplein interfaceIntegerImage- Parameters:
channelIndex- 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 channelIndex, int x, int y, int w, int h, int[] dest, int destOffset) 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:
channelIndex- 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 copieddestOffset- int index into the dest array for the position to which the samples will be copied
-
getWidth
public 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
-
isBlack
public boolean isBlack(int x, int y) Description copied from interface:GrayImageReturns if the pixel specified by the location in the arguments is black. -
isWhite
public boolean isWhite(int x, int y) Description copied from interface:GrayImageReturns if the pixel specified by the location in the arguments is white. -
putBlack
public void putBlack(int x, int y) Description copied from interface:GrayImageSets a pixel to black (minimum intensity value). -
putPackedBytes
public void putPackedBytes(int x, int y, int numSamples, byte[] src, int srcOffset, int srcBitOffset) Description copied from interface:BilevelImageSets a number of samples in the image from the argument array data.- Specified by:
putPackedBytesin interfaceBilevelImage- Parameters:
x- horizontal position of first sample to be sety- vertical position of samples to be setnumSamples- number of samples to be setsrc- array with packed pixels to be setsrcOffset- index into src array of the first byte value to read sample values fromsrcBitOffset- index of first bit ofsrc[srcOffset]to read a sample from (0 is leftmost, 1 is second-leftmost up to 7, which is the rightmost)
-
putSample
public 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 void putSample(int channelIndex, 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:
channelIndex- 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
-
putSamples
public void putSamples(int channelIndex, int x, int y, int w, int h, int[] src, int srcOffset) 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:
channelIndex- 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 copiedsrcOffset- int index into the src array for the position from which the samples will be copied
-
putWhite
public void putWhite(int x, int y) Description copied from interface:GrayImageSets a pixel to white (maximum intensity value).
-