1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
use Test::More tests => 54;
BEGIN { require 't/test_setup.pl'; }
my $tphoto = 't/test_photo.jpg';
my $tdata = 't/test_photo.desc';
my ($image, $image2, $seg, $hash, $hash2, $d1, $d2, $dt, $ref);
my $uc = sub { my $s = "\376\377";
$s .= "\000$_" for split(/ */,$_[0]);
$s .= "\000\000"; };
my $val = sub { my $nn = JPEG_lookup('APP1@IFD0@SubIFD', $_[0]);
$nn = JPEG_lookup('APP1@IFD0', $_[0]) unless defined $nn;
return $nn; };
my $IMAGE_data = {
'YCbCrPositioning' => 2,
'YCbCrCoefficients' => [1, 14, 34, 45, 65, 12],
'YCbCrSubSampling' => [2, 2],
&$val('ReferenceBlackWhite') => [7, 32, 5, 64, 18, 13, 0,0,0,0,0,0],
&$val('PrimaryChromaticities') => [(10..21)],
&$val('Copyright') => 'GPL',
'Software' => 'Image::MetaData::JPEG software',
'DateTime' => ['1996:07:12 14:36:55'],
'WhitePoint' => [12, 16, 8, 16],
&$val('WhiteBalance') => [1],
&$val('GainControl') => ['3'],
&$val('DeviceSettingDescription') => "abcd".&$uc("ciao").&$uc(""),
&$val('ImageUniqueID') => ['123789cd90ffa890' . "\000" x 17],
'_OwnerName' => "Owner's Name: Stefano Bettelli\000",
'_MoireFilter' => 'Moire Filter: OFF',
'FileSource' => ["\003"],
'SceneType' => "\001",
# there are two CFAPattern's !!!
&$val('CFAPattern') => "\000\003\000\003342623342",
'ExposureMode' => [ 2 ],
&$val('RelatedSoundFile') => ['ALB12_a5.DXf'],
&$val('FocalPlaneResolutionUnit') => 3,
&$val('SubjectLocation') => [13, 19],
&$val('SensingMethod') => '7',
'SubSecTime' => "133 \000",
'FlashpixVersion' => ['0100'],
'ColorSpace' => 65535,
'PixelXDimension' => [222],
&$val('LightSource') => 17,
&$val('Flash') => [79],
&$val('SubjectArea') => [10, 20, 30],
&$val('UserComment') => ["Unicode\000asdfgh"],
'ExifVersion' => '0220',
'DateTimeOriginal' => ['1996:07:12 14:36:55'],
'CompressedBitsPerPixel' => [79, 64],
'MeteringMode' => 6,
&$val('ExposureTime') => [12, 55],
&$val('ExposureProgram') => [7],
&$val('SpectralSensitivity') => 'a lot',
&$val('ISOSpeedRatings') => [1, 2, 3, 4],
&$val('XResolution') => [31000, 65536],
&$val('YResolution') => [72, 1],
&$val('ResolutionUnit') => 3,
'PhotometricInterpretation' => 2,
'PlanarConfiguration' => 2,
'Model' => 'Kodak DX3900',
'Orientation' => [4],
'TransferFunction' => [(1..768)],
&$val('Make') => 'Cooperativa Elettronica Reggiana',
&$val('Artist') => 'Stefano Bettelli',
&$val('ImageDescription') => 'spiaggia di Marina Romea',
};
my $cannot_be_set = {
'ImageWidth' => 640,
'ImageLength' => 480,
'BitsPerSample' => [8, 8, 8],
'Compression' => 6,
'FNumber' => [3, -1],
'ColorSpace' => 9,
'ColorSpace' => 'xxx',
'ExifVersion' => '9999',
'DateTimeOriginal' => '1994:23:23 12:14:61',
'ComponentsConfiguration' => "\004\006\005\000",
'BrightnessValue' => [-4],
'LightSource' => 16,
'Flash' => 26,
'StripOffsets' => [(1..10)],
'SamplesPerPixel' => 3,
'RowsPerStrip' => 5,
'StripByteCounts' => [(5..50)],
'JPEGInterchangeFormat' => 600,
'JPEGInterchangeFormatLength' => 3420,
'ExifOffset' => 848,
'GPSInfo' => 1264,
'SubjectArea' => 26,
'UserComment' => 'zzz',
'SubSecTime' => '130ms',
'RelatedSoundFile' => 'FILE.DAT',
'InteroperabilityOffset' => 'calculated',
};
my $must_go_into_SubIFD = {
'FlashEnergy' => [36, 10],
'SpatialFrequencyResponse' => ["\000P&\037cc.\002\005kl"],
'FocalPlaneXResolution' => [3072000, 892],
'FocalPlaneYResolution' => [2048000, 595],
'FocalPlaneResolutionUnit' => [2],
'ExposureIndex' => [200, 1],
'SensingMethod' => ['7'],
'CFAPattern' => ["\000\003\000\003342623342"],
};
#=======================================
diag "Testing APP1 Exif data routines (IMAGE_DATA & ROOT_DATA)";
#=======================================
BEGIN { use_ok ($::tabname, qw(:Lookups)) or exit; }
BEGIN { use_ok ($::pkgname) or exit; } # this must be loaded second!
######################### Redefine Segment's update() to check # of calls
{ no warnings; no strict; $d1 = 0;
local *{"${pkgname}::Segment::update"} = sub { ++$d1; };
$image = newimage($tphoto, '^APP1$');
$image->set_Exif_data($IMAGE_data, 'IMAGE_DATA', 'ADD');
is( $d1, 1, "update() called only once with IMAGE_DATA" ); }
#########################
$image = newimage($tphoto, '^APP1$');
$hash = $image->set_Exif_data($IMAGE_data, 'IMAGE_DATA', 'ADD');
is_deeply( $hash, {}, "all test IMAGE records ADDed" );
#########################
$hash = $image->set_Exif_data($cannot_be_set, 'IMAGE_DATA', 'ADD');
is( scalar keys %$hash, scalar keys %$cannot_be_set,
"all forbidden records are rejected" );
#########################
$hash = $image->set_Exif_data($cannot_be_set, 'IMAGE_DATA', 'REPLACE');
is( scalar keys %$hash, scalar keys %$cannot_be_set,
"all forbidden records rejected when replacing" );
#########################
$hash = $image->set_Exif_data($must_go_into_SubIFD, 'IMAGE_DATA', 'REPLACE');
is_deeply( $hash, {}, "all records which should go to SubIFD accepted" );
#########################
$hash = $image->get_Exif_data('SUBIFD_DATA', 'TEXTUAL');
ok( exists $$hash{$_}, "... $_ found in SubIFD" ),
is_deeply( $$hash{$_}, $$must_go_into_SubIFD{$_}, "... its value is OK" )
for keys %$must_go_into_SubIFD;
#########################
$hash = $image->set_Exif_data($IMAGE_data, 'IMAGE_DATA', 'REPLACE');
is_deeply( $hash, {}, "REPLACing in the image works" );
#########################
$image->set_Exif_data({}, 'IMAGE_DATA', 'REPLACE');
$hash = $image->get_Exif_data('IMAGE_DATA', 'TEXTUAL');
is_deeply( $$hash{'XResolution'}, [72,1], "Automatic IFD0 XResolution works" );
#########################
is_deeply( $$hash{'YCbCrPositioning'}, [1], "... also YCbCrPositioning" );
#########################
$hash = $image->get_Exif_data('IMAGE_DATA', 'TEXTUAL');
is_deeply($$hash{'ExifVersion'},['0220'],"Automatic SubIFD ExifVersion works");
#########################
is_deeply( $$hash{'ColorSpace'}, [1], "... also ColorSpace" );
#########################
is_deeply( [${$$hash{'PixelXDimension'}}[0], ${$$hash{'PixelYDimension'}}[0]],
[$image->get_dimensions()], "... also picture dimensions" );
#########################
$seg = $image->retrieve_app1_Exif_segment();
$seg->set_Exif_data($IMAGE_data, 'IMAGE_DATA', 'REPLACE');
$hash = $seg->get_Exif_data('IMAGE_DATA', 'NUMERIC');
$image->set_Exif_data($IMAGE_data, 'IMAGE_DATA', 'ADD');
$hash2 = $image->get_Exif_data('IMAGE_DATA', 'NUMERIC');
is_deeply( $hash, $hash2, "adding through image/segment coincide" );
#########################
$image->remove_app1_Exif_info(-1);
$hash = $image->set_Exif_data($IMAGE_data, 'IMAGE_DATA', 'ADD');
is_deeply( $hash, {}, "adding without the Exif segment" );
#########################
$ref = \ (my $buffer = "");
$image->save($ref);
$image2 = newimage($ref, '^APP1$');
is_deeply( $image2->{segments}, $image->{segments}, "Write and reread works");
#########################
$d1 = $image->get_description();
$d2 = $image2->get_description();
$d1 =~ s/(.*REFERENCE.*-->).*/$1/g; $d1 =~ s/Original .*//g;
$d2 =~ s/(.*REFERENCE.*-->).*/$1/g; $d2 =~ s/Original .*//g;
is( $d1, $d2, "Descriptions after write/read cycle are coincident" );
#########################
$hash = $image->get_Exif_data('IFD1_DATA', 'NUMERIC');
is_deeply( $hash, {}, "... no records found in IFD1" );
#########################
$hash = $image->get_Exif_data('INTEROP_DATA', 'NUMERIC');
is_deeply( $hash, {}, "... no records found in INTEROP" );
#########################
$hash = $image->get_Exif_data('GPS_DATA', 'NUMERIC');
is_deeply( $hash, {}, "... no records found in GPS" );
#########################
$hash = $image->set_Exif_data({'MakerNote' => "\023b-_"}, 'IMAGE_DATA', 'ADD');
ok( exists $$hash{&$val('MakerNote')}, "The MakerNote cannot be changed" );
#########################
$hash = $image->set_Exif_data({'Orientation' => 11}, 'IMAGE_DATA', 'ADD');
ok( exists $$hash{&$val('Orientation')}, "Invalid Orientation rejected" );
#########################
$hash = $image->set_Exif_data({'SceneType' => 4}, 'IMAGE_DATA', 'ADD');
ok( exists $$hash{&$val('SceneType')}, "Invalid SceneType rejected" );
#########################
$hash = $image->set_Exif_data({9999 => 2}, 'IMAGE_DATA', 'ADD');
ok( exists $$hash{9999}, "unknown numeric tags are rejected" );
#########################
$hash = $image->set_Exif_data({'Pippero' => 2}, 'IMAGE_DATA', 'ADD');
ok( exists $$hash{'Pippero'}, "unknown textual tags are rejected" );
#########################
$dt = '1999:05:05 12:00:00';
$hash = $image->set_Exif_data({'DateTime' => $dt}, 'IMAGE_DATA', 'ADD');
ok( ! exists $$hash{&$val('DateTime')}, "Standard date/time accepted" );
#########################
$hash = $image->get_Exif_data('IMAGE_DATA', 'TEXTUAL');
ok( exists $$hash{'DateTime'}, "... gotten back via get_Exif_data" );
#########################
is_deeply( $$hash{'DateTime'}, [$dt."\000"], "... and its value is correct" );
#########################
$hash = $image->set_Exif_data({'Identifier' => "Exif\000\000",
'ThumbnailData' => 'dfdfdf',
'Endianness' => 'MM',
'Signature' => 42 }, 'ROOT_DATA', 'ADD');
is( scalar keys %$hash, 3, "3 properties out of 4 rejected with ROOT_DATA" );
#########################
is_deeply([sort keys %$hash],[sort ('Identifier','ThumbnailData','Signature')],
"... only 'Endianness' was accepted" );
#########################
$hash = $image->set_Exif_data({'Endianness' => 'ZX'}, 'ROOT_DATA', 'ADD');
is( scalar keys %$hash, 1, "Malformed endianness rejected" );
#########################
$hash = $image->set_Exif_data({'Endianness' => 'II'}, 'ROOT_DATA', 'ADD');
is( scalar keys %$hash, 0, "... but legal endianness accepted" );
#########################
$d1 = $image->get_description();
like( $d1, qr/Endianness[^\n]*'II'/, "... tag read with get_description" );
#########################
$hash = $image->set_Exif_data({'Endianness' => 'II'}, 'ROOT_DATA', 'ADD');
$image->save($ref);
$d1 = newimage($ref, '^APP1$', 'FASTREADONLY')->get_description();
$hash = $image->set_Exif_data({'Endianness' => 'MM'}, 'ROOT_DATA', 'ADD');
$image->save($ref);
$d2 = newimage($ref, '^APP1$', 'FASTREADONLY')->get_description();
$d1 =~ s/(.*REFERENCE.*-->).*/$1/g; $d1 =~ s/Original .*//g;
$d2 =~ s/(.*REFERENCE.*-->).*/$1/g; $d2 =~ s/Original .*//g;
like( $d1, qr/Endianness[^\n]*'II'/, "Little-endianness correctly saved" );
like( $d2, qr/Endianness[^\n]*'MM'/, "... also big-endianness" );
#########################
unlike( $d2, qr/Endianness[^\n]*'II'/, "... incorrect match fails (II)" );
unlike( $d1, qr/Endianness[^\n]*'MM'/, "... incorrect match fails (MM)" );
#########################
$d1 =~ s/(.*Endianness.*UNDEF.).*/$1 REPLACED/g;
$d2 =~ s/(.*Endianness.*UNDEF.).*/$1 REPLACED/g;
is( $d1, $d2, "... descriptions are otherwise equivalent" );
### Local Variables: ***
### mode:perl ***
### End: ***
|