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

Function get_test_pattern_index

scripts/generate_test_bmps.py:62–102  ·  view source on GitHub ↗

Return palette index (0-3) for a test pattern designed to reveal dithering. Layout (4 horizontal bands): Band 1 (top 25%): Checkerboard of all 4 gray levels in 16x16 blocks Band 2 (25-50%): Fine horizontal lines (1px) alternating gray levels Band 3 (50-75%): 4 verti

(x, y, width, height)

Source from the content-addressed store, hash-verified

60
61
62def get_test_pattern_index(x, y, width, height):
63 """Return palette index (0-3) for a test pattern designed to reveal dithering.
64
65 Layout (4 horizontal bands):
66 Band 1 (top 25%): Checkerboard of all 4 gray levels in 16x16 blocks
67 Band 2 (25-50%): Fine horizontal lines (1px) alternating gray levels
68 Band 3 (50-75%): 4 vertical stripes, each with a nested smaller pattern
69 Band 4 (bottom 25%): Diagonal gradient-like pattern using the 4 levels
70 """
71 band = y * 4 // height
72
73 if band == 0:
74 # Checkerboard: 16x16 blocks cycling through all 4 gray levels
75 bx = (x // 16) % 4
76 by = (y // 16) % 4
77 return (bx + by) % 4
78
79 elif band == 1:
80 # Fine lines: 1px horizontal lines alternating between two gray levels
81 # Left half: alternates black/white, Right half: alternates dark/light gray
82 if x < width // 2:
83 return 0 if (y % 2 == 0) else 3 # black/white
84 else:
85 return 1 if (y % 2 == 0) else 2 # dark gray/light gray
86
87 elif band == 2:
88 # 4 vertical stripes, each containing a smaller checkerboard at 4x4
89 stripe = min(x * 4 // width, 3)
90 inner = ((x // 4) + (y // 4)) % 2
91 if stripe == 0:
92 return 0 if inner else 1 # black / dark gray
93 elif stripe == 1:
94 return 1 if inner else 2 # dark gray / light gray
95 elif stripe == 2:
96 return 2 if inner else 3 # light gray / white
97 else:
98 return 0 if inner else 3 # black / white (max contrast)
99
100 else:
101 # Diagonal bands using all 4 levels
102 return ((x + y) // 20) % 4
103
104
105def get_test_pattern_lum(x, y, width, height):

Callers 3

generate_2bitFunction · 0.85
generate_4bitFunction · 0.85
generate_8bit_4colorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected