Re: Loading a EXIF thumbnail with Gtk2::Gdk::Pixbuf->new_from_data



On Sep 13, 2005, at 8:08 AM, Johnny Morano wrote:

This is my first message to the list.
Welcome.  We'll try to make the hazing light.


This is my code:

 my $data = pack( 'a*', ${ $image->get_exif->{ThumbnailImage} } );
The pack() here isn't what you want.  See below.

 my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_data($data,'rgb',0,8,$width,
$height,$width * 3);
...
BUT, the thumbs are scrambled (snowy black).
Is the image data actually raw, packed, 24-bit pixels?  If it's in a  
compressed format, you'll have to do incremental loading with a  
PixbufLoader.
/me pokes google for EXIF thumbnail format

According to http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif- e.html#ExifThumbs the thumbnail will be JPEG or TIFF, not raw bits.
Do this, instead:

  my $loader = Gtk2::Gdk::PixbufLoader->new;
  $loader->write ($data);
  $loader->close ();
  my $pixbuf = $loader->get_pixbuf ();

(That code is from memory, check for yourself to make sure i'm not telling lies.)

I used to load the the image file with new_from_file, and then scaled it
to a thumbnail size. But, this isn't as fast as just loading the the
thumb from a file ofcourse.
There's new_from_file_at_size(), which uses a PixbufLoader to scale  
the image as it reads each chunk.  But, this is still slower than  
using the precomputed thumbnail.

The perldoc of Gtk2::Gdk::Pixbuf suggests that I have to pack the $data, but, I don't know how.
That's referring to how to create image data in your script.  The  
image data is expected to be a flat buffer of pixel data, and to  
manipulate the contents of such a thing in perl, you need to use pack 
().  If you have packed data returned from some other source, you  
have no further work to do.


--
"Ears! They help us -- Ears! They help us hear th-- Ea--E--E--E-- Ears!"
  -- A Sesame Street singing toy, with Yvonne gleefully pressing
    the button over and over and over and over and...




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]