每个人都有自己的想法,哪怕仅仅一瞬间~!
| 订阅 XIntend |
| 访问此论坛 |
目前进度50%
已完成数据解码和校验~~~~ 不过目前还是体力活~~~
接下来是还原图片。。。。。。哎,周末结束了.............真不知道我下次有时间是什么时候了。。
以下是测试代码,工程截图............. 哦 对了,这个所谓的 1455049.png就是前篇博文:APNG?
中插入图片,我之所以写这段解码器目的其实只是想让IE也能预览APNG而已........哎.....
不知道哪位同学有APNG解码器的代码呢?有的话可以告诉我声哦~~~
- public function Main():void {
- var l:URLLoader = new URLLoader();
- l.dataFormat = URLLoaderDataFormat.BINARY;
- l.addEventListener(Event.COMPLETE, handleURLloader);
- l.load(new URLRequest("../image/1455049.png"));
- }
- private function handleURLloader(e:Event):void {
- apngdecoder.decode(e.target.data)
- trace(apngdecoder.getResult().getTotalFrames())
- trace(apngdecoder.getResult().getWidth())
- trace(apngdecoder.getResult().getWidth())
- trace(apngdecoder.getResult().getBitDepth())
- }
因为需要用到CRC32的算法,所以改写了下原来as3corelib 的 CRC算法,单独提出来作为一个类,当然您也可以 搜索 "Sample Cyclic Redundancy Code implementation" 找到 ISO C [ISO-9899] 的C语言描述。
下面我都会帖出:
本人的类:
- package {
- import flash.utils.ByteArray;
- /**
- * CRC 32位 校验类
- * 与JAVA的CRC32类似
- * 算法参考自 as3corelib http://code.google.com/p/as3corelib/
- * 的 PNGEncoder.as 中CRC算法部分
- * @author Telds[KingFo]
- * @version 0.0.1
- * @example
- * var bytes:ByteArray = new ByteArray();
- * var crc32:CRC32 = new CRC32();
- * var str:String="kingfo";
- * bytes.writeUTFBytes(str);
- * crc32.update(bytes);
- * trace(crc32);
- */
- public class CRC32 {
- public static const POLYNOMIAL:uint = 0xEDB88320;
- /**
- * 创建获取CRC表
- * @return
- */
- public static function getCrcTable():Array {
- /* Make the table for a fast CRC. */
- if (!crcTableComputed) {
- crcTable = new Array(256);
- var c:uint;
- for (var i:uint=0; i < 256; i++) {
- c = i;
- for (var j:uint=0; j < 8; j++) {
- c = (c & 1) ? (c >>> 1) ^ POLYNOMIAL : (c >>> 1);
- }
- crcTable[i] = c;
- }
- crcTableComputed = true;
- }
- return crcTable;
- }
- /**
- * 构造函数,实例化同时产生CRC表
- */
- public function CRC32() {
- getCrcTable();
- }
- /**
- * 更新CRC
- * @param bytes 指定更新的字节流
- * @param offset 偏移量,默认从 bytes.position=0 开始
- * @param length 长度,默认为0,即指定更新的字节流的长度
- */
- public function update(bytes:ByteArray, offset:int=0,length:int=0):void {
- length = length > 0 ? length : bytes.length;
- var c:uint = ~value;
- for (var i:int = offset; i < length; i++) {
- c = crcTable[(c ^ bytes[i]) & 0xFF] ^ (c >>> 8);
- }
- value = ~c;
- }
- /**
- * 获取结果
- * @return
- */
- public function getValue():uint {
- return value & 0xFFFFFFFF;
- }
- /**
- * 重置结果
- */
- public function reset():void {
- value = 0x00000000;
- }
- public function toString():String {
- var v:uint = getValue();
- return "0x"+v.toString(16).toUpperCase();
- }
- private var value:uint = 0x00000000;
- /* Table of CRCs of all 8-bit messages. */
- private static var crcTable:Array;
- /* Flag: has the table been computed? Initially false. */
- private static var crcTableComputed:Boolean = false;
- }
- }
PNGEncoder.as 中CRC 核心代码部分:
- if (!crcTableComputed) {
- crcTableComputed = true;
- crcTable = [];
- var c:uint;
- for (var n:uint = 0; n < 256; n++) {
- c = n;
- for (var k:uint = 0; k < 8; k++) {
- if (c & 1) {
- c = uint(uint(0xedb88320) ^
- uint(c >>> 1));
- } else {
- c = uint(c >>> 1);
- }
- }
- crcTable[n] = c;
- }
- }
- /////
- c = 0xffffffff;
- for (var i:int = 0; i < (e-p); i++) {
- c = uint(crcTable[
- (c ^ png.readUnsignedByte()) &
- uint(0xff)] ^ uint(c >>> 8));
- }
- c = uint(c^uint(0xffffffff));
Sample Cyclic Redundancy Code implementation
- /* Table of CRCs of all 8-bit messages. */
- unsigned long crc_table[256];
- /* Flag: has the table been computed? Initially false. */
- int crc_table_computed = 0;
- /* Make the table for a fast CRC. */
- void make_crc_table(void)
- {
- unsigned long c;
- int n, k;
- for (n = 0; n < 256; n++) {
- c = (unsigned long) n;
- for (k = 0; k < 8; k++) {
- if (c & 1)
- c = 0xedb88320L ^ (c >> 1);
- else
- c = c >> 1;
- }
- crc_table[n] = c;
- }
- crc_table_computed = 1;
- }
- /* Update a running CRC with the bytes buf[0..len-1]--the CRC
- should be initialized to all 1's, and the transmitted value
- is the 1's complement of the final running CRC (see the
- crc() routine below). */
- unsigned long update_crc(unsigned long crc, unsigned char *buf,
- int len)
- {
- unsigned long c = crc;
- int n;
- if (!crc_table_computed)
- make_crc_table();
- for (n = 0; n < len; n++) {
- c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
- }
- return c;
- }
- /* Return the CRC of the bytes buf[0..len-1]. */
- unsigned long crc(unsigned char *buf, int len)
- {
- return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
- }
今天看到达达(ASFlex)的博文,关于跨域的问题,突然想起来我之前[原]淘宝店家起义篇。。。要做的实验之一,遂趁当前下班时间,在公司里写了一段测试代码。
果然是无法Draw的,在帮助文档已经明确的写了......................................
如何突破呢? 还是以后直接拿TextField来用?
以此标记,下回,改用AVM1+AVM2混合内容测试
目前方法是猥琐的抽出Loader来用
测试连接:
www.xintend.com/temp/icd/index.html
有兴趣的同学可以去玩下~~ 图片可以拖动~~~~~~~
核心 代码部分:
- function handleLoadBtn():void {
- var s:String = urlInput.text;
- var ht:String = "<img src='";
- if (s.length > 0) {
- ht += s;
- ht += "' ";
- ht += "id='image'>";
- tf.htmlText = ht;
- output.text = ht;
- output.text += "\n";
- output.text += tf.getImageReference("image");
- var c:DisplayObject = tf.getImageReference("image");
- ui.addChild(c);
- output.text += "\n ui.addChild(c);";
- }
- }
Theme by Yofox, Powered by Roclog v3.2.0
Copyright © 2007 X-Intend[超级打算]. All rights reserved.