Annotation of /trunk/lib/getid3/module.graphic.pcd.php
Parent Directory
|
Revision Log
Revision 2 - (view) (download)
| 1 : | andphe | 2 | <?php |
| 2 : | ///////////////////////////////////////////////////////////////// | ||
| 3 : | /// getID3() by James Heinrich <info@getid3.org> // | ||
| 4 : | // available at http://getid3.sourceforge.net // | ||
| 5 : | // or http://www.getid3.org // | ||
| 6 : | ///////////////////////////////////////////////////////////////// | ||
| 7 : | // See readme.txt for more details // | ||
| 8 : | ///////////////////////////////////////////////////////////////// | ||
| 9 : | // // | ||
| 10 : | // module.graphic.pcd.php // | ||
| 11 : | // module for analyzing PhotoCD (PCD) Image files // | ||
| 12 : | // dependencies: NONE // | ||
| 13 : | // /// | ||
| 14 : | ///////////////////////////////////////////////////////////////// | ||
| 15 : | // MOS Intruder Alerts | ||
| 16 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 17 : | |||
| 18 : | class getid3_pcd | ||
| 19 : | { | ||
| 20 : | function getid3_pcd(&$fd, &$ThisFileInfo, $ExtractData=0) { | ||
| 21 : | $ThisFileInfo['fileformat'] = 'pcd'; | ||
| 22 : | $ThisFileInfo['video']['dataformat'] = 'pcd'; | ||
| 23 : | $ThisFileInfo['video']['lossless'] = false; | ||
| 24 : | |||
| 25 : | |||
| 26 : | fseek($fd, $ThisFileInfo['avdataoffset'] + 72, SEEK_SET); | ||
| 27 : | |||
| 28 : | $PCDflags = fread($fd, 1); | ||
| 29 : | $PCDisVertical = ((ord($PCDflags) & 0x01) ? true : false); | ||
| 30 : | |||
| 31 : | |||
| 32 : | if ($PCDisVertical) { | ||
| 33 : | $ThisFileInfo['video']['resolution_x'] = 3072; | ||
| 34 : | $ThisFileInfo['video']['resolution_y'] = 2048; | ||
| 35 : | } else { | ||
| 36 : | $ThisFileInfo['video']['resolution_x'] = 2048; | ||
| 37 : | $ThisFileInfo['video']['resolution_y'] = 3072; | ||
| 38 : | } | ||
| 39 : | |||
| 40 : | |||
| 41 : | if ($ExtractData > 3) { | ||
| 42 : | |||
| 43 : | $ThisFileInfo['error'][] = 'Cannot extract PSD image data for detail levels above BASE (3)'; | ||
| 44 : | |||
| 45 : | } elseif ($ExtractData > 0) { | ||
| 46 : | |||
| 47 : | $PCD_levels[1] = array( 192, 128, 0x02000); // BASE/16 | ||
| 48 : | $PCD_levels[2] = array( 384, 256, 0x0B800); // BASE/4 | ||
| 49 : | $PCD_levels[3] = array( 768, 512, 0x30000); // BASE | ||
| 50 : | //$PCD_levels[4] = array(1536, 1024, ??); // BASE*4 - encrypted with Kodak-proprietary compression/encryption | ||
| 51 : | //$PCD_levels[5] = array(3072, 2048, ??); // BASE*16 - encrypted with Kodak-proprietary compression/encryption | ||
| 52 : | //$PCD_levels[6] = array(6144, 4096, ??); // BASE*64 - encrypted with Kodak-proprietary compression/encryption; PhotoCD-Pro only | ||
| 53 : | |||
| 54 : | list($PCD_width, $PCD_height, $PCD_dataOffset) = $PCD_levels[3]; | ||
| 55 : | |||
| 56 : | fseek($fd, $ThisFileInfo['avdataoffset'] + $PCD_dataOffset, SEEK_SET); | ||
| 57 : | |||
| 58 : | for ($y = 0; $y < $PCD_height; $y += 2) { | ||
| 59 : | // The image-data of these subtypes start at the respective offsets of 02000h, 0b800h and 30000h. | ||
| 60 : | // To decode the YcbYr to the more usual RGB-code, three lines of data have to be read, each | ||
| 61 : | // consisting of �w� bytes, where �w� is the width of the image-subtype. The first �w� bytes and | ||
| 62 : | // the first half of the third �w� bytes contain data for the first RGB-line, the second �w� bytes | ||
| 63 : | // and the second half of the third �w� bytes contain data for a second RGB-line. | ||
| 64 : | |||
| 65 : | $PCD_data_Y1 = fread($fd, $PCD_width); | ||
| 66 : | $PCD_data_Y2 = fread($fd, $PCD_width); | ||
| 67 : | $PCD_data_Cb = fread($fd, intval(round($PCD_width / 2))); | ||
| 68 : | $PCD_data_Cr = fread($fd, intval(round($PCD_width / 2))); | ||
| 69 : | |||
| 70 : | for ($x = 0; $x < $PCD_width; $x++) { | ||
| 71 : | if ($PCDisVertical) { | ||
| 72 : | $ThisFileInfo['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)})); | ||
| 73 : | $ThisFileInfo['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)})); | ||
| 74 : | } else { | ||
| 75 : | $ThisFileInfo['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)})); | ||
| 76 : | $ThisFileInfo['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)})); | ||
| 77 : | } | ||
| 78 : | } | ||
| 79 : | } | ||
| 80 : | |||
| 81 : | // Example for plotting extracted data | ||
| 82 : | //getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true); | ||
| 83 : | //if ($PCDisVertical) { | ||
| 84 : | // $BMPinfo['resolution_x'] = $PCD_height; | ||
| 85 : | // $BMPinfo['resolution_y'] = $PCD_width; | ||
| 86 : | //} else { | ||
| 87 : | // $BMPinfo['resolution_x'] = $PCD_width; | ||
| 88 : | // $BMPinfo['resolution_y'] = $PCD_height; | ||
| 89 : | //} | ||
| 90 : | //$BMPinfo['bmp']['data'] = $ThisFileInfo['pcd']['data']; | ||
| 91 : | //getid3_bmp::PlotBMP($BMPinfo); | ||
| 92 : | //exit; | ||
| 93 : | |||
| 94 : | } | ||
| 95 : | |||
| 96 : | } | ||
| 97 : | |||
| 98 : | function YCbCr2RGB($Y, $Cb, $Cr) { | ||
| 99 : | static $YCbCr_constants = array(); | ||
| 100 : | if (empty($YCbCr_constants)) { | ||
| 101 : | $YCbCr_constants['red']['Y'] = 0.0054980 * 256; | ||
| 102 : | $YCbCr_constants['red']['Cb'] = 0.0000000 * 256; | ||
| 103 : | $YCbCr_constants['red']['Cr'] = 0.0051681 * 256; | ||
| 104 : | $YCbCr_constants['green']['Y'] = 0.0054980 * 256; | ||
| 105 : | $YCbCr_constants['green']['Cb'] = -0.0015446 * 256; | ||
| 106 : | $YCbCr_constants['green']['Cr'] = -0.0026325 * 256; | ||
| 107 : | $YCbCr_constants['blue']['Y'] = 0.0054980 * 256; | ||
| 108 : | $YCbCr_constants['blue']['Cb'] = 0.0079533 * 256; | ||
| 109 : | $YCbCr_constants['blue']['Cr'] = 0.0000000 * 256; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | $RGBcolor = array('red'=>0, 'green'=>0, 'blue'=>0); | ||
| 113 : | foreach ($RGBcolor as $rgbname => $dummy) { | ||
| 114 : | $RGBcolor[$rgbname] = max(0, | ||
| 115 : | min(255, | ||
| 116 : | intval( | ||
| 117 : | round( | ||
| 118 : | ($YCbCr_constants[$rgbname]['Y'] * $Y) + | ||
| 119 : | ($YCbCr_constants[$rgbname]['Cb'] * ($Cb - 156)) + | ||
| 120 : | ($YCbCr_constants[$rgbname]['Cr'] * ($Cr - 137)) | ||
| 121 : | ) | ||
| 122 : | ) | ||
| 123 : | ) | ||
| 124 : | ); | ||
| 125 : | } | ||
| 126 : | return (($RGBcolor['red'] * 65536) + ($RGBcolor['green'] * 256) + $RGBcolor['blue']); | ||
| 127 : | } | ||
| 128 : | |||
| 129 : | } | ||
| 130 : | |||
| 131 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

