function parseContent($tagCode, $content, $opts = array()) { $reader = new IO_Bit(); $reader->input($content); $this->_buttonId = $reader->getUI16LE(); $opts['tagCode'] = $tagCode; if ($tagCode == 34) { // DefineButton2 $this->_reservedFlags = $reader->getUIBits(7); $this->_trackAsMenu = $reader->getUIBit(); list($offset_actionOffset, $dummy) = $reader->getOffset(); $this->_actionOffset = $reader->getUI16LE(); } $characters = array(); while ($reader->getUI8() != 0) { $reader->incrementOffset(-1, 0); // 1 byte back $characters[] = IO_SWF_Type_BUTTONRECORD::parse($reader, $opts); } $this->_characters = $characters; if ($tagCode == 34) { // DefineButton2 // TODO: skip ActionOffset - CurrentOffsetUntilCharactersField $actions = array(); if ($this->_actionOffset > 0) { list($offset_buttonCondition, $dummy) = $reader->getOffset(); if ($offset_actionOffset + $this->_actionOffset != $offset_buttonCondition) { // TODO: warning $reader->setOffset($offset_actionOffset + $this->_actionOffset, 0); } while (true) { $action = IO_SWF_Type_BUTTONCONDACTION::parse($reader, $opts); $actions[] = $action; if ($action['CondActionSize'] == 0) { break; // last action } } $this->_actions = $actions; } else { $this->_actions = null; } } else { $actions = array(); while ($reader->getUI8() != 0) { $reader->incrementOffset(-1, 0); // 1 byte back $actions[] = IO_SWF_Type_Action::parse($reader); } $this->_actions = $actions; } return true; }
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; } } }
function parseDataChunks(&$reader) { $chunks = array(); while ($reader->hasNextData(8)) { $chunk = array(); $chunkID = $reader->getData(4); $size = $reader->getUI32BE(); $chunk['ID'] = $chunkID; $chunkID_3byte = substr($chunkID, 0, 3); $chunkID_4th_value = ord($chunkID[3]); switch ($chunkID_3byte) { case 'Dch': $chunk['ID'] = $chunkID_3byte; $chunk['CodeType'] = $chunkID_4th_value; break; case 'MTR': case 'ATR': case 'GTR': $chunk['ID'] = $chunkID_3byte; $chunk['TrackNumber'] = $chunkID_4th_value; break; } $chunk['Size'] = $size; switch (substr($chunkID, 0, 3)) { case 'CNT': // CNTI: Contents Information Chunk $chunk['Contents Class'] = $reader->getUI8(); $chunk['Contents Type'] = $reader->getUI8(); $chunk['Contents Code Type'] = $reader->getUI8(); $chunk['Copy Status'] = $reader->getUI8(); $chunk['Copy Counts'] = $reader->getUI8(); if ($size > 5) { $chunk['Option'] = $reader->getData($size - 5); } break; case 'MTR': // MTR*: Score Track Chunk $chunk['Format Type'] = $reader->getUI8(); $chunk['Sequence Type'] = $reader->getUI8(); $chunk['Timebase D'] = $reader->getUI8(); $chunk['Timebase G'] = $reader->getUI8(); $chunk['Channnel Status'] = $reader->getUI16BE(); $data = $reader->getData($size - 6); $reader_chunkdata = new IO_Bit(); $reader_chunkdata->input($data); $this->seekToAlphabet($reader_chunkdata); $chunk[$structure_type] = $this->parseDataChunks($reader_chunkdata); break; case 'Mts': // Mtsu, Mtsq, Mts $data = $reader->getData($size); $reader_tracks = new IO_Bit(); $reader_tracks->input($data); switch ($chunkID) { case 'Mtsu': // Score Track Setup Data // Score Track Setup Data case 'Mtsq': // Score Track Sequence Data $tracks = array(); while ($reader_tracks->hasNextData(4)) { $end_check = $reader_tracks->getUI32BE(); if ($end_check == 0) { break; } $reader_tracks->incrementOffset(-4, 0); $track = array(); // Duration if ($chunkID != 'Mtsu') { // Mtsu は Duration 無し $duration = $reader_tracks->getUI8(); if ($duration & 0x80) { $duration = ($duration & 0x7f) << 8; $duration |= $reader_tracks->getUI8(); } $track['Duration'] = $duration; } // Event $event = $reader_tracks->getUI8(); $eventData = array(); if ($event != 0) { $eventData['Type'] = 'Note Message'; $eventData['GetTime'] = $reader_tracks->getUI8(); // Option ??? } else { $data1 = $reader_tracks->getUI8(); $eventData['Channel'] = $data1 >> 6; if (($data1 & 0xf) == 0) { $eventData['Type'] = 'Program change'; } elseif (($data1 & 0xf) == 1) { $eventData['Type'] = 'Bank Select'; } else { $msg = sprintf("Unknow Event Data#1=0x%02x", $data1); // throw new Exception($msg); printf($msg . "\n"); break 2; } $eventData['Value'] = $reader_tracks->getUI8(); } $track['event'] = $tracks[] = $track; } $chunk['Tracks'] = $tracks; break 2; } default: $data = $reader->getData($size); if ($structure_type = $this->nestedChunkIDSize($chunkID)) { $reader_chunkdata = new IO_Bit(); $reader_chunkdata->input($data); $method = 'parseData' . $structure_type; $chunk[$structure_type] = $this->{$method}($reader_chunkdata); } else { $chunk['Data'] = $data; } break; } // var_dump($chunk); $chunks[] = $chunk; } return $chunks; }