ec681142586b4c4a827495f36cde9cf29066483b
[yaffs-website] / test / image-tests / NikonE5000Test.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 NikonE5000Test extends \PHPUnit_Framework_TestCase
29 {
30     public function testRead()
31     {
32         Pel::clearExceptions();
33         Pel::setStrictParsing(false);
34         $jpeg = new PelJpeg(dirname(__FILE__) . '/nikon-e5000.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()), 9);
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(), 'E5000');
62         $this->assertEquals($entry->getText(), 'E5000');
63
64         $entry = $ifd0->getEntry(282); // XResolution
65         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
66         $this->assertEquals($entry->getValue(), array(
67             0 => 300,
68             1 => 1
69         ));
70         $this->assertEquals($entry->getText(), '300/1');
71
72         $entry = $ifd0->getEntry(283); // YResolution
73         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
74         $this->assertEquals($entry->getValue(), array(
75             0 => 300,
76             1 => 1
77         ));
78         $this->assertEquals($entry->getText(), '300/1');
79
80         $entry = $ifd0->getEntry(296); // ResolutionUnit
81         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
82         $this->assertEquals($entry->getValue(), 2);
83         $this->assertEquals($entry->getText(), 'Inch');
84
85         $entry = $ifd0->getEntry(305); // Software
86         $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
87         $this->assertEquals($entry->getValue(), 'E5000v1.6');
88         $this->assertEquals($entry->getText(), 'E5000v1.6');
89
90         $entry = $ifd0->getEntry(306); // DateTime
91         $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
92         $this->assertEquals($entry->getValue(), 1021992832);
93         $this->assertEquals($entry->getText(), '2002:05:21 14:53:52');
94
95         $entry = $ifd0->getEntry(531); // YCbCrPositioning
96         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
97         $this->assertEquals($entry->getValue(), 1);
98         $this->assertEquals($entry->getText(), 'centered');
99
100         /* Sub IFDs of $ifd0. */
101         $this->assertEquals(count($ifd0->getSubIfds()), 2);
102         $ifd0_0 = $ifd0->getSubIfd(2); // IFD Exif
103         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_0);
104
105         /* Start of IDF $ifd0_0. */
106         $this->assertEquals(count($ifd0_0->getEntries()), 22);
107
108         $entry = $ifd0_0->getEntry(33434); // ExposureTime
109         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
110         $this->assertEquals($entry->getValue(), array(
111             0 => 1642036,
112             1 => 100000000
113         ));
114         $this->assertEquals($entry->getText(), '1/60 sec.');
115
116         $entry = $ifd0_0->getEntry(33437); // FNumber
117         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
118         $this->assertEquals($entry->getValue(), array(
119             0 => 28,
120             1 => 10
121         ));
122         $this->assertEquals($entry->getText(), 'f/2.8');
123
124         $entry = $ifd0_0->getEntry(34850); // ExposureProgram
125         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
126         $this->assertEquals($entry->getValue(), 2);
127         $this->assertEquals($entry->getText(), 'Normal program');
128
129         $entry = $ifd0_0->getEntry(34855); // ISOSpeedRatings
130         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
131         $this->assertEquals($entry->getValue(), 100);
132         $this->assertEquals($entry->getText(), '100');
133
134         $entry = $ifd0_0->getEntry(36864); // ExifVersion
135         $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
136         $this->assertEquals($entry->getValue(), 2.1);
137         $this->assertEquals($entry->getText(), 'Exif Version 2.1');
138
139         $entry = $ifd0_0->getEntry(36867); // DateTimeOriginal
140         $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
141         $this->assertEquals($entry->getValue(), 1021992832);
142         $this->assertEquals($entry->getText(), '2002:05:21 14:53:52');
143
144         $entry = $ifd0_0->getEntry(36868); // DateTimeDigitized
145         $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
146         $this->assertEquals($entry->getValue(), 1021992832);
147         $this->assertEquals($entry->getText(), '2002:05:21 14:53:52');
148
149         $entry = $ifd0_0->getEntry(37121); // ComponentsConfiguration
150         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
151         $this->assertEquals($entry->getValue(), "\x01\x02\x03\0");
152         $this->assertEquals($entry->getText(), 'Y Cb Cr -');
153
154         $entry = $ifd0_0->getEntry(37380); // ExposureBiasValue
155         $this->assertInstanceOf('lsolesen\pel\PelEntrySRational', $entry);
156         $this->assertEquals($entry->getValue(), array(
157             0 => 0,
158             1 => 10
159         ));
160         $this->assertEquals($entry->getText(), '0.0');
161
162         $entry = $ifd0_0->getEntry(37381); // MaxApertureValue
163         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
164         $this->assertEquals($entry->getValue(), array(
165             0 => 3,
166             1 => 1
167         ));
168         $this->assertEquals($entry->getText(), '3/1');
169
170         $entry = $ifd0_0->getEntry(37383); // MeteringMode
171         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
172         $this->assertEquals($entry->getValue(), 5);
173         $this->assertEquals($entry->getText(), 'Pattern');
174
175         $entry = $ifd0_0->getEntry(37384); // LightSource
176         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
177         $this->assertEquals($entry->getValue(), 0);
178         $this->assertEquals($entry->getText(), 'Unknown');
179
180         $entry = $ifd0_0->getEntry(37385); // Flash
181         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
182         $this->assertEquals($entry->getValue(), 0);
183         $this->assertEquals($entry->getText(), 'Flash did not fire.');
184
185         $entry = $ifd0_0->getEntry(37386); // FocalLength
186         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
187         $this->assertEquals($entry->getValue(), array(
188             0 => 71,
189             1 => 10
190         ));
191         $this->assertEquals($entry->getText(), '7.1 mm');
192
193         $entry = $ifd0_0->getEntry(37500); // MakerNote
194         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
195         $expected = "\x15\0\x01\0\x07\0\x04\0\0\0\0\x01\0\0\x02\0\x03\0\x02\0\0\0\0\0\0\0\x03\0\x02\0\x06\0\0\0\xbc\x03\0\0\x04\0\x02\0\x08\0\0\0\xc2\x03\0\0\x05\0\x02\0\x0d\0\0\0\xca\x03\0\0\x06\0\x02\0\x07\0\0\0\xd8\x03\0\0\x07\0\x02\0\x07\0\0\0\xe0\x03\0\0\x08\0\x02\0\x0d\0\0\0\xe8\x03\0\0\x0a\0\x05\0\x01\0\0\0\xf6\x03\0\0\x0f\0\x02\0\x07\0\0\0\xfe\x03\0\0\x11\0\x04\0\x01\0\0\0\x14\x05\0\0\x80\0\x02\0\x0e\0\0\0\x06\x04\0\0\x82\0\x02\0\x0d\0\0\0\x14\x04\0\0\x85\0\x05\0\x01\0\0\0\x22\x04\0\0\x86\0\x05\0\x01\0\0\0\x2a\x04\0\0\x88\0\x07\0\x04\0\0\0\0\0\0\0\x8f\0\x02\0\x11\0\0\0\x32\x04\0\0\x94\0\x08\0\x01\0\0\0\0\0\0\0\x95\0\x02\0\x05\0\0\0\x44\x04\0\0\0\x0e\x07\0\xca\0\0\0\x4a\x04\0\0\x10\x0e\x04\0\x01\0\0\0\x72\x05\0\0\0\0\0\0\x43\x4f\x4c\x4f\x52\0\x46\x49\x4e\x45\x20\x20\x20\0\x41\x55\x54\x4f\x20\x20\x20\x20\x20\x20\x20\x20\0\x31\x41\x55\x54\x4f\x20\x20\0\0\x41\x46\x2d\x43\x20\x20\0\x3a\x4e\x4f\x52\x4d\x41\x4c\x20\x20\x20\x20\x20\x20\0\0\x80\x22\0\0\xe8\x03\0\0\x41\x55\x54\x4f\x20\x20\0\0\x41\x55\x54\x4f\x20\x20\x20\x20\x20\x20\x20\x20\x20\0\x4f\x46\x46\x20\x20\x20\x20\x20\x20\x20\x20\x20\0\x20\0\0\0\0\0\0\0\0\x01\0\0\0\x01\0\0\0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\0\x20\x4f\x46\x46\x20\0\x20\x50\x72\x69\x6e\x74\x49\x4d\0\x30\x31\x30\x30\0\0\x0d\0\x01\0\x16\0\x16\0\x02\0\x01\0\0\0\x03\0\x5e\0\0\0\x07\0\0\0\0\0\x08\0\0\0\0\0\x09\0\0\0\0\0\x0a\0\0\0\0\0\x0b\0\xa6\0\0\0\x0c\0\0\0\0\0\x0d\0\0\0\0\0\x0e\0\xbe\0\0\0\0\x01\x05\0\0\0\x01\x01\x01\0\0\0\x09\x11\0\0\x10\x27\0\0\x0b\x0f\0\0\x10\x27\0\0\x97\x05\0\0\x10\x27\0\0\xb0\x08\0\0\x10\x27\0\0\x01\x1c\0\0\x10\x27\0\0\x5e\x02\0\0\x10\x27\0\0\x8b\0\0\0\x10\x27\0\0\xcb\x03\0\0\x10\x27\0\0\xe5\x1b\0\0\x10\x27\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\0\0\0\0\0\x06\0";
196         $this->assertEquals($entry->getValue(), $expected);
197         $this->assertEquals($entry->getText(), '604 bytes unknown MakerNote data');
198
199         $entry = $ifd0_0->getEntry(37510); // UserComment
200         $this->assertInstanceOf('lsolesen\pel\PelEntryUserComment', $entry);
201         $this->assertEquals($entry->getValue(), '                                                                                                                     ');
202         $this->assertEquals($entry->getText(), '                                                                                                                     ');
203
204         $entry = $ifd0_0->getEntry(40960); // FlashPixVersion
205         $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
206         $this->assertEquals($entry->getValue(), 1);
207         $this->assertEquals($entry->getText(), 'FlashPix Version 1.0');
208
209         $entry = $ifd0_0->getEntry(40961); // ColorSpace
210         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
211         $this->assertEquals($entry->getValue(), 1);
212         $this->assertEquals($entry->getText(), 'sRGB');
213
214         $entry = $ifd0_0->getEntry(40962); // PixelXDimension
215         $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
216         $this->assertEquals($entry->getValue(), 1600);
217         $this->assertEquals($entry->getText(), '1600');
218
219         $entry = $ifd0_0->getEntry(40963); // PixelYDimension
220         $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
221         $this->assertEquals($entry->getValue(), 1200);
222         $this->assertEquals($entry->getText(), '1200');
223
224         $entry = $ifd0_0->getEntry(41728); // FileSource
225         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
226         $this->assertEquals($entry->getValue(), "\x03");
227         $this->assertEquals($entry->getText(), 'DSC');
228
229         $entry = $ifd0_0->getEntry(41729); // SceneType
230         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
231         $this->assertEquals($entry->getValue(), "\x01");
232         $this->assertEquals($entry->getText(), 'Directly photographed');
233
234         /* Sub IFDs of $ifd0_0. */
235         $this->assertEquals(count($ifd0_0->getSubIfds()), 0);
236
237         $this->assertEquals($ifd0_0->getThumbnailData(), '');
238
239         /* Next IFD. */
240         $ifd0_1 = $ifd0_0->getNextIfd();
241         $this->assertNull($ifd0_1);
242         /* End of IFD $ifd0_0. */
243         $ifd0_1 = $ifd0->getSubIfd(3); // IFD GPS
244         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_1);
245
246         /* Start of IDF $ifd0_1. */
247         $this->assertEquals(count($ifd0_1->getEntries()), 0);
248
249         /* Sub IFDs of $ifd0_1. */
250         $this->assertEquals(count($ifd0_1->getSubIfds()), 0);
251
252         $this->assertEquals($ifd0_1->getThumbnailData(), '');
253
254         /* Next IFD. */
255         $ifd0_2 = $ifd0_1->getNextIfd();
256         $this->assertNull($ifd0_2);
257         /* End of IFD $ifd0_1. */
258
259         $this->assertEquals($ifd0->getThumbnailData(), '');
260
261         /* Next IFD. */
262         $ifd1 = $ifd0->getNextIfd();
263         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd1);
264         /* End of IFD $ifd0. */
265
266         /* Start of IDF $ifd1. */
267         $this->assertEquals(count($ifd1->getEntries()), 4);
268
269         $entry = $ifd1->getEntry(259); // Compression
270         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
271         $this->assertEquals($entry->getValue(), 6);
272         $this->assertEquals($entry->getText(), 'JPEG compression');
273
274         $entry = $ifd1->getEntry(282); // XResolution
275         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
276         $this->assertEquals($entry->getValue(), array(
277             0 => 72,
278             1 => 1
279         ));
280         $this->assertEquals($entry->getText(), '72/1');
281
282         $entry = $ifd1->getEntry(283); // YResolution
283         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
284         $this->assertEquals($entry->getValue(), array(
285             0 => 72,
286             1 => 1
287         ));
288         $this->assertEquals($entry->getText(), '72/1');
289
290         $entry = $ifd1->getEntry(296); // ResolutionUnit
291         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
292         $this->assertEquals($entry->getValue(), 2);
293         $this->assertEquals($entry->getText(), 'Inch');
294
295         /* Sub IFDs of $ifd1. */
296         $this->assertEquals(count($ifd1->getSubIfds()), 0);
297
298         $thumb_data = file_get_contents(dirname(__FILE__) . '/nikon-e5000-thumb.jpg');
299         $this->assertEquals($ifd1->getThumbnailData(), $thumb_data);
300
301         /* Next IFD. */
302         $ifd2 = $ifd1->getNextIfd();
303         $this->assertNull($ifd2);
304         /* End of IFD $ifd1. */
305
306         $exceptions = Pel::getExceptions();
307         $this->assertInstanceOf('lsolesen\pel\PelException', $exceptions[0]);
308         $this->assertEquals($exceptions[0]->getMessage(), 'Found trailing content after EOI: 1396 bytes');
309     }
310 }