예제 #1
0
 public function parse($swfdata)
 {
     $reader = new Media_SWF_Parser();
     $reader->input($swfdata);
     /* SWF Header */
     $this->_headers = $reader->getSWFHeader();
     /* SWF Tags */
     while (true) {
         $tag = $reader->getTag();
         $this->_tags[] = $tag;
         if ($tag['Code'] == 0) {
             // END Tag
             break;
         }
     }
     return true;
 }
예제 #2
0
 public function convertImageData()
 {
     $format = (int) $this->getField('BitmapFormat');
     $width = (int) $this->getField('BitmapWidth');
     $height = (int) $this->getField('BitmapHeight');
     $bitmapdata = gzuncompress($this->getField('ZlibBitmapData'));
     $bitmapReader = new Media_SWF_Parser();
     $bitmapReader->input($bitmapdata);
     $im = imagecreatetruecolor($width, $height);
     if ($im === false) {
         throw new Exception('Cannot Initialize new GD image stream.');
     }
     $color_palette = array();
     if ($format == 3) {
         // color palette
         $palette_size = (int) $this->getField('BitmapColorTableSize');
         if ($this->code == 20) {
             for ($i = 0; $i <= $palette_size; $i++) {
                 $r = $bitmapReader->getUI8();
                 $g = $bitmapReader->getUI8();
                 $b = $bitmapReader->getUI8();
                 $color_palette[$i] = imagecolorallocate($im, $r, $g, $b);
             }
         } else {
             // alpha
             imagealphablending($im, false);
             imagesavealpha($im, true);
             for ($i = 0; $i <= $palette_size; $i++) {
                 $r = $bitmapReader->getUI8();
                 $g = $bitmapReader->getUI8();
                 $b = $bitmapReader->getUI8();
                 $a = $bitmapReader->getUI8();
                 $a = (1 - $a / 255) * 127;
                 $color_palette[$i] = imagecolorallocatealpha($im, $r, $g, $b, $a);
             }
         }
         // widthの読み出しbyte数を32bitで丸める(must be rounded up to the next 32-bit word boundary)
         $padding = ($width + 3 & -4) - $width;
         for ($y = 0; $y < $height; ++$y) {
             for ($x = 0; $x < $width; ++$x) {
                 $bi = $bitmapReader->getUI8();
                 imagesetpixel($im, $x, $y, $color_palette[$bi]);
             }
             $bi = $bitmapReader->incrementOffset($padding, 0);
             // skip
         }
     } else {
         // non parette
         if ($format == 4) {
             // PIX15
             for ($y = 0; $y < $height; ++$y) {
                 for ($x = 0; $x < $width; ++$x) {
                     $a = $bitmapReader->getUIBit();
                     // Pix15Reserved always 0
                     $r = $bitmapReader->getUIBits(5);
                     $g = $bitmapReader->getUIBits(5);
                     $b = $bitmapReader->getUIBits(5);
                     $c = imagecolorallocate($im, $r, $g, $b);
                     imagesetpixel($im, $x, $y, $c);
                 }
             }
         } elseif ($this->code == 20) {
             // PIX24
             for ($y = 0; $y < $height; ++$y) {
                 for ($x = 0; $x < $width; ++$x) {
                     $a = $bitmapReader->getUI8();
                     // 0 // Pix24Reserved always0
                     $r = $bitmapReader->getUI8();
                     $g = $bitmapReader->getUI8();
                     $b = $bitmapReader->getUI8();
                     $c = imagecolorallocate($im, $r, $g, $b);
                     imagesetpixel($im, $x, $y, $c);
                 }
             }
         } else {
             // alpha
             imagealphablending($im, false);
             imagesavealpha($im, true);
             for ($y = 0; $y < $height; ++$y) {
                 for ($x = 0; $x < $width; ++$x) {
                     $a = $bitmapReader->getUI8();
                     $a = (1 - $a / 255) * 127;
                     $r = $bitmapReader->getUI8();
                     $g = $bitmapReader->getUI8();
                     $b = $bitmapReader->getUI8();
                     $c = imagecolorallocatealpha($im, $r, $g, $b, $a);
                     imagesetpixel($im, $x, $y, $c);
                 }
             }
         }
     }
     ob_start();
     imagepng($im);
     $image_data = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $image_data;
 }
