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

Refresh preview problem #173

Open
og900aero opened this issue Apr 5, 2024 · 11 comments
Open

Refresh preview problem #173

og900aero opened this issue Apr 5, 2024 · 11 comments

Comments

@og900aero
Copy link

I use Debian 12 Stable with bspwm tiling windows manager, and lf file manager, and I configured preview. But I have a big problem. Sometimes there are cases where the EXIF orientation of the completed images does not get a good value. Image viewers can handle this just fine, but the preview image will show it rotated. For this, I created a command that rotates the image in the right direction and saves the file under its original name (convert file -auto-orient file)
The problem is that no matter how hard you do it, the preview image doesn't show it. It doesn't show even if I quit the lf program and open it again. It only updates if I open another window (no matter what program) and then the lf window shrinks and thus suddenly updates the preview image and now shows it well.
What could be the problem? How should one of the scripts be modified?

The following config files use:

cleaner:

#!/bin/sh
if [ -n "$FIFO_UEBERZUG" ]; then
  printf '{"action": "remove", "identifier": "preview"}\n' >"$FIFO_UEBERZUG"
fi

lfrun

#!/bin/sh
set -e

cleanup() {
    exec 3>&-
rm "$FIFO_UEBERZUG"
}

if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
lf "$@"
else
[ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf"
export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$"
mkfifo "$FIFO_UEBERZUG"
ueberzug layer -s <"$FIFO_UEBERZUG" -p json &
exec 3>"$FIFO_UEBERZUG"
trap cleanup EXIT
lf "$@" 3>&-
fi

previewer:

#!/bin/sh

draw() {
if [ -n "$FIFO_UEBERZUG" ]; then
  printf '{"action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' \
    "$4" "$5" "$2" "$3" "$1" >"$FIFO_UEBERZUG"
fi
  exit 1
}

hash() {
  printf '%s/.cache/lf/%s' "$HOME" \
    "$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
}

cache() {
  if [ -f "$1" ]; then
    draw "$@"
  fi
}

batorcat() {
if command -v batcat > /dev/null 2>&1; then
batcat --color=always --style=snip --pager=never --decorations=always "$file"
else
cat "$file"
fi
}

file="$1"
shift

if [ -n "$FIFO_UEBERZUG" ]; then
  case "$(file -Lb --mime-type -- "$file")" in
    image/*)
        draw "$file" "$@"
      ;;
    video/*)
      cache="$(hash "$file").jpg"
      cache "$cache" "$@"
      ffmpegthumbnailer -i "$file" -o "$cache" -s 0
      draw "$cache" "$@"
      ;;
    audio/*) exiftool "$file" ;;
    message/rfc822) w3m -dump "$file" ;;
    */*torrent) exiftool "$file" ;;
    */pdf)
      pdftoppm -jpeg -f 1 -singlefile "$1" "$hash"
 draw "$file" "$@"
      ;;
    */rtf) catdoc "$file" ;;
    */msword) catdoc "$file" ;;
    */*wordprocessing*) docx2txt < "$file" | batcat --style=plain ;;
    */*spreadsheet*) xlsx2csv "$file" ;;
    text/*|*/json) batorcat ;;
    */zip) unzip -l "$file" ;;
    */gzip)
      tar tzf "$file"
      gzip -l "$file"
      ;;
    */zstd) tar tf "$file" ;;
    */x-bzip2) tar tjf "$file" ;;
    */x-xz) tar tf "$file" ;;
    */x-tar) tar tf "$file" ;;
    */*rar) unrar l "$file" ;;
*) file -ibL "$file" | grep -q text && batorcat "$file" || file -Lb "$file" ;;
  esac
fi

file -Lb -- "$1" | fold -s -w "$width"
exit 0
@jstkdng
Copy link
Owner

jstkdng commented Apr 5, 2024

can you post those images that have bad exif values?

@og900aero
Copy link
Author

can you post those images that have bad exif values?

I sent email with example picture ([email protected])

@jstkdng
Copy link
Owner

jstkdng commented Apr 6, 2024

Should be working properly with latest commit, please do test.

@og900aero
Copy link
Author

I try and working properly with problem's picture, but now the first opening of all non-landscape images (were fine originally too) is very slow (2-3 seconds).

@jstkdng
Copy link
Owner

jstkdng commented Apr 7, 2024

Are those images just regular ones? Like, without exif and such?

@og900aero
Copy link
Author

No. Also taken with a mobile phone and contains EXIF data. Ex: Orientation : Horizontal (normal).
So the EXIF data is good, but it opens very slowly the first time you open it. But after that it's good. Even if I restart the machine. Is it hidden somewhere that you have already dealt with it?

@jstkdng
Copy link
Owner

jstkdng commented Apr 8, 2024

Is it hidden somewhere that you have already dealt with it?

yeah, processed images are cached to prevent reprocessing later on

Can you post the images you are testing? maybe the processing I'm doing for the other exif cases aren't the best. Please don't email as I don't think my server can handle attachments properly.

@og900aero
Copy link
Author

Example:

Orientation: Unknown (0)
Grincs

Orientation: Rotate 90 CW
IMG_20210816_132007

Orientation: Horizontal (normal)
IMG_20210816_135759

Of this, in the old ueberzugpp, only the Rotate 90 CW version appeared badly, and it displayed them all at lightning speed, instantly. In the new version, all three display well, but it loads very slowly at first.
However, if there is no EXIF (Unknown (0), or if it has a good value (Horizontal (normal)), then you don't have to deal with it, just display it.

@og900aero
Copy link
Author

How can I remove fresh ueberzugpp? I cloned to directory, and make install in past. Now I want uninstall this, and install from Debian 12 repo, because that version havent slow load problem (vertically picture). I try sudo make uninstall command in cloned directoty, but I get error message: No rule to make target 'uninstall'.

@jstkdng
Copy link
Owner

jstkdng commented Apr 19, 2024

I think make install places all files under /usr/local/ you can remove them from it.

@og900aero
Copy link
Author

Cool. It worked.

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

No branches or pull requests

2 participants