1 if(!dojo._hasResource["dojox.encoding.compression.lzw"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.encoding.compression.lzw"] = true;
3 dojo.provide("dojox.encoding.compression.lzw");
4 dojo.require("dojox.encoding.bits");
7 var _bits = function(x){
9 for(var v = 2; x >= v; v <<= 1, ++w);
13 dojox.encoding.compression.lzw.Encoder = function(n){
18 dojo.extend(dojox.encoding.compression.lzw.Encoder, {
21 for(var i = 0; i < this.size; ++i){
22 this.dict[String.fromCharCode(i)] = i;
24 this.width = _bits(this.code = this.size);
27 encode: function(value, stream){
28 var c = String.fromCharCode(value), p = this.p + c, r = 0;
29 // if already in the dictionary
34 stream.putBits(this.dict[this.p], this.width);
35 // if we need to increase the code length
36 if((this.code & (this.code + 1)) == 0){
37 stream.putBits(this.code++, r = this.width++);
40 this.dict[p] = this.code++;
42 return r + this.width;
44 flush: function(stream){
45 if(this.p.length == 0){
48 stream.putBits(this.dict[this.p], this.width);
54 dojox.encoding.compression.lzw.Decoder = function(n){
59 dojo.extend(dojox.encoding.compression.lzw.Decoder, {
61 this.codes = new Array(this.size);
62 for(var i = 0; i < this.size; ++i){
63 this.codes[i] = String.fromCharCode(i);
65 this.width = _bits(this.size);
68 decode: function(stream){
69 var c = stream.getBits(this.width), v;
70 if(c < this.codes.length){
73 this.codes.push(this.codes[this.p] + v.substr(0, 1));
76 if((c & (c + 1)) == 0){
81 var x = this.codes[this.p];
82 v = x + x.substr(0, 1);