예제 #3
0
 public function getActionQueue()
 {
     $actions = new _ActionQueue();
     $point_offset = 0;
     foreach ($this->_actions as $act) {
         $r = null;
         // offsetの更新
         ++$point_offset;
         if ($act['ActionCode'] & 0x80) {
             $point_offset += 2;
             $point_offset += $act['Length'];
         }
         switch ($act['ActionCode']) {
             case self::PUSH:
                 $r = new Media_SWF_Parser();
                 $r->input($act['Content']);
                 $type = $r->getUI8();
                 switch ($type) {
                     case 0:
                         $data = $this->root->convertEncoding($r->getString());
                         break;
                     case 1:
                         $data = $r->getFLOAT();
                         break;
                     case 4:
                     case 5:
                     case 8:
                         $data = $r->getUI8();
                         break;
                     case 6:
                         $data = $r->getDOUBLE();
                         break;
                     case 7:
                         $data = $r->getUI32LE();
                         break;
                     case 9:
                         $data = $r->getUI16LE();
                         break;
                     default:
                         $data = null;
                 }
                 if ($type === 0 && !(strlen($data) > 1 && substr($data, 0, 1) == 0) && is_numeric($data)) {
                     $data = intval($data);
                 }
                 $actions->add($act['ActionCode'], array($data), $point_offset);
                 break;
             case self::_IF:
             case self::JUMP:
                 $r = new Media_SWF_Parser();
                 $r->input($act['Content']);
                 $offset = $r->getSI16();
                 $actions->add($act['ActionCode'], array($point_offset + $offset), $point_offset);
                 break;
             case self::GET_URL2:
                 $r = new Media_SWF_Parser();
                 $r->input($act['Content']);
                 $m = $r->getUIBits(2);
                 $r->getUIBits(4);
                 $lt_flag = $r->getUIBit();
                 $vr_flag = $r->getUIBit();
                 $method = $m == 1 ? 'GET' : ($m == 2 ? 'POST' : 'NONE');
                 $actions->add($act['ActionCode'], array($method, $lt_flag, $vr_flag), $point_offset);
                 break;
             case self::GOTO_FRAME2:
                 $r = new Media_SWF_Parser();
                 $r->input($act['Content']);
                 $r->getUIBits(6);
                 $sceneBiasFlag = (bool) $r->getUIBit();
                 $playFlag = (int) $r->getUIBit();
                 if ($sceneBiasFlag) {
                     $sceneBias = $r->getUI16LE();
                 }
                 $actions->add($act['ActionCode'], array($playFlag), $point_offset);
                 break;
             case self::GOTO_FRAME:
                 $r = new Media_SWF_Parser();
                 $r->input($act['Content']);
                 $frame = $r->getUI16LE();
                 $actions->add($act['ActionCode'], array($frame, 0), $point_offset);
                 break;
             case self::GOTO_LABEL:
                 $r = new Media_SWF_Parser();
                 $r->input($act['Content']);
                 $frame = $r->getString();
                 $actions->add($act['ActionCode'], array($frame, 0), $point_offset);
                 break;
             case self::SET_TARGET:
                 $r = new Media_SWF_Parser();
                 $r->input($act['Content']);
                 $target = $r->getString();
                 $actions->add($act['ActionCode'], array($target), $point_offset);
                 break;
             default:
                 $actions->add($act['ActionCode'], array(), $point_offset);
                 break;
         }
     }
     return $actions;
 }
예제 #4
0
 public function parseContent($content)
 {
     $reader = new Media_SWF_Parser();
     $reader->input($content);
     $this->parse($reader);
 }
예제 #5
0
 public function loadFromString($swfdata)
 {
     $reader = new Media_SWF_Parser();
     $reader->input($swfdata);
     $this->parse($reader);
 }