Package org.apache.pdfbox.jbig2
Class Bitmap
java.lang.Object
org.apache.pdfbox.jbig2.Bitmap
This class represents a bi-level image that is organized like a bitmap.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBitmap
(int width, int height) Creates an instance of a blank image.
The image data is stored in a byte array. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Copy parts of the underlying array of a Bitmap to another Bitmap.boolean
void
fillBitmap
(byte fillByte) Fill the underlying bitmap with the given byte value.int
getBitOffset
(int x) Computes the offset of the given x coordinate in its byte.byte
getByte
(int index) Simply returns a byte from the bitmap byte array.byte[]
Deprecated.don't expose the underlying byte array, will be removed in a future release.int
getByteAsInteger
(int index) Converts the byte at specified index into an integer and returns the value.int
getByteIndex
(int x, int y) Returns the index of the byte that contains the pixel, specified by the pixel's x and y coordinates.int
Simply returns the height of this bitmap.int
Returns the length of the underlying byte array.int
Deprecated.renamed, will be removed in a future release.byte
getPixel
(int x, int y) Returns the value of a pixel specified by the given coordinates.int
Simply returns the row stride of this bitmap.int
getWidth()
Simply returns the width of this bitmap.void
setByte
(int index, byte value) Simply sets the given value at the given array index position.void
setPixel
(int x, int y, byte pixelValue)
-
Field Details
-
height
private final int heightThe height of the bitmap in pixels. -
width
private final int widthThe width of the bitmap in pixels. -
rowStride
private final int rowStrideThe amount of bytes used per row. -
bitmap
private byte[] bitmap8 pixels per byte, 0 for white, 1 for black
-
-
Constructor Details
-
Bitmap
public Bitmap(int width, int height) Creates an instance of a blank image.
The image data is stored in a byte array. Each pixels is stored as one bit, so that each byte contains 8 pixel. A pixel has by default the value0
for white and1
for black.
Row stride means the amount of bytes per line. It is computed automatically and fills the pad bits with 0.- Parameters:
width
- - The real width of the bitmap in pixels.height
- - The real height of the bitmap in pixels.
-
-
Method Details
-
getPixel
public byte getPixel(int x, int y) Returns the value of a pixel specified by the given coordinates.By default, the value is
0
for a white pixel and1
for a black pixel. The value is placed in the rightmost bit in the byte.- Parameters:
x
- - The x coordinate of the pixel.y
- - The y coordinate of the pixel.- Returns:
- The value of a pixel.
-
setPixel
public void setPixel(int x, int y, byte pixelValue) -
getByteIndex
public int getByteIndex(int x, int y) Returns the index of the byte that contains the pixel, specified by the pixel's x and y coordinates.
- Parameters:
x
- - The pixel's x coordinate.y
- - The pixel's y coordinate.- Returns:
- The index of the byte that contains the specified pixel.
-
getByteArray
public byte[] getByteArray()Deprecated.don't expose the underlying byte array, will be removed in a future release.Simply returns the byte array of this bitmap.- Returns:
- The byte array of this bitmap.
-
getByte
public byte getByte(int index) Simply returns a byte from the bitmap byte array. Throws anIndexOutOfBoundsException
if the given index is out of bound.- Parameters:
index
- - The array index that specifies the position of the wanted byte.- Returns:
- The byte at the
index
-position. - Throws:
IndexOutOfBoundsException
- if the index is out of bound.
-
setByte
public void setByte(int index, byte value) Simply sets the given value at the given array index position. Throws anIndexOutOfBoundsException
if the given index is out of bound.- Parameters:
index
- - The array index that specifies the position of a byte.value
- - The byte that should be set.- Throws:
IndexOutOfBoundsException
- if the index is out of bound.
-
getByteAsInteger
public int getByteAsInteger(int index) Converts the byte at specified index into an integer and returns the value. Throws anIndexOutOfBoundsException
if the given index is out of bound.- Parameters:
index
- - The array index that specifies the position of the wanted byte.- Returns:
- The converted byte at the
index
-position as an integer. - Throws:
IndexOutOfBoundsException
- if the index is out of bound.
-
getBitOffset
public int getBitOffset(int x) Computes the offset of the given x coordinate in its byte. The method uses optimized modulo operation for a better performance.- Parameters:
x
- - The x coordinate of a pixel.- Returns:
- The bit offset of a pixel in its byte.
-
getHeight
public int getHeight()Simply returns the height of this bitmap.- Returns:
- The height of this bitmap.
-
getWidth
public int getWidth()Simply returns the width of this bitmap.- Returns:
- The width of this bitmap.
-
getRowStride
public int getRowStride()Simply returns the row stride of this bitmap.
(Row stride means the amount of bytes per line.)- Returns:
- The row stride of this bitmap.
-
getBounds
-
getMemorySize
public int getMemorySize()Deprecated.renamed, will be removed in a future release. UsegetLength()
instead.Returns the length of the underlying byte array.- Returns:
- byte array length
-
getLength
public int getLength()Returns the length of the underlying byte array.- Returns:
- byte array length
-
fillBitmap
public void fillBitmap(byte fillByte) Fill the underlying bitmap with the given byte value.- Parameters:
fillByte
- the value to be stored in all elements of the bitmap
-
equals
-
arraycopy
Copy parts of the underlying array of a Bitmap to another Bitmap.- Parameters:
src
- the source BitmapsrcPos
- start position within the source Bitmapdest
- the destination BitmapdestPos
- start position within the destination Bitmaplength
- the number of bytes to be copied
-