1 #include "precompiled.h"
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.
8 // loadimage.cpp: Defines image loading functions.
10 #include "libGLESv2/renderer/loadimage.h"
15 void loadAlphaDataToBGRA(int width, int height, int depth,
16 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
17 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
19 const unsigned char *source = NULL;
20 unsigned char *dest = NULL;
22 for (int z = 0; z < depth; z++)
24 for (int y = 0; y < height; y++)
26 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
27 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
28 for (int x = 0; x < width; x++)
33 dest[4 * x + 3] = source[x];
39 void loadAlphaDataToNative(int width, int height, int depth,
40 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
41 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
43 const unsigned char *source = NULL;
44 unsigned char *dest = NULL;
46 for (int z = 0; z < depth; z++)
48 for (int y = 0; y < height; y++)
50 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
51 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
52 memcpy(dest, source, width);
57 void loadAlphaFloatDataToRGBA(int width, int height, int depth,
58 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
59 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
61 const float *source = NULL;
64 for (int z = 0; z < depth; z++)
66 for (int y = 0; y < height; y++)
68 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
69 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
70 for (int x = 0; x < width; x++)
75 dest[4 * x + 3] = source[x];
81 void loadAlphaHalfFloatDataToRGBA(int width, int height, int depth,
82 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
83 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
85 const unsigned short *source = NULL;
86 unsigned short *dest = NULL;
88 for (int z = 0; z < depth; z++)
90 for (int y = 0; y < height; y++)
92 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
93 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
94 for (int x = 0; x < width; x++)
99 dest[4 * x + 3] = source[x];
105 void loadLuminanceDataToNative(int width, int height, int depth,
106 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
107 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
109 const unsigned char *source = NULL;
110 unsigned char *dest = NULL;
112 for (int z = 0; z < depth; z++)
114 for (int y = 0; y < height; y++)
116 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
117 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
118 memcpy(dest, source, width);
123 void loadLuminanceDataToBGRA(int width, int height, int depth,
124 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
125 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
127 const unsigned char *source = NULL;
128 unsigned char *dest = NULL;
130 for (int z = 0; z < depth; z++)
132 for (int y = 0; y < height; y++)
134 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
135 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
136 for (int x = 0; x < width; x++)
138 dest[4 * x + 0] = source[x];
139 dest[4 * x + 1] = source[x];
140 dest[4 * x + 2] = source[x];
141 dest[4 * x + 3] = 0xFF;
147 void loadLuminanceFloatDataToRGBA(int width, int height, int depth,
148 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
149 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
151 const float *source = NULL;
154 for (int z = 0; z < depth; z++)
156 for (int y = 0; y < height; y++)
158 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
159 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
160 for (int x = 0; x < width; x++)
162 dest[4 * x + 0] = source[x];
163 dest[4 * x + 1] = source[x];
164 dest[4 * x + 2] = source[x];
165 dest[4 * x + 3] = 1.0f;
171 void loadLuminanceFloatDataToRGB(int width, int height, int depth,
172 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
173 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
175 const float *source = NULL;
178 for (int z = 0; z < depth; z++)
180 for (int y = 0; y < height; y++)
182 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
183 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
184 for (int x = 0; x < width; x++)
186 dest[3 * x + 0] = source[x];
187 dest[3 * x + 1] = source[x];
188 dest[3 * x + 2] = source[x];
194 void loadLuminanceHalfFloatDataToRGBA(int width, int height, int depth,
195 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
196 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
198 const unsigned short *source = NULL;
199 unsigned short *dest = NULL;
201 for (int z = 0; z < depth; z++)
203 for (int y = 0; y < height; y++)
205 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
206 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
207 for (int x = 0; x < width; x++)
209 dest[4 * x + 0] = source[x];
210 dest[4 * x + 1] = source[x];
211 dest[4 * x + 2] = source[x];
212 dest[4 * x + 3] = gl::Float16One;
218 void loadLuminanceAlphaDataToNative(int width, int height, int depth,
219 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
220 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
222 const unsigned char *source = NULL;
223 unsigned char *dest = NULL;
225 for (int z = 0; z < depth; z++)
227 for (int y = 0; y < height; y++)
229 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
230 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
232 memcpy(dest, source, width * 2);
237 void loadLuminanceAlphaDataToBGRA(int width, int height, int depth,
238 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
239 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
241 const unsigned char *source = NULL;
242 unsigned char *dest = NULL;
244 for (int z = 0; z < depth; z++)
246 for (int y = 0; y < height; y++)
248 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
249 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
251 for (int x = 0; x < width; x++)
253 dest[4 * x + 0] = source[2*x+0];
254 dest[4 * x + 1] = source[2*x+0];
255 dest[4 * x + 2] = source[2*x+0];
256 dest[4 * x + 3] = source[2*x+1];
262 void loadLuminanceAlphaFloatDataToRGBA(int width, int height, int depth,
263 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
264 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
266 const float *source = NULL;
269 for (int z = 0; z < depth; z++)
271 for (int y = 0; y < height; y++)
273 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
274 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
275 for (int x = 0; x < width; x++)
277 dest[4 * x + 0] = source[2*x+0];
278 dest[4 * x + 1] = source[2*x+0];
279 dest[4 * x + 2] = source[2*x+0];
280 dest[4 * x + 3] = source[2*x+1];
286 void loadLuminanceAlphaHalfFloatDataToRGBA(int width, int height, int depth,
287 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
288 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
290 const unsigned short *source = NULL;
291 unsigned short *dest = NULL;
293 for (int z = 0; z < depth; z++)
295 for (int y = 0; y < height; y++)
297 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
298 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
299 for (int x = 0; x < width; x++)
301 dest[4 * x + 0] = source[2*x+0];
302 dest[4 * x + 1] = source[2*x+0];
303 dest[4 * x + 2] = source[2*x+0];
304 dest[4 * x + 3] = source[2*x+1];
310 void loadRGBUByteDataToBGRX(int width, int height, int depth,
311 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
312 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
314 const unsigned char *source = NULL;
315 unsigned char *dest = NULL;
317 for (int z = 0; z < depth; z++)
319 for (int y = 0; y < height; y++)
321 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
322 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
323 for (int x = 0; x < width; x++)
325 dest[4 * x + 0] = source[x * 3 + 2];
326 dest[4 * x + 1] = source[x * 3 + 1];
327 dest[4 * x + 2] = source[x * 3 + 0];
328 dest[4 * x + 3] = 0xFF;
334 void loadRGUByteDataToBGRX(int width, int height, int depth,
335 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
336 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
338 const unsigned char *source = NULL;
339 unsigned char *dest = NULL;
341 for (int z = 0; z < depth; z++)
343 for (int y = 0; y < height; y++)
345 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
346 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
347 for (int x = 0; x < width; x++)
349 dest[4 * x + 0] = 0x00;
350 dest[4 * x + 1] = source[x * 2 + 1];
351 dest[4 * x + 2] = source[x * 2 + 0];
352 dest[4 * x + 3] = 0xFF;
358 void loadRUByteDataToBGRX(int width, int height, int depth,
359 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
360 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
362 const unsigned char *source = NULL;
363 unsigned char *dest = NULL;
365 for (int z = 0; z < depth; z++)
367 for (int y = 0; y < height; y++)
369 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
370 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
371 for (int x = 0; x < width; x++)
373 dest[4 * x + 0] = 0x00;
374 dest[4 * x + 1] = 0x00;
375 dest[4 * x + 2] = source[x];
376 dest[4 * x + 3] = 0xFF;
382 void loadRGBUByteDataToRGBA(int width, int height, int depth,
383 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
384 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
386 const unsigned char *source = NULL;
387 unsigned char *dest = NULL;
389 for (int z = 0; z < depth; z++)
391 for (int y = 0; y < height; y++)
393 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
394 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
395 for (int x = 0; x < width; x++)
397 dest[4 * x + 0] = source[x * 3 + 0];
398 dest[4 * x + 1] = source[x * 3 + 1];
399 dest[4 * x + 2] = source[x * 3 + 2];
400 dest[4 * x + 3] = 0xFF;
406 void loadRGBSByteDataToRGBA(int width, int height, int depth,
407 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
408 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
410 const char *source = NULL;
413 for (int z = 0; z < depth; z++)
415 for (int y = 0; y < height; y++)
417 source = offsetDataPointer<char>(input, y, z, inputRowPitch, inputDepthPitch);
418 dest = offsetDataPointer<char>(output, y, z, outputRowPitch, outputDepthPitch);
419 for (int x = 0; x < width; x++)
421 dest[4 * x + 0] = source[x * 3 + 0];
422 dest[4 * x + 1] = source[x * 3 + 1];
423 dest[4 * x + 2] = source[x * 3 + 2];
424 dest[4 * x + 3] = 0x7F;
430 void loadRGB565DataToBGRA(int width, int height, int depth,
431 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
432 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
434 const unsigned short *source = NULL;
435 unsigned char *dest = NULL;
437 for (int z = 0; z < depth; z++)
439 for (int y = 0; y < height; y++)
441 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
442 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
443 for (int x = 0; x < width; x++)
445 unsigned short rgba = source[x];
446 dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
447 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
448 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
449 dest[4 * x + 3] = 0xFF;
455 void loadRGB565DataToRGBA(int width, int height, int depth,
456 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
457 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
459 const unsigned short *source = NULL;
460 unsigned char *dest = NULL;
462 for (int z = 0; z < depth; z++)
464 for (int y = 0; y < height; y++)
466 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
467 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
468 for (int x = 0; x < width; x++)
470 unsigned short rgba = source[x];
471 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
472 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
473 dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
474 dest[4 * x + 3] = 0xFF;
480 void loadRGBFloatDataToRGBA(int width, int height, int depth,
481 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
482 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
484 const float *source = NULL;
487 for (int z = 0; z < depth; z++)
489 for (int y = 0; y < height; y++)
491 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
492 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
493 for (int x = 0; x < width; x++)
495 dest[4 * x + 0] = source[x * 3 + 0];
496 dest[4 * x + 1] = source[x * 3 + 1];
497 dest[4 * x + 2] = source[x * 3 + 2];
498 dest[4 * x + 3] = 1.0f;
504 void loadRGBFloatDataToNative(int width, int height, int depth,
505 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
506 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
508 const float *source = NULL;
511 for (int z = 0; z < depth; z++)
513 for (int y = 0; y < height; y++)
515 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
516 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
517 memcpy(dest, source, width * 12);
522 void loadRGBHalfFloatDataToRGBA(int width, int height, int depth,
523 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
524 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
526 const unsigned short *source = NULL;
527 unsigned short *dest = NULL;
529 for (int z = 0; z < depth; z++)
531 for (int y = 0; y < height; y++)
533 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
534 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
535 for (int x = 0; x < width; x++)
537 dest[4 * x + 0] = source[x * 3 + 0];
538 dest[4 * x + 1] = source[x * 3 + 1];
539 dest[4 * x + 2] = source[x * 3 + 2];
540 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
546 void loadRGBAUByteDataToBGRA(int width, int height, int depth,
547 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
548 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
550 const unsigned int *source = NULL;
551 unsigned int *dest = NULL;
553 for (int z = 0; z < depth; z++)
555 for (int y = 0; y < height; y++)
557 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
558 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
560 for (int x = 0; x < width; x++)
562 unsigned int rgba = source[x];
563 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
569 void loadRGBAUByteDataToNative(int width, int height, int depth,
570 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
571 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
573 const unsigned int *source = NULL;
574 unsigned int *dest = NULL;
576 for (int z = 0; z < depth; z++)
578 for (int y = 0; y < height; y++)
580 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
581 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
583 memcpy(dest, source, width * 4);
588 void loadRGBA4444DataToBGRA(int width, int height, int depth,
589 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
590 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
592 const unsigned short *source = NULL;
593 unsigned char *dest = NULL;
595 for (int z = 0; z < depth; z++)
597 for (int y = 0; y < height; y++)
599 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
600 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
601 for (int x = 0; x < width; x++)
603 unsigned short rgba = source[x];
604 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
605 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
606 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
607 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
613 void loadRGBA4444DataToRGBA(int width, int height, int depth,
614 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
615 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
617 const unsigned short *source = NULL;
618 unsigned char *dest = NULL;
620 for (int z = 0; z < depth; z++)
622 for (int y = 0; y < height; y++)
624 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
625 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
626 for (int x = 0; x < width; x++)
628 unsigned short rgba = source[x];
629 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
630 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
631 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
632 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
638 void loadRGBA5551DataToBGRA(int width, int height, int depth,
639 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
640 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
642 const unsigned short *source = NULL;
643 unsigned char *dest = NULL;
645 for (int z = 0; z < depth; z++)
647 for (int y = 0; y < height; y++)
649 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
650 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
651 for (int x = 0; x < width; x++)
653 unsigned short rgba = source[x];
654 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
655 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
656 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
657 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
662 void loadRGBA5551DataToRGBA(int width, int height, int depth,
663 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
664 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
666 const unsigned short *source = NULL;
667 unsigned char *dest = NULL;
669 for (int z = 0; z < depth; z++)
671 for (int y = 0; y < height; y++)
673 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
674 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
675 for (int x = 0; x < width; x++)
677 unsigned short rgba = source[x];
678 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
679 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
680 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
681 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
687 void loadRGBAFloatDataToRGBA(int width, int height, int depth,
688 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
689 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
691 const float *source = NULL;
694 for (int z = 0; z < depth; z++)
696 for (int y = 0; y < height; y++)
698 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
699 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
700 memcpy(dest, source, width * 16);
705 void loadRGBAHalfFloatDataToRGBA(int width, int height, int depth,
706 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
707 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
709 const unsigned char *source = NULL;
710 unsigned char *dest = NULL;
712 for (int z = 0; z < depth; z++)
714 for (int y = 0; y < height; y++)
716 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
717 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
718 memcpy(dest, source, width * 8);
723 void loadBGRADataToBGRA(int width, int height, int depth,
724 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
725 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
727 const unsigned char *source = NULL;
728 unsigned char *dest = NULL;
730 for (int z = 0; z < depth; z++)
732 for (int y = 0; y < height; y++)
734 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
735 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
736 memcpy(dest, source, width*4);
741 void loadRGBA2101010ToNative(int width, int height, int depth,
742 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
743 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
745 const unsigned int *source = NULL;
746 unsigned int *dest = NULL;
748 for (int z = 0; z < depth; z++)
750 for (int y = 0; y < height; y++)
752 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
753 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
754 memcpy(dest, source, width * sizeof(unsigned int));
759 void loadRGBA2101010ToRGBA(int width, int height, int depth,
760 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
761 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
763 const unsigned int *source = NULL;
764 unsigned char *dest = NULL;
766 for (int z = 0; z < depth; z++)
768 for (int y = 0; y < height; y++)
770 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
771 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
773 for (int x = 0; x < width; x++)
775 unsigned int rgba = source[x];
776 dest[4 * x + 0] = (rgba & 0x000003FF) >> 2;
777 dest[4 * x + 1] = (rgba & 0x000FFC00) >> 12;
778 dest[4 * x + 2] = (rgba & 0x3FF00000) >> 22;
779 dest[4 * x + 3] = ((rgba & 0xC0000000) >> 30) * 0x55;
785 void loadRGBHalfFloatDataTo999E5(int width, int height, int depth,
786 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
787 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
789 const unsigned short *source = NULL;
790 unsigned int *dest = NULL;
792 for (int z = 0; z < depth; z++)
794 for (int y = 0; y < height; y++)
796 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
797 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
799 for (int x = 0; x < width; x++)
801 dest[x] = gl::convertRGBFloatsTo999E5(gl::float16ToFloat32(source[x * 3 + 0]),
802 gl::float16ToFloat32(source[x * 3 + 1]),
803 gl::float16ToFloat32(source[x * 3 + 2]));
809 void loadRGBFloatDataTo999E5(int width, int height, int depth,
810 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
811 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
813 const float *source = NULL;
814 unsigned int *dest = NULL;
816 for (int z = 0; z < depth; z++)
818 for (int y = 0; y < height; y++)
820 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
821 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
823 for (int x = 0; x < width; x++)
825 dest[x] = gl::convertRGBFloatsTo999E5(source[x * 3 + 0], source[x * 3 + 1], source[x * 3 + 2]);
831 void loadRGBHalfFloatDataTo111110Float(int width, int height, int depth,
832 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
833 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
835 const unsigned short *source = NULL;
836 unsigned int *dest = NULL;
838 for (int z = 0; z < depth; z++)
840 for (int y = 0; y < height; y++)
842 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
843 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
845 for (int x = 0; x < width; x++)
847 dest[x] = (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 0])) << 0) |
848 (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 1])) << 11) |
849 (gl::float32ToFloat10(gl::float16ToFloat32(source[x * 3 + 2])) << 22);
855 void loadRGBFloatDataTo111110Float(int width, int height, int depth,
856 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
857 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
859 const float *source = NULL;
860 unsigned int *dest = NULL;
862 for (int z = 0; z < depth; z++)
864 for (int y = 0; y < height; y++)
866 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
867 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
869 for (int x = 0; x < width; x++)
871 dest[x] = (gl::float32ToFloat11(source[x * 3 + 0]) << 0) |
872 (gl::float32ToFloat11(source[x * 3 + 1]) << 11) |
873 (gl::float32ToFloat10(source[x * 3 + 2]) << 22);
880 void loadG8R24DataToR24G8(int width, int height, int depth,
881 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
882 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
884 const unsigned int *source = NULL;
885 unsigned int *dest = NULL;
887 for (int z = 0; z < depth; z++)
889 for (int y = 0; y < height; y++)
891 source = offsetDataPointer<const unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
892 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
894 for (int x = 0; x < width; x++)
896 unsigned int d = source[x] >> 8;
897 unsigned int s = source[x] & 0xFF;
898 dest[x] = d | (s << 24);
904 void loadFloatRGBDataToHalfFloatRGBA(int width, int height, int depth,
905 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
906 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
908 const float *source = NULL;
909 unsigned short *dest = NULL;
911 for (int z = 0; z < depth; z++)
913 for (int y = 0; y < height; y++)
915 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
916 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
918 for (int x = 0; x < width; x++)
920 dest[x * 4 + 0] = gl::float32ToFloat16(source[x * 3 + 0]);
921 dest[x * 4 + 1] = gl::float32ToFloat16(source[x * 3 + 1]);
922 dest[x * 4 + 2] = gl::float32ToFloat16(source[x * 3 + 2]);
923 dest[x * 4 + 3] = gl::Float16One;
929 void loadUintDataToUshort(int width, int height, int depth,
930 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
931 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
933 const unsigned int *source = NULL;
934 unsigned short *dest = NULL;
936 for (int z = 0; z < depth; z++)
938 for (int y = 0; y < height; y++)
940 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
941 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
943 for (int x = 0; x < width; x++)
945 dest[x] = source[x] >> 16;