ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Pcd.php
Go to the documentation of this file.
1<?php
2
4
6
9// available at http://getid3.sourceforge.net //
10// or http://www.getid3.org //
12// See readme.txt for more details //
14// //
15// module.graphic.pcd.php //
16// module for analyzing PhotoCD (PCD) Image files //
17// dependencies: NONE //
18// ///
20
28class Pcd extends BaseHandler
29{
34 public $ExtractData = 0;
35
39 public function analyze()
40 {
41 $info = &$this->getid3->info;
42
43 $info['fileformat'] = 'pcd';
44 $info['video']['dataformat'] = 'pcd';
45 $info['video']['lossless'] = false;
46
47 fseek($this->getid3->fp, $info['avdataoffset'] + 72, SEEK_SET);
48
49 $PCDflags = fread($this->getid3->fp, 1);
50 $PCDisVertical = ((ord($PCDflags) & 0x01) ? true : false);
51
52 if ($PCDisVertical) {
53 $info['video']['resolution_x'] = 3072;
54 $info['video']['resolution_y'] = 2048;
55 } else {
56 $info['video']['resolution_x'] = 2048;
57 $info['video']['resolution_y'] = 3072;
58 }
59
60 if ($this->ExtractData > 3) {
61
62 $info['error'][] = 'Cannot extract PSD image data for detail levels above BASE (level-3) because encrypted with Kodak-proprietary compression/encryption.';
63
64 } elseif ($this->ExtractData > 0) {
65
66 $PCD_levels[1] = array( 192, 128, 0x02000); // BASE/16
67 $PCD_levels[2] = array( 384, 256, 0x0B800); // BASE/4
68 $PCD_levels[3] = array( 768, 512, 0x30000); // BASE
69 //$PCD_levels[4] = array(1536, 1024, ??); // BASE*4 - encrypted with Kodak-proprietary compression/encryption
70 //$PCD_levels[5] = array(3072, 2048, ??); // BASE*16 - encrypted with Kodak-proprietary compression/encryption
71 //$PCD_levels[6] = array(6144, 4096, ??); // BASE*64 - encrypted with Kodak-proprietary compression/encryption; PhotoCD-Pro only
72
73 list($PCD_width, $PCD_height, $PCD_dataOffset) = $PCD_levels[3];
74
75 fseek($this->getid3->fp, $info['avdataoffset'] + $PCD_dataOffset, SEEK_SET);
76
77 for ($y = 0; $y < $PCD_height; $y += 2) {
78 // The image-data of these subtypes start at the respective offsets of 02000h, 0b800h and 30000h.
79 // To decode the YcbYr to the more usual RGB-code, three lines of data have to be read, each
80 // consisting of ‘w’ bytes, where ‘w’ is the width of the image-subtype. The first ‘w’ bytes and
81 // the first half of the third ‘w’ bytes contain data for the first RGB-line, the second ‘w’ bytes
82 // and the second half of the third ‘w’ bytes contain data for a second RGB-line.
83
84 $PCD_data_Y1 = fread($this->getid3->fp, $PCD_width);
85 $PCD_data_Y2 = fread($this->getid3->fp, $PCD_width);
86 $PCD_data_Cb = fread($this->getid3->fp, intval(round($PCD_width / 2)));
87 $PCD_data_Cr = fread($this->getid3->fp, intval(round($PCD_width / 2)));
88
89 for ($x = 0; $x < $PCD_width; $x++) {
90 if ($PCDisVertical) {
91 $info['pcd']['data'][$PCD_width - $x][$y] = $this->YCbCr2RGB(ord($PCD_data_Y1{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)}));
92 $info['pcd']['data'][$PCD_width - $x][$y + 1] = $this->YCbCr2RGB(ord($PCD_data_Y2{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)}));
93 } else {
94 $info['pcd']['data'][$y][$x] = $this->YCbCr2RGB(ord($PCD_data_Y1{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)}));
95 $info['pcd']['data'][$y + 1][$x] = $this->YCbCr2RGB(ord($PCD_data_Y2{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)}));
96 }
97 }
98 }
99
100 // Example for plotting extracted data
101 //getid3_lib::IncludeDependency(GetId3Core::getIncludePath().'module.audio.ac3.php', __FILE__, true);
102 //if ($PCDisVertical) {
103 // $BMPinfo['resolution_x'] = $PCD_height;
104 // $BMPinfo['resolution_y'] = $PCD_width;
105 //} else {
106 // $BMPinfo['resolution_x'] = $PCD_width;
107 // $BMPinfo['resolution_y'] = $PCD_height;
108 //}
109 //$BMPinfo['bmp']['data'] = $info['pcd']['data'];
110 //getid3_bmp::PlotBMP($BMPinfo);
111 //exit;
112
113 }
114
115 }
116
125 public function YCbCr2RGB($Y, $Cb, $Cr)
126 {
127 static $YCbCr_constants = array();
128 if (empty($YCbCr_constants)) {
129 $YCbCr_constants['red']['Y'] = 0.0054980 * 256;
130 $YCbCr_constants['red']['Cb'] = 0.0000000 * 256;
131 $YCbCr_constants['red']['Cr'] = 0.0051681 * 256;
132 $YCbCr_constants['green']['Y'] = 0.0054980 * 256;
133 $YCbCr_constants['green']['Cb'] = -0.0015446 * 256;
134 $YCbCr_constants['green']['Cr'] = -0.0026325 * 256;
135 $YCbCr_constants['blue']['Y'] = 0.0054980 * 256;
136 $YCbCr_constants['blue']['Cb'] = 0.0079533 * 256;
137 $YCbCr_constants['blue']['Cr'] = 0.0000000 * 256;
138 }
139
140 $RGBcolor = array('red'=>0, 'green'=>0, 'blue'=>0);
141 foreach ($RGBcolor as $rgbname => $dummy) {
142 $RGBcolor[$rgbname] = max(0,
143 min(255,
144 intval(
145 round(
146 ($YCbCr_constants[$rgbname]['Y'] * $Y) +
147 ($YCbCr_constants[$rgbname]['Cb'] * ($Cb - 156)) +
148 ($YCbCr_constants[$rgbname]['Cr'] * ($Cr - 137))
149 )
150 )
151 )
152 );
153 }
154
155 return (($RGBcolor['red'] * 65536) + ($RGBcolor['green'] * 256) + $RGBcolor['blue']);
156 }
157
158}
An exception for terminatinating execution or to throw for unit testing.
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:26
fseek($bytes, $whence=SEEK_SET)
GetId3() by James Heinrich info@getid3.org //.
Definition: Pcd.php:29
analyze()
Analyze from file pointer.
Definition: Pcd.php:39
YCbCr2RGB($Y, $Cb, $Cr)
@staticvar array $YCbCr_constants
Definition: Pcd.php:125
$y
Definition: example_007.php:83
$x
Definition: example_009.php:98
$info
Definition: example_052.php:80