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

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

Optimize some memory leak and some bugged lines of code

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