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 | |
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')
11 files changed, 851 insertions, 0 deletions
diff --git a/includes/js/dojox/encoding/tests/compression/_base.js b/includes/js/dojox/encoding/tests/compression/_base.js new file mode 100644 index 0000000..ec9d560 --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/_base.js @@ -0,0 +1,12 @@ +if(!dojo._hasResource["dojox.encoding.tests.compression._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.encoding.tests.compression._base"] = true; +dojo.provide("dojox.encoding.tests.compression._base"); + +try{ + dojo.require("dojox.encoding.tests.compression.splay"); + dojo.require("dojox.encoding.tests.compression.lzw"); +}catch(e){ + doh.debug(e); +} + +} diff --git a/includes/js/dojox/encoding/tests/compression/colors.js b/includes/js/dojox/encoding/tests/compression/colors.js new file mode 100644 index 0000000..caedbb1 --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/colors.js @@ -0,0 +1,156 @@ +if(!dojo._hasResource["dojox.encoding.tests.compression.colors"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.encoding.tests.compression.colors"] = true; +dojo.provide("dojox.encoding.tests.compression.colors"); + +// all CSS3 colors +dojox.encoding.tests.compression.colors = { +aliceblue: [240,248,255], +antiquewhite: [250,235,215], +aqua: [0,255,255], +aquamarine: [127,255,212], +azure: [240,255,255], +beige: [245,245,220], +bisque: [255,228,196], +black: [0,0,0], +blanchedalmond: [255,235,205], +blue: [0,0,255], +blueviolet: [138,43,226], +brown: [165,42,42], +burlywood: [222,184,135], +cadetblue: [95,158,160], +chartreuse: [127,255,0], +chocolate: [210,105,30], +coral: [255,127,80], +cornflowerblue: [100,149,237], +cornsilk: [255,248,220], +crimson: [220,20,60], +cyan: [0,255,255], +darkblue: [0,0,139], +darkcyan: [0,139,139], +darkgoldenrod: [184,134,11], +darkgray: [169,169,169], +darkgreen: [0,100,0], +darkgrey: [169,169,169], +darkkhaki: [189,183,107], +darkmagenta: [139,0,139], +darkolivegreen: [85,107,47], +darkorange: [255,140,0], +darkorchid: [153,50,204], +darkred: [139,0,0], +darksalmon: [233,150,122], +darkseagreen: [143,188,143], +darkslateblue: [72,61,139], +darkslategray: [47,79,79], +darkslategrey: [47,79,79], +darkturquoise: [0,206,209], +darkviolet: [148,0,211], +deeppink: [255,20,147], +deepskyblue: [0,191,255], +dimgray: [105,105,105], +dimgrey: [105,105,105], +dodgerblue: [30,144,255], +firebrick: [178,34,34], +floralwhite: [255,250,240], +forestgreen: [34,139,34], +fuchsia: [255,0,255], +gainsboro: [220,220,220], +ghostwhite: [248,248,255], +gold: [255,215,0], +goldenrod: [218,165,32], +gray: [128,128,128], +green: [0,128,0], +greenyellow: [173,255,47], +grey: [128,128,128], +honeydew: [240,255,240], +hotpink: [255,105,180], +indianred: [205,92,92], +indigo: [75,0,130], +ivory: [255,255,240], +khaki: [240,230,140], +lavender: [230,230,250], +lavenderblush: [255,240,245], +lawngreen: [124,252,0], +lemonchiffon: [255,250,205], +lightblue: [173,216,230], +lightcoral: [240,128,128], +lightcyan: [224,255,255], +lightgoldenrodyellow: [250,250,210], +lightgray: [211,211,211], +lightgreen: [144,238,144], +lightgrey: [211,211,211], +lightpink: [255,182,193], +lightsalmon: [255,160,122], +lightseagreen: [32,178,170], +lightskyblue: [135,206,250], +lightslategray: [119,136,153], +lightslategrey: [119,136,153], +lightsteelblue: [176,196,222], +lightyellow: [255,255,224], +lime: [0,255,0], +limegreen: [50,205,50], +linen: [250,240,230], +magenta: [255,0,255], +maroon: [128,0,0], +mediumaquamarine: [102,205,170], +mediumblue: [0,0,205], +mediumorchid: [186,85,211], +mediumpurple: [147,112,219], +mediumseagreen: [60,179,113], +mediumslateblue: [123,104,238], +mediumspringgreen: [0,250,154], +mediumturquoise: [72,209,204], +mediumvioletred: [199,21,133], +midnightblue: [25,25,112], +mintcream: [245,255,250], +mistyrose: [255,228,225], +moccasin: [255,228,181], +navajowhite: [255,222,173], +navy: [0,0,128], +oldlace: [253,245,230], +olive: [128,128,0], +olivedrab: [107,142,35], +orange: [255,165,0], +orangered: [255,69,0], +orchid: [218,112,214], +palegoldenrod: [238,232,170], +palegreen: [152,251,152], +paleturquoise: [175,238,238], +palevioletred: [219,112,147], +papayawhip: [255,239,213], +peachpuff: [255,218,185], +peru: [205,133,63], +pink: [255,192,203], +plum: [221,160,221], +powderblue: [176,224,230], +purple: [128,0,128], +red: [255,0,0], +rosybrown: [188,143,143], +royalblue: [65,105,225], +saddlebrown: [139,69,19], +salmon: [250,128,114], +sandybrown: [244,164,96], +seagreen: [46,139,87], +seashell: [255,245,238], +sienna: [160,82,45], +silver: [192,192,192], +skyblue: [135,206,235], +slateblue: [106,90,205], +slategray: [112,128,144], +slategrey: [112,128,144], +snow: [255,250,250], +springgreen: [0,255,127], +steelblue: [70,130,180], +tan: [210,180,140], +teal: [0,128,128], +thistle: [216,191,216], +tomato: [255,99,71], +turquoise: [64,224,208], +violet: [238,130,238], +wheat: [245,222,179], +white: [255,255,255], +whitesmoke: [245,245,245], +yellow: [255,255,0], +yellowgreen: [154,205,50] +}; + +} diff --git a/includes/js/dojox/encoding/tests/compression/colors2.html b/includes/js/dojox/encoding/tests/compression/colors2.html new file mode 100644 index 0000000..24bb9fe --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/colors2.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.ascii85"); + 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 % 4){ buf.push(0); } + var a85 = dc.ascii85.encode(buf); + result.push("<div>Encoded output is " + a85.length + " bytes.</div>"); + result.push("<div><textarea>" + a85 + "</textarea></div>"); + // test + { + var buf = dc.ascii85.decode(a85); + 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); } + a85 = dc.ascii85.encode(buf); + result.push("<div>Encoded output is " + a85.length + " bytes.</div>"); + result.push("<div><textarea>" + a85 + "</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> diff --git a/includes/js/dojox/encoding/tests/compression/colors2.js b/includes/js/dojox/encoding/tests/compression/colors2.js new file mode 100644 index 0000000..52f9186 --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/colors2.js @@ -0,0 +1,64 @@ +if(!dojo._hasResource["dojox.encoding.tests.compression.colors2"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.encoding.tests.compression.colors2"] = true; +dojo.provide("dojox.encoding.tests.compression.colors2"); + +// all CSS3 colors +dojox.encoding.tests.compression.colors2 = {}; + +(function(){ + var n = "!mi-='%@Md%8;F\"=E5(:$@nHf!(;HYAOL),#XJKa#UHDMYQ0@q6C8='JBa#m1`YRS;3_\\P=@.(bN\\!)0d:Nar*Fo]]G`\\[X7Cb@r#pc;D3!k*8^\"bS8DAYbu'J5[`7Fh5S1e8`@1^N\"n8R:+ZQt]Ab.S>NP-jkO\"N$oQpbVbYtZl1&rSs%_;'!e8\"ij:*R!%9&P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?N99:!s7#]/quHcnc)oX\\n:6&Is8VrldaQ[oORA4Ze'n?*_>g0S+L8#&cMDa@R<OITYf,Dus53nW!&DeSqXEYI!<7QL!+sKU!!(9T<R[.NgH;f^HYDgIqO0t&bf:HP)&[Dds8)cViW%uHs5'jX!.b%@k(%s^CQ9Y>V#^Na!8;DCmc^[<qj=STmb;]Es6nM<g:>I^5QAOBh4WT.i9#OiJH#TL]T8+>C#Ot='Dd6\"oV>kIMc]rOm\\!H0^qda@cKf4Kc#A2pE.F&MqYC3lIn#$sd^4r5J:Q:ef`,GO5iC#WK'r<gZiC(*p%A\"XrrAM41&q:S"; + var a = function(s){ + var n = s.length, r = [], b = [0, 0, 0, 0, 0], i, j, t, x, y, d; + for(i = 0; i < n; i += 5){ + for(j = 0; j < 5; ++j){ b[j] = s.charCodeAt(i + j) - 33; } + t = (((b[0] * 85 + b[1]) * 85 + b[2]) * 85 + b[3]) * 85 + b[4]; + x = t & 255; t >>>= 8; y = t & 255; t >>>= 8; + r.push(t >>> 8, t & 255, y, x); + } + return r; + }; + var B = function(f){ this.f = f; this.y = this.t = 0; }; + B.prototype.g = function(b){ + var r = 0; + while(b){ + var w = Math.min(b, 8 - this.t), v = this.f[this.y] >>> (8 - this.t - w); + r <<= w; r |= v & ~(~0 << w); + if((this.t += w) == 8){ ++this.y; this.t = 0; } + b -= w; + } + return r; + }; + var D = function(n, w){ + this.c = new Array(n); this.w = w; this.p = -1; + for(var i = 0; i < n; ++i){ this.c[i] = [i + 97]; } + }; + D.prototype.d = function(s){ + var c = s.g(this.w), v; + if(c < this.c.length){ + v = this.c[c]; + if(this.p >= 0){ + this.c.push(this.c[this.p].concat(v[0])); + } + }else{ + this.c.push([]); + ++this.w; + return []; + } + this.p = c; + return v; + }; + var i = new B(a(n)), d = new D(27, 5), t = []; + while(t.length < 1455){ + var v = d.d(i); + dojo.forEach(v, function(x){ t.push(x); }); + } + var n2 = dojo.map(t, function(x){ return String.fromCharCode(x); }).join("").split("{"); + i = a(c); + for(var j = 0, k = 0; j < n2.length; ++j){ + dojox.encoding.tests.compression.colors2[n2[j]] = [i[k++], i[k++], i[k++]]; + } + +})(); + +} 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> diff --git a/includes/js/dojox/encoding/tests/compression/colors3.js b/includes/js/dojox/encoding/tests/compression/colors3.js new file mode 100644 index 0000000..f0a1587 --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/colors3.js @@ -0,0 +1,53 @@ +if(!dojo._hasResource["dojox.encoding.tests.compression.colors3"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.encoding.tests.compression.colors3"] = true; +dojo.provide("dojox.encoding.tests.compression.colors3"); + +// all CSS3 colors +dojox.encoding.tests.compression.colors3 = {}; + +(function(){ + var n = "!N!C@\",5%;!.4)1D7()4E!K!FS-!2).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var c = "]0D`_OP8!0``@``5]0``^@8=`_4%!!!!`_P.!!$`CCPCJ3IKXLC(8Z[A@`]!UGE?`X^1:*8N``D=X\"1]!0``!!#,!)O,O)9,K;GJ!'1!K;GJP<>LCQ#,67MP`YQ!G4,-CQ!![::[D\\S03$W,,U^0,U^0!-\\2F!$4`R34!,``;7FJ;7FJ(J$`MC)C``LQ)IMC`Q$`X.T=_0D``^=!WK5AA)#!!)!!L@]PA)#!]0`Q`WGUT6R=3Q##```Q]/;-ZO<[``$V@0Q!``L.L>DG])#!Y0``_PL3U^04E/[1U^04`\\<\"`[\"[),+KB]\\[>YC:>YC:M-4?```A!0]!-MUS_P$G`Q$`A!!!:MWK!!$.OF84EX$<0,.R?WDO!0K;3.(-RR7&'2FQ^@`[`_4B`_3V`^[N!!#!`@8GA)!!;YYD`[5!`U5!WH$7\\OCKG0O9L_\\OWX#4`_`6`^KZT95``]$,X;$>M/$GA!#!`Q!!P)_017HBCU54_I\"S^+2A,IN8``8OI&)NQ-$!B]\\L;FL.=)#1=)#1``L[!0^`2I+UUL3-!)#!W,`9`W.(1/$1\\I,O^>[T````^@8V``]!GMUS!!!!"; + var B = function(f){ var t = this; t.f = f; t.y = t.t = 0; t.x = f.charCodeAt(0) - 33; }; + B.prototype.g = function(b){ + var r = 0, t = this; + while(b){ + var w = Math.min(b, 6 - t.t), v = t.x >>> (6 - t.t - w); + r <<= w; r |= v & ~(~0 << w); + if((t.t += w) == 6){ t.x = t.f.charCodeAt(++t.y) - 33; t.t = 0; } + b -= w; + } + return r; + }; + var D = function(n, w){ + this.c = new Array(n); this.w = w; this.p = -1; + for(var i = 0; i < n; ++i){ this.c[i] = [i + 97]; } + }; + D.prototype.d = function(s){ + var c = s.g(this.w), t = this, v; + if(c < t.c.length){ + v = t.c[c]; + if(t.p >= 0){ + t.c.push(t.c[t.p].concat(v[0])); + } + }else{ + t.c.push([]); + ++t.w; + return []; + } + t.p = c; + return v; + }; + var i = new B(n), d = new D(27, 5), t = []; + while(t.length < 1455){ + var v = d.d(i); + dojo.forEach(v, function(x){ t.push(x); }); + } + var n2 = dojo.map(t, function(x){ return String.fromCharCode(x); }).join("").split("{"); + i = new B(c); + for(var j = 0; j < n2.length; ++j){ + dojox.encoding.tests.compression.colors3[n2[j]] = [i.g(8), i.g(8), i.g(8)]; + } +})(); + +} diff --git a/includes/js/dojox/encoding/tests/compression/lzw.js b/includes/js/dojox/encoding/tests/compression/lzw.js new file mode 100644 index 0000000..7956a0e --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/lzw.js @@ -0,0 +1,54 @@ +if(!dojo._hasResource["dojox.encoding.tests.compression.lzw"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.encoding.tests.compression.lzw"] = true; +dojo.provide("dojox.encoding.tests.compression.lzw"); +dojo.require("dojox.encoding.compression.lzw"); +dojo.require("dojox.encoding.bits"); + +(function(){ + var msg1 = "The rain in Spain falls mainly on the plain."; + var msg2 = "The rain in Spain falls mainly on the plain.1"; + var msg3 = "The rain in Spain falls mainly on the plain.ab"; + var msg4 = "The rain in Spain falls mainly on the plain.!@#"; + var dc = dojox.encoding.compression, dcb = dojox.encoding.bits, dcl = dc.lzw; + + var s2b = function(s){ + var b = []; + for(var i = 0; i < s.length; ++i){ + b.push(s.charCodeAt(i)); + } + return b; + }; + + var b2s = function(b){ + var s = []; + dojo.forEach(b, function(c){ s.push(String.fromCharCode(c)); }); + return s.join(""); + }; + + var encode = function(msg){ + var x = new dcb.OutputStream(), encoder = new dcl.Encoder(128); + dojo.forEach(s2b(msg), function(v){ encoder.encode(v, x); }); + encoder.flush(x); + console.debug("bits =", x.getWidth()); + return x.getBuffer(); + }; + + var decode = function(n, buf){ + var x = new dcb.InputStream(buf, buf.length * 8), decoder = new dcl.Decoder(128), t = [], w = 0; + while(w < n){ + var v = decoder.decode(x); + t.push(v); + w += v.length; + } + return t.join(""); + }; + + tests.register("dojox.encoding.tests.compression.lzw", [ + function testLzwMsg1(t){ t.assertEqual(msg1, decode(msg1.length, encode(msg1))); }, + function testLzwMsg2(t){ t.assertEqual(msg2, decode(msg2.length, encode(msg2))); }, + function testLzwMsg3(t){ t.assertEqual(msg3, decode(msg3.length, encode(msg3))); }, + function testLzwMsg4(t){ t.assertEqual(msg4, decode(msg4.length, encode(msg4))); } + ]); +})(); + +} diff --git a/includes/js/dojox/encoding/tests/compression/runTests.html b/includes/js/dojox/encoding/tests/compression/runTests.html new file mode 100644 index 0000000..4a24eef --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/runTests.html @@ -0,0 +1,9 @@ +<html> + <head> + <title>DojoX Compression Unit Test Runner</title> + <meta http-equiv="REFRESH" content="0;url=../../../../util/doh/runner.html?testModule=dojox.encoding.tests.compression._base" /> + </head> + <body> + <p>Redirecting to D.O.H runner.</p> + </body> +</html> diff --git a/includes/js/dojox/encoding/tests/compression/splay.js b/includes/js/dojox/encoding/tests/compression/splay.js new file mode 100644 index 0000000..44d157c --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/splay.js @@ -0,0 +1,49 @@ +if(!dojo._hasResource["dojox.encoding.tests.compression.splay"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.encoding.tests.compression.splay"] = true; +dojo.provide("dojox.encoding.tests.compression.splay"); +dojo.require("dojox.encoding.compression.splay"); +dojo.require("dojox.encoding.bits"); + +(function(){ + var msg1 = "The rain in Spain falls mainly on the plain."; + var msg2 = "The rain in Spain falls mainly on the plain.1"; + var msg3 = "The rain in Spain falls mainly on the plain.ab"; + var msg4 = "The rain in Spain falls mainly on the plain.!@#"; + var dc = dojox.encoding.compression, dcb = dojox.encoding.bits; + + var s2b = function(s){ + var b = []; + for(var i = 0; i < s.length; ++i){ + b.push(s.charCodeAt(i)); + } + return b; + }; + + var b2s = function(b){ + var s = []; + dojo.forEach(b, function(c){ s.push(String.fromCharCode(c)); }); + return s.join(""); + }; + + var encode = function(msg){ + var x = new dcb.OutputStream(), encoder = new dc.Splay(256); + dojo.forEach(s2b(msg), function(v){ encoder.encode(v, x); }); + console.debug("bits =", x.getWidth()); + return x.getBuffer(); + }; + + var decode = function(n, buf){ + var x = new dcb.InputStream(buf, buf.length * 8), decoder = new dc.Splay(256), t = []; + for(var i = 0; i < n; ++i){ t.push(decoder.decode(x)); } + return b2s(t); + }; + + tests.register("dojox.encoding.tests.compression.splay", [ + function testSplayMsg1(t){ t.assertEqual(msg1, decode(msg1.length, encode(msg1))); }, + function testSplayMsg2(t){ t.assertEqual(msg2, decode(msg2.length, encode(msg2))); }, + function testSplayMsg3(t){ t.assertEqual(msg3, decode(msg3.length, encode(msg3))); }, + function testSplayMsg4(t){ t.assertEqual(msg4, decode(msg4.length, encode(msg4))); } + ]); +})(); + +} diff --git a/includes/js/dojox/encoding/tests/compression/test.html b/includes/js/dojox/encoding/tests/compression/test.html new file mode 100644 index 0000000..8f07c59 --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/test.html @@ -0,0 +1,61 @@ +<html> + <head> + <title>Test 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" src="colors2.js"></script> + <script type="text/javascript"> + dojo.require("dojox.encoding.tests.compression.colors"); + //dojo.require("dojox.encoding.tests.compression.colors2"); + dojo.require("dojox.encoding.tests.compression.colors3"); + var dct = dojox.encoding.tests.compression; + + var test = function(c1, c2, result){ + var empty = {}; + for(var i in c1){ + if(i in empty){ continue; } + if(!(i in c2)){ + result.push("<div>" + i + " is missing.</div>"); + continue; + } + var v1 = c1[i], v2 = c2[i]; + if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]){ + result.push("<div>" + i + " doesn't match.</div>"); + continue; + } + result.push("<div style='color: green'>" + i + " is ok.</div>"); + } + }; + + var run = function(){ + var result = []; + result.push("<p><strong>Comparing colors to colors3.</strong></p>"); + test(dct.colors, dct.colors3, result); + result.push("<p><strong>Comparing colors3 to colors.</strong></p>"); + test(dct.colors3, dct.colors, result); + /* + result.push("<p><strong>Comparing colors to colors2.</strong></p>"); + test(dct.colors, dct.colors2, result); + result.push("<p><strong>Comparing colors2 to colors.</strong></p>"); + test(dct.colors2, dct.colors, result); + */ + dojo.byId("status").innerHTML = result.join("\n"); + }; + + dojo.addOnLoad(function(){ + dojo.connect(dojo.byId("run"), "onclick", run); + }); + </script> + </head> + <body> + <h1>Test colors</h1> + <p><button id="run">Run</button></p> + <div id="status" class="pane"><em>No status yet.</em></div> + </body> +</html> diff --git a/includes/js/dojox/encoding/tests/compression/vq.html b/includes/js/dojox/encoding/tests/compression/vq.html new file mode 100644 index 0000000..7805bd4 --- /dev/null +++ b/includes/js/dojox/encoding/tests/compression/vq.html @@ -0,0 +1,185 @@ +<html> + <head> + <title>Compress colors using VQ</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.compression.splay"); + dojo.require("dojox.encoding.bits"); + + var colors = dojox.encoding.tests.compression.colors; + + var dist = function(a, b){ + var r = a[0] - b[0], g = a[1] - b[1], b = a[2] - b[2]; + return r * r + g * g + b * b; + }; + + var hexcolor = function(c){ + return "#" + (c[0] < 16 ? "0" : "") + c[0].toString(16) + + (c[1] < 16 ? "0" : "") + c[1].toString(16) + + (c[2] < 16 ? "0" : "") + c[2].toString(16); + }; + + var maxdist = function(a, b, maxdist){ + var r = Math.abs(a[0] - b[0]), g = Math.abs(a[1] - b[1]), b = Math.abs(a[2] - b[2]); + ++maxdist[bits(r)]; + ++maxdist[bits(g)]; + ++maxdist[bits(b)]; + }; + + var encodeColor = function(a, b, splay, stream){ + var r = a[0] - b[0], g = a[1] - b[1], b = a[2] - b[2]; + stream.putBits(r < 0 ? 1 : 0, 1); + splay.encode(Math.abs(r), stream); + stream.putBits(g < 0 ? 1 : 0, 1); + splay.encode(Math.abs(g), stream); + stream.putBits(b < 0 ? 1 : 0, 1); + splay.encode(Math.abs(b), stream); + }; + + var bits = function(x){ + var w = 1; + for(var v = 2; x >= v; v <<= 1, ++w); + return w; + }; + + var runVQ = function(n){ + dojo.byId("status").innerHTML = "<em>Initializing...</em>"; + dojo.byId("report").innerHTML = "<em>Running VQ...</em>"; + var clusters = []; + // select initial cluster centers + var empty = {}; + for(var i in colors){ + if(i in empty){ continue; } + clusters.push({center: colors[i]}); + if(clusters.length == n){ break; } + } + /* + for(var i = 0; i < n; ++i){ + var r = Math.floor(Math.random() * 256), g = Math.floor(Math.random() * 256), b = Math.floor(Math.random() * 256); + clusters.push({center: [r, g, b]}); + } + */ + // do runs + dojo.byId("status").innerHTML = "<div>Starting runs...</div>"; + var jitter = 0, niter = 1; + do { + // save previous centers + var old_clusters = []; + dojo.forEach(clusters, function(c){ old_clusters.push({center: c.center}); c.members = []; }); + // assign colors to clusters + for(var i in colors){ + if(i in empty){ continue; } + var c = colors[i], k = -1, kd = Number.MAX_VALUE; + for(var j = 0; j < clusters.length; ++j){ + var jd = dist(clusters[j].center, c); + if(jd < kd){ k = j, kd = jd; } + } + clusters[k].members.push(i); + } + // recalculate cluster centers + for(var i = 0; i < clusters.length; ++i){ + if(!clusters[i].members.length){ continue; } + var r = 0, g = 0, b = 0; + dojo.forEach(clusters[i].members, function(name){ + var c = colors[name]; + r += c[0]; + g += c[1]; + b += c[2]; + }); + r = Math.round(r / clusters[i].members.length); + g = Math.round(g / clusters[i].members.length); + b = Math.round(b / clusters[i].members.length); + clusters[i].center = [r, g, b]; + } + // calculate the jitter + jitter = 0; + for(var i = 0; i < clusters.length; ++i){ + jitter = Math.max(jitter, dist(clusters[i].center, old_clusters[i].center)); + } + var node = dojo.doc.createElement("div"); + node.innerHTML = "Run #" + niter + ", jitter = " + jitter; + dojo.byId("status").appendChild(node); + ++niter; + }while(jitter > 1 && niter < 1000); + // calculate the required number of bytes + var output = new dojox.encoding.bits.OutputStream(), + splay = new dojox.encoding.compression.Splay(256); + for(var i = 0; i < clusters.length; ++i){ + var c = clusters[i], m = c.members, d = 0, ol = output.getWidth(); + output.putBits(c.center[0], 8); + output.putBits(c.center[1], 8); + output.putBits(c.center[2], 8); + splay.reset(); + c.maxdist = [0, 0, 0, 0, 0, 0, 0, 0, 0]; + for(var j = 0; j < m.length; ++j){ + var color = colors[m[j]]; + maxdist(c.center, color, c.maxdist); + encodeColor(c.center, color, splay, output); + } + c.bits = output.getWidth() - ol; + } + var node = dojo.doc.createElement("div"); + node.innerHTML = "Required " + Math.ceil(output.getWidth() / 8) + " bytes"; + dojo.byId("status").appendChild(node); + // generate color tables + var reps = []; + for(var i = 0; i < clusters.length; ++i){ + var c = clusters[i], m = c.members; + reps.push("<p>Cluster #" + i + " contains " + m.length + " members. Length histogram:"); + for(var j = 0; j < c.maxdist.length; ++j){ + if(c.maxdist[j]){ + reps.push(" " + j + "—" + c.maxdist[j]); + } + } + reps.push(". It requires " + c.bits + " bits (" + Math.ceil(c.bits / 8) + " bytes) to be encoded.</p>"); + reps.push("<table>"); + var wd = dist([255,255,255], c.center), bd = dist([0,0,0], c.center); + reps.push("<tr><td style='background: " + hexcolor(c.center) + "; color: " + + (wd < bd ? "black" : "white") + "'><strong>CENTER</strong></td><td>" + + c.center[0] + "</td><td>" + c.center[1] + "</td><td>" + c.center[2] + "</td></tr>"); + for(var j = 0; j < m.length; ++j){ + var color = colors[m[j]]; + wd = dist([255,255,255], color); + bd = dist([0,0,0], color); + reps.push("<tr><td style='background: " + m[j] + "; color: " + + (wd < bd ? "black" : "white") + "'><strong>" + m[j] + "</strong></td><td>" + + color[0] + "</td><td>" + color[1] + "</td><td>" + color[2] + "</td></tr>"); + } + reps.push("</table>"); + } + dojo.byId("report").innerHTML = reps.join("\n"); + }; + + run = function(){ + var n = parseInt(dojo.byId("ncluster").value); + runVQ(n); + }; + + dojo.addOnLoad(function(){ + dojo.connect(dojo.byId("run"), "onclick", run); + }); + </script> + </head> + <body> + <h1>Compress colors using VQ</h1> + <p>Select desirable number of clusters: <select id="ncluster"> + <option value="1">1</option> + <option value="2">2</option> + <option value="4">4</option> + <option value="8">8</option> + <option value="16">16</option> + <option value="32">32</option> + <option value="64">64</option> + </select> <button id="run">Run</button></p> + <div id="status" class="pane"><em>No status yet.</em></div> + <div id="report" class="pane"><em>No results yet.</em></div> + </body> +</html> |