Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w3m image preview banding/flickering #86

Open
taylorchu opened this issue Mar 25, 2013 · 77 comments
Open

w3m image preview banding/flickering #86

taylorchu opened this issue Mar 25, 2013 · 77 comments

Comments

@taylorchu
Copy link
Contributor

the image shows in one blink. but xterm works fine.

@ok100
Copy link

ok100 commented Mar 25, 2013

I have the same issue, but only with st (urxvt works fine).

@devendra-ghate
Copy link

I have problem with some images in urxvt. Certain blocks of the images are shown as just white patches. But some images are shown clearly. Don't know how to pin-point the source of the error.

@Adarsh-Barik
Copy link

I have the same issue with urxvt (some image previews are shown clearly while some have black patches). However, it runs fine in xterm.
Also, is it possible to make it work in tilda (or gnome-terminal)?

@Edholm
Copy link

Edholm commented Apr 18, 2013

I resolved this by removing URxvt.depth: 32 from my .Xdefaults file.
(Urxvt never showed images for me)

@Ambrevar
Copy link
Contributor

Ambrevar commented May 2, 2013

Been playing a bit with .Xresources, and found out that loading an Xft font caused URxvt to be messy with w3m image preview (random black stripes on preview). Xft fonts work fine with xterm.
My .Xresources:

! Fails
URxvt_font : xft:Dejavu Sans Mono:pixelsize=14
! Works
URxvt_font : --dejavu sans mono-----------iso8859-

! Works
xterm*faceName:DejaVu Sans Mono:pixelsize=12

@taylorchu
Copy link
Contributor Author

Finally trace down the exact problem:
the anti-aliasing of xft font of urxvt breaks w3m image preview.

I guess we cannot do anything about this in ranger

@Ambrevar
Copy link
Contributor

I wanted to report the urxvt bug upstream. Is it me or is there no bugtraker ?
Besides I do not seem to be able to subscribe to the mailing list (never
received any confirmation mail). And I hate IRC, so...

@ghost
Copy link

ghost commented May 10, 2013

There was some discussion about this a while back on the suckless mailing list. They were hoping to get it working with st. It looks like it may be a issue with w3m-img.

@Ambrevar
Copy link
Contributor

Funny, I just received the confirmation mail for the urxvt mailing list today! Hell, I subscribed 15 days ago! Well, it's no use anymore.

@ghost
Copy link

ghost commented Sep 11, 2013

So did anyone ever find a fix for this? I tried to visit the w3m mailing list archives a few times (as referenced here: http://w3m.sourceforge.net/) but it seems the connection times out. Is there even still any development on w3m?

By the way, seems to me there are two different issues going on here:

  • Using an antialiased font breaks the preview completely.
  • Having 32bit color depth enabled causes the preview to behave weirdly (jumps sometimes, being only half drawn sometimes, etc.)

@brunal
Copy link

brunal commented Oct 18, 2013

This is definitely a w3m problem and not a ranger one: w3mimgdisplay does not handle 32 bit colors. However, the project seems stagnant indeed and we'd have to fix it ouselves. A feature request can be opened on http://sourceforge.net/p/w3m/feature-requests/ but all of them seem to fall in /dev/null.
The source is available on sourceforce, and can be retrieved as a tarball or with cvs (no kidding).
Interesting folder is wm3img/fb/. The Readme seems to hold strange characters... Is it Japanese?
I'm from the generation that does not speak c, but I'll have a go at reading the source this weekend. It's only 46 lines of *.h and 1336 lines of *.c.

Anyone else interested?

@BwackNinja
Copy link

w3m was handling visuals and colormaps incorrectly. It always used the default rather than taking it from where it wants to draw to. Here's a patch for it:
https://gist.github.com/BwackNinja/60a344730170f9ce2163

@r8b7xy
Copy link

r8b7xy commented Mar 25, 2015

How to apply this patch?
Thanks in advance.

@ghost
Copy link

ghost commented Jun 2, 2015

Hi There,

I managed to get it working perfectly by setting:
set draw_borders true

In the ~/.config/ranger/rc.conf

Cheers!

@tats
Copy link

tats commented Oct 23, 2015

w3m was handling visuals and colormaps incorrectly.
https://gist.github.com/BwackNinja/60a344730170f9ce2163

@BwackNinja Thanks for the contribution to w3m.
Merged in the development repository for Debian's w3m.
cf. https://sourceforge.net/p/w3m/patches/72/

@fmthoma
Copy link

fmthoma commented Dec 19, 2015

After applying @BwackNinja's patch I still had problems with resized images not being displayed correctly in urxvt with 32-bit enabled, showing semi-transparent artifacts on resized images. It looks like this is a bug (?) in imlib2, but can be worked around in w3m-img by using a different method for resizing the image. Now image preview in ranger works for me without set draw_borders true, even with background transparency enabled in urxvt.

Here is the patch, should be applied in addition to the one supplied by @BwackNinja: https://gist.github.com/fmthoma/f76a1b44e00d5ca972bb

tats referenced this issue in tats/w3m Dec 20, 2015
… (e.g. urxvt)

imlib_render_image_on_drawable_at_size() tended to leave nasty
semi-transparent artifacts in 32-bit mode.  Apparently, resizing an
image in 32-bit mode affects the alpha channel even if there is no
transparency in the image.  With this patch, resizing is done in
24-bit mode (or whatever depth the original image has) before
converting the image to 32-bit and rendering it on the display.

Origin: https://gist.github.com/fmthoma/f76a1b44e00d5ca972bb
cf. https://github.com/hut/ranger/issues/86#issuecomment-166027119
@tats
Copy link

tats commented Dec 20, 2015

https://gist.github.com/fmthoma/f76a1b44e00d5ca972bb

@fmthoma Merged in Debian's w3m development repo. Thank you.

@noctuid
Copy link
Contributor

noctuid commented Dec 22, 2015

@tats @fmthoma Installing w3m from that repo does not fix image display in termite for me. It also breaks ranger's preview (but not using w3m directly) in both xterm and urxvt. Any ideas on why this happens?

@fmthoma
Copy link

fmthoma commented Dec 22, 2015

Does it only break after my patch, or is it broken before? What library do you use for loading images, imlib or imlib2 or gkd-pixbuf? My patch applies only to the imlib2 backend.

I did not test with termite, but it works on xterm (unchanged by my patch, since xterm does not support 32-bit color anyways) and urxvt. In gnome-terminal, ranger's image preview does not work (I don't know why), but w3mimgdisplay works.

