Class SlidingBitmapWindow
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
ConstructorsConstructorDescriptionSlidingBitmapWindow(Bitmap bitmap) 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 TypeMethodDescriptionvoidadvance()Advances the window one pixel to the right.intgetBit(int rowOffset, int colOffset) Returns the bit value at the given row and column offset relative to the current position.intgetBitFast(int rowOffset, int colOffset) Returns the bit value at the given row and column offset without bounds checking.voidmoveTo(int x, int y) Repositions the window to (x, y), loading the 3-row neighbourhood.voidnextRow()Moves the window one row down and resets to x=0.voidreset()Resets the window to (0, 0), reloading the 3-row neighbourhood.
-
Constructor Details
-
SlidingBitmapWindow
Constructs a window over the given bitmap, positioned at (0, 0).- Parameters:
bitmap- the bitmap to window over
-
SlidingBitmapWindow
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 overdx- 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 coordinatey- logical y coordinate
-
reset
public void reset()Resets the window to (0, 0), reloading the 3-row neighbourhood. Equivalent tomoveTo(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
-