c30caa43899ff1773ab1d329835de6be064e8d66
2 /////////////////////////////////////////////////////////////////
3 /// getID3() by James Heinrich <info@getid3.org> //
4 // available at http://getid3.sourceforge.net //
5 // or http://www.getid3.org //
6 // also https://github.com/JamesHeinrich/getID3 //
7 /////////////////////////////////////////////////////////////////
8 // See readme.txt for more details //
9 /////////////////////////////////////////////////////////////////
11 // module.graphic.png.php //
12 // module for analyzing PNG Image files //
13 // dependencies: NONE //
15 /////////////////////////////////////////////////////////////////
18 class getid3_png
extends getid3_handler
20 public $max_data_bytes = 10000000; // if data chunk is larger than this do not read it completely (getID3 only needs the first few dozen bytes for parsing)
22 public function Analyze() {
24 $info = &$this->getid3
->info
;
27 $info['png'] = array();
28 $thisfile_png = &$info['png'];
30 $info['fileformat'] = 'png';
31 $info['video']['dataformat'] = 'png';
32 $info['video']['lossless'] = false;
34 $this->fseek($info['avdataoffset']);
35 $PNGfiledata = $this->fread($this->getid3
->fread_buffer_size());
38 $PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A
41 if ($PNGidentifier != "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
42 $this->error('First 8 bytes of file ('.getid3_lib
::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier');
43 unset($info['fileformat']);
47 while ((($this->ftell() - (strlen($PNGfiledata) - $offset)) < $info['filesize'])) {
48 $chunk['data_length'] = getid3_lib
::BigEndian2Int(substr($PNGfiledata, $offset, 4));
49 if ($chunk['data_length'] === false) {
50 $this->error('Failed to read data_length at offset '.$offset);
54 $truncated_data = false;
55 while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] +
4)) && ($this->ftell() < $info['filesize'])) {
56 if (strlen($PNGfiledata) < $this->max_data_bytes
) {
57 $PNGfiledata .= $this->fread($this->getid3
->fread_buffer_size());
59 $this->warning('At offset '.$offset.' chunk "'.substr($PNGfiledata, $offset, 4).'" exceeded max_data_bytes value of '.$this->max_data_bytes
.', data chunk will be truncated at '.(strlen($PNGfiledata) - 8).' bytes');
63 $chunk['type_text'] = substr($PNGfiledata, $offset, 4);
65 $chunk['type_raw'] = getid3_lib
::BigEndian2Int($chunk['type_text']);
66 $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']);
67 $offset +
= $chunk['data_length'];
68 $chunk['crc'] = getid3_lib
::BigEndian2Int(substr($PNGfiledata, $offset, 4));
71 $chunk['flags']['ancilliary'] = (bool) ($chunk['type_raw'] & 0x20000000);
72 $chunk['flags']['private'] = (bool) ($chunk['type_raw'] & 0x00200000);
73 $chunk['flags']['reserved'] = (bool) ($chunk['type_raw'] & 0x00002000);
74 $chunk['flags']['safe_to_copy'] = (bool) ($chunk['type_raw'] & 0x00000020);
77 $thisfile_png[$chunk['type_text']] = array();
78 $thisfile_png_chunk_type_text = &$thisfile_png[$chunk['type_text']];
80 switch ($chunk['type_text']) {
82 case 'IHDR': // Image Header
83 $thisfile_png_chunk_type_text['header'] = $chunk;
84 $thisfile_png_chunk_type_text['width'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4));
85 $thisfile_png_chunk_type_text['height'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4));
86 $thisfile_png_chunk_type_text['raw']['bit_depth'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 1));
87 $thisfile_png_chunk_type_text['raw']['color_type'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 9, 1));
88 $thisfile_png_chunk_type_text['raw']['compression_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 10, 1));
89 $thisfile_png_chunk_type_text['raw']['filter_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 11, 1));
90 $thisfile_png_chunk_type_text['raw']['interlace_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 12, 1));
92 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['raw']['compression_method']);
93 $thisfile_png_chunk_type_text['color_type']['palette'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x01);
94 $thisfile_png_chunk_type_text['color_type']['true_color'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x02);
95 $thisfile_png_chunk_type_text['color_type']['alpha'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x04);
97 $info['video']['resolution_x'] = $thisfile_png_chunk_type_text['width'];
98 $info['video']['resolution_y'] = $thisfile_png_chunk_type_text['height'];
100 $info['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']);
104 case 'PLTE': // Palette
105 $thisfile_png_chunk_type_text['header'] = $chunk;
107 for ($i = 0; $i <= 255; $i++
) {
108 //$thisfile_png_chunk_type_text['red'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
109 //$thisfile_png_chunk_type_text['green'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
110 //$thisfile_png_chunk_type_text['blue'][$i] = getid3_lib::BigEndian2Int(substr($chunk['data'], $paletteoffset++, 1));
111 $red = getid3_lib
::BigEndian2Int(substr($chunk['data'], $paletteoffset++
, 1));
112 $green = getid3_lib
::BigEndian2Int(substr($chunk['data'], $paletteoffset++
, 1));
113 $blue = getid3_lib
::BigEndian2Int(substr($chunk['data'], $paletteoffset++
, 1));
114 $thisfile_png_chunk_type_text[$i] = (($red << 16) |
($green << 8) |
($blue));
119 case 'tRNS': // Transparency
120 $thisfile_png_chunk_type_text['header'] = $chunk;
121 switch ($thisfile_png['IHDR']['raw']['color_type']) {
123 $thisfile_png_chunk_type_text['transparent_color_gray'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 2));
127 $thisfile_png_chunk_type_text['transparent_color_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 2));
128 $thisfile_png_chunk_type_text['transparent_color_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 2));
129 $thisfile_png_chunk_type_text['transparent_color_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 2));
133 for ($i = 0; $i < strlen($chunk['data']); $i++
) {
134 $thisfile_png_chunk_type_text['palette_opacity'][$i] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $i, 1));
140 $this->error('Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']);
143 $this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']);
149 case 'gAMA': // Image Gamma
150 $thisfile_png_chunk_type_text['header'] = $chunk;
151 $thisfile_png_chunk_type_text['gamma'] = getid3_lib
::BigEndian2Int($chunk['data']) / 100000;
155 case 'cHRM': // Primary Chromaticities
156 $thisfile_png_chunk_type_text['header'] = $chunk;
157 $thisfile_png_chunk_type_text['white_x'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4)) / 100000;
158 $thisfile_png_chunk_type_text['white_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4)) / 100000;
159 $thisfile_png_chunk_type_text['red_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 4)) / 100000;
160 $thisfile_png_chunk_type_text['red_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 12, 4)) / 100000;
161 $thisfile_png_chunk_type_text['green_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 16, 4)) / 100000;
162 $thisfile_png_chunk_type_text['green_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 20, 4)) / 100000;
163 $thisfile_png_chunk_type_text['blue_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 24, 4)) / 100000;
164 $thisfile_png_chunk_type_text['blue_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 28, 4)) / 100000;
168 case 'sRGB': // Standard RGB Color Space
169 $thisfile_png_chunk_type_text['header'] = $chunk;
170 $thisfile_png_chunk_type_text['reindering_intent'] = getid3_lib
::BigEndian2Int($chunk['data']);
171 $thisfile_png_chunk_type_text['reindering_intent_text'] = $this->PNGsRGBintentLookup($thisfile_png_chunk_type_text['reindering_intent']);
175 case 'iCCP': // Embedded ICC Profile
176 $thisfile_png_chunk_type_text['header'] = $chunk;
177 list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2);
178 $thisfile_png_chunk_type_text['profile_name'] = $profilename;
179 $thisfile_png_chunk_type_text['compression_method'] = getid3_lib
::BigEndian2Int(substr($compressiondata, 0, 1));
180 $thisfile_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1);
182 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
186 case 'tEXt': // Textual Data
187 $thisfile_png_chunk_type_text['header'] = $chunk;
188 list($keyword, $text) = explode("\x00", $chunk['data'], 2);
189 $thisfile_png_chunk_type_text['keyword'] = $keyword;
190 $thisfile_png_chunk_type_text['text'] = $text;
192 $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
196 case 'zTXt': // Compressed Textual Data
197 $thisfile_png_chunk_type_text['header'] = $chunk;
198 list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
199 $thisfile_png_chunk_type_text['keyword'] = $keyword;
200 $thisfile_png_chunk_type_text['compression_method'] = getid3_lib
::BigEndian2Int(substr($otherdata, 0, 1));
201 $thisfile_png_chunk_type_text['compressed_text'] = substr($otherdata, 1);
202 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
203 switch ($thisfile_png_chunk_type_text['compression_method']) {
205 $thisfile_png_chunk_type_text['text'] = gzuncompress($thisfile_png_chunk_type_text['compressed_text']);
209 // unknown compression method
213 if (isset($thisfile_png_chunk_type_text['text'])) {
214 $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
219 case 'iTXt': // International Textual Data
220 $thisfile_png_chunk_type_text['header'] = $chunk;
221 list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2);
222 $thisfile_png_chunk_type_text['keyword'] = $keyword;
223 $thisfile_png_chunk_type_text['compression'] = (bool) getid3_lib
::BigEndian2Int(substr($otherdata, 0, 1));
224 $thisfile_png_chunk_type_text['compression_method'] = getid3_lib
::BigEndian2Int(substr($otherdata, 1, 1));
225 $thisfile_png_chunk_type_text['compression_method_text'] = $this->PNGcompressionMethodLookup($thisfile_png_chunk_type_text['compression_method']);
226 list($languagetag, $translatedkeyword, $text) = explode("\x00", substr($otherdata, 2), 3);
227 $thisfile_png_chunk_type_text['language_tag'] = $languagetag;
228 $thisfile_png_chunk_type_text['translated_keyword'] = $translatedkeyword;
230 if ($thisfile_png_chunk_type_text['compression']) {
232 switch ($thisfile_png_chunk_type_text['compression_method']) {
234 $thisfile_png_chunk_type_text['text'] = gzuncompress($text);
238 // unknown compression method
244 $thisfile_png_chunk_type_text['text'] = $text;
248 if (isset($thisfile_png_chunk_type_text['text'])) {
249 $thisfile_png['comments'][$thisfile_png_chunk_type_text['keyword']][] = $thisfile_png_chunk_type_text['text'];
254 case 'bKGD': // Background Color
255 $thisfile_png_chunk_type_text['header'] = $chunk;
256 switch ($thisfile_png['IHDR']['raw']['color_type']) {
259 $thisfile_png_chunk_type_text['background_gray'] = getid3_lib
::BigEndian2Int($chunk['data']);
264 $thisfile_png_chunk_type_text['background_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
265 $thisfile_png_chunk_type_text['background_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
266 $thisfile_png_chunk_type_text['background_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2 * $thisfile_png['IHDR']['raw']['bit_depth'], $thisfile_png['IHDR']['raw']['bit_depth']));
270 $thisfile_png_chunk_type_text['background_index'] = getid3_lib
::BigEndian2Int($chunk['data']);
279 case 'pHYs': // Physical Pixel Dimensions
280 $thisfile_png_chunk_type_text['header'] = $chunk;
281 $thisfile_png_chunk_type_text['pixels_per_unit_x'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4));
282 $thisfile_png_chunk_type_text['pixels_per_unit_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4));
283 $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 1));
284 $thisfile_png_chunk_type_text['unit'] = $this->PNGpHYsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
288 case 'sBIT': // Significant Bits
289 $thisfile_png_chunk_type_text['header'] = $chunk;
290 switch ($thisfile_png['IHDR']['raw']['color_type']) {
292 $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
297 $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
298 $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
299 $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 1));
303 $thisfile_png_chunk_type_text['significant_bits_gray'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
304 $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
308 $thisfile_png_chunk_type_text['significant_bits_red'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
309 $thisfile_png_chunk_type_text['significant_bits_green'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
310 $thisfile_png_chunk_type_text['significant_bits_blue'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 1));
311 $thisfile_png_chunk_type_text['significant_bits_alpha'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 3, 1));
320 case 'sPLT': // Suggested Palette
321 $thisfile_png_chunk_type_text['header'] = $chunk;
322 list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2);
323 $thisfile_png_chunk_type_text['palette_name'] = $palettename;
325 $thisfile_png_chunk_type_text['sample_depth_bits'] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, 1));
327 $thisfile_png_chunk_type_text['sample_depth_bytes'] = $thisfile_png_chunk_type_text['sample_depth_bits'] / 8;
329 while ($sPLToffset < strlen($otherdata)) {
330 $thisfile_png_chunk_type_text['red'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
331 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
332 $thisfile_png_chunk_type_text['green'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
333 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
334 $thisfile_png_chunk_type_text['blue'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
335 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
336 $thisfile_png_chunk_type_text['alpha'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, $thisfile_png_chunk_type_text['sample_depth_bytes']));
337 $sPLToffset +
= $thisfile_png_chunk_type_text['sample_depth_bytes'];
338 $thisfile_png_chunk_type_text['frequency'][$paletteCounter] = getid3_lib
::BigEndian2Int(substr($otherdata, $sPLToffset, 2));
345 case 'hIST': // Palette Histogram
346 $thisfile_png_chunk_type_text['header'] = $chunk;
348 while ($hISTcounter < strlen($chunk['data'])) {
349 $thisfile_png_chunk_type_text[$hISTcounter] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $hISTcounter / 2, 2));
355 case 'tIME': // Image Last-Modification Time
356 $thisfile_png_chunk_type_text['header'] = $chunk;
357 $thisfile_png_chunk_type_text['year'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 2));
358 $thisfile_png_chunk_type_text['month'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 1));
359 $thisfile_png_chunk_type_text['day'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 3, 1));
360 $thisfile_png_chunk_type_text['hour'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 1));
361 $thisfile_png_chunk_type_text['minute'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 5, 1));
362 $thisfile_png_chunk_type_text['second'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 6, 1));
363 $thisfile_png_chunk_type_text['unix'] = gmmktime($thisfile_png_chunk_type_text['hour'], $thisfile_png_chunk_type_text['minute'], $thisfile_png_chunk_type_text['second'], $thisfile_png_chunk_type_text['month'], $thisfile_png_chunk_type_text['day'], $thisfile_png_chunk_type_text['year']);
367 case 'oFFs': // Image Offset
368 $thisfile_png_chunk_type_text['header'] = $chunk;
369 $thisfile_png_chunk_type_text['position_x'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 4), false, true);
370 $thisfile_png_chunk_type_text['position_y'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 4, 4), false, true);
371 $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 8, 1));
372 $thisfile_png_chunk_type_text['unit'] = $this->PNGoFFsUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
376 case 'pCAL': // Calibration Of Pixel Values
377 $thisfile_png_chunk_type_text['header'] = $chunk;
378 list($calibrationname, $otherdata) = explode("\x00", $chunk['data'], 2);
379 $thisfile_png_chunk_type_text['calibration_name'] = $calibrationname;
381 $thisfile_png_chunk_type_text['original_zero'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true);
383 $thisfile_png_chunk_type_text['original_max'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 4), false, true);
385 $thisfile_png_chunk_type_text['equation_type'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1));
387 $thisfile_png_chunk_type_text['equation_type_text'] = $this->PNGpCALequationTypeLookup($thisfile_png_chunk_type_text['equation_type']);
388 $thisfile_png_chunk_type_text['parameter_count'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], $pCALoffset, 1));
390 $thisfile_png_chunk_type_text['parameters'] = explode("\x00", substr($chunk['data'], $pCALoffset));
394 case 'sCAL': // Physical Scale Of Image Subject
395 $thisfile_png_chunk_type_text['header'] = $chunk;
396 $thisfile_png_chunk_type_text['unit_specifier'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
397 $thisfile_png_chunk_type_text['unit'] = $this->PNGsCALUnitLookup($thisfile_png_chunk_type_text['unit_specifier']);
398 list($pixelwidth, $pixelheight) = explode("\x00", substr($chunk['data'], 1));
399 $thisfile_png_chunk_type_text['pixel_width'] = $pixelwidth;
400 $thisfile_png_chunk_type_text['pixel_height'] = $pixelheight;
404 case 'gIFg': // GIF Graphic Control Extension
406 if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) {
407 $gIFgCounter = count($thisfile_png_chunk_type_text);
409 $thisfile_png_chunk_type_text[$gIFgCounter]['header'] = $chunk;
410 $thisfile_png_chunk_type_text[$gIFgCounter]['disposal_method'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 0, 1));
411 $thisfile_png_chunk_type_text[$gIFgCounter]['user_input_flag'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 1, 1));
412 $thisfile_png_chunk_type_text[$gIFgCounter]['delay_time'] = getid3_lib
::BigEndian2Int(substr($chunk['data'], 2, 2));
416 case 'gIFx': // GIF Application Extension
418 if (isset($thisfile_png_chunk_type_text) && is_array($thisfile_png_chunk_type_text)) {
419 $gIFxCounter = count($thisfile_png_chunk_type_text);
421 $thisfile_png_chunk_type_text[$gIFxCounter]['header'] = $chunk;
422 $thisfile_png_chunk_type_text[$gIFxCounter]['application_identifier'] = substr($chunk['data'], 0, 8);
423 $thisfile_png_chunk_type_text[$gIFxCounter]['authentication_code'] = substr($chunk['data'], 8, 3);
424 $thisfile_png_chunk_type_text[$gIFxCounter]['application_data'] = substr($chunk['data'], 11);
428 case 'IDAT': // Image Data
429 $idatinformationfieldindex = 0;
430 if (isset($thisfile_png['IDAT']) && is_array($thisfile_png['IDAT'])) {
431 $idatinformationfieldindex = count($thisfile_png['IDAT']);
433 unset($chunk['data']);
434 $thisfile_png_chunk_type_text[$idatinformationfieldindex]['header'] = $chunk;
438 case 'IEND': // Image Trailer
439 $thisfile_png_chunk_type_text['header'] = $chunk;
444 //unset($chunk['data']);
445 $thisfile_png_chunk_type_text['header'] = $chunk;
446 $this->warning('Unhandled chunk type: '.$chunk['type_text']);
454 public function PNGsRGBintentLookup($sRGB) {
455 static $PNGsRGBintentLookup = array(
457 1 => 'Relative colorimetric',
459 3 => 'Absolute colorimetric'
461 return (isset($PNGsRGBintentLookup[$sRGB]) ?
$PNGsRGBintentLookup[$sRGB] : 'invalid');
464 public function PNGcompressionMethodLookup($compressionmethod) {
465 static $PNGcompressionMethodLookup = array(
466 0 => 'deflate/inflate'
468 return (isset($PNGcompressionMethodLookup[$compressionmethod]) ?
$PNGcompressionMethodLookup[$compressionmethod] : 'invalid');
471 public function PNGpHYsUnitLookup($unitid) {
472 static $PNGpHYsUnitLookup = array(
476 return (isset($PNGpHYsUnitLookup[$unitid]) ?
$PNGpHYsUnitLookup[$unitid] : 'invalid');
479 public function PNGoFFsUnitLookup($unitid) {
480 static $PNGoFFsUnitLookup = array(
484 return (isset($PNGoFFsUnitLookup[$unitid]) ?
$PNGoFFsUnitLookup[$unitid] : 'invalid');
487 public function PNGpCALequationTypeLookup($equationtype) {
488 static $PNGpCALequationTypeLookup = array(
489 0 => 'Linear mapping',
490 1 => 'Base-e exponential mapping',
491 2 => 'Arbitrary-base exponential mapping',
492 3 => 'Hyperbolic mapping'
494 return (isset($PNGpCALequationTypeLookup[$equationtype]) ?
$PNGpCALequationTypeLookup[$equationtype] : 'invalid');
497 public function PNGsCALUnitLookup($unitid) {
498 static $PNGsCALUnitLookup = array(
502 return (isset($PNGsCALUnitLookup[$unitid]) ?
$PNGsCALUnitLookup[$unitid] : 'invalid');
505 public function IHDRcalculateBitsPerSample($color_type, $bit_depth) {
506 switch ($color_type) {
507 case 0: // Each pixel is a grayscale sample.
511 case 2: // Each pixel is an R,G,B triple
512 return 3 * $bit_depth;
515 case 3: // Each pixel is a palette index; a PLTE chunk must appear.
519 case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
520 return 2 * $bit_depth;
523 case 6: // Each pixel is an R,G,B triple, followed by an alpha sample.
524 return 4 * $bit_depth;