Friday, June 7, 2013

Start screensaver on still pictures

Start screensaver on still pictures

I have an Ubuntu box connected to a plasma TV. Still images reduce the lifetime of plasma TVs and reduce pixel-burn. I am looking for a technique to start the screensaver if the picture on the monitor is still for a while but prevents the screensaver if the picture is moving. Here is my not-working piece of python code but any solution using python or otherwise is good for me:
import gtk.gdk
import time
from subprocess import *

w = gtk.gdk.get_default_root_window()
sz = w.get_size()

while (True):
    buf1 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
    pb1 = buf1.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
    time.sleep(3)
    buf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
    pb2 = buf2.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])

    pix1 = pb1.get_pixels()
    pix2 = pb2.get_pixels()
    diffs = 0
    for i in range(len(pix1)):
        if(pix1[i] != pix2[i]):
            diffs = diffs + 1
    if(diffs > 10000):
        call(["xset", "dpms", "force", "on"])
        call(["gnome-screensaver-command", "--exit"])

No comments:

Post a Comment