Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / encoding / bits.js @ 12

History | View | Annotate | Download (1.43 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.encoding.bits"]){
9
dojo._hasResource["dojox.encoding.bits"]=true;
10
dojo.provide("dojox.encoding.bits");
11
dojox.encoding.bits.OutputStream=function(){
12
this.reset();
13
};
14
dojo.extend(dojox.encoding.bits.OutputStream,{reset:function(){
15
this.buffer=[];
16
this.accumulator=0;
17
this.available=8;
18
},putBits:function(_1,_2){
19
while(_2){
20
var w=Math.min(_2,this.available);
21
var v=(w<=_2?_1>>>(_2-w):_1)<<(this.available-w);
22
this.accumulator|=v&(255>>>(8-this.available));
23
this.available-=w;
24
if(!this.available){
25
this.buffer.push(this.accumulator);
26
this.accumulator=0;
27
this.available=8;
28
}
29
_2-=w;
30
}
31
},getWidth:function(){
32
return this.buffer.length*8+(8-this.available);
33
},getBuffer:function(){
34
var b=this.buffer;
35
if(this.available<8){
36
b.push(this.accumulator&(255<<this.available));
37
}
38
this.reset();
39
return b;
40
}});
41
dojox.encoding.bits.InputStream=function(_3,_4){
42
this.buffer=_3;
43
this.width=_4;
44
this.bbyte=this.bit=0;
45
};
46
dojo.extend(dojox.encoding.bits.InputStream,{getBits:function(_5){
47
var r=0;
48
while(_5){
49
var w=Math.min(_5,8-this.bit);
50
var v=this.buffer[this.bbyte]>>>(8-this.bit-w);
51
r<<=w;
52
r|=v&~(~0<<w);
53
this.bit+=w;
54
if(this.bit==8){
55
++this.bbyte;
56
this.bit=0;
57
}
58
_5-=w;
59
}
60
return r;
61
},getWidth:function(){
62
return this.width-this.bbyte*8-this.bit;
63
}});
64
}