source: extensions/AMetaData/JpegMetaData/Readers/PentaxReader.class.php @ 4931

Last change on this file since 4931 was 4931, checked in by grum, 14 years ago

Implement Nikon camera's maker note ; add some Xmp tag ; fix some bugs

  • Property svn:executable set to *
File size: 10.9 KB
Line 
1<?php
2/*
3 * --:: JPEG MetaDatas ::-------------------------------------------------------
4 *
5 *  Author    : Grum
6 *   email    : grum at piwigo.org
7 *   website  : http://photos.grum.fr
8 *
9 *   << May the Little SpaceFrog be with you ! >>
10 *
11 *
12 * +-----------------------------------------------------------------------+
13 * | JpegMetaData - a PHP based Jpeg Metadata manager                      |
14 * +-----------------------------------------------------------------------+
15 * | Copyright(C) 2010  Grum - http://www.grum.fr                          |
16 * +-----------------------------------------------------------------------+
17 * | This program is free software; you can redistribute it and/or modify  |
18 * | it under the terms of the GNU General Public License as published by  |
19 * | the Free Software Foundation                                          |
20 * |                                                                       |
21 * | This program is distributed in the hope that it will be useful, but   |
22 * | WITHOUT ANY WARRANTY; without even the implied warranty of            |
23 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
24 * | General Public License for more details.                              |
25 * |                                                                       |
26 * | You should have received a copy of the GNU General Public License     |
27 * | along with this program; if not, write to the Free Software           |
28 * | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
29 * | USA.                                                                  |
30 * +-----------------------------------------------------------------------+
31 *
32 *
33 * -----------------------------------------------------------------------------
34 *
35 * The PentaxReader class is the dedicated to read the specific Pentax tags
36 *
37 * ====> See MakerNotesReader.class.php to know more about the structure <======
38 *
39 * -----------------------------------------------------------------------------
40 *
41 * .. Notes ..
42 *
43 *
44 * ****             All known tags are not implemented !!                   ****
45 *
46 *
47 * The PentaxReader class is derived from the MakerNotesReader class.
48 *
49 * ======> See MakerNotesReader.class.php to know more about common methods <======
50 *
51 * -----------------------------------------------------------------------------
52 */
53
54
55
56  require_once(JPEG_METADATA_DIR."TagDefinitions/PentaxTags.class.php");
57  require_once(JPEG_METADATA_DIR."Readers/MakerNotesReader.class.php");
58
59  class PentaxReader extends MakerNotesReader
60  {
61    /**
62     * The constructor needs, like the ancestor, the datas to be parsed
63     *
64     * Some datas are offset on extra data, and this offset can be (some time)
65     * absolute inside the IFD, or relative. So, the offset of the IFD structure
66     * is needed
67     *
68     * The byte order can be different from the TIFF byte order !
69     *
70     * The constructor need the maker signature (see the MakerNotesSignatures
71     * class for a list of known signatures)
72     *
73     * @param String $data
74     * @param ULong $offset : offset of IFD block in the jpeg file
75     * @param String $byteOrder
76     * @param String $makerSignature :
77     */
78    function __construct($data, $offset, $byteOrder, $makerSignature)
79    {
80      $this->maker = MAKER_PENTAX;
81      switch($makerSignature)
82      {
83        case MakerNotesSignatures::PentaxHeader:
84          $this->header = MakerNotesSignatures::PentaxHeader;
85          $this->headerSize = MakerNotesSignatures::PentaxHeaderSize;
86          break;
87        case MakerNotesSignatures::Pentax2Header:
88          $this->header = MakerNotesSignatures::Pentax2Header;
89          $this->headerSize = MakerNotesSignatures::Pentax2HeaderSize;
90          break;
91      }
92
93      parent::__construct($data, $offset, $byteOrder);
94    }
95
96    function __destruct()
97    {
98      parent::__destruct();
99    }
100
101    /**
102     * initialize the definition for Pentax exif tags
103     */
104    protected function initializeTagDef()
105    {
106      $this->tagDef = new PentaxTags();
107    }
108
109    /**
110     * skip the IFD header
111     */
112    protected function skipHeader($headerSize=0)
113    {
114      parent::skipHeader($this->headerSize);
115    }
116
117    /**
118     * this function do the interpretation of specials tags
119     *
120     * the function return the interpreted value for the tag
121     *
122     * @param $tagId             : the id of the tag
123     * @param $values            : 'raw' value to be interpreted
124     * @param UByte $type        : if needed (for IFD structure) the type of data
125     * @param ULong $valueOffset : if needed, the offset of data in the jpeg file
126     * @return String or Array or DateTime or Integer or Float...
127     */
128    protected function processSpecialTag($tagId, $values, $type, $valuesOffset=0)
129    {
130      switch($tagId)
131      {
132        case 0x0000: // "Version"
133          $returned=sprintf("%d.%d.%d.%d", $values[0], $values[1], $values[2], $values[3]);
134          break;
135        case 0x0002: // "PreviewResolution"
136          $returned=sprintf("%dx%d", $values[0], $values[1]);
137          break;
138        case 0x0003: // "PreviewLength",
139        case 0x0004: // "PreviewOffset",
140          $returned=$values;
141          break;
142        case 0x0006: // "Date",
143          $returned=sprintf("%04d/%02d/%02d", ConvertData::toUShort($values, BYTE_ORDER_BIG_ENDIAN), ConvertData::toUByte($values{2}), ConvertData::toUByte($values{3}));
144          break;
145        case 0x0007: // "Time",
146          $returned=sprintf("%02d:%02d:%02d", ConvertData::toUByte($values{0}), ConvertData::toUByte($values{1}), ConvertData::toUByte($values{2}));
147          break;
148        case 0x000c: // "Flash",
149          $tag=$this->tagDef->getTagById(0x000c);
150          $returned="";
151          if(array_key_exists($values[0], $tag['tagValues.special'][0]))
152            $returned.=$tag['tagValues.special'][0][$values[0]];
153          if(array_key_exists($values[1], $tag['tagValues.special'][1]))
154            $returned.=";".$tag['tagValues.special'][1][$values[1]];
155          unset($tag);
156          break;
157        case 0x0012: // "ExposureTime", from exiftool
158           $returned=ConvertData::toExposureTime($values/100000);
159          break;
160        case 0x0013: // "FNumber",
161          $returned=ConvertData::toFNumber($values/10);
162          break;
163        case 0x0016: // "ExposureCompensation",
164          $returned=sprintf("%.1f EV", ($values-50)/10);
165          break;
166        case 0x0018: // "AutoBracketing",
167          /*
168           * $values if an array
169           *  [0] : exposure compensation
170           *  [1] : bracketing mode
171           */
172          if($values[0]<10)
173            $returned=Array(($values[0]/3)." EV");
174          else
175            $returned=Array(($values[0]-9.5)." EV");
176
177          if($values[1]==0)
178            $returned[]="No extended bracketing";
179          else
180          {
181            $type = $values[1] >> 8;
182            $range = $values[1] & 0xff;
183            switch ($type)
184            {
185              case 1:
186                $returned[]="WB-BA";
187                break;
188              case 2:
189                $returned[]="WB-GM";
190                break;
191              case 3:
192                $returned[]="Saturation";
193                break;
194              case 4:
195                $returned[]="Sharpness";
196                break;
197              case 5:
198                $returned[]="Contrast";
199                break;
200              default:
201                $returned[]="Unknown;".ConvertData::toHexDump($type, ByteType::USHORT);
202                break;
203            }
204            $returned[]=$range;
205          }
206          break;
207        case 0x001b: // "BlueBalance",
208        case 0x001c: // "RedBalance", from exiftool
209          $returned=sprintf("%d", $values/256+0.5);
210          break;
211        case 0x001d: // "FocalLength",
212          /* note : in exiftool, the formula change with the camera model... ? */
213          $returned=($values/100)." mm";
214          break;
215        case 0x001e: // "DigitalZoom", from exiftool
216          $returned=($values/100);
217          break;
218        case 0x0025: // "HometownDST",
219        case 0x0026: // "DestinationDST",
220          $returned=($values==1)?"Yes":"No";
221          break;
222        case 0x0027: // "DSPFirmwareVersion",
223        case 0x0028: // "CPUFirmwareVersion",
224          $returned=sprintf("%d.%d.%d.%d", 0xff-ConvertData::toUByte($values{0}), 0xff-ConvertData::toUByte($values{1}), 0xff-ConvertData::toUByte($values{2}), 0xff-ConvertData::toUByte($values{3}));
225          break;
226        case 0x002d: // "EffectiveLV",
227          $returned=sprintf("%.1f", $values/1024);
228          break;
229        case 0x0039: // "RawImageSize",
230          $returned=sprintf("%dx%d", $values[0], $values[1]);
231          break;
232        case 0x003e: // "PreviewImageBorders",
233          $returned=ConvertData::toHexDump($values, ByteType::UBYTE);
234          break;
235        case 0x0040: // "SensitivityAdjust", from exiftool
236          /* is the conversion perl => php is good !? */
237          $returned=sprintf("%.1f", ($values-50)/10+50);
238          break;
239        case 0x0047: // "Temperature",
240          $returned=(($values>127)?256-$values:$values)."°C";
241          break;
242        case 0x0048: // "AELock",
243        case 0x0049: // "NoiseReduction",
244          $returned=($values==1)?"On":"Off";
245          break;
246        case 0x004d: // "FlashExposureCompensation",
247          $returned=ConvertData::toEV($values/256);
248          break;
249        case 0x0050: // "ColorTemperature", from exiftool
250          $returned=53190 -$values;
251          break;
252
253        /* theses tags decoding is not yet implemented
254         * have to take a look on the algorithm in exiftool (it seems to work
255         * but I don't understand everything...)
256         */
257
258        case 0x0205: // "ShotInfo",
259        case 0x0206: // "AEInfo",
260        case 0x0207: // "LensInfo",
261        case 0x0208: // "FlashInfo",
262        case 0x0209: // "AEMeteringSegments",
263        case 0x020a: // "FlashADump",
264        case 0x020b: // "FlashBDump",
265        case 0x020d: // "WB_RGGBLevelsDaylight",
266        case 0x020e: // "WB_RGGBLevelsShade",
267        case 0x020f: // "WB_RGGBLevelsCloudy",
268        case 0x0210: // "WB_RGGBLevelsTungsten",
269        case 0x0211: // "WB_RGGBLevelsFluorescentD",
270        case 0x0212: // "WB_RGGBLevelsFluorescentN",
271        case 0x0213: // "WB_RGGBLevelsFluorescentW",
272        case 0x0214: // "WB_RGGBLevelsFlash",
273        case 0x0215: // "CameraInfo",
274        case 0x0216: // "BatteryInfo",
275        case 0x021f: // "AFInfo",
276        case 0x0222: // "ColorInfo",
277
278        case 0x0029: // "FrameNumber",
279        case 0x0041: // "DigitalFilter",
280        case 0x005c: // "ShakeReduction",
281        case 0x005d: // "ShutterCount",
282        case 0x0200: // "BlackPoint",
283        case 0x0201: // "WhitePoint",
284        case 0x0203: // "ColorMatrixA",
285        case 0x0204: // "ColorMatrixB",
286        default:
287          $returned="Not yet implemented;".ConvertData::toHexDump($tagId, ByteType::USHORT)." => ".ConvertData::toHexDump($values, $type);
288          break;
289      }
290      return($returned);
291    }
292  }
293
294?>
Note: See TracBrowser for help on using the repository browser.