source: extensions/AMetaData/JpegMetaData/Readers/NikonReader.class.php @ 4824

Last change on this file since 4824 was 4705, checked in by grum, 15 years ago

Change Locale class by L10n class ; add Readers for Nikon and Canon cameras ; some bug corrected

  • Property svn:executable set to *
File size: 5.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 NikonReader class is the dedicated to read the specific Nikon tags
36 *
37 * ====> See MakerNotesReader.class.php to know more about the structure <======
38 *
39 * -----------------------------------------------------------------------------
40 *
41 * .. Notes ..
42 *
43 *
44 * The NikonReader 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/NikonTags.class.php");
54  require_once(JPEG_METADATA_DIR."Readers/MakerNotesReader.class.php");
55
56  class NikonReader 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_NIKON;
78      switch($makerSignature)
79      {
80        case MakerNotesSignatures::Nikon2Header:
81          $this->header = MakerNotesSignatures::Nikon2Header;
82          $this->headerSize = MakerNotesSignatures::Nikon2HeaderSize;
83          break;
84        case MakerNotesSignatures::Nikon3Header:
85          $this->header = MakerNotesSignatures::Nikon3Header;
86          $this->headerSize = MakerNotesSignatures::Nikon3HeaderSize;
87          break;
88      }
89
90      parent::__construct($data, $offset, $byteOrder);
91    }
92
93
94    /**
95     * initialize the definition for Pentax exif tags
96     */
97    protected function initializeTagDef()
98    {
99      $this->tagDef = new NikonTags();
100    }
101
102    /**
103     * skip the IFD header
104     */
105    protected function skipHeader($headerSize=0)
106    {
107      parent::skipHeader($headerSize);
108      if($this->header == MakerNotesSignatures::Nikon3Header)
109      {
110        /*
111         * the nikon3header is made of 7 char, and then 3 next char ?????
112         */
113        $header=$this->data->readASCII(3);
114
115
116        $header=$this->data->readASCII(2);
117        /*
118         * The Nikon3Header is formatted as a TIFF header, but the class is not
119         * derived from TiffReader, because we can think there is no more than
120         * one IFD in the maker notes.
121         * By this way, it's easier to skip the header and start reading the
122         * entries.
123         *
124         * begins wih "II" or "MM" (indicate the byte order)
125         * next value is an USHORT, must equals 0x2a
126         *
127         * all data have to be read with the byte order defined in header
128         */
129        if($header=="II" or $header="MM")
130        {
131          $this->byteOrder=$header;
132          $this->data->setByteOrder($this->byteOrder);
133
134          $header=$this->data->readUShort();
135          if($header==0x002a)
136          {
137            $this->isValid=true;
138            $header=$this->data->readULong();
139          }
140        }
141      }
142    }
143
144    /**
145     * this function do the interpretation of specials tags
146     *
147     * the function return the interpreted value for the tag
148     *
149     * @param $tagId             : the id of the tag
150     * @param $values            : 'raw' value to be interpreted
151     * @param UByte $type        : if needed (for IFD structure) the type of data
152     * @param ULong $valueOffset : if needed, the offset of data in the jpeg file
153     * @return String or Array or DateTime or Integer or Float...
154     */
155    protected function processSpecialTag($tagId, $values, $type, $valuesOffset=0)
156    {
157      switch($tagId)
158      {
159        default:
160          $returned="Not yet implemented;".ConvertData::toHexDump($tagId, ByteType::USHORT)." => ".ConvertData::toHexDump($values, $type);
161          break;
162      }
163      return($returned);
164    }
165  }
166
167?>
Note: See TracBrowser for help on using the repository browser.