hzeller / timg

A terminal image and video viewer.
GNU General Public License v2.0
1.91k stars 73 forks source link

tmux show picture is blur #95

Closed newyorkthink closed 1 year ago

hzeller commented 1 year ago

tmux will limit the number of unicode characters and colors it can show. This is nothing timg or other terminal image displaying tools will be able to influence. Maybe it is something that you can configure in tmux already or have to implement there.

So this is not an issue with timg but something you have to figure out with tmux.

hzeller commented 1 year ago

I don't think that tmux allows the picture modes of kitty or wezterm. This is why images are shown in the character based pixelation.

Also 256 colors is limiting the color range, you'd like a 24 bit color mode if available.

gsbabil commented 1 year ago

There's a tmux plugin/kitten called icat which if used inside kitty > tmux (tmux running inside kitty) can draw images in full resolution using the kitty protocol.

But under the same kitty > tmux setup, the same image if displayed with timg, will appear blurred with --pixelation=quarter (default behavior), or as text if --pixelation=kitty is used (example screenshot below).

📍 Since icat works under the kitty > tmux setup, timg --pixelation=kitty should also work under the same kitty > tmux setup as well. Thanks!

image
hzeller commented 1 year ago

Interesting, I'll have to look what the difference is of what icat outputs on tmux vs. timg.

gsbabil commented 1 year ago

@hzeller Thanks. For the sake of completeness...

hzeller commented 1 year ago

I looked what kitty is doing there. It has to do an extremely ugly hack to work around tmux' refusal to work with image protocols. I'll have to see if I can integrate that in timg without breaking anyone else who is implementing that protocol.

hzeller commented 1 year ago

Can you try this AppImage zip ?

It should now work within tmux running inside the Kitty terminal (other terminals that support the Kitty protocol will likely not work as the Unicode Placeholder stuff is fairly new and probably only implemented properly there).

You have to manually provide the -pk option in timg for it to emit the Kitty protocol (because timg can't probe the terminal (Or, manually set the TERM environment variable to xterm-kitty).

# inside tmux
$ timg -pk some-image.jpg
gsbabil commented 1 year ago

@hzeller Thanks for the quick turnaround! Please see my test results below.

Kitty 0.28.1 > Tmux 3.3a

image

Kitty 0.28.1 > Tmux 3.3a > SSH (Ubuntu/Linux)

Kitty 0.28.1 > Tmux 3.3a > SSH (Ubuntu/Linux) > Tmux 3.2a

gsbabil commented 1 year ago

In case anyone else is struggling to reproduce the same behavior from the latest timg patch under Kitty v0.28.1 and v.29 (latest), this might be the reason. Thanks.

hzeller commented 1 year ago

Second case: ok, let me see if there is a simple way to detect the case where we're actually remote.

The last case, tmux before 3.3, probably just means that if passthrough didn't exist then, it would not possible to show images in tmux anyway, so showing an error message there is probably good, but I agree if we could take the version into account, we could provide a more tailored error message.

hzeller commented 1 year ago

Alright, the cases 2 and 3 should be a bit more useful now

There is an updated AppImage to test.

hzeller commented 1 year ago

Now in the latest release v1.5.1

hzeller commented 1 year ago

yes, tmux is refusing to work with image formats, so the Kitty workaround is the only way.

gsbabil commented 1 year ago

@hzeller Thanks again.

image
hzeller commented 1 year ago

FYI @kovidgoyal : implemented use of your unicode placeholders protocol to have timg work within tmux within kitty.

kovidgoyal commented 1 year ago

Cool, glad to hear it.

rpdelaney commented 1 year ago

Anyone have working usage examples for scope.sh in tmux? I'm having... problems...

m040601 commented 1 year ago

Just to give my 2 cents feedback.

This is working perfectly on my Archlinux system. That is, when I'm running tmux inside kitty and,

timg --pixelation=kitty someimage.jpg

I see a perfect not blurred image.

It "seems" to take a few almost unnoticeable micro/nano milliseconds more time than showing it without tmux in the middle. This is a 14 year old PC' ahha.

timg --version

timg 1.5.2+  <https://timg.sh/>
Copyright (c) 2016..2023 Henner Zeller. This program is free software; license GPL 2.0.

Image decoding GraphicsMagick 1.3.41 (2023-08-12)
Openslide 3.4.1
Turbo JPEG
QOI image loading
swscale 7.1.100
Video decoding libav 60.3.100; avdevice 60.1.100
Half, quarter, iterm2, and kitty graphics output: timg builtin.
Libsixel version 1.10.3

Installed from here, https://aur.archlinux.org/packages/timg

$ kitty --version

kitty 0.29.2 created by Kovid Goyal

$ tmux -V

tmux 3.3a

I always have this line in my ~/.tmux.conf

set -g default-terminal "tmux-256color"

and that's what is reported by echo $TERM.

From the 3 terminal image viewers that I use

timg is the only one that "manages" to do it. That is, to overcome tmux "obstacles" and display a perfect image , when running inside tmux inside kitty.