add -s sharpness flag to counteract aliasing

This commit is contained in:
xfnw 2021-06-20 12:53:07 -04:00
parent 40727c6918
commit 863cc599e4
2 changed files with 16 additions and 5 deletions

View file

@ -10,6 +10,7 @@
.Nm .Nm
.Op Fl d Ar delay .Op Fl d Ar delay
.Op Fl w Ar width .Op Fl w Ar width
.Op Fl s Ar sharpness
.Op Fl Fl colorfmt Ar format .Op Fl Fl colorfmt Ar format
.Op Fl Fl filler Ar filler .Op Fl Fl filler Ar filler
.Pa file .Pa file
@ -39,6 +40,14 @@ the
of filler characters. the actual line will almost certainly of filler characters. the actual line will almost certainly
be longer because of color codes. 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 .It Fl Fl colorfmt Ar format
the unicode-escaped format of the colorcodes. you probably the unicode-escaped format of the colorcodes. you probably
do not want to change it, the default of do not want to change it, the default of

View file

@ -9,19 +9,19 @@ from PIL import Image, ImageOps
from color import closestColor 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 = Image.open(imgPath, 'r')
im = ImageOps.scale(im, ASCIIWIDTH / im.width) im = ImageOps.scale(im, ASCIIWIDTH*SHARPNESS / im.width)
width, height = im.size width, height = im.size
pixel_values = list(im.getdata()) pixel_values = list(im.getdata())
currentPixel = 0 currentPixel = 0
for y in range(0, height, 2): for y in range(0, height, 2*SHARPNESS):
line = [] line = []
lastColor=69420 lastColor=69420
for x in range(width): for x in range(0, width, SHARPNESS):
color = closestColor(pixel_values[width*y+x]) color = closestColor(pixel_values[width*y+x])
if color == lastColor: if color == lastColor:
colorcode = '' colorcode = ''
@ -41,6 +41,7 @@ if __name__ == "__main__":
parser.add_argument("file") parser.add_argument("file")
parser.add_argument("-d",metavar='delay',default=0) parser.add_argument("-d",metavar='delay',default=0)
parser.add_argument("-w",metavar='width',default=80) 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("--colorfmt",metavar='format',default='\\x03{},{}')
parser.add_argument("--filler",metavar='filler',default='.') parser.add_argument("--filler",metavar='filler',default='.')
args = parser.parse_args() args = parser.parse_args()
@ -50,5 +51,6 @@ if __name__ == "__main__":
float(args.d), float(args.d),
int(args.w), int(args.w),
args.colorfmt.encode().decode('unicode_escape'), args.colorfmt.encode().decode('unicode_escape'),
args.filler.encode().decode('unicode_escape') args.filler.encode().decode('unicode_escape'),
int(args.s)
) )