Package org.apache.pdfbox.jbig2
Class Bitmap
- java.lang.Object
-
- org.apache.pdfbox.jbig2.Bitmap
-
public class Bitmap extends java.lang.Object
This class represents a bi-level image that is organized like a bitmap.
-
-
Constructor Summary
Constructors Constructor Description Bitmap(int width, int height)
Creates an instance of a blank image.
The image data is stored in a byte array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
arraycopy(Bitmap src, int srcPos, Bitmap dest, int destPos, int length)
Copy parts of the underlying array of a Bitmap to another Bitmap.boolean
equals(java.lang.Object obj)
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.java.awt.Rectangle
getBounds()
byte
getByte(int index)
Simply returns a byte from the bitmap byte array.byte[]
getByteArray()
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
getHeight()
Simply returns the height of this bitmap.int
getLength()
Returns the length of the underlying byte array.int
getMemorySize()
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
getRowStride()
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)
-
-
-
Constructor Detail
-
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:
height
- - The real height of the bitmap in pixels.width
- - The real width of the bitmap in pixels.
-
-
Method Detail
-
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:
java.lang.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:
java.lang.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:
java.lang.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
public java.awt.Rectangle 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
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
arraycopy
public static void arraycopy(Bitmap src, int srcPos, Bitmap dest, int destPos, int length)
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
-
-