File: JPEG_5_exif_SubIFD.t

package info (click to toggle)
libimage-metadata-jpeg-perl 0.159-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,236 kB
  • sloc: perl: 3,676; makefile: 2
file content (287 lines) | stat: -rw-r--r-- 11,846 bytes parent folder | download | duplicates (3)
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
287
use Test::More tests => 52;
BEGIN { require 't/test_setup.pl'; }

my $tphoto = 't/test_photo.jpg';
my $tdata  = 't/test_photo.desc';
my ($image, $image2, $seg, $hash, $d1, $d2, $dt, $data, $ref);
my $uc = sub { my $s = "\376\377";
	       $s .= "\000$_" for split(/ */,$_[0]);
	       $s .= "\000\000"; };
my $val = sub { return JPEG_lookup('APP1@IFD0@SubIFD', $_[0]) };

my $SubIFD_data = {
    &$val('ExposureTime')             => [12, 55],
    &$val('ExposureProgram')          => [7],
    &$val('SpectralSensitivity')      =>  'a lot',
    &$val('ISOSpeedRatings')          => [1, 2, 3, 4],
    'ExifVersion'                     => '0220',
    'DateTimeOriginal'                => ['1996:07:12 14:36:55'],
    'CompressedBitsPerPixel'          => [79, 64],
    'MeteringMode'                    =>  6,
    &$val('LightSource')              =>  17,
    &$val('Flash')                    => [79],
    &$val('SubjectArea')              => [10, 20, 30],
    &$val('UserComment')              => ["Unicode\000asdfgh"],
    'SubSecTime'                      =>  "133     \000",
    'FlashpixVersion'                 => ['0100'],
    'ColorSpace'                      =>  65535,
    'PixelXDimension'                 => [222],
    &$val('RelatedSoundFile')         => ['ALB12_a5.DXf'],
    &$val('FocalPlaneResolutionUnit') =>  3,
    &$val('SubjectLocation')          => [13, 19],
    &$val('SensingMethod')            =>  '7',
    'FileSource'                      => [ "\003" ],
    'SceneType'                       =>  "\001",
    'CFAPattern'                      =>  "\000\003\000\003342623342",
    'ExposureMode'                    => [ 2 ],
    &$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',
};

#=======================================
diag "Testing APP1 Exif data routines (SUBIFD_DATA)";
#=======================================

BEGIN { use_ok ($::tabname, qw(:Lookups)) or exit; }
BEGIN { use_ok ($::pkgname) or exit; } # this must be loaded second!

#########################
$image = newimage($tphoto, '^APP1$');
$seg   = $image->retrieve_app1_Exif_segment(0);
isnt( $seg, undef, "The Exif segment is there, hi!" );

#########################
$hash = $seg->set_Exif_data($SubIFD_data, 'SubIFD_DATA', 'REPLACE');
ok( exists $$hash{'ERROR'}, $$hash{'ERROR'} );

#########################
$hash = $seg->set_Exif_data($SubIFD_data, 'SUBIFD_DATA', 'RUN');
ok( exists $$hash{'ERROR'}, $$hash{'ERROR'} );

#########################
$hash = $seg->set_Exif_data($SubIFD_data, 'SUBIFD_DATA', 'ADD');
is_deeply( $hash, {}, "all test SubIFD records ADDed" );

#########################
$hash = $seg->get_Exif_data('SUBIFD_DATA', 'TEXTUAL');
is_deeply( $$hash{'Flash'}, $$SubIFD_data{&$val('Flash')},"numeric keys work");

#########################
$hash = $seg->get_Exif_data('SUBIFD_DATA', 'TEXTUAL');
is_deeply( $$hash{'DateTimeOriginal'}, $$SubIFD_data{'DateTimeOriginal'},
	   "textual keys too" );

#########################
$hash = $seg->set_Exif_data($SubIFD_data, 'SUBIFD_DATA', 'REPLACE');
is_deeply( $hash, {}, "also REPLACing works" );

