PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_jce/editor/tiny_mce/plugins/imgmanager_ext/classes/pel/PelEntryUndefined.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 416 lines | 135 code | 52 blank | 229 comment | 13 complexity | cb16ef2d23f10d6ef21ff91d0821a2b0 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /* PEL: PHP Exif Library. A library with support for reading and
  3. * writing all Exif headers in JPEG and TIFF images using PHP.
  4. *
  5. * Copyright (C) 2004, 2005 Martin Geisler.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program in the file COPYING; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301 USA
  21. */
  22. /* $Id$ */
  23. /**
  24. * Classes used to hold data for Exif tags of format undefined.
  25. *
  26. * This file contains the base class {@link PelEntryUndefined} and
  27. * the subclasses {@link PelEntryUserComment} which should be used
  28. * to manage the {@link PelTag::USER_COMMENT} tag, and {@link
  29. * PelEntryVersion} which is used to manage entries with version
  30. * information.
  31. *
  32. * @author Martin Geisler <mgeisler@users.sourceforge.net>
  33. * @version $Revision$
  34. * @date $Date$
  35. * @license http://www.gnu.org/licenses/gpl.html GNU General Public
  36. * License (GPL)
  37. * @package PEL
  38. */
  39. /**#@+ Required class definitions. */
  40. require_once('PelEntry.php');
  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. * Make a new PelEntry that can hold undefined data.
  53. *
  54. * @param PelTag the tag which this entry represents. This
  55. * should be one of the constants defined in {@link PelTag},
  56. * e.g., {@link PelTag::SCENE_TYPE}, {@link
  57. * PelTag::MAKER_NOTE} or any other tag with format {@link
  58. * PelFormat::UNDEFINED}.
  59. *
  60. * @param string the data that this entry will be holding. Since
  61. * the format is undefined, no checking will be done on the data.
  62. */
  63. function __construct($tag, $data = '') {
  64. $this->tag = $tag;
  65. $this->format = PelFormat::UNDEFINED;
  66. $this->setValue($data);
  67. }
  68. /**
  69. * Set the data of this undefined entry.
  70. *
  71. * @param string the data that this entry will be holding. Since
  72. * the format is undefined, no checking will be done on the data.
  73. */
  74. function setValue($data) {
  75. $this->components = strlen($data);
  76. $this->bytes = $data;
  77. }
  78. /**
  79. * Get the data of this undefined entry.
  80. *
  81. * @return string the data that this entry is holding.
  82. */
  83. function getValue() {
  84. return $this->bytes;
  85. }
  86. /**
  87. * Get the value of this entry as text.
  88. *
  89. * The value will be returned in a format suitable for presentation.
  90. *
  91. * @param boolean some values can be returned in a long or more
  92. * brief form, and this parameter controls that.
  93. *
  94. * @return string the value as text.
  95. */
  96. function getText($brief = false) {
  97. switch ($this->tag) {
  98. case PelTag::FILE_SOURCE:
  99. //CC (e->components, 1, v);
  100. switch (ord($this->bytes{0})) {
  101. case 0x03:
  102. return 'DSC';
  103. default:
  104. return sprintf('0x%02X', ord($this->bytes{0}));
  105. }
  106. case PelTag::SCENE_TYPE:
  107. //CC (e->components, 1, v);
  108. switch (ord($this->bytes{0})) {
  109. case 0x01:
  110. return 'Directly photographed';
  111. default:
  112. return sprintf('0x%02X', ord($this->bytes{0}));
  113. }
  114. case PelTag::COMPONENTS_CONFIGURATION:
  115. //CC (e->components, 4, v);
  116. $v = '';
  117. for ($i = 0; $i < 4; $i++) {
  118. switch (ord($this->bytes{$i})) {
  119. case 0:
  120. $v .= '-';
  121. break;
  122. case 1:
  123. $v .= 'Y';
  124. break;
  125. case 2:
  126. $v .= 'Cb';
  127. break;
  128. case 3:
  129. $v .= 'Cr';
  130. break;
  131. case 4:
  132. $v .= 'R';
  133. break;
  134. case 5:
  135. $v .= 'G';
  136. break;
  137. case 6:
  138. $v .= 'B';
  139. break;
  140. default:
  141. $v .= 'reserved';
  142. break;
  143. }
  144. if ($i < 3) $v .= ' ';
  145. }
  146. return $v;
  147. case PelTag::MAKER_NOTE:
  148. // TODO: handle maker notes.
  149. return $this->components . ' bytes unknown MakerNote data';
  150. default:
  151. return '(undefined)';
  152. }
  153. }
  154. }
  155. /**
  156. * Class for a user comment.
  157. *
  158. * This class is used to hold user comments, which can come in several
  159. * different character encodings. The Exif standard specifies a
  160. * certain format of the {@link PelTag::USER_COMMENT user comment
  161. * tag}, and this class will make sure that the format is kept.
  162. *
  163. * The most basic use of this class simply stores an ASCII encoded
  164. * string for later retrieval using {@link getValue}:
  165. *
  166. * <code>
  167. * $entry = new PelEntryUserComment('An ASCII string');
  168. * echo $entry->getValue();
  169. * </code>
  170. *
  171. * The string can be encoded with a different encoding, and if so, the
  172. * encoding must be given using the second argument. The Exif
  173. * standard specifies three known encodings: 'ASCII', 'JIS', and
  174. * 'Unicode'. If the user comment is encoded using a character
  175. * encoding different from the tree known encodings, then the empty
  176. * string should be passed as encoding, thereby specifying that the
  177. * encoding is undefined.
  178. *
  179. * @author Martin Geisler <mgeisler@users.sourceforge.net>
  180. * @package PEL
  181. */
  182. class PelEntryUserComment extends PelEntryUndefined {
  183. /**
  184. * The user comment.
  185. *
  186. * @var string
  187. */
  188. private $comment;
  189. /**
  190. * The encoding.
  191. *
  192. * This should be one of 'ASCII', 'JIS', 'Unicode', or ''.
  193. *
  194. * @var string
  195. */
  196. private $encoding;
  197. /**
  198. * Make a new entry for holding a user comment.
  199. *
  200. * @param string the new user comment.
  201. *
  202. * @param string the encoding of the comment. This should be either
  203. * 'ASCII', 'JIS', 'Unicode', or the empty string specifying an
  204. * undefined encoding.
  205. */
  206. function __construct($comment = '', $encoding = 'ASCII') {
  207. parent::__construct(PelTag::USER_COMMENT);
  208. $this->setValue($comment, $encoding);
  209. }
  210. /**
  211. * Set the user comment.
  212. *
  213. * @param string the new user comment.
  214. *
  215. * @param string the encoding of the comment. This should be either
  216. * 'ASCII', 'JIS', 'Unicode', or the empty string specifying an
  217. * unknown encoding.
  218. */
  219. function setValue($comment = '', $encoding = 'ASCII') {
  220. $this->comment = $comment;
  221. $this->encoding = $encoding;
  222. parent::setValue(str_pad($encoding, 8, chr(0)) . $comment);
  223. }
  224. /**
  225. * Returns the user comment.
  226. *
  227. * The comment is returned with the same character encoding as when
  228. * it was set using {@link setValue} or {@link __construct the
  229. * constructor}.
  230. *
  231. * @return string the user comment.
  232. */
  233. function getValue() {
  234. return $this->comment;
  235. }
  236. /**
  237. * Returns the encoding.
  238. *
  239. * @return string the encoding of the user comment.
  240. */
  241. function getEncoding() {
  242. return $this->encoding;
  243. }
  244. /**
  245. * Returns the user comment.
  246. *
  247. * @return string the user comment.
  248. */
  249. function getText($brief = false) {
  250. return $this->comment;
  251. }
  252. }
  253. /**
  254. * Class to hold version information.
  255. *
  256. * There are three Exif entries that hold version information: the
  257. * {@link PelTag::EXIF_VERSION}, {@link
  258. * PelTag::FLASH_PIX_VERSION}, and {@link
  259. * PelTag::INTEROPERABILITY_VERSION} tags. This class manages
  260. * those tags.
  261. *
  262. * The class is used in a very straight-forward way:
  263. * <code>
  264. * $entry = new PelEntryVersion(PelTag::EXIF_VERSION, 2.2);
  265. * </code>
  266. * This creates an entry for an file complying to the Exif 2.2
  267. * standard. It is easy to test for standards level of an unknown
  268. * entry:
  269. * <code>
  270. * if ($entry->getTag() == PelTag::EXIF_VERSION &&
  271. * $entry->getValue() > 2.0) {
  272. * echo 'Recent Exif version.';
  273. * }
  274. * </code>
  275. *
  276. * @author Martin Geisler <mgeisler@users.sourceforge.net>
  277. * @package PEL
  278. */
  279. class PelEntryVersion extends PelEntryUndefined {
  280. /**
  281. * The version held by this entry.
  282. *
  283. * @var float
  284. */
  285. private $version;
  286. /**
  287. * Make a new entry for holding a version.
  288. *
  289. * @param PelTag the tag. This should be one of {@link
  290. * PelTag::EXIF_VERSION}, {@link PelTag::FLASH_PIX_VERSION},
  291. * or {@link PelTag::INTEROPERABILITY_VERSION}.
  292. *
  293. * @param float the version. The size of the entries leave room for
  294. * exactly four digits: two digits on either side of the decimal
  295. * point.
  296. */
  297. function __construct($tag, $version = 0.0) {
  298. parent::__construct($tag);
  299. $this->setValue($version);
  300. }
  301. /**
  302. * Set the version held by this entry.
  303. *
  304. * @param float the version. The size of the entries leave room for
  305. * exactly four digits: two digits on either side of the decimal
  306. * point.
  307. */
  308. function setValue($version = 0.0) {
  309. $this->version = $version;
  310. $major = floor($version);
  311. $minor = ($version - $major)*100;
  312. parent::setValue(sprintf('%02.0f%02.0f', $major, $minor));
  313. }
  314. /**
  315. * Return the version held by this entry.
  316. *
  317. * @return float the version. This will be the same as the value
  318. * given to {@link setValue} or {@link __construct the
  319. * constructor}.
  320. */
  321. function getValue() {
  322. return $this->version;
  323. }
  324. /**
  325. * Return a text string with the version.
  326. *
  327. * @param boolean controls if the output should be brief. Brief
  328. * output omits the word 'Version' so the result is just 'Exif x.y'
  329. * instead of 'Exif Version x.y' if the entry holds information
  330. * about the Exif version --- the output for FlashPix is similar.
  331. *
  332. * @return string the version number with the type of the tag,
  333. * either 'Exif' or 'FlashPix'.
  334. */
  335. function getText($brief = false) {
  336. $v = $this->version;
  337. /* Versions numbers like 2.0 would be output as just 2 if we don't
  338. * add the '.0' ourselves. */
  339. if (floor($this->version) == $this->version)
  340. $v .= '.0';
  341. switch ($this->tag) {
  342. case PelTag::EXIF_VERSION:
  343. if ($brief)
  344. return Pel::fmt('Exif %s', $v);
  345. else
  346. return Pel::fmt('Exif Version %s', $v);
  347. case PelTag::FLASH_PIX_VERSION:
  348. if ($brief)
  349. return Pel::fmt('FlashPix %s', $v);
  350. else
  351. return Pel::fmt('FlashPix Version %s', $v);
  352. case PelTag::INTEROPERABILITY_VERSION:
  353. if ($brief)
  354. return Pel::fmt('Interoperability %s', $v);
  355. else
  356. return Pel::fmt('Interoperability Version %s', $v);
  357. }
  358. if ($brief)
  359. return $v;
  360. else
  361. return Pel::fmt('Version %s', $v);
  362. }
  363. }
  364. ?>