Class SlidingBitmapWindow

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

public class SlidingBitmapWindow extends Object
A sliding 3-row bit window over a Bitmap, providing efficient single-bit access to a 3-row neighbourhood around a current position.

The window maintains three rows simultaneously: the row above (-1), the current row (0), and the row below (+1). Each row is held as a 24-bit register (prevByte | currentByte | nextByte). As the window advances horizontally via advance(), bits slide through the register so that only a new byte needs to be fetched at each byte boundary. As the window moves down via nextRow(), registers rotate so that only the new bottom row needs to be fetched.

The optional dx/dy offsets allow the window to track a spatially shifted bitmap (e.g. GRREFERENCEDX / GRREFERENCEDY in §6.3.5). A call to getBit(int, int) at logical position (x, y) reads bitmap position (x - dx, y - dy).

All out-of-bounds accesses return 0 per §6.3.5.2.

Current status: this class is not yet used in production decoding paths. It exists as a standalone, testable abstraction of the sliding window bit-access mechanics that are currently inlined inside GenericRefinementRegionDecodingProcedure for the template 0 paths (decodeTemplate, decodeTypicalPredictedLineTemplate0). Its primary purpose is to provide a test bed for verifying the correctness of those paths — in particular at byte boundaries, edge rows, and non-zero reference offsets — where latent bugs may exist that are not yet covered by the current test suite.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a window over the given bitmap, positioned at (0, 0).
    SlidingBitmapWindow(Bitmap bitmap, int dx, int dy)
    Constructs a window over the given bitmap with a coordinate offset, positioned at (0, 0).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Advances the window one pixel to the right.
    int
    getBit(int rowOffset, int colOffset)
    Returns the bit value at the given row and column offset relative to the current position.
    int
    getBitFast(int rowOffset, int colOffset)
    Returns the bit value at the given row and column offset without bounds checking.
    void
    moveTo(int x, int y)
    Repositions the window to (x, y), loading the 3-row neighbourhood.
    void
    Moves the window one row down and resets to x=0.
    void
    Resets the window to (0, 0), reloading the 3-row neighbourhood.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SlidingBitmapWindow

      public SlidingBitmapWindow(Bitmap bitmap)
      Constructs a window over the given bitmap, positioned at (0, 0).
      Parameters:
      bitmap - the bitmap to window over
    • SlidingBitmapWindow

      public SlidingBitmapWindow(Bitmap bitmap, int dx, int dy)
      Constructs a window over the given bitmap with a coordinate offset, positioned at (0, 0). The offsets are subtracted from all pixel accesses: getBit() at logical (x, y) reads bitmap position (x-dx, y-dy).
      Parameters:
      bitmap - the bitmap to window over
      dx - horizontal offset (GRREFERENCEDX)
      dy - vertical offset (GRREFERENCEDY)
  • Method Details

    • moveTo

      public void moveTo(int x, int y)
      Repositions the window to (x, y), loading the 3-row neighbourhood. Must be called when changing position non-incrementally.
      Parameters:
      x - logical x coordinate
      y - logical y coordinate
    • reset

      public void reset()
      Resets the window to (0, 0), reloading the 3-row neighbourhood. Equivalent to moveTo(0, 0) but intended for use in benchmarks to avoid object allocation between invocations.
    • advance

      public void advance()
      Advances the window one pixel to the right. Leftmost bits fall out, existing bits shift left, new rightmost bits enter from the data layer at byte boundaries.
    • nextRow

      public void nextRow()
      Moves the window one row down and resets to x=0. The row above is discarded, current becomes above, below becomes current, and a new bottom row is fetched.
    • getBit

      public int getBit(int rowOffset, int colOffset)
      Returns the bit value at the given row and column offset relative to the current position.
      Parameters:
      rowOffset - -1 (above), 0 (current), or +1 (below)
      colOffset - column offset relative to current position, typically in the range -2 to +2
      Returns:
      0 or 1; 0 if the target position is out of bounds
    • getBitFast

      public int getBitFast(int rowOffset, int colOffset)
      Returns the bit value at the given row and column offset without bounds checking. Only call this when the current position is guaranteed to be in the interior of the bitmap (not near any edge).
      Parameters:
      rowOffset - -1 (above), 0 (current), or +1 (below)
      colOffset - column offset, typically -2 to +2
      Returns:
      0 or 1