SWF Lossless フォーマット記載ミス
ハマってしまった方、大変申し訳ありません。。
colormap_count のフィールド長を 2bytes と記述していましたが、
正しくは 1byte です。謹んでお詫び申し上げます。
これの お詫びといっては何ですが、
PHP と GD を用いた GIF to Lossless 変換ルーチンを作成しました。
ご参考までに。 (透明GIFにも対応)
GIF to Lossless
$im = imagecreatefromgif($giffile); if ($im === false) { echo "$giffile is not GIF file\n"; exit (1); } $colormap_num = imagecolorstotal($im); $transparent_index = imagecolortransparent($im); $colormap = ''; if ($transparent_index < 0) { for ($i = 0 ; $i < $colormap_num ; $i++) { $rgb = imagecolorsforindex($im, $i); $colormap .= chr($rgb['red']); $colormap .= chr($rgb['green']); $colormap .= chr($rgb['blue']); } } else { for ($i = 0 ; $i < $colormap_num ; $i++) { $rgb = imagecolorsforindex($im, $i); $colormap .= chr($rgb['red']); $colormap .= chr($rgb['green']); $colormap .= chr($rgb['blue']); $colormap .= ($i == $transparent_index)?chr(0):chr(255); } } $indices = ''; $i = 0; $width = imagesx($im); $height = imagesy($im); for ($y = 0 ; $y < $height ; $y++) { for ($x = 0 ; $x < $width ; $x++) { $indices .= chr(imagecolorat($im, $x, $y)); $i++; } while (($i % 4) != 0) { $indices .= chr(0); $i++; } } $format = chr(3); // palette format $content = pack('v', $image_id).$format.pack('v', $width).pack('v', $height); $content .= chr($colormap_num - 1).gzcompress($colormap.$indices); if ($transparent_index < 0) { $tagCode = 20; // DefineBitsLossless } else { $tagCode = 36; // DefineBitsLossless2 }
これで、$content に Lossless 形式のデータ(image_id混み))が入ります。
近いうちに、 [twitter:@yoyapp] さんが細かく説明してくれるはずなので、
図付きの解説が欲しいかたは、いましばらくお待ちください。