| 1 | package Palm::ZirePhoto; | ||
| 2 | # | ||
| 3 | # ABSTRACT: Handler for Palm Zire71 Photo thumbnail database | ||
| 4 | # | ||
| 5 | # Copyright (C) 2003, Alessandro Zummo. | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the same terms as Perl itself. | ||
| 9 | # | ||
| 10 | # This program is distributed in the hope that it will be useful, | ||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the | ||
| 13 | # GNU General Public License or the Artistic License for more details. | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use Palm::Raw(); | ||
| 17 | use Palm::StdAppInfo(); | ||
| 18 | |||
| 19 | use vars qw( $VERSION @ISA ); | ||
| 20 | |||
| 21 | # One liner, to allow MakeMaker to work. | ||
| 22 | $VERSION = '1.400'; | ||
| 23 | # This file is part of Palm 1.400 (March 14, 2015) | ||
| 24 | |||
| 25 | @ISA = qw( Palm::StdAppInfo Palm::Raw ); | ||
| 26 | |||
| 27 | |||
| 28 | #' | ||
| 29 | |||
| 30 | sub import | ||
| 31 | { | ||
| 32 | &Palm::PDB::RegisterPDBHandlers(__PACKAGE__, | ||
| 33 | [ "Foto", "Foto" ], | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub new | ||
| 38 | { | ||
| 39 | my $classname = shift; | ||
| 40 | my $self = $classname->SUPER::new(@_); | ||
| 41 | # Create a generic PDB. No need to rebless it, | ||
| 42 | # though. | ||
| 43 | |||
| 44 | $self->{name} = "PhotosDB-Foto"; # Default | ||
| 45 | $self->{creator} = "Foto"; | ||
| 46 | $self->{type} = "Foto"; | ||
| 47 | $self->{attributes}{resource} = 0; | ||
| 48 | # The PDB is not a resource database by | ||
| 49 | # default, but it's worth emphasizing. | ||
| 50 | |||
| 51 | # Give the PDB an empty list of records | ||
| 52 | $self->{records} = []; | ||
| 53 | |||
| 54 | return $self; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub ParseRecord | ||
| 58 | { | ||
| 59 | my $self = shift; | ||
| 60 | my %record = @_; | ||
| 61 | my $data = $record{'data'}; | ||
| 62 | |||
| 63 | delete $record{offset}; # This is useless | ||
| 64 | delete $record{data}; # No longer necessary | ||
| 65 | |||
| 66 | # when Photo thumbnail records are deleted/archived/whatever, the data section is | ||
| 67 | # actually set to zero length. Presumably this is so that thumbnails take up | ||
| 68 | # minimum space until a sync purges the records. | ||
| 69 | |||
| 70 | return \%record unless length $data > 36; | ||
| 71 | |||
| 72 | @record{ | ||
| 73 | 'width', | ||
| 74 | 'height', | ||
| 75 | 'time1_secs', | ||
| 76 | 'size', | ||
| 77 | 'nameSize', | ||
| 78 | 'time2_secs', | ||
| 79 | 'thumb', | ||
| 80 | 'name' | ||
| 81 | } = unpack "xxxx n n N N x5 n x5 N x4 N/a a*", $data; | ||
| 82 | |||
| 83 | $record{'thumbSize'} = length($record{'thumb'}); | ||
| 84 | |||
| 85 | $record{'time1'} = $record{'time1_secs'} - 2082844800; | ||
| 86 | $record{'time2'} = $record{'time2_secs'} - 2082844800; | ||
| 87 | |||
| 88 | $record{'name'} = substr($record{'name'}, 0, $record{'nameSize'}); | ||
| 89 | |||
| 90 | return \%record; | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | sub ParseNote | ||
| 95 | { | ||
| 96 | return ($_[0] =~ /NOTE.{8}([^\0]+)\0*ARCPHOTOBASE.{8}$/so) ? $1 : undef; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | sub ParseAlbum | ||
| 101 | { | ||
| 102 | my $album = shift; | ||
| 103 | |||
| 104 | # make sure it's an expected record format. | ||
| 105 | return undef unless $album =~ /^DBFH/o; | ||
| 106 | |||
| 107 | my @records; | ||
| 108 | |||
| 109 | # skip .db file's initial 16 byte header, then grab 292 byte records | ||
| 110 | for( my $pos = 16; $pos < length($album); $pos += 292 ) { | ||
| 111 | my $buf = substr( $album, $pos, 292 ); | ||
| 112 | last if length($buf) < 292; | ||
| 113 | |||
| 114 | my %record; | ||
| 115 | @record{ | ||
| 116 | 'name', | ||
| 117 | 'time1_secs', | ||
| 118 | 'time2_secs', | ||
| 119 | 'size', | ||
| 120 | 'width', | ||
| 121 | 'height' | ||
| 122 | } = unpack('a256 x4 N N N x8 n n x8', $buf); | ||
| 123 | |||
| 124 | $record{name} =~ s/\0+$//o; | ||
| 125 | $record{time1} = $record{time1_secs} - 2082844800; | ||
| 126 | $record{time2} = $record{time2_secs} - 2082844800; | ||
| 127 | $record{'thumbSize'} = 0; | ||
| 128 | $record{'thumb'} = ''; | ||
| 129 | $record{'nameSize'} = length $record{name}; | ||
| 130 | |||
| 131 | push @records, \%record; | ||
| 132 | } | ||
| 133 | |||
| 134 | return @records; | ||
| 135 | } | ||
| 136 | |||
| 137 | 1; | ||
| 138 | |||
| 139 | __END__ |