| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: DjVu.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: Read DjVu archive meta information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 09/25/2008 - P. Harvey Created | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # References: 1) http://djvu.sourceforge.net/ (DjVu v3 specification, Nov 2005) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # 2) http://www.djvu.org/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Notes: DjVu files are recognized and the IFF structure is processed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # by Image::ExifTool::AIFF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | package Image::ExifTool::DjVu; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Image::ExifTool qw(:DataAccess :Utils); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | $VERSION = '1.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | sub ParseAnt($); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub ProcessAnt($$$); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub ProcessMeta($$$); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub ProcessBZZ($$$); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # DjVu chunks that we parse (ref 4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | %Image::ExifTool::DjVu::Main = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | NOTES => q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | Information is extracted from the following chunks in DjVu images. See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | L<http://www.djvu.org/> for the DjVu specification. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | INFO => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | SubDirectory => { TagTable => 'Image::ExifTool::DjVu::Info' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | FORM => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | TypeOnly => 1, # extract chunk type only, then descend into chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | SubDirectory => { TagTable => 'Image::ExifTool::DjVu::Form' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ANTa => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | SubDirectory => { TagTable => 'Image::ExifTool::DjVu::Ant' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ANTz => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | Name => 'CompressedAnnotation', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | SubDirectory => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | TagTable => 'Image::ExifTool::DjVu::Ant', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ProcessProc => \&ProcessBZZ, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | INCL => 'IncludedFileID', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # information in the DjVu INFO chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | %Image::ExifTool::DjVu::Info = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | FORMAT => 'int8u', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | PRIORITY => 0, # first INFO block takes priority | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | Name => 'ImageWidth', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | Name => 'ImageHeight', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Name => 'DjVuVersion', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | Description => 'DjVu Version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | Format => 'int8u[2]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # (this may be just one byte as with version 0.16) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ValueConv => '$val=~/(\d+) (\d+)/ ? "$2.$1" : "0.$val"', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | Name => 'SpatialResolution', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Format => 'int16u', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ValueConv => '(($val & 0xff)<<8) + ($val>>8)', # (little-endian!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Name => 'Gamma', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ValueConv => '$val / 10', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 9 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | Name => 'Orientation', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Mask => 0x07, # (upper 5 bits reserved) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | PrintConv => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 => 'Horizontal (normal)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 => 'Rotate 180', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 => 'Rotate 90 CW', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 => 'Rotate 270 CW', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # information in the DjVu FORM chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | %Image::ExifTool::DjVu::Form = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Name => 'SubfileType', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | Format => 'undef[4]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | Priority => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | PrintConv => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | DJVU => 'Single-page image', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | DJVM => 'Multi-page document', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | PM44 => 'Color IW44', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | BM44 => 'Grayscale IW44', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | DJVI => 'Shared component', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | THUM => 'Thumbnail image', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # tags found in the DjVu annotation chunk (ANTz or ANTa) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | %Image::ExifTool::DjVu::Ant = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | PROCESS_PROC => \&Image::ExifTool::DjVu::ProcessAnt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | GROUPS => { 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | NOTES => 'Information extracted from annotation chunks.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Note: For speed, ProcessAnt() pre-scans for known tag ID's, so if any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # new tags are added here they must also be added to the pre-scan check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | metadata => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | SubDirectory => { TagTable => 'Image::ExifTool::DjVu::Meta' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | xmp => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | Name => 'XMP', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | SubDirectory => { TagTable => 'Image::ExifTool::XMP::Main' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # tags found in the DjVu annotation metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | %Image::ExifTool::DjVu::Meta = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | PROCESS_PROC => \&Image::ExifTool::DjVu::ProcessMeta, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | GROUPS => { 1 => 'DjVu-Meta', 2 => 'Image' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | NOTES => q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | This table lists the standard DjVu metadata tags, but ExifTool will extract | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | any tags that exist even if they don't appear here. The DjVu v3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | documentation endorses tags borrowed from two standards: 1) BibTeX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | bibliography system tags (all lowercase Tag ID's in the table below), and 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | PDF DocInfo tags (capitalized Tag ID's). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # BibTeX tags (ref http://en.wikipedia.org/wiki/BibTeX) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | address => { Groups => { 2 => 'Location' } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | annote => { Name => 'Annotation' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | author => { Groups => { 2 => 'Author' } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | booktitle => { Name => 'BookTitle' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | chapter => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | crossref => { Name => 'CrossRef' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | edition => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | eprint => { Name => 'EPrint' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | howpublished=> { Name => 'HowPublished' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | institution => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | journal => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | key => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | month => { Groups => { 2 => 'Time' } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | note => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | number => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | organization=> { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | pages => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | publisher => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | school => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | series => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | title => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | type => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | url => { Name => 'URL' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | volume => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | year => { Groups => { 2 => 'Time' } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # PDF tags (same as Image::ExifTool::PDF::Info) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | Title => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | Author => { Groups => { 2 => 'Author' } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Subject => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Keywords => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | Creator => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Producer => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | CreationDate => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | Name => 'CreateDate', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # RFC 3339 date/time format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ValueConv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::ConvertXMPDate($val)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ModDate => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | Name => 'ModifyDate', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ValueConv => 'require Image::ExifTool::XMP; Image::ExifTool::XMP::ConvertXMPDate($val)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | Trapped => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # remove leading '/' from '/True' or '/False' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ValueConv => '$val=~s{^/}{}; $val', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Parse DjVu annotation "s-expression" syntax (recursively) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Inputs: 0) data ref (with pos($$dataPt) set to start of annotation) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Returns: reference to list of tokens/references, or undef if no tokens, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # and the position in $$dataPt is set to end of last token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # Notes: The DjVu annotation syntax is not well documented, so I make | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # a number of assumptions here! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | sub ParseAnt($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ParseAnt: called CC=13 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 15 | my $dataPt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 15 | my (@toks, $tok, $more); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # (the DjVu annotation syntax really sucks, and requires that every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # single token be parsed in order to properly scan through the items) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 15 | Tok: for (;;) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # find the next token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 56 | ▶ | last unless $$dataPt =~ /(\S)/sg; # get next non-space character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 55 | ▶ | if ($1 eq '(') { # start of list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 14 | $tok = ParseAnt($dataPt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } elsif ($1 eq ')') { # end of list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 14 | $more = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 14 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } elsif ($1 eq '"') { # quoted string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 13 | $tok = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 13 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # get string up to the next quotation mark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # this doesn't work in perl 5.6.2! grrrr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # last Tok unless $$dataPt =~ /(.*?)"/sg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # $tok .= $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 16 | my $pos = pos($$dataPt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 16 | ▶ | last Tok unless $$dataPt =~ /"/sg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 16 | $tok .= substr($$dataPt, $pos, pos($$dataPt)-1-$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # we're good unless quote was escaped by odd number of backslashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 16 | ▶ | last unless $tok =~ /(\\+)$/ and length($1) & 0x01; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tok =~ /(\\+)$/ and length $1 & 1
MC/DC50%1/2
$tok =~ /(\\+)$/ and length $1 & 1
$tok =~ /(\\+)$/
length $1 & 1
Truth table66%2/3
A and B
A= $tok =~ /(\\+)$/B= length $1 & 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | $tok .= '"'; # quote is part of the string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # convert C escape sequences, allowed in quoted text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # (note: this only converts a few of them!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 13 | my %esc = ( a => "\a", b => "\b", f => "\f", n => "\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | r => "\r", t => "\t", '"' => '"', '\\' => '\\' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 13 | ▶ | $tok =~ s/\\(.)/$esc{$1}||'\\'.$1/egs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$esc{$1} || '\\' . $1
MC/DC0%0/1
$esc{$1} || '\\' . $1
$esc{$1}
Truth table50%1/2
A
A= $esc{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } else { # key name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 14 | pos($$dataPt) = pos($$dataPt) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # allow anything in key but whitespace, braces and double quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # (this is one of those assumptions I mentioned) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 14 | ▶ | $tok = $$dataPt =~ /([^\s()"]+)/sg ? $1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 41 | ▶ | push @toks, $tok if defined $tok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # prevent further parsing unless more after this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 15 | ▶ | pos($$dataPt) = length $$dataPt unless $more; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 15 | ▶ | return @toks ? \@toks : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # Process DjVu annotation chunk (ANTa or decoded ANTz) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) tag table ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # Returns: 1 on success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | sub ProcessAnt($$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ProcessAnt: called CC=10 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | my ($et, $dirInfo, $tagTablePtr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | my $dataPt = $$dirInfo{DataPt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # quick pre-scan to check for metadata or XMP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | return 1 unless $$dataPt =~ /\(\s*(metadata|xmp)[\s("]/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # parse annotations into a tree structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | pos($$dataPt) = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | ▶ | my $toks = ParseAnt($dataPt) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # process annotations individually | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | my $ant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | foreach $ant (@$toks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | ▶ | next unless ref $ant eq 'ARRAY' and @$ant >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $ant eq "ARRAY" and @$ant >= 2
MC/DC0%0/2
ref $ant eq "ARRAY" and @$ant >= 2
ref $ant eq "ARRAY"
@$ant >= 2
Truth table33%1/3
A and B
A= ref $ant eq "ARRAY"B= @$ant >= 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | my $tag = shift @$ant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | ▶ | next if ref $tag or not defined $$tagTablePtr{$tag}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $tag or not defined $tagTablePtr->{$tag}
MC/DC0%0/2
ref $tag or not defined $tagTablePtr->{$tag}
ref $tag
not defined $tagTablePtr->{$tag}
Truth table33%1/3
A or not(B)
A= ref $tagB= not defined $tagTablePtr->{$tag}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | ▶ | if ($tag eq 'metadata') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # ProcessMeta() takes array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | $et->HandleTag($tagTablePtr, $tag, $ant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | next if ref $$ant[0]; # only process simple values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | $et->HandleTag($tagTablePtr, $tag, $$ant[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # Process DjVu metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) tag table ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # Returns: 1 on success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Notes: input dirInfo DataPt is a reference to a list of pre-parsed metadata entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | sub ProcessMeta($$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ProcessMeta: called CC=10 SCAR=30.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | my ($et, $dirInfo, $tagTablePtr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | my $dataPt = $$dirInfo{DataPt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | ▶ | return 0 unless ref $$dataPt eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | $et->VerboseDir('Metadata', scalar @$$dataPt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | my ($item, $err); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | foreach $item (@$$dataPt) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # make sure item is a simple tag/value pair | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 12 | ▶ | $err=1, next unless ref $item eq 'ARRAY' and @$item >= 2 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
ref $item eq "ARRAY" and @$item >= 2 and not ref $item->[0] and not ref $item->[1]
ref $item eq "ARRAY" and @$item >= 2 and not ref $item->[0]
ref $item eq "ARRAY" and @$item >= 2
MC/DC0%0/4
ref $item eq "ARRAY" and @$item >= 2 and not ref $item->[0] and not ref $item->[1]
ref $item eq "ARRAY"
@$item >= 2
not ref $item->[0]
not ref $item->[1]
Truth table20%1/5
A and B and not(C) and not(D)
A= ref $item eq "ARRAY"B= @$item >= 2C= not ref $item->[0]D= not ref $item->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | not ref $$item[0] and not ref $$item[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # add any new tags to the table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 12 | ▶ | unless ($$tagTablePtr{$$item[0]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $name = $$item[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $name =~ tr/-_a-zA-Z0-9//dc; # remove illegal characters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | length $name or $err = 1, next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | AddTagToTable($tagTablePtr, $$item[0], { Name => ucfirst($name) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 12 | $et->HandleTag($tagTablePtr, $$item[0], $$item[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | ▶ | $err and $et->Warn('Ignored invalid metadata entry(s)'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # Process BZZ-compressed data (in DjVu images) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) tag table ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # Returns: 1 on success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | sub ProcessBZZ($$$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ProcessBZZ: called CC=4 SCAR=15.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | my ($et, $dirInfo, $tagTablePtr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | require Image::ExifTool::BZZ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | my $buff = Image::ExifTool::BZZ::Decode($$dirInfo{DataPt}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | unless (defined $buff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $et->Warn("Error decoding $$dirInfo{DirName}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | my $verbose = $et->Options('Verbose'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | if ($verbose >= 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # dump the decoded data in very verbose mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $et->VerboseDir("Decoded $$dirInfo{DirName}", 0, length $buff); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $et->VerboseDump(\$buff); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | $$dirInfo{DataPt} = \$buff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | $$dirInfo{DataLen} = $$dirInfo{DirLen} = length $buff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # process the data using the default process proc for this table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | ▶ | my $processProc = $$tagTablePtr{PROCESS_PROC} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | return &$processProc($et, $dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | 1; # end | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||