c679264dac72efbaa89e8416406e28a0f20542b1
[yaffs-website] / test / image-tests / NikonCoolscanIVTest.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 NikonCoolscanIVTest extends \PHPUnit_Framework_TestCase
29 {
30     public function testRead()
31     {
32         Pel::clearExceptions();
33         Pel::setStrictParsing(false);
34         $jpeg = new PelJpeg(dirname(__FILE__) . '/nikon-coolscan-iv.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()), 6);
48
49         $entry = $ifd0->getEntry(271); // Make
50         $this->assertInstanceOf('lsolesen\pel\PelEntryAscii', $entry);
51         $this->assertEquals($entry->getValue(), 'Nikon');
52         $this->assertEquals($entry->getText(), 'Nikon');
53
54         $entry = $ifd0->getEntry(282); // XResolution
55         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
56         $this->assertEquals($entry->getValue(), array(
57             0 => 2000,
58             1 => 1
59         ));
60         $this->assertEquals($entry->getText(), '2000/1');
61
62         $entry = $ifd0->getEntry(283); // YResolution
63         $this->assertInstanceOf('lsolesen\pel\PelEntryRational', $entry);
64         $this->assertEquals($entry->getValue(), array(
65             0 => 2000,
66             1 => 1
67         ));
68         $this->assertEquals($entry->getText(), '2000/1');
69
70         $entry = $ifd0->getEntry(296); // ResolutionUnit
71         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
72         $this->assertEquals($entry->getValue(), 2);
73         $this->assertEquals($entry->getText(), 'Inch');
74
75         $entry = $ifd0->getEntry(306); // DateTime
76         $this->assertInstanceOf('lsolesen\pel\PelEntryTime', $entry);
77         $this->assertEquals($entry->getValue(), 1090023875);
78         $this->assertEquals($entry->getText(), '2004:07:17 00:24:35');
79
80         $entry = $ifd0->getEntry(531); // YCbCrPositioning
81         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
82         $this->assertEquals($entry->getValue(), 1);
83         $this->assertEquals($entry->getText(), 'centered');
84
85         /* Sub IFDs of $ifd0. */
86         $this->assertEquals(count($ifd0->getSubIfds()), 2);
87         $ifd0_0 = $ifd0->getSubIfd(2); // IFD Exif
88         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_0);
89
90         /* Start of IDF $ifd0_0. */
91         $this->assertEquals(count($ifd0_0->getEntries()), 7);
92
93         $entry = $ifd0_0->getEntry(36864); // ExifVersion
94         $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
95         $this->assertEquals($entry->getValue(), 2.1);
96         $this->assertEquals($entry->getText(), 'Exif Version 2.1');
97
98         $entry = $ifd0_0->getEntry(37121); // ComponentsConfiguration
99         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
100         $this->assertEquals($entry->getValue(), "\x01\x02\x03\0");
101         $this->assertEquals($entry->getText(), 'Y Cb Cr -');
102
103         $entry = $ifd0_0->getEntry(37500); // MakerNote
104         $this->assertInstanceOf('lsolesen\pel\PelEntryUndefined', $entry);
105         $expected = "\x02\0\x01\0\x07\0\x04\0\0\0\x30\x31\x30\x30\x10\x0e\x04\0\x01\0\0\0\x16\x01\0\0\0\0\0\0\x05\0";
106         $this->assertEquals($entry->getValue(), $expected);
107         $this->assertEquals($entry->getText(), '32 bytes unknown MakerNote data');
108
109         $entry = $ifd0_0->getEntry(40960); // FlashPixVersion
110         $this->assertInstanceOf('lsolesen\pel\PelEntryVersion', $entry);
111         $this->assertEquals($entry->getValue(), 1);
112         $this->assertEquals($entry->getText(), 'FlashPix Version 1.0');
113
114         $entry = $ifd0_0->getEntry(40961); // ColorSpace
115         $this->assertInstanceOf('lsolesen\pel\PelEntryShort', $entry);
116         $this->assertEquals($entry->getValue(), 1);
117         $this->assertEquals($entry->getText(), 'sRGB');
118
119         $entry = $ifd0_0->getEntry(40962); // PixelXDimension
120         $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
121         $this->assertEquals($entry->getValue(), 960);
122         $this->assertEquals($entry->getText(), '960');
123
124         $entry = $ifd0_0->getEntry(40963); // PixelYDimension
125         $this->assertInstanceOf('lsolesen\pel\PelEntryLong', $entry);
126         $this->assertEquals($entry->getValue(), 755);
127         $this->assertEquals($entry->getText(), '755');
128
129         /* Sub IFDs of $ifd0_0. */
130         $this->assertEquals(count($ifd0_0->getSubIfds()), 0);
131
132         $this->assertEquals($ifd0_0->getThumbnailData(), '');
133
134         /* Next IFD. */
135         $ifd0_1 = $ifd0_0->getNextIfd();
136         $this->assertNull($ifd0_1);
137         /* End of IFD $ifd0_0. */
138         $ifd0_1 = $ifd0->getSubIfd(3); // IFD GPS
139         $this->assertInstanceOf('lsolesen\pel\PelIfd', $ifd0_1);
140
141         /* Start of IDF $ifd0_1. */
142         $this->assertEquals(count($ifd0_1->getEntries()), 0);
143
144         /* Sub IFDs of $ifd0_1. */
145         $this->assertEquals(count($ifd0_1->getSubIfds()), 0);
146
147         $this->assertEquals($ifd0_1->getThumbnailData(), '');
148
149         /* Next IFD. */
150         $ifd0_2 = $ifd0_1->getNextIfd();
151         $this->assertNull($ifd0_2);
152         /* End of IFD $ifd0_1. */
153
154         $this->assertEquals($ifd0->getThumbnailData(), '');
155
156         /* Next IFD. */
157         $ifd1 = $ifd0->getNextIfd();
158         $this->assertNull($ifd1);
159         /* End of IFD $ifd0. */
160
161         $this->assertTrue(count(Pel::getExceptions()) == 0);
162     }
163 }