diff options
author | 2008-11-13 09:49:11 +0000 | |
---|---|---|
committer | 2008-11-13 09:49:11 +0000 | |
commit | e44a7e37b6c7b5961adaffc62b9042b8d442938e (patch) | |
tree | 95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/encoding/tests/compression/colors3.html | |
parent | a62b9742ee5e28bcec6872d88f50f25b820914f6 (diff) | |
download | scuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz scuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.zip |
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojox/encoding/tests/compression/colors3.html')
-rw-r--r-- | includes/js/dojox/encoding/tests/compression/colors3.html | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/includes/js/dojox/encoding/tests/compression/colors3.html b/includes/js/dojox/encoding/tests/compression/colors3.html new file mode 100644 index 0000000..482c75d --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/colors3.html @@ -0,0 +1,104 @@ +<html> + <head> + <title>Compress colors</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style type="text/css"> + @import "../../../../dojo/resources/dojo.css"; + @import "../../../../dijit/tests/css/dijitTests.css"; + + .pane { margin-top: 2em; } + </style> + <script type="text/javascript" src="../../../../dojo/dojo.js" djConfig="isDebug: true"></script> + <script type="text/javascript"> + dojo.require("dojox.encoding.tests.compression.colors"); + dojo.require("dojox.encoding.easy64"); + dojo.require("dojox.encoding.bits"); + dojo.require("dojox.encoding.compression.splay"); + dojo.require("dojox.encoding.compression.lzw"); + + var dc = dojox.encoding, dcc = dc.compression, colors = dc.tests.compression.colors; + + var run = function(){ + var empty = {}, names = []; + for(var i in colors){ + if(i in empty){ continue; } + names.push(i); + } + names.sort(); + var output = new dc.bits.OutputStream(), result = []; + // encode names + var s = names.join("{"), encoder = new dcc.lzw.Encoder(27); + result.push("<div>Input is " + s.length + " bytes long.</div>"); + result.push("<div>Input: " + s + ".</div>"); + for(var i = 0; i < s.length; ++i){ + var v = s.charCodeAt(i) - 97; + if(v < 0 || v > 26) console.debug("error!", v); + encoder.encode(v, output); + } + encoder.flush(output); + var w = output.getWidth(); + result.push("<div>Output is " + Math.ceil(w / 8) + " bytes (" + w + " bits) long.</div>"); + var buf = output.getBuffer(); + { + var input = new dc.bits.InputStream(buf, buf.length * 8), decoder = new dcc.lzw.Decoder(27); + var t = []; + for(var w = 0; w < s.length;){ + var v = decoder.decode(input); + t.push(v); + w += v.length; + } + t = t.join(""); + var p = []; + for(var i = 0; i < t.length; ++i){ + p.push(String.fromCharCode(t.charCodeAt(i) + 97)); + } + p = p.join(""); + result.push("<div>Control: " + p + ".</div>"); + } + while(buf.length % 3){ buf.push(0); } + var e64 = dc.easy64.encode(buf); + result.push("<div>Encoded output is " + e64.length + " bytes.</div>"); + result.push("<div><textarea>" + e64 + "</textarea></div>"); + // test + { + var buf = dc.easy64.decode(e64); + var input = new dc.bits.InputStream(buf, buf.length * 8), decoder = new dcc.lzw.Decoder(27); + var t = []; + for(var w = 0; w < s.length;){ + var v = decoder.decode(input); + t.push(v); + w += v.length; + } + t = t.join(""); + var p = []; + for(var i = 0; i < t.length; ++i){ + p.push(String.fromCharCode(t.charCodeAt(i) + 97)); + } + p = p.join(""); + result.push("<div>Control: " + p + ".</div>"); + } + // encode values + buf = []; + for(var i = 0; i < names.length; ++i){ + var c = colors[names[i]]; + buf.push(c[0], c[1], c[2]); + } + result.push("<div>Output is " + buf.length + " bytes long.</div>"); + while(buf.length % 4){ buf.push(0); } + e64 = dc.easy64.encode(buf); + result.push("<div>Encoded output is " + e64.length + " bytes.</div>"); + result.push("<div><textarea>" + e64 + "</textarea></div>"); + dojo.byId("status").innerHTML = result.join("\n"); + }; + + dojo.addOnLoad(function(){ + dojo.connect(dojo.byId("run"), "onclick", run); + }); + </script> + </head> + <body> + <h1>Compress colors</h1> + <p><button id="run">Run</button></p> + <div id="status" class="pane"><em>No status yet.</em></div> + </body> +</html> |