Results 1 to 14 of 14
  1. PxT
    PxT is offline
    PxT's Avatar
    Posts
    34 Posts
       #1  
    [ Edit: Original post questioned how to do this properly, I have it figured out now. Here's the solution ]


    I have written a perl script to extract images from the Treo600 under Linux. As far as I know there is currently no way to sync the Treo Pictures folder under Linux as there is in Windows. This script solves that problem.

    Start by syncing the ImageLib_imageDB.pdb database. Then you will need to run the following script:

    Code:
    #!/usr/bin/perl -w
    
    use strict;
    use Palm::PDB;
    use Palm::Raw;
    
    my $DEBUG = 0;
    
    my $pdb = new Palm::PDB;
    $pdb->Load("ImageLib_imageDB.pdb");
    
    my $id = my $oldid = 0;
    my $partone = my $firsttime = 1;
    foreach my $chunk (@{$pdb->{records}}) {
               $id = $chunk->{'id'};
               if($oldid != 0 && $id > ($oldid+1)) {
                  close JPG;
                  $partone = 1;
               } elsif ($firsttime == 1) {
                  $firsttime = 0;
               }
               my $jpg = unpack("x4a*", $chunk->{'data'});
               if ($DEBUG) {
                    open(DJPG, "> chunk.$id.jpg") or die "Couldn't open debug file $id\n";
                    # print the raw packed data
                    print DJPG "$chunk->{'data'}";
                    close DJPG;
               }
    
               if($partone == 1) {
                    open(JPG, "> $id.jpg") or die "Couldn't open $id.jpg\n";
                    $partone = 0;
                    print "\n$id.jpg ";
               }
               print JPG "$jpg";
    
            $oldid = $id;
            print ".";
    }
    print "\n";
    This will extract all the images contained within the pdb file and output them to your current directory. You will need the Palm::PDB module available from CPAN.

    If you use this script, please let me know how it works for you.
    Last edited by PxT; 10/28/2003 at 01:08 PM.
  2. #2  
    Originally posted by PxT

    This will extract all the images contained within the pdb file and output them to your current directory. You will need the Palm::PDB module available from CPAN.

    If you use this script, please let me know how it works for you.
    Can't find a Palm::PDB on CPAN. Any suggestions?
  3. #4  
    I guess "perl -MCPAN -e shell" isn't very smart. "install Palm::PDB" doesn't work for me, but that does. Thanks!
  4. rosh's Avatar
    Posts
    19 Posts
    Global Posts
    22 Global Posts
    #5  
    I tried the script after downloading the appropriate perl library. I got JPEGS on the directory, but they seem to be incorrect jpegs. That is, programs like imageMagick and konqueror don't seem to like them and complain that they have bad headers or something of the like. Great script, hope you can get it working b/c it would be great to get these pics

    Thanks for all your help!!!

    actual error message:

    display: Not a JPEG file: starts with 0xc3 0xbf (3215418.jpg).
    Last edited by rosh; 12/28/2003 at 03:35 AM.
  5. #6  
    Hi,

    I was looking for a way to transfer pictures from my Treo 600 to my Linux desktop, and I'm happy I found this script.

    It's working OK, but it has some trouble determining the limit between each JPG file.
    Your script assumes that the first record containing data for a picture will not follow the previous chunk's id. The test is "$id > ($oldid+1)"
    But in my case, I had 3 pictures with all the chunks having consecutive ids (I think I took them in a row). All 3 pictures ended up in 1 file. I had to write out each chunk and put them together by hand.

    So I know what the problem is, but I can't think of any other way of determining when a chunk belongs to a new file.

    Any idea would be quite welcome, so that we can bring this script one step closer to perfection

    Thanks
  6. #7  
    All this is guess work, and could be wrong. But it works for me...

    Each pics got a record in ImageLib_mainDB.pdb, with this struct:
    Code:
    32 char : file name
    4 bytes : the second is the picure type
    4 bytes : padding ?
    1 long : start record id for picture (startrec)
    4 bytes : padding ?
    1 long : start record id for thumbnail
    1 short : nb records for picture (nbrec)
    1 short : nb records for thumbnail
    1 long : timestamp
    1 long : picture size
    1 long : thumb size
    52 char : padding ?
    So you need to read nbrec records, starting from startrec in ImageLib_mainDB.pdb, and remove the first 4 byte of each record to have a perfect jpeg file.

    Here is a crude python script outputing all the pictures from a ImageLib_mainDB.pdb, ImageLib_imageDB.pdb pair:

    Code:
    import struct
    from pisock import *
    import string
    import time
    
    class Image:
        def __init__(self, main_db, idx, image_db):
    
            ( self.rec, self.a1, self.a2, self.uid) = pi_file_read_record(main_db, idx)
            
            self.image_db = image_db
            
            ( self.name,
              self.b1, self.b2, self.b3, self.b4,
              self.l1, self.main_start, self.l3, self.aux_start,
              self.nb_main, self.nb_aux,
              self.time, self.main_size, self.aux_size, pad) = struct.unpack('32s4B4L2H3L52s', self.rec)
            
            if pad != '\0' * len(pad):
                raise 'Pad not null'
    
            idx = self.name.index('\0')
            self.name = self.name[:idx]
    
    
        def dump(self, start, nb, size, file):
            for i in range(nb):
                (rec, a1, a2, uid) = pi_file_read_record_by_id(image_db, start+i)
                data = rec[4:]
                file.write(data)
                size -= len(data)
    
            if size != 0:
                print "Size / extract size mismatch"
    
        def dump_main(self, name):
            file = open(name, 'wb')
            self.dump(self.main_start, self.nb_main, self.main_size, file)
            file.close()
            
        def dump_aux(self, name):
            file = open(name, 'wb')
            self.dump(self.aux_start, self.nb_aux, self.aux_size, file)
            file.close()
    
    main_db = pi_file_open('ImageLib_mainDB.pdb')
    image_db = pi_file_open('ImageLib_imageDB.pdb')
    
    nb_main = pi_file_get_entries(main_db)
    
    print nb_main, " images(s)"
    
    for i in range (nb_main):
        img = Image(main_db, i, image_db)
        img.dump_main('%s.jpg' % (img.name))
        img.dump_aux('%s.thumb' % (img.name))
  7. rosh's Avatar
    Posts
    19 Posts
    Global Posts
    22 Global Posts
    #8  
    Anton2,

    Tried your script, but I had issues trying to import the pisock module you imported. Is that something I have to download, if so, where?

    I just downloaded the python 2.2.3, the latest from www.python.org, and used that to run the script with the above result.

    Where do I get this module and how do I install it?

    Thanks,

    Roshan
  8. #9  
    Originally posted by rosh
    Anton2,

    Tried your script, but I had issues trying to import the pisock module you imported. Is that something I have to download, if so, where?
    Yes, you need the pisock module. This is a module to use the pilot-link library from python.

    Check first if this is provided with your distribution (may be named python-pisock). If it's not, you'll have to download and install pilot-link with python binding (it's a configure option).

    Good luck, I'll be interrested in your results.
  9. rosh's Avatar
    Posts
    19 Posts
    Global Posts
    22 Global Posts
    #10  
    Hey again,

    Sorry to be a bother, but I am using redhat packages to manage software on my system. I have installed pilot-link 11.8 and pilot-link-devel 11.8, but still don't seem to have this module. According to what was previously posted, I am supposed to install pilot-link by building it from the source with the python bindings. Is there any way to do this using rpm's, or am I just going to have to install pilot-link from source and deal with the dependency issues? Again, thanks for all your help, and would like to test the script as soon as I can get the module configured.

    -- roshan
  10. #11  
    Originally posted by rosh
    Hey again,
    ...snip...
    Is there any way to do this using rpm's, or am I just going to have to install pilot-link from source and deal with the dependency issues?
    ...snip...

    -- roshan
    It looks like pilot-link's rpms are compiled without the python bindings...

    As pilot-link is a little overkill to test this, I've modified the script to use the prc.py class from the Pyrite Publisher project.

    You just have to download the above prc.py file, and put it alongside this new version :

    Code:
    import struct
    import string
    import time
    import prc
    
    class Image:
        def __init__(self, main_db, idx, image_db):
    
            ( self.rec, self.idx, self.uid, self.attr, self.cat) = main_db.getRecord(idx)
            
            self.image_db = image_db
            
            ( self.name,
              self.b1, self.b2, self.b3, self.b4,
              self.l1, self.main_start, self.l3, self.aux_start,
              self.nb_main, self.nb_aux,
              self.time, self.main_size, self.aux_size, pad) = struct.unpack('32s4B4L2H3L52s', self.rec)
            
            if pad != '\0' * len(pad):
                raise 'Pad not null'
    
            idx = self.name.index('\0')
            self.name = self.name[:idx]
    
    
        def dump(self, start, nb, size, file):
            for i in range(nb):
                (rec, idx, uid, attr, cat) = self.image_db.getRecordByID(int(start+i))
                
                data = rec[4:]
                file.write(data)
                size -= len(data)
    
            if size != 0:
                print "Size / extract size mismatch"
    
        def dump_main(self, name):
            file = open(name, 'wb')
            self.dump(self.main_start, self.nb_main, self.main_size, file)
            file.close()
            
        def dump_aux(self, name):
            file = open(name, 'wb')
            self.dump(self.aux_start, self.nb_aux, self.aux_size, file)
            file.close()
    
    main_db = prc.File('ImageLib_mainDB.pdb')
    image_db = prc.File('ImageLib_imageDB.pdb')
    
    nb_main = main_db.getRecords()
    
    print nb_main, " images(s)"
    
    for i in range (nb_main):
        img = Image(main_db, i, image_db)
        img.dump_main('%s.jpg' % (img.name))
        img.dump_aux('%s.thumb' % (img.name))
    I hope this will work for you...
  11. rosh's Avatar
    Posts
    19 Posts
    Global Posts
    22 Global Posts
    #12  
    Great job with the python script, works great, got all the pics and everything like that

    woo hoo linux, got to love the open source community, now, if I can only figure out how to take good pics with the camera and avoid blue dots....

    thanks again!

    Roshan
  12. zrr
    zrr is offline
    zrr's Avatar
    Posts
    1 Posts
    #13  
    Hi

    I am a bit of a newbie.

    Can you post more detailed instructions what I need to do, to get my images out of my TREO 600? I downloaded the Python script but did not manage to pull the images out fo the .pdb files.

    I get:

    14 images(s)
    Traceback (most recent call last):
    File "./import_images", line 57, in ?
    img.dump_main('%s.jpg' % (img.name))
    File "./import_images", line 40, in dump_main
    self.dump(self.main_start, self.nb_main, self.main_size, file)
    File "./import_images", line 29, in dump
    (rec, idx, uid, attr, cat) = self.image_db.getRecordByID(int(start+i))
    TypeError: unpack non-sequence

    But no images ;-(

    Thanks in advance for your help.
    Last edited by zrr; 06/10/2004 at 03:53 AM.
  13. #14  
    You can also use Softick card export to transfer photos from your Sd card.
    It works on my system under Fedora Core 2.
    Mark

Posting Permissions