blob: 9513dbb9278364c3e6efe56d6c236400d1dc9057 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
3// Copyright (c) 0013 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// loadimage.cpp: Defines image loading functions.
9
10#include "libGLESv2/renderer/loadimage.h"
11
12namespace rx
13{
14
15template <typename T>
16inline static T *offsetDataPointer(void *data, int y, int z, int rowPitch, int depthPitch)
17{
18 return reinterpret_cast<T*>(reinterpret_cast<unsigned char*>(data) + (y * rowPitch) + (z * depthPitch));
19}
20
21template <typename T>
22inline static const T *offsetDataPointer(const void *data, int y, int z, int rowPitch, int depthPitch)
23{
24 return reinterpret_cast<const T*>(reinterpret_cast<const unsigned char*>(data) + (y * rowPitch) + (z * depthPitch));
25}
26
27void loadAlphaDataToBGRA(int width, int height, int depth,
28 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
29 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
30{
31 const unsigned char *source = NULL;
32 unsigned char *dest = NULL;
33
34 for (int z = 0; z < depth; z++)
35 {
36 for (int y = 0; y < height; y++)
37 {
38 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
39 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
40 for (int x = 0; x < width; x++)
41 {
42 dest[4 * x + 0] = 0;
43 dest[4 * x + 1] = 0;
44 dest[4 * x + 2] = 0;
45 dest[4 * x + 3] = source[x];
46 }
47 }
48 }
49}
50
51void loadAlphaDataToNative(int width, int height, int depth,
52 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
53 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
54{
55 const unsigned char *source = NULL;
56 unsigned char *dest = NULL;
57
58 for (int z = 0; z < depth; z++)
59 {
60 for (int y = 0; y < height; y++)
61 {
62 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
63 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
64 memcpy(dest, source, width);
65 }
66 }
67}
68
69void loadAlphaFloatDataToRGBA(int width, int height, int depth,
70 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
71 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
72{
73 const float *source = NULL;
74 float *dest = NULL;
75
76 for (int z = 0; z < depth; z++)
77 {
78 for (int y = 0; y < height; y++)
79 {
80 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
81 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
82 for (int x = 0; x < width; x++)
83 {
84 dest[4 * x + 0] = 0;
85 dest[4 * x + 1] = 0;
86 dest[4 * x + 2] = 0;
87 dest[4 * x + 3] = source[x];
88 }
89 }
90 }
91}
92
93void loadAlphaHalfFloatDataToRGBA(int width, int height, int depth,
94 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
95 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
96{
97 const unsigned short *source = NULL;
98 unsigned short *dest = NULL;
99
100 for (int z = 0; z < depth; z++)
101 {
102 for (int y = 0; y < height; y++)
103 {
104 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
105 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
106 for (int x = 0; x < width; x++)
107 {
108 dest[4 * x + 0] = 0;
109 dest[4 * x + 1] = 0;
110 dest[4 * x + 2] = 0;
111 dest[4 * x + 3] = source[x];
112 }
113 }
114 }
115}
116
117void loadLuminanceDataToNative(int width, int height, int depth,
118 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
119 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
120{
121 const unsigned char *source = NULL;
122 unsigned char *dest = NULL;
123
124 for (int z = 0; z < depth; z++)
125 {
126 for (int y = 0; y < height; y++)
127 {
128 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
129 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
130 memcpy(dest, source, width);
131 }
132 }
133}
134
135void loadLuminanceDataToBGRA(int width, int height, int depth,
136 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
137 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
138{
139 const unsigned char *source = NULL;
140 unsigned char *dest = NULL;
141
142 for (int z = 0; z < depth; z++)
143 {
144 for (int y = 0; y < height; y++)
145 {
146 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
147 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
148 for (int x = 0; x < width; x++)
149 {
150 dest[4 * x + 0] = source[x];
151 dest[4 * x + 1] = source[x];
152 dest[4 * x + 2] = source[x];
153 dest[4 * x + 3] = 0xFF;
154 }
155 }
156 }
157}
158
159void loadLuminanceFloatDataToRGBA(int width, int height, int depth,
160 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
161 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
162{
163 const float *source = NULL;
164 float *dest = NULL;
165
166 for (int z = 0; z < depth; z++)
167 {
168 for (int y = 0; y < height; y++)
169 {
170 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
171 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
172 for (int x = 0; x < width; x++)
173 {
174 dest[4 * x + 0] = source[x];
175 dest[4 * x + 1] = source[x];
176 dest[4 * x + 2] = source[x];
177 dest[4 * x + 3] = 1.0f;
178 }
179 }
180 }
181}
182
183void loadLuminanceFloatDataToRGB(int width, int height, int depth,
184 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
185 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
186{
187 const float *source = NULL;
188 float *dest = NULL;
189
190 for (int z = 0; z < depth; z++)
191 {
192 for (int y = 0; y < height; y++)
193 {
194 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
195 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
196 for (int x = 0; x < width; x++)
197 {
198 dest[3 * x + 0] = source[x];
199 dest[3 * x + 1] = source[x];
200 dest[3 * x + 2] = source[x];
201 }
202 }
203 }
204}
205
206void loadLuminanceHalfFloatDataToRGBA(int width, int height, int depth,
207 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
208 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
209{
210 const unsigned short *source = NULL;
211 unsigned short *dest = NULL;
212
213 for (int z = 0; z < depth; z++)
214 {
215 for (int y = 0; y < height; y++)
216 {
217 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
218 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
219 for (int x = 0; x < width; x++)
220 {
221 dest[4 * x + 0] = source[x];
222 dest[4 * x + 1] = source[x];
223 dest[4 * x + 2] = source[x];
224 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
225 }
226 }
227 }
228}
229
230void loadLuminanceAlphaDataToNative(int width, int height, int depth,
231 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
232 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
233{
234 const unsigned char *source = NULL;
235 unsigned char *dest = NULL;
236
237 for (int z = 0; z < depth; z++)
238 {
239 for (int y = 0; y < height; y++)
240 {
241 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
242 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
243
244 memcpy(dest, source, width * 2);
245 }
246 }
247}
248
249void loadLuminanceAlphaDataToBGRA(int width, int height, int depth,
250 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
251 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
252{
253 const unsigned char *source = NULL;
254 unsigned char *dest = NULL;
255
256 for (int z = 0; z < depth; z++)
257 {
258 for (int y = 0; y < height; y++)
259 {
260 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
261 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
262
263 for (int x = 0; x < width; x++)
264 {
265 dest[4 * x + 0] = source[2*x+0];
266 dest[4 * x + 1] = source[2*x+0];
267 dest[4 * x + 2] = source[2*x+0];
268 dest[4 * x + 3] = source[2*x+1];
269 }
270 }
271 }
272}
273
274void loadLuminanceAlphaFloatDataToRGBA(int width, int height, int depth,
275 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
276 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
277{
278 const float *source = NULL;
279 float *dest = NULL;
280
281 for (int z = 0; z < depth; z++)
282 {
283 for (int y = 0; y < height; y++)
284 {
285 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
286 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
287 for (int x = 0; x < width; x++)
288 {
289 dest[4 * x + 0] = source[2*x+0];
290 dest[4 * x + 1] = source[2*x+0];
291 dest[4 * x + 2] = source[2*x+0];
292 dest[4 * x + 3] = source[2*x+1];
293 }
294 }
295 }
296}
297
298void loadLuminanceAlphaHalfFloatDataToRGBA(int width, int height, int depth,
299 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
300 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
301{
302 const unsigned short *source = NULL;
303 unsigned short *dest = NULL;
304
305 for (int z = 0; z < depth; z++)
306 {
307 for (int y = 0; y < height; y++)
308 {
309 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
310 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
311 for (int x = 0; x < width; x++)
312 {
313 dest[4 * x + 0] = source[2*x+0];
314 dest[4 * x + 1] = source[2*x+0];
315 dest[4 * x + 2] = source[2*x+0];
316 dest[4 * x + 3] = source[2*x+1];
317 }
318 }
319 }
320}
321
322void loadRGBUByteDataToBGRX(int width, int height, int depth,
323 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
324 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
325{
326 const unsigned char *source = NULL;
327 unsigned char *dest = NULL;
328
329 for (int z = 0; z < depth; z++)
330 {
331 for (int y = 0; y < height; y++)
332 {
333 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
334 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
335 for (int x = 0; x < width; x++)
336 {
337 dest[4 * x + 0] = source[x * 3 + 2];
338 dest[4 * x + 1] = source[x * 3 + 1];
339 dest[4 * x + 2] = source[x * 3 + 0];
340 dest[4 * x + 3] = 0xFF;
341 }
342 }
343 }
344}
345
346void loadRGBUByteDataToRGBA(int width, int height, int depth,
347 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
348 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
349{
350 const unsigned char *source = NULL;
351 unsigned char *dest = NULL;
352
353 for (int z = 0; z < depth; z++)
354 {
355 for (int y = 0; y < height; y++)
356 {
357 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
358 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
359 for (int x = 0; x < width; x++)
360 {
361 dest[4 * x + 0] = source[x * 3 + 0];
362 dest[4 * x + 1] = source[x * 3 + 1];
363 dest[4 * x + 2] = source[x * 3 + 2];
364 dest[4 * x + 3] = 0xFF;
365 }
366 }
367 }
368}
369
370void loadRGB565DataToBGRA(int width, int height, int depth,
371 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
372 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
373{
374 const unsigned short *source = NULL;
375 unsigned char *dest = NULL;
376
377 for (int z = 0; z < depth; z++)
378 {
379 for (int y = 0; y < height; y++)
380 {
381 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
382 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
383 for (int x = 0; x < width; x++)
384 {
385 unsigned short rgba = source[x];
386 dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
387 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
388 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
389 dest[4 * x + 3] = 0xFF;
390 }
391 }
392 }
393}
394
395void loadRGB565DataToRGBA(int width, int height, int depth,
396 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
397 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
398{
399 const unsigned short *source = NULL;
400 unsigned char *dest = NULL;
401
402 for (int z = 0; z < depth; z++)
403 {
404 for (int y = 0; y < height; y++)
405 {
406 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
407 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
408 for (int x = 0; x < width; x++)
409 {
410 unsigned short rgba = source[x];
411 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
412 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
413 dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
414 dest[4 * x + 3] = 0xFF;
415 }
416 }
417 }
418}
419
420void loadRGBFloatDataToRGBA(int width, int height, int depth,
421 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
422 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
423{
424 const float *source = NULL;
425 float *dest = NULL;
426
427 for (int z = 0; z < depth; z++)
428 {
429 for (int y = 0; y < height; y++)
430 {
431 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
432 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
433 for (int x = 0; x < width; x++)
434 {
435 dest[4 * x + 0] = source[x * 3 + 0];
436 dest[4 * x + 1] = source[x * 3 + 1];
437 dest[4 * x + 2] = source[x * 3 + 2];
438 dest[4 * x + 3] = 1.0f;
439 }
440 }
441 }
442}
443
444void loadRGBFloatDataToNative(int width, int height, int depth,
445 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
446 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
447{
448 const float *source = NULL;
449 float *dest = NULL;
450
451 for (int z = 0; z < depth; z++)
452 {
453 for (int y = 0; y < height; y++)
454 {
455 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
456 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
457 memcpy(dest, source, width * 12);
458 }
459 }
460}
461
462void loadRGBHalfFloatDataToRGBA(int width, int height, int depth,
463 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
464 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
465{
466 const unsigned short *source = NULL;
467 unsigned short *dest = NULL;
468
469 for (int z = 0; z < depth; z++)
470 {
471 for (int y = 0; y < height; y++)
472 {
473 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
474 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
475 for (int x = 0; x < width; x++)
476 {
477 dest[4 * x + 0] = source[x * 3 + 0];
478 dest[4 * x + 1] = source[x * 3 + 1];
479 dest[4 * x + 2] = source[x * 3 + 2];
480 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
481 }
482 }
483 }
484}
485
486void loadRGBAUByteDataToBGRA(int width, int height, int depth,
487 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
488 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
489{
490 const unsigned int *source = NULL;
491 unsigned int *dest = NULL;
492
493 for (int z = 0; z < depth; z++)
494 {
495 for (int y = 0; y < height; y++)
496 {
497 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
498 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
499
500 for (int x = 0; x < width; x++)
501 {
502 unsigned int rgba = source[x];
503 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
504 }
505 }
506 }
507}
508
509void loadRGBAUByteDataToNative(int width, int height, int depth,
510 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
511 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
512{
513 const unsigned int *source = NULL;
514 unsigned int *dest = NULL;
515
516 for (int z = 0; z < depth; z++)
517 {
518 for (int y = 0; y < height; y++)
519 {
520 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
521 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
522
523 memcpy(dest, source, width * 4);
524 }
525 }
526}
527
528void loadRGBA4444DataToBGRA(int width, int height, int depth,
529 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
530 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
531{
532 const unsigned short *source = NULL;
533 unsigned char *dest = NULL;
534
535 for (int z = 0; z < depth; z++)
536 {
537 for (int y = 0; y < height; y++)
538 {
539 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
540 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
541 for (int x = 0; x < width; x++)
542 {
543 unsigned short rgba = source[x];
544 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
545 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
546 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
547 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
548 }
549 }
550 }
551}
552
553void loadRGBA4444DataToRGBA(int width, int height, int depth,
554 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
555 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
556{
557 const unsigned short *source = NULL;
558 unsigned char *dest = NULL;
559
560 for (int z = 0; z < depth; z++)
561 {
562 for (int y = 0; y < height; y++)
563 {
564 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
565 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
566 for (int x = 0; x < width; x++)
567 {
568 unsigned short rgba = source[x];
569 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
570 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
571 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
572 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
573 }
574 }
575 }
576}
577
578void loadRGBA5551DataToBGRA(int width, int height, int depth,
579 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
580 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
581{
582 const unsigned short *source = NULL;
583 unsigned char *dest = NULL;
584
585 for (int z = 0; z < depth; z++)
586 {
587 for (int y = 0; y < height; y++)
588 {
589 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
590 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
591 for (int x = 0; x < width; x++)
592 {
593 unsigned short rgba = source[x];
594 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
595 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
596 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
597 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
598 }
599 }
600 }
601}
602void loadRGBA5551DataToRGBA(int width, int height, int depth,
603 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
604 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
605{
606 const unsigned short *source = NULL;
607 unsigned char *dest = NULL;
608
609 for (int z = 0; z < depth; z++)
610 {
611 for (int y = 0; y < height; y++)
612 {
613 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
614 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
615 for (int x = 0; x < width; x++)
616 {
617 unsigned short rgba = source[x];
618 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
619 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
620 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
621 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
622 }
623 }
624 }
625}
626
627void loadRGBAFloatDataToRGBA(int width, int height, int depth,
628 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
629 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
630{
631 const float *source = NULL;
632 float *dest = NULL;
633
634 for (int z = 0; z < depth; z++)
635 {
636 for (int y = 0; y < height; y++)
637 {
638 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
639 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
640 memcpy(dest, source, width * 16);
641 }
642 }
643}
644
645void loadRGBAHalfFloatDataToRGBA(int width, int height, int depth,
646 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
647 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
648{
649 const unsigned char *source = NULL;
650 unsigned char *dest = NULL;
651
652 for (int z = 0; z < depth; z++)
653 {
654 for (int y = 0; y < height; y++)
655 {
656 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
657 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
658 memcpy(dest, source, width * 8);
659 }
660 }
661}
662
663void loadBGRADataToBGRA(int width, int height, int depth,
664 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
665 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
666{
667 const unsigned char *source = NULL;
668 unsigned char *dest = NULL;
669
670 for (int z = 0; z < depth; z++)
671 {
672 for (int y = 0; y < height; y++)
673 {
674 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
675 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
676 memcpy(dest, source, width*4);
677 }
678 }
679}
680
681}