Example #1
0
File: SWF.php Project: yoya/IO_SWF
 function parse($swfdata)
 {
     $reader = new IO_Bit();
     $reader->input($swfdata);
     $this->_swfdata = $swfdata;
     /* SWF Header */
     $this->_headers['Signature'] = $reader->getData(3);
     $this->_headers['Version'] = $reader->getUI8();
     $this->_headers['FileLength'] = $reader->getUI32LE();
     if ($this->_headers['Signature'][0] == 'C') {
         // CWS の場合、FileLength の後ろが zlib 圧縮されている
         $uncompressed_data = gzuncompress(substr($swfdata, 8));
         if ($uncompressed_data === false) {
             return false;
         }
         list($byte_offset, $dummy) = $reader->getOffset();
         $reader->setOffset(0, 0);
         $swfdata = $reader->getData($byte_offset) . $uncompressed_data;
         $reader = new IO_Bit();
         $reader->input($swfdata);
         $this->_swfdata = $swfdata;
         $reader->setOffset($byte_offset, 0);
     }
     /* SWF Movie Header */
     $this->_headers['FrameSize'] = IO_SWF_Type_RECT::parse($reader);
     $reader->byteAlign();
     $this->_headers['FrameRate'] = $reader->getUI16LE();
     $this->_headers['FrameCount'] = $reader->getUI16LE();
     list($this->_header_size, $dummy) = $reader->getOffset();
     /* SWF Tags */
     while (true) {
         $swfInfo = array('Version' => $this->_headers['Version']);
         $tag = new IO_SWF_Tag($swfInfo);
         $tag->parse($reader);
         $this->_tags[] = $tag;
         if ($tag->code == 0) {
             // END Tag
             break;
         }
     }
     return true;
 }
Example #2
0
File: JPEG.php Project: yoya/IO_SWF
 function _splitChunk($eoiFinish = true, $sosScan = true)
 {
     $bitin = new IO_Bit();
     $bitin->input($this->_jpegdata);
     while ($bitin->hasNextData()) {
         $marker1 = $bitin->getUI8();
         if ($marker1 != 0xff) {
             fprintf(STDERR, "dumpChunk: marker1=0x%02X", $marker1);
             return false;
         }
         $marker2 = $bitin->getUI8();
         switch ($marker2) {
             case 0xd8:
                 // SOI (Start of Image)
                 $this->_jpegChunk[] = array('marker' => $marker2, 'data' => null, 'length' => null);
                 continue;
             case 0xd9:
                 // EOI (End of Image)
                 $this->_jpegChunk[] = array('marker' => $marker2, 'data' => null, 'length' => null);
                 if ($eoiFinish) {
                     break 2;
                     // while break;
                 }
                 continue;
             case 0xda:
                 // SOS
                 if ($sosScan === false) {
                     $remainData = $bitin->getDataUntil(false);
                     $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $remainData, 'length' => null);
                     break 2;
                     // while break;
                 }
             case 0xd0:
             case 0xd1:
             case 0xd2:
             case 0xd3:
                 // RST
             // RST
             case 0xd4:
             case 0xd5:
             case 0xd6:
             case 0xd7:
                 // RST
                 list($chunk_data_offset, $dummy) = $bitin->getOffset();
                 while (true) {
                     $next_marker1 = $bitin->getUI8();
                     if ($next_marker1 != 0xff) {
                         continue;
                     }
                     $next_marker2 = $bitin->getUI8();
                     if ($next_marker2 == 0x0) {
                         continue;
                     }
                     $bitin->incrementOffset(-2, 0);
                     // back from next marker
                     list($next_chunk_offset, $dummy) = $bitin->getOffset();
                     $length = $next_chunk_offset - $chunk_data_offset;
                     $bitin->setOffset($chunk_data_offset, 0);
                     $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $bitin->getData($length), 'length' => null);
                     break;
                 }
                 break;
             default:
                 $length = $bitin->getUI16BE();
                 $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $bitin->getData($length - 2), 'length' => $length);
                 continue;
         }
     }
 }