diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/OpenJpeg/bio.cs | 300 |
1 files changed, 162 insertions, 138 deletions
diff --git a/OpenSim/Framework/OpenJpeg/bio.cs b/OpenSim/Framework/OpenJpeg/bio.cs index 4f095ad..4a5b321 100644 --- a/OpenSim/Framework/OpenJpeg/bio.cs +++ b/OpenSim/Framework/OpenJpeg/bio.cs | |||
@@ -1,138 +1,162 @@ | |||
1 | using System; | 1 | /* |
2 | using System.Collections.Generic; | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | using System.Text; | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | 4 | * | |
5 | namespace OpenSim.Framework.OpenJpeg | 5 | * Redistribution and use in source and binary forms, with or without |
6 | { | 6 | * modification, are permitted provided that the following conditions are met: |
7 | public static class bio | 7 | * * Redistributions of source code must retain the above copyright |
8 | { | 8 | * notice, this list of conditions and the following disclaimer. |
9 | 9 | * * Redistributions in binary form must reproduce the above copyright | |
10 | public static opj_bio bio_create() | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | { | 11 | * documentation and/or other materials provided with the distribution. |
12 | opj_bio bio = new opj_bio(); | 12 | * * Neither the name of the OpenSimulator Project nor the |
13 | return bio; | 13 | * names of its contributors may be used to endorse or promote products |
14 | } | 14 | * derived from this software without specific prior written permission. |
15 | 15 | * | |
16 | public static void bio_destroy(opj_bio bio) | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | { | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | // not needed on C# | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | } | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | public static int bio_numbytes(opj_bio bio) | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | { | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | return (bio.bp - bio.start); | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | } | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | public static void bio_init_enc(opj_bio bio, sbyte bp, int len) | 26 | */ |
27 | { | 27 | |
28 | bio.start = (byte)bp; | 28 | using System; |
29 | bio.end = (byte)(bp + (byte)len); | 29 | using System.Collections.Generic; |
30 | bio.bp = (byte)bp; | 30 | using System.Text; |
31 | bio.buf = 0; | 31 | |
32 | bio.ct = 8; | 32 | namespace OpenSim.Framework.OpenJpeg |
33 | } | 33 | { |
34 | 34 | public static class bio | |
35 | public static void bio_init_dec(opj_bio bio, sbyte bp, int len) | 35 | { |
36 | { | 36 | public static opj_bio bio_create() |
37 | bio.start = (byte)bp; | 37 | { |
38 | bio.end = (byte)(bp + len); | 38 | opj_bio bio = new opj_bio(); |
39 | bio.bp = (byte)bp; | 39 | return bio; |
40 | bio.buf = 0; | 40 | } |
41 | bio.ct = 0; | 41 | |
42 | } | 42 | public static void bio_destroy(opj_bio bio) |
43 | 43 | { | |
44 | public static void bio_write(opj_bio bio, int v, int n) | 44 | // not needed on C# |
45 | { | 45 | } |
46 | for (int i = n - 1; i >= 0; i--) | 46 | |
47 | bio_putbit(bio, (v >> i) & 1); | 47 | public static int bio_numbytes(opj_bio bio) |
48 | } | 48 | { |
49 | 49 | return (bio.bp - bio.start); | |
50 | public static int bio_read(opj_bio bio, int n) | 50 | } |
51 | { | 51 | |
52 | int v = 0; | 52 | public static void bio_init_enc(opj_bio bio, sbyte bp, int len) |
53 | for (int i = n - 1; i >= 0; i--) | 53 | { |
54 | v += bio_getbit(bio) << i; | 54 | bio.start = (byte)bp; |
55 | 55 | bio.end = (byte)(bp + (byte)len); | |
56 | return v; | 56 | bio.bp = (byte)bp; |
57 | } | 57 | bio.buf = 0; |
58 | 58 | bio.ct = 8; | |
59 | public static int bio_flush(opj_bio bio) | 59 | } |
60 | { | 60 | |
61 | bio.ct = 0; | 61 | public static void bio_init_dec(opj_bio bio, sbyte bp, int len) |
62 | if (bio_byteout(bio) != 0) | 62 | { |
63 | return 1; | 63 | bio.start = (byte)bp; |
64 | 64 | bio.end = (byte)(bp + len); | |
65 | if (bio.ct == 7) | 65 | bio.bp = (byte)bp; |
66 | { | 66 | bio.buf = 0; |
67 | bio.ct = 0; | 67 | bio.ct = 0; |
68 | if (bio_byteout(bio) != 0) | 68 | } |
69 | return 1; | 69 | |
70 | } | 70 | public static void bio_write(opj_bio bio, int v, int n) |
71 | return 0; | 71 | { |
72 | } | 72 | for (int i = n - 1; i >= 0; i--) |
73 | 73 | bio_putbit(bio, (v >> i) & 1); | |
74 | public static int bio_inalign(opj_bio bio) | 74 | } |
75 | { | 75 | |
76 | bio.ct = 0; | 76 | public static int bio_read(opj_bio bio, int n) |
77 | if ((bio.buf & 0xff) == 0xff) | 77 | { |
78 | { | 78 | int v = 0; |
79 | if (bio_bytein(bio) != 0) | 79 | for (int i = n - 1; i >= 0; i--) |
80 | return 1; | 80 | v += bio_getbit(bio) << i; |
81 | bio.ct = 0; | 81 | |
82 | } | 82 | return v; |
83 | return 0; | 83 | } |
84 | } | 84 | |
85 | 85 | public static int bio_flush(opj_bio bio) | |
86 | private static int bio_bytein(opj_bio bio) | 86 | { |
87 | { | 87 | bio.ct = 0; |
88 | bio.buf = (bio.buf << 8) & 0xffff; | 88 | if (bio_byteout(bio) != 0) |
89 | bio.ct = bio.buf == 0xff00 ? 7 : 8; | 89 | return 1; |
90 | if (bio.bp >= bio.end) | 90 | |
91 | return 1; | 91 | if (bio.ct == 7) |
92 | bio.buf |= bio.bp++; | 92 | { |
93 | 93 | bio.ct = 0; | |
94 | return 0; | 94 | if (bio_byteout(bio) != 0) |
95 | } | 95 | return 1; |
96 | 96 | } | |
97 | private static int bio_byteout(opj_bio bio) | 97 | return 0; |
98 | { | 98 | } |
99 | bio.buf = (bio.buf << 8) & 0xffff; | 99 | |
100 | bio.ct = bio.buf == 0xff00 ? 7 : 8; | 100 | public static int bio_inalign(opj_bio bio) |
101 | if (bio.bp >= bio.end) | 101 | { |
102 | return 1; | 102 | bio.ct = 0; |
103 | 103 | if ((bio.buf & 0xff) == 0xff) | |
104 | bio.bp = (byte)(bio.buf >> 8); | 104 | { |
105 | bio.bp++; | 105 | if (bio_bytein(bio) != 0) |
106 | return 0; | 106 | return 1; |
107 | } | 107 | bio.ct = 0; |
108 | 108 | } | |
109 | private static void bio_putbit(opj_bio bio, int b) | 109 | return 0; |
110 | { | 110 | } |
111 | if (bio.ct == 0) | 111 | |
112 | bio_byteout(bio); | 112 | private static int bio_bytein(opj_bio bio) |
113 | 113 | { | |
114 | bio.ct--; | 114 | bio.buf = (bio.buf << 8) & 0xffff; |
115 | bio.buf |= (byte)(b << bio.ct); | 115 | bio.ct = bio.buf == 0xff00 ? 7 : 8; |
116 | 116 | if (bio.bp >= bio.end) | |
117 | } | 117 | return 1; |
118 | 118 | bio.buf |= bio.bp++; | |
119 | private static int bio_getbit(opj_bio bio) | 119 | |
120 | { | 120 | return 0; |
121 | if (bio.ct == 0) | 121 | } |
122 | bio_bytein(bio); | 122 | |
123 | bio.ct--; | 123 | private static int bio_byteout(opj_bio bio) |
124 | 124 | { | |
125 | return (int)((bio.buf >> bio.ct) & 1); | 125 | bio.buf = (bio.buf << 8) & 0xffff; |
126 | } | 126 | bio.ct = bio.buf == 0xff00 ? 7 : 8; |
127 | 127 | if (bio.bp >= bio.end) | |
128 | } | 128 | return 1; |
129 | 129 | ||
130 | public struct opj_bio | 130 | bio.bp = (byte)(bio.buf >> 8); |
131 | { | 131 | bio.bp++; |
132 | public byte start; | 132 | return 0; |
133 | public byte end; | 133 | } |
134 | public byte bp; | 134 | |
135 | public uint buf; | 135 | private static void bio_putbit(opj_bio bio, int b) |
136 | public int ct; | 136 | { |
137 | } | 137 | if (bio.ct == 0) |
138 | } | 138 | bio_byteout(bio); |
139 | |||
140 | bio.ct--; | ||
141 | bio.buf |= (byte)(b << bio.ct); | ||
142 | } | ||
143 | |||
144 | private static int bio_getbit(opj_bio bio) | ||
145 | { | ||
146 | if (bio.ct == 0) | ||
147 | bio_bytein(bio); | ||
148 | bio.ct--; | ||
149 | |||
150 | return (int)((bio.buf >> bio.ct) & 1); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | public struct opj_bio | ||
155 | { | ||
156 | public byte start; | ||
157 | public byte end; | ||
158 | public byte bp; | ||
159 | public uint buf; | ||
160 | public int ct; | ||
161 | } | ||
162 | } | ||