Using tclMagick, I read a .jpeg image, resize it, preserving the aspect
ratio to create a thumbnail, and copy it to a photo image for display
purposes. As the file read/resize/copy operation is somewhat expensive,
I'd like to save the thumbnail as an SQLite BLOB, but the image size is
still pretty big (puts [string length [$img data]] reports over 150K for a
160x120 thumbnail).
What is the most efficient way of storing the image data in order for it
to be copied back and forth from a database? Do I need to compress and
perhaps then encode the data for efficiency? Should I be using the WAND
data and compression for the I/O rather than the final image data? As I'm
trying to avoid I/O and CPU cycles in the process, I'm looking for
efficiency gains ...
Thanks for any ideas or pointers.
Cheers,
Rob.
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
>What is the most efficient way of storing the image data in order for it
>to be copied back and forth from a database? Do I need to compress and
>perhaps then encode the data for efficiency? Should I be using the WAND
>data and compression for the I/O rather than the final image data? As I'm
>trying to avoid I/O and CPU cycles in the process, I'm looking for
>efficiency gains ...
No idea wrt to these questions.
Just my 0.02 - wait, make that 0.01 :)
Best regards
Helmut Giese
Image content as returned from [$img data] is a very unefficient way to
store image data, since this is a list of pixels, and each pixel is
represented by a #RRGGBB (7 characters) value. Even if stored as
uncompressed RGB data, a 160x120 thumbnail requires 56kB (160*120*3).
Such a bytes array can easily be extracted from [$img data]:
# Get data as list of colors
set tkdata [$img data]
# Convert to hexadecimal string
set hexdata [string map [list " " "" "#" "" "{" "" "}" ""] $tkdata]
# And format it into a bytes array (RGB)
set bdata [binary format H* $hexdata]
Note that this raw data can be converted into a Tk image very quickly,
thanks to support for PPM in Tk core since 8.4.7 (no extension required):
set ppmdata "P6\n\# PPM data\n160 120\n255\n"
append ppmdata $bdata
set img2 [image create photo -data $ppmdata]
However, if you know that interpreter used to read those thumbnails will
incorporate support for more image formats than PPM and GIF (that is,
either Img or Pixane extensions will be available), saving thumbnails in
PNG or JPEG format is probably a simpler, more portable, and more
efficient way to go (a typical 160x120 photographic image wil be 35-40kB
in PNG format, 20-25kB in JPEG format).
Eric
-----
Eric Hassold
Evolane - http://www.evolane.com/
Thanks for your input ... I now have a working prototype which I can
enhance from a performance standpoint and move forward.