Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.encoding.bits"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.encoding.bits"] = true;
3
dojo.provide("dojox.encoding.bits");
4
 
5
dojox.encoding.bits.OutputStream = function(){
6
	this.reset();
7
};
8
 
9
dojo.extend(dojox.encoding.bits.OutputStream, {
10
	reset: function(){
11
		this.buffer = [];
12
		this.accumulator = 0;
13
		this.available = 8;
14
	},
15
	putBits: function(value, width){
16
		while(width){
17
			var w = Math.min(width, this.available);
18
			var v = (w <= width ? value >>> (width - w) : value) << (this.available - w);
19
			this.accumulator |= v & (255 >>> (8 - this.available));
20
			this.available -= w;
21
			if(!this.available){
22
				this.buffer.push(this.accumulator);
23
				this.accumulator = 0;
24
				this.available = 8;
25
			}
26
			width -= w;
27
		}
28
	},
29
	getWidth: function(){
30
		return this.buffer.length * 8 + (8 - this.available);
31
	},
32
	getBuffer: function(){
33
		var b = this.buffer;
34
		if(this.available < 8){ b.push(this.accumulator & (255 << this.available)); }
35
		this.reset();
36
		return b;
37
	}
38
});
39
 
40
dojox.encoding.bits.InputStream = function(buffer, width){
41
	this.buffer = buffer;
42
	this.width = width;
43
	this.bbyte = this.bit = 0;
44
};
45
 
46
dojo.extend(dojox.encoding.bits.InputStream, {
47
	getBits: function(width){
48
		var r = 0;
49
		while(width){
50
			var w = Math.min(width, 8 - this.bit);
51
			var v = this.buffer[this.bbyte] >>> (8 - this.bit - w);
52
			r <<= w;
53
			r |= v & ~(~0 << w);
54
			this.bit += w;
55
			if(this.bit == 8){
56
				++this.bbyte;
57
				this.bit = 0;
58
			}
59
			width -= w;
60
		}
61
		return r;
62
	},
63
	getWidth: function(){
64
		return this.width - this.bbyte * 8 - this.bit;
65
	}
66
});
67
 
68
}