public class MemoryBilevelImage extends java.lang.Object implements BilevelImage
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.Modifier and Type | Field and Description |
---|---|
private int |
BYTES_PER_ROW |
private byte[] |
data |
private int |
HEIGHT |
private int |
WIDTH |
BLACK, WHITE
Constructor and Description |
---|
MemoryBilevelImage(int width,
int height)
Create a new MemoryBilevelImage object with the specified resolution.
|
Modifier and Type | Method and Description |
---|---|
private 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 the
channelIndex 'th channel to newValue . |
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.
|
java.lang.Class |
getImageType()
If there is a single interface or class that describes the image data type
of this class, the
Class object associated with that
interface (or class) is returned (or null otherwise). |
int |
getMaxSample(int channelIndex)
Returns the maximum value for one of the image's channels.
|
int |
getNumChannels()
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 an
int[] 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 an
int[] array to this image. |
void |
putWhite(int x,
int y)
Sets a pixel to white (maximum intensity value).
|
private final int BYTES_PER_ROW
private final byte[] data
private final int HEIGHT
private final int WIDTH
public MemoryBilevelImage(int width, int height)
width
- the horizontal resolution of the new image, must be larger than zeroheight
- the vertical resolution of the new image, must be larger than zerojava.lang.IllegalArgumentException
- if any of the two parameters is smaller than oneprivate void checkBitOffset(int bitOffset)
private void checkPositionAndNumber(int x, int y, int w, int h)
private void checkValue(int value)
public void clear(int newValue)
IntegerImage
clear(0, newValue);
:clear
in interface IntegerImage
public void clear(int channelIndex, int newValue)
IntegerImage
channelIndex
'th channel to newValue
.clear
in interface IntegerImage
public PixelImage createCompatibleImage(int width, int height)
PixelImage
createCompatibleImage
in interface PixelImage
width
- the horizontal resolution of the new imageheight
- the vertical resolution of the new imagepublic PixelImage createCopy()
PixelImage
createCopy
in interface PixelImage
public long getAllocatedMemory()
PixelImage
getAllocatedMemory
in interface PixelImage
public int getBitsPerPixel()
PixelImage
getBitsPerPixel
in interface PixelImage
public int getHeight()
PixelImage
getHeight
in interface PixelImage
public java.lang.Class getImageType()
PixelImage
Class
object associated with that
interface (or class) is returned (or null
otherwise).
This Class
object, if available for two image objects,
can be used to find out if they are compatible.
Example: MemoryGray8Image
returns
net.sourceforge.jiu.data.Gray8Image.class
.getImageType
in interface PixelImage
public int getMaxSample(int channelIndex)
IntegerImage
0
.getMaxSample
in interface IntegerImage
channelIndex
- zero-based index of the channel, from 0
to PixelImage.getNumChannels()
- 1
public int getNumChannels()
PixelImage
getNumChannels
in interface PixelImage
public void getPackedBytes(int x, int y, int numSamples, byte[] dest, int destOffset, int destBitOffset)
BilevelImage
getPackedBytes
in interface BilevelImage
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 of dest[destOffset]
to write a sample to (0 is leftmost, 1 is second-leftmost up to 7, which is the rightmost)public int getSample(int x, int y)
IntegerImage
getSample(0, x, y);
.getSample
in interface IntegerImage
x
- the horizontal position of the sample, from 0
to PixelImage.getWidth()
- 1
y
- the vertical position of the sample, from 0
to PixelImage.getHeight()
- 1
public int getSample(int channelIndex, int x, int y)
IntegerImage
getSample
in interface IntegerImage
channelIndex
- the number of the channel, from 0
to PixelImage.getNumChannels()
- 1
x
- the horizontal position of the sample, from 0
to PixelImage.getWidth()
- 1
y
- the vertical position of the sample, from 0
to PixelImage.getHeight()
- 1
public void getSamples(int channelIndex, int x, int y, int w, int h, int[] dest, int destOffset)
IntegerImage
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.getSamples
in interface IntegerImage
channelIndex
- zero-based index of the channel from which data is to be copied (valid values: 0 to PixelImage.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 copiedpublic int getWidth()
PixelImage
getWidth
in interface PixelImage
public boolean isBlack(int x, int y)
GrayImage
public boolean isWhite(int x, int y)
GrayImage
public void putBlack(int x, int y)
GrayImage
public void putPackedBytes(int x, int y, int numSamples, byte[] src, int srcOffset, int srcBitOffset)
BilevelImage
putPackedBytes
in interface BilevelImage
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 of src[srcOffset]
to
read a sample from (0 is leftmost, 1 is second-leftmost up to 7, which is the rightmost)public void putSample(int x, int y, int newValue)
IntegerImage
putSample(0, x, y)
.
The sample location is given by the spatial coordinates, x and y.putSample
in interface IntegerImage
x
- the horizontal position of the sample, from 0
to PixelImage.getWidth()
- 1
y
- the vertical position of the sample, from 0
to PixelImage.getHeight()
- 1
newValue
- the new value of the samplepublic void putSample(int channelIndex, int x, int y, int newValue)
IntegerImage
putSample
in interface IntegerImage
channelIndex
- the number of the channel, from 0
to PixelImage.getNumChannels()
- 1
x
- the horizontal position of the sample, from 0
to PixelImage.getWidth()
- 1
y
- the vertical position of the sample, from 0
to PixelImage.getHeight()
- 1
newValue
- the new value of the samplepublic void putSamples(int channelIndex, int x, int y, int w, int h, int[] src, int srcOffset)
IntegerImage
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.putSamples
in interface IntegerImage
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