blob: 10debe8562507b4b9dd6a3aacdc13d88679cab31 [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
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000015void 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)
18{
19 const unsigned char *source = NULL;
20 unsigned char *dest = NULL;
21
22 for (int z = 0; z < depth; z++)
23 {
24 for (int y = 0; y < height; y++)
25 {
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++)
29 {
30 dest[4 * x + 0] = 0;
31 dest[4 * x + 1] = 0;
32 dest[4 * x + 2] = 0;
33 dest[4 * x + 3] = source[x];
34 }
35 }
36 }
37}
38
39void 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)
42{
43 const unsigned char *source = NULL;
44 unsigned char *dest = NULL;
45
46 for (int z = 0; z < depth; z++)
47 {
48 for (int y = 0; y < height; y++)
49 {
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);
53 }
54 }
55}
56
57void 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)
60{
61 const float *source = NULL;
62 float *dest = NULL;
63
64 for (int z = 0; z < depth; z++)
65 {
66 for (int y = 0; y < height; y++)
67 {
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++)
71 {
72 dest[4 * x + 0] = 0;
73 dest[4 * x + 1] = 0;
74 dest[4 * x + 2] = 0;
75 dest[4 * x + 3] = source[x];
76 }
77 }
78 }
79}
80
81void 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)
84{
85 const unsigned short *source = NULL;
86 unsigned short *dest = NULL;
87
88 for (int z = 0; z < depth; z++)
89 {
90 for (int y = 0; y < height; y++)
91 {
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++)
95 {
96 dest[4 * x + 0] = 0;
97 dest[4 * x + 1] = 0;
98 dest[4 * x + 2] = 0;
99 dest[4 * x + 3] = source[x];
100 }
101 }
102 }
103}
104
105void 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)
108{
109 const unsigned char *source = NULL;
110 unsigned char *dest = NULL;
111
112 for (int z = 0; z < depth; z++)
113 {
114 for (int y = 0; y < height; y++)
115 {
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);
119 }
120 }
121}
122
123void 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)
126{
127 const unsigned char *source = NULL;
128 unsigned char *dest = NULL;
129
130 for (int z = 0; z < depth; z++)
131 {
132 for (int y = 0; y < height; y++)
133 {
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++)
137 {
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;
142 }
143 }
144 }
145}
146
147void 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)
150{
151 const float *source = NULL;
152 float *dest = NULL;
153
154 for (int z = 0; z < depth; z++)
155 {
156 for (int y = 0; y < height; y++)
157 {
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++)
161 {
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;
166 }
167 }
168 }
169}
170
171void 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)
174{
175 const float *source = NULL;
176 float *dest = NULL;
177
178 for (int z = 0; z < depth; z++)
179 {
180 for (int y = 0; y < height; y++)
181 {
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++)
185 {
186 dest[3 * x + 0] = source[x];
187 dest[3 * x + 1] = source[x];
188 dest[3 * x + 2] = source[x];
189 }
190 }
191 }
192}
193
194void 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)
197{
198 const unsigned short *source = NULL;
199 unsigned short *dest = NULL;
200
201 for (int z = 0; z < depth; z++)
202 {
203 for (int y = 0; y < height; y++)
204 {
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++)
208 {
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] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
213 }
214 }
215 }
216}
217
218void 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)
221{
222 const unsigned char *source = NULL;
223 unsigned char *dest = NULL;
224
225 for (int z = 0; z < depth; z++)
226 {
227 for (int y = 0; y < height; y++)
228 {
229 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
230 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
231
232 memcpy(dest, source, width * 2);
233 }
234 }
235}
236
237void 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)
240{
241 const unsigned char *source = NULL;
242 unsigned char *dest = NULL;
243
244 for (int z = 0; z < depth; z++)
245 {
246 for (int y = 0; y < height; y++)
247 {
248 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
249 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
250
251 for (int x = 0; x < width; x++)
252 {
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];
257 }
258 }
259 }
260}
261
262void 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)
265{
266 const float *source = NULL;
267 float *dest = NULL;
268
269 for (int z = 0; z < depth; z++)
270 {
271 for (int y = 0; y < height; y++)
272 {
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++)
276 {
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];
281 }
282 }
283 }
284}
285
286void 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)
289{
290 const unsigned short *source = NULL;
291 unsigned short *dest = NULL;
292
293 for (int z = 0; z < depth; z++)
294 {
295 for (int y = 0; y < height; y++)
296 {
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++)
300 {
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];
305 }
306 }
307 }
308}
309
310void 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)
313{
314 const unsigned char *source = NULL;
315 unsigned char *dest = NULL;
316
317 for (int z = 0; z < depth; z++)
318 {
319 for (int y = 0; y < height; y++)
320 {
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++)
324 {
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;
329 }
330 }
331 }
332}
333
334void loadRGBUByteDataToRGBA(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)
337{
338 const unsigned char *source = NULL;
339 unsigned char *dest = NULL;
340
341 for (int z = 0; z < depth; z++)
342 {
343 for (int y = 0; y < height; y++)
344 {
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++)
348 {
349 dest[4 * x + 0] = source[x * 3 + 0];
350 dest[4 * x + 1] = source[x * 3 + 1];
351 dest[4 * x + 2] = source[x * 3 + 2];
352 dest[4 * x + 3] = 0xFF;
353 }
354 }
355 }
356}
357
358void loadRGB565DataToBGRA(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)
361{
362 const unsigned short *source = NULL;
363 unsigned char *dest = NULL;
364
365 for (int z = 0; z < depth; z++)
366 {
367 for (int y = 0; y < height; y++)
368 {
369 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
370 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
371 for (int x = 0; x < width; x++)
372 {
373 unsigned short rgba = source[x];
374 dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
375 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
376 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
377 dest[4 * x + 3] = 0xFF;
378 }
379 }
380 }
381}
382
383void loadRGB565DataToRGBA(int width, int height, int depth,
384 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
385 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
386{
387 const unsigned short *source = NULL;
388 unsigned char *dest = NULL;
389
390 for (int z = 0; z < depth; z++)
391 {
392 for (int y = 0; y < height; y++)
393 {
394 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
395 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
396 for (int x = 0; x < width; x++)
397 {
398 unsigned short rgba = source[x];
399 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
400 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
401 dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
402 dest[4 * x + 3] = 0xFF;
403 }
404 }
405 }
406}
407
408void loadRGBFloatDataToRGBA(int width, int height, int depth,
409 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
410 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
411{
412 const float *source = NULL;
413 float *dest = NULL;
414
415 for (int z = 0; z < depth; z++)
416 {
417 for (int y = 0; y < height; y++)
418 {
419 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
420 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
421 for (int x = 0; x < width; x++)
422 {
423 dest[4 * x + 0] = source[x * 3 + 0];
424 dest[4 * x + 1] = source[x * 3 + 1];
425 dest[4 * x + 2] = source[x * 3 + 2];
426 dest[4 * x + 3] = 1.0f;
427 }
428 }
429 }
430}
431
432void loadRGBFloatDataToNative(int width, int height, int depth,
433 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
434 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
435{
436 const float *source = NULL;
437 float *dest = NULL;
438
439 for (int z = 0; z < depth; z++)
440 {
441 for (int y = 0; y < height; y++)
442 {
443 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
444 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
445 memcpy(dest, source, width * 12);
446 }
447 }
448}
449
450void loadRGBHalfFloatDataToRGBA(int width, int height, int depth,
451 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
452 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
453{
454 const unsigned short *source = NULL;
455 unsigned short *dest = NULL;
456
457 for (int z = 0; z < depth; z++)
458 {
459 for (int y = 0; y < height; y++)
460 {
461 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
462 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
463 for (int x = 0; x < width; x++)
464 {
465 dest[4 * x + 0] = source[x * 3 + 0];
466 dest[4 * x + 1] = source[x * 3 + 1];
467 dest[4 * x + 2] = source[x * 3 + 2];
468 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
469 }
470 }
471 }
472}
473
474void loadRGBAUByteDataToBGRA(int width, int height, int depth,
475 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
476 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
477{
478 const unsigned int *source = NULL;
479 unsigned int *dest = NULL;
480
481 for (int z = 0; z < depth; z++)
482 {
483 for (int y = 0; y < height; y++)
484 {
485 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
486 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
487
488 for (int x = 0; x < width; x++)
489 {
490 unsigned int rgba = source[x];
491 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
492 }
493 }
494 }
495}
496
497void loadRGBAUByteDataToNative(int width, int height, int depth,
498 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
499 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
500{
501 const unsigned int *source = NULL;
502 unsigned int *dest = NULL;
503
504 for (int z = 0; z < depth; z++)
505 {
506 for (int y = 0; y < height; y++)
507 {
508 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
509 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
510
511 memcpy(dest, source, width * 4);
512 }
513 }
514}
515
516void loadRGBA4444DataToBGRA(int width, int height, int depth,
517 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
518 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
519{
520 const unsigned short *source = NULL;
521 unsigned char *dest = NULL;
522
523 for (int z = 0; z < depth; z++)
524 {
525 for (int y = 0; y < height; y++)
526 {
527 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
528 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
529 for (int x = 0; x < width; x++)
530 {
531 unsigned short rgba = source[x];
532 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
533 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
534 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
535 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
536 }
537 }
538 }
539}
540
541void loadRGBA4444DataToRGBA(int width, int height, int depth,
542 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
543 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
544{
545 const unsigned short *source = NULL;
546 unsigned char *dest = NULL;
547
548 for (int z = 0; z < depth; z++)
549 {
550 for (int y = 0; y < height; y++)
551 {
552 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
553 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
554 for (int x = 0; x < width; x++)
555 {
556 unsigned short rgba = source[x];
557 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
558 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
559 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
560 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
561 }
562 }
563 }
564}
565
566void loadRGBA5551DataToBGRA(int width, int height, int depth,
567 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
568 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
569{
570 const unsigned short *source = NULL;
571 unsigned char *dest = NULL;
572
573 for (int z = 0; z < depth; z++)
574 {
575 for (int y = 0; y < height; y++)
576 {
577 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
578 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
579 for (int x = 0; x < width; x++)
580 {
581 unsigned short rgba = source[x];
582 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
583 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
584 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
585 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
586 }
587 }
588 }
589}
590void loadRGBA5551DataToRGBA(int width, int height, int depth,
591 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
592 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
593{
594 const unsigned short *source = NULL;
595 unsigned char *dest = NULL;
596
597 for (int z = 0; z < depth; z++)
598 {
599 for (int y = 0; y < height; y++)
600 {
601 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
602 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
603 for (int x = 0; x < width; x++)
604 {
605 unsigned short rgba = source[x];
606 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
607 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
608 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
609 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
610 }
611 }
612 }
613}
614
615void loadRGBAFloatDataToRGBA(int width, int height, int depth,
616 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
617 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
618{
619 const float *source = NULL;
620 float *dest = NULL;
621
622 for (int z = 0; z < depth; z++)
623 {
624 for (int y = 0; y < height; y++)
625 {
626 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
627 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
628 memcpy(dest, source, width * 16);
629 }
630 }
631}
632
633void loadRGBAHalfFloatDataToRGBA(int width, int height, int depth,
634 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
635 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
636{
637 const unsigned char *source = NULL;
638 unsigned char *dest = NULL;
639
640 for (int z = 0; z < depth; z++)
641 {
642 for (int y = 0; y < height; y++)
643 {
644 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
645 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
646 memcpy(dest, source, width * 8);
647 }
648 }
649}
650
651void loadBGRADataToBGRA(int width, int height, int depth,
652 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
653 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
654{
655 const unsigned char *source = NULL;
656 unsigned char *dest = NULL;
657
658 for (int z = 0; z < depth; z++)
659 {
660 for (int y = 0; y < height; y++)
661 {
662 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
663 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
664 memcpy(dest, source, width*4);
665 }
666 }
667}
668
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000669void loadRGBA2101010ToNative(int width, int height, int depth,
670 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
671 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
672{
673 const unsigned int *source = NULL;
674 unsigned int *dest = NULL;
675
676 for (int z = 0; z < depth; z++)
677 {
678 for (int y = 0; y < height; y++)
679 {
680 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
681 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
682 memcpy(dest, source, width * sizeof(unsigned int));
683 }
684 }
685}
686
687void loadRGBA2101010ToRGBA(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)
690{
691 const unsigned int *source = NULL;
692 unsigned char *dest = NULL;
693
694 for (int z = 0; z < depth; z++)
695 {
696 for (int y = 0; y < height; y++)
697 {
698 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
699 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
700
701 for (int x = 0; x < width; x++)
702 {
703 unsigned int rgba = source[x];
704 dest[4 * x + 0] = (rgba & 0x000003FF) >> 2;
705 dest[4 * x + 1] = (rgba & 0x000FFC00) >> 12;
706 dest[4 * x + 2] = (rgba & 0x3FF00000) >> 22;
707 dest[4 * x + 3] = ((rgba & 0xC0000000) >> 30) * 0x55;
708 }
709 }
710 }
711}
712
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000713void loadRGBHalfFloatDataTo999E5(int width, int height, int depth,
714 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
715 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
716{
717 const unsigned short *source = NULL;
718 unsigned int *dest = NULL;
719
720 for (int z = 0; z < depth; z++)
721 {
722 for (int y = 0; y < height; y++)
723 {
724 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
725 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
726
727 for (int x = 0; x < width; x++)
728 {
729 dest[x] = gl::convertRGBFloatsTo999E5(gl::float16ToFloat32(source[x * 3 + 0]),
730 gl::float16ToFloat32(source[x * 3 + 1]),
731 gl::float16ToFloat32(source[x * 3 + 2]));
732 }
733 }
734 }
735}
736
737void loadRGBFloatDataTo999E5(int width, int height, int depth,
738 const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch,
739 void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch)
740{
741 const float *source = NULL;
742 unsigned int *dest = NULL;
743
744 for (int z = 0; z < depth; z++)
745 {
746 for (int y = 0; y < height; y++)
747 {
748 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
749 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
750
751 for (int x = 0; x < width; x++)
752 {
753 dest[x] = gl::convertRGBFloatsTo999E5(source[x * 3 + 0], source[x * 3 + 1], source[x * 3 + 2]);
754 }
755 }
756 }
757}
758
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000759}