a2112c370f00e4dd545320e02f192e91a1651b3c
[yaffs-website] / lsolesen / pel / src / PelEntryUndefined.php
1 <?php
2
3 /**
4  * PEL: PHP Exif Library.
5  * A library with support for reading and
6  * writing all Exif headers in JPEG and TIFF images using PHP.
7  *
8  * Copyright (C) 2004, 2005 Martin Geisler.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program in the file COPYING; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301 USA
24  */
25 namespace lsolesen\pel;
26
27 /**
28  * Classes used to hold data for Exif tags of format undefined.
29  *
30  * This file contains the base class {@link PelEntryUndefined} and
31  * the subclasses {@link PelEntryUserComment} which should be used
32  * to manage the {@link PelTag::USER_COMMENT} tag, and {@link
33  * PelEntryVersion} which is used to manage entries with version
34  * information.
35  *
36  * @author Martin Geisler <mgeisler@users.sourceforge.net>
37  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
38  *          License (GPL)
39  * @package PEL
40  */
41
42 /**
43  * Class for holding data of any kind.
44  *
45  * This class can hold bytes of undefined format.
46  *
47  * @author Martin Geisler <mgeisler@users.sourceforge.net>
48  * @package PEL
49  */
50 class PelEntryUndefined extends PelEntry
51 {
52
53     /**
54      * Make a new PelEntry that can hold undefined data.
55      *
56      * @param integer $tag
57      *            which this entry represents. This
58      *            should be one of the constants defined in {@link PelTag},
59      *            e.g., {@link PelTag::SCENE_TYPE}, {@link
60      *            PelTag::MAKER_NOTE} or any other tag with format {@link
61      *            PelFormat::UNDEFINED}.
62      *
63      * @param string $data
64      *            the data that this entry will be holding. Since
65      *            the format is undefined, no checking will be done on the data. If no data are given, a empty string will be stored
66      */
67     public function __construct($tag, $data = '')
68     {
69         $this->tag = $tag;
70         $this->format = PelFormat::UNDEFINED;
71         $this->setValue($data);
72     }
73
74     /**
75      * Set the data of this undefined entry.
76      *
77      * @param string $data
78      *            the data that this entry will be holding. Since
79      *            the format is undefined, no checking will be done on the data.
80      */
81     public function setValue($data)
82     {
83         $this->components = strlen($data);
84         $this->bytes = $data;
85     }
86
87     /**
88      * Get the data of this undefined entry.
89      *
90      * @return string the data that this entry is holding.
91      */
92     public function getValue()
93     {
94         return $this->bytes;
95     }
96
97     /**
98      * Get the value of this entry as text.
99      *
100      * The value will be returned in a format suitable for presentation.
101      *
102      * @param
103      *            boolean some values can be returned in a long or more
104      *            brief form, and this parameter controls that.
105      *
106      * @return string the value as text.
107      */
108     public function getText($brief = false)
109     {
110         switch ($this->tag) {
111             case PelTag::FILE_SOURCE:
112                 // CC (e->components, 1, v);
113                 switch (ord($this->bytes{0})) {
114                     case 0x03:
115                         return 'DSC';
116                     default:
117                         return sprintf('0x%02X', ord($this->bytes{0}));
118                 }
119                 break;
120             case PelTag::SCENE_TYPE:
121                 // CC (e->components, 1, v);
122                 switch (ord($this->bytes{0})) {
123                     case 0x01:
124                         return 'Directly photographed';
125                     default:
126                         return sprintf('0x%02X', ord($this->bytes{0}));
127                 }
128                 break;
129             case PelTag::COMPONENTS_CONFIGURATION:
130                 // CC (e->components, 4, v);
131                 $v = '';
132                 for ($i = 0; $i < 4; $i ++) {
133                     switch (ord($this->bytes{$i})) {
134                         case 0:
135                             $v .= '-';
136                             break;
137                         case 1:
138                             $v .= 'Y';
139                             break;
140                         case 2:
141                             $v .= 'Cb';
142                             break;
143                         case 3:
144                             $v .= 'Cr';
145                             break;
146                         case 4:
147                             $v .= 'R';
148                             break;
149                         case 5:
150                             $v .= 'G';
151                             break;
152                         case 6:
153                             $v .= 'B';
154                             break;
155                         default:
156                             $v .= 'reserved';
157                             break;
158                     }
159                     if ($i < 3) {
160                         $v .= ' ';
161                     }
162                 }
163                 return $v;
164                 break;
165             case PelTag::MAKER_NOTE:
166                 // TODO: handle maker notes.
167                 return $this->components . ' bytes unknown MakerNote data';
168                 break;
169             default:
170                 return '(undefined)';
171         }
172     }
173 }