#########################
$hash = $seg->set_Exif_data({}, 'SUBIFD_DATA', 'REPLACE');
$hash = $seg->get_Exif_data('SUBIFD_DATA', 'TEXTUAL');
is_deeply( $$hash{'ExifVersion'}, ['0220'], "Automatic ExifVersion works" );

#########################
is_deeply( $$hash{'ComponentsConfiguration'}, ["\001\002\003\000"],
	   "Automatic ComponentsConfiguration works" );

#########################
is_deeply( $$hash{'FlashpixVersion'}, ['0100'],
	   "Automatic FlashpixVersion works" );

#########################
is_deeply( $$hash{'ColorSpace'}, [1], "Automatic ColorSpace works" );

#########################
# Remember that if you want to test with get_dimensions()
# you have to parse also the SOF segment.
is_deeply( [${$$hash{'PixelXDimension'}}[0],
	    ${$$hash{'PixelYDimension'}}[0]],
	   [0, 0], "Meaningful dimensions set to 0x0" );

#########################
$seg->set_Exif_data({'ExifVersion' => ['0210']}, 'SUBIFD_DATA', 'ADD');
$hash = $seg->get_Exif_data('SUBIFD_DATA', 'TEXTUAL');
is_deeply( $$hash{'ExifVersion'}, ['0210'], "Manual ExifVersion works" );

#########################
$hash = $image->set_Exif_data($SubIFD_data, 'SUBIFD_DATA', 'ADD');
is_deeply( $hash, {}, "adding through image object" );

#########################
$image->remove_app1_Exif_info(-1);
$hash = $image->set_Exif_data($SubIFD_data, 'SUBIFD_DATA', 'ADD');
is_deeply( $hash, {}, "adding without the SubIFD dir" );

#########################
$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->set_Exif_data({'MakerNote'=>"\023b-_"}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('MakerNote')}, "The MakerNote cannot be changed" );

#########################
$hash = $image->set_Exif_data({'FNumber' => [3, -1]}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('FNumber')}, "Invalid rational rejected" );

#########################
$hash = $image->set_Exif_data({'ColorSpace' => 9}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('ColorSpace')}, "Out-of-bound short rejected");

#########################
$hash = $image->set_Exif_data({'ColorSpace' => 'xxx'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('ColorSpace')}, "Invalid short (a string) rejected");

#########################
$hash = $image->set_Exif_data({'ExifVersion' => '9999'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('ExifVersion')}, "Invalid Exif version rejected" );

#########################
$dt = '1994:23:23 12:14:61';
$hash = $image->set_Exif_data({'DateTimeOriginal'=>$dt}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('DateTimeOriginal')}, "Invalid date/time rejected" );

#########################
$dt = '1994:06:07 12:14:31';
$hash = $image->set_Exif_data({'DateTimeDigitized'=>$dt,
			       'DateTimeOriginal'=>$dt}, 'SUBIFD_DATA', 'ADD');
is( scalar keys %$hash, 0, "Dates in the 20th century accepted" );

#########################
$dt = '1823:06:07 12:14:31';
$hash = $image->set_Exif_data({'DateTimeDigitized'=>$dt,
			       'DateTimeOriginal'=>$dt}, 'SUBIFD_DATA', 'ADD');
is( scalar keys %$hash, 0, "Dates in the 19th century accepted" );

#########################
$dt = '1756:06:07 12:14:31';
$hash = $image->set_Exif_data({'DateTimeDigitized'=>$dt,
			       'DateTimeOriginal'=>$dt}, 'SUBIFD_DATA', 'ADD');
is( scalar keys %$hash, 2, "Dates in the 18th century rejected" );

#########################
$dt = '1994:23:23 12:14:61';
$hash = $image->set_Exif_data({'DateTimeOriginal'=>$dt}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('DateTimeOriginal')}, "Invalid date/time rejected" );

#########################
$dt = '    :  :     :  :  ';
$hash = $image->set_Exif_data({'DateTimeOriginal'=>$dt}, 'SUBIFD_DATA', 'ADD');
ok( ! exists $$hash{&$val('DateTimeOriginal')}, "Blank date/time accepted(1)");