Have you tried running w3mimgdisplay separately?
/usr/lib/w3m/w3mimgdisplay <<<$'0;1;100;100;100;100;;;;;/path/to/some/picture\n4;\n3;'

@noctuid
Copy link
Contributor

noctuid commented Dec 23, 2015

Installing from that repo, it's broken both before and after the patch. I tried using --with-imagelib=imlib2 without success. I don't have /usr/lib/w3m/w3mimgdisplay (I guess I need to look through the Makefile), but moving the w3mimgdisplay binary there fixes the problem for xterm but not termite. I can view images in termite now using w3m /path/to/image without it opening an external image viewer, but I don't see anything (just the background color; all black).

@fmthoma
Copy link

fmthoma commented Dec 24, 2015

Okay, I did not try to install from the development repo. I just fetch the sources (apt-get source w3m) and apply the patches. For Ubuntu (and probably other Debian based systems) have a look at my dotfiles.

cstrahan referenced this issue in cstrahan/nixpkgs Dec 25, 2015
Fix the built-in help (perl.patch)
  https://bugs.archlinux.org/task/45608

Properly link w3mimgdisplay to x11
  https://bbs.archlinux.org/viewtopic.php?id=196093

Fix rendering bug in w3mimgdisplay (w3m_rgba.patch)
  https://github.com/hut/ranger/issues/86

Don't ignore input tags with invalid types (form_unkown.patch)
  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=615843

Fix a segfault when using https (https.patch)
  https://bugzilla.redhat.com/show_bug.cgi?id=707994
@lcpz
Copy link

lcpz commented Apr 26, 2017

