From 863cc599e45bbeed0d40d141b6f1dd51861ee50b Mon Sep 17 00:00:00 2001 From: xfnw Date: Sun, 20 Jun 2021 12:53:07 -0400 Subject: [PATCH] add -s sharpness flag to counteract aliasing --- banter.1 | 9 +++++++++ banter.py | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/banter.1 b/banter.1 index b10ab74..c897564 100644 --- a/banter.1 +++ b/banter.1 @@ -10,6 +10,7 @@ .Nm .Op Fl d Ar delay .Op Fl w Ar width +.Op Fl s Ar sharpness .Op Fl Fl colorfmt Ar format .Op Fl Fl filler Ar filler .Pa file @@ -39,6 +40,14 @@ the of filler characters. the actual line will almost certainly be longer because of color codes. . +.It Fl s Ar sharpness +doubles the pixels to make edges sharper, however uses +exponentially more ram. +.Ar sharpness +is +.Cm 4 +by default and can be lowered to reduce ram usage. +. .It Fl Fl colorfmt Ar format the unicode-escaped format of the colorcodes. you probably do not want to change it, the default of diff --git a/banter.py b/banter.py index fb7f5b9..6cfb2c5 100755 --- a/banter.py +++ b/banter.py @@ -9,19 +9,19 @@ from PIL import Image, ImageOps from color import closestColor -def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER): +def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER,SHARPNESS): im = Image.open(imgPath, 'r') - im = ImageOps.scale(im, ASCIIWIDTH / im.width) + im = ImageOps.scale(im, ASCIIWIDTH*SHARPNESS / im.width) width, height = im.size pixel_values = list(im.getdata()) currentPixel = 0 - for y in range(0, height, 2): + for y in range(0, height, 2*SHARPNESS): line = [] lastColor=69420 - for x in range(width): + for x in range(0, width, SHARPNESS): color = closestColor(pixel_values[width*y+x]) if color == lastColor: colorcode = '' @@ -41,6 +41,7 @@ if __name__ == "__main__": parser.add_argument("file") parser.add_argument("-d",metavar='delay',default=0) parser.add_argument("-w",metavar='width',default=80) + parser.add_argument("-s",metavar='sharpness',default=4) parser.add_argument("--colorfmt",metavar='format',default='\\x03{},{}') parser.add_argument("--filler",metavar='filler',default='.') args = parser.parse_args() @@ -50,5 +51,6 @@ if __name__ == "__main__": float(args.d), int(args.w), args.colorfmt.encode().decode('unicode_escape'), - args.filler.encode().decode('unicode_escape') + args.filler.encode().decode('unicode_escape'), + int(args.s) )