Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
background drawer that cares about pixelaspectratio
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
javeree
Guru
Guru


Joined: 29 Jan 2006
Posts: 356

PostPosted: Wed Mar 02, 2011 12:16 pm    Post subject: background drawer that cares about pixelaspectratio Reply with quote

I have a HTPC with output to a TV (using VGA input).
The TV has 16:9 aspect ratio, but the resolution is 4:3. This means that pixels are not square but stretched horizontally.
With programs such as mplayer and VLC, I can set them to take this into pixel aspect ratio into account, so in movies, squares look like squares and circles like circles.

I also want a program like feh or hsetroot or similar to regularly show a picture on the background. It is possible to tell such programs to fill the screen as much as possible while preserving the aspect ratio of the picture. However, all programs I have tried seem to assume that the display has square pixels, so the end result is that the pictures on the background are stretched horizontally, resulting in short, fat people :-)

Does anyone have a suggestion of a (lightweight) picture displaying program that can write to the root window and takes into account pixel aspect ratio ?
Back to top
View user's profile Send private message
javeree
Guru
Guru


Joined: 29 Jan 2006
Posts: 356

PostPosted: Fri Apr 29, 2011 9:53 am    Post subject: Reply with quote

I have found a satisfactory solution: using ImageMagick to predistort the image to display.

The script below is a rough start. It is not polished (hardcoding directories) nor robust (e.g. assuming all files named *.jpg are actually of type JPG), but it does the job.

The key line in the script is:
Code:
display -window $BACKGROUNDWINDOWID -backdrop -filter Lanczos -resize $SCREENSIZE -resize 75%x100% "$FILENAME"   


My main gripe with the script is:
it consumes a huge amount of CPU for doing the resizes (multiple seconds of full CPU usage)

Code:

#!/bin/bash
# todo: when a file is not valid, remove it from the playlist
set -x

FOTOBASEDIR="$HOME/mnt/$HOSTNAME/Fotos/"
FOTOPLAYLIST="/var/tmp/FvwmMediaBackgroundPlaylist"
COMMANDFILE="/var/tmp/FvwmMediaBackgroundCommand"
SLEEPTIME=60
FILEDESCRIPTOR=51
BACKGROUNDWINDOWID=root

if [ ! -z $1 ] ; then
        echo $1 > $COMMANDFILE
        exit
else
        mkfifo $COMMANDFILE
        COMMAND="exec $FILEDESCRIPTOR<>$COMMANDFILE"
        eval $COMMAND
fi

function checkdepends {
        PROGRAMS="convert cut find grep sed xrandr"
        for PROGRAM in PROGRAMS ; do
                if [ ! -x "$(which ${PROGRAM} )" ] ; then
                        echo $0 error: missing ${PROGRAM}
                fi
        done
}


function buildplaylist {
                find "$FOTOBASEDIR" -follow -maxdepth 5 -type f -iname '*.jpg' | sort -R > "$FOTOPLAYLIST"
}

if [ ! -d "$FOTOBASEDIR" ] ; then
        echo $0 error: could not find  "$FOTOBASEDIR"
        exit 1
fi

# initially start unpaused
PAUSE=false
SCREENSIZE=$(xrandr | grep 'current' | cut -d ',' -f 2 | sed 's:current::' | sed 's: ::g')

while true ; do

        if [ ! -s "$FOTOPLAYLIST" ] ; then
                buildplaylist
        fi
        if [ ! -s "$FOTOPLAYLIST" ] ; then
                echo "$0 error: no fotos found"
                exit
        fi

        while read FILENAME ; do
                # 75%x100%: displaying a 4/3 screen on a 16/9 displays means a distortion of (16/9)/(4/3) = 4/3 since 75%/100% is 3/4, this compensates to give 1, so no distortion anymore.
                # Slow operation. Speed up using Lanczos filter, which is a faster filter than the default
                display -window $BACKGROUNDWINDOWID -backdrop -filter Lanczos -resize $SCREENSIZE -resize 75%x100% "$FILENAME"               
                WAITFORCOMMAND=true
                while  $WAITFORCOMMAND ; do
                        read -t $SLEEPTIME COMMAND <&$FILEDESCRIPTOR
                        case $COMMAND in
                        pause) PAUSE=true ;;
                        play) PAUSE=false ;;
                        next) break ;;
                        stop) exit ;;
                        rebuild) buildplaylist ;;
                        esac
                        if $PAUSE ; then WAITFORCOMMAND=true ; else WAITFORCOMMAND=false ; fi
                done

        done < "$FOTOPLAYLIST"
done
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum