MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / generate_2bit

Function generate_2bit

scripts/generate_test_bmps.py:163–186  ·  view source on GitHub ↗

2-bit BMP: 4-level grayscale test pattern (non-standard, CrossPoint extension).

(path)

Source from the content-addressed store, hash-verified

161
162
163def generate_2bit(path):
164 """2-bit BMP: 4-level grayscale test pattern (non-standard, CrossPoint extension)."""
165 bpp = 2
166 palette = GRAY_LEVELS
167 row_bytes = (WIDTH * bpp + 31) // 32 * 4
168 palette_size = len(palette) * 4
169 pixel_offset = 14 + 40 + palette_size
170 file_size = pixel_offset + row_bytes * HEIGHT
171
172 with open(path, 'wb') as f:
173 write_bmp_file_header(f, pixel_offset, file_size)
174 write_bmp_dib_header(f, WIDTH, HEIGHT, bpp, len(palette))
175 write_palette(f, palette)
176
177 for y in range(HEIGHT):
178 row = bytearray(row_bytes)
179 for x in range(WIDTH):
180 idx = get_test_pattern_index(x, y, WIDTH, HEIGHT)
181 byte_pos = x >> 2
182 bit_shift = 6 - ((x & 3) * 2)
183 row[byte_pos] |= (idx << bit_shift)
184 f.write(row)
185
186 print(f" Created: {path} ({bpp}-bit, {len(palette)} colors)")
187
188
189def generate_4bit(path):

Callers 1

mainFunction · 0.85

Calls 5

write_bmp_file_headerFunction · 0.85
write_bmp_dib_headerFunction · 0.85
write_paletteFunction · 0.85
get_test_pattern_indexFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected