* added remote_insert_description (for adding linkback in html inserts of media)
[lhc/web/wiklou.git] / js2 / mwEmbed / binPlayers / omtk-fx / src / as / org / omtk / util / BitByteArray.as
1 /*
2
3 Copyright 2008 Tor-Einar Jarnbjo
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 */
18
19 package org.omtk.util {
20
21 import flash.utils.ByteArray;
22 import flash.utils.Endian;
23 import flash.errors.IllegalOperationError;
24
25 public class BitByteArray extends ByteArray {
26
27 private var currentByte:uint;
28 private var bitIndex:int = 8;
29
30 public function BitByteArray() {
31 this.endian = Endian.LITTLE_ENDIAN;
32 }
33
34 public function readBit():Boolean {
35 if (bitIndex > 7) {
36 bitIndex = 0;
37 currentByte = readUnsignedByte();
38 }
39 return (currentByte & (1 << (bitIndex++))) != 0;
40 }
41
42 public function readUnsignedBitwiseInt(bits:int):uint {
43
44 var res:uint = 0;
45
46 for (var i : int = 0; i < bits; i++) {
47 if (bitIndex > 7) {
48 bitIndex = 0;
49 currentByte = readUnsignedByte();
50 }
51 if((currentByte & (1 << (bitIndex++))) != 0) {
52 res |= (1 << i);
53 }
54 }
55
56 return res;
57 }
58
59 public function readUnsignedHuffmanInt(root:HuffmanNode):uint {
60
61 while (!root.hasValue) {
62 if (bitIndex > 7) {
63 bitIndex = 0;
64 currentByte = readUnsignedByte();
65 }
66 root = (currentByte & (1 << (bitIndex++))) != 0 ? root._o1 : root._o0;
67 }
68
69 return root._value;
70 }
71
72 }
73
74
75 }