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 int
private final byte[]
private final int
private final int
Fields 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 void
checkBitOffset
(int bitOffset) private void
checkPositionAndNumber
(int x, int y, int w, int h) private void
checkValue
(int value) 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
.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.int
Returns 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, theClass
object associated with that interface (or class) is returned (ornull
otherwise).int
getMaxSample
(int channelIndex) Returns the maximum value for one of the image's channels.int
Returns the number of channels in this image.void
getPackedBytes
(int x, int y, int numSamples, byte[] dest, int destOffset, int destBitOffset) Sets a number of samples in the argument array from this image.int
getSample
(int x, int y) Returns one sample of the first channel (index 0).int
getSample
(int channelIndex, int x, int y) Returns one sample, specified by its channel index and location.void
getSamples
(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.int
getWidth()
Returns the horizontal resolution of the image in pixels.boolean
isBlack
(int x, int y) Returns if the pixel specified by the location in the arguments is black.boolean
isWhite
(int x, int y) Returns if the pixel specified by the location in the arguments is white.void
putBlack
(int x, int y) Sets a pixel to black (minimum intensity value).void
putPackedBytes
(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.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 channelIndex, int x, int y, int newValue) This method sets one sample to a new value.void
putSamples
(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.void
putWhite
(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: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
-
getHeight
public 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
-
getImageType
Description copied from interface:PixelImage
If there is a single interface or class that describes the image data type of this class, theClass
object associated with that interface (or class) is returned (ornull
otherwise). ThisClass
object, if available for two image objects, can be used to find out if they are compatible. Example:MemoryGray8Image
returnsnet.sourceforge.jiu.data.Gray8Image.class
.- Specified by:
getImageType
in interfacePixelImage
-
getMaxSample
public int getMaxSample(int channelIndex) 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:
channelIndex
- 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
-
getPackedBytes
public void getPackedBytes(int x, int y, int numSamples, byte[] dest, int destOffset, int destBitOffset) Description copied from interface:BilevelImage
Sets a number of samples in the argument array from this image.- Specified by:
getPackedBytes
in 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: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 int getSample(int channelIndex, 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:
channelIndex
- 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 channelIndex, int x, int y, int w, int h, int[] dest, int destOffset) 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:
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:PixelImage
Returns the horizontal resolution of the image in pixels. Must be one or larger.- Specified by:
getWidth
in interfacePixelImage
- Returns:
- width in pixels
-
isBlack
public boolean isBlack(int x, int y) Description copied from interface:GrayImage
Returns if the pixel specified by the location in the arguments is black. -
isWhite
public boolean isWhite(int x, int y) Description copied from interface:GrayImage
Returns if the pixel specified by the location in the arguments is white. -
putBlack
public void putBlack(int x, int y) Description copied from interface:GrayImage
Sets 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:BilevelImage
Sets a number of samples in the image from the argument array data.- Specified by:
putPackedBytes
in 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: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 void putSample(int channelIndex, 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:
channelIndex
- 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
-
putSamples
public void putSamples(int channelIndex, int x, int y, int w, int h, int[] src, int srcOffset) 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:
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:GrayImage
Sets a pixel to white (maximum intensity value).
-