#########################
$dt = ' ' x 19;
$hash = $image->set_Exif_data({'DateTimeOriginal'=>$dt}, 'SUBIFD_DATA', 'ADD');
ok( ! exists $$hash{&$val('DateTimeOriginal')}, "Blank date/time accepted(2)");

#########################
$hash = $image->set_Exif_data
    ({'ComponentsConfiguration' => "\004\006\005\000"}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('ComponentsConfiguration')}, "Invalid CCfg rejected" );

#########################
$hash = $image->set_Exif_data
    ({'ComponentsConfiguration' => '1230'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('ComponentsConfiguration')}, "'Char' CCfg rejected" );

#########################
$hash = $image->set_Exif_data({'FileSource' => '3'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('FileSource')}, "'Char' FileSource rejected" );

#########################
$hash = $image->set_Exif_data({'FileSource' => 3}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('FileSource')}, "Numeric FileSource rejected" );

#########################
$hash = $image->set_Exif_data({'SceneType' => '1'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('SceneType')}, "'Char' SceneType rejected" );

#########################
$hash = $image->set_Exif_data({'SceneType' => 1}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('SceneType')}, "Numeric SceneType rejected" );

#########################
$hash = $image->set_Exif_data({'BrightnessValue'=>[-4]}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('BrightnessValue')}, "Invalid s-rational rejected" );

#########################
$hash = $image->set_Exif_data({'LightSource' => 16}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('LightSource')}, "Out-of-bound LightSource rejected" );

#########################
$hash = $image->set_Exif_data({'Flash' => 26}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('Flash')}, "Out-of-bound Flash rejected" );

#########################
$hash = $image->set_Exif_data({'SubjectArea' => 26}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('SubjectArea')}, "Invalid SubjectArea rejected" );

#########################
$hash = $image->set_Exif_data({'UserComment' => 'zzz'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('UserComment')},"Plain string invalid as UserComment");

#########################
$hash = $image->set_Exif_data({'SubSecTime' => '130ms'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('SubSecTime')}, "Letters not accepted in SubSecTime" );

#########################
$data = 'FILE.DAT';
$hash = $image->set_Exif_data({'RelatedSoundFile'=>$data},'SUBIFD_DATA','ADD');
ok( exists $$hash{&$val('RelatedSoundFile')},
    "Non-conforming RelatedSoundFile rejected" );

#########################
$hash = $image->set_Exif_data({'InteroperabilityOffset' => 'calculated'},
			      'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('InteroperabilityOffset')}, "Offsets are invalid" );

#########################
$data = "\000\003\000\003203046715"; # 7 is invalid
$hash = $image->set_Exif_data({'CFAPattern' => $data}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('CFAPattern')}, "Invalid CFAPattern rejected (1)" );

#########################
$data = "\000\003\000\00220304"; # wrong size
$hash = $image->set_Exif_data({'CFAPattern' => $data}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('CFAPattern')}, "Invalid CFAPattern rejected (2)" );

#########################
$data = 'xxxxdummy';
$hash = $image->set_Exif_data({'DeviceSettingDescription' => $data},
			      'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('DeviceSettingDescription')}, 
    "Non UCS-2 in DeviceSettingDescription rejected" );

#########################
$data = ('f' x 30) . '-' . ('a' x 3);
$hash = $image->set_Exif_data({'ImageUniqueID'=>$data}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('ImageUniqueID')}, "Invalid ImageUniqueID rejected" );

#########################
$hash = $image->set_Exif_data({'_Lens' => '1/16'}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{&$val('_Lens')}, "Invalid Photoshop tag rejected" );

#########################
$hash = $image->set_Exif_data({9999 => 2}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{9999}, "unknown numeric tags are rejected" );

#########################
$hash = $image->set_Exif_data({'Pippero' => 2}, 'SUBIFD_DATA', 'ADD');
ok( exists $$hash{'Pippero'}, "unknown textual tags are rejected" );

### Local Variables: ***
### mode:perl ***
### End: ***