Update of /cvsroot/freevo/freevo/src/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4579/util
Modified Files:
fileops.py
Log Message:
change thumbnail caching format to be much faster: do not use pickle and
also reduce the image size from max 300x300 to 255x255
Index: fileops.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/util/fileops.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** fileops.py 22 Mar 2004 11:04:51 -0000 1.17
--- fileops.py 9 Jun 2004 19:50:32 -0000 1.18
***************
*** 11,14 ****
--- 11,18 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.18 2004/06/09 19:50:32 dischi
+ # change thumbnail caching format to be much faster: do not use pickle and
+ # also reduce the image size from max 300x300 to 255x255
+ #
# Revision 1.17 2004/03/22 11:04:51 dischi
# improve caching
***************
*** 63,68 ****
import fnmatch
import traceback
! import Image
! import cStringIO
if float(sys.version[0:3]) < 2.3:
--- 67,78 ----
import fnmatch
import traceback
!
!
! if sys.argv[0].find('setup.py') == -1 and sys.argv[0].find('install.py') == -1:
! # don't try to import these when Freevo isn't installed (yet)
! import Image
! import cStringIO
! from mmpython.image import EXIF as exif
!
if float(sys.version[0:3]) < 2.3:
***************
*** 462,502 ****
#
! def cache_image(filename, thumbnail=None):
"""
! cache image for faster access
"""
- sinfo = os.stat(filename)
thumb = vfs.getoverlay(filename + '.raw')
try:
! if os.stat(thumb)[stat.ST_MTIME] > sinfo[stat.ST_MTIME]:
! return
except OSError:
pass
if thumbnail:
- image = Image.open(cStringIO.StringIO(thumbnail))
- else:
try:
! image = Image.open(filename)
except:
! return
if not image:
! return
! try:
! if image.size[0] > 300 and image.size[1] > 300:
! image.thumbnail((300,300), Image.ANTIALIAS)
! if image.mode == 'P':
! image = image.convert('RGB')
! # save for future use
! data = (image.tostring(), image.size, image.mode)
! save_pickle(data, thumb)
! except Exception, e:
! print 'error caching image %s' % filename
! if config.DEBUG:
! print e
!
!
--- 472,538 ----
#
! def read_thumbnail(filename):
"""
! return image cached inside filename
! """
! f = open(filename)
! header = f.read(10)
! if not header[:3] == 'FRI':
! return read_pickle(filename)
! data = f.read(), (ord(header[3]), ord(header[4])), header[5:].strip(' ')
! f.close()
! return data
!
!
! def cache_image(filename, thumbnail=None, use_exif=False):
! """
! cache image for faster access, return cached image
"""
thumb = vfs.getoverlay(filename + '.raw')
try:
! if os.stat(thumb)[stat.ST_MTIME] > os.stat(filename)[stat.ST_MTIME]:
! data = read_thumbnail(thumb)
! if data:
! return data
except OSError:
pass
+ image = None
if thumbnail:
try:
! image = Image.open(cStringIO.StringIO(thumbnail))
except:
! pass
if not image:
! if use_exif:
! f=open(filename, 'rb')
! tags=exif.process_file(f)
! f.close()
!
! if tags.has_key('JPEGThumbnail'):
! image = Image.open(cStringIO.StringIO(tags['JPEGThumbnail']))
! if not image or image.size[0] < 100 or image.size[1] < 100:
! try:
! image = Image.open(filename)
! except Exception, e:
! print 'error caching image %s' % filename
! if config.DEBUG:
! print e
! return None
!
! if image.size[0] > 255 or image.size[1] > 255:
! image.thumbnail((255,255), Image.ANTIALIAS)
! if image.mode == 'P':
! image = image.convert('RGB')
! data = (image.tostring(), image.size, image.mode)
!
! f = open(thumb, 'w')
! f.write('FRI%s%s%5s' % (chr(image.size[0]), chr(image.size[1]), image.mode))
! f.write(data[0])
! f.close()
!
! return data
-------------------------------------------------------
This SF.Net email is sponsored by: GNOME Foundation
Hackers Unite! GUADEC: The world's #1 Open Source Desktop Event.
GNOME Users and Developers European Conference, 28-30th June in Norway
http://2004/guadec.org
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog