Parametrize dither patterns as command-line argument

This commit is contained in:
kris 2021-01-15 22:25:06 +00:00
parent f5553e00b8
commit c5b8feb17e
2 changed files with 17 additions and 3 deletions

View File

@ -25,6 +25,9 @@ def main():
"--lookahead", type=int, default=4,
help=("How many pixels to look ahead to compensate for NTSC colour "
"artifacts."))
parser.add_argument('--dither', type=str,
choices=list(dither_pattern.PATTERNS.keys()),
default=dither_pattern.DEFAULT_PATTERN)
args = parser.parse_args()
palette = palette_py.Palette()
@ -34,9 +37,7 @@ def main():
image = image_py.open(screen.X_RES, screen.Y_RES, args.input)
# image_rgb.show()
# dither = dither_pattern.FloydSteinbergDither()
# dither = dither_pattern.BuckelsDither()
dither = dither_pattern.JarvisDither()
dither = dither_pattern.PATTERNS[args.dither]()
start = time.time()
output_4bit, output_rgb = dither_pyx.dither_image(

View File

@ -7,6 +7,7 @@ class DitherPattern:
class FloydSteinbergDither(DitherPattern):
"""Floyd-Steinberg dither."""
# 0 * 7
# 3 5 1
PATTERN = np.array(((0, 0, 7), (3, 5, 1)),
@ -16,6 +17,7 @@ class FloydSteinbergDither(DitherPattern):
class BuckelsDither(DitherPattern):
"""Default dither from bmp2dhr."""
# 0 * 2 1
# 1 2 1 0
# 0 1 0 0
@ -25,6 +27,8 @@ class BuckelsDither(DitherPattern):
class JarvisDither(DitherPattern):
"""Jarvis dithering."""
# 0 0 X 7 5
# 3 5 7 5 3
# 1 3 5 3 1
@ -32,3 +36,12 @@ class JarvisDither(DitherPattern):
dtype=np.float32).reshape(3, 5, 1) / np.float32(48)
ORIGIN = (0, 2)
PATTERNS = {
'floyd': FloydSteinbergDither,
'floyd-steinberg': FloydSteinbergDither,
'buckels': BuckelsDither,
'jarvis': JarvisDither
}
DEFAULT_PATTERN = 'jarvis'