aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/OpenJpeg/bio.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-12-20 01:20:40 +0000
committerTeravus Ovares2008-12-20 01:20:40 +0000
commit4d26da545d8df85917b06cd603ffa6e92fd431e5 (patch)
treedec31f79c4a3d0736fd798442e090de7b951008f /OpenSim/Framework/OpenJpeg/bio.cs
parentRevert OpenId until we can come to grips with the mono 2 requirement (diff)
downloadopensim-SC_OLD-4d26da545d8df85917b06cd603ffa6e92fd431e5.zip
opensim-SC_OLD-4d26da545d8df85917b06cd603ffa6e92fd431e5.tar.gz
opensim-SC_OLD-4d26da545d8df85917b06cd603ffa6e92fd431e5.tar.bz2
opensim-SC_OLD-4d26da545d8df85917b06cd603ffa6e92fd431e5.tar.xz
* ReCommit the OpenID patch with a few less dependencies.
* Removes all references to ASP.NET (System.Web.UI,*) * Removes all references to System.Web.Mobile
Diffstat (limited to 'OpenSim/Framework/OpenJpeg/bio.cs')
-rw-r--r--OpenSim/Framework/OpenJpeg/bio.cs138
1 files changed, 138 insertions, 0 deletions
diff --git a/OpenSim/Framework/OpenJpeg/bio.cs b/OpenSim/Framework/OpenJpeg/bio.cs
new file mode 100644
index 0000000..4f095ad
--- /dev/null
+++ b/OpenSim/Framework/OpenJpeg/bio.cs
@@ -0,0 +1,138 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.OpenJpeg
6{
7 public static class bio
8 {
9
10 public static opj_bio bio_create()
11 {
12 opj_bio bio = new opj_bio();
13 return bio;
14 }
15
16 public static void bio_destroy(opj_bio bio)
17 {
18 // not needed on C#
19 }
20
21 public static int bio_numbytes(opj_bio bio)
22 {
23 return (bio.bp - bio.start);
24 }
25
26 public static void bio_init_enc(opj_bio bio, sbyte bp, int len)
27 {
28 bio.start = (byte)bp;
29 bio.end = (byte)(bp + (byte)len);
30 bio.bp = (byte)bp;
31 bio.buf = 0;
32 bio.ct = 8;
33 }
34
35 public static void bio_init_dec(opj_bio bio, sbyte bp, int len)
36 {
37 bio.start = (byte)bp;
38 bio.end = (byte)(bp + len);
39 bio.bp = (byte)bp;
40 bio.buf = 0;
41 bio.ct = 0;
42 }
43
44 public static void bio_write(opj_bio bio, int v, int n)
45 {
46 for (int i = n - 1; i >= 0; i--)
47 bio_putbit(bio, (v >> i) & 1);
48 }
49
50 public static int bio_read(opj_bio bio, int n)
51 {
52 int v = 0;
53 for (int i = n - 1; i >= 0; i--)
54 v += bio_getbit(bio) << i;
55
56 return v;
57 }
58
59 public static int bio_flush(opj_bio bio)
60 {
61 bio.ct = 0;
62 if (bio_byteout(bio) != 0)
63 return 1;
64
65 if (bio.ct == 7)
66 {
67 bio.ct = 0;
68 if (bio_byteout(bio) != 0)
69 return 1;
70 }
71 return 0;
72 }
73
74 public static int bio_inalign(opj_bio bio)
75 {
76 bio.ct = 0;
77 if ((bio.buf & 0xff) == 0xff)
78 {
79 if (bio_bytein(bio) != 0)
80 return 1;
81 bio.ct = 0;
82 }
83 return 0;
84 }
85
86 private static int bio_bytein(opj_bio bio)
87 {
88 bio.buf = (bio.buf << 8) & 0xffff;
89 bio.ct = bio.buf == 0xff00 ? 7 : 8;
90 if (bio.bp >= bio.end)
91 return 1;
92 bio.buf |= bio.bp++;
93
94 return 0;
95 }
96
97 private static int bio_byteout(opj_bio bio)
98 {
99 bio.buf = (bio.buf << 8) & 0xffff;
100 bio.ct = bio.buf == 0xff00 ? 7 : 8;
101 if (bio.bp >= bio.end)
102 return 1;
103
104 bio.bp = (byte)(bio.buf >> 8);
105 bio.bp++;
106 return 0;
107 }
108
109 private static void bio_putbit(opj_bio bio, int b)
110 {
111 if (bio.ct == 0)
112 bio_byteout(bio);
113
114 bio.ct--;
115 bio.buf |= (byte)(b << bio.ct);
116
117 }
118
119 private static int bio_getbit(opj_bio bio)
120 {
121 if (bio.ct == 0)
122 bio_bytein(bio);
123 bio.ct--;
124
125 return (int)((bio.buf >> bio.ct) & 1);
126 }
127
128 }
129
130 public struct opj_bio
131 {
132 public byte start;
133 public byte end;
134 public byte bp;
135 public uint buf;
136 public int ct;
137 }
138}