Hi again,
thumbnails should not be regenerated every time they need to be
displayed in the open-dialog (quote maxy: "the point is that we don't
recompute the thumbnail of a 2000x2000 .png every time the user clicks
on it in the file browser"). I have taken care of that by searching
"~/.thumbnails". (Note, however, that I haven't looked into the windows
side of things, yet. It should be sufficient to extract a thumbnail from
the correct Thumbs.db [I think it is generated and saved folder wise,
right?] which, if I remember correctly, is sqlite)
I also changed the preview size to 128x128px² as that's the default
freedesktop thumbnail size and added to the pixbuf_thumbnail method in
helpers.py to allow an alpha channel (failed for some images, e.g.
screenshots made with the compiz screenshot plugin).
Also I have to admit that I didn't look into learning git, yet, so I
simply attached the git diff patch again.
Till
diff --git a/gui/filehandling.py b/gui/filehandling.py
index 871f071..14b5da8 100644
--- a/gui/filehandling.py
+++ b/gui/filehandling.py
@@ -269,11 +269,18 @@ class FileHandler(object):
loader.write(data)
loader.close()
pixbuf = loader.get_pixbuf()
+ pixbuf = helpers.scale_proportionally(pixbuf, 128, 128)
return pixbuf
else:
try:
- #TODO do not scale images smaller than 256x256 up.
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, 256, 256)
+ #TODO find out how to use windows' "Thumbs.db" (sqlite?)
+ thumb_filename = helpers.get_freedesktop_thumbnail_file(filename)
+ if thumb_filename:
+ pixbuf = gtk.gdk.pixbuf_new_from_file(thumb_filename)
+ pixbuf = helpers.pixbuf_thumbnail(pixbuf, 128, 128, True) # width should always be 128px
+ else:
+ pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
+ pixbuf = helpers.pixbuf_thumbnail(pixbuf, 128, 128, True)
return pixbuf
except:
pass
diff --git a/lib/helpers.py b/lib/helpers.py
index f6ca5af..5e58358 100644
--- a/lib/helpers.py
+++ b/lib/helpers.py
@@ -12,6 +12,9 @@ import colorsys, urllib, gc
from gtk import gdk # for gdk_pixbuf stuff
import mypaintlib
+import hashlib
+import os
+
try:
from json import dumps as json_dumps, loads as json_loads
print "builtin python 2.6 json support"
@@ -111,7 +114,24 @@ def gdkpixbuf2numpy(pixbuf):
arr = pixbuf.get_pixels_array()
return mypaintlib.gdkpixbuf_numeric2numpy(arr)
-def pixbuf_thumbnail(src, w, h):
+def get_freedesktop_thumbnail_file(filename):
+ file_hash = hashlib.md5('file://'+filename).hexdigest()
+ tb_filename = os.path.join(os.path.expanduser('~/.thumbnails/normal'), file_hash) + '.png'
+ if os.path.exists(tb_filename):
+ return tb_filename
+ else:
+ return None
+
+def scale_proportionally(pixbuf, w, h):
+ width = pixbuf.get_width()
+ height = pixbuf.get_height()
+ scale = min(w / float(width), h / float(height))
+ new_width = int((width * scale))
+ new_height = int((height * scale))
+ pixbuf = pixbuf.scale_simple(new_width, new_height, gdk.INTERP_BILINEAR)
+ return pixbuf
+
+def pixbuf_thumbnail(src, w, h, alpha=False):
"""
Creates a centered thumbnail of a gdk.pixbuf.
"""
@@ -128,9 +148,11 @@ def pixbuf_thumbnail(src, w, h):
assert w2 <= w and h2 <= h
src2 = src.scale_simple(w2, h2, gdk.INTERP_BILINEAR)
- dst = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, w, h)
- dst.fill(0xffffffff) # white background
-
+ dst = gdk.Pixbuf(gdk.COLORSPACE_RGB, alpha, 8, w, h)
+ if alpha:
+ dst.fill(0xffffff00) # transparent background
+ else:
+ dst.fill(0xffffffff) # white background
src2.copy_area(0, 0, w2, h2, dst, (w-w2)/2, (h-h2)/2)
return dst
_______________________________________________
Mypaint-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/mypaint-discuss