Class Bitmap

java.lang.Object
org.apache.pdfbox.jbig2.Bitmap

public class Bitmap extends Object
This class represents a bi-level image that is organized like a bitmap.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
    8 pixels per byte, 0 for white, 1 for black
    private final int
    The height of the bitmap in pixels.
    private final int
    The amount of bytes used per row.
    private final int
    The width of the bitmap in pixels.
  • 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

    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
     
    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
    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)
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • height

      private final int height
      The height of the bitmap in pixels.
    • width

      private final int width
      The width of the bitmap in pixels.
    • rowStride

      private final int rowStride
      The amount of bytes used per row.
    • bitmap

      private byte[] bitmap
      8 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 value 0 for white and 1 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 and 1 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 an IndexOutOfBoundsException 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 an IndexOutOfBoundsException 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 an IndexOutOfBoundsException 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

      public Rectangle getBounds()
    • getMemorySize

      public int getMemorySize()
      Deprecated.
      renamed, will be removed in a future release. Use getLength() 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(Object obj)
      Overrides:
      equals in class 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 Bitmap
      srcPos - start position within the source Bitmap
      dest - the destination Bitmap
      destPos - start position within the destination Bitmap
      length - the number of bytes to be copied