Diffs
IO_SWF/tags/2.0.19-stable-20111205020102/sample/jpeg_dump.php
@@ -0,0 +1,34 @@
+<?php
+
+require_once 'IO/SWF/JPEG.php';
+
+function usage() {
+ echo "Usage: php jpeg_dump.php <dump|jpegtables|imagedata>".PHP_EOL;
+}
+
+if ($argc != 3) {
+ usage();
+ exit(1);
+}
+
+$jpegdata = file_get_contents($argv[2]);
+
+$jpeg = new IO_SWF_JPEG();
+$jpeg->input($jpegdata);
+
+switch($argv[1]) {
+ case 'dump':
+ $jpeg->dumpChunk();
+ break;
+ case 'jpegtables':
+ echo $jpeg->getEncodingTables();
+ break;
+ case 'imagedata':
+ echo $jpeg->getImageData();
+ break;
+ default:
+ usage();
+ exit(1);
+}
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfconvlossless2pngjpeg.php
@@ -0,0 +1,62 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 2) {
+ echo "Usage: php swfconvlossless2pngjpeg.php <swf_file>\n";
+ echo "ex) php swfconvlossless2pngjpeg.php test.swf\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+foreach ($swf->_tags as &$tag) {
+ $tag_code = $tag->code;
+ if (($tag_code == 20) || // DefineBitsLossless
+ ($tag_code == 36)) { // DefineBitsLossless2
+ if ($tag->parseTagContent()) {
+ $cid = $tag->tag->_CharacterID;
+ $format = $tag->tag->_BitmapFormat;
+ $width = $tag->tag->_BitmapWidth;
+ $height = $tag->tag->_BitmapHeight;
+ $lossless_bitmap_data = gzuncompress($tag->tag->_ZlibBitmapData);
+ if ($format == 3) {
+ $palette_num = $tag->tag->_BitmapColorTableSize;
+ if ($tag_code == 20) { // DefineBisLossless
+ $palette_bytesize = 3 * $palette_num;
+ } else {
+ $palette_bytesize = 4 * $palette_num;
+ }
+ $palette_data = substr($lossless_bitmap_data, 0, $palette_bytesize);
+ $lossless_bitmap_data = substr($lossless_bitmap_data, $palette_bytesize);
+ } else {
+ $palette_num = 0;
+ $palette_data = null;
+ }
+ $png_data = IO_SWF_Lossless::Lossless2PNG($tag_code, $format,
+ $width, $height,
+ $palette_num,
+ $palette_data,
+ $lossless_bitmap_data);
+ $jpeg_tag = new IO_SWF_Tag_Jpeg();
+ $jpeg_tag->code = 21; // DefineBitsJPEG2
+ $jpeg_tag->_CharacterID = $cid;
+ $jpeg_tag->_JPEGData = $png_data; // SWF8 spec
+
+ $tag->code = 21; // DefineBitsJPEG2
+ $tag->tag = $jpeg_tag;
+
+ $tag->content = null;
+ }
+ }
+}
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfconvlossless2pngjpeg.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:mergeinfo
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfcopy.php
@@ -0,0 +1,22 @@
+<?php
+
+require 'IO/SWF.php';
+// require dirname(__FILE__).'/../IO/SWF.php';
+
+if ($argc != 2) {
+ echo "Usage: php swfcopy.php <swf_file>\n";
+ echo "ex) php swfdopy.php test.swf\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF();
+
+$swf->parse($swfdata);
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfcountshapeedges.php
@@ -0,0 +1,28 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 2) {
+ echo "Usage: php swfcountshapeedges.php <swf_file>\n";
+ echo "ex) php swfcountshapeedges.php test.swf\n";
+ exit(1);
+}
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$count_table = $swf->countShapeEdges();
+if ($count_table === false) {
+ printf("countShapeEdges return false\n");
+ exit(1);
+}
+
+foreach ($count_table as $shape_id => $count) {
+ echo "shape_id: $shape_id => edges_count: $count\n";
+}
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfcountshapeedges.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfdeformeshape.php
@@ -0,0 +1,26 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 3) {
+ fprintf(STDERR, "Usage: php swfdeformeshape.php <swf_file> <threshold>\n");
+ fprintf(STDERR, "ex) php swfdeformeshape.php test.swf 10 \n");
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_numeric($argv[2]));
+
+$swfdata = file_get_contents($argv[1]);
+$threshold = $argv[2];
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->deformeShape($threshold);
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfreplacebitmapdata.php
@@ -0,0 +1,36 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if (($argc != 4) && ($argc != 5)) {
+ echo "Usage: php swfreplacebitmapdata.php <swf_file> <bitmap_id> <bitmap_file> [<alpha_file>]\n";
+ echo "ex) php swfreplacebitmapdata.php test.swf 1 test.jpg test.alpha\n";
+ echo "ex) php swfreplacebitmapdata.php test.swf 1 test.png\n";
+ echo "ex) php swfreplacebitmapdata.php test.swf 1 test.git\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_numeric($argv[2]));
+assert(is_readable($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$bitmap_id = (int) $argv[2];
+$bitmapdata = file_get_contents($argv[3]);
+if (isset($argv[4])) { // with jpeg alphadata
+ assert(is_readable($argv[4]));
+ $jpeg_alphadata = file_get_contents($argv[4]);
+} else {
+ $jpeg_alphadata = null;
+}
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+// $swf->setShapeAdjustMode(IO_SWF_Editor::SHAPE_BITMAP_RECT_RESIZE);
+$ret = $swf->replaceBitmapData($bitmap_id, $bitmapdata, $jpeg_alphadata);
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfreplacebitmapdata.php
___________________________________________________________________
追加: svn:mergeinfo
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfsetactionvariables.php
@@ -0,0 +1,28 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 4) {
+ fprintf(STDERR, "Usage: php swfsetactiovaribles.phpp <swf_file> <from_str> <to_str>\n");
+ fprintf(STDERR, "ex) php swfactionvariables.php test.swf foo baa\n");
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+assert(isset($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$from_str = $argv[2];
+$to_str = $argv[3];
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->setActionVariables($from_str, $to_str);
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfreplaceactionstrings.php
@@ -0,0 +1,28 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 4) {
+ fprintf(STDERR, "Usage: php swfreplaceactionstrings.php <swf_file> <from_str> <to_str>\n");
+ fprintf(STDERR, "ex) php swfreplaceactionstrings.php test.swf foo baa\n");
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+assert(isset($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$from_str = $argv[2];
+$to_str = $argv[3];
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->replaceActionStrings($from_str, $to_str);
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfreplaceactionstrings.php
___________________________________________________________________
追加: svn:mergeinfo
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfreplacemovieclip.php
@@ -0,0 +1,30 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if (($argc != 4)) {
+ echo "Usage: php swfreplacemovieclip.php <swf_file> <target_path> <mc_swf_file>\n";
+ echo "ex) php swfreplacemovieclip.php negimiku2_mcnest.swf miku/negi saitama3.swf\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+assert(is_readable($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$target_path = $argv[2];
+$mc_swfdata = file_get_contents($argv[3]);
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+$ret = $swf->replaceMovieClip($target_path, $mc_swfdata);
+if ($ret === false) {
+ exit(1);
+}
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfsetbgcolor.php
@@ -0,0 +1,27 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 5) {
+ echo "Usage: php swfsetbgcolor.php <swf_file> <red> <green> <blue>\n";
+ echo "ex) php swfsetbgcolor.php test.swf 0 0 255\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_numeric($argv[2]));
+assert(is_numeric($argv[3]));
+assert(is_numeric($argv[4]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$color = pack('CCC', $argv[2], $argv[3], $argv[4]);
+$swf->replaceTagContent(9, $color);
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfactioneditor.php
@@ -0,0 +1,30 @@
+<?php
+
+require 'IO/SWF.php';
+// require dirname(__FILE__).'/../IO/SWF/ActionEditor.php';
+
+if ($argc != 2) {
+ echo "Usage: php swfactioneditor.php <swf_file>\n";
+ echo "ex) php swfactioneditor.php test.swf\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+$swf = new IO_SWF_ActionEditor();
+$swf->parse($swfdata);
+
+$opts = array();
+$swf->parseAllTagContent($opts);
+
+// Insert simple trace at main time line, frame 1, line 1.
+$swf->insertSimpleTrace(0, 1, 1, "(^_^)/ Hello, world.");
+
+// Insert trace which shows value of i at sprite1, frame 2, line 4.
+$swf->insertVarDumpTrace(1, 2, 4, "i");
+
+$swf->rebuild();
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfdump.php
@@ -0,0 +1,27 @@
+<?php
+
+require 'IO/SWF.php';
+// require dirname(__FILE__).'/../IO/SWF.php';
+
+$options = getopt("f:h");
+
+if (is_readable($options['f']) === false) {
+ echo "Usage: php swfdump.php -f <swf_file> [-h]\n";
+ echo "ex) php swfdump.php -f test.swf -h \n";
+ exit(1);
+}
+
+$swfdata = file_get_contents($options['f']);
+
+$swf = new IO_SWF();
+
+$swf->parse($swfdata);
+
+$opts = array();
+if (isset($options['h'])) {
+ $opts['hexdump'] = true;
+}
+
+$swf->dump($opts);
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/get_bitmapsize.php
@@ -0,0 +1,16 @@
+<?php
+
+require_once 'IO/SWF/Bitmap.php';
+// require_once './IO/SWF/Bitmap.php';
+
+if ($argc != 2) {
+ echo "Usage: php get_bitmapsize.php <bitmap_file>\n";
+ echo "ex) php get_bitmapsize.php test.jpg\n";
+ exit(1);
+}
+
+$bitmap_data = file_get_contents($argv[1]);
+
+$ret = IO_SWF_Bitmap::get_bitmapsize($bitmap_data);
+
+echo "width:{$ret['width']} height:{$ret['height']}\n";
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfrebuild.php
@@ -0,0 +1,23 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 2) {
+ echo "Usage: php swfrebuild.php <swf_file>\n";
+ echo "ex) php swfrebuild.php test.swf\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->rebuild();
+
+echo $swf->build();
+
+exit(0);
IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfreplaceeditstring.php
@@ -0,0 +1,31 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 4) {
+ echo "Usage: php swfreplaceeditstring.php <swf_file> <id> <initial_text>\n";
+ echo "ex) php swfreplaceeditstring.php test.swf 1 baa\n";
+ echo "ex) php swfreplaceeditstring.php test.swf foo baa\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+$id = $argv[2];
+$initialText = $argv[3];
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+$ret = $swf->replaceEditString($id, $initialText);
+
+if ($ret === false) {
+ echo "failed to replaceEditString($id, $initialText)\n";
+ exit(1);
+}
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/sample/swfreplaceeditstring.php
___________________________________________________________________
追加: svn:mergeinfo
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Former.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * 2010/8/12- (c) yoya@awm.jp
+ */
+
+require_once dirname(__FILE__).'/../SWF.php';
+
+class IO_SWF_Former extends IO_SWF {
+ // var $_headers = array(); // protected
+ // var $_tags = array(); // protected
+
+ function form() {
+ foreach ($this->_tags as $idx => $tag) {
+ switch ($tag['Code']) {
+ case 26: // PlaceObject2
+ $this->_form_26($tag);
+ break;
+ }
+ }
+ }
+ function _form_26($tag) { // PlaceObject2
+ $reader = new IO_Bit();
+ $reader->input($tab['Content']);
+ $placeFlag = $reader->getUI8();
+ $depth = $reader->getUI16LE();
+ if ($placeFlag & 0x02) {
+ $characterId = $reader->getUI16LE();
+ }
+ //
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag.php
@@ -0,0 +1,306 @@
+<?php
+
+require_once dirname(__FILE__).'/../SWF.php';
+require_once dirname(__FILE__).'/../SWF/Tag/Shape.php';
+
+class IO_SWF_Tag {
+ var $swfInfo;
+ var $code = 0;
+ var $content = null;
+ var $tag = null;
+ var $byte_offset, $byte_size;
+ function __construct($swfInfo) {
+ $this->swfInfo = $swfInfo;
+ }
+ function getTagInfo($tagCode, $label) {
+ static $tagMap = array(
+ // code => array(name , klass)
+ 0 => array('name' => 'End'),
+ 1 => array('name' => 'ShowFrame'),
+ 2 => array('name' => 'DefineShape', 'klass' => 'Shape'),
+// 3 => array('name' => 'FreeCharacter'), // ???
+ 4 => array('name' => 'PlaceObject', 'klass' => 'Place'),
+ 5 => array('name' => 'RemoveObject', 'klass' => 'Remove'),
+ 6 => array('name' => 'DefineBits', 'klass' => 'Jpeg'),
+ 7 => array('name' => 'DefineButton', 'klass' => 'Button'),
+ 8 => array('name' => 'JPEGTables', 'klass' => 'Jpeg'),
+ 9 => array('name' => 'SetBackgroundColor', 'klass' => 'BGColor'),
+ 10 => array('name' => 'DefineFont'),
+ 11 => array('name' => 'DefineText', 'klass' => 'Text'),
+ 12 => array('name' => 'DoAction', 'klass' => 'Action'),
+ 13 => array('name' => 'DefineFontInfo'),
+ 14 => array('name' => 'DefineSound'),
+ 15 => array('name' => 'StartSound'),
+ // 16 missing
+ 17 => array('name' => 'DefineButtonSound'),
+ 18 => array('name' => 'SoundStreamHead'),
+ 19 => array('name' => 'SoundStreamBlock'),
+ 20 => array('name' => 'DefineBitsLossless', 'klass' => 'Lossless'),
+ 21 => array('name' => 'DefineBitsJPEG2', 'klass' => 'Jpeg'),
+ 22 => array('name' => 'DefineShape2', 'klass' => 'Shape'),
+ 24 => array('name' => 'Protect'),
+ // 25 missing
+ 26 => array('name' => 'PlaceObject2', 'klass' => 'Place'),
+ // 27 missing
+ 28 => array('name' => 'RemoveObject2', 'klass' => 'Remove'),
+ // 29,30,31 missing
+ 32 => array('name' => 'DefineShape3', 'klass' => 'Shape'),
+ 33 => array('name' => 'DefineText2', 'klass' => 'Text'),
+ 34 => array('name' => 'DefineButton2', 'klass' => 'Button'),
+ 35 => array('name' => 'DefineBitsJPEG3', 'klass' => 'Jpeg'),
+ 36 => array('name' => 'DefineBitsLossless2', 'klass' => 'Lossless'),
+ 37 => array('name' => 'DefineEditText', 'klass' => 'EditText'),
+ // 38 missing
+ 39 => array('name' => 'DefineSprite', 'klass' => 'Sprite'),
+ // 40,41,42 missing
+ 43 => array('name' => 'FrameLabel', 'klass' => 'FrameLabel'),
+ // 44 missing
+ 45 => array('name' => 'SoundStreamHead2'),
+ 46 => array('name' => 'DefineMorphShape', 'klass' => 'Shape'),
+ 48 => array('name' => 'DefineFont2'),
+ 56 => array('name' => 'Export'),
+ 57 => array('name' => ''),
+ 58 => array('name' => ''),
+ 59 => array('name' => 'DoInitAction', 'klass' => 'Action'),
+ //
+ 60 => array('name' => 'DefineVideoStream'),
+ 61 => array('name' => 'videoFrame'),
+ 62 => array('name' => 'DefineFontInfo2'),
+ // 63 missing
+ 64 => array('name' => 'EnableDebugger2'),
+ 65 => array('name' => 'ScriptLimits'),
+ 66 => array('name' => 'SetTabIndex'),
+ // 67,68 missing
+ 69 => array('name' => 'FileAttributes'),
+ 70 => array('name' => 'PlaceObject3'),
+ 71 => array('name' => 'ImportAssets2'),
+ // 72 missing
+ 73 => array('name' => 'DefineFontAlignZones'),
+ 74 => array('name' => 'CSMTextSettings'),
+ 75 => array('name' => 'DefineFont3'),
+ 76 => array('name' => 'SymbolClass'),
+ 77 => array('name' => 'MetaData'),
+ 78 => array('name' => 'DefineScalingGrid'),
+ // 79,80,81 missing
+ 82 => array('name' => 'DoABC'),
+ 83 => array('name' => 'DefineShape4'),
+ 84 => array('name' => 'DefineMorphShape2'),
+ // 85 missing
+ 86 => array('name' => 'DefineSceneAndFrameLabelData'),
+ 87 => array('name' => 'DefineBinaryData'),
+ 88 => array('name' => 'DefineFontName'),
+ 89 => array('name' => 'StartSound2'),
+ 90 => array('name' => 'DefineBitsJPEG4'),
+ 91 => array('name' => 'DefineFont4'),
+ 777 => array('name' => 'Reflex'), // swftools ?
+ );
+ if (isset($tagMap[$tagCode][$label])) {
+ return $tagMap[$tagCode][$label];
+ }
+ return false;
+ }
+ function parse(&$reader, $opts = array()) {
+ list($this->byte_offset, $dummy) = $reader->getOffset();
+ $tagAndLength = $reader->getUI16LE();
+ $this->code = $tagAndLength >> 6;
+ $length = $tagAndLength & 0x3f;
+ if ($length == 0x3f) { // long format
+ $length = $reader->getUI32LE();
+ }
+ $this->content = $reader->getData($length);
+ list($byte_offset, $dummy) = $reader->getOffset();
+ $this->byte_size = $byte_offset - $this->byte_offset;
+ }
+ function dump($opts = array()) {
+ $code = $this->code;
+ $name = $this->getTagInfo($code, 'name');
+ if ($name === false) {
+ $name = 'unknown';
+ }
+ $length = strlen($this->content);
+ echo "Code: $code($name) Length: $length".PHP_EOL;
+ $opts['Version'] = $this->swfInfo['Version'];
+ if ($this->parseTagContent($opts)) {
+ $this->tag->dumpContent($code, $opts);
+ }
+ if (empty($opts['hexdump']) === false) {
+ $bitio =& $opts['bitio'];
+ $bitio->hexdump($this->byte_offset, $this->byte_size);
+ }
+ }
+ function build($opts = array()) {
+ $code = $this->code;
+ if (is_null($this->content)) {
+ $this->content = $this->buildTagContent();
+ }
+ $length = strlen($this->content);
+ $writer = new IO_Bit();
+ switch ($code) {
+ case 6: // DefineBitsJPEG
+ case 21: // DefineBitsJPEG2
+ case 35: // DefineBitsJPEG3
+ case 20: // DefineBitsLossless
+ case 36: // DefineBitsLossless2
+ case 19: // SoundStreamBlock
+ $longFormat = true;
+ break;
+ default:
+ $longFormat = false;
+ break;
+ }
+ if (($longFormat === false) && ($length < 0x3f)) {
+ $tagAndLength = ($code << 6) | $length;
+ $writer->putUI16LE($tagAndLength);
+ } else {
+ $tagAndLength = ($code << 6) | 0x3f;
+ $writer->putUI16LE($tagAndLength);
+ $writer->putUI32LE($length);
+ }
+ return $writer->output() . $this->content;
+ }
+ function parseTagContent() {
+ if (is_null($this->tag) === false) {
+ return true;
+ }
+ $code = $this->code;
+ $klass = self::getTagInfo($code, 'klass');
+ if ($klass === false) {
+ return false; // no parse
+ }
+ require_once dirname(__FILE__)."/Tag/$klass.php";
+ $klass = "IO_SWF_Tag_$klass";
+ $obj = new $klass($this->swfInfo);
+ $opts['Version'] = $this->swfInfo['Version'];
+ $obj->parseContent($code, $this->content, $opts);
+ $this->tag = $obj;
+ return true;
+ }
+ function buildTagContent() {
+ if ((is_null($this->content) === false)) {
+ return $this->content;
+ }
+ if (is_null($this->tag)) {
+ return false; // throw Exception!
+ }
+ $code = $this->code;
+ $opts['Version'] = $this->swfInfo['Version'];
+ $this->content = $this->tag->buildContent($code, $opts); // XXX
+ return $this->content;
+ }
+
+ function bitmapSize() {
+ $code = $this->code;
+ if ($this->parseTagContent() === false) {
+ throw new IO_SWF_Exception("failed to parseTagContent");
+ }
+ switch ($code) {
+ case 6: // DefineBitsJPEG
+ case 21: // DefineBitsJPEG2
+ case 35: // DefineBitsJPEG3
+ ;
+ break;
+ case 20: // DefineBitsLossless
+ case 36: // DefineBitsLossless2
+ break;
+ default:
+ break;
+ }
+ }
+ function replaceCharacterId($trans_table) {
+ $new_cid = $trans_table[$this->characterId];
+ if ($new_cid == $this->characterId) {
+ return true; // no change
+ }
+ $this->characterId = $new_cid;
+ if (isset($this->content)) {
+ $this->content[0] = chr($new_cid & 0xff);
+ $this->content[1] = chr($new_cid >> 8);
+ }
+ if (isset($this->tag)) {
+ switch ($this->code) {
+ case 6: // DefineBits
+ case 21: // DefineBitsJPEG2
+ case 35: // DefineBitsJPEG3
+ case 20: // DefineBitsLossless
+ case 36: // DefineBitsLossless2
+ case 2: // DefineShape (ShapeId)
+ case 22: // DefineShape2 (ShapeId)
+ case 32: // DefineShape3 (ShapeId)
+ case 46: // DefineMorphShape (ShapeId)
+ case 11: // DefineText
+ case 33: // DefineText2
+ case 37: // DefineTextEdit
+ case 39: // DefineSprite
+ foreach (array('_CharacterID', '_spriteId', '_shapeId', 'CharacterID') as $id_prop_name) {
+ if (isset($this->tag->$id_prop_name)) {
+ $this->tag->$id_prop_name = $new_cid;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ return true;
+ }
+ function replaceReferenceId($trans_table) {
+ if ($this->parseTagContent() === false) {
+ new IO_SWF_Exception("parseTagContent failed");
+ }
+ switch ($this->code) {
+ case 4: // PlaceObject
+ case 5: // RemoveObject
+ case 26: // PlaceObject2 (Shape Reference)
+ if (isset($this->tag->_characterId)) {
+ $new_cid = $trans_table[$this->tag->_characterId];
+ if ($this->tag->_characterId != $new_cid) {
+ $this->tag->_characterId = $new_cid;
+ $this->content = null;
+ }
+ }
+ break;
+ case 2: // DefineShape (Bitmap ReferenceId)
+ case 22: // DefineShape2 (Bitmap ReferenceId)
+ case 32: // DefineShape3 (Bitmap ReferenceId)
+ case 46: // DefineMorphShape (Bitmap ReferenceId)
+ if ($this->parseTagContent() === false) {
+ throw new IO_SWF_Exception("failed to parseTagContent");
+ }
+ $modified = false;
+ if (is_null($this->tag->_fillStyles) === false) {
+ foreach ($this->tag->_fillStyles as &$fillStyle) {
+ if (isset($fillStyle['BitmapId'])) {
+ if ($fillStyle['BitmapId'] != 65535) {
+ $new_id = $trans_table[$fillStyle['BitmapId']];
+ if ($fillStyle['BitmapId'] != $new_id) {
+ $modified = true;
+ $fillStyle['BitmapId'] = $new_id;
+ }
+ }
+ }
+ }
+ }
+ if (is_null($this->tag->_shapeRecords) === false) {
+ foreach ($this->tag->_shapeRecords as &$shapeRecord) {
+ if (isset($shapeRecord['FillStyles'])) {
+ foreach ($shapeRecord['FillStyles'] as &$fillStyle) {
+ if (isset($fillStyle['BitmapId'])) {
+ if ($fillStyle['BitmapId'] != 65535) {
+ $new_id = $trans_table[$fillStyle['BitmapId']];
+ if ($fillStyle['BitmapId'] != $new_id) {
+ $modified = true;
+ $fillStyle['BitmapId'] = $new_id;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if ($modified) {
+ $this->content = null;
+ }
+ break;
+ }
+ return true;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/RECT.php
@@ -0,0 +1,44 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_RECT extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $frameSize = array();
+ $reader->byteAlign();
+ $nBits = $reader->getUIBits(5);
+ $frameSize['Xmin'] = $reader->getSIBits($nBits);
+ $frameSize['Xmax'] = $reader->getSIBits($nBits);
+ $frameSize['Ymin'] = $reader->getSIBits($nBits);
+ $frameSize['Ymax'] = $reader->getSIBits($nBits) ;
+ return $frameSize;
+ }
+ static function build(&$writer, $frameSize, $opts = array()) {
+ $nBits = 0;
+ foreach ($frameSize as $size) {
+ if ($size == 0){
+ $bits = 0;
+ } else {
+ $bits = $writer->need_bits_signed($size);
+ }
+ $nBits = max($nBits, $bits);
+ }
+ $writer->byteAlign();
+ $writer->putUIBits($nBits, 5);
+ $writer->putSIBits($frameSize['Xmin'], $nBits);
+ $writer->putSIBits($frameSize['Xmax'], $nBits);
+ $writer->putSIBits($frameSize['Ymin'], $nBits);
+ $writer->putSIBits($frameSize['Ymax'], $nBits);
+ }
+ static function string($rect, $opts = array()) {
+ return "Xmin: ".($rect['Xmin'] / 20).
+ " Xmax: ".($rect['Xmax'] / 20).
+ " Ymin: ".($rect['Ymin'] / 20).
+ " Ymax: ".($rect['Ymax'] / 20);
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/RECT.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/CXFORM.php
@@ -0,0 +1,86 @@
+<?php
+
+/*
+ * 2011/7/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_CXFORM extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $cxform = array();
+ $reader->byteAlign();
+ $hasAddTerms = $reader->getUIBit();
+ $hasMultiTerms = $reader->getUIBit();
+ $cxform['HasAddTerms'] = $hasAddTerms;
+ $cxform['HasMultiTerms'] = $hasMultiTerms;
+ $nbits = $reader->getUIBits(4);
+ if ($hasMultiTerms) {
+ $cxform['RedMultiTerm'] = $reader->getSIBits($nbits);
+ $cxform['GreenMultiTerm'] = $reader->getSIBits($nbits);
+ $cxform['BlueMultiTerm'] = $reader->getSIBits($nbits);
+ }
+ if ($hasAddTerms) {
+ $cxform['RedAddTerm'] = $reader->getSIBits($nbits);
+ $cxform['GreenAddTerm'] = $reader->getSIBits($nbits);
+ $cxform['BlueAddTerm'] = $reader->getSIBits($nbits);
+ }
+ return $cxform;
+ }
+ static function build(&$writer, $cxform, $opts = array()) {
+ $nbits = 0;
+ $hasAddTerms = 0;
+ $hasMultiTerms = 0;
+ $multi_term_list = array('RedMultiTerm', 'GreenMultiTerm', 'BlueMultiTerm');
+ $writer->byteAlign();
+ foreach ($multi_term_list as $term) {
+ if (isset($cxform[$term])) {
+ $hasMultiTerms = 1;
+ $need_bits = $writer->need_bits_signed($cxform[$term]);
+ if ($nbits < $need_bits){
+ $nbits = $need_bits;
+ }
+ }
+ }
+ $add_term_list = array('RedAddTerm', 'GreenAddTerm', 'BlueAddTerm');
+ foreach ($add_term_list as $term) {
+ if (isset($cxform[$term])) {
+ $hasAddTerms = 1;
+ $need_bits = $writer->need_bits_signed($cxform[$term]);
+ if ($nbits < $need_bits){
+ $nbits = $need_bits;
+ }
+ }
+ }
+ $writer->putUIBit($hasAddTerms);
+ $writer->putUIBit($hasMultiTerms);
+ $writer->putUIBits($nbits, 4);
+ if ($hasMultiTerms) {
+ $writer->putSIBits($cxform['RedMultiTerm'], $nbits);
+ $writer->putSIBits($cxform['GreenMultiTerm'], $nbits);
+ $writer->putSIBits($cxform['BlueMultiTerm'], $nbits);
+ }
+ if ($hasAddTerms) {
+ $writer->putSIBits($cxform['RedAddTerm'], $nbits);
+ $writer->putSIBits($cxform['GreenAddTerm'], $nbits);
+ $writer->putSIBits($cxform['BlueAddTerm'], $nbits);
+ }
+ }
+ static function string($cxform, $opts = array()) {
+ if (($cxform['HasMultiTerms'] == 0) && ($cxform['HasAddTerms'] == 0)) {
+ return '(No Data: CXFORM)';
+ }
+ $text = '';
+ if ($cxform['HasMultiTerms']) {
+ $text .= sprintf("MultiTerms:(%d,%d,%d)", $cxform['RedMultiTerm'], $cxform['GreenMultiTerm'], $cxform['BlueMultiTerm']);
+ }
+ if ($cxform['HasAddTerms']) {
+ if ($cxform['HasMultiTerms']) {
+ $text .= ' ';
+ }
+ $text .= sprintf("AddTerms:(%d,%d,%d)", $cxform['RedAddTerm'], $cxform['GreenAddTerm'], $cxform['BlueAddTerm']);
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/CXFORM.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/SHAPE.php
@@ -0,0 +1,330 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/../Type/FILLSTYLEARRAY.php';
+require_once dirname(__FILE__).'/../Type/LINESTYLEARRAY.php';
+
+class IO_SWF_Type_SHAPE extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $shapeRecords = array();
+
+ $reader->byteAlign();
+ // 描画スタイルを参照するインデックスのビット幅
+ $numFillBits = $reader->getUIBits(4);
+ $numLineBits = $reader->getUIBits(4);
+
+ $currentDrawingPositionX = 0;
+ $currentDrawingPositionY = 0;
+ $currentFillStyle0 = 0;
+ $currentFillStyle1 = 0;
+ $currentLineStyle = 0;
+ $done = false;
+
+ // ShapeRecords
+ while ($done === false) {
+ $shapeRecord = array();
+ $typeFlag = $reader->getUIBit();
+ $shapeRecord['TypeFlag'] = $typeFlag;
+ if ($typeFlag == 0) {
+ $endOfShape = $reader->getUIBits(5);
+ if ($endOfShape == 0) {
+ // EndShapeRecord
+ $shapeRecord['EndOfShape'] = $endOfShape;
+ $done = true;
+ } else {
+ // StyleChangeRecord
+ $reader->incrementOffset(0, -5);
+ $stateNewStyles = $reader->getUIBit();
+ $stateLineStyle = $reader->getUIBit();
+ $stateFillStyle1 = $reader->getUIBit();
+ $stateFillStyle0 = $reader->getUIBit();
+
+ $stateMoveTo = $reader->getUIBit();
+ if ($stateMoveTo) {
+ $moveBits = $reader->getUIBits(5);
+// $shapeRecord['(MoveBits)'] = $moveBits;
+ $moveDeltaX = $reader->getSIBits($moveBits);
+ $moveDeltaY = $reader->getSIBits($moveBits);
+// $currentDrawingPositionX += $moveDeltaX;
+// $currentDrawingPositionY += $moveDeltaY;
+ $currentDrawingPositionX = $moveDeltaX;
+ $currentDrawingPositionY = $moveDeltaY;
+ $shapeRecord['MoveX'] = $currentDrawingPositionX;
+ $shapeRecord['MoveY'] = $currentDrawingPositionY;
+ }
+ $shapeRecord['MoveX'] = $currentDrawingPositionX;
+ $shapeRecord['MoveY'] = $currentDrawingPositionY;
+
+ if ($stateFillStyle0) {
+ $currentFillStyle0 = $reader->getUIBits($numFillBits);
+ }
+ if ($stateFillStyle1) {
+ $currentFillStyle1 = $reader->getUIBits($numFillBits);
+ }
+ if ($stateLineStyle) {
+ $currentLineStyle = $reader->getUIBits($numLineBits);
+ }
+ $shapeRecord['FillStyle0'] = $currentFillStyle0;
+ $shapeRecord['FillStyle1'] = $currentFillStyle1;
+ $shapeRecord['LineStyle'] = $currentLineStyle;
+ if ($stateNewStyles) {
+ $opts = array('tagCode' => $tagCode);
+ $shapeRecord['FillStyles'] = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
+ $shapeRecord['LineStyles'] = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
+ $reader->byteAlign();
+ $numFillBits = $reader->getUIBits(4);
+ $numLineBits = $reader->getUIBits(4);
+ }
+ }
+ } else { // Edge records
+ $shapeRecord['StraightFlag'] = $reader->getUIBit();
+ if ($shapeRecord['StraightFlag']) {
+ // StraightEdgeRecord
+ $numBits = $reader->getUIBits(4);
+// $shapeRecord['(NumBits)'] = $numBits;
+ $generalLineFlag = $reader->getUIBit();
+ if ($generalLineFlag == 0) {
+ $vertLineFlag = $reader->getUIBit();
+ }
+ if ($generalLineFlag || ($vertLineFlag == 0)) {
+ $deltaX = $reader->getSIBits($numBits + 2);
+ $currentDrawingPositionX += $deltaX;
+ }
+ if ($generalLineFlag || $vertLineFlag) {
+ $deltaY = $reader->getSIBits($numBits + 2);
+ $currentDrawingPositionY += $deltaY;
+ }
+ $shapeRecord['X'] = $currentDrawingPositionX;
+ $shapeRecord['Y'] = $currentDrawingPositionY;
+ } else {
+ // CurvedEdgeRecord
+ $numBits = $reader->getUIBits(4);
+// $shapeRecord['(NumBits)'] = $numBits;
+
+ $controlDeltaX = $reader->getSIBits($numBits + 2);
+ $controlDeltaY = $reader->getSIBits($numBits + 2);
+ $anchorDeltaX = $reader->getSIBits($numBits + 2);
+ $anchorDeltaY = $reader->getSIBits($numBits + 2);
+
+ $currentDrawingPositionX += $controlDeltaX;
+ $currentDrawingPositionY += $controlDeltaY;
+ $shapeRecord['ControlX'] = $currentDrawingPositionX;
+ $shapeRecord['ControlY'] = $currentDrawingPositionY;
+
+ $currentDrawingPositionX += $anchorDeltaX;
+ $currentDrawingPositionY += $anchorDeltaY;
+ $shapeRecord['AnchorX'] = $currentDrawingPositionX;
+ $shapeRecord['AnchorY'] = $currentDrawingPositionY;
+ }
+ }
+ $shapeRecords []= $shapeRecord;
+ }
+ return $shapeRecords;
+ }
+ static function build(&$writer, $shapeRecords, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $fillStyleCount = $opts['fillStyleCount'];
+ $lineStyleCount = $opts['lineStyleCount'];
+ if ($fillStyleCount == 0) {
+ $numFillBits = 0;
+ } else {
+ // $fillStyleCount == fillStyle MaxValue because 'undefined' use 0
+ $numFillBits = $writer->need_bits_unsigned($fillStyleCount);
+ }
+ if ($lineStyleCount == 0) {
+ $numLineBits = 0;
+ } else {
+ // $lineStyleCount == lineStyle MaxValue because 'undefined' use 0
+ $numLineBits = $writer->need_bits_unsigned($lineStyleCount);
+ }
+
+ $writer->byteAlign();
+ $writer->putUIBits($numFillBits, 4);
+ $writer->putUIBits($numLineBits, 4);
+ $currentDrawingPositionX = 0;
+ $currentDrawingPositionY = 0;
+ $currentFillStyle0 = 0;
+ $currentFillStyle1 = 0;
+ $currentLineStyle = 0;
+ foreach ($shapeRecords as $shapeRecordIndex => $shapeRecord) {
+ $typeFlag = $shapeRecord['TypeFlag'];
+ $writer->putUIBit($typeFlag);
+ if($typeFlag == 0) {
+ if (isset($shapeRecord['EndOfShape']) && ($shapeRecord['EndOfShape']) == 0) {
+ // EndShapeRecord
+ $writer->putUIBits(0, 5);
+ } else {
+ // StyleChangeRecord
+ $stateNewStyles = isset($shapeRecord['FillStyles'])?1:0;
+ $stateLineStyle = ($shapeRecord['LineStyle'] != $currentLineStyle)?1:0;
+ $stateFillStyle1 = ($shapeRecord['FillStyle1'] != $currentFillStyle1)?1:0;
+ $stateFillStyle0 = ($shapeRecord['FillStyle0'] != $currentFillStyle0)?1:0;
+
+ $writer->putUIBit($stateNewStyles);
+ $writer->putUIBit($stateLineStyle);
+ $writer->putUIBit($stateFillStyle1);
+ $writer->putUIBit($stateFillStyle0);
+
+ if (($shapeRecord['MoveX'] != $currentDrawingPositionX) || ($shapeRecord['MoveY'] != $currentDrawingPositionY)) {
+ $stateMoveTo = true;
+ } else {
+ $stateMoveTo = false;
+ }
+ $writer->putUIBit($stateMoveTo);
+ if ($stateMoveTo) {
+ $moveX = $shapeRecord['MoveX'];
+ $moveY = $shapeRecord['MoveY'];
+ $currentDrawingPositionX = $moveX;
+ $currentDrawingPositionY = $moveY;
+ if ($moveX | $moveY) {
+ $XmoveBits = $writer->need_bits_signed($moveX);
+ $YmoveBits = $writer->need_bits_signed($moveY);
+ $moveBits = max($XmoveBits, $YmoveBits);
+ } else {
+ $moveBits = 0;
+ }
+ $writer->putUIBits($moveBits, 5);
+ $writer->putSIBits($moveX, $moveBits);
+ $writer->putSIBits($moveY, $moveBits);
+ }
+ if ($stateFillStyle0) {
+ $currentFillStyle0 = $shapeRecord['FillStyle0'];
+ $writer->putUIBits($currentFillStyle0, $numFillBits);
+ }
+ if ($stateFillStyle1) {
+ $currentFillStyle1 = $shapeRecord['FillStyle1'];
+ $writer->putUIBits($currentFillStyle1, $numFillBits);
+ }
+ if ($stateLineStyle) {
+ $currentLineStyle = $shapeRecord['LineStyle'];
+ $writer->putUIBits($currentLineStyle, $numLineBits);
+ }
+ if ($stateNewStyles) {
+ $opts = array('tagCode' => $tagCode);
+ IO_SWF_Type_FILLSTYLEARRAY::build($writer, $shapeRecord['FillStyles'], $opts);
+ IO_SWF_Type_LINESTYLEARRAY::build($writer, $shapeRecord['LineStyles'], $opts);
+ $fillStyleCount = count($shapeRecord['FillStyles']);
+ if ($fillStyleCount == 0) {
+ $numFillBits = 0;
+ } else {
+ // $fillStyleCount == fillStyle MaxValue because 'undefined' use 0
+ $numFillBits = $writer->need_bits_unsigned($fillStyleCount);
+ }
+ if ($lineStyleCount == 0) {
+ $numLineBits = 0;
+ } else {
+ // $lineStyleCount == lineStyle MaxValue because 'undefined' use 0
+ $numLineBits = $writer->need_bits_unsigned($lineStyleCount);
+ }
+ $writer->byteAlign();
+ $writer->putUIBits($numFillBits, 4);
+ $writer->putUIBits($numLineBits, 4);
+ }
+ }
+ } else {
+ $straightFlag = $shapeRecord['StraightFlag'];
+ $writer->putUIBit($straightFlag);
+ if ($straightFlag) {
+ $deltaX = $shapeRecord['X'] - $currentDrawingPositionX;
+ $deltaY = $shapeRecord['Y'] - $currentDrawingPositionY;
+ if ($deltaX | $deltaY) {
+ $XNumBits = $writer->need_bits_signed($deltaX);
+ $YNumBits = $writer->need_bits_signed($deltaY);
+ $numBits = max($XNumBits, $YNumBits);
+ } else {
+ $numBits = 0;
+ }
+ if ($numBits < 2) {
+ $numBits = 2;
+ }
+ $writer->putUIBits($numBits - 2, 4);
+ if ($deltaX && $deltaY) {
+ $writer->putUIBit(1); // GeneralLineFlag
+ $writer->putSIBits($deltaX, $numBits);
+ $writer->putSIBits($deltaY, $numBits);
+ } else {
+ $writer->putUIBit(0); // GeneralLineFlag
+ if ($deltaX) {
+ $writer->putUIBit(0); // VertLineFlag
+ $writer->putSIBits($deltaX, $numBits);
+ } else {
+ $writer->putUIBit(1); // VertLineFlag
+ $writer->putSIBits($deltaY, $numBits);
+ }
+ }
+ $currentDrawingPositionX = $shapeRecord['X'];
+ $currentDrawingPositionY = $shapeRecord['Y'];
+ } else {
+ $controlDeltaX = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+ $controlDeltaY = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+ $currentDrawingPositionX = $shapeRecord['ControlX'];
+ $currentDrawingPositionY = $shapeRecord['ControlY'];
+ $anchorDeltaX = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+ $anchorDeltaY = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+ $currentDrawingPositionX = $shapeRecord['AnchorX'];
+ $currentDrawingPositionY = $shapeRecord['AnchorY'];
+
+ $numBitsControlDeltaX = $writer->need_bits_signed($controlDeltaX);
+ $numBitsControlDeltaY = $writer->need_bits_signed($controlDeltaY);
+ $numBitsAnchorDeltaX = $writer->need_bits_signed($anchorDeltaX);
+ $numBitsAnchorDeltaY = $writer->need_bits_signed($anchorDeltaY);
+ $numBits = max($numBitsControlDeltaX, $numBitsControlDeltaY, $numBitsAnchorDeltaX, $numBitsAnchorDeltaY);
+ if ($numBits < 2) {
+ $numBits = 2;
+ }
+ $writer->putUIBits($numBits - 2, 4);
+ $writer->putSIBits($controlDeltaX, $numBits);
+ $writer->putSIBits($controlDeltaY, $numBits);
+ $writer->putSIBits($anchorDeltaX, $numBits);
+ $writer->putSIBits($anchorDeltaY, $numBits);
+ }
+ }
+ }
+ return true;
+ }
+ static function string($shapeRecords, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ foreach ($shapeRecords as $shapeRecord) {
+ $typeFlag = $shapeRecord['TypeFlag'];
+ if ($typeFlag == 0) {
+ if (isset($shapeRecord['EndOfShape'])) {
+ break;
+ } else {
+ $moveX = $shapeRecord['MoveX'] / 20;
+ $moveY = $shapeRecord['MoveY'] / 20;
+ echo "\tChangeStyle: MoveTo: ($moveX, $moveY)";
+ $style_list = array('FillStyle0', 'FillStyle1', 'LineStyle');
+ echo " FillStyle: ".$shapeRecord['FillStyle0']."|".$shapeRecord['FillStyle1'];
+ echo " LineStyle: ".$shapeRecord['LineStyle']."\n";
+ if (isset($shapeRecord['FillStyles'])) {
+ echo " FillStyles:\n";
+ echo IO_SWF_Type_FILLSTYLEARRAY::string($shapeRecord['FillStyles'], $opts);
+ }
+ if (isset($shapeRecord['LineStyles'])) {
+ echo " LineStyles:\n";
+ echo IO_SWF_Type_LINESTYLEARRAY::string($shapeRecord['LineStyles'], $opts);
+ }
+ }
+ } else {
+ $straightFlag = $shapeRecord['StraightFlag'];
+ if ($straightFlag) {
+ $x = $shapeRecord['X'] / 20;
+ $y = $shapeRecord['Y'] / 20;
+ echo "\tStraightEdge: MoveTo: ($x, $y)\n";
+ } else {
+ $controlX = $shapeRecord['ControlX'] / 20;
+ $controlY = $shapeRecord['ControlY'] / 20;
+ $anchorX = $shapeRecord['AnchorX'] / 20;
+ $anchorY = $shapeRecord['AnchorY'] / 20;
+ echo "\tCurvedEdge: MoveTo: Control($controlX, $controlY) Anchor($anchorX, $anchorY)\n";
+ }
+ }
+ }
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/SHAPE.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/CXFORMWITHALPHA.php
@@ -0,0 +1,90 @@
+<?php
+
+/*
+ * 2011/7/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_CXFORMWITHALPHA extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $cxform = array();
+ $reader->byteAlign();
+ $hasAddTerms = $reader->getUIBit();
+ $hasMultiTerms = $reader->getUIBit();
+ $cxform['HasAddTerms'] = $hasAddTerms;
+ $cxform['HasMultiTerms'] = $hasMultiTerms;
+ $nbits = $reader->getUIBits(4);
+ if ($hasMultiTerms) {
+ $cxform['RedMultiTerm'] = $reader->getSIBits($nbits);
+ $cxform['GreenMultiTerm'] = $reader->getSIBits($nbits);
+ $cxform['BlueMultiTerm'] = $reader->getSIBits($nbits);
+ $cxform['AlphaMultiTerm'] = $reader->getSIBits($nbits);
+ }
+ if ($hasAddTerms) {
+ $cxform['RedAddTerm'] = $reader->getSIBits($nbits);
+ $cxform['GreenAddTerm'] = $reader->getSIBits($nbits);
+ $cxform['BlueAddTerm'] = $reader->getSIBits($nbits);
+ $cxform['AlphaAddTerm'] = $reader->getSIBits($nbits);
+ }
+ return $cxform;
+ }
+ static function build(&$writer, $cxform, $opts = array()) {
+ $nbits = 0;
+ $hasAddTerms = 0;
+ $hasMultiTerms = 0;
+ $multi_term_list = array('RedMultiTerm', 'GreenMultiTerm', 'BlueMultiTerm', 'AlphaMultiTerm');
+ $writer->byteAlign();
+ foreach ($multi_term_list as $term) {
+ if (isset($cxform[$term])) {
+ $hasMultiTerms = 1;
+ $need_bits = $writer->need_bits_signed($cxform[$term]);
+ if ($nbits < $need_bits){
+ $nbits = $need_bits;
+ }
+ }
+ }
+ $add_term_list = array('RedAddTerm', 'GreenAddTerm', 'BlueAddTerm', 'AlphaAddTerm');
+ foreach ($add_term_list as $term) {
+ if (isset($cxform[$term])) {
+ $hasAddTerms = 1;
+ $need_bits = $writer->need_bits_signed($cxform[$term]);
+ if ($nbits < $need_bits){
+ $nbits = $need_bits;
+ }
+ }
+ }
+ $writer->putUIBit($hasAddTerms);
+ $writer->putUIBit($hasMultiTerms);
+ $writer->putUIBits($nbits, 4);
+ if ($hasMultiTerms) {
+ $writer->putSIBits($cxform['RedMultiTerm'] , $nbits);
+ $writer->putSIBits($cxform['GreenMultiTerm'], $nbits);
+ $writer->putSIBits($cxform['BlueMultiTerm'] , $nbits);
+ $writer->putSIBits($cxform['AlphaMultiTerm'], $nbits);
+ }
+ if ($hasAddTerms) {
+ $writer->putSIBits($cxform['RedAddTerm'] , $nbits);
+ $writer->putSIBits($cxform['GreenAddTerm'], $nbits);
+ $writer->putSIBits($cxform['BlueAddTerm'] , $nbits);
+ $writer->putSIBits($cxform['AlphaAddTerm'], $nbits);
+ }
+ }
+ static function string($cxform, $opts = array()) {
+ if (($cxform['HasMultiTerms'] == 0) && ($cxform['HasAddTerms'] == 0)) {
+ return '(No Data: CXFORMWITHALPHA)';
+ }
+ $text = '';
+ if ($cxform['HasMultiTerms']) {
+ $text .= sprintf("MultiTerms:(%d,%d,%d,%d)", $cxform['RedMultiTerm'], $cxform['GreenMultiTerm'], $cxform['BlueMultiTerm'], $cxform['AlphaMultiTerm']);
+ }
+ if ($cxform['HasAddTerms']) {
+ if ($cxform['HasMultiTerms']) {
+ $text .= ' ';
+ }
+ $text .= sprintf("AddTerms:(%d,%d,%d,%d)", $cxform['RedAddTerm'], $cxform['GreenAddTerm'], $cxform['BlueAddTerm'], $cxform['AlphaAddTerm']);
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/CXFORMWITHALPHA.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/MATRIX.php
@@ -0,0 +1,103 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_MATRIX extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $matrix = array();
+
+ $reader->byteAlign();
+ $hasScale = $reader->getUIBit();
+ if ($hasScale) {
+ $nScaleBits = $reader->getUIBits(5);
+// $matrix['(NScaleBits)'] = $nScaleBits;
+ $matrix['ScaleX'] = $reader->getSIBits($nScaleBits);
+ $matrix['ScaleY'] = $reader->getSIBits($nScaleBits);
+ } else {
+ $matrix['ScaleX'] = 0x10000;
+ $matrix['ScaleY'] = 0x10000;
+ }
+ $hasRotate = $reader->getUIBit();
+ if ($hasRotate) {
+ $nRotateBits = $reader->getUIBits(5);
+// $matrix['(NRotateBits)'] = $nRotateBits;
+ $matrix['RotateSkew0'] = $reader->getSIBits($nRotateBits);
+ $matrix['RotateSkew1'] = $reader->getSIBits($nRotateBits);
+ } else {
+ $matrix['RotateSkew0'] = 0;
+ $matrix['RotateSkew1'] = 0;
+ }
+ $nTranslateBits = $reader->getUIBits(5);
+ $matrix['TranslateX'] = $reader->getSIBits($nTranslateBits);
+ $matrix['TranslateY'] = $reader->getSIBits($nTranslateBits);
+ return $matrix;
+ }
+ static function build(&$writer, $matrix, $opts = array()) {
+ $writer->byteAlign();
+ if (($matrix['ScaleX'] != 0x10000) || ($matrix['ScaleY'] != 0x10000)) {
+ $writer->putUIBit(1); // HasScale;
+ if ($matrix['ScaleX'] | $matrix['ScaleY']) {
+ $xNBits = $writer->need_bits_signed($matrix['ScaleX']);
+ $yNBits = $writer->need_bits_signed($matrix['ScaleY']);
+ $nScaleBits = max($xNBits, $yNBits);
+ } else {
+ $nScaleBits = 0;
+ }
+ $writer->putUIBits($nScaleBits, 5);
+ $writer->putSIBits($matrix['ScaleX'], $nScaleBits);
+ $writer->putSIBits($matrix['ScaleY'], $nScaleBits);
+ } else {
+ $writer->putUIBit(0); // HasScale;
+ }
+ if ($matrix['RotateSkew0'] | $matrix['RotateSkew1']) {
+ $writer->putUIBit(1); // HasRotate
+ if ($matrix['RotateSkew0'] | $matrix['RotateSkew1']) {
+ $rs0NBits = $writer->need_bits_signed($matrix['RotateSkew0']);
+ $rs1NBits = $writer->need_bits_signed($matrix['RotateSkew1']);
+ $nRotateBits = max($rs0NBits, $rs1NBits);
+ } else {
+ $nRotateBits = 0;
+ }
+ $writer->putUIBits($nRotateBits, 5);
+ $writer->putSIBits($matrix['RotateSkew0'], $nRotateBits);
+ $writer->putSIBits($matrix['RotateSkew1'], $nRotateBits);
+ } else {
+ $writer->putUIBit(0); // HasRotate
+ }
+ if ($matrix['TranslateX'] | $matrix['TranslateY']) {
+ $xNTranslateBits = $writer->need_bits_signed($matrix['TranslateX']);
+ $yNTranslateBits = $writer->need_bits_signed($matrix['TranslateY']);
+ $nTranslateBits = max($xNTranslateBits, $yNTranslateBits);
+ } else {
+ $nTranslateBits = 0;
+ }
+ $writer->putUIBits($nTranslateBits, 5);
+ $writer->putSIBits($matrix['TranslateX'], $nTranslateBits);
+ $writer->putSIBits($matrix['TranslateY'], $nTranslateBits);
+ }
+
+ static function string($matrix, $opts = array()) {
+ $indent = 0;
+ if (isset($opts['indent'])) {
+ $indent = $opts['indent'];
+ }
+ $text_fmt = <<< EOS
+%s| %3.3f %3.3f | %3.2f
+%s| %3.3f %3.3f | %3.2f
+EOS;
+ return sprintf($text_fmt,
+ str_repeat("\t", $indent),
+ $matrix['ScaleX'] / 0x10000,
+ $matrix['RotateSkew0'] / 0x10000,
+ $matrix['TranslateX'] / 20,
+ str_repeat("\t", $indent),
+ $matrix['RotateSkew1'] / 0x10000,
+ $matrix['ScaleY'] / 0x10000,
+ $matrix['TranslateY'] / 20);
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/MATRIX.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/Float.php
@@ -0,0 +1,23 @@
+<?php
+
+/*
+ * 2011/6/27- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_Float extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $data = $reader->getData(4);
+ $unpacked_data = unpack('f', $data);
+ return (float)$unpacked_data[1];
+ }
+ static function build(&$writer, $value, $opts = array()) {
+ $data = pack('f', (float)$value);
+ $writer->putData($data, 4);
+ }
+ static function string($value, $opts = array()) {
+ return sprintf("(Float)%f", $value);
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/GLYPHENTRY.php
@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * 2011/8/22- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_GLYPHENTRY extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $glyphentry = array();
+ $glyphentry['GlyphIndex'] = $reader->getUIBits($opts['GlyphBits']);
+ $glyphentry['GlyphAdvance'] = $reader->getUIBits($opts['AdvanceBits']);
+ return $glyphentry;
+ }
+ static function build(&$writer, $glyphentry, $opts = array()) {
+ $writer->putUIBits($glyphentry['GlyphIndex'], $opts['GlyphBits']);
+ $writer->putUIBits($glyphentry['GlyphAdvance'], $opts['AdvanceBits']);
+ }
+ static function string($glyphentry, $opts = array()) {
+ return sprintf("GlyphIndex:%s GlyphAdvance:%s", $glyphentry['GlyphIndex'], $glyphentry['GlyphAdvance']);
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/GLYPHENTRY.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/String.php
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_String extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $str = '';
+ while ($reader->hasNextData(1)) {
+ $c = $reader->getData(1);
+ if ($c === "\0") {
+ break;
+ }
+ $str .= $c;
+ }
+ return $str;
+ }
+ static function build(&$writer, $str, $opts = array()) {
+ $strs = explode("\0", $str);
+ $str = $strs[0];
+ $writer->putData($str."\0", strlen($str) + 1);
+ }
+ static function string($str, $opts = array()) {
+ return $str;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/CLIPEVENTFLAGS.php
@@ -0,0 +1,56 @@
+<?php
+
+/*
+ * 2011/7/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_CLIPEVENTFLAGS extends IO_SWF_Type {
+ static $clipevent_list = array(
+ 'KeyUp', 'KeyDown', 'MouseUp', 'MouseDown', 'MouseMove',
+ 'Unload', 'EnterFrame', 'Load', 'DragOver',
+ 'RollOut', 'RollOver',
+ 'ReleaseOutside', 'Release', 'Press', 'Initialize', 'Data');
+ static function parse(&$reader, $opts = array()) {
+ $clipeventflags = array();
+ foreach (self::$clipevent_list as $key) {
+ $clipeventflags['ClipEvent'.$key] = $reader->getUIBit();
+ }
+ if ($opts['Version'] >= 6) {
+ $clipeventflags['Reserved'] = $reader->getUIBits(5);
+ $clipeventflags['ClipEventKeyConstruct'] = $reader->getUIBit();
+ $clipeventflags['ClipEventKeyPress'] = $reader->getUIBit();
+ $clipeventflags['ClipEventDragOut'] = $reader->getUIBit();
+ $clipeventflags['Reserved2'] = $reader->getUIBits(8);
+ }
+ return $clipeventflags;
+ }
+ static function build(&$writer, $clipeventflags, $opts = array()) {
+ foreach (self::$clipevent_list as $key) {
+ $writer->putUIBit($clipeventflags['ClipEvent'.$key]);
+ }
+ if ($opts['Version'] >= 6) {
+ $writer->putUIBits($clipeventflags['Reserved'], 5);
+ $writer->putUIBit($clipeventflags['ClipEventConstruct']);
+ $writer->putUIBit($clipeventflags['ClipEventKeyPress']);
+ $writer->putUIBit($clipeventflags['ClipEventDragOut']);
+ $writer->putUIBits($clipeventflags['Reserved2'], 8);
+ }
+ }
+ static function string($clipeventflags, $opts = array()) {
+ $text = "ClipEvent: ";
+ if ($opts['Version'] <= 5) {
+ $clipevent_list = self::$clipevent_list;
+ } else {
+ $clipevent_list = self::$clipevent_list + array('Construct', 'KeyPress', 'DragOut');
+ }
+ foreach ($clipevent_list as $key) {
+ if ($clipeventflags['ClipEvent'.$key] == 1) {
+ $text .= $key.' ';
+ }
+ }
+ return $text;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILLSTYLEARRAY.php
@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/FILLSTYLE.php';
+
+class IO_SWF_Type_FILLSTYLEARRAY extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $fillStyles = array();
+
+ // FillStyle
+ $fillStyleCount = $reader->getUI8();
+ if (($tagCode > 2) && ($fillStyleCount == 0xff)) {
+ // DefineShape2 以降は 0xffff サイズまで扱える
+ $fillStyleCount = $reader->getUI16LE();
+ }
+ for ($i = 0 ; $i < $fillStyleCount ; $i++) {
+ $fillStyles[] = IO_SWF_Type_FILLSTYLE::parse($reader, $opts);
+ }
+ return $fillStyles;
+ }
+ static function build(&$writer, $fillStyles, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $fillStyleCount = count($fillStyles);
+ if ($fillStyleCount < 0xff) {
+ $writer->putUI8($fillStyleCount);
+ } else {
+ $writer->putUI8(0xff);
+ if ($tagCode > 2) {
+ $writer->putUI16LE($fillStyleCount);
+ } else {
+ $fillStyleCount = 0xff; // DefineShape(1)
+ }
+ }
+ foreach ($fillStyles as $fillStyle) {
+ IO_SWF_Type_FILLSTYLE::build($writer, $fillStyle, $opts);
+ }
+ return true;
+ }
+ static function string($fillStyles, $opts = array()) {
+ $text = '';
+ foreach ($fillStyles as $fillStyle) {
+ $text .= IO_SWF_Type_FILLSTYLE::string($fillStyle, $opts);
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILLSTYLEARRAY.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/LINESTYLEARRAY.php
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/LINESTYLE.php';
+
+
+class IO_SWF_Type_LINESTYLEARRAY extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $lineStyles = array();
+ // LineStyle
+ $lineStyleCount = $reader->getUI8();
+ if (($tagCode > 2) && ($lineStyleCount == 0xff)) {
+ // DefineShape2 以降は 0xffff サイズまで扱える
+ $lineStyleCount = $reader->getUI16LE();
+ }
+ for ($i = 0 ; $i < $lineStyleCount ; $i++) {
+ $lineStyles[] = IO_SWF_Type_LINESTYLE::parse($reader, $opts);
+ }
+ return $lineStyles;
+ }
+ static function build(&$writer, $lineStyles, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $lineStyleCount = count($lineStyles);
+ if ($lineStyleCount < 0xff) {
+ $writer->putUI8($lineStyleCount);
+ } else {
+ $writer->putUI8(0xff);
+ if ($tagCode > 2) {
+ $writer->putUI16LE($lineStyleCount);
+ } else {
+ $lineStyleCount = 0xff; // DefineShape(1)
+ }
+ }
+ foreach ($lineStyles as $lineStyle) {
+ IO_SWF_Type_LINESTYLE::build($writer, $lineStyle, $opts);
+ }
+ return true;
+ }
+ static function string($lineStyles, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $text = '';
+ foreach ($lineStyles as $lineStyle) {
+ $text .= IO_SWF_Type_LINESTYLE::string($lineStyle, $opts);
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/LINESTYLEARRAY.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILLSTYLE.php
@@ -0,0 +1,250 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/../Exception.php';
+require_once dirname(__FILE__).'/../Type/MATRIX.php';
+require_once dirname(__FILE__).'/../Type/RGB.php';
+require_once dirname(__FILE__).'/../Type/RGBA.php';
+
+class IO_SWF_Type_FILLSTYLE extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+ $fillStyle = array();
+ $fillStyleType = $reader->getUI8();
+ $fillStyle['FillStyleType'] = $fillStyleType;
+ switch ($fillStyleType) {
+ case 0x00: // solid fill
+ if ($isMorph === false) {
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ $fillStyle['Color'] = IO_SWF_Type_RGB::parse($reader);
+ } else {
+ $fillStyle['Color'] = IO_SWF_Type_RGBA::parse($reader);
+ }
+ } else {
+ $fillStyle['StartColor'] = IO_SWF_Type_RGBA::parse($reader);
+ $fillStyle['EndColor'] = IO_SWF_Type_RGBA::parse($reader);
+ }
+ break;
+ case 0x10: // linear gradient fill
+ case 0x12: // radial gradient fill
+ if ($isMorph === false) {
+ $fillStyle['GradientMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+ } else {
+ $fillStyle['StartGradientMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+ $fillStyle['EndGradientMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+ }
+ $reader->byteAlign();
+ if ($isMorph === false) {
+ $fillStyle['SpreadMode'] = $reader->getUIBits(2);
+ $fillStyle['InterpolationMode'] = $reader->getUIBits(2);
+ $numGradients = $reader->getUIBits(4);
+ } else {
+ $numGradients = $reader->getUI8();
+ }
+ $fillStyle['GradientRecords'] = array();
+ for ($j = 0 ; $j < $numGradients ; $j++) {
+ $gradientRecord = array();
+ if ($isMorph === false) {
+ $gradientRecord['Ratio'] = $reader->getUI8();
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ $gradientRecord['Color'] = IO_SWF_Type_RGB::parse($reader);
+ } else {
+ $gradientRecord['Color'] = IO_SWF_Type_RGBA::parse($reader);
+ }
+ } else { // Morph
+ $gradientRecord['StartRatio'] = $reader->getUI8();
+ $gradientRecord['StartColor'] = IO_SWF_Type_RGBA::parse($reader);
+ $gradientRecord['EndRatio'] = $reader->getUI8();
+ $gradientRecord['EndColor'] = IO_SWF_Type_RGBA::parse($reader);
+ }
+ $fillStyle['GradientRecords'] []= $gradientRecord;
+ }
+ break;
+ // case 0x13: // focal gradient fill // 8 and later
+ // break;
+ case 0x40: // repeating bitmap fill
+ case 0x41: // clipped bitmap fill
+ case 0x42: // non-smoothed repeating bitmap fill
+ case 0x43: // non-smoothed clipped bitmap fill
+ $fillStyle['BitmapId'] = $reader->getUI16LE();
+ if ($isMorph === false) {
+ $fillStyle['BitmapMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+ } else {
+ $fillStyle['StartBitmapMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+ $fillStyle['EndBitmapMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+ }
+ break;
+ default:
+ throw new IO_SWF_Exception("Unknown FillStyleType=$fillStyleType tagCode=$tagCode");
+ }
+ return $fillStyle;
+ }
+ static function build(&$writer, $fillStyle, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+ $fillStyleType = $fillStyle['FillStyleType'];
+ $writer->putUI8($fillStyleType);
+ switch ($fillStyleType) {
+ case 0x00: // solid fill
+ if ($isMorph === false) {
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ IO_SWF_Type_RGB::build($writer, $fillStyle['Color']);
+ } else {
+ IO_SWF_Type_RGBA::build($writer, $fillStyle['Color']);
+ }
+ } else {
+ IO_SWF_Type_RGBA::build($writer, $fillStyle['StartColor']);
+ IO_SWF_Type_RGBA::build($writer, $fillStyle['EndColor']);
+ }
+ break;
+ case 0x10: // linear gradient fill
+ case 0x12: // radial gradient fill
+ if ($isMorph === false) {
+ IO_SWF_Type_MATRIX::build($writer, $fillStyle['GradientMatrix']);
+ } else {
+ IO_SWF_Type_MATRIX::build($writer, $fillStyle['StartGradientMatrix']);
+ IO_SWF_Type_MATRIX::build($writer, $fillStyle['EndGradientMatrix']);
+ }
+ $writer->byteAlign();
+ if ($isMorph === false) {
+ $writer->putUIBits($fillStyle['SpreadMode'], 2);
+ $writer->putUIBits($fillStyle['InterpolationMode'], 2);
+ $numGradients = count($fillStyle['GradientRecords']);
+ $writer->putUIBits($numGradients , 4);
+ } else {
+ $numGradients = count($fillStyle['GradientRecords']);
+ $writer->putUI8($numGradients);
+ }
+ foreach ($fillStyle['GradientRecords'] as $gradientRecord) {
+ if ($isMorph === false) {
+ $writer->putUI8($gradientRecord['Ratio']);
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ IO_SWF_Type_RGB::build($writer, $gradientRecord['Color']);
+ } else {
+ IO_SWF_Type_RGBA::build($writer, $gradientRecord['Color']);
+ }
+ } else {
+ $writer->putUI8($gradientRecord['StartRatio']);
+ IO_SWF_Type_RGBA::build($writer, $gradientRecord['StartColor']);
+ $writer->putUI8($gradientRecord['EndRatio']);
+ IO_SWF_Type_RGBA::build($writer, $gradientRecord['EndColor']);
+ }
+ }
+ break;
+ // case 0x13: // focal gradient fill // 8 and later
+ // break;
+ case 0x40: // repeating bitmap fill
+ case 0x41: // clipped bitmap fill
+ case 0x42: // non-smoothed repeating bitmap fill
+ case 0x43: // non-smoothed clipped bitmap fill
+ $writer->putUI16LE($fillStyle['BitmapId']);
+ if ($isMorph === false) {
+ IO_SWF_Type_MATRIX::build($writer, $fillStyle['BitmapMatrix']);
+ } else {
+ IO_SWF_Type_MATRIX::build($writer, $fillStyle['StartBitmapMatrix']);
+ IO_SWF_Type_MATRIX::build($writer, $fillStyle['EndBitmapMatrix']);
+ }
+ break;
+ default:
+ throw new IO_SWF_Exception("Unknown FillStyleType=$fillStyleType tagCode=$tagCode");
+ }
+ return true;
+ }
+ static function string($fillStyle, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+ $text = '';
+ $fillStyleType = $fillStyle['FillStyleType'];
+ switch ($fillStyleType) {
+ case 0x00: // solid fill
+ if ($isMorph === false) {
+ $color = $fillStyle['Color'];
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ $color_str = IO_SWF_Type_RGB::string($color);
+ } else {
+ $color_str = IO_SWF_Type_RGBA::string($color);
+ }
+ $text .= "\tsolid fill: $color_str\n";
+ } else{
+ $startColor = $fillStyle['StartColor'];
+ $endColor = $fillStyle['EndColor'];
+ $startColor_str = IO_SWF_Type_RGBA::string($startColor);
+ $endColor_str = IO_SWF_Type_RGBA::string($endColor);
+ $text .= "\tsolid fill: $startColor_str => $endColor_str\n";
+ }
+ break;
+ case 0x10: // linear gradient fill
+ case 0x12: // radial gradient fill
+ if ($fillStyleType == 0x10) {
+ $text .= "\tlinear gradient fill\n";
+ } else {
+ $text .= "\tradial gradient fill\n";
+ }
+ $opts = array('indent' => 2);
+ if ($isMorph === false) {
+ $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['GradientMatrix'], $opts);
+ $text .= $matrix_str . "\n";
+ $spreadMode = $fillStyle['SpreadMode'];
+ $interpolationMode = $fillStyle['InterpolationMode'];
+ } else {
+ $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['StartGradientMatrix'], $opts);
+ $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['EndGradientMatrix'], $opts);
+ $text .= $matrix_str . "\n";
+ }
+
+ foreach ($fillStyle['GradientRecords'] as $gradientRecord) {
+ if ($isMorph === false) {
+ $ratio = $gradientRecord['Ratio'];
+ $color = $gradientRecord['Color'];
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ $color_str = IO_SWF_Type_RGB::string($color);
+ } else {
+ $color_str = IO_SWF_Type_RGBA::string($color);
+ }
+ $text .= "\t\tRatio: $ratio Color:$color_str\n";
+ } else {
+ $startRatio = $gradientRecord['StartRatio'];
+ $startColorStr = IO_SWF_Type_RGBA::string($gradientRecord['StartColor']);
+ $endRatio = $gradientRecord['EndRatio'];
+
+ $endColorStr = IO_SWF_Type_RGBA::string($gradientRecord['EndColor']);
+ $text .= "\t\tStart: Ratio:$startRatio Color:$startColorStr => End: Ratio:$endRatio Color:$endColorStr\n";
+ }
+ }
+ break;
+ case 0x40: // repeating bitmap fill
+ case 0x41: // clipped bitmap fill
+ case 0x42: // non-smoothed repeating bitmap fill
+ case 0x43: // non-smoothed clipped bitmap fill
+ $text .= "\tBigmap($fillStyleType): ";
+ $text .= " BitmapId: ".$fillStyle['BitmapId']."\n";
+ if ($isMorph === false) {
+ $text .= "\tBitmapMatrix:\n";
+ $opts = array('indent' => 2);
+ $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['BitmapMatrix'], $opts);
+ $text .= $matrix_str . "\n";
+ } else {
+ $opts = array('indent' => 2);
+ $text .= "\tStartBitmapMatrix:\n";
+ $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['StartBitmapMatrix'], $opts);
+ $text .= $matrix_str . "\n";
+ $text .= "\tEndBitmapMatrix:\n";
+ $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['EndBitmapMatrix'], $opts);
+ $text .= $matrix_str . "\n";
+ }
+ break;
+ default:
+ $text .= "Unknown FillStyleType($fillStyleType)\n";
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILLSTYLE.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/CLIPACTIONS.php
@@ -0,0 +1,57 @@
+<?php
+
+/*
+ * 2011/7/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/CLIPEVENTFLAGS.php';
+require_once dirname(__FILE__).'/CLIPACTIONRECORD.php';
+
+class IO_SWF_Type_CLIPACTIONS extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $clipactions = array();
+ $clipactions['Reserved'] = $reader->getUI16LE(); // must be 0
+ $clipactions['AllEventFlags'] = IO_SWF_Type_CLIPEVENTFLAGS::parse($reader, $opts);
+ $clipActionRecords = array();
+ while (true) {
+ if ($opts['Version'] <= 5) {
+ if ($reader->getUI16LE() == 0) {
+ break;
+ }
+ $reader->incrementOffset(-2, 0); // 2 bytes back
+ } else {
+ if ($reader->getUI32LE() == 0) {
+ break;
+ }
+ $reader->incrementOffset(-4, 0); // 4 bytes back
+ }
+ $clipActionRecords []= IO_SWF_Type_CLIPACTIONRECORD::parse($reader, $opts);
+ }
+ $clipactions['ClipActionRecords'] = $clipActionRecords;
+ return $clipactions;
+ }
+ static function build(&$writer, $clipactions, $opts = array()) {
+ $writer->putUI16LE($clipactions['Reserved']); // must be 0
+ IO_SWF_Type_CLIPEVENTFLAGS::build($writer, $clipactions['AllEventFlags'], $opts);
+ foreach ($clipactions['ClipActionRecords'] as $clipActionRecord) {
+ IO_SWF_Type_CLIPACTIONRECORD::build($writer, $clipActionRecord, $opts);
+ }
+ if ($opts['Version'] <= 5) {
+ $writer->putUI16LE(0); // ClipActionEndFlag
+ } else {
+ $writer->putUI32LE(0); // ClipActionEndFlag
+ }
+ }
+ static function string($clipactions, $opts = array()) {
+ $text = 'ALLEventFlags: ';
+ $text .= IO_SWF_Type_CLIPEVENTFLAGS::string($clipactions['AllEventFlags'], $opts);
+ $text .= "\n";
+ $text .= "\tClipActionRecords:\n";
+ foreach ($clipactions['ClipActionRecords'] as $clipActionRecord) {
+ $text .= "\t".IO_SWF_Type_CLIPACTIONRECORD::string($clipActionRecord, $opts)."\n";
+ }
+ return $text;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/LINESTYLE.php
@@ -0,0 +1,72 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/../Type/RGB.php';
+require_once dirname(__FILE__).'/../Type/RGBA.php';
+
+class IO_SWF_Type_LINESTYLE extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+ $lineStyle = array();
+ if ($isMorph === false) {
+ $lineStyle['Width'] = $reader->getUI16LE();
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ $lineStyle['Color'] = IO_SWF_Type_RGB::parse($reader);
+ } else {
+ $lineStyle['Color'] = IO_SWF_Type_RGBA::parse($reader);
+ }
+ } else {
+ $lineStyle['StartWidth'] = $reader->getUI16LE();
+ $lineStyle['EndWidth'] = $reader->getUI16LE();
+ $lineStyle['StartColor'] = IO_SWF_Type_RGBA::parse($reader);
+ $lineStyle['EndColor'] = IO_SWF_Type_RGBA::parse($reader);
+ }
+ return $lineStyle;
+ }
+ static function build(&$writer, $lineStyle, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+ if ($isMorph === false) {
+ $writer->putUI16LE($lineStyle['Width']);
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ IO_SWF_Type_RGB::build($writer, $lineStyle['Color']);
+ } else {
+ IO_SWF_Type_RGBA::build($writer, $lineStyle['Color']);
+ }
+ } else {
+ $writer->putUI16LE($lineStyle['StartWidth']);
+ $writer->putUI16LE($lineStyle['EndWidth']);
+ IO_SWF_Type_RGBA::build($writer, $lineStyle['StartColor']);
+ IO_SWF_Type_RGBA::build($writer, $lineStyle['EndColor']);
+ }
+ return true;
+ }
+ static function string($lineStyle, $opts = array()) {
+ $tagCode = $opts['tagCode'];
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+ $text = '';
+
+ if ($isMorph === false) {
+ $width = $lineStyle['Width'];
+ if ($tagCode < 32 ) { // 32:DefineShape3
+ $color_str = IO_SWF_Type_RGB::string($lineStyle['Color']);
+ } else {
+ $color_str = IO_SWF_Type_RGBA::string($lineStyle['Color']);
+ }
+ $text .= "\tWidth: $width Color: $color_str\n";
+ } else {
+ $startWidth = $lineStyle['StartWidth'];
+ $endWidth = $lineStyle['EndWidth'];
+ $startColorStr = IO_SWF_Type_RGBA::string($lineStyle['StartColor']);
+ $endColorStr = IO_SWF_Type_RGBA::string($lineStyle['EndColor']);
+ $text .= "\tWidth: $startWidth => $endWidth Color: $startColorStr => $endColorStr\n";
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/LINESTYLE.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/BUTTONRECORD.php
@@ -0,0 +1,107 @@
+<?php
+
+/*
+ * 2011/7/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/CXFORM.php';
+require_once dirname(__FILE__).'/CXFORMWITHALPHA.php';
+require_once dirname(__FILE__).'/FILTERLIST.php';
+
+class IO_SWF_Type_BUTTONRECORD extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $buttonrecord = array();
+ $reader->byteAlign();
+ $buttonrecord['ButtonReserved'] = $reader->getUIBits(2); // must be 0
+ $buttonHasBlendMode = $reader->getUIBit();
+ $buttonHasFilterList = $reader->getUIBit();
+ $buttonrecord['ButtonHasBlandMode'] = $buttonHasBlendMode;
+ $buttonrecord['ButtonHasFilterList'] = $buttonHasFilterList;
+
+ $buttonrecord['ButtonStateHitTest'] = $reader->getUIBit();
+ $buttonrecord['ButtonStateDown'] = $reader->getUIBit();
+ $buttonrecord['ButtonStateOver'] = $reader->getUIBit();
+ $buttonrecord['ButtonStateUp'] = $reader->getUIBit();
+
+ $buttonrecord['CharacterID'] = $reader->getUI16LE();
+ $buttonrecord['PlaceDepth'] = $reader->getUI16LE();
+ $buttonrecord['PlaceMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+ if ($opts['tagCode'] == 34) { // DefineButton2
+ $buttonrecord['ColorTransform'] = IO_SWF_Type_CXFORMWITHALPHA::parse($reader);
+ } else {
+ $buttonrecord['ColorTransform'] = IO_SWF_Type_CXFORM::parse($reader);
+ }
+ if (($opts['tagCode'] == 34) && ($opts['Version'] >= 8)) {
+ // DefineButton2 & SWF8 later
+ if ($buttonHasFilterList == 1) {
+ $buttonrecord['FilterList'] = IO_SWF_Type_FILTERLIST::parse($reader);
+ }
+ if ($buttonHasBlendMode == 1) {
+ $buttonrecord['BlendMode'] = $reader->getUI8();
+ }
+ }
+ return $buttonrecord;
+ }
+
+ static function build(&$writer, $buttonrecord, $opts = array()) {
+ $writer->byteAlign();
+ $writer->putUIBits(0, 2); // ButtonReserved
+ $buttonHasBlendMode = $buttonrecord['ButtonHasBlandMode'];
+ $buttonHasFilterList = $buttonrecord['ButtonHasFilterList'];
+ $writer->putUIBit($buttonHasBlendMode);
+ $writer->putUIBit($buttonHasFilterList);
+ $writer->putUIBit($buttonrecord['ButtonStateHitTest']);
+ $writer->putUIBit($buttonrecord['ButtonStateDown']);
+ $writer->putUIBit($buttonrecord['ButtonStateOver']);
+ $writer->putUIBit($buttonrecord['ButtonStateUp']);
+ //
+ $writer->putUI16LE($buttonrecord['CharacterID']);
+ $writer->putUI16LE($buttonrecord['PlaceDepth']);
+ IO_SWF_Type_MATRIX::build($writer, $buttonrecord['PlaceMatrix']);
+ if ($opts['tagCode'] == 34) { // DefineButton2
+ IO_SWF_Type_CXFORMWITHALPHA::build($writer, $buttonrecord['ColorTransform']);
+ } else {
+ IO_SWF_Type_CXFORM::build($writer, $buttonrecord['ColorTransform']);
+ }
+ if (($opts['tagCode'] == 34) && ($opts['Version'] >= 8)) {
+ // DefineButton2 & SWF8 later
+ if ($buttonHasFilterList == 1) {
+ IO_SWF_Type_FILTERLIST::build($writer, $buttonrecord['FilterList']);
+ }
+ if ($buttonHasBlendMode == 1) {
+ $writer->putUI8($buttonrecord['BlendMode']);
+ }
+ }
+ }
+ static function string($buttonrecord, $opts = array()) {
+ $text = '';
+ $buttonHasBlendMode = $buttonrecord['ButtonHasBlandMode'];
+ $buttonHasFilterList = $buttonrecord['ButtonHasFilterList'];
+ $text .= "HasBlandMode:".$buttonrecord['ButtonHasBlandMode'].' HasFilterList:'. $buttonrecord['ButtonHasFilterList']."\n\t\t";
+ foreach (array('StateHitTest', 'StateDown', 'StateOver', 'StateUp') as $label) {
+ $text .= $label.':'.$buttonrecord['Button'.$label].' ';
+ }
+ $text .= "\n\t\t";
+ $text .= "CharacterID:{$buttonrecord['CharacterID']} PlaceDepth:{$buttonrecord['PlaceDepth']}";
+ $text .= "\n";
+ $opts['indent']++;
+ $text .= IO_SWF_Type_MATRIX::string($buttonrecord['PlaceMatrix'], $opts)."\n";
+ if ($opts['tagCode'] == 34) { // DefineButton2
+ $text .= "\t\tColorTransform:". IO_SWF_Type_CXFORMWITHALPHA::string($buttonrecord['ColorTransform']).' ';
+ } else {
+ $text .= 'ColorTransform:'.IO_SWF_Type_CXFORM::string($buttonrecord['ColorTransform']).' ';
+ }
+ if (($opts['tagCode'] == 34) && ($opts['Version'] >= 8)) {
+ // DefineButton2 & SWF8 later
+ if ($buttonHasFilterList == 1) {
+ $text .= 'FilterList:'.IO_SWF_Type_FILTERLIST::string($buttonrecord['FilterList'])."\n";
+ }
+ if ($buttonHasBlendMode == 1) {
+ $text .= 'BlendMode:'.$buttonrecord['BlendMode']."\n";
+ }
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/BUTTONRECORD.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/Double.php
@@ -0,0 +1,23 @@
+<?php
+
+/*
+ * 2011/6/27- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_Double extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $data = $reader->getData(8);
+ $unpacked_data = unpack('d', $data);
+ return (double)$unpacked_data[1];
+ }
+ static function build(&$writer, $value, $opts = array()) {
+ $data = pack('d', (double)$value);
+ $writer->putData($data, 8);
+ }
+ static function string($value, $opts = array()) {
+ return sprintf("(Double)%d", $value);
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/RGB.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_RGB extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $rgb = array();
+ $rgb['Red'] = $reader->getUI8();
+ $rgb['Green'] = $reader->getUI8();
+ $rgb['Blue'] = $reader->getUI8();
+ return $rgb;
+ }
+ static function build(&$writer, $rgb, $opts = array()) {
+ $writer->putUI8($rgb['Red']);
+ $writer->putUI8($rgb['Green']);
+ $writer->putUI8($rgb['Blue']);
+ }
+ static function string($color, $opts = array()) {
+ return sprintf("#%02x%02x%02x", $color['Red'], $color['Green'], $color['Blue']);
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/RGB.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/RGBA.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_RGBA extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $rgba = array();
+ $rgba['Red'] = $reader->getUI8();
+ $rgba['Green'] = $reader->getUI8();
+ $rgba['Blue'] = $reader->getUI8();
+ $rgba['Alpha'] = $reader->getUI8();
+ return $rgba;
+ }
+ static function build(&$writer, $rgba, $opts = array()) {
+ $writer->putUI8($rgba['Red']);
+ $writer->putUI8($rgba['Green']);
+ $writer->putUI8($rgba['Blue']);
+ $writer->putUI8($rgba['Alpha']);
+ }
+ static function string($color, $opts = array()) {
+ return sprintf("#%02x%02x%02x(%02x)", $color['Red'], $color['Green'], $color['Blue'], $color['Alpha']);
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/RGBA.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/BUTTONCONDACTION.php
@@ -0,0 +1,68 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_BUTTONCONDACTION extends IO_SWF_Type {
+ static $buttoncond_list = array(
+ 'IdleToOverDown', 'OutDownToIdle', 'OutDownToOverDown',
+ 'OverDownToOutDown', 'OverDownToOverUp', 'OverUpToOverDown',
+ 'OverUpToIdle', 'IdleToOverUp');
+ static function parse(&$reader, $opts = array()) {
+ $condAction = array();
+ $condAction['CondActionSize'] = $reader->getUI16LE();
+ foreach (self::$buttoncond_list as $key) {
+ $condAction['Cond'.$key] = $reader->getUIBit();
+ }
+ $condAction['CondKeyPress'] = $reader->getUIBits(7);
+ $condAction['CondOverDownToIdle'] = $reader->getUIBit();
+ if ($reader->hasNextData()) { // XXX (depends on ActionOffset
+ $actions = array();
+ while ($reader->getUI8() != 0) {
+ $reader->incrementOffset(-1, 0); // 1 byte back
+ $actions []= IO_SWF_Type_Action::parse($reader);
+ }
+ $condAction['Actions'] = $actions;
+ }
+ return $condAction;
+ }
+ static function build(&$writer, $condAction, $opts = array()) {
+ list($offset_condAction, $dummy) = $writer->getOffset();
+ $writer->putUI16LE(0);
+ foreach (self::$buttoncond_list as $key) {
+ $writer->putUIBit($condAction['Cond'.$key]);
+ }
+ $writer->putUIBits($condAction['CondKeyPress'], 7);
+ $writer->putUIBit($condAction['CondOverDownToIdle']);
+ foreach ($condAction['Actions'] as $action) {
+ IO_SWF_Type_Action::build($writer, $action);
+ }
+ $writer->putUI8(0); // terminate
+ if ($opts['lastAction'] === false) {
+ list($offset_next, $dummy) = $writer->getOffset();
+ $writer->setUI16LE($offset_next - $offset_condAction, $offset_condAction);
+ }
+ return true;
+ }
+ static function string($condAction, $opts = array()) {
+ $text = "\tBUTTONCONDACTION (CondActionSize:{$condAction['CondActionSize']})\n";
+
+ $text .= "\t\tCondAction: ";
+ foreach (self::$buttoncond_list as $key) {
+ $text .= " $key:".$condAction['Cond'.$key];
+ }
+ $text .= "\n";
+ $text .= "\t\tCondKeyPress:".$condAction['CondKeyPress']." CondOverDownToIdle:".$condAction['CondOverDownToIdle']."\n";
+
+
+ $text .= "\t\tActions:\n";
+ foreach ($condAction['Actions'] as $action) {
+ $text .= "\t\t\t".IO_SWF_Type_Action::string($action, $opts)."\n";
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/BUTTONCONDACTION.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/Action.php
@@ -0,0 +1,426 @@
+<?php
+
+/*
+ * 2011/06/03- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/String.php';
+require_once dirname(__FILE__).'/Float.php';
+require_once dirname(__FILE__).'/Double.php';
+
+class IO_SWF_Type_Action extends IO_SWF_Type {
+ static $action_code_table = array(
+ //
+ // ActionCode only
+ //
+ 0x04 => 'NextFrame',
+ 0x05 => 'PreviousFrame',
+ 0x06 => 'Play',
+ 0x07 => 'Stop',
+ 0x08 => 'ToggleQuality',
+ 0x09 => 'StopSounds',
+ //
+ 0x0A => 'Add',
+ 0x0B => 'Subtract',
+ 0x0C => 'Multiply',
+ 0x0D => 'Divide',
+ 0x0E => 'Equals',
+ 0x0F => 'Less',
+ 0x10 => 'And',
+ 0x11 => 'Or',
+ 0x12 => 'Not',
+ 0x13 => 'StringEquals',
+ 0x14 => 'StringLength',
+ 0x15 => 'StringExtract',
+ //
+ 0x17 => 'Pop',
+ 0x18 => 'ToInteger',
+ //
+ 0x1C => 'GetVariable',
+ 0x1D => 'SetVariable',
+ //
+ 0x20 => 'SetTarget2',
+ 0x21 => 'StringAdd',
+ 0x22 => 'GetProperty',
+ 0x23 => 'SetProperty',
+ 0x24 => 'CloneSprite',
+ 0x25 => 'RemoveSprite',
+ 0x26 => 'Trace',
+ //
+ 0x2D => 'FSCommand2',// Flash Lite
+ //
+ 0x27 => 'StartDrag',
+ 0x28 => 'EndDrag',
+ 0x29 => 'StringLess',
+ //
+ 0x30 => 'RandomNumber',
+ 0x31 => 'MBStringLength',
+ 0x32 => 'CharToAscii',
+ 0x33 => 'AsciiToChar',
+ 0x34 => 'GetTime',
+ 0x35 => 'MBStringExtract',
+ 0x36 => 'MBCharToAscii',
+ 0x37 => 'MBAsciiToChar',
+ //
+ 0x3A => 'Delete', // SWF 5
+ 0x3B => 'Delete2', // SWF 5
+ 0x3C => 'DefineLocal', // SWF 5
+ 0x3D => 'CallFunction', // SWF 5
+ 0x3E => 'Return', // SWF 5
+ 0x3F => 'Modulo', // SWF 5
+ 0x40 => 'NewObject', // SWF 5
+ 0x41 => 'DefineLocal2', // SWF 5
+ 0x42 => 'InitArray', // SWF 5
+ 0x43 => 'InitObject', // SWF 5
+ 0x44 => 'TypeOf', // SWF 5
+ 0x45 => 'TargetPath', // SWF 5
+ 0x46 => 'Enumerate', // SWF 5
+ 0x47 => 'Add2', // SWF 5
+ 0x48 => 'Less2', // SWF 5
+ 0x49 => 'Equals2', // SWF 5
+ 0x4A => 'ToNumber', // SWF 5
+ 0x4B => 'ToString', // SWF 5
+ 0x4C => 'PushDuplicate', // SWF 5
+ 0x4D => 'StackSwap', // SWF 5
+ 0x4E => 'GetMember', // SWF 5
+ 0x4F => 'SetMember', // SWF 5
+ 0x50 => 'Increment', // SWF 5
+ 0x51 => 'Decrement', // SWF 5
+ 0x52 => 'CallMethod', // SWF 5
+ 0x53 => 'NewMethod', // SWF 5
+ 0x54 => 'InstanceOf', // SWF 6
+ 0x55 => 'Enumerate2', // SWF 6
+ //
+ 0x60 => 'BitAnd', // SWF 5
+ 0x61 => 'BitOr', // SWF 5
+ 0x62 => 'BitXOr', // SWF 5
+ 0x63 => 'BitShift', // SWF 5
+ 0x64 => 'BitURShift', // SWF 5
+ //
+ 0x66 => 'StrictEquals', // SWF 6
+ 0x67 => 'Greater', // SWF 6
+ 0x68 => 'StringGreater', // SWF 6
+ //
+ // has Data Payload
+ //
+ 0x81 => 'GotoFrame',
+ 0x83 => 'GetURL',
+ 0x87 => 'StoreRegister', // SWF 5
+ 0x88 => 'ConstantPool', // SWF 5
+ 0x8A => 'WaitForFrame',
+ 0x8B => 'SetTarget',
+ 0x8C => 'GoToLabel',
+ 0x8D => 'WaitForFrame2',
+ //
+ 0x94 => 'With', // SWF 5
+ 0x96 => 'Push',
+ //
+ 0x99 => 'Jump',
+ 0x9A => 'GetURL2',
+ 0x9B => 'DefineFunction', // SWF 5
+ //
+ 0x9D => 'If',
+ 0x9E => 'Call', // why it >=0x80 ?
+ 0x9F => 'GotoFrame2',
+ );
+ static function getCodeName($code) {
+ if (isset(self::$action_code_table[$code])) {
+ return self::$action_code_table[$code];
+ } else {
+ return "Unknown";
+ }
+ }
+ static function parse(&$reader, $opts = array()) {
+ $action = array();
+ $code = $reader->getUI8();
+ $action['Code'] = $code;
+ if ($code >= 0x80) {
+ $length = $reader->getUI16LE();
+ $action['Length'] = $length;
+ switch ($code) {
+ case 0x81: // ActionGotoFrame
+ $action['Frame'] = $reader->getUI16LE();
+ break;
+ case 0x83: // ActionGetURL
+ $data = $reader->getData($length);
+ $strs = explode("\0", $data, 2+1);
+ $action['UrlString'] = $strs[0];
+ $action['TargetString'] = $strs[1];
+ break;
+ case 0x88: // ActionConstantPool
+ $count = $reader->getUI16LE();
+ $action['Count'] = $count;
+ $data = $reader->getData($length - 2);
+ $strs = explode("\0", $data, $count+1);
+ $action['ConstantPool'] = array_splice($strs, 0, $count);
+ break;
+ case 0x8A: // ActionWaitForFrame
+ $action['Frame'] = $reader->getUI16LE();
+ $action['SkipCount'] = $reader->getUI8();
+ break;
+ case 0x8B: // ActionSetTarget
+ $data = $reader->getData($length);
+ $strs = explode("\0", $data, 1+1);
+ $action['TargetName'] = $strs[0];
+ break;
+ case 0x8C: // ActionSetTarget
+ $data = $reader->getData($length);
+ $strs = explode("\0", $data, 1+1);
+ $action['Label'] = $strs[0];
+ break;
+ case 0x8D: // ActionWaitForFrame2
+ $action['Frame'] = $reader->getUI16LE();
+ $action['SkipCount'] = $reader->getUI8();
+ break;
+ case 0x96: // ActionPush
+ $data = $reader->getData($length);
+ $values = array();
+ $values_reader = new IO_Bit();
+ $values_reader->input($data);
+ while ($values_reader->hasNextData()) {
+ $value = array();
+ $type = $values_reader->getUI8();
+ $value['Type'] = $type;
+ switch ($type) {
+ case 0: // STRING
+ $value['String'] = IO_SWF_Type_String::parse($values_reader);
+ break;
+ case 1: // Float
+ $value['Float'] = IO_SWF_Type_Float::parse($values_reader);
+ break;
+ case 2: // null
+ $value['null'] = null;
+ break;
+ case 3: // undefined
+ $value['undefined'] = null;
+ break;
+ case 4: // RegisterNumber
+ $value['RegisterNumber'] = $values_reader->getUI8();
+ break;
+ case 5: // Boolean
+ $value['Boolean'] = $values_reader->getUI8();
+ break;
+ case 6: // Double
+ $value['Double'] = IO_SWF_Type_Double::parse($values_reader);
+ break;
+ case 7: // Integer
+ $value['Integer'] = $values_reader->getUI32LE();
+ break;
+ case 8: // Constant8
+ $value['Constant8'] = $values_reader->getUI8();
+ break;
+ case 9: // Constant16
+ $value['Constant16'] = $values_reader->getUI16LE();
+ break;
+ default:
+ throw new IO_SWF_Exception("Illegal ActionPush value's type($type)");
+ }
+ $values[] = $value;
+ }
+ $action['Values'] = $values;
+ break;
+ case 0x99: // ActionJump
+ $action['BranchOffset'] = $reader->getSI16LE();
+ break;
+ case 0x9A: // ActionGetURL2
+ $action['SendVarsMethod'] = $reader->getUIBits(2);
+ $action['(Reserved)'] = $reader->getUIBits(4);
+ $action['LoadTargetFlag'] = $reader->getUIBit();
+ $action['LoadVariablesFlag'] = $reader->getUIBit();
+ break;
+ case 0x9D: // ActionIf
+ $action['Offset'] = $reader->getSI16LE();
+ break;
+ case 0x9F: // ActionGotoFrame2
+ $action['(Reserved)'] = $reader->getUIBits(6);
+ $sceneBlasFlag = $reader->getUIBit();
+ $action['SceneBlasFlag'] = $sceneBlasFlag;
+ $action['PlayFlag'] = $reader->getUIBit();
+ if ($sceneBlasFlag == 1) {
+ $action['SceneBias'] = $reader->getUI16LE();
+ }
+ break;
+ default:
+ if ($length > 0) {
+ $action['Data'] = $reader->getData($length);
+ }
+ break;
+ }
+ }
+ return $action;
+ }
+ static function build(&$writer, $action, $opts = array()) {
+ $code = $action['Code'];
+ $writer->putUI8($code);
+ if (0x80 <= $code) {
+ switch ($code) {
+ case 0x81: // ActionGotoFrame
+ $writer->putUI16LE(2);
+ $writer->putUI16LE($action['Frame']);
+ break;
+ case 0x83: // ActionGetURL
+ $data = $action['UrlString']."\0".$action['TargetString']."\0";
+ $writer->putUI16LE(strlen($data));
+ $writer->putData($data);
+ break;
+ case 0x88: // ActionConstantPool
+ $count = count($action['ConstantPool']);
+ $data = implode("\0", $action['ConstantPool'])."\0";
+ $writer->putUI16LE(strlen($data) + 2);
+ $writer->putUI16LE($count);
+ $writer->putData($data);
+ break;
+ case 0x8A: // ActionWaitForFrame
+ $writer->putUI16LE($action['Frame']);
+ $writer->putUI8($action['SkipCount']);
+ break;
+ case 0x8B: // ActionSetTarget
+ $data = $action['TargetName']."\0";
+ $writer->putUI16LE(strlen($data));
+ $writer->putData($data);
+ break;
+ case 0x8C: // ActionGoToLabel
+ $data = $action['Label']."\0";
+ $writer->putUI16LE(strlen($data));
+ $writer->putData($data);
+ break;
+ case 0x8D: // ActionWaitForFrame2
+ $writer->putUI16LE($action['Frame']);
+ $writer->putUI8($action['SkipCount']);
+ break;
+ case 0x96: // ActionPush
+ $values_writer = new IO_Bit();
+ foreach ($action['Values'] as $value) {
+ $type = $value['Type'];
+ $values_writer->putUI8($type);
+ switch ($type) {
+ case 0: // STRING
+ $str = $value['String'];
+ $pos = strpos($str, "\0");
+ if ($pos === false) {
+ $str .= "\0";
+ } else {
+ $str = substr($str, 0, $pos + 1);
+ }
+ $values_writer->putData($str);
+ break;
+ case 1: // Float
+ IO_SWF_Type_Float::build($values_writer, $value['Float']);
+ break;
+ case 2: // null
+ // nothing to do.
+ break;
+ case 3: // undefined
+ // nothing to do.
+ break;
+ case 4: // RegisterNumber
+ $values_writer->putUI8($value['RegisterNumber']);
+ break;
+ case 5: // Boolean
+ $values_writer->putUI8($value['Boolean']);
+ break;
+ case 6: // Double
+ IO_SWF_Type_Double::build($values_writer, $value['Double']);
+ break;
+ case 7: // Integer
+ $values_writer->putUI32LE($value['Integer']);
+ break;
+ case 8: // Constant8
+ $values_writer->putUI8($value['Constant8']);
+ break;
+ case 9: // Constant16
+ $values_writer->putUI16LE($value['Constant16']);
+ break;
+ default:
+ throw new IO_SWF_Exception("Illegal ActionPush value's type($type)");
+ break;
+ }
+ }
+ $values_data = $values_writer->output();
+ $writer->putUI16LE(strlen($values_data));
+ $writer->putData($values_data);
+ break;
+ case 0x99: // ActionJump
+ $writer->putUI16LE(2);
+ $writer->putSI16LE($action['BranchOffset']);
+ break;
+ case 0x9A: // ActionGetURL2
+ $writer->putUI16LE(1);
+ $writer->putUIBits($action['SendVarsMethod'], 2);
+ $writer->putUIBits(0, 4); // Reserved
+ $writer->putUIBit($action['LoadTargetFlag']);
+ $writer->putUIBit($action['LoadVariablesFlag']);
+ break;
+ case 0x9D: // ActionIf
+ $writer->putUI16LE(2);
+ $writer->putSI16LE($action['Offset']);
+ break;
+ case 0x9F: // ActionGotoFrame2
+ if (isset($action['SceneBias'])) {
+ $sceneBlasFlag = 1;
+ $writer->putUI16LE(3);
+ } else {
+ $sceneBlasFlag = 0;
+ $writer->putUI16LE(1);
+ }
+ $writer->putUIBits(0, 6); // Reserved
+ $writer->putUIBit($sceneBlasFlag);
+ $writer->putUIBit($action['PlayFlag']);
+ if ($sceneBlasFlag) {
+ $writer->putUI16LE($action['SceneBias']);
+ }
+ break;
+ default:
+ if (isset($action['Data'])) {
+ $data = $action['Data'];
+ $writer->putUI16LE(strlen($data));
+ $writer->putData($data);
+ } else {
+ $writer->putUI16LE(0);
+ }
+ break;
+ }
+ }
+ }
+ static function string($action, $opts = array()) {
+ $code = $action['Code'];
+ $str = sprintf('%s(Code=0x%02X)', self::getCodeName($code), $code);
+ if (isset($action['Length'])) {
+ $str .= sprintf(" (Length=%d):", $action['Length']);
+ switch ($code) {
+ case 0x88: // ActonConstantPool
+ $str .= " Count=".$action['Count'].PHP_EOL;
+ foreach ($action['ConstantPool'] as $idx => $c) {
+ $str .= "\t[$idx] $c".PHP_EOL;
+ }
+ break;
+ case 0x96: // ActonPush
+ foreach ($action['Values'] as $value) {
+ unset($value['Type']);
+ list($type_name) = array_keys($value);
+ $str .= " ($type_name)".$value[$type_name];
+ }
+ break;
+ default:
+ $data_keys = array_diff(array_keys($action), array('Code', 'Length'));
+ if (count($data_keys) > 0) {
+ foreach ($data_keys as $key) {
+ $value = $action[$key];
+ if (is_array($value)) {
+ $new_value = array();
+ foreach ($value as $k => $v) {
+ $new_value[] = "$k:$v";
+ }
+ $value = implode(' ', $new_value);
+ }
+ $str .= " " ."$key=$value";
+ }
+ }
+ break;
+ }
+ }
+ return $str;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILTERLIST.php
@@ -0,0 +1,38 @@
+<?php
+
+/*
+ * 2011/9/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/FILTER.php';
+
+class IO_SWF_Type_FILTERLIST extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $filterlist = array();
+ $NumberOfFilters = $reader->getUI8();
+ echo "XXX: $NumberOfFilters:{$NumberOfFilters}\n";
+ $filterlist['NumberOfFilters'] = $NumberOfFilters;
+ $filter = array();
+ for ($i = 0 ; $i < $NumberOfFilters ; $i++) {
+ $filter []= IO_SWF_Type_FILTER::parse($reader, $opts);
+ }
+ $filterlist['Filter'] = $filter;
+ return $filterlist;
+ }
+ static function build(&$writer, $filterlist, $opts = array()) {
+ $NumberOfFilters = count($filterlist['Filter']);
+ $writer->putUI8($NumberOfFilters);
+ foreach ($filterlist['Filter'] as $filter_entry) {
+ IO_SWF_Type_FILTER::build($writer, $filter_entry, $opts);
+ }
+ }
+ static function string($filterlist, $opts = array()) {
+ $text = "\tNumberOfFilters:{$filterlist['NumberOfFilters']}\n";
+ foreach ($filterlist['Filter'] as $filter_entry) {
+ $text .= "\t\t".IO_SWF_Type_FILTER::string($$filter_entry, $opts);
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILTERLIST.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/TEXTRECORD.php
@@ -0,0 +1,128 @@
+<?php
+
+/*
+ * 2011/8/22- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/RGB.php';
+require_once dirname(__FILE__).'/RGBA.php';
+require_once dirname(__FILE__).'/GLYPHENTRY.php';
+
+
+class IO_SWF_Type_TEXTRECORD extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $textrecord = array();
+ $reader->byteAlign();
+ $textrecord['TextRecordType'] = $reader->getUIBit();
+ $textrecord['StyleFlagsReserved'] = $reader->getUIBits(3);
+ $styleFlagsHasFont = $reader->getUIBit();
+ $styleFlagsHasColor = $reader->getUIBit();
+ $styleFlagsHasYOffeet = $reader->getUIBit();
+ $styleFlagsHasXOffeet = $reader->getUIBit();
+ $textrecord['StyleFlagsHasFont'] = $styleFlagsHasFont;
+ $textrecord['StyleFlagsHasColor'] = $styleFlagsHasColor;
+ $textrecord['StyleFlagsHasYOffeet'] = $styleFlagsHasYOffeet;
+ $textrecord['StyleFlagsHasXOffeet'] = $styleFlagsHasXOffeet;
+ //
+ if ($styleFlagsHasFont) {
+ $textrecord['FontID'] = $reader->getUI16LE();
+ }
+ if ($styleFlagsHasColor) {
+ if ($opts['tagCode'] == 11) {// DefintText
+ $textrecord['TextColor'] = IO_SWF_Type_RGB::parse($reader);
+ } else { // DefineText2
+ $textrecord['TextColor'] = IO_SWF_Type_RGBA::parse($reader);
+ }
+ }
+ if ($styleFlagsHasXOffeet) {
+ $textrecord['XOffset'] = $reader->getUI16LE();
+ }
+ if ($styleFlagsHasYOffeet) {
+ $textrecord['YOffset'] = $reader->getUI16LE();
+ }
+ if ($styleFlagsHasFont) {
+ $textrecord['TextHeight'] = $reader->getUI16LE();
+ }
+ $glyphCount = $reader->getUI8();
+ $textrecord['GlyphCount'] = $glyphCount;
+ $glyphEntries = array();
+ for ($i = 0 ; $i < $glyphCount; $i++) {
+ $glyphEntries []= IO_SWF_Type_GLYPHENTRY::parse($reader, $opts);
+ }
+ $textrecord['GlyphEntries'] = $glyphEntries;
+ return $textrecord;
+ }
+ static function build(&$writer, $textrecord, $opts = array()) {
+ $writer->byteAlign();
+ $writer->putUIBit($textrecord['TextRecordType']);
+ $writer->putUIBits($textrecord['StyleFlagsReserved'], 3);
+
+ $styleFlagsHasFont = $textrecord['StyleFlagsHasFont'];
+ $styleFlagsHasColor = $textrecord['StyleFlagsHasColor'];
+ $styleFlagsHasYOffeet = $textrecord['StyleFlagsHasYOffeet'];
+ $styleFlagsHasXOffeet = $textrecord['StyleFlagsHasXOffeet'];
+ $writer->putUIBit($styleFlagsHasFont);
+ $writer->putUIBit($styleFlagsHasColor);
+ $writer->putUIBit($styleFlagsHasYOffeet);
+ $writer->putUIBit($styleFlagsHasXOffeet);
+ //
+ if ($styleFlagsHasFont) {
+ $writer->putUI16LE($textrecord['FontID']);
+ }
+ if ($styleFlagsHasColor) {
+ if ($opts['tagCode'] == 11) {// DefintText
+ IO_SWF_Type_RGB::build($writer, $textrecord['TextColor']);
+ } else { // DefineText2
+ IO_SWF_Type_RGBA::build($writer, $textrecord['TextColor']);
+ }
+ }
+ if ($styleFlagsHasXOffeet) {
+ $writer->putUI16LE($textrecord['XOffset']);
+ }
+ if ($styleFlagsHasYOffeet) {
+ $writer->putUI16LE($textrecord['YOffset']);
+ }
+ if ($styleFlagsHasFont) {
+ $writer->putUI16LE($textrecord['TextHeight']);
+ }
+ $glyphCount = count($textrecord['GlyphEntries']);
+ $writer->putUI8($glyphCount);
+ foreach ($textrecord['GlyphEntries'] as $glyphEntrie) {
+ IO_SWF_Type_GLYPHENTRY::build($writer, $glyphEntrie, $opts);
+ }
+ }
+ static function string($textrecord, $opts = array()) {
+ $text = '';
+ if ($textrecord['StyleFlagsHasFont']) {
+ $text .= sprintf("FontID:%d TextHeight:%d ",
+ $textrecord['FontID'],
+ $textrecord['TextHeight']);
+ }
+ if ($textrecord['StyleFlagsHasColor']) {
+ if ($opts['tagCode'] == 11) {// DefintText
+ $color_str = IO_SWF_Type_RGB::string($textrecord['TextColor']);
+ } else { // DefineText2
+ $color_str = IO_SWF_Type_RGBA::string($textrecord['TextColor']);
+ }
+ $text .= "TextColor:$color_str ";
+ }
+ if ($textrecord['StyleFlagsHasXOffeet']) {
+ $text .= sprintf("XOffset: %s", $textrecord['XOffset']);
+ }
+ if ($textrecord['StyleFlagsHasYOffeet']) {
+ $text .= sprintf("YOffset: %s", $textrecord['YOffset']);
+ }
+ if ($text != '') {
+ $text .= "\n\t";
+ }
+
+ $text .= "GryphEntries:";
+ foreach ($textrecord['GlyphEntries'] as $glyphEntrie) {
+ $text .= "\n\t\t".IO_SWF_Type_GLYPHENTRY::string($glyphEntrie, $opts);
+ }
+ $text .= "\n";
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/TEXTRECORD.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/CLIPACTIONRECORD.php
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * 2011/7/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/Action.php';
+require_once dirname(__FILE__).'/CLIPEVENTFLAGS.php';
+
+class IO_SWF_Type_CLIPACTIONRECORD extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $clipactionrecord = array();
+ $clipactionrecord['EventFlags'] = IO_SWF_Type_CLIPEVENTFLAGS::parse($reader, $opts);
+ $clipactionrecord['ActionRecordSize'] = $reader->getUI32LE();
+ if ($clipactionrecord['EventFlags']['ClipEventKeyPress'] == 1) {
+ $clipactionrecord['KeyCode'] = $reader->getUI8();
+ }
+ $actions = array();
+ while ($reader->getUI8() != 0) {
+ $reader->incrementOffset(-1, 0); // 1 byte back
+ $action = IO_SWF_Type_Action::parse($reader);
+ $actions [] = $action;
+ }
+ $clipactionrecord['Actions'] = $actions;
+ return $clipactionrecord;
+ }
+ static function build(&$writer, $clipactionrecord, $opts = array()) {
+ IO_SWF_Type_CLIPEVENTFLAGS::build($writer, $clipactionrecord['EventFlags'], $opts);
+ $actionRecordSize = $clipactionrecord['ActionRecordSize']; // XXX
+ $writer->putUI32LE($actionRecordSize);
+ if ($clipactionrecord['EventFlags']['ClipEventKeyPress'] == 1) {
+ $writer->putUI8($clipactionrecord['KeyCode']);
+ }
+ $actions = array();
+ foreach ($clipactionrecord['Actions'] as $action) {
+ IO_SWF_Type_Action::build($writer, $action);
+ }
+ $writer->putUI8(0); // ActionEndFlag
+ }
+ static function string($clipactionrecord, $opts = array()) {
+ $text = '';
+ $text .= IO_SWF_Type_CLIPEVENTFLAGS::string($clipactionrecord['EventFlags'], $opts);
+ $text .= "\n";
+ $text .= "\tActions:\n";
+ foreach ($clipactionrecord['Actions'] as $action) {
+ $text .= "\t";
+ $text .= IO_SWF_Type_Action::string($action, $opts);
+ $text .= "\n";
+ }
+ return $text;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILTER.php
@@ -0,0 +1,155 @@
+<?php
+
+/*
+ * 2011/9/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/RGBA.php';
+require_once dirname(__FILE__).'/Float.php';
+
+class IO_SWF_Type_FILTER extends IO_SWF_Type {
+ static function parse(&$reader, $opts = array()) {
+ $filter = array();
+ $filterID = $reader->getUI8();
+ $filter['FilterID'] = $filterID;
+ echo "XXX: filterID:$filterID\n";
+ switch ($filterID) {
+ case 0: // DropShadowFilter
+ $dropshadowfilter = array();
+ $dropshadowfilter['DefaultColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+ $dropshadowfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+ $dropshadowfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+ $dropshadowfilter['Angle'] = $reader->getUI32LE(); // 16.16 FIXED
+ $dropshadowfilter['Distance'] = $reader->getUI32LE(); // 16.16 FIXED
+ $dropshadowfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+ $dropshadowfilter['InnerShadow'] = $reader->getUIBit();
+ $dropshadowfilter['Knockout'] = $reader->getUIBit();
+ $dropshadowfilter['CompositeSource'] = $reader->getUIBit();
+ $dropshadowfilter['Passed'] = $reader->getUIBits(5);
+ $filter['DropShadowFilter'] = $dropshadowfilter;
+ break;
+ case 1: // BlurFilter
+ $blurfilter = array();
+ $blurfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+ $blurfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+ $blurfilter['Passes'] = $reader->getUIBits(5);
+ $blurfilter['Reserved'] = $reader->getUIBits(3);
+ $filter['BlurFilter'] = $blurfilter;
+ break;
+ case 2: // GlowFilter
+ $glowfilter = array();
+ $glowfilter['GlowColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+ $glowfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+ $glowfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+ $glowfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+ $glowfilter['InnerGlow'] = $reader->getUIBit();
+ $glowfilter['Knockout'] = $reader->getUIBit();
+ $glowfilter['CompositeSource'] = $reader->getUIBit();
+ $glowfilter['Passed'] = $reader->getUIBits(5);
+ $filte['GlowFilter'] = $glowfilter;
+ break;
+ case 3: // BevelFilter
+ $bevelfilter = array();
+ $bevelfilter['ShadowColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+ $bevelfilter['HighlightColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+ $bevelfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+ $bevelfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+ $bevelfilter['Angle'] = $reader->getUI32LE(); // 16.16 FIXED
+ $bevelfilter['Distance'] = $reader->getUI32LE(); // 16.16 FIXED
+ $bevelfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+ $bevelfilter['InnerShadow'] = $reader->getUIBit();
+ $bevelfilter['Knockout'] = $reader->getUIBit();
+ $bevelfilter['CompositeSource'] = $reader->getUIBit();
+ $bevelfilter['OnTop'] = $reader->getUIBit();
+ $bevelfilter['Passed'] = $reader->getUIBits(4);
+ $filter['BevelFilter'] = $bevelfilter;
+ break;
+ case 4: // GradientFilter
+ $gradientfilter = array();
+ $numColors = $reader->getUI8();
+ $gradientfilter['NumColors'] = $numColors;
+ $gradientColors = array();
+ for ($i = 0 ; $i < $numColors ; $i++) {
+ $gradientColors []= IO_SWF_Type_RGBA::parse($reader, $opts);
+ }
+ $gradientfilter['GradientColors'] = $gradientColors;
+ $gradientRatio = array();
+ for ($i = 0 ; $i < $numColors ; $i++) {
+ $gradientRatio []= $reader->getUI8();
+ }
+ $gradientfilter['GradientRatio'] = $gradientRatio;
+ $filter['GradientFilter'] = $gradientfilter;
+ break;
+ case 5: // ConvolutionFilter
+ $convfilter = array();
+ $matrixX = $reader->getUI8();
+ $matrixY = $reader->getUI8();
+ $convfilter['MatrixX'] = $matrixX;
+ $convfilter['MatrixY'] = $matrixY;
+ $convfilter['Divisor'] = IO_SWF_Type_Float($reader);
+ $convfilter['Bios'] = IO_SWF_Type_Float($reader);
+ $matrix_mn = array();
+ $mn = $marixX * $matrixY;
+ for ($i = 0 ; $i < $mn ; $i++) {
+ $matrix_mn []= IO_SWF_Type_Float($reader);
+ }
+ $convfilter['Matrix'] = $matrix_mn;
+ $convfilter['DefaultColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+ $convfilter['Reserved'] = $reader->getUIBits(6);
+ $convfilter['Clamp'] = $reader->getUIBit();
+ $convfilter['PreserveAlpha'] = $reader->getUIBit();
+ $filter['ColorMatrixFilter'] = $convfilter;
+ break;
+ case 6: // ColorMatrixFilter
+ $matrix_20 = array();
+ for ($i = 0 ; $i < 20 ; $i++) {
+ $matrix_20 []= IO_SWF_Type_Float($reader);
+ }
+ $filter['ColorMatrixFilter'] = array('Matrix' => $matrix_20);
+ break;
+ case 7: // GradientBevelFilter
+ $gradientbevelfilter = array();
+ $numColors = $reader->getUI8();
+ $gradientbevelfilter['NumColors'] = $numColors;
+ $gradientColors = array();
+ for ($i = 0 ; $i < $numColors ; $i++) {
+ $gradientColors []= IO_SWF_Type_RGBA::parse($reader, $opts);
+ }
+ $gradientbevelfilter['GradientColors'] = $gradientColors;
+ $gradientRatio = array();
+ for ($i = 0 ; $i < $numColors ; $i++) {
+ $gradientRatio []= $reader->getUI8();
+ }
+ $gradientbevelfilter['GradientRatio'] = $gradientRatio;
+ $gradientbevelfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+ $gradientbevelfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+ $gradientbevelfilter['Angle'] = $reader->getUI32LE(); // 16.16 FIXED
+ $gradientbevelfilter['Distance'] = $reader->getUI32LE(); // 16.16 FIXED
+ $gradientbevelfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+ $gradientbevelfilter['InnerShadow'] = $reader->getUIBit();
+ $gradientbevelfilter['Knockout'] = $reader->getUIBit();
+ $gradientbevelfilter['CompositeSource'] = $reader->getUIBit();
+ $gradientbevelfilter['OnTop'] = $reader->getUIBit();
+ $gradientbevelfilter['Passed'] = $reader->getUIBits(4);
+ $filter['GradientBevelFilter'] = $gradientbevelfilter;
+ break;
+ }
+ return $filter;
+ }
+ static function build(&$writer, $filterlist, $opts = array()) {
+ $NumberOfFilters = count($filterlist['Filter']);
+ $writer->putUI8($NumberOfFilters);
+ foreach ($filterlist['Filter'] as $filter_entry) {
+ IO_SWF_Type_FILTER::build($writer, $filter_entry, $opts);
+ }
+ }
+ static function string($filterlist, $opts = array()) {
+ $text = "\tNumberOfFilters:{$filterlist['NumberOfFilters']}\n";
+ foreach ($filterlist['Filter'] as $filter_entry) {
+ $text .= "\t\t".IO_SWF_Type_FILTER::string($$filter_entry, $opts);
+ }
+ return $text;
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type/FILTER.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Bitmap.php
@@ -0,0 +1,99 @@
+<?php
+
+/*
+ * Bitmap Utility Routine
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Exception.php';
+
+class IO_SWF_Bitmap {
+ const FORMAT_UNKNOW = 0;
+ const FORMAT_JPEG = 1;
+ const FORMAT_PNG = 2;
+ const FORMAT_GIF = 4;
+ static function detect_bitmap_format($bitmap_data) {
+ if (strncmp($bitmap_data, "\xff\xd8\xff", 3) == 0) {
+ return self::FORMAT_JPEG;
+ } else if (strncmp($bitmap_data, "\x89PNG", 4) == 0) {
+ return self::FORMAT_PNG;
+ } else if (strncmp($bitmap_data, 'GIF', 3) == 0) {
+ return self::FORMAT_GIF;
+ }
+ return self::FORMAT_UNKNOWN;
+ }
+ static function get_jpegsize($jpegdata) {
+ $chunk_length = 0;
+ $jpegdata_len = strlen($jpegdata);
+ for ($idx = 0 ; (($idx + 8) < $jpegdata_len) ; $idx += $chunk_length) {
+ $marker1 = ord($jpegdata[$idx]);
+ if ($marker1 != 0xFF) {
+ break;
+ }
+ $marker2 = ord($jpegdata[$idx + 1]);
+ switch ($marker2) {
+ case 0xD8: // SOI (Start of Image)
+ case 0xD9: // EOI (End of Image)
+ $chunk_length = 2;
+ break;
+ case 0xDA: // SOS
+ throw new IO_SWF_Exception("encounter SOS before SOF");
+ case 0xC0: // SOF0
+ case 0xC1: // SOF1
+ case 0xC2: // SOF2
+ case 0xC3: // SOF3
+ case 0xC5: // SOF5
+ case 0xC6: // SOF6
+ case 0xC7: // SOF7
+ case 0xC9: // SOF9
+ case 0xCA: // SOF10
+ case 0xCB: // SOF11
+ case 0xCD: // SOF13
+ case 0xCE: // SOF14
+ case 0xCF: // SOF15
+ $width = 0x100 * ord($jpegdata[$idx + 7]) + ord($jpegdata[$idx + 8]);
+ $height = 0x100 * ord($jpegdata[$idx + 5]) + ord($jpegdata[$idx + 6]);
+ return array($width, $height); // success
+ default:
+ $chunk_length = 0x100 * ord($jpegdata[$idx + 2]) + ord($jpegdata[$idx + 3]) + 2;
+ if ($chunk_length == 0) { // fail safe;
+ break;
+ }
+ }
+ }
+ return false; // NG
+ }
+
+ static function get_pngsize($pngdata) {
+ $pngdata_len = strlen($pngdata);
+ if ($pngdata_len< 24) {
+ fprintf(stderr, "IO_SWF_Bitmap::get_pngsize: data_len(%lu) < 16\n", $pngdata_len);
+ return 1;
+ }
+ $width = (((ord($pngdata[16])*0x100) + ord($pngdata[17]))*0x100 + ord($pngdata[18]))*0x100 + ord($pngdata[19]);
+ $height =(((ord($pngdata[20])*0x100) + ord($pngdata[21]))*0x100 + ord($pngdata[22]))*0x100 + ord($pngdata[23]);
+ return array('width' => $width, 'height' => $height); // success
+ }
+
+ static function get_gifsize($gifdata) {
+ $gifdata_len = strlen($gifdata);
+ if ($gifdata_len < 10) {
+ fprintf(stderr, "IO_SWF_Bitmap::get_gifsize: data_len(%lu) < 10\n", $gifdata_len);
+ return false;
+ }
+ $width = 0x100 * ord($gifdata[7]) + ord($gifdata[6]);
+ $height = 0x100 * ord($gifdata[9]) + ord($gifdata[8]);
+ return array('width' => $width, 'height' => $height); // success
+ }
+
+ static function get_bitmapsize($bitmapdata) {
+ if (strncmp($bitmapdata, "\xff\xd8\xff", 3) == 0) { // JPEG
+ return self::get_jpegsize($bitmapdata);
+ } elseif (strncmp($bitmapdata,"\x89PNG", 4) == 0) { // PNG
+ return self::get_pngsize($bitmapdata);
+ } elseif (strncmp($bitmapdata, 'GIF', 3) == 0) { // GIF
+ return self::get_gifsize($bitmapdata);
+ }
+ return false; // NG
+ }
+ }
\ No newline at end of file
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Exception.php
@@ -0,0 +1,3 @@
+<?php
+
+class IO_SWF_Exception extends Exception { }
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Exception.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Type.php
@@ -0,0 +1,13 @@
+<?php
+
+/*
+ * 2011/1/25- (c) yoya@awm.jp
+ */
+
+// require_once 'IO/Bit.php';
+
+abstract class IO_SWF_Type {
+ abstract static function parse(&$reader, $opts = array());
+ abstract static function build(&$writer, $data, $opts = array());
+ abstract static function string($data, $opts = array());
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/ActionEditor.php
@@ -0,0 +1,167 @@
+<?php
+
+/*
+ * 2011/10/06 - (c) takebe@cityfujisawa.ne.jp
+ */
+
+require_once dirname(__FILE__).'/Exception.php';
+require_once dirname(__FILE__).'/../SWF.php';
+require_once dirname(__FILE__).'/Tag/Shape.php';
+require_once dirname(__FILE__).'/Tag/Action.php';
+require_once dirname(__FILE__).'/Tag/Sprite.php';
+require_once dirname(__FILE__).'/Lossless.php';
+require_once dirname(__FILE__).'/../SWF/Bitmap.php';
+
+class IO_SWF_ActionEditor extends IO_SWF {
+ static function parseTagContent($tag, $opts) {
+ $code = $tag->code;
+ $name = $tag->getTagInfo($code, 'name');
+ if ($name === false) {
+ $name = 'unknown';
+ }
+ $length = strlen($tag->content);
+ $opts['Version'] = $tag->swfInfo['Version'];
+ if ($code == 12 || $code == 59) {
+ $tag->parseTagContent($opts);
+ $tag->content = null; // remove original binary
+ }
+ if ($code == 39) { // Sprite
+ $tag->parseTagContent($opts);
+ $tag->content = null; // remove original binary
+ foreach ($tag->tag->_controlTags as $control_tag) {
+ self::parseTagContent($control_tag, $opts);
+ }
+ }
+ }
+
+ function parseAllTagContent($opts) {
+ foreach ($this->_tags as $tag) {
+ self::parseTagContent($tag, $opts);
+ }
+ }
+
+ function findActionTagInTags($frame, $tags) {
+ $frame_num = 1;
+ foreach ($tags as $tag) {
+ if ($frame_num == $frame && ($tag->code == 12 || $tag->code == 59)) {
+ return $tag;
+ }
+ if ($tag->code == 1) { // ShowFrame
+ $frame_num++;
+ }
+ }
+ return null;
+ }
+
+ function findSpriteInTags($sprite_id, $tags) {
+ foreach ($tags as $tag) {
+ if ($tag->code == 39) { // Sprite
+ if ($tag->tag->_spriteId == $sprite_id) {
+ return $tag;
+ } else {
+ $result = $this->findSpriteInTags($sprite_id, $tag->tag->_controlTags);
+ if ($result) {
+ return $result;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ function findSprite($sprite_id) {
+ if ($sprite_id == 0) {
+ return null;
+ } else {
+ return $this->findSpriteInTags($sprite_id, $this->_tags);
+ }
+ }
+
+ function insertAction($sprite_id, $frame, $pos, $action) {
+ if ($sprite_id == 0) {
+ $tags = $this->_tags;
+ } else {
+ $sprite = $this->findSprite($sprite_id);
+ if (!$sprite) {
+ return null;
+ }
+ $tags = $sprite->tag->_controlTags;
+ }
+ $action_tag = $this->findActionTagInTags($frame, $tags);
+ if (!$action_tag) {
+ return null;
+ }
+
+ $action_tag->tag->insertAction($pos, $action);
+
+ return true;
+ }
+
+ function insertSimpleTrace($sprite_id, $frame, $pos, $str) {
+ $push_str = array(
+ 'Code' => 0x96,
+ 'Length' => strlen($str) + 2,
+ 'Values' => array(
+ array(
+ 'Type' => 0,
+ 'String' => $str
+ )
+ )
+ );
+ $this->insertAction($sprite_id, $frame, $pos, $push_str);
+
+ $trace = array(
+ 'Code' => 0x26,
+ 'Length' => 0
+ );
+ $this->insertAction($sprite_id, $frame, $pos + 1, $trace);
+ }
+
+ function insertVarDumpTrace($sprite_id, $frame, $pos, $var) {
+ $str = "(^_^)/ $var = ";
+ $push_str = array(
+ 'Code' => 0x96,
+ 'Length' => strlen($str) + 2,
+ 'Values' => array(
+ array(
+ 'Type' => 0,
+ 'String' => $str
+ )
+ )
+ );
+ $this->insertAction($sprite_id, $frame, $pos, $push_str);
+ $str = $var;
+ $push_str = array(
+ 'Code' => 0x96,
+ 'Length' => strlen($str) + 2,
+ 'Values' => array(
+ array(
+ 'Type' => 0,
+ 'String' => $str
+ )
+ )
+ );
+ $this->insertAction($sprite_id, $frame, $pos + 1, $push_str);
+ $get_variable = array(
+ 'Code' => 0x1c,
+ 'Length' => 0
+ );
+ $this->insertAction($sprite_id, $frame, $pos + 2, $get_variable);
+ $string_add = array(
+ 'Code' => 0x21,
+ 'Length' => 0
+ );
+ $this->insertAction($sprite_id, $frame, $pos + 3, $string_add);
+ $trace = array(
+ 'Code' => 0x26,
+ 'Length' => 0
+ );
+ $this->insertAction($sprite_id, $frame, $pos + 4, $trace);
+ }
+
+ function rebuild() {
+ foreach ($this->_tags as $tag) {
+ $tag->buildTagContent();
+ }
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/JPEG.php
@@ -0,0 +1,145 @@
+<?php
+
+require_once 'IO/Bit.php';
+
+class IO_SWF_JPEG {
+ var $marker_name_table = array(
+ 0xD8 => 'SOI',
+ 0xE0 => 'APP0', 0xE1 => 'APP1', 0xE2 => 'APP2', 0xE3 => 'APP3',
+ 0xE4 => 'APP4', 0xE5 => 'APP5', 0xE6 => 'APP6', 0xE7 => 'APP7',
+ 0xE8 => 'APP8', 0xE9 => 'APP9', 0xEA => 'APP10', 0xEB => 'APP11',
+ 0xEC => 'APP12', 0xED => 'APP13', 0xEE => 'APP14', 0xEF => 'APP15',
+ 0xFE => 'COM',
+ 0xDB => 'DQT',
+ 0xC0 => 'SOF0', 0xC1 => 'SOF1', 0xC2 => 'SOF2', 0xC3 => 'SOF3',
+ 0xC5 => 'SOF5', 0xC6 => 'SOF6', 0xC7 => 'SOF7',
+ 0xC8 => 'JPG', 0xC9 => 'SOF9', 0xCA => 'SOF10', 0xCB => 'SOF11',
+ 0xCC => 'DAC', 0xCD => 'SOF13', 0xCE => 'SOF14', 0xCF => 'SOF15',
+ 0xC4 => 'DHT',
+ 0xDA => 'SOS',
+ 0xD0 => 'RST0', 0xD1 => 'RST1', 0xD2 => 'RST2', 0xD3 => 'RST3',
+ 0xD4 => 'RST4', 0xD5 => 'RST5', 0xD6 => 'RST6', 0xD7 => 'RST7',
+ 0xDD => 'DRI',
+ 0xD9 => 'EOI',
+ 0xDC => 'DNL', 0xDE => 'DHP', 0xDF => 'EXP',
+ 0xF0 => 'JPG0', 0xF1 => 'JPG1', 0xF2 => 'JPG2', 0xF3 => 'JPG3',
+ 0xF4 => 'JPG4', 0xF5 => 'JPG5', 0xF6 => 'JPG6', 0xF7 => 'JPG7',
+ 0xF8 => 'JPG8', 0xF9 => 'JPG9', 0xFA => 'JPG10', 0xFB => 'JPG11',
+ 0xFC => 'JPG12', 0xFD => 'JPG13'
+ );
+ var $_jpegdata = null;
+ var $_jpegChunk = array();
+ function input($jpegdata) {
+ $this->_jpegdata = $jpegdata;
+ }
+ function _splitChunk() {
+ $bitin = new IO_Bit();
+ $bitin->input($this->_jpegdata);
+ while ($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: // EOE (End of Image)
+ $this->_jpegChunk[] = array('marker' => $marker2, 'data' => null, 'length' => null);
+ break 2; // while break;
+ case 0xDA: // SOS
+ case 0xD0: case 0xD1: case 0xD2: case 0xD3: // 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 == 0x00) {
+ 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;
+ }
+ }
+ }
+ // from: SOI APP* DQT SOF* DHT SOS EOI
+ // to: SOI APP* SOF* SOS EOI
+ function getImageData() {
+ if (count($this->_jpegChunk) == 0) {
+ $this->_splitChunk();
+ }
+ $bitout = new IO_Bit();
+ foreach ($this->_jpegChunk as $chunk) {
+ $marker = $chunk['marker'];
+ if (($marker == 0xDB) || ($marker == 0xC4)) {
+ continue; // skip DQT(0xDB) or DHT(0xC4)
+ }
+ $bitout->putUI8(0xFF);
+ $bitout->putUI8($marker);
+ if (is_null($chunk['data'])) { // SOI or EOI
+ ; // nothing to do
+ } else {
+ if (! is_null($chunk['length'])) {
+ $bitout->putUI16BE($chunk['length']);
+ }
+ $bitout->putData($chunk['data']);
+ }
+ }
+ return $bitout->output();
+ }
+ // from: SOI APP* DQT SOF* DHT SOS EOI
+ // to: SOI DQT DHT EOI
+ function getEncodingTables() {
+ if (count($this->_jpegChunk) == 0) {
+ $this->_splitChunk();
+ }
+ $bitout = new IO_Bit();
+ $bitout->putUI8(0xFF);
+ $bitout->putUI8(0xD8); // SOI;
+ foreach ($this->_jpegChunk as $chunk) {
+ $marker = $chunk['marker'];
+ if (($marker != 0xDB) && ($marker != 0xC4)) {
+ continue; // skip not ( DQT(0xDB) or DHT(0xC4) )
+ }
+ $bitout->putUI8(0xFF);
+ $bitout->putUI8($marker);
+ $bitout->putUI16BE($chunk['length']);
+ $bitout->putData($chunk['data']);
+ }
+ $bitout->putUI8(0xFF);
+ $bitout->putUI8(0xD9); // EOI;
+ return $bitout->output();
+
+ }
+ function dumpChunk() { // for debug
+ if (count($this->_jpegChunk) == 0) {
+ $this->_splitChunk();
+ }
+ foreach ($this->_jpegChunk as $chunk) {
+ $marker = $chunk['marker'];
+ $marker_name = $this->marker_name_table{$marker};
+ if (is_null($chunk['data'])) {
+ echo "$marker_name:".PHP_EOL;
+ } else {
+ $length = strlen($chunk['data']);
+ $md5 = md5($chunk['data']);
+ echo "$marker_name: length=$length md5=$md5".PHP_EOL;
+ }
+ }
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Base.php
@@ -0,0 +1,11 @@
+<?php
+
+abstract class IO_SWF_Tag_Base {
+ var $swfInfo;
+ function __construct($swfInfo = null) {
+ $this->swfInfo = $swfInfo;
+ }
+ abstract function parseContent($tagCode, $content, $opts = array());
+ abstract function dumpContent($tagCode, $opts = array());
+ abstract function buildContent($tagCode, $opts = array());
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/EditText.php
@@ -0,0 +1,154 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RECT.php';
+require_once dirname(__FILE__).'/../Type/RGBA.php';
+require_once dirname(__FILE__).'/../Type/String.php';
+
+class IO_SWF_Tag_EditText extends IO_SWF_Tag_Base {
+ var $CharacterID;
+ var $Bounds;
+ var $WordWrap, $Multiline, $Password, $ReadOnly;
+ var $AutoSize, $NoSelect, $Border, $WasStatic, $HTML, $UseOutlines;
+ var $FontID = null, $FontClass = null, $FontHeight = null;
+ var $TextColor = null, $MaxLength = null;
+ var $Align = null, $LeftMargin, $RightMargin, $Indent, $Leading;
+ var $VariableName, $InitialText = null;
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ $this->CharacterID = $reader->getUI16LE();
+ $this->Bounds = IO_SWF_Type_RECT::parse($reader);
+ // ----
+ $reader->byteAlign();
+ $hasText = $reader->getUIBit();
+ $this->WordWrap = $reader->getUIBit();
+ $this->Multiline = $reader->getUIBit();
+ $this->Password = $reader->getUIBit();
+ $this->ReadOnly = $reader->getUIBit();
+ $hasTextColor = $reader->getUIBit();
+ $hasMaxLength = $reader->getUIBit();
+ $hasFont = $reader->getUIBit();
+ // ----
+ $hasFontClass = $reader->getUIBit();
+ $this->AutoSize = $reader->getUIBit();
+ $hasLayout = $reader->getUIBit();
+ $this->NoSelect = $reader->getUIBit();
+ $this->Border = $reader->getUIBit();
+ $this->WasStatic = $reader->getUIBit();
+ $this->HTML = $reader->getUIBit();
+ $this->UseOutlines = $reader->getUIBit();
+ if ($hasFont) {
+ $this->FontID = $reader->getUI16LE();
+ }
+ if ($hasFontClass) {
+ $this->FontClass = IO_SWF_Type_String::parse($reader);
+ }
+ if ($hasFont) {
+ $this->FontHeight = $reader->getUI16LE();
+ }
+ if ($hasTextColor) {
+ $this->TextColor = IO_SWF_Type_RGBA::parse($reader);
+ }
+ if ($hasMaxLength) {
+ $this->MaxLength = $reader->getUI16LE();
+ }
+ if ($hasLayout) {
+ $this->Align = $reader->getUI8();
+ $this->LeftMargin = $reader->getUI16LE();
+ $this->RightMargin = $reader->getUI16LE();
+ $this->Indent = $reader->getUI16LE();
+ $this->Leading = $reader->getSI16LE();
+ }
+
+ $this->VariableName = IO_SWF_Type_String::parse($reader);
+ if ($hasText) {
+ $this->InitialText = IO_SWF_Type_String::parse($reader);
+ }
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ echo "\tCharacterID:{$this->CharacterID}\n";
+ echo IO_SWF_Type_RECT::string($this->Bounds)."\n";
+ echo "WordWrap:{$this->WordWrap} Multiline:{$this->Multiline} Password:{$this->Password} ReadOnly:{$this->ReadOnly}\n";
+ if (is_null($this->FontID) === false) {
+ echo "FontID:{$this->FontID} FontHeight:".($this->FontHeight/20)."\n";
+ }
+ if (is_null($this->FontClass) === false) {
+ echo "FontClass:{$this->FontClass}({".bin2hex($this->FontClass).")\n";
+ }
+ if (is_null($this->TextColor) === false) {
+ echo 'TextColor'.IO_SWF_Type_RGBA::string($this->TextColor)."\n";
+ }
+ if (is_null($this->MaxLength) === false) {
+ echo "MaxLength:{$this->MaxLength}\n";
+ }
+ if (is_null($this->Align) === false) {
+ echo "Align:{$this->Align} LeftMargin:{$this->LeftMargin} RightMargin:{$this->RightMargin} Indent:{$this->Indent} Leading:".($this->Leading/20)."\n";
+ }
+ echo "VariableName:{$this->VariableName}\n";
+ if (is_null($this->InitialText) == false) {
+ echo "InitialText:{$this->InitialText}\n";
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ $writer->putUI16LE($this->CharacterID);
+ IO_SWF_Type_RECT::build($writer, $this->Bounds);
+ // ----
+ $hasText = is_null($this->InitialText)?0:1;
+ $hasTextColor = is_null($this->TextColor)?0:1;
+ $hasMaxLength = is_null($this->MaxLength)?0:1;
+ $hasFont = is_null($this->FontID)?0:1;
+ $hasFontClass = is_null($this->FontClass)?0:1;
+ $hasLayout = is_null($this->Align)?0:1;
+ // ----
+ $writer->byteAlign();
+ $writer->putUIBit($hasText);
+ $writer->putUIBit($this->WordWrap);
+ $writer->putUIBit($this->Multiline);
+ $writer->putUIBit($this->Password);
+ $writer->putUIBit($this->ReadOnly);
+ $writer->putUIBit($hasTextColor);
+ $writer->putUIBit($hasMaxLength);
+ $writer->putUIBit($hasFont);
+ // ----
+ $writer->putUIBit($hasFontClass);
+ $writer->putUIBit($this->AutoSize);
+ $writer->putUIBit($hasLayout);
+ $writer->putUIBit($this->NoSelect);
+ $writer->putUIBit($this->Border);
+ $writer->putUIBit($this->WasStatic);
+ $writer->putUIBit($this->HTML);
+ $writer->putUIBit($this->UseOutlines);
+ if ($hasFont) {
+ $writer->putUI16LE($this->FontID);
+ }
+ if ($hasFontClass) {
+ IO_SWF_Type_String::build($writer, $this->FontClass);
+ }
+ if ($hasFont) {
+ $writer->putUI16LE($this->FontHeight);
+ }
+ if ($hasTextColor) {
+ IO_SWF_Type_RGBA::build($writer, $this->TextColor);
+ }
+ if ($hasMaxLength) {
+ $writer->putUI16LE($this->MaxLength);
+ }
+ if ($hasLayout) {
+ $writer->putUI8($this->Align);
+ $writer->putUI16LE($this->LeftMargin);
+ $writer->putUI16LE($this->RightMargin);
+ $writer->putUI16LE($this->Indent);
+ $writer->putSI16LE($this->Leading);
+ }
+ IO_SWF_Type_String::build($writer, $this->VariableName);
+ if ($hasText) {
+ IO_SWF_Type_String::build($writer, $this->InitialText);
+ }
+ return $writer->output();
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/FrameLabel.php
@@ -0,0 +1,26 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/String.php';
+
+class IO_SWF_Tag_FrameLabel extends IO_SWF_Tag_Base {
+ var $_label;
+
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ $this->_label = IO_SWF_Type_String::parse($reader);
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ $label_str = IO_SWF_Type_String::string($this->_label);
+ echo "\tLabel: $label_str\n";
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ IO_SWF_Type_String::build($writer, $this->_label);
+ return $writer->output();
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/FrameLabel.php
___________________________________________________________________
追加: svn:executable
+ *
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Button.php
@@ -0,0 +1,133 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Tag.php';
+require_once dirname(__FILE__).'/../Type/BUTTONRECORD.php';
+require_once dirname(__FILE__).'/../Type/BUTTONCONDACTION.php';
+require_once dirname(__FILE__).'/../Type/Action.php';
+
+class IO_SWF_Tag_Button extends IO_SWF_Tag_Base {
+ var $_buttonId = null;
+ var $_reservedFlags = null;
+ var $_trackAsMenu = null;
+ var $_actionOffset = null;
+ var $_characters = null;
+ var $_actions = null;
+ 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 dumpContent($tagCode, $opts = array()) {
+ $opts['tagCode'] = $tagCode;
+ echo "\tButtonID:{$this->_buttonId} TrackAsMenu:{$this->_trackAsMenu} (ActionOffset:{$this->_actionOffset})\n";
+ echo "\t Characters:\n";
+ $opts['indent']++;
+ foreach ($this->_characters as $character) {
+ $buttonrecord_str = IO_SWF_Type_BUTTONRECORD::string($character, $opts);
+ echo "\t\t$buttonrecord_str\n";
+ }
+ echo "\t Actions:\n";
+ if ($tagCode == 34) { // DefineButton2
+ if (is_null($this->_actions)) {
+ echo "\t\t(no actions)\n";
+ } else {
+ foreach ($this->_actions as $action) {
+ $action_str = IO_SWF_Type_BUTTONCONDACTION::string($action, $opts);
+ echo "\t\t$action_str\n";
+ }
+ }
+ } else {
+ if (is_null($this->_actions)) {
+ echo "\t\t(no actions)\n";
+ } else {
+ foreach ($this->_actions as $action) {
+ $action_str = IO_SWF_Type_Action::string($action, $opts);
+ echo "\t\t$action_str\n";
+ }
+ }
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ $writer->putUI16LE($this->_buttonId);
+ $opts['tagCode'] = $tagCode; ;
+ if ($tagCode == 34) { // DefineButton2
+ $writer->putUIBits($this->_reservedFlags, 7);
+ $writer->putUIBit($this->_trackAsMenu);
+ list($offset_actionOffset, $dummy) = $writer->getOffset();
+ $writer->putUI16LE(0); // dummy;
+ }
+ foreach ($this->_characters as $character) {
+ IO_SWF_Type_BUTTONRECORD::build($writer, $character, $opts);
+ }
+ $writer->putUI8(0); // terminater of button record
+ if ($tagCode == 34) { // DefineButton2
+ $actions = array();
+ if (is_null($this->_actions) === false) {
+ list($offset_buttonCondition, $dummy) = $writer->getOffset();
+ $writer->setUI16LE($offset_buttonCondition - $offset_actionOffset, $offset_actionOffset);
+ foreach ($this->_actions as $idx => $action) {
+ if (isset($this->_actions[$idx + 1]) === false) {
+ $opts['lastAction'] = true;
+ } else {
+ $opts['lastAction'] = false;
+ }
+ IO_SWF_Type_BUTTONCONDACTION::build($writer, $action, $opts);
+ }
+ }
+ } else {
+ foreach ($this->_actions as $action) {
+ IO_SWF_Type_Action::build($writer, $action);
+ }
+ $writer->putUI8(0); // terminator of actions
+
+ }
+ return $writer->output();
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Button.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Action.php
@@ -0,0 +1,201 @@
+<?php
+
+/*
+ * 2011/06/03- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/Action.php';
+
+class IO_SWF_Tag_Action extends IO_SWF_Tag_Base {
+ var $_actions = array();
+ var $_spriteId = null; // DoInitAction
+ var $_labels = array();
+ var $_branches = array();
+
+ static function actionLength($action) {
+ $length = 1;
+ if ($action['Code'] >= 0x80) {
+ $length += 2 + $action['Length'];
+ }
+ return $length;
+ }
+
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ if ($tagCode == 59) { // DoInitAction
+ $this->_spriteId = $reader->getUI16LE();
+ }
+ while ($reader->getUI8() != 0) {
+ $reader->incrementOffset(-1, 0); // 1 byte back
+ $action = IO_SWF_Type_Action::parse($reader);
+ $this->_actions [] = $action;
+ }
+ // ActionEndFlag
+
+ $label_num = 0;
+ for ($i = 0; $i < count($this->_actions); $i++) {
+ $action = $this->_actions[$i];
+ if ($action['Code'] == 0x99 || $action['Code'] == 0x9D) {
+ if ($action['Code'] == 0x99) { // Jump
+ $branch_offset = $action['BranchOffset'];
+ }
+ if ($action['Code'] == 0x9D) { // If
+ $branch_offset = $action['Offset'];
+ }
+ $offset = 0;
+ $j = $i + 1;
+ if ($branch_offset > 0) {
+ while ($offset != $branch_offset) {
+ $offset += IO_SWF_Tag_Action::actionLength(
+ $this->_actions[$j]);
+ $j++;
+ }
+ } else {
+ while ($offset != $branch_offset) {
+ $offset -= IO_SWF_Tag_Action::actionLength(
+ $this->_actions[$j - 1]);
+ $j--;
+ }
+ }
+ if (isset($this->_labels[$j])) {
+ // More than two If / Jump to a label.
+ $this->_branches[$i] = $this->_labels[$j];
+ } else {
+ $this->_branches[$i] = $this->_labels[$j] = $label_num;
+ }
+ $label_num++;
+ }
+ }
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ echo " Actions:";
+ if ($tagCode == 59) { // DoInitAction
+ echo " SpriteID=".$this->_spriteId;
+ }
+ echo "\n";
+ for ($i = 0; $i < count($this->_actions); $i++) {
+ $action = $this->_actions[$i];
+ if (isset($opts['addlabel']) && $opts['addlabel']
+ && isset($this->_labels[$i])) {
+ echo " (LABEL" . $this->_labels[$i] . "):\n";
+ }
+ $action_str = IO_SWF_Type_Action::string($action);
+ if (isset($opts['addlabel']) && $opts['addlabel']
+ && isset($this->_branches[$i])) {
+ echo "\t$action_str (LABEL" . $this->_branches[$i] . ")\n";
+ } else {
+ echo "\t$action_str\n";
+ }
+ }
+ if (isset($opts['addlabel']) && $opts['addlabel']
+ && isset($this->_labels[$i])) {
+ echo " (LABEL" . $this->_labels[$i] . "):\n";
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ if ($tagCode == 59) { // DoInitAction
+ $writer->putUI16LE($this->_spriteId);
+ }
+ for ($i = 0; $i < count($this->_actions); $i++) {
+ $action = $this->_actions[$i];
+ if ($action['Code'] == 0x99 || $action['Code'] == 0x9D) { // Jump
+ // Find label to jump
+ for ($j = 0; $j <= count($this->_actions); $j++) {
+ if (isset($this->_labels[$j])
+ && $this->_labels[$j] == $this->_branches[$i]) {
+ break;
+ }
+ }
+
+ // Calculate new offset
+ $branch_offset = 0;
+ if ($i < $j) {
+ for ($k = $i + 1; $k < $j; $k++) {
+ $branch_offset += IO_SWF_Tag_Action::actionLength(
+ $this->_actions[$k]);
+ }
+ } else {
+ for ($k = $i; $k >= $j; $k--) {
+ $branch_offset -= IO_SWF_Tag_Action::actionLength(
+ $this->_actions[$k]);
+ }
+ }
+ if ($action['Code'] == 0x99) { // Jump
+ $action['BranchOffset'] = $branch_offset;
+ }
+ if ($action['Code'] == 0x9D) { // If
+ $action['Offset'] = $branch_offset;
+ }
+ }
+ IO_SWF_Type_Action::build($writer, $action);
+ }
+ $writer->putUI8(0); // ActionEndFlag
+ return $writer->output();
+ }
+
+ function replaceActionStrings($trans_table) {
+ foreach ($this->_actions as &$action) {
+ switch($action['Code']) {
+ case 0x83: // ActionGetURL
+ ;
+ if (isset($trans_table[$action['UrlString']])) {
+ $action['UrlString'] = $trans_table[$action['UrlString']];
+ }
+ if (isset($trans_table[$action['TargetString']])) {
+ $action['TargetString'] = $trans_table[$action['TargetString']];
+ }
+ break;
+ case 0x88: // ActionConstantPool
+ foreach ($action['ConstantPool'] as $idx_cp => $cp) {
+ if (isset($trans_table[$cp])) {
+ $action['ConstantPool'][$idx_cp] = $trans_table[$cp];
+ }
+ }
+ break;
+ case 0x96: // ActionPush
+ foreach ($action['Values'] as &$value) {
+ if ($value['Type'] == 0) { // Type String
+ if (isset($trans_table[$value['String']])) {
+ $value['String'] = $trans_table[$value['String']];
+ }
+ }
+ }
+ break;
+
+ }
+
+ }
+ // don't touch $action(reference), danger!
+ }
+
+ function insertAction($pos, $action) {
+ array_splice($this->_actions, $pos - 1, 0, array($action));
+
+ $labels = array();
+ $branches = array();
+
+ foreach ($this->_labels as $key => $value) {
+ if ($key < $pos - 1) {
+ $labels[$key] = $value;
+ } else {
+ $labels[$key + 1] = $value;
+ }
+ }
+ $this->_labels = $labels;
+
+ foreach ($this->_branches as $key => $value) {
+ if ($key < $pos - 1) {
+ $branches[$key] = $value;
+ } else {
+ $branches[$key + 1] = $value;
+ }
+ }
+ $this->_branches = $branches;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Remove.php
@@ -0,0 +1,47 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+
+class IO_SWF_Tag_Remove extends IO_SWF_Tag_Base {
+ var $_characterId = null;
+ var $_depth;
+
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ switch ($tagCode) {
+ case 5: // RemoveObject
+ $this->_characterId = $reader->getUI16LE();
+ $this->_depth = $reader->getUI16LE();
+ break;
+ case 28: // RemoveObject2
+ $this->_depth = $reader->getUI16LE();
+ break;
+ }
+ return true;
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ if (is_null($this->_characterId) === false) {
+ echo "\tCharacterId: ".$this->_characterId."\n";
+ }
+ if (is_null($this->_depth) === false) {
+ echo "\tDepth: ".$this->_depth."\n";
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ switch ($tagCode) {
+ case 5: // RemoveObject
+ $this->_characterId = $writer->getUI16LE();
+ $this->_depth = $writer->getUI16LE();
+ break;
+ case 28: // RemoveObject2
+ $this->_depth = $writer->getUI16LE();
+ break;
+ }
+ return $writer->output();
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Shape.php
@@ -0,0 +1,355 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RECT.php';
+require_once dirname(__FILE__).'/../Type/FILLSTYLEARRAY.php';
+require_once dirname(__FILE__).'/../Type/LINESTYLEARRAY.php';
+require_once dirname(__FILE__).'/../Type/SHAPE.php';
+
+class IO_SWF_Tag_Shape extends IO_SWF_Tag_Base {
+ var $_shapeId = null;
+ // DefineShape, DefineShape2, DefineShape3
+ var $_shapeBounds;
+ var $_fillStyles, $_lineStyles;
+ var $_shapeRecords;
+ // DefineMorphShape
+ var $_startBounds, $_endBounds;
+ var $_offset;
+ var $_morphFillStyles, $_morphLineStyles;
+ var $_startEdge, $_endEdges;
+
+ function parseContent($tagCode, $content, $opts = array()) {
+
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+ $reader = new IO_Bit();
+ $reader->input($content);
+ $this->_shapeId = $reader->getUI16LE();
+
+ $opts = array('tagCode' => $tagCode, 'isMorph' => $isMorph);
+
+ if ($isMorph === false) {
+ // 描画スタイル
+ $this->_shapeBounds = IO_SWF_TYPE_RECT::parse($reader);
+ $this->_fillStyles = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
+ $this->_lineStyles = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
+ // 描画枠
+ $this->_shapeRecords = IO_SWF_Type_SHAPE::parse($reader, $opts);
+ } else {
+ $this->_startBounds = IO_SWF_TYPE_RECT::parse($reader);
+ $this->_endBounds = IO_SWF_TYPE_RECT::parse($reader);
+ list($offset_offset, $dummy) = $reader->getOffset();
+ $this->_offset = $reader->getUI32LE();
+ // 描画スタイル
+ $this->_morphFillStyles = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
+ $this->_morphLineStyles = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
+ // 描画枠
+ $this->_startEdge = IO_SWF_Type_SHAPE::parse($reader, $opts);
+ list($end_edge_offset, $dummy) = $reader->getOffset();
+ if ($offset_offset + $this->_offset + 4 != $end_edge_offset) {
+ // warn!
+ $reader->setOffset($offset_offset + $this->_offset + 4, 9);
+ }
+ $this->_endEdge = IO_SWF_Type_SHAPE::parse($reader, $opts);
+ }
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+ if (is_null($this->_shapeId) === false) {
+ echo " ShapeId: {$this->_shapeId}\n";
+ }
+ $opts = array('tagCode' => $tagCode, 'isMorph' => $isMorph);
+
+ if ($isMorph === false) {
+ echo " ShapeBounds: ". IO_SWF_Type_RECT::string($this->_shapeBounds)."\n";
+ echo " FillStyles:\n";
+ echo IO_SWF_Type_FILLSTYLEARRAY::string($this->_fillStyles, $opts);
+ echo " LineStyles:\n";
+ echo IO_SWF_Type_LINESTYLEARRAY::string($this->_lineStyles, $opts);
+
+ echo " ShapeRecords:\n";
+ echo IO_SWF_Type_SHAPE::string($this->_shapeRecords, $opts);
+ } else {
+ echo " StartBounds: ". IO_SWF_Type_RECT::string($this->_startBounds)."\n";
+ echo " EndBounds: ". IO_SWF_Type_RECT::string($this->_endBounds)."\n";
+ echo " FillStyles:\n";
+ echo IO_SWF_Type_FILLSTYLEARRAY::string($this->_morphFillStyles, $opts);
+ echo " LineStyles:\n";
+ echo IO_SWF_Type_LINESTYLEARRAY::string($this->_morphLineStyles, $opts);
+
+ echo " StartEdge:\n";
+ echo IO_SWF_Type_SHAPE::string($this->_startEdge, $opts);
+ echo " endEdge:\n";
+ echo IO_SWF_Type_SHAPE::string($this->_endEdge, $opts);
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $isMorph = ($tagCode == 46) || ($tagCode == 84);
+ $writer = new IO_Bit();
+ if (empty($opts['noShapeId'])) {
+ $writer->putUI16LE($this->_shapeId);
+ }
+ $opts = array('tagCode' => $tagCode);
+
+ if ($isMorph === false) {
+ IO_SWF_Type_RECT::build($writer, $this->_shapeBounds);
+ // 描画スタイル
+ IO_SWF_Type_FILLSTYLEARRAY::build($writer, $this->_fillStyles, $opts);
+ IO_SWF_Type_LINESTYLEARRAY::build($writer, $this->_lineStyles, $opts);
+ // 描画枠
+ $opts['fillStyleCount'] = count($this->_fillStyles);
+ $opts['lineStyleCount'] = count($this->_lineStyles);
+ IO_SWF_Type_SHAPE::build($writer, $this->_shapeRecords, $opts);
+ } else {
+ IO_SWF_Type_RECT::build($writer, $this->_startBounds);
+ IO_SWF_Type_RECT::build($writer, $this->_endBounds);
+
+ $writer->byteAlign();
+ list($offset_offset, $dummy) = $writer->getOffset();
+ $this->_offset = $writer->putUI32LE(0); // at first, write dummy
+
+ // 描画スタイル
+ IO_SWF_Type_FILLSTYLEARRAY::build($writer, $this->_morphFillStyles, $opts);
+ IO_SWF_Type_LINESTYLEARRAY::build($writer, $this->_morphLineStyles, $opts);
+ // 描画枠
+ $opts['fillStyleCount'] = count($this->_morphFillStyles);
+ $opts['lineStyleCount'] = count($this->_morphLineStyles);
+
+ // StartEdge
+ IO_SWF_Type_SHAPE::build($writer, $this->_startEdge, $opts);
+
+ // EndEdge
+ $writer->byteAlign();
+ list($end_edge_offset, $dummy) = $writer->getOffset();
+ $this->_offset = $end_edge_offset - $offset_offset - 4;
+ $writer->setUI32LE($this->_offset, $offset_offset);
+
+ IO_SWF_Type_SHAPE::build($writer, $this->_endEdge, $opts);
+ }
+ return $writer->output();
+ }
+
+ function deforme($threshold) {
+ $startIndex = null;
+ foreach ($this->_shapeRecords as $shapeRecordIndex => $shapeRecord) {
+ if (($shapeRecord['TypeFlag'] == 0) && (isset($shapeRecord['EndOfShape']) === false)) {
+ // StyleChangeRecord
+ $endIndex = $shapeRecordIndex - 1;
+ if (is_null($startIndex) === false) {
+ $this->deformeShapeRecordUnit($threshold, $startIndex, $endIndex);
+ }
+ $startIndex = $shapeRecordIndex;
+ }
+ if (isset($shapeRecord['EndOfShape']) && ($shapeRecord['EndOfShape']) == 0) {
+ // EndShapeRecord
+ $endIndex = $shapeRecordIndex - 1;
+ $this->deformeShapeRecordUnit($threshold, $startIndex, $endIndex);
+ }
+ }
+ $this->_shapeRecords = array_values($this->_shapeRecords);
+ }
+
+ function deformeShapeRecordUnit($threshold, $startIndex, $endIndex) {
+// return $this->deformeShapeRecordUnit_1($threshold, $startIndex, $endIndex);
+ return $this->deformeShapeRecordUnit_2($threshold, $startIndex, $endIndex);
+ }
+ function deformeShapeRecordUnit_1($threshold, $startIndex, $endIndex) {
+ $threshold_2 = $threshold * $threshold;
+ $shapeRecord = $this->_shapeRecords[$startIndex];
+ $prevIndex = null;
+ $currentDrawingPositionX = $shapeRecord['MoveX'];
+ $currentDrawingPositionY = $shapeRecord['MoveY'];
+ for ($i = $startIndex + 1 ;$i <= $endIndex; $i++) {
+ $shapeRecord = & $this->_shapeRecords[$i];
+ if ($shapeRecord['StraightFlag'] == 0) {
+ // 曲線に対する処理
+ $diff_x = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+ $diff_y = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+ $distance_2_control = $diff_x * $diff_x + $diff_y * $diff_y;
+ $diff_x = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+ $diff_y = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+ $distance_2_anchor = $diff_x * $diff_x + $diff_y * $diff_y;
+// if (max($distance_2_control, $distance_2_anchor) > $threshold_2) {
+ if (($distance_2_control + $distance_2_anchor) > $threshold_2) {
+ // 何もしない
+ $prevIndex = $i;
+ $prevDrawingPositionX = $currentDrawingPositionX;
+ $prevDrawingPositionY = $currentDrawingPositionY;
+ $currentDrawingPositionX = $shapeRecord['AnchorX'];
+ $currentDrawingPositionY = $shapeRecord['AnchorY'];
+ continue; // skip
+ }
+ // 直線に変換する
+ $shapeRecord['StraightFlag'] = 1; // to Straight
+ $shapeRecord['X'] = $shapeRecord['AnchorX'];
+ $shapeRecord['Y'] = $shapeRecord['AnchorY'];
+ unset($shapeRecord['ControlX'], $shapeRecord['ControlY']);
+ unset($shapeRecord['AnchorX'], $shapeRecord['AnchorY']);
+ }
+ if (is_null($prevIndex)) {
+ // 何もしない
+ $prevIndex = $i;
+ $prevDrawingPositionX = $currentDrawingPositionX;
+ $prevDrawingPositionY = $currentDrawingPositionY;
+ $currentDrawingPositionX = $shapeRecord['X'];
+ $currentDrawingPositionY = $shapeRecord['Y'];
+ continue; // skip
+ }
+ $diff_x = $shapeRecord['X'] - $prevDrawingPositionX;
+ $diff_y = $shapeRecord['Y'] - $prevDrawingPositionY;
+ $distance_2 = $diff_x * $diff_x + $diff_y * $diff_y;
+ if ($distance_2 > $threshold_2) {
+ // 何もしない
+ $prevIndex = $i;
+ $prevDrawingPositionX = $currentDrawingPositionX;
+ $prevDrawingPositionY = $currentDrawingPositionY;
+ $currentDrawingPositionX = $shapeRecord['X'];
+ $currentDrawingPositionY = $shapeRecord['Y'];
+ continue; // skip
+ }
+ // 前の直線にくっつける。
+ $prevShapeRecord = & $this->_shapeRecords[$prevIndex];
+ $prevShapeRecord['X'] = $shapeRecord['X'];
+ $prevShapeRecord['Y'] = $shapeRecord['Y'];
+ $currentDrawingPositionX = $shapeRecord['X'];
+ $currentDrawingPositionY = $shapeRecord['Y'];
+ unset($this->_shapeRecords[$i]);
+ }
+ }
+
+ function deformeShapeRecordUnit_2($threshold, $startIndex, $endIndex) {
+ $this->deformeShapeRecordUnit_2_curve($threshold, $startIndex, $endIndex);
+ while ($this->deformeShapeRecordUnit_2_line($threshold, $startIndex, $endIndex));
+ }
+
+ function deformeShapeRecordUnit_2_curve($threshold, $startIndex, $endIndex) {
+ $threshold_2 = $threshold * $threshold;
+ $shapeRecord = $this->_shapeRecords[$startIndex];
+ $currentDrawingPositionX = $shapeRecord['MoveX'];
+ $currentDrawingPositionY = $shapeRecord['MoveY'];
+ for ($i = $startIndex + 1 ;$i <= $endIndex; $i++) {
+ $shapeRecord = & $this->_shapeRecords[$i];
+ if ($shapeRecord['StraightFlag'] == 0) {
+ // 曲線に対する処理
+ $diff_x = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+ $diff_y = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+ $distance_2_control = $diff_x * $diff_x + $diff_y * $diff_y;
+ $diff_x = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+ $diff_y = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+ $distance_2_anchor = $diff_x * $diff_x + $diff_y * $diff_y;
+ if (($distance_2_control + $distance_2_anchor) > $threshold_2) {
+ // 何もしない
+ $currentDrawingPositionX = $shapeRecord['AnchorX'];
+ $currentDrawingPositionY = $shapeRecord['AnchorY'];
+ continue; // skip
+ }
+ // 直線に変換する
+ $shapeRecord['StraightFlag'] = 1; // to Straight
+ $shapeRecord['X'] = $shapeRecord['AnchorX'];
+ $shapeRecord['Y'] = $shapeRecord['AnchorY'];
+ unset($shapeRecord['ControlX'], $shapeRecord['ControlY']);
+ unset($shapeRecord['AnchorX'], $shapeRecord['AnchorY']);
+ $currentDrawingPositionX = $shapeRecord['X'];
+ $currentDrawingPositionY = $shapeRecord['Y'];
+ }
+ }
+ }
+
+ function deformeShapeRecordUnit_2_line($threshold, $startIndex, $endIndex) {
+ $threshold_2 = $threshold * $threshold;
+ $shapeRecord = $this->_shapeRecords[$startIndex];
+ $prevIndex = null;
+ $currentDrawingPositionX = $shapeRecord['MoveX'];
+ $currentDrawingPositionY = $shapeRecord['MoveY'];
+ $distance_list_short = array();
+ $distance_table_all = array();
+ for ($i = $startIndex + 1 ;$i <= $endIndex; $i++) {
+ $shapeRecord = & $this->_shapeRecords[$i];
+ if ($shapeRecord['StraightFlag'] == 0) {
+ $diff_x = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+ $diff_y = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+ $distance_2_control = $diff_x * $diff_x + $diff_y * $diff_y;
+ $diff_x = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+ $diff_y = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+ $distance_2_anchor = $diff_x * $diff_x + $diff_y * $diff_y;
+// $distance_list[$i] = $distance_2_control + $distance_2_anchor;
+ $distance_table_all[$i] = $distance_2_control + $distance_2_anchor;
+ $currentDrawingPositionX = $shapeRecord['AnchorX'];
+ $currentDrawingPositionY = $shapeRecord['AnchorY'];
+ } else {
+ $diff_x = $shapeRecord['X'] - $currentDrawingPositionX;
+ $diff_y = $shapeRecord['Y'] - $currentDrawingPositionY;
+ $distance_2 = $diff_x * $diff_x + $diff_y * $diff_y;
+ if ($distance_2 < $threshold_2) {
+ $distance_list_short[] = $i;
+ }
+ $distance_table_all[$i] = $distance_2;
+ $currentDrawingPositionX = $shapeRecord['X'];
+ $currentDrawingPositionY = $shapeRecord['Y'];
+ }
+ }
+ sort($distance_list_short);
+ $deforme_number = 0;
+ foreach ($distance_list_short as $i) {
+ $distance_2 = $distance_table_all[$i];
+ if ($distance_2 > $threshold_2) {
+ continue; // 一定距離以上の線分は処理しない
+ }
+ if (empty($distance_list_all[$i-1]) && empty($distance_list_all[$i+1])) {
+ // 隣の線分が吸収され済みor曲線の場合は処理しない
+
+ }
+ $index_to_merge;
+ if (empty($distance_list_all[$i-1])) {
+ if (empty($distance_list_all[$i+1])) {
+ // 隣の線分が吸収されている場合は処理しない
+ continue;
+ } else {
+ $index_to_merge = $i+1;
+ }
+ } else {
+ if (empty($distance_list_all[$i+1])) {
+ $index_to_merge = $i-1;
+ } else {
+ $index_to_merge = $i-1; // XXX 後で選択する処理を入れる
+ }
+ }
+ // line merge 処理
+ $shapeRecord = $this->_shapeRecords[$i];
+ $shapeRecord_toMerge = & $this->_shapeRecords[$index_to_merge];
+ if ($i > $index_to_merge) {
+ if ($shapeRecord['StraightFlag']) {
+ $shapeRecord_toMerge['X'] = $shapeRecord['X'];
+ $shapeRecord_toMerge['Y'] = $shapeRecord['Y'];
+ } else {
+ $shapeRecord_toMerge['AnchorX'] = $shapeRecord['X'];
+ $shapeRecord_toMerge['AnchorY'] = $shapeRecord['Y'];
+ }
+ }
+ $distance_list_all[$index_to_merge] += $distance_list_all[$i];
+// unset($distance_list_all[$i]);
+ unset($this->_shapeRecords[$i]);
+ $deforme_number += 1;
+ }
+ return $deforme_number;
+ }
+ function countEdges() {
+ $edges_count = 0;
+ if (isset($this->_shapeRecords)) {
+ $shapeRecords = $this->_shapeRecords;
+ } elseif (isset($this->_startEdge)) {
+ $shapeRecords = $this->_startEdge;
+ } else {
+ $shapeRecords = array(); // nothing to do.
+ }
+ foreach ($shapeRecords as $shapeRecordIndex => $shapeRecord) {
+ if (isset($shapeRecord['StraightFlag'])) { // XXX
+ $edges_count++;
+ }
+ }
+ return array($this->_shapeId, $edges_count);
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Shape.php
___________________________________________________________________
追加: svn:mergeinfo
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Place.php
@@ -0,0 +1,187 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Tag.php';
+require_once dirname(__FILE__).'/../Type/String.php';
+require_once dirname(__FILE__).'/../Type/CXFORM.php';
+require_once dirname(__FILE__).'/../Type/CXFORMWITHALPHA.php';
+require_once dirname(__FILE__).'/../Type/CLIPACTIONS.php';
+
+class IO_SWF_Tag_Place extends IO_SWF_Tag_Base {
+ var $_characterId = null; // refid
+ var $_depth = null;
+ var $_matrix = null;
+ var $_colorTransform = null;
+ var $_ratio = null;
+ var $_name = null;
+ var $_clipDepth = null;
+ var $_clipActions = null;
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ switch ($tagCode) {
+ case 4: // PlaceObject
+ $this->_characterId = $reader->getUI16LE();
+ $this->_depth = $reader->getUI16LE();
+ $this->_matrix = IO_SWF_Type_MATRIX::parse($reader);
+ if ($reader->hasNextData()) { // optional
+ $this->_colorTransform = IO_SWF_Type_CXFORM::parse($reader);
+ }
+ break;
+ case 26: // PlaceObject2
+ // placeFlag
+ $this->_placeFlagHasClipActions = $reader->getUIBit();
+ $this->_placeFlagHasClipDepth = $reader->getUIBit();
+ $this->_placeFlagHasName = $reader->getUIBit();
+ $this->_placeFlagHasRatio = $reader->getUIBit();
+ $this->_placeFlagHasColorTransform = $reader->getUIBit();
+ $this->_placeFlagHasMatrix = $reader->getUIBit();
+ $this->_placeFlagHasCharacter = $reader->getUIBit();
+ $this->_placeFlagMove = $reader->getUIBit();
+ //
+ $this->_depth = $reader->getUI16LE();
+ if ($this->_placeFlagHasCharacter) {
+ $this->_characterId = $reader->getUI16LE();
+ }
+ if ($this->_placeFlagHasMatrix) {
+ $this->_matrix = IO_SWF_Type_MATRIX::parse($reader);
+ }
+ if ($this->_placeFlagHasColorTransform) {
+ $this->_colorTransform = IO_SWF_Type_CXFORMWITHALPHA::parse($reader);
+ }
+ if ($this->_placeFlagHasRatio) {
+ $this->_ratio = $reader->getUI16LE();
+ }
+ if ($this->_placeFlagHasName) {
+ $this->_name = IO_SWF_Type_String::parse($reader);
+ }
+ if ($this->_placeFlagHasClipDepth) {
+ $this->_clipDepth = $reader->getUI16LE();
+ }
+ if ($this->_placeFlagHasClipActions) {
+ $this->_clipActions = IO_SWF_Type_CLIPACTIONS::parse($reader, $opts);
+ }
+ break;
+ }
+ return true;
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ if (is_null($this->_characterId) === false) {
+ echo "\tCharacterId: ".$this->_characterId."\n";
+ }
+ if (is_null($this->_depth) === false) {
+ echo "\tDepth: ".$this->_depth."\n";
+ }
+ if (is_null($this->_matrix) === false) {
+ $opts['indent'] = 2;
+ echo "\tMatrix:\n".IO_SWF_Type_MATRIX::string($this->_matrix, $opts)."\n";
+ }
+ if (is_null($this->_colorTransform) === false) {
+ if ($tagCode == 4) { // PlaceObject
+ echo "\tColorTransform: ".IO_SWF_Type_CXFORM::string($this->_colorTransform)."\n";
+ } else {
+ echo "\tColorTransform: ".IO_SWF_Type_CXFORMWITHALPHA::string($this->_colorTransform)."\n";
+ }
+ }
+ if (is_null($this->_ratio) === false) {
+ echo "\tRatio: ".$this->_ratio."\n";
+ }
+ if (is_null($this->_name) === false) {
+ echo "\tName:".$this->_name."\n";
+ }
+ if (is_null($this->_clipDepth) === false) {
+ echo "\tClipDepth:".$this->_clipDepth."\n";
+ }
+ if (is_null($this->_clipActions) === false) {
+ echo "\tClipActions:\n";
+ echo "\t".IO_SWF_Type_CLIPACTIONS::string($this->_clipActions, $opts)."\n";
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ switch ($tagCode) {
+ case 4: // PlaceObject
+ $this->_characterId = $writer->getUI16LE();
+ $this->_depth = $writer->getUI16LE();
+ $this->_matrix = IO_SWF_Type_MATRIX::parse($writer);
+ if ($writer->hasNextData()) { // optional
+ $this->_colorTransform = IO_SWF_Type_CXFORM::parse($writer);
+ }
+ break;
+ case 26: // PlaceObject2
+ //
+ if (is_null($this->_characterId) === false) {
+ $this->_placeFlagHasCharacter = 1;
+ } else {
+ $this->_placeFlagHasCharacter = 0;
+ }
+ if (is_null($this->_matrix) === false) {
+ $this->_placeFlagHasMatrix = 1;
+ } else {
+ $this->_placeFlagHasMatrix = 0;
+ }
+ if (is_null($this->_colorTransform) === false) {
+ $this->_placeFlagHasColorTransform = 1;
+ } else {
+ $this->_placeFlagHasColorTransform = 0;
+ }
+ if (is_null($this->_ratio) === false) {
+ $this->_placeFlagHasRatio = 1;
+ } else {
+ $this->_placeFlagHasRatio = 0;
+ }
+ if (is_null($this->_name) === false) {
+ $this->_placeFlagHasName = 1;
+ } else {
+ $this->_placeFlagHasName = 0;
+ }
+ if (is_null($this->_clipDepth) === false) {
+ $this->_placeFlagHasClipDepth = 1;
+ } else {
+ $this->_placeFlagHasClipDepth = 0;
+ }
+ if (is_null($this->_clipActions) === false) {
+ $this->_placeFlagHasClipActions = 1;
+ } else {
+ $this->_placeFlagHasClipActions = 0;
+ }
+ // placeFlag
+ $writer->putUIBit($this->_placeFlagHasClipActions);
+ $writer->putUIBit($this->_placeFlagHasClipDepth);
+ $writer->putUIBit($this->_placeFlagHasName);
+ $writer->putUIBit($this->_placeFlagHasRatio);
+ $writer->putUIBit($this->_placeFlagHasColorTransform);
+ $writer->putUIBit($this->_placeFlagHasMatrix);
+ $writer->putUIBit($this->_placeFlagHasCharacter);
+ $writer->putUIBit($this->_placeFlagMove);
+ //
+ $writer->putUI16LE($this->_depth);
+ if ($this->_placeFlagHasCharacter) {
+ $writer->putUI16LE($this->_characterId);
+ }
+ if ($this->_placeFlagHasMatrix) {
+ IO_SWF_Type_MATRIX::build($writer, $this->_matrix);
+ }
+ if ($this->_placeFlagHasColorTransform) {
+ IO_SWF_Type_CXFORMWITHALPHA::build($writer, $this->_colorTransform);
+ }
+ if ($this->_placeFlagHasRatio) {
+ $writer->putUI16LE($this->_ratio);
+ }
+ if ($this->_placeFlagHasName) {
+ IO_SWF_Type_String::build($writer, $this->_name);
+ }
+ if ($this->_placeFlagHasClipDepth) {
+ $writer->putUI16LE($this->_clipDepth);
+ }
+ if ($this->_placeFlagHasClipActions) {
+ IO_SWF_Type_CLIPACTIONS::build($writer, $this->_clipActions, $opts);
+ }
+ break;
+ }
+ return $writer->output();
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Place.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Text.php
@@ -0,0 +1,83 @@
+<?php
+
+ /*
+ * 2011/8/22- (c) yoya@awm.jp
+ */
+
+
+require_once 'IO/Bit.php';
+
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RECT.php';
+require_once dirname(__FILE__).'/../Type/MATRIX.php';
+require_once dirname(__FILE__).'/../Type/TEXTRECORD.php';
+
+class IO_SWF_Tag_Text extends IO_SWF_Tag_Base {
+ var $_CharacterID;
+ var $_TextBounds;
+ var $_TextMatrix;
+ var $_GlyphBits;
+ var $_AdvanceBits;
+ function parseContent($tagCode, $content, $opts = array()) {
+ $opts['tagCode'] = $tagCode;
+ $reader = new IO_Bit();
+ $reader->input($content);
+ $this->_CharacterID = $reader->getUI16LE();
+ $this->_TextBounds = IO_SWF_TYPE_RECT::parse($reader);
+ $this->_TextMatrix = IO_SWF_Type_MATRIX::parse($reader);
+ $glyphBits = $reader->getUI8();
+ $advanceBits = $reader->getUI8();
+ $this->_GlyphBits = $glyphBits;
+ $this->_AdvanceBits = $advanceBits;
+ $textRecords = array();
+ $opts['GlyphBits'] = $glyphBits;
+ $opts['AdvanceBits'] = $advanceBits;
+ while ($reader->getUI8() != 0) {
+ $reader->incrementOffset(-1, 0); // 1 byte back
+ $textRecords []= IO_SWF_Type_TEXTRECORD::parse($reader, $opts);
+ }
+ $this->_TextRecords = $textRecords;
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ $opts['tagCode'] = $tagCode;
+ echo "\tCharacterID:{$this->_CharacterID}\n";
+ echo "\tTextBounds:\n";
+ $rect_str = IO_SWF_Type_RECT::string($this->_TextBounds, $opts);
+ echo "\t$rect_str\n";
+ echo "";
+ $opts['indent'] = 2;
+ $matrix_str = IO_SWF_Type_MATRIX::string($this->_TextMatrix, $opts);
+ echo "\tTextMatrix:\n";
+ echo "$matrix_str\n";
+ echo "\tGlyphBits:{$this->_GlyphBits} AdvanceBits:{$this->_AdvanceBits}\n";
+ if (count($this->_TextRecords) == 0) {
+ echo "\t(TEXTRECORD empty)\n";
+ } else {
+ foreach ($this->_TextRecords as $textRecord) {
+ echo "\t".IO_SWF_Type_TEXTRECORD::string($textRecord, $opts);
+ }
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $opts['tagCode'] = $tagCode;
+ $writer = new IO_Bit();
+ $writer->putUI16LE($this->_CharacterID);
+ IO_SWF_TYPE_RECT::build($writer, $this->_TextBounds);
+ IO_SWF_Type_MATRIX::build($writer, $this->_TextMatrix);
+
+ $glyphBits = $this->_GlyphBits;
+ $advanceBits = $this->_AdvanceBits;
+ $writer->putUI8($glyphBits);
+ $writer->putUI8($advanceBits);
+
+ $opts['GlyphBits'] = $glyphBits;
+ $opts['AdvanceBits'] = $advanceBits;
+ foreach ($this->_TextRecords as $textRecord) {
+ IO_SWF_Type_TEXTRECORD::build($writer, $textRecord, $opts);
+ }
+ $writer->putUI8(0); // TEXTRECORD TERMINATER
+ return $writer->output();
+ }
+}
属性に変更があったパス: IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Text.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Jpeg.php
@@ -0,0 +1,55 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+
+class IO_SWF_Tag_Jpeg extends IO_SWF_Tag_Base {
+ var $_CharacterID;
+ var $_AlphaDataOffset = null;
+ var $_JPEGData;
+ var $_ZlibBitmapAlphaData = null;
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ if ($tagCode != 8) { // ! JPEGTable
+ $this->_CharacterID = $reader->getUI16LE();
+ }
+ if ($tagCode == 35) { // DefgineBitsJPEG3
+ $alphaDataOffset = $reader->getUI32LE();
+ $this->_AlphaDataOffset = $alphaDataOffset;
+ }
+ if ($tagCode != 35) { // ! DefgineBitsJPEG3
+ $this->_JPEGData = $reader->getDataUntil(false);
+ } else {
+ $this->_JPEGData = $reader->getData($alphaDataOffset);
+ $this->_ZlibBitmapAlphaData = $reader->getDataUntil(false);
+ }
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ if ($tagCode != 8) { // ! JPEGTables
+ echo "\tCharacterID:{$this->_CharacterID}\n";
+ }
+ if ($tagCode == 35) { // DefineBitsJPEG3
+ echo "\tAlphaDataOffset:{$this->_AlphaDataOffset}\n";
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ if ($tagCode != 8) { // ! JPEGTablesa
+ $writer->putUI16LE($this->_CharacterID);
+ }
+ if ($tagCode == 35) { // DefgineBitsJPEG3
+ $this->_AlphaDataOffset = strlen($this->_JPEGData);
+ $writer->putUI32LE($this->_AlphaDataOffset);
+ }
+ if ($tagCode != 35) { // ! DefgineBitsJPEG3
+ $writer->putData($this->_JPEGData);
+ } else {
+ $writer->putData($this->_JPEGData);
+ $writer->putData($this->_ZlibBitmapAlphaData);
+ }
+ return $writer->output();
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Sprite.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Tag.php';
+
+class IO_SWF_Tag_Sprite extends IO_SWF_Tag_Base {
+ var $_spriteId = null;
+ var $_frameCount = null;
+ var $_controlTags = array();
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+
+ $this->_spriteId = $reader->getUI16LE();
+ $this->_frameCount = $reader->getUI16LE();
+ /* SWF Tags */
+ while (true) {
+ $tag = new IO_SWF_Tag($this->swfInfo);
+ $tag->parse($reader);
+ $this->_controlTags[] = $tag;
+ if ($tag->code == 0) { // END Tag
+ break;
+ }
+ }
+ return true;
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ echo "\tSprite: SpriteID={$this->_spriteId} FrameCount={$this->_frameCount}\n";
+ foreach ($this->_controlTags as $tag) {
+ echo " ";
+ $tag->dump($opts);
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ $writer->putUI16LE($this->_spriteId);
+ $writer->putUI16LE($this->_frameCount);
+ foreach ($this->_controlTags as $tag) {
+ $tagData = $tag->build();
+ if ($tagData != false) {
+ $writer->putData($tag->build());
+ }
+ }
+ return $writer->output();
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/BGColor.php
@@ -0,0 +1,26 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RGB.php';
+
+class IO_SWF_Tag_BGColor extends IO_SWF_Tag_Base {
+ var $_color;
+
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ $this->_color = IO_SWF_Type_RGB::parse($reader);
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ $color_str = IO_SWF_Type_RGB::string($this->_color);
+ echo "\tColor: $color_str\n";
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ IO_SWF_Type_RGB::build($writer, $this->_color);
+ return $writer->output();
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Tag/Lossless.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+
+class IO_SWF_Tag_Lossless extends IO_SWF_Tag_Base {
+ var $_CharacterID;
+ var $_BitmapFormat;
+ var $_BitmapWidth;
+ var $_BitmapHeight;
+ var $_BitmapColorTableSize = null;
+ var $_ZlibBitmapData;
+ function parseContent($tagCode, $content, $opts = array()) {
+ $reader = new IO_Bit();
+ $reader->input($content);
+ $this->_CharacterID = $reader->getUI16LE();
+ $bitmapFormat = $reader->getUI8();
+ $this->_BitmapFormat = $bitmapFormat;
+ $this->_BitmapWidth = $reader->getUI16LE();
+ $this->_BitmapHeight = $reader->getUI16LE();
+ if ($bitmapFormat == 3) {
+ $this->_BitmapColorTableSize = $reader->getUI8() + 1;
+ }
+ $this->_ZlibBitmapData = $reader->getDataUntil(false);
+ }
+
+ function dumpContent($tagCode, $opts = array()) {
+ $bitmapFormat = $this->_BitmapFormat;
+ echo "\tCharacterID:{$this->_CharacterID} BitmapFormat={$bitmapFormat}\n";
+ echo "\tBitmapWidth:{$this->_BitmapWidth} BitmapHeight:{$this->_BitmapHeight}\n";
+ if ($bitmapFormat == 3) {
+ echo "\tBitmapColorTableSize:{$this->_BitmapColorTableSize}\n";
+ }
+ }
+
+ function buildContent($tagCode, $opts = array()) {
+ $writer = new IO_Bit();
+ $writer->putUI16LE($this->_CharacterID);
+ $bitmapFormat = $this->_BitmapFormat;
+ $writer->putUI8($bitmapFormat);
+ $writer->putUI16LE($this->_BitmapWidth);
+ $writer->putUI16LE($this->_BitmapHeight);
+ if ($bitmapFormat == 3) {
+ $writer->putUI8($this->_BitmapColorTableSize - 1);
+ }
+ $writer->putData($this->_ZlibBitmapData);
+ return $writer->output();
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Editor.php
@@ -0,0 +1,581 @@
+<?php
+
+/*
+ * 2010/8/12- (c) yoya@awm.jp
+ */
+
+require_once dirname(__FILE__).'/Exception.php';
+require_once dirname(__FILE__).'/../SWF.php';
+require_once dirname(__FILE__).'/Tag/Shape.php';
+require_once dirname(__FILE__).'/Tag/Action.php';
+require_once dirname(__FILE__).'/Tag/Sprite.php';
+require_once dirname(__FILE__).'/Lossless.php';
+require_once dirname(__FILE__).'/../SWF/Bitmap.php';
+
+class IO_SWF_Editor extends IO_SWF {
+ // var $_headers = array(); // protected
+ // var $_tags = array(); // protected
+ var $shape_adjust_mode = self::SHAPE_BITMAP_NONE;
+
+ const SHAPE_BITMAP_NONE = 0;
+ const SHAPE_BITMAP_MATRIX_RESCALE = 1;
+ const SHAPE_BITMAP_RECT_RESIZE = 2;
+ const SHAPE_BITMAP_TYPE_TILED = 4;
+
+ var $setCharacterIdDone = false;
+ var $setReferenceIdDone = false;
+
+ function rebuild() {
+ foreach ($this->_tags as &$tag) {
+ if ($tag->parseTagContent()) {
+ $tag->content = null;
+ }
+ }
+ }
+
+ function setCharacterId() {
+ if ($this->setCharacterIdDone) {
+ return ;
+ }
+ foreach ($this->_tags as &$tag) {
+ if (is_null($tag->content)) {
+ throw IO_SWF_Exception("setCharacterId method must be called at next of parse");
+ }
+ $content_reader = new IO_Bit();
+ $content_reader->input($tag->content);
+ switch ($tag->code) {
+ case 6: // DefineBits
+ case 21: // DefineBitsJPEG2
+ case 35: // DefineBitsJPEG3
+ case 20: // DefineBitsLossless
+ case 36: // DefineBitsLossless2
+ case 2: // DefineShape (ShapeId)
+ case 22: // DefineShape2 (ShapeId)
+ case 32: // DefineShape3 (ShapeId)
+ case 46: // DefineMorphShape (ShapeId)
+ case 11: // DefineText
+ case 33: // DefineText2
+ case 37: // DefineTextEdit
+ case 39: // DefineSprite
+ $tag->characterId = $content_reader->getUI16LE();
+ break;
+ }
+ }
+ $this->setCharacterIdDone = true;
+ }
+
+ function setReferenceId() {
+ if ($this->setReferenceIdDone) {
+ return ;
+ }
+ foreach ($this->_tags as &$tag) {
+ $content_reader = new IO_Bit();
+ $content_reader->input($tag->content);
+ switch ($tag->code) {
+ case 4: // PlaceObject
+ case 5: // RemoveObject
+ $tag->referenceId = $content_reader->getUI16LE();
+ break;
+ case 26: // PlaceObject2 (Shape Reference)
+ $tag->placeFlag = $content_reader->getUI8();
+ if ($tag->placeFlag & 0x02) {
+ $tag->referenceId = $content_reader->getUI16LE();
+ }
+ break;
+ case 2: // DefineShape (Bitmap ReferenceId)
+ case 22: // DefineShape2 (Bitmap ReferenceId)
+ case 32: // DefineShape3 (Bitmap ReferenceId)
+ case 46: // DefineMorphShape (Bitmap ReferenceId)
+ $refIds = array();
+ if ($tag->parseTagContent() === false) {
+ throw new IO_SWF_Exception("failed to parseTagContent");
+ }
+ if (is_null($tag->tag->_fillStyles) === false) {
+ foreach ($tag->tag->_fillStyles as $fillStyle) {
+ if (isset($fillStyle['BitmapId'])) {
+ if ($fillStyle['BitmapId'] != 65535) {
+ $refIds []= $fillStyle['BitmapId'];
+ }
+ }
+ }
+ }
+ if (is_null($tag->tag->_shapeRecords) === false) {
+ foreach ($tag->tag->_shapeRecords as $shapeRecord) {
+ if (isset($shapeRecord['FillStyles'])) {
+ foreach ($shapeRecord['FillStyles'] as $fillStyle) {
+ if (isset($fillStyle['BitmapId'])) {
+ if ($fillStyle['BitmapId'] != 65535) {
+ $refIds []= $fillStyle['BitmapId'];
+ }
+ }
+ }
+ }
+ }
+ }
+ $tag->referenceId = $refIds;
+ break;
+ }
+ }
+ $this->setReferenceIdDone = true;
+ }
+
+ function replaceTagContent($tagCode, $content, $limit = 1) {
+ $count = 0;
+ foreach ($this->_tags as &$tag) {
+ if ($tag->code == $tagCode) {
+ $tag->content = $content;
+ $count += 1;
+ if ($limit <= $count) {
+ break;
+ }
+ }
+ }
+ return $count;
+ }
+ function getTagContent($tagCode) {
+ $count = 0;
+ foreach ($this->_tags as &$tag) {
+ if ($tag->code == $tagCode) {
+ return $tag->content;
+ }
+ }
+ return null;
+ }
+
+ function replaceTagContentByCharacterId($tagCode, $characterId, $content_after_character_id) {
+ if (! is_array($tagCode)) {
+ $tagCode = array($tagCode);
+ }
+ $ret = false;
+ foreach ($this->_tags as &$tag) {
+ if (in_array($tag->code, $tagCode) && isset($tag->characterId)) {
+ if ($tag->characterId == $characterId) {
+ $tag->content = pack('v', $characterId).$content_after_character_id;
+ $ret = true;
+ break;
+ }
+ }
+ }
+ return $ret;
+ }
+
+ function replaceTagByCharacterId($tagCode, $characterId, $replaceTag) {
+ if (! is_array($tagCode)) {
+ $tagCode = array($tagCode);
+ }
+ $ret = 0;
+ foreach ($this->_tags as &$tag) {
+ if (in_array($tag->code, $tagCode) && isset($tag->characterId)) {
+ if ($tag->characterId == $characterId) {
+ if (isset($replaceTag['Code'])) {
+ $tag->code = $replaceTag['Code'];
+ }
+ $tag->length = strlen($replaceTag['Content']);
+ $tag->content = $replaceTag['Content'];
+ $ret = 1;
+ break;
+ }
+ }
+ }
+ return $ret;
+ }
+
+ function replaceBitmapTagByCharacterId($tagCode, $characterId, $replaceTag) {
+ if (! is_array($tagCode)) {
+ $tagCode = array($tagCode);
+ }
+ $ret = 0;
+ foreach ($this->_tags as &$tag) {
+ if (in_array($tag->code, $tagCode) && isset($tag->characterId)) {
+ if ($tag->characterId == $characterId) {
+ if (isset($replaceTag['Code'])) {
+ $tag->code = $replaceTag['Code'];
+ }
+ $tag->length = strlen($replaceTag['Content']);
+ $tag->content = $replaceTag['Content'];
+ $ret = 1;
+ break;
+ }
+ }
+ }
+ return $ret;
+ }
+
+ function getTagContentByCharacterId($tagCode, $characterId) {
+ foreach ($this->_tags as $tag) {
+ if (($tag->code == $tagCode) && isset($tag->characterId)) {
+ if ($tag->characterId == $characterId) {
+ return $tag->content;
+ break;
+ }
+ }
+ }
+ return null;
+ }
+
+ function deformeShape($threshold) {
+ foreach ($this->_tags as &$tag) {
+ $code = $tag->code;
+ switch($code) {
+ case 2: // DefineShape
+ case 22: // DefineShape2
+ case 32: // DefineShape3
+ $shape = new IO_SWF_Tag_Shape();
+ $shape->parseContent($code, $tag->content);
+ $shape->deforme($threshold);
+ $tag->content = $shape->buildContent($code); // XXX
+ break;
+ }
+ }
+ }
+
+ function setActionVariables($trans_table_or_key_str, $value_str = null) {
+ if(is_array($trans_table_or_key_str)) {
+ $trans_table = $trans_table_or_key_str;
+ } else {
+ $trans_table = array($trans_table_or_key_str => $value_str);
+ }
+ foreach ($this->_tags as $tagidx => &$tag) {
+ $code = $tag->code;
+ switch($code) {
+ case 12: // DoAction
+ case 59: // DoInitAction
+ $action = new IO_SWF_Tag_Action();
+ $action->parseContent($code, $tag->content);
+ break 2;
+ case 1: // ShowFrame
+ break 2;
+ }
+ }
+ if (isset($action) === false) {
+ // 1 frame 目に Action タグがないので新規作成
+ $bytecode = '';
+ foreach ($trans_table as $key_str => $value_str) {
+ $key_strs = explode("\0", $key_str); // \0 除去
+ $value_strs = explode("\0", $value_str); // \0 除去
+ $key_data = chr(0).$key_strs[0]."\0";
+ $value_data = chr(0).$value_strs[0]."\0";
+ // Push
+ $bytecode .= chr(0x96).pack('v', strlen($key_data)).$key_data;
+ // Push
+ $bytecode .= chr(0x96).pack('v', strlen($value_data)).$value_data;
+ // SetVarables
+ $bytecode .= chr(0x1d);
+ // End
+ $bytecode .= chr(0);
+ }
+ $tag_action = new IO_SWF_Tag();
+ $tag_action->code = 12; // DoAction
+ $tag_action->content = $bytecode;
+ // 新規タグ挿入
+ array_splice($this->_tags, $tagidx, 0, array($tag_action));
+ } else { // 既にある Action タグに bytecode 追加。
+ $let_action = array();
+ foreach ($trans_table as $key_str => $value_str) {
+ $let_action []= array('Code' => 0x96, // Push
+ 'Values' => array(
+ array('Type' => 0,
+ 'String' => $key_str)));
+ $let_action []= array('Code' => 0x96, // Push
+ 'Values' => array(
+ array('Type' => 0,
+ 'String' => $value_str)));
+ $let_action []= array('Code' => 0x1d); // SetVariable
+ }
+ $action->_actions = array_merge($let_action, $action->_actions);
+ $tag->content = $action->buildContent($code);
+ }
+ }
+
+ function replaceActionStrings($trans_table_or_from_str, $to_str = null) {
+ if(is_array($trans_table_or_from_str)) {
+ $trans_table = $trans_table_or_from_str;
+ } else {
+ $trans_table = array($trans_table_or_from_str => $to_str);
+ }
+ foreach ($this->_tags as &$tag) {
+ $code = $tag->code;
+ switch($code) {
+ case 12: // DoAction
+ case 59: // DoInitAction
+ $action = new IO_SWF_Tag_Action();
+ $action->parseContent($code, $tag->content);
+ $action->replaceActionStrings($trans_table);
+ $tag->content = null;
+ break;
+ case 39: // Sprite
+ $sprite = new IO_SWF_Tag_Sprite();
+ $sprite->parseContent($code, $tag->content);
+ foreach ($sprite->_controlTags as &$tag_in_sprite) {
+ $code_in_sprite = $tag_in_sprite->code;
+ switch ($code_in_sprite) {
+ case 12: // DoAction
+ case 59: // DoInitAction
+ $action_in_sprite = new IO_SWF_Tag_Action();
+ $action_in_sprite->parseContent($code_in_sprite, $tag_in_sprite->content);
+ $action_in_sprite->replaceActionStrings($trans_table);
+ $tag_in_sprite->content = $action_in_sprite->buildContent($code_in_sprite);
+ break;
+ }
+ }
+ $tag->content = $sprite->buildContent($code);
+ break;
+ }
+ }
+ }
+
+ function replaceBitmapData($bitmap_id, $bitmap_data, $jpeg_alphadata = null) {
+ $this->setCharacterId();
+ // TODO: 後で IO_SWF_Bitmap::detect_bitmap_format を使うよう書き換える
+ if ((strncmp($bitmap_data, 'GIF', 3) == 0) ||
+ (strncmp($bitmap_data, "\x89PNG", 4) == 0)) {
+ $tag = IO_SWF_Lossless::BitmapData2Lossless($bitmap_id, $bitmap_data);
+ $new_width = $tag['width'];
+ $new_height = $tag['height'];
+ } else if (strncmp($bitmap_data, "\xff\xd8\xff", 3) == 0) {
+ $erroneous_header = pack('CCCC', 0xFF, 0xD9, 0xFF, 0xD8);
+ if (is_null($jpeg_alphadata)) {
+ // 21: DefineBitsJPEG2
+ $content = pack('v', $bitmap_id).$erroneous_header.$bitmap_data;
+ $tag = array('Code' => 21,
+ 'Content' => $content);
+ } else {
+ // 35: DefineBitsJPEG3
+ $jpeg_data = $erroneous_header.$bitmap_data;
+ $compressed_alphadata = gzcompress($jpeg_alphadata);
+ $content = pack('v', $bitmap_id).pack('V', strlen($jpeg_data)).$jpeg_data.$compressed_alphadata;
+ $tag = array('Code' => 35,
+ 'Content' => $content);
+ }
+ list($new_width, $new_height) = IO_SWF_Bitmap::get_jpegsize($bitmap_data);
+ } else {
+ throw new IO_SWF_Exception("Unknown Bitmap Format: ".bin2hex(substr($bitmap_data, 0, 4)));
+ }
+ if ($this->shape_adjust_mode > 0) {
+ $ret = $this->applyShapeAdjustModeByRefId($bitmap_id, $new_width, $new_height);
+ }
+ // DefineBits,DefineBitsJPEG2,3, DefineBitsLossless,DefineBitsLossless2
+ $tag_code = array(6, 21, 35, 20, 36);
+ if ($this->shape_adjust_mode > 0) {
+ $tag['shape_adjust_mode'] = $this->shape_adjust_mode;
+ }
+ $ret = $this->replaceBitmapTagByCharacterId($tag_code, $bitmap_id, $tag);
+// $ret = $this->replaceTagByCharacterId($tag_code, $bitmap_id, $tag);
+ return $ret;
+ }
+ function applyShapeAdjustModeByRefId($bitmap_id, $new_height, $old_height) {
+ $shape_adjust_mode = $this->shape_adjust_mode;
+ switch ($shape_adjust_mode) {
+ case self::SHAPE_BITMAP_NONE:
+ return false;
+ case self::SHAPE_BITMAP_MATRIX_RESCALE:
+ case self::SHAPE_BITMAP_RECT_RESIZE:
+
+ case self::SHAPE_BITMAP_TYPE_TYLED:
+ break ;
+ default:
+ trigger_error("Illegal shape_adjust_mode($shape_adjust_mode)");
+ return false;
+ }
+
+ switch ($shape_adjust_mode) {
+ case self::SHAPE_BITMAP_MATRIX_RESCALE:
+ break ;
+ case self::SHAPE_BITMAP_RECT_RESIZE:
+ break ;
+ case self::SHAPE_BITMAP_TYPE_TYLED:
+ break ;
+ default:
+ trigger_error("Illegal shape_adjust_mode($shape_adjust_mode)");
+ return false;
+ }
+ return true;
+ }
+
+ function countShapeEdges($opts = array()) {
+ $count_table = array();
+ foreach ($this->_tags as $tag) {
+ $code = $tag->code;
+ switch ($code) {
+ case 2: // DefineShape
+ case 22: // DefineShape2
+ case 32: // DefineShape3
+ case 46: // DefineMorphShape
+ $shape = new IO_SWF_Tag_Shape();
+ $shape->parseContent($code, $tag->content);
+ list($shape_id, $edges_count) = $shape->countEdges();
+ $count_table[$shape_id] = $edges_count;
+ }
+ }
+ return $count_table;
+ }
+ function setShapeAdjustMode($mode) {
+ $this->shape_adjust_mode = $mode;
+ }
+ function replaceMovieClip($target_path, $mc_swfdata) {
+ $this->setCharacterId();
+ $mc_tag_idx = null;
+ if ($target_path === '') {
+ trigger_error('target_path is null string');
+ return false;
+ }
+ $opts = array('Version' => $this->_headers['Version']); // for parser
+
+ /*
+ * scanning for target sprite tag
+ */
+ $target_sprite_tag_idx = -1;
+ $target_path_list = explode('/', $target_path);
+ $tag_scan_state = 1; // 1:scan for name 2: scan for character id
+ $tag_scan_character_id = -1;
+ foreach (array_reverse(array_keys($this->_tags)) as $tag_idx) {
+ $tag = $this->_tags[$tag_idx];
+ $code = $tag->code;
+ switch($tag_scan_state) {
+ case 1: // scan for name
+ if ($code == 26) { // PlaceObject2
+ if ($tag->parseTagContent($opts) &&
+ isset($tag->tag->_name) &&
+ ($tag->tag->_name == $target_path_list[0])) {
+ array_shift($target_path_list);
+ $tag_scan_character_id = $tag->tag->_characterId;
+ $tag_scan_state = 2; // scan for character id
+ }
+ }
+ break;
+ case 2: // scan for character id
+ if ($code == 39) { // DefineSprite
+ if (isset($tag->characterId) && ($tag->characterId == $tag_scan_character_id)) {
+ if (count($target_path_list) === 0) {
+ $target_sprite_tag_idx = $tag_idx;
+ break; // sprite tag found !!
+ }
+ if ($tag->parseTagContent($opts)) {
+ foreach ($tag->tag->_controlTags as $tag_in_sprite) {
+ // PlaceObject2 in DefineSprite
+ if ($tag_in_sprite->code == 26) {
+ if ($tag_in_sprite->parseTagContent($opts) &&
+ isset($tag_in_sprite->tag->_name) &&
+ ($tag_in_sprite->tag->_name == $target_path_list[0])) {
+ array_shift($target_path_list);
+ $tag_scan_character_id = $tag_in_sprite->tag->_characterId;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (0 <= $target_sprite_tag_idx) {
+ break; // target sprite found
+ }
+ }
+
+ if ($target_sprite_tag_idx < 0) {
+ trigger_error("target_path symbol not found($target_path)");
+ return false;
+ }
+
+ /*
+ * base swf character id check
+ */
+ $used_base_character_id_table = array();
+ foreach ($this->_tags as $tag) {
+ if (isset($tag->characterId)) {
+ $used_base_character_id_table[$tag->characterId] = true;
+ }
+ }
+ /*
+ * new sprite tag character id renumbering
+ */
+ $character_id_trans_table = array();
+ $mc_swf = new IO_SWF_Editor();
+ $mc_swf->parse($mc_swfdata);
+ $mc_swf->setCharacterId();
+ $mc_swf->setReferenceId();
+ $mc_character_tag_list = array();
+ foreach ($mc_swf->_tags as $tag_idx => &$tag) {
+ switch ($tag->code) {
+ case 8: //JPEGTables
+ case 9: // SetBackgroundColor
+ case 69: // FileAttributes
+ unset($mc_swf->_tags[$tag_idx]); // delete
+ continue;
+ }
+ if (isset($tag->characterId)) {
+// echo "code={$tag->code}\n";
+ $cid = $tag->characterId;
+ $new_cid = $cid;
+ while (isset($used_base_character_id_table[$new_cid]) ||
+ isset($character_id_trans_table[$new_cid])) {
+ $new_cid++;
+ }
+ $character_id_trans_table[$cid] = $new_cid;
+ $used_base_character_id_table[$new_cid] = true;
+ $tag->replaceCharacterId($character_id_trans_table);
+ $mc_character_tag_list[] = $tag;
+ unset($mc_swf->_tags[$tag_idx]); // delete
+ }
+ if (isset($tag->referenceId)) {
+ $tag->replaceReferenceId($character_id_trans_table);
+ }
+ if ($tag->code == 39) { // DefineSprite
+ if ($tag->parseTagContent()) {
+ foreach ($tag->tag->_controlTags as &$tag_in_sprite) {
+ $tag_in_sprite->replaceReferenceId($character_id_trans_table);
+ }
+ $tag->content = null;
+ }
+ }
+ }
+ unset($tag);
+ /*
+ * replace
+ */
+ $sprite_tag_ref =& $this->_tags[$target_sprite_tag_idx];
+ if ($sprite_tag_ref->parseTagContent() === false) {
+ return false;
+ }
+ $frameCount = 0;
+ $controlTags = array_values($mc_swf->_tags);
+ foreach ($controlTags as $tag) {
+ if ($tag->code == 1) {
+ $frameCount++;
+ }
+ }
+ $sprite_tag_ref->tag->_frameCount = $frameCount;
+ $sprite_tag_ref->tag->_controlTags = $controlTags;
+ $sprite_tag_ref->content = null;
+ /*
+ * character tag insert
+ */
+ array_splice($this->_tags, $target_sprite_tag_idx, 0, $mc_character_tag_list);
+ return true;
+ }
+ function replaceEditString($id, $initialText) {
+ $this->setCharacterId();
+ foreach ($this->_tags as &$tag) {
+ if ($tag->code == 37) { // DefineEditText
+ if ($tag->characterId === $id) {
+ if ($tag->parseTagContent() === false) {
+ return false;
+ }
+ $tag->tag->initialText = $initialText;
+ $tag->content = null;
+ return true;
+ } else {
+ if ($tag->parseTagContent() === false) {
+ return false;
+ }
+ if ($tag->tag->VariableName === $id) {
+ $tag->tag->InitialText = $initialText;
+ $tag->content = null;
+ return true;
+ }
+ }
+ }
+ }
+ trigger_error("Can't found EditText($id)");
+ return false;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF/Lossless.php
@@ -0,0 +1,207 @@
+<?php
+
+require ('IO/SWF/Tag/Jpeg.php');
+
+class IO_SWF_Lossless {
+ /* PNG と GIF の Bitmap データを Lossless 形式に変換する
+ * return array('Code' => ..., 'Content' => ...)
+ */
+ function BitmapData2Lossless($bitmap_id, $bitmap_data) {
+ $im = imagecreatefromstring($bitmap_data);
+ if ($im === false) {
+ throw new IO_SWF_Exception("not Bitmap Image");
+ }
+
+ $colortable_size = imagecolorstotal($im);
+
+ if ((imageistruecolor($im) === false) && ($colortable_size <= 256)) {
+ $format = 3; // palette format
+ $transparent_exists = false;
+ for ($i = 0 ; $i < $colortable_size ; $i++) {
+ $rgba = imagecolorsforindex($im, $i);
+ if (array_key_exists('alpha', $rgba) && ($rgba['alpha'] > 0)) {
+ $transparent_exists = true;
+ break;
+ }
+ }
+ $colortable = '';
+ if ($transparent_exists == false) {
+ for ($i = 0 ; $i < $colortable_size ; $i++) {
+ $rgb = imagecolorsforindex($im, $i);
+ $colortable .= chr($rgb['red']);
+ $colortable .= chr($rgb['green']);
+ $colortable .= chr($rgb['blue']);
+ }
+ } else {
+ for ($i = 0 ; $i < $colortable_size ; $i++) {
+ $rgba = imagecolorsforindex($im, $i);
+ $alpha = $rgba['alpha'];
+ $alpha = 2 * (127 - $alpha);
+ $colortable .= chr($rgba['red'] * $alpha / 255);
+ $colortable .= chr($rgba['green']* $alpha / 255);
+ $colortable .= chr($rgba['blue'] * $alpha / 255);
+ $colortable .= chr($alpha);
+ }
+ }
+
+ $pixeldata = '';
+ $i = 0;
+ $width = imagesx($im);
+ $height = imagesy($im);
+
+ for ($y = 0 ; $y < $height ; $y++) {
+ for ($x = 0 ; $x < $width ; $x++) {
+ $pixeldata .= chr(imagecolorat($im, $x, $y));
+ $i++;
+ }
+ while (($i % 4) != 0) {
+ $pixeldata .= chr(0);
+ $i++;
+ }
+ }
+ } else { // truecolor
+ $format = 5; // trurcolor format
+ $transparent_exists = false;
+
+ $width = imagesx($im);
+ $height = imagesy($im);
+ for ($y = 0 ; $y < $height ; $y++) {
+ for ($x = 0 ; $x < $width ; $x++) {
+ $i = imagecolorat($im, $x, $y);
+ $rgba = imagecolorsforindex($im, $i);
+ if (array_key_exists('alpha', $rgba) && ($rgba['alpha'] > 0)) {
+ $transparent_exists = true;
+ break;
+ }
+ }
+ }
+ $pixeldata = '';
+ if ($transparent_exists === false) {
+ for ($y = 0 ; $y < $height ; $y++) {
+ for ($x = 0 ; $x < $width ; $x++) {
+ $i = imagecolorat($im, $x, $y);
+ $rgb = imagecolorsforindex($im, $i);
+ $pixeldata .= 0; // Always 0
+ $pixeldata .= chr($rgb['red']);
+ $pixeldata .= chr($rgb['green']);
+ $pixeldata .= chr($rgb['blue']);
+ }
+ }
+ } else {
+ for ($y = 0 ; $y < $height ; $y++) {
+ for ($x = 0 ; $x < $width ; $x++) {
+ $i = imagecolorat($im, $x, $y);
+ $rgba = imagecolorsforindex($im, $i);
+ $alpha = $rgba['alpha'];
+ $alpha = 2 * (127 - $alpha);
+ $pixeldata .= chr($alpha);
+ $pixeldata .= chr($rgba['red'] * $alpha / 255);
+ $pixeldata .= chr($rgba['green']* $alpha / 255);
+ $pixeldata .= chr($rgba['blue'] * $alpha / 255);
+ }
+ }
+ }
+ }
+
+ imagedestroy($im);
+ $content = pack('v', $bitmap_id).chr($format).pack('v', $width).pack('v', $height);
+ if ($format == 3) {
+ $content .= chr($colortable_size - 1).gzcompress($colortable.$pixeldata);
+ } else {
+ $content .= gzcompress($pixeldata);
+ }
+
+ if ($transparent_exists === false) {
+ $tagCode = 20; // DefineBitsLossless
+ } else {
+ $tagCode = 36; // DefineBitsLossless2
+ }
+ $tag = array('Code' => $tagCode,
+ 'width' => $width,
+ 'height' => $height,
+ 'Content' => $content);
+ return $tag;
+ }
+
+ /* Lossless 形式のデータ PNG データに変換する (一時ファイルを作ります)
+ * return (string) $pngdata;
+ */
+ function Lossless2PNG($tagCode, $format, $width, $height,
+ $palette_num, $palette_data,
+ $lossless_bitmap_data) {
+ if ($format == 3) {
+ $im = imagecreate($width, $height);
+ $gd_palette = array();
+ $padding = 0;
+ if ($tagCode == 20) { // DefineBitsLossless
+ $palette_bytesize = 3 * $palette_num;
+ for ($i = 0, $j = 0; $i < $palette_num; $i++) {
+ $red = ord($palette_data[$j++]);
+ $green = ord($palette_data[$j++]);
+ $blue = ord($palette_data[$j++]);
+ $gd_palette []= imagecolorallocate($im, $red, $green, $blue);
+ }
+ } else { // DefineBitsLossless2
+ for ($i = 0, $j = 0; $i < $palette_num; $i++) {
+ $red = ord($palette_data[$j++]);
+ $green = ord($palette_data[$j++]);
+ $blue = ord($palette_data[$j++]);
+ $alpha = ord($palette_data[$j++]);
+ $alpha = 127 - $alpha / 2;
+ $gd_palette []= imagecolorallocatealpha($im, $red, $green, $blue, $alpha);
+ }
+ }
+ if ($width % 4) {
+ $padding = 4 - ($width % 4);
+ }
+ $i = 0;
+ for ($y = 0 ; $y < $height ; $y++) {
+ for ($x = 0 ; $x < $width ; $x++) {
+ $color_index = ord($lossless_bitmap_data[$i++]);
+ imagesetpixel($im, $x, $y, $gd_palette[$color_index]);
+ }
+ $i += $padding;
+ }
+ } else if ($format == 4) {
+ ;
+ } else { // format 5
+ $im = imagecreatetruecolor($width, $height);
+ if ($tagCode == 20) { // DefineBitsLossless
+ $i = 0;
+ for ($y = 0 ; $y < $height ; $y++) {
+ for ($x = 0 ; $x < $width ; $x++) {
+ $i++; // reserved X of XRGB
+ $red = ord($lossless_bitmap_data[$i++]);
+ $green = ord($lossless_bitmap_data[$i++]);
+ $blue = ord($lossless_bitmap_data[$i++]);
+ $color = imagecolorallocate($im, $red, $green, $blue);
+ imagesetpixel($im, $x, $y, $color);
+ }
+ }
+ } else { // DefineBitsLossless2
+ $i = 0;
+ for ($y = 0 ; $y < $height ; $y++) {
+ for ($x = 0 ; $x < $width ; $x++) {
+ $alpha = ord($lossless_bitmap_data[$i++]);
+ $alpha = 127 - $alpha / 2;
+ $red = ord($lossless_bitmap_data[$i++]);
+ $green = ord($lossless_bitmap_data[$i++]);
+ $blue = ord($lossless_bitmap_data[$i++]);
+ $color = imagecolorallocatealpha($im, $red, $green, $blue, $alpha);
+ imagesetpixel($im, $x, $y, $color);
+ }
+ }
+ }
+ }
+ if ($tagCode == 36) { // DefineBitsLossless2
+ imagesavealpha($im, true);
+ }
+ $filename = tempnam("/tmp", "swfcl2p");
+ if (imagepng($im, $filename) === false) {
+ return false;
+ }
+ $png_data = file_get_contents($filename);
+ unlink($filename);
+ return $png_data;
+ }
+}
IO_SWF/tags/2.0.19-stable-20111205020102/IO/SWF.php
@@ -0,0 +1,122 @@
+<?php
+
+/*
+ * 2010/8/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/SWF/Type/RECT.php';
+require_once dirname(__FILE__).'/SWF/Type/MATRIX.php';
+require_once dirname(__FILE__).'/SWF/Tag.php';
+
+class IO_SWF {
+ // instance variable
+ var $_headers = array(); // protected
+ var $_header_size; // XXX
+ var $_tags = array(); // protected
+ // for debug
+ var $_swfdata = null;
+
+ 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;
+ }
+
+ function build() {
+ $writer_head = new IO_Bit();
+ $writer = new IO_Bit();
+
+ /* SWF Header */
+ $writer_head->putData($this->_headers['Signature']);
+ $writer_head->putUI8($this->_headers['Version']);
+ $writer_head->putUI32LE($this->_headers['FileLength']);
+
+ /* SWF Movie Header */
+ IO_SWF_Type_RECT::build($writer, $this->_headers['FrameSize']);
+ $writer->byteAlign();
+ $writer->putUI16LE($this->_headers['FrameRate']);
+ $writer->putUI16LE($this->_headers['FrameCount']);
+
+ /* SWF Tags */
+ foreach ($this->_tags as $idx => $tag) {
+ $tagData = $tag->build();
+ if ($tagData != false) {
+ $writer->putData($tagData);
+ } else {
+ throw new IO_SWF_Exception("tag build failed (tag idx=$idx)");
+ }
+ }
+ list($fileLength, $bit_offset_dummy) = $writer->getOffset();
+ $fileLength += 8; // swf header
+ $this->_headers['FileLength'] = $fileLength;
+ $writer_head->setUI32LE($fileLength, 4);
+ if ($this->_headers['Signature']{0} == 'C') {
+ return $writer_head->output() . gzcompress($writer->output());
+ }
+ return $writer_head->output().$writer->output();
+ }
+
+ function dump($opts = array()) {
+ if (empty($opts['hexdump']) === false) {
+ $bitio = new IO_Bit();
+ $bitio->input($this->_swfdata);
+ }
+ /* SWF Header */
+ echo 'Signature: '.$this->_headers['Signature'].PHP_EOL;
+ echo 'Version: '.$this->_headers['Version'].PHP_EOL;
+ echo 'FileLength: '.$this->_headers['FileLength'].PHP_EOL;
+ echo 'FrameSize: '. IO_SWF_Type_RECT::string($this->_headers['FrameSize'])."\n";
+ echo 'FrameRate: '.($this->_headers['FrameRate'] / 0x100).PHP_EOL;
+ echo 'FrameCount: '.$this->_headers['FrameCount'].PHP_EOL;
+
+ if (empty($opts['hexdump']) === false) {
+ $bitio->hexdump(0, $this->_header_size);
+ $opts['bitio'] =& $bitio; // for tag
+ }
+ $opts['indent'] = 0;
+ /* SWF Tags */
+
+ echo 'Tags:'.PHP_EOL;
+ foreach ($this->_tags as $tag) {
+ $tag->dump($opts);
+ }
+ }
+}