aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CColorConverter.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CColorConverter.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CColorConverter.cpp1410
1 files changed, 705 insertions, 705 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CColorConverter.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CColorConverter.cpp
index abc2c33..e9aad7a 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CColorConverter.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CColorConverter.cpp
@@ -1,705 +1,705 @@
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#include "CColorConverter.h" 5#include "CColorConverter.h"
6#include "SColor.h" 6#include "SColor.h"
7#include "os.h" 7#include "os.h"
8#include "irrString.h" 8#include "irrString.h"
9 9
10namespace irr 10namespace irr
11{ 11{
12namespace video 12namespace video
13{ 13{
14 14
15//! converts a monochrome bitmap to A1R5G5B5 data 15//! converts a monochrome bitmap to A1R5G5B5 data
16void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, s32 linepad, bool flip) 16void CColorConverter::convert1BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, s32 linepad, bool flip)
17{ 17{
18 if (!in || !out) 18 if (!in || !out)
19 return; 19 return;
20 20
21 if (flip) 21 if (flip)
22 out += width * height; 22 out += width * height;
23 23
24 for (s32 y=0; y<height; ++y) 24 for (s32 y=0; y<height; ++y)
25 { 25 {
26 s32 shift = 7; 26 s32 shift = 7;
27 if (flip) 27 if (flip)
28 out -= width; 28 out -= width;
29 29
30 for (s32 x=0; x<width; ++x) 30 for (s32 x=0; x<width; ++x)
31 { 31 {
32 out[x] = *in>>shift & 0x01 ? (s16)0xffff : (s16)0x8000; 32 out[x] = *in>>shift & 0x01 ? (s16)0xffff : (s16)0x8000;
33 33
34 if ((--shift)<0) // 8 pixel done 34 if ((--shift)<0) // 8 pixel done
35 { 35 {
36 shift=7; 36 shift=7;
37 ++in; 37 ++in;
38 } 38 }
39 } 39 }
40 40
41 if (shift != 7) // width did not fill last byte 41 if (shift != 7) // width did not fill last byte
42 ++in; 42 ++in;
43 43
44 if (!flip) 44 if (!flip)
45 out += width; 45 out += width;
46 in += linepad; 46 in += linepad;
47 } 47 }
48} 48}
49 49
50 50
51 51
52//! converts a 4 bit palettized image to A1R5G5B5 52//! converts a 4 bit palettized image to A1R5G5B5
53void CColorConverter::convert4BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad, bool flip) 53void CColorConverter::convert4BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad, bool flip)
54{ 54{
55 if (!in || !out || !palette) 55 if (!in || !out || !palette)
56 return; 56 return;
57 57
58 if (flip) 58 if (flip)
59 out += width*height; 59 out += width*height;
60 60
61 for (s32 y=0; y<height; ++y) 61 for (s32 y=0; y<height; ++y)
62 { 62 {
63 s32 shift = 4; 63 s32 shift = 4;
64 if (flip) 64 if (flip)
65 out -= width; 65 out -= width;
66 66
67 for (s32 x=0; x<width; ++x) 67 for (s32 x=0; x<width; ++x)
68 { 68 {
69 out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)((*in >> shift) & 0xf)]); 69 out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)((*in >> shift) & 0xf)]);
70 70
71 if (shift==0) 71 if (shift==0)
72 { 72 {
73 shift = 4; 73 shift = 4;
74 ++in; 74 ++in;
75 } 75 }
76 else 76 else
77 shift = 0; 77 shift = 0;
78 } 78 }
79 79
80 if (shift == 0) // odd width 80 if (shift == 0) // odd width
81 ++in; 81 ++in;
82 82
83 if (!flip) 83 if (!flip)
84 out += width; 84 out += width;
85 in += linepad; 85 in += linepad;
86 } 86 }
87} 87}
88 88
89 89
90 90
91//! converts a 8 bit palettized image into A1R5G5B5 91//! converts a 8 bit palettized image into A1R5G5B5
92void CColorConverter::convert8BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad, bool flip) 92void CColorConverter::convert8BitTo16Bit(const u8* in, s16* out, s32 width, s32 height, const s32* palette, s32 linepad, bool flip)
93{ 93{
94 if (!in || !out || !palette) 94 if (!in || !out || !palette)
95 return; 95 return;
96 96
97 if (flip) 97 if (flip)
98 out += width * height; 98 out += width * height;
99 99
100 for (s32 y=0; y<height; ++y) 100 for (s32 y=0; y<height; ++y)
101 { 101 {
102 if (flip) 102 if (flip)
103 out -= width; // one line back 103 out -= width; // one line back
104 for (s32 x=0; x<width; ++x) 104 for (s32 x=0; x<width; ++x)
105 { 105 {
106 out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)(*in)]); 106 out[x] = X8R8G8B8toA1R5G5B5(palette[(u8)(*in)]);
107 ++in; 107 ++in;
108 } 108 }
109 if (!flip) 109 if (!flip)
110 out += width; 110 out += width;
111 in += linepad; 111 in += linepad;
112 } 112 }
113} 113}
114 114
115//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8 115//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8
116void CColorConverter::convert8BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad, bool flip) 116void CColorConverter::convert8BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad, bool flip)
117{ 117{
118 if (!in || !out ) 118 if (!in || !out )
119 return; 119 return;
120 120
121 const s32 lineWidth = 3 * width; 121 const s32 lineWidth = 3 * width;
122 if (flip) 122 if (flip)
123 out += lineWidth * height; 123 out += lineWidth * height;
124 124
125 for (s32 y=0; y<height; ++y) 125 for (s32 y=0; y<height; ++y)
126 { 126 {
127 if (flip) 127 if (flip)
128 out -= lineWidth; // one line back 128 out -= lineWidth; // one line back
129 for (s32 x=0; x< lineWidth; x += 3) 129 for (s32 x=0; x< lineWidth; x += 3)
130 { 130 {
131 if ( palette ) 131 if ( palette )
132 { 132 {
133#ifdef __BIG_ENDIAN__ 133#ifdef __BIG_ENDIAN__
134 out[x+0] = palette[ (in[0] << 2 ) + 0]; 134 out[x+0] = palette[ (in[0] << 2 ) + 0];
135 out[x+1] = palette[ (in[0] << 2 ) + 1]; 135 out[x+1] = palette[ (in[0] << 2 ) + 1];
136 out[x+2] = palette[ (in[0] << 2 ) + 2]; 136 out[x+2] = palette[ (in[0] << 2 ) + 2];
137#else 137#else
138 out[x+0] = palette[ (in[0] << 2 ) + 2]; 138 out[x+0] = palette[ (in[0] << 2 ) + 2];
139 out[x+1] = palette[ (in[0] << 2 ) + 1]; 139 out[x+1] = palette[ (in[0] << 2 ) + 1];
140 out[x+2] = palette[ (in[0] << 2 ) + 0]; 140 out[x+2] = palette[ (in[0] << 2 ) + 0];
141#endif 141#endif
142 } 142 }
143 else 143 else
144 { 144 {
145 out[x+0] = in[0]; 145 out[x+0] = in[0];
146 out[x+1] = in[0]; 146 out[x+1] = in[0];
147 out[x+2] = in[0]; 147 out[x+2] = in[0];
148 } 148 }
149 ++in; 149 ++in;
150 } 150 }
151 if (!flip) 151 if (!flip)
152 out += lineWidth; 152 out += lineWidth;
153 in += linepad; 153 in += linepad;
154 } 154 }
155} 155}
156 156
157//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8 157//! converts a 8 bit palettized or non palettized image (A8) into R8G8B8
158void CColorConverter::convert8BitTo32Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad, bool flip) 158void CColorConverter::convert8BitTo32Bit(const u8* in, u8* out, s32 width, s32 height, const u8* palette, s32 linepad, bool flip)
159{ 159{
160 if (!in || !out ) 160 if (!in || !out )
161 return; 161 return;
162 162
163 const u32 lineWidth = 4 * width; 163 const u32 lineWidth = 4 * width;
164 if (flip) 164 if (flip)
165 out += lineWidth * height; 165 out += lineWidth * height;
166 166
167 u32 x; 167 u32 x;
168 register u32 c; 168 register u32 c;
169 for (u32 y=0; y < (u32) height; ++y) 169 for (u32 y=0; y < (u32) height; ++y)
170 { 170 {
171 if (flip) 171 if (flip)
172 out -= lineWidth; // one line back 172 out -= lineWidth; // one line back
173 173
174 if ( palette ) 174 if ( palette )
175 { 175 {
176 for (x=0; x < (u32) width; x += 1) 176 for (x=0; x < (u32) width; x += 1)
177 { 177 {
178 c = in[x]; 178 c = in[x];
179 ((u32*)out)[x] = ((u32*)palette)[ c ]; 179 ((u32*)out)[x] = ((u32*)palette)[ c ];
180 } 180 }
181 } 181 }
182 else 182 else
183 { 183 {
184 for (x=0; x < (u32) width; x += 1) 184 for (x=0; x < (u32) width; x += 1)
185 { 185 {
186 c = in[x]; 186 c = in[x];
187#ifdef __BIG_ENDIAN__ 187#ifdef __BIG_ENDIAN__
188 ((u32*)out)[x] = c << 24 | c << 16 | c << 8 | 0x000000FF; 188 ((u32*)out)[x] = c << 24 | c << 16 | c << 8 | 0x000000FF;
189#else 189#else
190 ((u32*)out)[x] = 0xFF000000 | c << 16 | c << 8 | c; 190 ((u32*)out)[x] = 0xFF000000 | c << 16 | c << 8 | c;
191#endif 191#endif
192 } 192 }
193 193
194 } 194 }
195 195
196 if (!flip) 196 if (!flip)
197 out += lineWidth; 197 out += lineWidth;
198 in += width + linepad; 198 in += width + linepad;
199 } 199 }
200} 200}
201 201
202 202
203 203
204//! converts 16bit data to 16bit data 204//! converts 16bit data to 16bit data
205void CColorConverter::convert16BitTo16Bit(const s16* in, s16* out, s32 width, s32 height, s32 linepad, bool flip) 205void CColorConverter::convert16BitTo16Bit(const s16* in, s16* out, s32 width, s32 height, s32 linepad, bool flip)
206{ 206{
207 if (!in || !out) 207 if (!in || !out)
208 return; 208 return;
209 209
210 if (flip) 210 if (flip)
211 out += width * height; 211 out += width * height;
212 212
213 for (s32 y=0; y<height; ++y) 213 for (s32 y=0; y<height; ++y)
214 { 214 {
215 if (flip) 215 if (flip)
216 out -= width; 216 out -= width;
217#ifdef __BIG_ENDIAN__ 217#ifdef __BIG_ENDIAN__
218 for (s32 x=0; x<width; ++x) 218 for (s32 x=0; x<width; ++x)
219 out[x]=os::Byteswap::byteswap(in[x]); 219 out[x]=os::Byteswap::byteswap(in[x]);
220#else 220#else
221 memcpy(out, in, width*sizeof(s16)); 221 memcpy(out, in, width*sizeof(s16));
222#endif 222#endif
223 if (!flip) 223 if (!flip)
224 out += width; 224 out += width;
225 in += width; 225 in += width;
226 in += linepad; 226 in += linepad;
227 } 227 }
228} 228}
229 229
230 230
231 231
232//! copies R8G8B8 24bit data to 24bit data 232//! copies R8G8B8 24bit data to 24bit data
233void CColorConverter::convert24BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, s32 linepad, bool flip, bool bgr) 233void CColorConverter::convert24BitTo24Bit(const u8* in, u8* out, s32 width, s32 height, s32 linepad, bool flip, bool bgr)
234{ 234{
235 if (!in || !out) 235 if (!in || !out)
236 return; 236 return;
237 237
238 const s32 lineWidth = 3 * width; 238 const s32 lineWidth = 3 * width;
239 if (flip) 239 if (flip)
240 out += lineWidth * height; 240 out += lineWidth * height;
241 241
242 for (s32 y=0; y<height; ++y) 242 for (s32 y=0; y<height; ++y)
243 { 243 {
244 if (flip) 244 if (flip)
245 out -= lineWidth; 245 out -= lineWidth;
246 if (bgr) 246 if (bgr)
247 { 247 {
248 for (s32 x=0; x<lineWidth; x+=3) 248 for (s32 x=0; x<lineWidth; x+=3)
249 { 249 {
250 out[x+0] = in[x+2]; 250 out[x+0] = in[x+2];
251 out[x+1] = in[x+1]; 251 out[x+1] = in[x+1];
252 out[x+2] = in[x+0]; 252 out[x+2] = in[x+0];
253 } 253 }
254 } 254 }
255 else 255 else
256 { 256 {
257 memcpy(out,in,lineWidth); 257 memcpy(out,in,lineWidth);
258 } 258 }
259 if (!flip) 259 if (!flip)
260 out += lineWidth; 260 out += lineWidth;
261 in += lineWidth; 261 in += lineWidth;
262 in += linepad; 262 in += linepad;
263 } 263 }
264} 264}
265 265
266 266
267 267
268//! Resizes the surface to a new size and converts it at the same time 268//! Resizes the surface to a new size and converts it at the same time
269//! to an A8R8G8B8 format, returning the pointer to the new buffer. 269//! to an A8R8G8B8 format, returning the pointer to the new buffer.
270void CColorConverter::convert16bitToA8R8G8B8andResize(const s16* in, s32* out, s32 newWidth, s32 newHeight, s32 currentWidth, s32 currentHeight) 270void CColorConverter::convert16bitToA8R8G8B8andResize(const s16* in, s32* out, s32 newWidth, s32 newHeight, s32 currentWidth, s32 currentHeight)
271{ 271{
272 if (!newWidth || !newHeight) 272 if (!newWidth || !newHeight)
273 return; 273 return;
274 274
275 // note: this is very very slow. (i didn't want to write a fast version. 275 // note: this is very very slow. (i didn't want to write a fast version.
276 // but hopefully, nobody wants to convert surfaces every frame. 276 // but hopefully, nobody wants to convert surfaces every frame.
277 277
278 f32 sourceXStep = (f32)currentWidth / (f32)newWidth; 278 f32 sourceXStep = (f32)currentWidth / (f32)newWidth;
279 f32 sourceYStep = (f32)currentHeight / (f32)newHeight; 279 f32 sourceYStep = (f32)currentHeight / (f32)newHeight;
280 f32 sy; 280 f32 sy;
281 s32 t; 281 s32 t;
282 282
283 for (s32 x=0; x<newWidth; ++x) 283 for (s32 x=0; x<newWidth; ++x)
284 { 284 {
285 sy = 0.0f; 285 sy = 0.0f;
286 286
287 for (s32 y=0; y<newHeight; ++y) 287 for (s32 y=0; y<newHeight; ++y)
288 { 288 {
289 t = in[(s32)(((s32)sy)*currentWidth + x*sourceXStep)]; 289 t = in[(s32)(((s32)sy)*currentWidth + x*sourceXStep)];
290 t = (((t >> 15)&0x1)<<31) | (((t >> 10)&0x1F)<<19) | 290 t = (((t >> 15)&0x1)<<31) | (((t >> 10)&0x1F)<<19) |
291 (((t >> 5)&0x1F)<<11) | (t&0x1F)<<3; 291 (((t >> 5)&0x1F)<<11) | (t&0x1F)<<3;
292 out[(s32)(y*newWidth + x)] = t; 292 out[(s32)(y*newWidth + x)] = t;
293 293
294 sy+=sourceYStep; 294 sy+=sourceYStep;
295 } 295 }
296 } 296 }
297} 297}
298 298
299 299
300 300
301//! copies X8R8G8B8 32 bit data 301//! copies X8R8G8B8 32 bit data
302void CColorConverter::convert32BitTo32Bit(const s32* in, s32* out, s32 width, s32 height, s32 linepad, bool flip) 302void CColorConverter::convert32BitTo32Bit(const s32* in, s32* out, s32 width, s32 height, s32 linepad, bool flip)
303{ 303{
304 if (!in || !out) 304 if (!in || !out)
305 return; 305 return;
306 306
307 if (flip) 307 if (flip)
308 out += width * height; 308 out += width * height;
309 309
310 for (s32 y=0; y<height; ++y) 310 for (s32 y=0; y<height; ++y)
311 { 311 {
312 if (flip) 312 if (flip)
313 out -= width; 313 out -= width;
314#ifdef __BIG_ENDIAN__ 314#ifdef __BIG_ENDIAN__
315 for (s32 x=0; x<width; ++x) 315 for (s32 x=0; x<width; ++x)
316 out[x]=os::Byteswap::byteswap(in[x]); 316 out[x]=os::Byteswap::byteswap(in[x]);
317#else 317#else
318 memcpy(out, in, width*sizeof(s32)); 318 memcpy(out, in, width*sizeof(s32));
319#endif 319#endif
320 if (!flip) 320 if (!flip)
321 out += width; 321 out += width;
322 in += width; 322 in += width;
323 in += linepad; 323 in += linepad;
324 } 324 }
325} 325}
326 326
327 327
328 328
329void CColorConverter::convert_A1R5G5B5toR8G8B8(const void* sP, s32 sN, void* dP) 329void CColorConverter::convert_A1R5G5B5toR8G8B8(const void* sP, s32 sN, void* dP)
330{ 330{
331 u16* sB = (u16*)sP; 331 u16* sB = (u16*)sP;
332 u8 * dB = (u8 *)dP; 332 u8 * dB = (u8 *)dP;
333 333
334 for (s32 x = 0; x < sN; ++x) 334 for (s32 x = 0; x < sN; ++x)
335 { 335 {
336 dB[2] = (*sB & 0x7c00) >> 7; 336 dB[2] = (*sB & 0x7c00) >> 7;
337 dB[1] = (*sB & 0x03e0) >> 2; 337 dB[1] = (*sB & 0x03e0) >> 2;
338 dB[0] = (*sB & 0x1f) << 3; 338 dB[0] = (*sB & 0x1f) << 3;
339 339
340 sB += 1; 340 sB += 1;
341 dB += 3; 341 dB += 3;
342 } 342 }
343} 343}
344 344
345void CColorConverter::convert_A1R5G5B5toB8G8R8(const void* sP, s32 sN, void* dP) 345void CColorConverter::convert_A1R5G5B5toB8G8R8(const void* sP, s32 sN, void* dP)
346{ 346{
347 u16* sB = (u16*)sP; 347 u16* sB = (u16*)sP;
348 u8 * dB = (u8 *)dP; 348 u8 * dB = (u8 *)dP;
349 349
350 for (s32 x = 0; x < sN; ++x) 350 for (s32 x = 0; x < sN; ++x)
351 { 351 {
352 dB[0] = (*sB & 0x7c00) >> 7; 352 dB[0] = (*sB & 0x7c00) >> 7;
353 dB[1] = (*sB & 0x03e0) >> 2; 353 dB[1] = (*sB & 0x03e0) >> 2;
354 dB[2] = (*sB & 0x1f) << 3; 354 dB[2] = (*sB & 0x1f) << 3;
355 355
356 sB += 1; 356 sB += 1;
357 dB += 3; 357 dB += 3;
358 } 358 }
359} 359}
360 360
361void CColorConverter::convert_A1R5G5B5toA8R8G8B8(const void* sP, s32 sN, void* dP) 361void CColorConverter::convert_A1R5G5B5toA8R8G8B8(const void* sP, s32 sN, void* dP)
362{ 362{
363 u16* sB = (u16*)sP; 363 u16* sB = (u16*)sP;
364 u32* dB = (u32*)dP; 364 u32* dB = (u32*)dP;
365 365
366 for (s32 x = 0; x < sN; ++x) 366 for (s32 x = 0; x < sN; ++x)
367 *dB++ = A1R5G5B5toA8R8G8B8(*sB++); 367 *dB++ = A1R5G5B5toA8R8G8B8(*sB++);
368} 368}
369 369
370void CColorConverter::convert_A1R5G5B5toA1R5G5B5(const void* sP, s32 sN, void* dP) 370void CColorConverter::convert_A1R5G5B5toA1R5G5B5(const void* sP, s32 sN, void* dP)
371{ 371{
372 memcpy(dP, sP, sN * 2); 372 memcpy(dP, sP, sN * 2);
373} 373}
374 374
375void CColorConverter::convert_A1R5G5B5toR5G6B5(const void* sP, s32 sN, void* dP) 375void CColorConverter::convert_A1R5G5B5toR5G6B5(const void* sP, s32 sN, void* dP)
376{ 376{
377 u16* sB = (u16*)sP; 377 u16* sB = (u16*)sP;
378 u16* dB = (u16*)dP; 378 u16* dB = (u16*)dP;
379 379
380 for (s32 x = 0; x < sN; ++x) 380 for (s32 x = 0; x < sN; ++x)
381 *dB++ = A1R5G5B5toR5G6B5(*sB++); 381 *dB++ = A1R5G5B5toR5G6B5(*sB++);
382} 382}
383 383
384void CColorConverter::convert_A8R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP) 384void CColorConverter::convert_A8R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP)
385{ 385{
386 u8* sB = (u8*)sP; 386 u8* sB = (u8*)sP;
387 u8* dB = (u8*)dP; 387 u8* dB = (u8*)dP;
388 388
389 for (s32 x = 0; x < sN; ++x) 389 for (s32 x = 0; x < sN; ++x)
390 { 390 {
391 // sB[3] is alpha 391 // sB[3] is alpha
392 dB[0] = sB[2]; 392 dB[0] = sB[2];
393 dB[1] = sB[1]; 393 dB[1] = sB[1];
394 dB[2] = sB[0]; 394 dB[2] = sB[0];
395 395
396 sB += 4; 396 sB += 4;
397 dB += 3; 397 dB += 3;
398 } 398 }
399} 399}
400 400
401void CColorConverter::convert_A8R8G8B8toB8G8R8(const void* sP, s32 sN, void* dP) 401void CColorConverter::convert_A8R8G8B8toB8G8R8(const void* sP, s32 sN, void* dP)
402{ 402{
403 u8* sB = (u8*)sP; 403 u8* sB = (u8*)sP;
404 u8* dB = (u8*)dP; 404 u8* dB = (u8*)dP;
405 405
406 for (s32 x = 0; x < sN; ++x) 406 for (s32 x = 0; x < sN; ++x)
407 { 407 {
408 // sB[3] is alpha 408 // sB[3] is alpha
409 dB[0] = sB[0]; 409 dB[0] = sB[0];
410 dB[1] = sB[1]; 410 dB[1] = sB[1];
411 dB[2] = sB[2]; 411 dB[2] = sB[2];
412 412
413 sB += 4; 413 sB += 4;
414 dB += 3; 414 dB += 3;
415 } 415 }
416} 416}
417 417
418void CColorConverter::convert_A8R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP) 418void CColorConverter::convert_A8R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP)
419{ 419{
420 memcpy(dP, sP, sN * 4); 420 memcpy(dP, sP, sN * 4);
421} 421}
422 422
423void CColorConverter::convert_A8R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP) 423void CColorConverter::convert_A8R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP)
424{ 424{
425 u32* sB = (u32*)sP; 425 u32* sB = (u32*)sP;
426 u16* dB = (u16*)dP; 426 u16* dB = (u16*)dP;
427 427
428 for (s32 x = 0; x < sN; ++x) 428 for (s32 x = 0; x < sN; ++x)
429 *dB++ = A8R8G8B8toA1R5G5B5(*sB++); 429 *dB++ = A8R8G8B8toA1R5G5B5(*sB++);
430} 430}
431 431
432void CColorConverter::convert_A8R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP) 432void CColorConverter::convert_A8R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP)
433{ 433{
434 u8 * sB = (u8 *)sP; 434 u8 * sB = (u8 *)sP;
435 u16* dB = (u16*)dP; 435 u16* dB = (u16*)dP;
436 436
437 for (s32 x = 0; x < sN; ++x) 437 for (s32 x = 0; x < sN; ++x)
438 { 438 {
439 s32 r = sB[2] >> 3; 439 s32 r = sB[2] >> 3;
440 s32 g = sB[1] >> 2; 440 s32 g = sB[1] >> 2;
441 s32 b = sB[0] >> 3; 441 s32 b = sB[0] >> 3;
442 442
443 dB[0] = (r << 11) | (g << 5) | (b); 443 dB[0] = (r << 11) | (g << 5) | (b);
444 444
445 sB += 4; 445 sB += 4;
446 dB += 1; 446 dB += 1;
447 } 447 }
448} 448}
449 449
450void CColorConverter::convert_A8R8G8B8toR3G3B2(const void* sP, s32 sN, void* dP) 450void CColorConverter::convert_A8R8G8B8toR3G3B2(const void* sP, s32 sN, void* dP)
451{ 451{
452 u8* sB = (u8*)sP; 452 u8* sB = (u8*)sP;
453 u8* dB = (u8*)dP; 453 u8* dB = (u8*)dP;
454 454
455 for (s32 x = 0; x < sN; ++x) 455 for (s32 x = 0; x < sN; ++x)
456 { 456 {
457 u8 r = sB[2] & 0xe0; 457 u8 r = sB[2] & 0xe0;
458 u8 g = (sB[1] & 0xe0) >> 3; 458 u8 g = (sB[1] & 0xe0) >> 3;
459 u8 b = (sB[0] & 0xc0) >> 6; 459 u8 b = (sB[0] & 0xc0) >> 6;
460 460
461 dB[0] = (r | g | b); 461 dB[0] = (r | g | b);
462 462
463 sB += 4; 463 sB += 4;
464 dB += 1; 464 dB += 1;
465 } 465 }
466} 466}
467 467
468void CColorConverter::convert_R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP) 468void CColorConverter::convert_R8G8B8toR8G8B8(const void* sP, s32 sN, void* dP)
469{ 469{
470 memcpy(dP, sP, sN * 3); 470 memcpy(dP, sP, sN * 3);
471} 471}
472 472
473void CColorConverter::convert_R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP) 473void CColorConverter::convert_R8G8B8toA8R8G8B8(const void* sP, s32 sN, void* dP)
474{ 474{
475 u8* sB = (u8* )sP; 475 u8* sB = (u8* )sP;
476 u32* dB = (u32*)dP; 476 u32* dB = (u32*)dP;
477 477
478 for (s32 x = 0; x < sN; ++x) 478 for (s32 x = 0; x < sN; ++x)
479 { 479 {
480 *dB = 0xff000000 | (sB[0]<<16) | (sB[1]<<8) | sB[2]; 480 *dB = 0xff000000 | (sB[0]<<16) | (sB[1]<<8) | sB[2];
481 481
482 sB += 3; 482 sB += 3;
483 ++dB; 483 ++dB;
484 } 484 }
485} 485}
486 486
487void CColorConverter::convert_R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP) 487void CColorConverter::convert_R8G8B8toA1R5G5B5(const void* sP, s32 sN, void* dP)
488{ 488{
489 u8 * sB = (u8 *)sP; 489 u8 * sB = (u8 *)sP;
490 u16* dB = (u16*)dP; 490 u16* dB = (u16*)dP;
491 491
492 for (s32 x = 0; x < sN; ++x) 492 for (s32 x = 0; x < sN; ++x)
493 { 493 {
494 s32 r = sB[0] >> 3; 494 s32 r = sB[0] >> 3;
495 s32 g = sB[1] >> 3; 495 s32 g = sB[1] >> 3;
496 s32 b = sB[2] >> 3; 496 s32 b = sB[2] >> 3;
497 497
498 dB[0] = (0x8000) | (r << 10) | (g << 5) | (b); 498 dB[0] = (0x8000) | (r << 10) | (g << 5) | (b);
499 499
500 sB += 3; 500 sB += 3;
501 dB += 1; 501 dB += 1;
502 } 502 }
503} 503}
504 504
505void CColorConverter::convert_B8G8R8toA8R8G8B8(const void* sP, s32 sN, void* dP) 505void CColorConverter::convert_B8G8R8toA8R8G8B8(const void* sP, s32 sN, void* dP)
506{ 506{
507 u8* sB = (u8* )sP; 507 u8* sB = (u8* )sP;
508 u32* dB = (u32*)dP; 508 u32* dB = (u32*)dP;
509 509
510 for (s32 x = 0; x < sN; ++x) 510 for (s32 x = 0; x < sN; ++x)
511 { 511 {
512 *dB = 0xff000000 | (sB[2]<<16) | (sB[1]<<8) | sB[0]; 512 *dB = 0xff000000 | (sB[2]<<16) | (sB[1]<<8) | sB[0];
513 513
514 sB += 3; 514 sB += 3;
515 ++dB; 515 ++dB;
516 } 516 }
517} 517}
518 518
519void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* dP) 519void CColorConverter::convert_B8G8R8A8toA8R8G8B8(const void* sP, s32 sN, void* dP)
520{ 520{
521 u8* sB = (u8*)sP; 521 u8* sB = (u8*)sP;
522 u8* dB = (u8*)dP; 522 u8* dB = (u8*)dP;
523 523
524 for (s32 x = 0; x < sN; ++x) 524 for (s32 x = 0; x < sN; ++x)
525 { 525 {
526 dB[0] = sB[3]; 526 dB[0] = sB[3];
527 dB[1] = sB[2]; 527 dB[1] = sB[2];
528 dB[2] = sB[1]; 528 dB[2] = sB[1];
529 dB[3] = sB[0]; 529 dB[3] = sB[0];
530 530
531 sB += 4; 531 sB += 4;
532 dB += 4; 532 dB += 4;
533 } 533 }
534 534
535} 535}
536 536
537void CColorConverter::convert_R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP) 537void CColorConverter::convert_R8G8B8toR5G6B5(const void* sP, s32 sN, void* dP)
538{ 538{
539 u8 * sB = (u8 *)sP; 539 u8 * sB = (u8 *)sP;
540 u16* dB = (u16*)dP; 540 u16* dB = (u16*)dP;
541 541
542 for (s32 x = 0; x < sN; ++x) 542 for (s32 x = 0; x < sN; ++x)
543 { 543 {
544 s32 r = sB[0] >> 3; 544 s32 r = sB[0] >> 3;
545 s32 g = sB[1] >> 2; 545 s32 g = sB[1] >> 2;
546 s32 b = sB[2] >> 3; 546 s32 b = sB[2] >> 3;
547 547
548 dB[0] = (r << 11) | (g << 5) | (b); 548 dB[0] = (r << 11) | (g << 5) | (b);
549 549
550 sB += 3; 550 sB += 3;
551 dB += 1; 551 dB += 1;
552 } 552 }
553} 553}
554 554
555void CColorConverter::convert_R5G6B5toR5G6B5(const void* sP, s32 sN, void* dP) 555void CColorConverter::convert_R5G6B5toR5G6B5(const void* sP, s32 sN, void* dP)
556{ 556{
557 memcpy(dP, sP, sN * 2); 557 memcpy(dP, sP, sN * 2);
558} 558}
559 559
560void CColorConverter::convert_R5G6B5toR8G8B8(const void* sP, s32 sN, void* dP) 560void CColorConverter::convert_R5G6B5toR8G8B8(const void* sP, s32 sN, void* dP)
561{ 561{
562 u16* sB = (u16*)sP; 562 u16* sB = (u16*)sP;
563 u8 * dB = (u8 *)dP; 563 u8 * dB = (u8 *)dP;
564 564
565 for (s32 x = 0; x < sN; ++x) 565 for (s32 x = 0; x < sN; ++x)
566 { 566 {
567 dB[0] = (*sB & 0xf800) >> 8; 567 dB[0] = (*sB & 0xf800) >> 8;
568 dB[1] = (*sB & 0x07e0) >> 3; 568 dB[1] = (*sB & 0x07e0) >> 3;
569 dB[2] = (*sB & 0x001f) << 3; 569 dB[2] = (*sB & 0x001f) << 3;
570 570
571 sB += 1; 571 sB += 1;
572 dB += 3; 572 dB += 3;
573 } 573 }
574} 574}
575 575
576void CColorConverter::convert_R5G6B5toB8G8R8(const void* sP, s32 sN, void* dP) 576void CColorConverter::convert_R5G6B5toB8G8R8(const void* sP, s32 sN, void* dP)
577{ 577{
578 u16* sB = (u16*)sP; 578 u16* sB = (u16*)sP;
579 u8 * dB = (u8 *)dP; 579 u8 * dB = (u8 *)dP;
580 580
581 for (s32 x = 0; x < sN; ++x) 581 for (s32 x = 0; x < sN; ++x)
582 { 582 {
583 dB[2] = (*sB & 0xf800) >> 8; 583 dB[2] = (*sB & 0xf800) >> 8;
584 dB[1] = (*sB & 0x07e0) >> 3; 584 dB[1] = (*sB & 0x07e0) >> 3;
585 dB[0] = (*sB & 0x001f) << 3; 585 dB[0] = (*sB & 0x001f) << 3;
586 586
587 sB += 1; 587 sB += 1;
588 dB += 3; 588 dB += 3;
589 } 589 }
590} 590}
591 591
592void CColorConverter::convert_R5G6B5toA8R8G8B8(const void* sP, s32 sN, void* dP) 592void CColorConverter::convert_R5G6B5toA8R8G8B8(const void* sP, s32 sN, void* dP)
593{ 593{
594 u16* sB = (u16*)sP; 594 u16* sB = (u16*)sP;
595 u32* dB = (u32*)dP; 595 u32* dB = (u32*)dP;
596 596
597 for (s32 x = 0; x < sN; ++x) 597 for (s32 x = 0; x < sN; ++x)
598 *dB++ = R5G6B5toA8R8G8B8(*sB++); 598 *dB++ = R5G6B5toA8R8G8B8(*sB++);
599} 599}
600 600
601void CColorConverter::convert_R5G6B5toA1R5G5B5(const void* sP, s32 sN, void* dP) 601void CColorConverter::convert_R5G6B5toA1R5G5B5(const void* sP, s32 sN, void* dP)
602{ 602{
603 u16* sB = (u16*)sP; 603 u16* sB = (u16*)sP;
604 u16* dB = (u16*)dP; 604 u16* dB = (u16*)dP;
605 605
606 for (s32 x = 0; x < sN; ++x) 606 for (s32 x = 0; x < sN; ++x)
607 *dB++ = R5G6B5toA1R5G5B5(*sB++); 607 *dB++ = R5G6B5toA1R5G5B5(*sB++);
608} 608}
609 609
610 610
611void CColorConverter::convert_viaFormat(const void* sP, ECOLOR_FORMAT sF, s32 sN, 611void CColorConverter::convert_viaFormat(const void* sP, ECOLOR_FORMAT sF, s32 sN,
612 void* dP, ECOLOR_FORMAT dF) 612 void* dP, ECOLOR_FORMAT dF)
613{ 613{
614 switch (sF) 614 switch (sF)
615 { 615 {
616 case ECF_A1R5G5B5: 616 case ECF_A1R5G5B5:
617 switch (dF) 617 switch (dF)
618 { 618 {
619 case ECF_A1R5G5B5: 619 case ECF_A1R5G5B5:
620 convert_A1R5G5B5toA1R5G5B5(sP, sN, dP); 620 convert_A1R5G5B5toA1R5G5B5(sP, sN, dP);
621 break; 621 break;
622 case ECF_R5G6B5: 622 case ECF_R5G6B5:
623 convert_A1R5G5B5toR5G6B5(sP, sN, dP); 623 convert_A1R5G5B5toR5G6B5(sP, sN, dP);
624 break; 624 break;
625 case ECF_A8R8G8B8: 625 case ECF_A8R8G8B8:
626 convert_A1R5G5B5toA8R8G8B8(sP, sN, dP); 626 convert_A1R5G5B5toA8R8G8B8(sP, sN, dP);
627 break; 627 break;
628 case ECF_R8G8B8: 628 case ECF_R8G8B8:
629 convert_A1R5G5B5toR8G8B8(sP, sN, dP); 629 convert_A1R5G5B5toR8G8B8(sP, sN, dP);
630 break; 630 break;
631#ifndef _DEBUG 631#ifndef _DEBUG
632 default: 632 default:
633 break; 633 break;
634#endif 634#endif
635 } 635 }
636 break; 636 break;
637 case ECF_R5G6B5: 637 case ECF_R5G6B5:
638 switch (dF) 638 switch (dF)
639 { 639 {
640 case ECF_A1R5G5B5: 640 case ECF_A1R5G5B5:
641 convert_R5G6B5toA1R5G5B5(sP, sN, dP); 641 convert_R5G6B5toA1R5G5B5(sP, sN, dP);
642 break; 642 break;
643 case ECF_R5G6B5: 643 case ECF_R5G6B5:
644 convert_R5G6B5toR5G6B5(sP, sN, dP); 644 convert_R5G6B5toR5G6B5(sP, sN, dP);
645 break; 645 break;
646 case ECF_A8R8G8B8: 646 case ECF_A8R8G8B8:
647 convert_R5G6B5toA8R8G8B8(sP, sN, dP); 647 convert_R5G6B5toA8R8G8B8(sP, sN, dP);
648 break; 648 break;
649 case ECF_R8G8B8: 649 case ECF_R8G8B8:
650 convert_R5G6B5toR8G8B8(sP, sN, dP); 650 convert_R5G6B5toR8G8B8(sP, sN, dP);
651 break; 651 break;
652#ifndef _DEBUG 652#ifndef _DEBUG
653 default: 653 default:
654 break; 654 break;
655#endif 655#endif
656 } 656 }
657 break; 657 break;
658 case ECF_A8R8G8B8: 658 case ECF_A8R8G8B8:
659 switch (dF) 659 switch (dF)
660 { 660 {
661 case ECF_A1R5G5B5: 661 case ECF_A1R5G5B5:
662 convert_A8R8G8B8toA1R5G5B5(sP, sN, dP); 662 convert_A8R8G8B8toA1R5G5B5(sP, sN, dP);
663 break; 663 break;
664 case ECF_R5G6B5: 664 case ECF_R5G6B5:
665 convert_A8R8G8B8toR5G6B5(sP, sN, dP); 665 convert_A8R8G8B8toR5G6B5(sP, sN, dP);
666 break; 666 break;
667 case ECF_A8R8G8B8: 667 case ECF_A8R8G8B8:
668 convert_A8R8G8B8toA8R8G8B8(sP, sN, dP); 668 convert_A8R8G8B8toA8R8G8B8(sP, sN, dP);
669 break; 669 break;
670 case ECF_R8G8B8: 670 case ECF_R8G8B8:
671 convert_A8R8G8B8toR8G8B8(sP, sN, dP); 671 convert_A8R8G8B8toR8G8B8(sP, sN, dP);
672 break; 672 break;
673#ifndef _DEBUG 673#ifndef _DEBUG
674 default: 674 default:
675 break; 675 break;
676#endif 676#endif
677 } 677 }
678 break; 678 break;
679 case ECF_R8G8B8: 679 case ECF_R8G8B8:
680 switch (dF) 680 switch (dF)
681 { 681 {
682 case ECF_A1R5G5B5: 682 case ECF_A1R5G5B5:
683 convert_R8G8B8toA1R5G5B5(sP, sN, dP); 683 convert_R8G8B8toA1R5G5B5(sP, sN, dP);
684 break; 684 break;
685 case ECF_R5G6B5: 685 case ECF_R5G6B5:
686 convert_R8G8B8toR5G6B5(sP, sN, dP); 686 convert_R8G8B8toR5G6B5(sP, sN, dP);
687 break; 687 break;
688 case ECF_A8R8G8B8: 688 case ECF_A8R8G8B8:
689 convert_R8G8B8toA8R8G8B8(sP, sN, dP); 689 convert_R8G8B8toA8R8G8B8(sP, sN, dP);
690 break; 690 break;
691 case ECF_R8G8B8: 691 case ECF_R8G8B8:
692 convert_R8G8B8toR8G8B8(sP, sN, dP); 692 convert_R8G8B8toR8G8B8(sP, sN, dP);
693 break; 693 break;
694#ifndef _DEBUG 694#ifndef _DEBUG
695 default: 695 default:
696 break; 696 break;
697#endif 697#endif
698 } 698 }
699 break; 699 break;
700 } 700 }
701} 701}
702 702
703 703
704} // end namespace video 704} // end namespace video
705} // end namespace irr 705} // end namespace irr