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

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

JpegMetaData class is updated

  • english Tag.po file is (almost) ready to be translated in other lang
  • fixes some bugs on readers & tag definitions
  • Property svn:executable set to *
File size: 13.4 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."Common/GlobalTags.class.php");
57  require_once(JPEG_METADATA_DIR."TagDefinitions/PentaxTags.class.php");
58  require_once(JPEG_METADATA_DIR."Readers/MakerNotesReader.class.php");
59
60  class PentaxReader extends MakerNotesReader
61  {
62    /**
63     * The constructor needs, like the ancestor, the datas to be parsed
64     *
65     * Some datas are offset on extra data, and this offset can be (some time)
66     * absolute inside the IFD, or relative. So, the offset of the IFD structure
67     * is needed
68     *
69     * The byte order can be different from the TIFF byte order !
70     *
71     * The constructor need the maker signature (see the MakerNotesSignatures
72     * class for a list of known signatures)
73     *
74     * @param String $data
75     * @param ULong $offset : offset of IFD block in the jpeg file
76     * @param String $byteOrder
77     * @param String $makerSignature :
78     */
79    function __construct($data, $offset, $byteOrder, $makerSignature)
80    {
81      $this->maker = MAKER_PENTAX;
82      switch($makerSignature)
83      {
84        case MakerNotesSignatures::PentaxHeader:
85          $this->header = MakerNotesSignatures::PentaxHeader;
86          $this->headerSize = MakerNotesSignatures::PentaxHeaderSize;
87          break;
88        case MakerNotesSignatures::Pentax2Header:
89          $this->header = MakerNotesSignatures::Pentax2Header;
90          $this->headerSize = MakerNotesSignatures::Pentax2HeaderSize;
91          break;
92      }
93
94      parent::__construct($data, $offset, $byteOrder);
95    }
96
97    function __destruct()
98    {
99      parent::__destruct();
100    }
101
102    /**
103     * initialize the definition for Pentax exif tags
104     */
105    protected function initializeTagDef()
106    {
107      $this->tagDef = new PentaxTags();
108    }
109
110    /**
111     * skip the IFD header
112     */
113    protected function skipHeader($headerSize=0)
114    {
115      parent::skipHeader($this->headerSize);
116    }
117
118    /**
119     * this function do the interpretation of specials tags
120     *
121     * the function return the interpreted value for the tag
122     *
123     * @param $tagId             : the id of the tag
124     * @param $values            : 'raw' value to be interpreted
125     * @param UByte $type        : if needed (for IFD structure) the type of data
126     * @param ULong $valueOffset : if needed, the offset of data in the jpeg file
127     * @return String or Array or DateTime or Integer or Float...
128     */
129    protected function processSpecialTag($tagId, $values, $type, $valuesOffset=0)
130    {
131      switch($tagId)
132      {
133        case 0x0000: // "Version"
134          $returned=sprintf("%d.%d.%d.%d", $values[0], $values[1], $values[2], $values[3]);
135          break;
136        case 0x0002: // "PreviewResolution"
137          $returned=sprintf("%dx%d", $values[0], $values[1]);
138          break;
139        case 0x0003: // "PreviewLength",
140        case 0x0004: // "PreviewOffset",
141          $returned=$values;
142          break;
143        case 0x0006: // "Date",
144          $returned=sprintf("%04d/%02d/%02d", ConvertData::toUShort($values, BYTE_ORDER_BIG_ENDIAN), ConvertData::toUByte($values{2}), ConvertData::toUByte($values{3}));
145          break;
146        case 0x0007: // "Time",
147          $returned=sprintf("%02d:%02d:%02d", ConvertData::toUByte($values{0}), ConvertData::toUByte($values{1}), ConvertData::toUByte($values{2}));
148          break;
149        case 0x000c: // "Flash",
150          $tag=$this->tagDef->getTagById(0x000c);
151          $returned=Array();
152          if(array_key_exists($values[0], $tag['tagValues.special'][0]))
153            $returned[]=$tag['tagValues.special'][0][$values[0]];
154          if(array_key_exists($values[1], $tag['tagValues.special'][1]))
155            $returned[]=$tag['tagValues.special'][1][$values[1]];
156          unset($tag);
157          break;
158        case 0x0012: // "ExposureTime", from exiftool
159           $returned=ConvertData::toExposureTime($values/100000);
160          break;
161        case 0x0013: // "FNumber",
162          $returned=ConvertData::toFNumber($values/10);
163          break;
164        case 0x0016: // "ExposureCompensation",
165          $returned=sprintf("%.1f EV", ($values-50)/10);
166          break;
167        case 0x0018: // "AutoBracketing",
168          /*
169           * $values if an array
170           *  [0] : exposure compensation
171           *  [1] : bracketing mode
172           */
173          if($values[0]<10)
174            $returned=Array(($values[0]/3)." EV");
175          else
176            $returned=Array(($values[0]-9.5)." EV");
177
178          if($values[1]==0)
179            $returned[]="No extended bracketing";
180          else
181          {
182            $type = $values[1] >> 8;
183            $range = $values[1] & 0xff;
184            switch ($type)
185            {
186              case 1:
187                $returned[]="WB-BA";
188                break;
189              case 2:
190                $returned[]="WB-GM";
191                break;
192              case 3:
193                $returned[]="Saturation";
194                break;
195              case 4:
196                $returned[]="Sharpness";
197                break;
198              case 5:
199                $returned[]="Contrast";
200                break;
201              default:
202                $returned[]="Unknown;".ConvertData::toHexDump($type, ByteType::USHORT);
203                break;
204            }
205            $returned[]=$range;
206          }
207          break;
208        case 0x001b: // "BlueBalance",
209        case 0x001c: // "RedBalance", from exiftool
210          $returned=sprintf("%d", $values/256+0.5);
211          break;
212        case 0x001d: // "FocalLength",
213          /* note : in exiftool, the formula change with the camera model... ? */
214          $returned=($values/100)." mm";
215          break;
216        case 0x001e: // "DigitalZoom", from exiftool
217          $returned=($values/100);
218          break;
219        case 0x0025: // "HometownDST",
220        case 0x0026: // "DestinationDST",
221          $returned=($values==1)?"Yes":"No";
222          break;
223        case 0x0027: // "DSPFirmwareVersion",
224        case 0x0028: // "CPUFirmwareVersion",
225          $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}));
226          break;
227        case 0x002d: // "EffectiveLV",
228          $returned=sprintf("%.1f", $values/1024);
229          break;
230        case 0x0039: // "RawImageSize",
231          $returned=sprintf("%dx%d", $values[0], $values[1]);
232          break;
233        case 0x003e: // "PreviewImageBorders",
234          $returned=ConvertData::toHexDump($values, ByteType::UBYTE);
235          break;
236        case 0x003f: // "LensType",
237          $tag=$this->tagDef->getTagById(0x003f);
238          $id=$values[1]+($values[0]<<8);
239          if(!array_key_exists($id, $tag['tagValues.special'])) $id=0xffff;
240
241          $returned="";
242
243          $lensesList=$tag['tagValues.special'][$id];
244          if(is_array($lensesList))
245          {
246            foreach($lensesList as $lens)
247            {
248              /*
249               * If there is more than one lens associated with a lens id
250               *
251               * 1/ try to found the min/max focals of the lens
252               * 2/ try to found the min/max aperture of the lens
253               * 3/ if focal is fixed, make min = max
254               * 4/ if aperture is constant, make min)max
255               * 5/ look if : min focal <= photo focal <= max focal  and
256               *              photo aperture >= min aperture
257               *            if yes, the lens is returned, otherwise test next
258               *            lens
259               */
260              preg_match("/.*\s(?:([0-9]+){1}(?:-([0-9]+))?)mm.*/i", $lens, $focals);
261              preg_match("/.*\sF(?:([0-9\.]+){1}(?:-([0-9\.]+))?).*/i", $lens, $apertures);
262
263              if(count($focals)==2)
264              {
265                //focal is not a zoom, min = max
266                $focals[]=$focal[1];
267              }
268              elseif(count($focals)==0)
269              {
270                $focal=Array(0,0,0);
271              }
272
273
274              if(count($apertures)==2)
275              {
276                //aperture is constant, min = max
277                $apertures[]=$apertures[1];
278              }
279              elseif(count($apertures)==0)
280              {
281                $apertures=Array(0,0,0);
282              }
283
284              $focal=GlobalTags::getExifFocal();
285              if($focal=="") $focal=-1;
286
287              $aperture=GlobalTags::getExifAperture();
288              if($aperture=="") $aperture=-1;
289
290              if($focals[1]<=$focal && $focal<=$focals[2] && $aperture>=$apertures[1] && $returned=="")
291              {
292                $returned=$lens;
293              }
294
295              unset($lens);
296              unset($focals);
297              unset($apertures);
298            }
299            if($returned=="")
300            {
301              // no lens seems to be valid, returns the lens list
302              $returned=$lensesList;
303            }
304          }
305          else
306          {
307            // not a list, just a single lens
308            $returned=$lensesList;
309          }
310
311          unset($tag);
312          unset($id);
313          break;
314        case 0x0040: // "SensitivityAdjust", from exiftool
315          /* is the conversion perl => php is good !? */
316          $returned=sprintf("%.1f", ($values-50)/10+50);
317          break;
318        case 0x0047: // "Temperature",
319          $returned=(($values>127)?256-$values:$values)."°C";
320          break;
321        case 0x0048: // "AELock",
322        case 0x0049: // "NoiseReduction",
323          $returned=($values==1)?"On":"Off";
324          break;
325        case 0x004d: // "FlashExposureCompensation",
326          $returned=ConvertData::toEV($values/256);
327          break;
328        case 0x0050: // "ColorTemperature", from exiftool
329          $returned=53190 -$values;
330          break;
331
332        /* theses tags decoding is not yet implemented
333         * have to take a look on the algorithm in exiftool (it seems to work
334         * but I don't understand everything...)
335         */
336
337        case 0x0205: // "ShotInfo",
338        case 0x0206: // "AEInfo",
339        case 0x0207: // "LensInfo",
340        case 0x0208: // "FlashInfo",
341        case 0x0209: // "AEMeteringSegments",
342        case 0x020a: // "FlashADump",
343        case 0x020b: // "FlashBDump",
344        case 0x020d: // "WB_RGGBLevelsDaylight",
345        case 0x020e: // "WB_RGGBLevelsShade",
346        case 0x020f: // "WB_RGGBLevelsCloudy",
347        case 0x0210: // "WB_RGGBLevelsTungsten",
348        case 0x0211: // "WB_RGGBLevelsFluorescentD",
349        case 0x0212: // "WB_RGGBLevelsFluorescentN",
350        case 0x0213: // "WB_RGGBLevelsFluorescentW",
351        case 0x0214: // "WB_RGGBLevelsFlash",
352        case 0x0215: // "CameraInfo",
353        case 0x0216: // "BatteryInfo",
354        case 0x021f: // "AFInfo",
355        case 0x0222: // "ColorInfo",
356
357        case 0x0029: // "FrameNumber",
358        case 0x0041: // "DigitalFilter",
359        case 0x005c: // "ShakeReduction",
360        case 0x005d: // "ShutterCount",
361        case 0x0200: // "BlackPoint",
362        case 0x0201: // "WhitePoint",
363        case 0x0203: // "ColorMatrixA",
364        case 0x0204: // "ColorMatrixB",
365        default:
366          $returned="Not yet implemented;".ConvertData::toHexDump($tagId, ByteType::USHORT)." => ".ConvertData::toHexDump($values, $type);
367          break;
368      }
369      return($returned);
370    }
371  }
372
373?>
Note: See TracBrowser for help on using the repository browser.