PageRenderTime 37ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/sys/plugins/id3/getid3/module.graphic.pcd.php

https://bitbucket.org/Sanek_OS9/dcms-24
PHP | 133 lines | 74 code | 25 blank | 34 comment | 8 complexity | 539e893600f7eab33fb468b55df8ef5d MD5 | raw file
  1. <?php
  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. /////////////////////////////////////////////////////////////////
  10. // //
  11. // module.graphic.pcd.php //
  12. // module for analyzing PhotoCD (PCD) Image files //
  13. // dependencies: NONE //
  14. // ///
  15. /////////////////////////////////////////////////////////////////
  16. class getid3_pcd extends getid3_handler
  17. {
  18. public $ExtractData = 0;
  19. public function Analyze() {
  20. $info = &$this->getid3->info;
  21. $info['fileformat'] = 'pcd';
  22. $info['video']['dataformat'] = 'pcd';
  23. $info['video']['lossless'] = false;
  24. $this->fseek($info['avdataoffset'] + 72);
  25. $PCDflags = $this->fread(1);
  26. $PCDisVertical = ((ord($PCDflags) & 0x01) ? true : false);
  27. if ($PCDisVertical) {
  28. $info['video']['resolution_x'] = 3072;
  29. $info['video']['resolution_y'] = 2048;
  30. } else {
  31. $info['video']['resolution_x'] = 2048;
  32. $info['video']['resolution_y'] = 3072;
  33. }
  34. if ($this->ExtractData > 3) {
  35. $info['error'][] = 'Cannot extract PSD image data for detail levels above BASE (level-3) because encrypted with Kodak-proprietary compression/encryption.';
  36. } elseif ($this->ExtractData > 0) {
  37. $PCD_levels[1] = array( 192, 128, 0x02000); // BASE/16
  38. $PCD_levels[2] = array( 384, 256, 0x0B800); // BASE/4
  39. $PCD_levels[3] = array( 768, 512, 0x30000); // BASE
  40. //$PCD_levels[4] = array(1536, 1024, ??); // BASE*4 - encrypted with Kodak-proprietary compression/encryption
  41. //$PCD_levels[5] = array(3072, 2048, ??); // BASE*16 - encrypted with Kodak-proprietary compression/encryption
  42. //$PCD_levels[6] = array(6144, 4096, ??); // BASE*64 - encrypted with Kodak-proprietary compression/encryption; PhotoCD-Pro only
  43. list($PCD_width, $PCD_height, $PCD_dataOffset) = $PCD_levels[3];
  44. $this->fseek($info['avdataoffset'] + $PCD_dataOffset);
  45. for ($y = 0; $y < $PCD_height; $y += 2) {
  46. // The image-data of these subtypes start at the respective offsets of 02000h, 0b800h and 30000h.
  47. // To decode the YcbYr to the more usual RGB-code, three lines of data have to be read, each
  48. // consisting of ‘w’ bytes, where ‘w’ is the width of the image-subtype. The first ‘w’ bytes and
  49. // the first half of the third ‘w’ bytes contain data for the first RGB-line, the second ‘w’ bytes
  50. // and the second half of the third ‘w’ bytes contain data for a second RGB-line.
  51. $PCD_data_Y1 = $this->fread($PCD_width);
  52. $PCD_data_Y2 = $this->fread($PCD_width);
  53. $PCD_data_Cb = $this->fread(intval(round($PCD_width / 2)));
  54. $PCD_data_Cr = $this->fread(intval(round($PCD_width / 2)));
  55. for ($x = 0; $x < $PCD_width; $x++) {
  56. if ($PCDisVertical) {
  57. $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)}));
  58. $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)}));
  59. } else {
  60. $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)}));
  61. $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)}));
  62. }
  63. }
  64. }
  65. // Example for plotting extracted data
  66. //getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true);
  67. //if ($PCDisVertical) {
  68. // $BMPinfo['resolution_x'] = $PCD_height;
  69. // $BMPinfo['resolution_y'] = $PCD_width;
  70. //} else {
  71. // $BMPinfo['resolution_x'] = $PCD_width;
  72. // $BMPinfo['resolution_y'] = $PCD_height;
  73. //}
  74. //$BMPinfo['bmp']['data'] = $info['pcd']['data'];
  75. //getid3_bmp::PlotBMP($BMPinfo);
  76. //exit;
  77. }
  78. }
  79. public function YCbCr2RGB($Y, $Cb, $Cr) {
  80. static $YCbCr_constants = array();
  81. if (empty($YCbCr_constants)) {
  82. $YCbCr_constants['red']['Y'] = 0.0054980 * 256;
  83. $YCbCr_constants['red']['Cb'] = 0.0000000 * 256;
  84. $YCbCr_constants['red']['Cr'] = 0.0051681 * 256;
  85. $YCbCr_constants['green']['Y'] = 0.0054980 * 256;
  86. $YCbCr_constants['green']['Cb'] = -0.0015446 * 256;
  87. $YCbCr_constants['green']['Cr'] = -0.0026325 * 256;
  88. $YCbCr_constants['blue']['Y'] = 0.0054980 * 256;
  89. $YCbCr_constants['blue']['Cb'] = 0.0079533 * 256;
  90. $YCbCr_constants['blue']['Cr'] = 0.0000000 * 256;
  91. }
  92. $RGBcolor = array('red'=>0, 'green'=>0, 'blue'=>0);
  93. foreach ($RGBcolor as $rgbname => $dummy) {
  94. $RGBcolor[$rgbname] = max(0,
  95. min(255,
  96. intval(
  97. round(
  98. ($YCbCr_constants[$rgbname]['Y'] * $Y) +
  99. ($YCbCr_constants[$rgbname]['Cb'] * ($Cb - 156)) +
  100. ($YCbCr_constants[$rgbname]['Cr'] * ($Cr - 137))
  101. )
  102. )
  103. )
  104. );
  105. }
  106. return (($RGBcolor['red'] * 65536) + ($RGBcolor['green'] * 256) + $RGBcolor['blue']);
  107. }
  108. }