Package net.sourceforge.jiu.data

# Class MemoryBilevelImage

java.lang.Object
net.sourceforge.jiu.data.MemoryBilevelImage

All Implemented Interfaces:
  `BilevelImage`, `GrayImage`, `GrayIntegerImage`, `IntegerImage`, `PixelImage`

public class MemoryBilevelImage extends Object implements BilevelImage
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

Fields
Modifier and Type
Field
Description
`private final int`
`BYTES_PER_ROW`
`private final byte[]`
`data`
`private final int`
`HEIGHT`
`private final int`
`WIDTH`

### Fields inherited from interface net.sourceforge.jiu.data.BilevelImage

`BLACK, WHITE`

## Constructor Summary

Constructors
Constructor
Description
`MemoryBilevelImage(int width, int height)`
Create a new MemoryBilevelImage object with the specified resolution.

## Method Summary

Modifier and Type
Method
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.
`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).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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 zero
  `height` - 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 to `clear(0, newValue);`:

Specified by:
  `clear` in interface `IntegerImage`

### clear

public void clear(int channelIndex, int newValue)
Description copied from interface: `IntegerImage`
Sets all samples of the `channelIndex`'th channel to `newValue`.

Specified by:
  `clear` in interface `IntegerImage`

### createCompatibleImage

public PixelImage createCompatibleImage(int width, int height)
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 interface `PixelImage`
Parameters:
  `width` - the horizontal resolution of the new image
  `height` - the vertical resolution of the new image
Returns:
  the new image

### createCopy

public PixelImage 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 interface `PixelImage`
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 interface `PixelImage`
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 interface `PixelImage`

### 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 interface `PixelImage`
Returns:
  height in pixels

### getImageType

public Class getImageType()
Description copied from interface: `PixelImage`
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). 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`.

Specified by:
  `getImageType` in interface `PixelImage`

### 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 always `0`.

Specified by:
  `getMaxSample` in interface `IntegerImage`
Parameters:
  `channelIndex` - zero-based index of the channel, from `0` to `PixelImage.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 interface `PixelImage`
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 interface `BilevelImage`
Parameters:
  `x` - horizontal position of first sample of this image to read
  `y` - vertical position of samples to be read from this image
  `numSamples` - number of samples to be set
  `dest` - array with packed pixels to which samples are copied
  `destOffset` - index into dest array of the first byte value to write sample values to
  `destBitOffset` - 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)

### 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 call `getSample(0, x, y);`.

Specified by:
  `getSample` in interface `IntegerImage`
Parameters:
  `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`
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 interface `IntegerImage`
Parameters:
  `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`
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 an `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.

Specified by:
  `getSamples` in interface `IntegerImage`
Parameters:
  `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 copied
  `y` - vertical position of upper left corner of the rectangle to be copied
  `w` - width of rectangle to be copied
  `h` - height of rectangle to be copied
  `dest` - int array to which the samples will be copied
  `destOffset` - 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 interface `PixelImage`
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.

Specified by:
  `isBlack` in interface `GrayImage`
Parameters:
  `x` - the horizontal location of the pixel
  `y` - the vertical location of the pixel

### 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.

Specified by:
  `isWhite` in interface `GrayImage`
Parameters:
  `x` - the horizontal location of the pixel
  `y` - the vertical location of the pixel

### putBlack

public void putBlack(int x, int y)
Description copied from interface: `GrayImage`
Sets a pixel to black (minimum intensity value).

Specified by:
  `putBlack` in interface `GrayImage`
Parameters:
  `x` - horizontal position of the pixel's location
  `y` - vertical position of the pixel's location

### 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 interface `BilevelImage`
Parameters:
  `x` - horizontal position of first sample to be set
  `y` - vertical position of samples to be set
  `numSamples` - number of samples to be set
  `src` - array with packed pixels to be set
  `srcOffset` - index into src array of the first byte value to read sample values from
  `srcBitOffset` - 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)

### 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 call `putSample(0, x, y)`. The sample location is given by the spatial coordinates, x and y.

Specified by:
  `putSample` in interface `IntegerImage`
Parameters:
  `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 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 interface `IntegerImage`
Parameters:
  `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 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 an `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.

Specified by:
  `putSamples` in interface `IntegerImage`
Parameters:
  `channelIndex` - int (from 0 to getNumChannels() - 1) to indicate the channel to which data is copied
  `x` - horizontal position of upper left corner of the rectangle to be copied
  `y` - vertical position of upper left corner of the rectangle to be copied
  `w` - width of rectangle to be copied
  `h` - height of rectangle to be copied
  `src` - int array from which the samples will be copied
  `srcOffset` - 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).

Specified by:
  `putWhite` in interface `GrayImage`
Parameters:
  `x` - horizontal position of the pixel's location
  `y` - vertical position of the pixel's location