diff --git a/README.md b/README.md index fdf42c3..a24466c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ lid [option]... [source path] [output name] Options:
-f = output format, defaults to the recommended setting: png
--m = mode, available: o4, o9, e. default: o4.
+-m = mode, available: o4, o9, e, t, r, a. default: o4.
-q = quality (0 - 100), defaults to 90, only affects jpeg/jpg
-t = threshold (0 - 255), defaults to image average level. only affects dither mode 't' @@ -28,6 +28,9 @@ Lid works best outputting png files from any input. You will get the smallest fi #### t This is the lowest quality mode. It produces the smallest file, but at the cost of most detail. +#### r +Random dithering produces a fairly large file (comparable to error diffusion), without moving much closer to photographic quality. However, it does provide an interesting effect. + #### o4 This mode is a noticable difference from the stark two tone appearance of threashold mode. The appearance 'gray' areas make for a slightly more photographic image. diff --git a/lid b/lid index f474fb7..bc98de2 100755 --- a/lid +++ b/lid @@ -7,6 +7,7 @@ from PIL import Image import sys import os, os.path +from random import randint class Dither: def __init__(self, data): @@ -88,7 +89,14 @@ class Dither: def random_dither(self): - pass + print("Dither method: random\033[?25l".format(self.threshold)) + for row in range(0, self.height): + for col in range(0, self.width): + px = self.get_pixel(col, row) + rand = randint(1,255) + self.new_pixels[col, row] = int(px > rand) + self.update_progress() + self.save_file() def error_diffusion_dither(self): i = self.source_image.load() @@ -161,7 +169,7 @@ def display_help(): options: -f output format. defaults to: png (recommended) - -m dither mode. defaults to: o4. other options: e, o9 + -m dither mode. defaults to: o4. other options: e, o9, t, r, a -q image quality. defaults to: 90. only has effect on png/jpg -t threshold. default: image average tone. onls has effect in mode 't' @@ -179,6 +187,8 @@ def display_help(): the quality flag mostly seems to effect jpegs and does not do a whole heap to PNG files, but play around with it as mileage may vary. + + to output an image with each type of dither, use mode a """ print(helptext) @@ -226,8 +236,8 @@ def parse_input(): elif argmap["-f"] == "jpg": argmap["-f"] = "jpeg" - if not argmap["-m"] in ["o4", "e", "o9", "t", "a"]: - print("lid error: invalid dither mode provided for -m. Options: o4, o9, e. Default: o4") + if not argmap["-m"] in ["o4", "e", "o9", "t", "r", "a"]: + print("lid error: invalid dither mode provided for -m. Options: o4, o9, e, t, r, a. Default: o4") return None try: @@ -267,6 +277,8 @@ if __name__ == "__main__": d.error_diffusion_dither() elif request["-m"] == "t": d.threshold_dither() + elif request["-m"] == "r": + d.random_dither() elif request["-m"] == "a": name = request["out"] request["out"] = name + "_o4" @@ -281,6 +293,9 @@ if __name__ == "__main__": request["out"] = name + "_e" d4 = Dither(request) d4.error_diffusion_dither() + request["out"] = name + "_r" + d4 = Dither(request) + d4.random_diffusion_dither() else: print("Unknown mode flag") sys.exit(2)