c4d85a4a104f4c61e8214ce37ebf957d106bcea9
[yaffs-website] / test / image-tests / NikonE950Test.php
1 <?php
2
3 /*
4  * PEL: PHP Exif Library. A library with support for reading and
5  * writing all Exif headers in JPEG and TIFF images using PHP.
6  *
7  * Copyright (C) 2005, 2006 Martin Geisler.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program in the file COPYING; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22  * Boston, MA 02110-1301 USA
23  */
24
25 use lsolesen\pel\Pel;
26 use lsolesen\pel\PelJpeg;
27
28 class NikonE950Test extends \PHPUnit_Framework_TestCase
29 {
30     public function testRead()
31     {
32         Pel::clearExceptions();
33         Pel::setStrictParsing(false);
34         $jpeg = new PelJpeg(dirname(__FILE__) . '/nikon-e950.jpg');
35
36         $exif = $jpeg->getExif();
37         $this->assertInstanceOf('lsolesen\pel\PelExif', $exif);
38
39         $tiff = $exif->getTiff();
40         $this->assertInstanceOf('lsolesen\pel\PelTiff', $tiff);
41
42         /* The first IFD. */
43         $ifd0 = $tiff->getIfd();
44         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0);
45
46         /* Start of IDF $ifd0. */
47         $this->assertEquals(count($ifd0->getEntries()), 10);
48
49         $entry = $ifd0->getEntry(270); // ImageDescription
50         $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
51         $this->assertEquals($entry->getValue(), '          ');
52         $this->assertEquals($entry->getText(), '          ');
53
54         $entry = $ifd0->getEntry(271); // Make
55         $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
56         $this->assertEquals($entry->getValue(), 'NIKON');
57         $this->assertEquals($entry->getText(), 'NIKON');
58
59         $entry = $ifd0->getEntry(272); // Model
60         $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
61         $this->assertEquals($entry->getValue(), 'E950');
62         $this->assertEquals($entry->getText(), 'E950');
63
64         $entry = $ifd0->getEntry(274); // Orientation
65         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
66         $this->assertEquals($entry->getValue(), 1);
67         $this->assertEquals($entry->getText(), 'top - left');
68
69         $entry = $ifd0->getEntry(282); // XResolution
70         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
71         $this->assertEquals($entry->getValue(), array(
72             0 => 300,
73             1 => 1
74         ));
75         $this->assertEquals($entry->getText(), '300/1');
76
77         $entry = $ifd0->getEntry(283); // YResolution
78         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
79         $this->assertEquals($entry->getValue(), array(
80             0 => 300,
81             1 => 1
82         ));
83         $this->assertEquals($entry->getText(), '300/1');
84
85         $entry = $ifd0->getEntry(296); // ResolutionUnit
86         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
87         $this->assertEquals($entry->getValue(), 2);
88         $this->assertEquals($entry->getText(), 'Inch');
89
90         $entry = $ifd0->getEntry(305); // Software
91         $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
92         $this->assertEquals($entry->getValue(), 'v981p-78');
93         $this->assertEquals($entry->getText(), 'v981p-78');
94
95         $entry = $ifd0->getEntry(306); // DateTime
96         $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
97         $this->assertEquals($entry->getValue(), 978276013);
98         $this->assertEquals($entry->getText(), '2000:12:31 15:20:13');
99
100         $entry = $ifd0->getEntry(531); // YCbCrPositioning
101         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
102         $this->assertEquals($entry->getValue(), 2);
103         $this->assertEquals($entry->getText(), 'co-sited');
104
105         /* Sub IFDs of $ifd0. */
106         $this->assertEquals(count($ifd0->getSubIfds()), 1);
107         $ifd0_0 = $ifd0->getSubIfd(2); // IFD Exif
108         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_0);
109
110         /* Start of IDF $ifd0_0. */
111         $this->assertEquals(count($ifd0_0->getEntries()), 23);
112
113         $entry = $ifd0_0->getEntry(33434); // ExposureTime
114         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
115         $this->assertEquals($entry->getValue(), array(
116             0 => 10,
117             1 => 1120
118         ));
119         $this->assertEquals($entry->getText(), '1/112 sec.');
120
121         $entry = $ifd0_0->getEntry(33437); // FNumber
122         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
123         $this->assertEquals($entry->getValue(), array(
124             0 => 60,
125             1 => 10
126         ));
127         $this->assertEquals($entry->getText(), 'f/6.0');
128
129         $entry = $ifd0_0->getEntry(34850); // ExposureProgram
130         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
131         $this->assertEquals($entry->getValue(), 2);
132         $this->assertEquals($entry->getText(), 'Normal program');
133
134         $entry = $ifd0_0->getEntry(34855); // ISOSpeedRatings
135         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
136         $this->assertEquals($entry->getValue(), 80);
137         $this->assertEquals($entry->getText(), '80');
138
139         $entry = $ifd0_0->getEntry(36864); // ExifVersion
140         $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
141         $this->assertEquals($entry->getValue(), 2.1);
142         $this->assertEquals($entry->getText(), 'Exif Version 2.1');
143
144         $entry = $ifd0_0->getEntry(36867); // DateTimeOriginal
145         $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
146         $this->assertEquals($entry->getValue(), 978276013);
147         $this->assertEquals($entry->getText(), '2000:12:31 15:20:13');
148
149         $entry = $ifd0_0->getEntry(36868); // DateTimeDigitized
150         $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
151         $this->assertEquals($entry->getValue(), 978276013);
152         $this->assertEquals($entry->getText(), '2000:12:31 15:20:13');
153
154         $entry = $ifd0_0->getEntry(37121); // ComponentsConfiguration
155         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
156         $this->assertEquals($entry->getValue(), "\x01\x02\x03\0");
157         $this->assertEquals($entry->getText(), 'Y Cb Cr -');
158
159         $entry = $ifd0_0->getEntry(37122); // CompressedBitsPerPixel
160         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
161         $this->assertEquals($entry->getValue(), array(
162             0 => 4,
163             1 => 1
164         ));
165         $this->assertEquals($entry->getText(), '4/1');
166
167         $entry = $ifd0_0->getEntry(37380); // ExposureBiasValue
168         $this->assertInstanceOf('lsolesen\pel\PelEntrySRational', $entry);
169         $this->assertEquals($entry->getValue(), array(
170             0 => 0,
171             1 => 10
172         ));
173         $this->assertEquals($entry->getText(), '0.0');
174
175         $entry = $ifd0_0->getEntry(37381); // MaxApertureValue
176         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
177         $this->assertEquals($entry->getValue(), array(
178             0 => 26,
179             1 => 10
180         ));
181         $this->assertEquals($entry->getText(), '26/10');
182
183         $entry = $ifd0_0->getEntry(37383); // MeteringMode
184         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
185         $this->assertEquals($entry->getValue(), 5);
186         $this->assertEquals($entry->getText(), 'Pattern');
187
188         $entry = $ifd0_0->getEntry(37384); // LightSource
189         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
190         $this->assertEquals($entry->getValue(), 0);
191         $this->assertEquals($entry->getText(), 'Unknown');
192
193         $entry = $ifd0_0->getEntry(37385); // Flash
194         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
195         $this->assertEquals($entry->getValue(), 0);
196         $this->assertEquals($entry->getText(), 'Flash did not fire.');
197
198         $entry = $ifd0_0->getEntry(37386); // FocalLength
199         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
200         $this->assertEquals($entry->getValue(), array(
201             0 => 158,
202             1 => 10
203         ));
204         $this->assertEquals($entry->getText(), '15.8 mm');
205
206         $entry = $ifd0_0->getEntry(37500); // MakerNote
207         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
208         $expected = "\x4e\x69\x6b\x6f\x6e\0\x01\0\x0b\0\x02\0\x02\0\x06\0\0\0\x26\x04\0\0\x03\0\x03\0\x01\0\0\0\x0c\0\0\0\x04\0\x03\0\x01\0\0\0\x01\0\0\0\x05\0\x03\0\x01\0\0\0\0\0\0\0\x06\0\x03\0\x01\0\0\0\0\0\0\0\x07\0\x03\0\x01\0\0\0\0\0\0\0\x08\0\x05\0\x01\0\0\0\x2c\x04\0\0\x09\0\x02\0\x14\0\0\0\x34\x04\0\0\x0a\0\x05\0\x01\0\0\0\x48\x04\0\0\x0b\0\x03\0\x01\0\0\0\0\0\0\0\0\x0f\x04\0\x1e\0\0\0\x50\x04\0\0\0\0\0\0\x30\x38\x2e\x30\x30\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x64\0\0\0\x01\x3e\0\x80\x01\x58\0\0\0\0\xff\x01\0\0\0\0\x0c\xe5\x10\x8c\0\0\0\0\x0a\x5b\0\0\x18\x6a\0\0\x23\x04\0\0\x11\x16\0\0\x11\x16\0\0\x1f\x05\x0c\x9f\0\x2f\0\0\0\0\x01\xcb\x02\x27\x02\x7b\x02\xd8\x03\x6a\x08\x5c\0\0\0\0\x10\x0e\x15\0\0\x01\x60\0\0\x30\0\0\0\x10\0\0\x5b\x18\x02\0\x48\x04\x16\x68\0\x0b\x58\x29\0\x3f\0\0\x15\x19\x15\x1a\x0f\xe1\x42\0\xff\0\x4f\x5d\x32\x0c\xa1\x02\0\0";
209         $this->assertEquals($entry->getValue(), $expected);
210         $this->assertEquals($entry->getText(), '308 bytes unknown MakerNote data');
211
212         $entry = $ifd0_0->getEntry(37510); // UserComment
213         $this->assertInstanceOf('lsolesen\pel\PelEntryUserComment', $entry);
214         $this->assertEquals($entry->getValue(), '                                                                                                                     ');
215         $this->assertEquals($entry->getText(), '                                                                                                                     ');
216
217         $entry = $ifd0_0->getEntry(40960); // FlashPixVersion
218         $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
219         $this->assertEquals($entry->getValue(), 1);
220         $this->assertEquals($entry->getText(), 'FlashPix Version 1.0');
221
222         $entry = $ifd0_0->getEntry(40961); // ColorSpace
223         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
224         $this->assertEquals($entry->getValue(), 1);
225         $this->assertEquals($entry->getText(), 'sRGB');
226
227         $entry = $ifd0_0->getEntry(40962); // PixelXDimension
228         $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
229         $this->assertEquals($entry->getValue(), 1600);
230         $this->assertEquals($entry->getText(), '1600');
231
232         $entry = $ifd0_0->getEntry(40963); // PixelYDimension
233         $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
234         $this->assertEquals($entry->getValue(), 1200);
235         $this->assertEquals($entry->getText(), '1200');
236
237         $entry = $ifd0_0->getEntry(41728); // FileSource
238         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
239         $this->assertEquals($entry->getValue(), "\x03");
240         $this->assertEquals($entry->getText(), 'DSC');
241
242         $entry = $ifd0_0->getEntry(41729); // SceneType
243         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
244         $this->assertEquals($entry->getValue(), "\x01");
245         $this->assertEquals($entry->getText(), 'Directly photographed');
246
247         /* Sub IFDs of $ifd0_0. */
248         $this->assertEquals(count($ifd0_0->getSubIfds()), 1);
249         $ifd0_0_0 = $ifd0_0->getSubIfd(4); // IFD Interoperability
250         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_0_0);
251
252         /* Start of IDF $ifd0_0_0. */
253         $this->assertEquals(count($ifd0_0_0->getEntries()), 2);
254
255         $entry = $ifd0_0_0->getEntry(1); // InteroperabilityIndex
256         $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
257         $this->assertEquals($entry->getValue(), 'R98');
258         $this->assertEquals($entry->getText(), 'R98');
259
260         $entry = $ifd0_0_0->getEntry(2); // InteroperabilityVersion
261         $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
262         $this->assertEquals($entry->getValue(), 1);
263         $this->assertEquals($entry->getText(), 'Interoperability Version 1.0');
264
265         /* Sub IFDs of $ifd0_0_0. */
266         $this->assertEquals(count($ifd0_0_0->getSubIfds()), 0);
267
268         $this->assertEquals($ifd0_0_0->getThumbnailData(), '');
269
270         /* Next IFD. */
271         $ifd0_0_1 = $ifd0_0_0->getNextIfd();
272         $this->assertNull($ifd0_0_1);
273         /* End of IFD $ifd0_0_0. */
274
275         $this->assertEquals($ifd0_0->getThumbnailData(), '');
276
277         /* Next IFD. */
278         $ifd0_1 = $ifd0_0->getNextIfd();
279         $this->assertNull($ifd0_1);
280         /* End of IFD $ifd0_0. */
281
282         $this->assertEquals($ifd0->getThumbnailData(), '');
283
284         /* Next IFD. */
285         $ifd1 = $ifd0->getNextIfd();
286         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd1);
287         /* End of IFD $ifd0. */
288
289         /* Start of IDF $ifd1. */
290         $this->assertEquals(count($ifd1->getEntries()), 4);
291
292         $entry = $ifd1->getEntry(259); // Compression
293         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
294         $this->assertEquals($entry->getValue(), 6);
295         $this->assertEquals($entry->getText(), 'JPEG compression');
296
297         $entry = $ifd1->getEntry(282); // XResolution
298         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
299         $this->assertEquals($entry->getValue(), array(
300             0 => 300,
301             1 => 1
302         ));
303         $this->assertEquals($entry->getText(), '300/1');
304
305         $entry = $ifd1->getEntry(283); // YResolution
306         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
307         $this->assertEquals($entry->getValue(), array(
308             0 => 300,
309             1 => 1
310         ));
311         $this->assertEquals($entry->getText(), '300/1');
312
313         $entry = $ifd1->getEntry(296); // ResolutionUnit
314         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
315         $this->assertEquals($entry->getValue(), 2);
316         $this->assertEquals($entry->getText(), 'Inch');
317
318         /* Sub IFDs of $ifd1. */
319         $this->assertEquals(count($ifd1->getSubIfds()), 0);
320
321         $thumb_data = file_get_contents(dirname(__FILE__) . '/nikon-e950-thumb.jpg');
322         $this->assertEquals($ifd1->getThumbnailData(), $thumb_data);
323
324         /* Next IFD. */
325         $ifd2 = $ifd1->getNextIfd();
326         $this->assertNull($ifd2);
327         /* End of IFD $ifd1. */
328
329         $this->assertTrue(count(Pel::getExceptions()) == 0);
330     }
331 }