kitty icat: Add a --scale-up option to expand images when used with the --place operator

This commit is contained in:
Kovid Goyal 2018-01-10 13:32:05 +05:30
parent 3cd744b247
commit 03702772d3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -54,6 +54,13 @@ are in cells (i.e. cursor positions) with the origin |_ (0, 0)| at
the top-left corner of the screen. the top-left corner of the screen.
--scale-up
type=bool-set
When used in combination with |_ --place| it will cause images that
are smaller than the specified area to be scaled up to use as much
of the specified area as possible.
--clear --clear
type=bool-set type=bool-set
Remove all images currently displayed on the screen. Remove all images currently displayed on the screen.
@ -219,9 +226,13 @@ def identify(path):
return ImageData(parts[0].lower(), int(parts[1]), int(parts[2]), mode) return ImageData(parts[0].lower(), int(parts[1]), int(parts[2]), mode)
def convert(path, m, available_width, available_height): def convert(path, m, available_width, available_height, scale_up):
width, height = m.width, m.height width, height = m.width, m.height
cmd = ['convert', '-background', 'none', path] cmd = ['convert', '-background', 'none', path]
if scale_up:
if width < available_width:
r = available_width / width
width, height = available_width, int(height * r)
if width > available_width or height > available_height: if width > available_width or height > available_height:
width, height = fit_image(width, height, available_width, available_height) width, height = fit_image(width, height, available_width, available_height)
cmd += ['-resize', '{}x{}'.format(width, height)] cmd += ['-resize', '{}x{}'.format(width, height)]
@ -236,6 +247,7 @@ def process(path, args):
available_width = args.place.width * (ss.width / ss.cols) if args.place else ss.width available_width = args.place.width * (ss.width / ss.cols) if args.place else ss.width
available_height = args.place.height * (ss.height / ss.rows) if args.place else 10 * m.height available_height = args.place.height * (ss.height / ss.rows) if args.place else 10 * m.height
needs_scaling = m.width > available_width or m.height > available_height needs_scaling = m.width > available_width or m.height > available_height
needs_scaling = needs_scaling or args.scale_up
if m.fmt == 'png' and not needs_scaling: if m.fmt == 'png' and not needs_scaling:
outfile = path outfile = path
transmit_mode = 'f' transmit_mode = 'f'
@ -244,7 +256,7 @@ def process(path, args):
else: else:
fmt = 24 if m.mode == 'rgb' else 32 fmt = 24 if m.mode == 'rgb' else 32
transmit_mode = 't' transmit_mode = 't'
outfile, width, height = convert(path, m, available_width, available_height) outfile, width, height = convert(path, m, available_width, available_height, args.scale_up)
show(outfile, width, height, fmt, transmit_mode, align=args.align, place=args.place) show(outfile, width, height, fmt, transmit_mode, align=args.align, place=args.place)
if not args.place: if not args.place:
print() # ensure cursor is on a new line print() # ensure cursor is on a new line