There's no point using w3m with rxvt as it has it's own method (but bad font handling:-( )

The urxvt method is just rubbing the image on the terminal, without honoring the aspect ratio, plus it requires urxvt to be compiled with a certain non-standard option. Instead, w3mimgdisplay creates a thumbnail.

I don't use a background or transparency, so my banding "stripes" are black.

@vifon
Copy link
Member

vifon commented Apr 26, 2017

requires urxvt to be compiled with a certain non-standard option

Sorry for nitpicking but I'm aware of only one Linux distro that supplies urxvt without this option (Arch). I would rather call the lack of this option "non-standard" and file a bug report to the package maintainer.

As for the issue as a whole, not much can be done on our side. The way w3m previews work will always be buggy and it only gets worse with the additional stuff like compositors (e.g. compton).

The urxvt method is just rubbing the image on the terminal, without honoring the aspect ratio

@copycat-killer, I cannot reproduce the aspect ratio issues. Could you provide a confirmed test case?
What do you mean by "rubbing"?

@crocket
Copy link

crocket commented Apr 26, 2017

@vifon rubbing means #815 which happens with urxvt image preview method. That's why I don't use urxvt image preview method.

I wonder if SIXEL doesn't have this issue.

@lcpz
Copy link

lcpz commented Apr 27, 2017

Sorry for nitpicking but I'm aware of only one Linux distro that supplies urxvt without this option (Arch). I would rather call the lack of this option "non-standard" and file a bug report to the package maintainer.

It seems to me improbable that Arch is the only distro without it as standard, anyway there is rxvt-unicode-pixbuf in the AUR.

But enough discussing, let's focus on PySixel. All we have to do is to create a SIXELImageDisplayer class which implement this interface.

@crocket
Copy link

crocket commented Apr 27, 2017

I feel that https://github.com/saitoha/PySixel is unmaintained. Perhaps, there is a better sixel binding.

@j-degreef
Copy link

Sixel works on a limited number of terminals.
Unless people are ok to switch to another term, which I will not do for functionality reasons (Using i3 I need a term with keyboard navigation as Termite or urxvt have) that will not solve the problem for most.

@noctuid
Copy link
Contributor

noctuid commented Apr 27, 2017

Maybe it's not an ideal solution for everyone, but tmux has much better keyboard navigation in my experience (and actually has customizable keybindings). I've not once used termite's keybindings. Regardless, I don't think limited terminal support is any reason not to add support for sixel as a method.

@lcpz
Copy link

lcpz commented Apr 27, 2017

Yeah, PySixel is unmaintained, and works on a limited number of terminals.

That's why there's libsixel-python.

As soon as I have enough time I'll try to implement the above mentioned displayer.

EDIT: well, urxt seems still unsupported, but I want to play with it anyway.

@vifon
Copy link
Member

vifon commented Apr 27, 2017

Sixel support would certainly be nice if you could code it. It's a shame urxvt doesn't support it (personally I don't plan to switch terminals) but a new option is always welcome, as long as it won't be a hard dependency.

@crocket
Copy link

crocket commented Apr 27, 2017

st will probably support SIXEL within this year because someone started pushing SIXEL support to st.
If he hears that ranger guys are going to add SIXEL support, he'll definitely push harder.

st is a viable alternative to urxvt and termite if you are willing to compile your configuration from C and accept XIM input method(which ibus supports) instead of the full ibus input method.

The advantage of st is that it supports fontconfig properly while urxvt does only partially.
As a result, there are a lot of unicode characters that st can display and urxvt can't.

Gentoo makes it very easy to compile configurations in programming languages, so I use st along with urxvt on Gentoo Linux.

@WhyNotHugo
Copy link

st is a viable alternative to urxvt and termite if you are willing to compile your configuration from C and accept XIM input method(which ibus supports) instead of the full ibus input method.

That's an absurdly huge if. I use a package manager to track that everything is up to date. I've no intention of ever changing that. A great deal of others thing the same. Manually staying up to date on releases and rebuilding is cumbersome and unmaintainable.

@crocket
Copy link

crocket commented May 7, 2017

@hobarrera I am on gentoo linux. Gentoo's package manager makes it easy to compile st with a configuration file when it installs st. Thus, I can just reinstall the package after changing the configuration.

It takes less than 30 seconds to reinstall st on gentoo.

It seems st is not good on binary linux distributions. Perhaps, you want to check if it's possible to do the same on your linux distribution.

@AeliusSaionji
Copy link

You forgot to account for the amount of time it takes to fix your config to match upstream changes.

Even with gentoo, there is more management overhead. You and I are happy to deal with that, but respect that not everyone is.

@WhyNotHugo
Copy link

It seems st is not good on binary linux distributions. Perhaps, you want to check if it's possible to do the same on your linux distribution.

You also forgot that I need to subscribe to some for of RSS, and keep an eye on newer releases. Like @Link-Satonaka mentioned, also update the config every time upstream changes.
You might convince some people to do this, but 99% of the people prefer to have updates automated, rather than have to manually patch and install releases.

The idea of manually building from source (even if you build a package) will never be upstream because of the huge overhead. For those who prefer it: go ahead and use that, I've no issue. But don't expect the rest of the world to adopt that.

@crocket
Copy link

crocket commented May 8, 2017

The idea of manually building from source (even if you build a package) will never be upstream

On Gentoo, you don't build package manually. Gentoo's package manager, emerge, automates compilation although compilation takes time. For example, if you want to compile and install firefox, you just execute emerge -q x11-client/firefox. For system upgrade, I execute emerge -auDN @world. I use gentoo because I want specific customizations to many packages, but if you don't want specific customizations to your linux distribution, you don't want gentoo's compilation overhead. That said, the compilation overhead is acceptable if you have FX-8300 or anything faster and compile everything in tmpfs.

For now, st is convenient only on gentoo systems because gentoo's package manager takes care of compiling st with its configuration file.

st better adopt a model similar to XMonad for configuration.
You can just install XMonad binary package which compiles haskell configuration file with GHC.
Unlike GHC, gcc, which st can use to compile configuration, is not considered as a bloat by many users. Binary linux distribution users have no problem with using XMonad as long as they are willing to live with GHC on their storage devices.

By the way, ordinary text configuration files are just as susceptible to upstream changes, and they can be harder to debug because there is hardly any useful debugging information for ordinary text configuration files. I used to update gitea and gitlab. It was hard to keep up with configuration file changes. At least, with gcc or GHC, compiler helps you find and fix errors.

@steelvelveteen
Copy link

Hi, I got rid of the annoying black band across the previews by setting the border for ranger as true
Aprox around line 122 of the rc.conf file
set draw_borders true (it is false by default)
and this solved my problem
Hope it helps

@4drift
Copy link

4drift commented Dec 27, 2017

Just wanted to say that there is support for urxvt, but thus far it doesn't compile for me.

https://github.com/saitoha/rxvt-unicode-sixel

@slve
Copy link

slve commented Mar 19, 2018

The only workaround for the banding issue that worked for me is editing
/usr/lib/python3.6/site-packages/ranger/ext/img_display.py
adding import time at the top,
and time.sleep(1/100) just right above self.process.stdin.write(input_gen)
around line 122

btw. I had exactly the same issue with xterm, even though it came up less often

using 1/100 is reliable enough on my pc, still, not much lagging when scrolling through many images,
if you still see some bands on your pc, try increasing it,
using 1/20 not a single band showed up,
but scrolling through a lot of images wasn't as smooth as with 1/100

using this patch, there is no need to set draw_borders true, which is a big plus for me

@wilzbach
Copy link

The only workaround for the banding issue that worked for me is editing
/usr/lib/python3.6/site-packages/ranger/ext/img_display.py
adding import time at the top,
and time.sleep(1/100)

Nice! That worked for me too. Is there any chance we could get such a workaround upstream?

@vifon
Copy link
Member

vifon commented Jun 14, 2018

@wilzbach Already there. :) #1193

@doa379
Copy link

doa379 commented Jun 5, 2019

I'm experiencing this in Debian 10 Testing.
I was using w3m to preview images in Xterm and it's been working fine. But after switching to URxvt recently, images are flickering in the Ranger preview.
Clearly whatever fix that was pushed out has not really worked.

@doa379
Copy link

doa379 commented Jun 5, 2019

I would like to give credence to the theory that it's Xft related because the issue is not present when I start URxvt with a bitmap font instead of an Xft font.

@Ojousama
Copy link

Ojousama commented Jun 13, 2019

urxvt xft problem

@DanielAndreasen
Copy link

I had the same flickering problem with st (and tried most things). What in the end worked for me, was to clone this repo and install from source (sudo make install). I made sure ranger.py was in my PATH (I made a link and called it ranger).
After that I tweaked the w3m_delay a bit and ended up with adding this to my config which seems to work in 95% of the cases
set w3m_delay 0.1

@amahmod
Copy link

amahmod commented Oct 3, 2019

adding w3m_delay to rc.conf solved my problem with st
Thanks to @DanielAndreasen

@thepenguinthatwants
Copy link

thepenguinthatwants commented Apr 26, 2020

adding w3m_delay to rc.conf solved my problem with st
Thanks to @DanielAndreasen
Can you show your whole config?

I've being struggling with this for ages.
Pictures show up in ST or alacritty only milliseconds. urxvt and xterm they dont even show up.

set w3m_delay 0.1
didnt help it only delayed showing picture

set preview_files true
set preview_script ~/.config/ranger/scope.sh
set use_preview_script true
set preview_images_method w3m
set draw_borders true

The problem is mostly because of w3m as pictures show there only just milliseconds.

@MarcoDiFrancesco
Copy link

set draw_borders true

This solved the problem for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests