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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Bitmapprivate intprivate intprivate intprivate intprivate intprivate final intprivate final intprivate final intprivate intprivate intprivate final intprivate final int -
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.private intbuildRegister(int bmpRow) Builds a fresh 24-bit register for the given bitmap row at the current byte column position.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.private intloadByte(int col, int row) Loads one byte from the bitmap at the given byte column and row.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.private intslideRegister(int reg, int bmpRow) Advances a 24-bit register by one byte: prevByte is dropped, currentByte becomes prevByte, nextByte becomes currentByte, and a new nextByte is fetched.
-
Field Details
-
bitmap
-
dx
private final int dx -
dy
private final int dy -
width
private final int width -
height
private final int height -
rowStride
private final int rowStride -
bitmapX
private int bitmapX -
bitmapY
private int bitmapY -
bitPosition
private int bitPosition -
byteColumn
private int byteColumn -
previousLine
private int previousLine -
currentLine
private int currentLine -
nextLine
private int nextLine
-
-
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
-
buildRegister
private int buildRegister(int bmpRow) Builds a fresh 24-bit register for the given bitmap row at the current byte column position. -
slideRegister
private int slideRegister(int reg, int bmpRow) Advances a 24-bit register by one byte: prevByte is dropped, currentByte becomes prevByte, nextByte becomes currentByte, and a new nextByte is fetched. -
loadByte
private int loadByte(int col, int row) Loads one byte from the bitmap at the given byte column and row. Returns 0 for out-of-bounds positions per §6.3.5.2.
-