diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CMY3DHelper.h')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CMY3DHelper.h | 894 |
1 files changed, 447 insertions, 447 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CMY3DHelper.h b/libraries/irrlicht-1.8/source/Irrlicht/CMY3DHelper.h index e045444..4d05260 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CMY3DHelper.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/CMY3DHelper.h | |||
@@ -1,447 +1,447 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | // | 4 | // |
5 | // This file was originally written by ZDimitor. | 5 | // This file was originally written by ZDimitor. |
6 | 6 | ||
7 | //---------------------------------------------------------------------- | 7 | //---------------------------------------------------------------------- |
8 | // somefuncs.h - part of the My3D Tools | 8 | // somefuncs.h - part of the My3D Tools |
9 | // | 9 | // |
10 | // This tool was created by Zhuck Dmitry (ZDimitor). | 10 | // This tool was created by Zhuck Dmitry (ZDimitor). |
11 | // Everyone can use it as wants ( i'll be happy if it helps to someone :) ). | 11 | // Everyone can use it as wants ( i'll be happy if it helps to someone :) ). |
12 | //---------------------------------------------------------------------- | 12 | //---------------------------------------------------------------------- |
13 | 13 | ||
14 | //********************************************************************** | 14 | //********************************************************************** |
15 | // some useful functions | 15 | // some useful functions |
16 | //********************************************************************** | 16 | //********************************************************************** |
17 | 17 | ||
18 | #ifndef __C_MY3D_HELPER_H_INCLUDED__ | 18 | #ifndef __C_MY3D_HELPER_H_INCLUDED__ |
19 | #define __C_MY3D_HELPER_H_INCLUDED__ | 19 | #define __C_MY3D_HELPER_H_INCLUDED__ |
20 | 20 | ||
21 | #include <irrTypes.h> | 21 | #include <irrTypes.h> |
22 | 22 | ||
23 | namespace irr | 23 | namespace irr |
24 | { | 24 | { |
25 | namespace scene | 25 | namespace scene |
26 | { | 26 | { |
27 | 27 | ||
28 | //********************************************************************** | 28 | //********************************************************************** |
29 | // MY3D stuff | 29 | // MY3D stuff |
30 | //********************************************************************** | 30 | //********************************************************************** |
31 | 31 | ||
32 | // byte-align structures | 32 | // byte-align structures |
33 | #include "irrpack.h" | 33 | #include "irrpack.h" |
34 | 34 | ||
35 | struct SMyVector3 | 35 | struct SMyVector3 |
36 | { SMyVector3 () {;} | 36 | { SMyVector3 () {;} |
37 | SMyVector3 (f32 __X, f32 __Y, f32 __Z) | 37 | SMyVector3 (f32 __X, f32 __Y, f32 __Z) |
38 | : X(__X), Y(__Y), Z(__Z) {} | 38 | : X(__X), Y(__Y), Z(__Z) {} |
39 | f32 X, Y, Z; | 39 | f32 X, Y, Z; |
40 | } PACK_STRUCT; | 40 | } PACK_STRUCT; |
41 | 41 | ||
42 | struct SMyVector2 | 42 | struct SMyVector2 |
43 | { SMyVector2 () {;} | 43 | { SMyVector2 () {;} |
44 | SMyVector2(f32 __X, f32 __Y) | 44 | SMyVector2(f32 __X, f32 __Y) |
45 | : X(__X), Y(__Y) {} | 45 | : X(__X), Y(__Y) {} |
46 | f32 X, Y; | 46 | f32 X, Y; |
47 | } PACK_STRUCT; | 47 | } PACK_STRUCT; |
48 | 48 | ||
49 | struct SMyVertex | 49 | struct SMyVertex |
50 | { SMyVertex () {;} | 50 | { SMyVertex () {;} |
51 | SMyVertex (SMyVector3 _Coord, SMyColor _Color, SMyVector3 _Normal) | 51 | SMyVertex (SMyVector3 _Coord, SMyColor _Color, SMyVector3 _Normal) |
52 | :Coord(_Coord), Color(_Color), Normal(_Normal) {;} | 52 | :Coord(_Coord), Color(_Color), Normal(_Normal) {;} |
53 | SMyVector3 Coord; | 53 | SMyVector3 Coord; |
54 | SMyColor Color; | 54 | SMyColor Color; |
55 | SMyVector3 Normal; | 55 | SMyVector3 Normal; |
56 | } PACK_STRUCT; | 56 | } PACK_STRUCT; |
57 | 57 | ||
58 | struct SMyTVertex | 58 | struct SMyTVertex |
59 | { SMyTVertex () {;} | 59 | { SMyTVertex () {;} |
60 | SMyTVertex (SMyVector2 _TCoord) | 60 | SMyTVertex (SMyVector2 _TCoord) |
61 | : TCoord(_TCoord) {;} | 61 | : TCoord(_TCoord) {;} |
62 | SMyVector2 TCoord; | 62 | SMyVector2 TCoord; |
63 | } PACK_STRUCT; | 63 | } PACK_STRUCT; |
64 | 64 | ||
65 | struct SMyFace | 65 | struct SMyFace |
66 | { SMyFace() {;} | 66 | { SMyFace() {;} |
67 | SMyFace(u32 __A, u32 __B, u32 __C) | 67 | SMyFace(u32 __A, u32 __B, u32 __C) |
68 | : A(__A), B(__B), C(__C) {} | 68 | : A(__A), B(__B), C(__C) {} |
69 | u32 A, B, C; | 69 | u32 A, B, C; |
70 | } PACK_STRUCT; | 70 | } PACK_STRUCT; |
71 | 71 | ||
72 | // file header (6 bytes) | 72 | // file header (6 bytes) |
73 | struct SMyFileHeader | 73 | struct SMyFileHeader |
74 | { u32 MyId; // MY3D | 74 | { u32 MyId; // MY3D |
75 | u16 Ver; // Version | 75 | u16 Ver; // Version |
76 | } PACK_STRUCT; | 76 | } PACK_STRUCT; |
77 | 77 | ||
78 | // scene header | 78 | // scene header |
79 | struct SMySceneHeader | 79 | struct SMySceneHeader |
80 | { SMyColor BackgrColor; // background color | 80 | { SMyColor BackgrColor; // background color |
81 | SMyColor AmbientColor; // ambient color | 81 | SMyColor AmbientColor; // ambient color |
82 | s32 MaterialCount; // material count | 82 | s32 MaterialCount; // material count |
83 | s32 MeshCount; // mesh count | 83 | s32 MeshCount; // mesh count |
84 | } PACK_STRUCT; | 84 | } PACK_STRUCT; |
85 | 85 | ||
86 | // mesh header | 86 | // mesh header |
87 | struct SMyMeshHeader | 87 | struct SMyMeshHeader |
88 | { c8 Name[256]; // material name | 88 | { c8 Name[256]; // material name |
89 | u32 MatIndex; // index of the mesh material | 89 | u32 MatIndex; // index of the mesh material |
90 | u32 TChannelCnt; // mesh mapping channels count | 90 | u32 TChannelCnt; // mesh mapping channels count |
91 | } PACK_STRUCT; | 91 | } PACK_STRUCT; |
92 | 92 | ||
93 | // texture data header | 93 | // texture data header |
94 | struct SMyTexDataHeader | 94 | struct SMyTexDataHeader |
95 | { c8 Name[256]; // texture name | 95 | { c8 Name[256]; // texture name |
96 | u32 ComprMode; //compression mode | 96 | u32 ComprMode; //compression mode |
97 | u32 PixelFormat; | 97 | u32 PixelFormat; |
98 | u32 Width; // image width | 98 | u32 Width; // image width |
99 | u32 Height; // image height | 99 | u32 Height; // image height |
100 | } PACK_STRUCT; | 100 | } PACK_STRUCT; |
101 | 101 | ||
102 | // pixel color 24bit (R8G8B8) | 102 | // pixel color 24bit (R8G8B8) |
103 | struct SMyPixelColor24 | 103 | struct SMyPixelColor24 |
104 | { SMyPixelColor24() {;} | 104 | { SMyPixelColor24() {;} |
105 | SMyPixelColor24(u8 __r, u8 __g, u8 __b) | 105 | SMyPixelColor24(u8 __r, u8 __g, u8 __b) |
106 | : r(__r), g(__g), b(__b) {} | 106 | : r(__r), g(__g), b(__b) {} |
107 | u8 r, g, b; | 107 | u8 r, g, b; |
108 | } PACK_STRUCT; | 108 | } PACK_STRUCT; |
109 | 109 | ||
110 | // pixel color 16bit (A1R5G5B5) | 110 | // pixel color 16bit (A1R5G5B5) |
111 | struct SMyPixelColor16 | 111 | struct SMyPixelColor16 |
112 | { SMyPixelColor16() {;} | 112 | { SMyPixelColor16() {;} |
113 | SMyPixelColor16(s16 _argb): argb(_argb) {;} | 113 | SMyPixelColor16(s16 _argb): argb(_argb) {;} |
114 | SMyPixelColor16(u8 r, u8 g, u8 b) | 114 | SMyPixelColor16(u8 r, u8 g, u8 b) |
115 | { argb = ((r&0x1F)<<10) | ((g&0x1F)<<5) | (b&0x1F); | 115 | { argb = ((r&0x1F)<<10) | ((g&0x1F)<<5) | (b&0x1F); |
116 | } | 116 | } |
117 | s16 argb; | 117 | s16 argb; |
118 | } PACK_STRUCT; | 118 | } PACK_STRUCT; |
119 | 119 | ||
120 | // RLE Header | 120 | // RLE Header |
121 | struct SMyRLEHeader | 121 | struct SMyRLEHeader |
122 | { SMyRLEHeader() {} | 122 | { SMyRLEHeader() {} |
123 | u32 nEncodedBytes; | 123 | u32 nEncodedBytes; |
124 | u32 nDecodedBytes; | 124 | u32 nDecodedBytes; |
125 | } PACK_STRUCT; | 125 | } PACK_STRUCT; |
126 | 126 | ||
127 | // Default alignment | 127 | // Default alignment |
128 | #include "irrunpack.h" | 128 | #include "irrunpack.h" |
129 | 129 | ||
130 | } // end namespace | 130 | } // end namespace |
131 | } // end namespace | 131 | } // end namespace |
132 | 132 | ||
133 | //----------------------------------------------------------------------------- | 133 | //----------------------------------------------------------------------------- |
134 | namespace irr | 134 | namespace irr |
135 | { | 135 | { |
136 | namespace core | 136 | namespace core |
137 | { | 137 | { |
138 | 138 | ||
139 | //-----------------RLE stuff----------------------------------------- | 139 | //-----------------RLE stuff----------------------------------------- |
140 | 140 | ||
141 | int rle_encode ( | 141 | int rle_encode ( |
142 | unsigned char *in_buf, int in_buf_size, | 142 | unsigned char *in_buf, int in_buf_size, |
143 | unsigned char *out_buf, int out_buf_size | 143 | unsigned char *out_buf, int out_buf_size |
144 | ); | 144 | ); |
145 | unsigned long process_comp( | 145 | unsigned long process_comp( |
146 | unsigned char *buf, int buf_size, | 146 | unsigned char *buf, int buf_size, |
147 | unsigned char *out_buf, int out_buf_size | 147 | unsigned char *out_buf, int out_buf_size |
148 | ); | 148 | ); |
149 | void process_uncomp( | 149 | void process_uncomp( |
150 | unsigned char, unsigned char *out_buf, int out_buf_size | 150 | unsigned char, unsigned char *out_buf, int out_buf_size |
151 | ); | 151 | ); |
152 | void flush_outbuf( | 152 | void flush_outbuf( |
153 | unsigned char *out_buf, int out_buf_size | 153 | unsigned char *out_buf, int out_buf_size |
154 | ); | 154 | ); |
155 | unsigned long get_byte ( | 155 | unsigned long get_byte ( |
156 | unsigned char *ch, | 156 | unsigned char *ch, |
157 | unsigned char *in_buf, int in_buf_size, | 157 | unsigned char *in_buf, int in_buf_size, |
158 | unsigned char *out_buf, int out_buf_size | 158 | unsigned char *out_buf, int out_buf_size |
159 | ); | 159 | ); |
160 | void put_byte( | 160 | void put_byte( |
161 | unsigned char ch, unsigned char *out_buf, int out_buf_size | 161 | unsigned char ch, unsigned char *out_buf, int out_buf_size |
162 | ); | 162 | ); |
163 | //----------------------------------------------------------- | 163 | //----------------------------------------------------------- |
164 | const unsigned long LIMIT = 1; // was #define LIMIT 1 | 164 | const unsigned long LIMIT = 1; // was #define LIMIT 1 |
165 | const unsigned long NON_MATCH = 2; // was: #define NON_MATCH 2 | 165 | const unsigned long NON_MATCH = 2; // was: #define NON_MATCH 2 |
166 | const unsigned long EOD_FOUND = 3; // was: #define EOD_FOUND 3 | 166 | const unsigned long EOD_FOUND = 3; // was: #define EOD_FOUND 3 |
167 | const unsigned long EOD = 0x00454f44; // was: #define EOD 'EOD' | 167 | const unsigned long EOD = 0x00454f44; // was: #define EOD 'EOD' |
168 | //----------------------------------------------------------- | 168 | //----------------------------------------------------------- |
169 | // number of decoded bytes | 169 | // number of decoded bytes |
170 | static int nDecodedBytes=0; | 170 | static int nDecodedBytes=0; |
171 | // number of coded bytes | 171 | // number of coded bytes |
172 | static int nCodedBytes=0; | 172 | static int nCodedBytes=0; |
173 | // number of read bytes | 173 | // number of read bytes |
174 | static int nReadedBytes=0; | 174 | static int nReadedBytes=0; |
175 | // table used to look for sequences of repeating bytes | 175 | // table used to look for sequences of repeating bytes |
176 | static unsigned char tmpbuf[4]; // we use subscripts 1 - 3 | 176 | static unsigned char tmpbuf[4]; // we use subscripts 1 - 3 |
177 | static int tmpbuf_cnt; | 177 | static int tmpbuf_cnt; |
178 | // output buffer for non-compressed output data | 178 | // output buffer for non-compressed output data |
179 | static unsigned char outbuf[128]; | 179 | static unsigned char outbuf[128]; |
180 | static int outbuf_cnt; | 180 | static int outbuf_cnt; |
181 | 181 | ||
182 | 182 | ||
183 | //----------------------------------------------------------- | 183 | //----------------------------------------------------------- |
184 | int rle_encode ( | 184 | int rle_encode ( |
185 | unsigned char *in_buf, int in_buf_size, | 185 | unsigned char *in_buf, int in_buf_size, |
186 | unsigned char *out_buf, int out_buf_size | 186 | unsigned char *out_buf, int out_buf_size |
187 | ) | 187 | ) |
188 | { | 188 | { |
189 | unsigned long ret_code; | 189 | unsigned long ret_code; |
190 | 190 | ||
191 | unsigned char ch; | 191 | unsigned char ch; |
192 | 192 | ||
193 | nCodedBytes=0; | 193 | nCodedBytes=0; |
194 | nReadedBytes=0; | 194 | nReadedBytes=0; |
195 | 195 | ||
196 | tmpbuf_cnt = 0; // no. of char's in tmpbuf | 196 | tmpbuf_cnt = 0; // no. of char's in tmpbuf |
197 | outbuf_cnt = 0; // no. of char's in outbuf | 197 | outbuf_cnt = 0; // no. of char's in outbuf |
198 | while (1) | 198 | while (1) |
199 | { | 199 | { |
200 | if (get_byte(&ch, in_buf, in_buf_size, | 200 | if (get_byte(&ch, in_buf, in_buf_size, |
201 | out_buf, out_buf_size) == (int)EOD) // read next byte into ch | 201 | out_buf, out_buf_size) == (int)EOD) // read next byte into ch |
202 | break; | 202 | break; |
203 | 203 | ||
204 | tmpbuf[++tmpbuf_cnt] = (unsigned char) ch; | 204 | tmpbuf[++tmpbuf_cnt] = (unsigned char) ch; |
205 | if (tmpbuf_cnt == 3) | 205 | if (tmpbuf_cnt == 3) |
206 | { | 206 | { |
207 | // see if all 3 match each other | 207 | // see if all 3 match each other |
208 | if ((tmpbuf[1] == tmpbuf[2]) && (tmpbuf[2] == tmpbuf[3])) | 208 | if ((tmpbuf[1] == tmpbuf[2]) && (tmpbuf[2] == tmpbuf[3])) |
209 | { | 209 | { |
210 | // they do - add compression | 210 | // they do - add compression |
211 | // this will process all bytes in input file until | 211 | // this will process all bytes in input file until |
212 | // a non-match occurs, or 128 bytes are processed, | 212 | // a non-match occurs, or 128 bytes are processed, |
213 | // or we find eod */ | 213 | // or we find eod */ |
214 | ret_code = process_comp(in_buf, in_buf_size, out_buf, out_buf_size); | 214 | ret_code = process_comp(in_buf, in_buf_size, out_buf, out_buf_size); |
215 | if (ret_code == (int)EOD_FOUND) | 215 | if (ret_code == (int)EOD_FOUND) |
216 | break; // stop compressing | 216 | break; // stop compressing |
217 | if (ret_code == (int)NON_MATCH) | 217 | if (ret_code == (int)NON_MATCH) |
218 | tmpbuf_cnt=1; /* save the char that didn't match */ | 218 | tmpbuf_cnt=1; /* save the char that didn't match */ |
219 | else | 219 | else |
220 | // we just compressed the max. of 128 bytes | 220 | // we just compressed the max. of 128 bytes |
221 | tmpbuf_cnt=0; /* start over for next chunk */ | 221 | tmpbuf_cnt=0; /* start over for next chunk */ |
222 | } | 222 | } |
223 | else | 223 | else |
224 | { | 224 | { |
225 | // we know the first byte doesn't match 2 or more | 225 | // we know the first byte doesn't match 2 or more |
226 | // others, so just send it out as uncompressed. */ | 226 | // others, so just send it out as uncompressed. */ |
227 | process_uncomp(tmpbuf[1], out_buf, out_buf_size); | 227 | process_uncomp(tmpbuf[1], out_buf, out_buf_size); |
228 | 228 | ||
229 | // see if the last 2 bytes in the buffer match | 229 | // see if the last 2 bytes in the buffer match |
230 | if (tmpbuf[2] == tmpbuf[3]) | 230 | if (tmpbuf[2] == tmpbuf[3]) |
231 | { | 231 | { |
232 | // move byte 3 to position 1 and pretend we just | 232 | // move byte 3 to position 1 and pretend we just |
233 | // have 2 bytes -- note that the first byte was | 233 | // have 2 bytes -- note that the first byte was |
234 | // already sent to output */ | 234 | // already sent to output */ |
235 | tmpbuf[1]=tmpbuf[3]; | 235 | tmpbuf[1]=tmpbuf[3]; |
236 | tmpbuf_cnt=2; | 236 | tmpbuf_cnt=2; |
237 | } | 237 | } |
238 | else | 238 | else |
239 | { | 239 | { |
240 | // send byte 2 and keep byte 3 - it may match the | 240 | // send byte 2 and keep byte 3 - it may match the |
241 | // next byte. Move byte 3 to position 1 and set | 241 | // next byte. Move byte 3 to position 1 and set |
242 | // count to 1. Note that the first byte was | 242 | // count to 1. Note that the first byte was |
243 | // already sent to output | 243 | // already sent to output |
244 | process_uncomp(tmpbuf[2], out_buf, out_buf_size); | 244 | process_uncomp(tmpbuf[2], out_buf, out_buf_size); |
245 | tmpbuf[1]=tmpbuf[3]; | 245 | tmpbuf[1]=tmpbuf[3]; |
246 | tmpbuf_cnt=1; | 246 | tmpbuf_cnt=1; |
247 | } | 247 | } |
248 | } | 248 | } |
249 | } | 249 | } |
250 | } // end while | 250 | } // end while |
251 | flush_outbuf(out_buf, out_buf_size); | 251 | flush_outbuf(out_buf, out_buf_size); |
252 | 252 | ||
253 | return nCodedBytes; | 253 | return nCodedBytes; |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
257 | //------------------------------------------------------------------ | 257 | //------------------------------------------------------------------ |
258 | // This flushes any non-compressed data not yet sent, then it processes | 258 | // This flushes any non-compressed data not yet sent, then it processes |
259 | // repeating bytes until > 128, or EOD, or non-match. | 259 | // repeating bytes until > 128, or EOD, or non-match. |
260 | // return values: LIMIT, EOD_FOUND, NON_MATCH | 260 | // return values: LIMIT, EOD_FOUND, NON_MATCH |
261 | // Prior to ANY return, it writes out the 2 byte compressed code. | 261 | // Prior to ANY return, it writes out the 2 byte compressed code. |
262 | // If a NON_MATCH was found, this returns with the non-matching char | 262 | // If a NON_MATCH was found, this returns with the non-matching char |
263 | // residing in tmpbuf[0]. | 263 | // residing in tmpbuf[0]. |
264 | // Inputs: tmpbuf[0], input file | 264 | // Inputs: tmpbuf[0], input file |
265 | // Outputs: tmpbuf[0] (sometimes), output file, and return code | 265 | // Outputs: tmpbuf[0] (sometimes), output file, and return code |
266 | //------------------------------------------------------------------ | 266 | //------------------------------------------------------------------ |
267 | unsigned long process_comp( | 267 | unsigned long process_comp( |
268 | unsigned char *buf, int buf_size, | 268 | unsigned char *buf, int buf_size, |
269 | unsigned char *out_buf, int out_buf_size) | 269 | unsigned char *out_buf, int out_buf_size) |
270 | { | 270 | { |
271 | // we start out with 3 repeating bytes | 271 | // we start out with 3 repeating bytes |
272 | register int len = 3; | 272 | register int len = 3; |
273 | 273 | ||
274 | unsigned char ch; | 274 | unsigned char ch; |
275 | 275 | ||
276 | // we're starting a repeating chunk - end the non-repeaters | 276 | // we're starting a repeating chunk - end the non-repeaters |
277 | flush_outbuf(out_buf, out_buf_size); | 277 | flush_outbuf(out_buf, out_buf_size); |
278 | 278 | ||
279 | while (get_byte(&ch, buf, buf_size, out_buf, out_buf_size) != (int)EOD) | 279 | while (get_byte(&ch, buf, buf_size, out_buf, out_buf_size) != (int)EOD) |
280 | { | 280 | { |
281 | if (ch != tmpbuf[1]) | 281 | if (ch != tmpbuf[1]) |
282 | { | 282 | { |
283 | // send no. of repeated bytes to be encoded | 283 | // send no. of repeated bytes to be encoded |
284 | put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); | 284 | put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); |
285 | // send the byte's value being repeated | 285 | // send the byte's value being repeated |
286 | put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); | 286 | put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); |
287 | /* save the non-matching character just read */ | 287 | /* save the non-matching character just read */ |
288 | tmpbuf[1]=(unsigned char) ch; | 288 | tmpbuf[1]=(unsigned char) ch; |
289 | return NON_MATCH; | 289 | return NON_MATCH; |
290 | } | 290 | } |
291 | /* we know the new byte is part of the repeating seq */ | 291 | /* we know the new byte is part of the repeating seq */ |
292 | len++; | 292 | len++; |
293 | if (len == 128) | 293 | if (len == 128) |
294 | { | 294 | { |
295 | // send no. of repeated bytes to be encoded | 295 | // send no. of repeated bytes to be encoded |
296 | put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); | 296 | put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); |
297 | // send the byte's value being repeated | 297 | // send the byte's value being repeated |
298 | put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); | 298 | put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); |
299 | return LIMIT; | 299 | return LIMIT; |
300 | } | 300 | } |
301 | } // end while | 301 | } // end while |
302 | 302 | ||
303 | // if flow comes here, we just read an EOD | 303 | // if flow comes here, we just read an EOD |
304 | // send no. of repeated bytes to be encoded | 304 | // send no. of repeated bytes to be encoded |
305 | put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); | 305 | put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); |
306 | // send the byte's value being repeated | 306 | // send the byte's value being repeated |
307 | put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); | 307 | put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); |
308 | return EOD_FOUND; | 308 | return EOD_FOUND; |
309 | } | 309 | } |
310 | 310 | ||
311 | 311 | ||
312 | //---------------------------------------------------------------- | 312 | //---------------------------------------------------------------- |
313 | // This adds 1 non-repeating byte to outbuf. If outbuf becomes full | 313 | // This adds 1 non-repeating byte to outbuf. If outbuf becomes full |
314 | // with 128 bytes, it flushes outbuf. | 314 | // with 128 bytes, it flushes outbuf. |
315 | // There are no return codes and no bytes are read from the input. | 315 | // There are no return codes and no bytes are read from the input. |
316 | //---------------------------------------------------------------- | 316 | //---------------------------------------------------------------- |
317 | void process_uncomp( | 317 | void process_uncomp( |
318 | unsigned char char1, unsigned char *out_buf, int out_buf_size | 318 | unsigned char char1, unsigned char *out_buf, int out_buf_size |
319 | ) | 319 | ) |
320 | { | 320 | { |
321 | outbuf[outbuf_cnt++] = char1; | 321 | outbuf[outbuf_cnt++] = char1; |
322 | if (outbuf_cnt == 128) | 322 | if (outbuf_cnt == 128) |
323 | flush_outbuf(out_buf, out_buf_size); | 323 | flush_outbuf(out_buf, out_buf_size); |
324 | } | 324 | } |
325 | //----------------------------------------------------------- | 325 | //----------------------------------------------------------- |
326 | // This flushes any non-compressed data not yet sent. | 326 | // This flushes any non-compressed data not yet sent. |
327 | // On exit, outbuf_cnt will equal zero. | 327 | // On exit, outbuf_cnt will equal zero. |
328 | //----------------------------------------------------------- | 328 | //----------------------------------------------------------- |
329 | void flush_outbuf(unsigned char *out_buf, int out_buf_size) | 329 | void flush_outbuf(unsigned char *out_buf, int out_buf_size) |
330 | { | 330 | { |
331 | register int pos=0; | 331 | register int pos=0; |
332 | 332 | ||
333 | if(!outbuf_cnt) | 333 | if(!outbuf_cnt) |
334 | return; // nothing to do */ | 334 | return; // nothing to do */ |
335 | 335 | ||
336 | // send no. of unencoded bytes to be sent | 336 | // send no. of unencoded bytes to be sent |
337 | put_byte((unsigned char)(outbuf_cnt - 1), out_buf, out_buf_size); | 337 | put_byte((unsigned char)(outbuf_cnt - 1), out_buf, out_buf_size); |
338 | 338 | ||
339 | for ( ; outbuf_cnt; outbuf_cnt--) | 339 | for ( ; outbuf_cnt; outbuf_cnt--) |
340 | put_byte((unsigned char)outbuf[pos++], out_buf, out_buf_size); | 340 | put_byte((unsigned char)outbuf[pos++], out_buf, out_buf_size); |
341 | } | 341 | } |
342 | //--------------------------------------------------- | 342 | //--------------------------------------------------- |
343 | void put_byte(unsigned char ch, unsigned char *out_buf, int out_buf_size) | 343 | void put_byte(unsigned char ch, unsigned char *out_buf, int out_buf_size) |
344 | { | 344 | { |
345 | if (nCodedBytes<=(out_buf_size-1)) | 345 | if (nCodedBytes<=(out_buf_size-1)) |
346 | { out_buf[nCodedBytes++]=ch; | 346 | { out_buf[nCodedBytes++]=ch; |
347 | out_buf[nCodedBytes]=0; | 347 | out_buf[nCodedBytes]=0; |
348 | } | 348 | } |
349 | } | 349 | } |
350 | //--------------------------------------------------- | 350 | //--------------------------------------------------- |
351 | // This reads the next byte into ch. It returns EOD | 351 | // This reads the next byte into ch. It returns EOD |
352 | // at end-of-data | 352 | // at end-of-data |
353 | //--------------------------------------------------- | 353 | //--------------------------------------------------- |
354 | unsigned long get_byte( | 354 | unsigned long get_byte( |
355 | unsigned char *ch, | 355 | unsigned char *ch, |
356 | unsigned char *in_buf, int in_buf_size, | 356 | unsigned char *in_buf, int in_buf_size, |
357 | unsigned char *out_buf, int out_buf_size | 357 | unsigned char *out_buf, int out_buf_size |
358 | ) | 358 | ) |
359 | { | 359 | { |
360 | if (nReadedBytes>=in_buf_size) | 360 | if (nReadedBytes>=in_buf_size) |
361 | { | 361 | { |
362 | // there are either 0, 1, or 2 char's to write before we quit | 362 | // there are either 0, 1, or 2 char's to write before we quit |
363 | if (tmpbuf_cnt == 1) | 363 | if (tmpbuf_cnt == 1) |
364 | process_uncomp(tmpbuf[1], out_buf, out_buf_size); | 364 | process_uncomp(tmpbuf[1], out_buf, out_buf_size); |
365 | else | 365 | else |
366 | { | 366 | { |
367 | if (tmpbuf_cnt == 2) | 367 | if (tmpbuf_cnt == 2) |
368 | { | 368 | { |
369 | process_uncomp(tmpbuf[1], out_buf, out_buf_size); | 369 | process_uncomp(tmpbuf[1], out_buf, out_buf_size); |
370 | process_uncomp(tmpbuf[2], out_buf, out_buf_size); | 370 | process_uncomp(tmpbuf[2], out_buf, out_buf_size); |
371 | } | 371 | } |
372 | } | 372 | } |
373 | nReadedBytes =0; | 373 | nReadedBytes =0; |
374 | 374 | ||
375 | return EOD; | 375 | return EOD; |
376 | } | 376 | } |
377 | 377 | ||
378 | (*ch) = (unsigned char)in_buf[nReadedBytes++]; | 378 | (*ch) = (unsigned char)in_buf[nReadedBytes++]; |
379 | 379 | ||
380 | return 0; | 380 | return 0; |
381 | } | 381 | } |
382 | //----------------------------------------------------------- | 382 | //----------------------------------------------------------- |
383 | int rle_decode ( | 383 | int rle_decode ( |
384 | unsigned char *in_buf, int in_buf_size, | 384 | unsigned char *in_buf, int in_buf_size, |
385 | unsigned char *out_buf, int out_buf_size | 385 | unsigned char *out_buf, int out_buf_size |
386 | ) | 386 | ) |
387 | { | 387 | { |
388 | nDecodedBytes=0; | 388 | nDecodedBytes=0; |
389 | nReadedBytes=0; | 389 | nReadedBytes=0; |
390 | 390 | ||
391 | int ch, i; | 391 | int ch, i; |
392 | while (1) | 392 | while (1) |
393 | { | 393 | { |
394 | 394 | ||
395 | if (nReadedBytes>=in_buf_size) | 395 | if (nReadedBytes>=in_buf_size) |
396 | break; | 396 | break; |
397 | else | 397 | else |
398 | ch=in_buf[nReadedBytes]; | 398 | ch=in_buf[nReadedBytes]; |
399 | nReadedBytes++; | 399 | nReadedBytes++; |
400 | 400 | ||
401 | if (ch > 127) | 401 | if (ch > 127) |
402 | { | 402 | { |
403 | i = ch - 127; // i is the number of repetitions | 403 | i = ch - 127; // i is the number of repetitions |
404 | // get the byte to be repeated | 404 | // get the byte to be repeated |
405 | if (nReadedBytes>=in_buf_size) | 405 | if (nReadedBytes>=in_buf_size) |
406 | break; | 406 | break; |
407 | else | 407 | else |
408 | ch=in_buf[nReadedBytes]; | 408 | ch=in_buf[nReadedBytes]; |
409 | nReadedBytes++; | 409 | nReadedBytes++; |
410 | 410 | ||
411 | // uncompress a chunk | 411 | // uncompress a chunk |
412 | for ( ; i ; i--) | 412 | for ( ; i ; i--) |
413 | { | 413 | { |
414 | if (nDecodedBytes<out_buf_size) | 414 | if (nDecodedBytes<out_buf_size) |
415 | out_buf[nDecodedBytes] = ch; | 415 | out_buf[nDecodedBytes] = ch; |
416 | nDecodedBytes++; | 416 | nDecodedBytes++; |
417 | } | 417 | } |
418 | } | 418 | } |
419 | else | 419 | else |
420 | { | 420 | { |
421 | // copy out some uncompressed bytes | 421 | // copy out some uncompressed bytes |
422 | i = ch + 1; // i is the no. of bytes | 422 | i = ch + 1; // i is the no. of bytes |
423 | // uncompress a chunk | 423 | // uncompress a chunk |
424 | for ( ; i ; i--) | 424 | for ( ; i ; i--) |
425 | { | 425 | { |
426 | if (nReadedBytes>=in_buf_size) | 426 | if (nReadedBytes>=in_buf_size) |
427 | break; | 427 | break; |
428 | else | 428 | else |
429 | ch=in_buf[nReadedBytes]; | 429 | ch=in_buf[nReadedBytes]; |
430 | nReadedBytes++; | 430 | nReadedBytes++; |
431 | 431 | ||
432 | if (nDecodedBytes<out_buf_size) | 432 | if (nDecodedBytes<out_buf_size) |
433 | out_buf[nDecodedBytes] = ch; | 433 | out_buf[nDecodedBytes] = ch; |
434 | nDecodedBytes++; | 434 | nDecodedBytes++; |
435 | } | 435 | } |
436 | } | 436 | } |
437 | } // end while | 437 | } // end while |
438 | 438 | ||
439 | return nDecodedBytes; | 439 | return nDecodedBytes; |
440 | } | 440 | } |
441 | 441 | ||
442 | } //end namespace core | 442 | } //end namespace core |
443 | } //end namespace irr | 443 | } //end namespace irr |
444 | 444 | ||
445 | 445 | ||
446 | #endif // __C_MY3D_HELPER_H_INCLUDED__ | 446 | #endif // __C_MY3D_HELPER_H_INCLUDED__ |
447 | 447 | ||