Bitmap Character to Image Conversion (3 phases)
You are given a bitmap lookup table (a dictionary/map) that represents a tiny “font”.
-
Key
: a character (e.g.,
'J'
)
-
Value
: a 2D grid (matrix) of
0/1
integers where:
-
0
= background pixel
-
1
= foreground pixel
Example bitmap for the letter J (10 rows × 6 columns):
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
1 0 0 0 1 0
0 1 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Phase 1: Basic printing
Implement a function that, given the lookup table and an input character, prints the character’s bitmap to the console in the same grid format (preserve rows/columns).
Phase 2: Compression & decompression
To save space, implement:
-
compress(bitmap)
: Convert a 2D
0/1
matrix into a more compact representation.
-
decompress(compressed)
: Restore the original 2D matrix.
Requirements:
-
The decompressed bitmap must be
identical
to the original.
-
After decompressing, print the bitmap again (reuse Phase 1 printing).
Notes:
-
You may choose any reasonable compression format (e.g., row-wise run-length encoding (RLE), storing coordinates of
1
s, etc.), but it must support lossless round-trip.
Phase 3: Manipulation & reuse
Perform an additional transformation on the bitmap(s), then print the result.
-
Example transformation:
invert
the bitmap (swap
0
and
1
).
-
You must
reuse
part of your Phase 2 code (e.g., decompress → manipulate → print, or manipulate compressed data then use existing logic).
Assumptions / clarifications
-
All bitmaps are rectangular matrices.
-
Printing can be
0/1
separated by spaces (or equivalent consistent formatting).
-
The lookup table may contain multiple characters; your functions should work for any entry in the table.