Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / state_trackers / vega / vg_translate.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 **************************************************************************/
26
27 #include "vg_translate.h"
28
29 #include "pipe/p_format.h"
30 #include "util/u_pack_color.h"
31
32 void _vega_pack_rgba_span_float(struct vg_context *ctx,
33 VGuint n, VGfloat rgba[][4],
34 VGImageFormat dstFormat,
35 void *dstAddr)
36 {
37 VGint i;
38
39 switch (dstFormat) {
40 case VG_sRGBX_8888: {
41 VGint *dst = (VGint *)dstAddr;
42 for (i = 0; i < n; ++i) {
43 VGubyte r, g, b ,a;
44 r = float_to_ubyte(rgba[i][0]);
45 g = float_to_ubyte(rgba[i][1]);
46 b = float_to_ubyte(rgba[i][2]);
47 a = 255;
48 dst[i] = r << 24 | g << 16 | b << 8 | a;
49 }
50 return;
51 }
52 break;
53 case VG_sRGBA_8888: {
54 VGint *dst = (VGint *)dstAddr;
55 for (i = 0; i < n; ++i) {
56 VGubyte r, g, b ,a;
57 r = float_to_ubyte(rgba[i][0]);
58 g = float_to_ubyte(rgba[i][1]);
59 b = float_to_ubyte(rgba[i][2]);
60 a = float_to_ubyte(rgba[i][3]);
61 dst[i] = r << 24 | g << 16 | b << 8 | a;
62 }
63 return;
64 }
65 break;
66 case VG_sRGBA_8888_PRE: {
67 VGint *dst = (VGint *)dstAddr;
68 for (i = 0; i < n; ++i) {
69 VGubyte r, g, b ,a;
70 r = float_to_ubyte(rgba[i][0]);
71 g = float_to_ubyte(rgba[i][1]);
72 b = float_to_ubyte(rgba[i][2]);
73 a = float_to_ubyte(rgba[i][3]);
74 dst[i] = r << 24 | g << 16 | b << 8 | a;
75 }
76 return;
77 }
78 break;
79 case VG_sRGB_565: {
80 VGshort *dst = (VGshort *)dstAddr;
81 for (i = 0; i < n; ++i) {
82 VGubyte r, g, b;
83 r = float_to_ubyte(rgba[i][0]);
84 g = float_to_ubyte(rgba[i][1]);
85 b = float_to_ubyte(rgba[i][2]);
86 r = (r / 255.0) * 32;
87 g = (g / 255.0) * 32;
88 b = (b / 255.0) * 32;
89
90 dst[i] = b | g << 5 | r << 11;
91 }
92 return;
93 }
94 break;
95 case VG_sRGBA_5551: {
96 VGshort *dst = (VGshort *)dstAddr;
97 for (i = 0; i < n; ++i) {
98 VGubyte r, g, b, a;
99 r = float_to_ubyte(rgba[i][0]);
100 g = float_to_ubyte(rgba[i][1]);
101 b = float_to_ubyte(rgba[i][2]);
102 a = float_to_ubyte(rgba[i][3]);
103 r = (r / 255.0) * 32;
104 g = (g / 255.0) * 32;
105 b = (b / 255.0) * 32;
106 a = (a / 255.0);
107
108 dst[i] = a | b << 1 | g << 6 | r << 11;
109 }
110 return;
111 }
112 break;
113 case VG_sRGBA_4444: {
114 VGshort *dst = (VGshort *)dstAddr;
115 for (i = 0; i < n; ++i) {
116 VGubyte r, g, b, a;
117 r = float_to_ubyte(rgba[i][0]);
118 g = float_to_ubyte(rgba[i][1]);
119 b = float_to_ubyte(rgba[i][2]);
120 a = float_to_ubyte(rgba[i][3]);
121 r = (r / 255.0) * 16;
122 g = (g / 255.0) * 16;
123 b = (b / 255.0) * 16;
124 a = (a / 255.0) * 16;
125
126 dst[i] = a | b << 4 | g << 8 | r << 12;
127 }
128 return;
129 }
130 break;
131 case VG_sL_8: {
132 VGubyte *dst = (VGubyte *)dstAddr;
133 for (i = 0; i < n; ++i) {
134 VGubyte r, g, b, a;
135 r = float_to_ubyte(rgba[i][0]);
136 g = float_to_ubyte(rgba[i][1]);
137 b = float_to_ubyte(rgba[i][2]);
138 a = float_to_ubyte(rgba[i][3]);
139
140 dst[i] = a;
141 }
142 return;
143 }
144 break;
145 case VG_lRGBX_8888: {
146 VGint *dst = (VGint *)dstAddr;
147 for (i = 0; i < n; ++i) {
148 VGubyte r, g, b ,a;
149 r = float_to_ubyte(rgba[i][0]);
150 g = float_to_ubyte(rgba[i][1]);
151 b = float_to_ubyte(rgba[i][2]);
152 a = 255;
153 dst[i] = r << 24 | g << 16 | b << 8 | a;
154 }
155 return;
156 }
157 break;
158 case VG_lRGBA_8888: {
159 VGint *dst = (VGint *)dstAddr;
160 for (i = 0; i < n; ++i) {
161 VGubyte r, g, b ,a;
162 r = float_to_ubyte(rgba[i][0]);
163 g = float_to_ubyte(rgba[i][1]);
164 b = float_to_ubyte(rgba[i][2]);
165 a = float_to_ubyte(rgba[i][3]);
166 dst[i] = r << 24 | g << 16 | b << 8 | a;
167 }
168 return;
169 }
170 case VG_lRGBA_8888_PRE: {
171 VGint *dst = (VGint *)dstAddr;
172 for (i = 0; i < n; ++i) {
173 VGubyte r, g, b ,a;
174 r = float_to_ubyte(rgba[i][0]);
175 g = float_to_ubyte(rgba[i][1]);
176 b = float_to_ubyte(rgba[i][2]);
177 a = float_to_ubyte(rgba[i][3]);
178 dst[i] = r << 24 | g << 16 | b << 8 | a;
179 }
180 return;
181 }
182 break;
183 case VG_lL_8: {
184 VGubyte *dst = (VGubyte *)dstAddr;
185 for (i = 0; i < n; ++i) {
186 VGubyte r, g, b ,a;
187 r = float_to_ubyte(rgba[i][0]);
188 g = float_to_ubyte(rgba[i][1]);
189 b = float_to_ubyte(rgba[i][2]);
190 a = float_to_ubyte(rgba[i][3]);
191 dst[i] = a;
192 }
193 return;
194 }
195 break;
196 case VG_A_8: {
197 VGubyte *dst = (VGubyte *)dstAddr;
198 for (i = 0; i < n; ++i) {
199 VGubyte r, g, b, a;
200 r = float_to_ubyte(rgba[i][0]);
201 g = float_to_ubyte(rgba[i][1]);
202 b = float_to_ubyte(rgba[i][2]);
203 a = float_to_ubyte(rgba[i][3]);
204
205 dst[i] = a;
206 }
207 return;
208 }
209 break;
210 case VG_BW_1: {
211 VGshort *dst = (VGshort *)dstAddr;
212 for (i = 0; i < n; ++i) {
213 VGubyte r, g, b, a;
214 VGubyte res;
215 r = float_to_ubyte(rgba[i][0]);
216 g = float_to_ubyte(rgba[i][1]);
217 b = float_to_ubyte(rgba[i][2]);
218 a = float_to_ubyte(rgba[i][3]);
219
220 res = (r + g + b + a)/4;
221 dst[i] = (res & (128));
222 }
223 return;
224 }
225 break;
226 #ifdef OPENVG_VERSION_1_1
227 case VG_A_1: {
228 VGshort *dst = (VGshort *)dstAddr;
229 for (i = 0; i < n; ++i) {
230 VGubyte r, g, b, a;
231 r = float_to_ubyte(rgba[i][0]);
232 g = float_to_ubyte(rgba[i][1]);
233 b = float_to_ubyte(rgba[i][2]);
234 a = float_to_ubyte(rgba[i][3]);
235
236 dst[i] = (a & (128));
237 }
238 return;
239 }
240 break;
241 case VG_A_4: {
242 VGshort *dst = (VGshort *)dstAddr;
243 for (i = 0; i < n; ++i) {
244 VGubyte r, g, b, a;
245 VGubyte res;
246 r = float_to_ubyte(rgba[i][0]);
247 g = float_to_ubyte(rgba[i][1]);
248 b = float_to_ubyte(rgba[i][2]);
249 a = float_to_ubyte(rgba[i][3]);
250
251 res = a/4;
252 dst[i] = (res & (128));
253 }
254 return;
255 }
256 break;
257 #endif
258 case VG_sXRGB_8888:
259 break;
260 case VG_sARGB_8888: {
261 VGint *dst = (VGint *)dstAddr;
262 for (i = 0; i < n; ++i) {
263 VGubyte r, g, b ,a;
264 r = float_to_ubyte(rgba[i][0]);
265 g = float_to_ubyte(rgba[i][1]);
266 b = float_to_ubyte(rgba[i][2]);
267 a = float_to_ubyte(rgba[i][3]);
268 dst[i] = a << 24 | r << 16 | g << 8 | b;
269 }
270 return;
271 }
272 break;
273 case VG_sARGB_8888_PRE: {
274 VGint *dst = (VGint *)dstAddr;
275 for (i = 0; i < n; ++i) {
276 VGubyte r, g, b ,a;
277 r = float_to_ubyte(rgba[i][0]);
278 g = float_to_ubyte(rgba[i][1]);
279 b = float_to_ubyte(rgba[i][2]);
280 a = float_to_ubyte(rgba[i][3]);
281 dst[i] = a << 24 | r << 16 | g << 8 | b;
282 }
283 return;
284 }
285 break;
286 case VG_sARGB_1555:
287 break;
288 case VG_sARGB_4444:
289 break;
290 case VG_lXRGB_8888:
291 break;
292 case VG_lARGB_8888: {
293 VGint *dst = (VGint *)dstAddr;
294 for (i = 0; i < n; ++i) {
295 VGubyte r, g, b ,a;
296 r = float_to_ubyte(rgba[i][0]);
297 g = float_to_ubyte(rgba[i][1]);
298 b = float_to_ubyte(rgba[i][2]);
299 a = float_to_ubyte(rgba[i][3]);
300 dst[i] = a << 24 | r << 16 | g << 8 | b;
301 }
302 return;
303 }
304 break;
305 case VG_lARGB_8888_PRE: {
306 VGint *dst = (VGint *)dstAddr;
307 for (i = 0; i < n; ++i) {
308 VGubyte r, g, b ,a;
309 r = float_to_ubyte(rgba[i][0]);
310 g = float_to_ubyte(rgba[i][1]);
311 b = float_to_ubyte(rgba[i][2]);
312 a = float_to_ubyte(rgba[i][3]);
313 dst[i] = a << 24 | r << 16 | g << 8 | b;
314 }
315 return;
316 }
317 break;
318 case VG_sBGRX_8888: {
319 VGint *dst = (VGint *)dstAddr;
320 for (i = 0; i < n; ++i) {
321 VGubyte r, g, b ,a;
322 r = float_to_ubyte(rgba[i][0]);
323 g = float_to_ubyte(rgba[i][1]);
324 b = float_to_ubyte(rgba[i][2]);
325 a = 0xff;
326 dst[i] = b << 24 | g << 16 | r << 8 | a;
327 }
328 return;
329 }
330 break;
331 case VG_sBGRA_8888: {
332 VGint *dst = (VGint *)dstAddr;
333 for (i = 0; i < n; ++i) {
334 VGubyte r, g, b ,a;
335 r = float_to_ubyte(rgba[i][0]);
336 g = float_to_ubyte(rgba[i][1]);
337 b = float_to_ubyte(rgba[i][2]);
338 a = float_to_ubyte(rgba[i][3]);
339 dst[i] = b << 24 | g << 16 | r << 8 | a;
340 }
341 return;
342 }
343 break;
344 case VG_sBGRA_8888_PRE: {
345 VGint *dst = (VGint *)dstAddr;
346 for (i = 0; i < n; ++i) {
347 VGubyte r, g, b ,a;
348 r = float_to_ubyte(rgba[i][0]);
349 g = float_to_ubyte(rgba[i][1]);
350 b = float_to_ubyte(rgba[i][2]);
351 a = float_to_ubyte(rgba[i][3]);
352 dst[i] = b << 24 | g << 16 | r << 8 | a;
353 }
354 return;
355 }
356 break;
357 case VG_sBGR_565:
358 break;
359 case VG_sBGRA_5551:
360 break;
361 case VG_sBGRA_4444:
362 break;
363 case VG_lBGRX_8888: {
364 VGint *dst = (VGint *)dstAddr;
365 for (i = 0; i < n; ++i) {
366 VGubyte r, g, b ,a;
367 r = float_to_ubyte(rgba[i][0]);
368 g = float_to_ubyte(rgba[i][1]);
369 b = float_to_ubyte(rgba[i][2]);
370 a = 0xff;
371 dst[i] = b << 24 | g << 16 | r << 8 | a;
372 }
373 return;
374 }
375 break;
376 case VG_lBGRA_8888: {
377 VGint *dst = (VGint *)dstAddr;
378 for (i = 0; i < n; ++i) {
379 VGubyte r, g, b ,a;
380 r = float_to_ubyte(rgba[i][0]);
381 g = float_to_ubyte(rgba[i][1]);
382 b = float_to_ubyte(rgba[i][2]);
383 a = float_to_ubyte(rgba[i][3]);
384 dst[i] = b << 24 | g << 16 | r << 8 | a;
385 }
386 return;
387 }
388 break;
389 case VG_lBGRA_8888_PRE: {
390 VGint *dst = (VGint *)dstAddr;
391 for (i = 0; i < n; ++i) {
392 VGubyte r, g, b ,a;
393 r = float_to_ubyte(rgba[i][0]);
394 g = float_to_ubyte(rgba[i][1]);
395 b = float_to_ubyte(rgba[i][2]);
396 a = float_to_ubyte(rgba[i][3]);
397 dst[i] = b << 24 | g << 16 | r << 8 | a;
398 }
399 return;
400 }
401 break;
402 case VG_sXBGR_8888:
403 break;
404 case VG_sABGR_8888: {
405 VGint *dst = (VGint *)dstAddr;
406 for (i = 0; i < n; ++i) {
407 VGubyte r, g, b ,a;
408 r = float_to_ubyte(rgba[i][0]);
409 g = float_to_ubyte(rgba[i][1]);
410 b = float_to_ubyte(rgba[i][2]);
411 a = float_to_ubyte(rgba[i][3]);
412 dst[i] = a << 24 | b << 16 | g << 8 | r;
413 }
414 return;
415 }
416 break;
417 case VG_sABGR_8888_PRE: {
418 VGint *dst = (VGint *)dstAddr;
419 for (i = 0; i < n; ++i) {
420 VGubyte r, g, b ,a;
421 r = float_to_ubyte(rgba[i][0]);
422 g = float_to_ubyte(rgba[i][1]);
423 b = float_to_ubyte(rgba[i][2]);
424 a = float_to_ubyte(rgba[i][3]);
425 dst[i] = a << 24 | b << 16 | g << 8 | r;
426 }
427 return;
428 }
429 break;
430 case VG_sABGR_1555:
431 break;
432 case VG_sABGR_4444:
433 break;
434 case VG_lXBGR_8888:
435 break;
436 case VG_lABGR_8888: {
437 VGint *dst = (VGint *)dstAddr;
438 for (i = 0; i < n; ++i) {
439 VGubyte r, g, b ,a;
440 r = float_to_ubyte(rgba[i][0]);
441 g = float_to_ubyte(rgba[i][1]);
442 b = float_to_ubyte(rgba[i][2]);
443 a = float_to_ubyte(rgba[i][3]);
444 dst[i] = a << 24 | b << 16 | g << 8 | r;
445 }
446 return;
447 }
448 break;
449 case VG_lABGR_8888_PRE: {
450 VGint *dst = (VGint *)dstAddr;
451 for (i = 0; i < n; ++i) {
452 VGubyte r, g, b ,a;
453 r = float_to_ubyte(rgba[i][0]);
454 g = float_to_ubyte(rgba[i][1]);
455 b = float_to_ubyte(rgba[i][2]);
456 a = float_to_ubyte(rgba[i][3]);
457 dst[i] = a << 24 | b << 16 | g << 8 | r;
458 }
459 return;
460 }
461 break;
462 default:
463 assert(!"Unknown ReadPixels format");
464 break;
465 }
466 assert(!"Not implemented ReadPixels format");
467 }
468
469 void _vega_unpack_float_span_rgba(struct vg_context *ctx,
470 VGuint n,
471 VGuint offset,
472 const void * data,
473 VGImageFormat dataFormat,
474 VGfloat rgba[][4])
475 {
476 VGint i;
477
478 switch (dataFormat) {
479 case VG_sRGBX_8888: {
480 VGuint *src = (VGuint *)data;
481 src += offset;
482 for (i = 0; i < n; ++i) {
483 VGubyte r, g, b ,a;
484 r = (*src >> 24) & 0xff;
485 g = (*src >> 16) & 0xff;
486 b = (*src >> 8) & 0xff;
487 a = 0xff;
488
489 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
490 rgba[i]);
491 ++src;
492 }
493 }
494 return;
495 case VG_sRGBA_8888: {
496 VGuint *src = (VGuint *)data;
497 src += offset;
498 for (i = 0; i < n; ++i) {
499 VGubyte r, g, b ,a;
500 r = (*src >> 24) & 0xff;
501 g = (*src >> 16) & 0xff;
502 b = (*src >> 8) & 0xff;
503 a = (*src >> 0) & 0xff;
504
505 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
506 rgba[i]);
507 ++src;
508 }
509 return;
510 }
511 break;
512 case VG_sRGBA_8888_PRE: {
513 VGint *src = (VGint *)data;
514 src += offset;
515 for (i = 0; i < n; ++i) {
516 VGubyte r, g, b ,a;
517 r = (*src >> 24) & 0xff;
518 g = (*src >> 16) & 0xff;
519 b = (*src >> 8) & 0xff;
520 a = (*src >> 0) & 0xff;
521
522 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
523 rgba[i]);
524 ++src;
525 }
526 return;
527 }
528 break;
529 case VG_sRGB_565: {
530 VGshort *src = (VGshort *)data;
531 src += offset;
532 for (i = 0; i < n; ++i) {
533 VGfloat clr[4];
534 clr[0] = ((*src >> 10) & 31)/31.;
535 clr[1] = ((*src >> 5) & 95)/95.;
536 clr[2] = ((*src >> 0) & 31)/31.;
537 clr[3] = 1.f;
538
539 util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT,
540 rgba[i]);
541 ++src;
542 }
543 }
544 return;
545 case VG_sRGBA_5551: {
546 VGshort *src = (VGshort *)data;
547 src += offset;
548 for (i = 0; i < n; ++i) {
549 VGfloat clr[4];
550 clr[0] = ((*src >> 10) & 31)/31.;
551 clr[1] = ((*src >> 5) & 31)/31.;
552 clr[2] = ((*src >> 1) & 31)/31.;
553 clr[3] = ((*src >> 0) & 1)/1.;
554
555 util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT,
556 rgba[i]);
557 ++src;
558 }
559 }
560 return;
561 case VG_sRGBA_4444: {
562 VGshort *src = (VGshort *)data;
563 src += offset;
564 for (i = 0; i < n; ++i) {
565 VGfloat clr[4];
566 clr[0] = ((*src >> 12) & 15)/15.;
567 clr[1] = ((*src >> 8) & 15)/15.;
568 clr[2] = ((*src >> 4) & 15)/15.;
569 clr[3] = ((*src >> 0) & 15)/15.;
570
571 util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT,
572 rgba[i]);
573 ++src;
574 }
575 }
576 return;
577 case VG_sL_8: {
578 VGubyte *src = (VGubyte *)data;
579 src += offset;
580 for (i = 0; i < n; ++i) {
581 util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT,
582 rgba[i]);
583 ++src;
584 }
585 }
586 return;
587 case VG_lRGBX_8888: {
588 VGuint *src = (VGuint *)data;
589 src += offset;
590 for (i = 0; i < n; ++i) {
591 VGubyte r, g, b ,a;
592 r = (*src >> 24) & 0xff;
593 g = (*src >> 16) & 0xff;
594 b = (*src >> 8) & 0xff;
595 a = 0xff;
596
597 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
598 rgba[i]);
599 ++src;
600 }
601 }
602 return;
603 case VG_lRGBA_8888: {
604 VGint *src = (VGint *)data;
605 src += offset;
606 for (i = 0; i < n; ++i) {
607 VGubyte r, g, b ,a;
608 r = (*src >> 24) & 0xff;
609 g = (*src >> 16) & 0xff;
610 b = (*src >> 8) & 0xff;
611 a = (*src >> 0) & 0xff;
612
613 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
614 rgba[i]);
615 ++src;
616 }
617 return;
618 }
619 break;
620 case VG_lRGBA_8888_PRE: {
621 VGint *src = (VGint *)data;
622 src += offset;
623 for (i = 0; i < n; ++i) {
624 VGubyte r, g, b ,a;
625 r = (*src >> 24) & 0xff;
626 g = (*src >> 16) & 0xff;
627 b = (*src >> 8) & 0xff;
628 a = (*src >> 0) & 0xff;
629
630 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
631 rgba[i]);
632 ++src;
633 }
634 return;
635 }
636 break;
637 case VG_lL_8: {
638 VGubyte *src = (VGubyte *)data;
639 src += offset;
640 for (i = 0; i < n; ++i) {
641 util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT,
642 rgba[i]);
643 ++src;
644 }
645 }
646 return;
647 case VG_A_8: {
648 VGubyte *src = (VGubyte *)data;
649 src += offset;
650 for (i = 0; i < n; ++i) {
651 util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT,
652 rgba[i]);
653 ++src;
654 }
655 }
656 return;
657 case VG_BW_1: {
658 VGubyte *src = (VGubyte *)data;
659 src += offset;
660 for (i = 0; i < n; i += 8) {
661 VGfloat clr[4];
662 VGint j;
663 for (j = 0; j < 8 && j < n ; ++j) {
664 VGint shift = j;
665 clr[0] = (((*src) & (1<<shift)) >> shift);
666 clr[1] = clr[0];
667 clr[2] = clr[0];
668 clr[3] = 1.f;
669
670 util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT,
671 rgba[i+j]);
672 }
673 ++src;
674 }
675 }
676 return;
677 #ifdef OPENVG_VERSION_1_1
678 case VG_A_1: {
679 VGubyte *src = (VGubyte *)data;
680 src += offset;
681 for (i = 0; i < n; i += 8) {
682 VGfloat clr[4];
683 VGint j;
684 for (j = 0; j < 8 && j < n ; ++j) {
685 VGint shift = j;
686 clr[0] = 0.f;
687 clr[1] = 0.f;
688 clr[2] = 0.f;
689 clr[3] = (((*src) & (1<<shift)) >> shift);
690
691 util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT,
692 rgba[i+j]);
693 }
694 ++src;
695 }
696 }
697 return;
698 case VG_A_4: {
699 VGubyte *src = (VGubyte *)data;
700 src += offset/2;
701 for (i = 0; i < n; i += 2) {
702 VGfloat clr[4];
703 VGint j;
704 for (j = 0; j < n && j < 2; ++j) {
705 VGint bitter, shift;
706 if (j == 0) {
707 bitter = 0x0f;
708 shift = 0;
709 } else {
710 bitter = 0xf0;
711 shift = 4;
712 }
713 clr[0] = 0.f;
714 clr[1] = 0.f;
715 clr[2] = 0.f;
716 clr[3] = ((*src) & (bitter)) >> shift;
717
718 util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT,
719 rgba[i +j]);
720 }
721 ++src;
722 }
723 }
724 return;
725 #endif
726 case VG_sXRGB_8888:
727 break;
728 case VG_sARGB_8888: {
729 VGuint *src = (VGuint *)data;
730 src += offset;
731 for (i = 0; i < n; ++i) {
732 VGubyte r, g, b ,a;
733 a = (*src >> 24) & 0xff;
734 r = (*src >> 16) & 0xff;
735 g = (*src >> 8) & 0xff;
736 b = (*src >> 0) & 0xff;
737
738 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
739 rgba[i]);
740 ++src;
741 }
742 return;
743 }
744 break;
745 case VG_sARGB_8888_PRE: {
746 VGuint *src = (VGuint *)data;
747 src += offset;
748 for (i = 0; i < n; ++i) {
749 VGubyte r, g, b ,a;
750 a = (*src >> 24) & 0xff;
751 r = (*src >> 16) & 0xff;
752 g = (*src >> 8) & 0xff;
753 b = (*src >> 0) & 0xff;
754
755 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
756 rgba[i]);
757 ++src;
758 }
759 return;
760 }
761 break;
762 case VG_sARGB_1555:
763 break;
764 case VG_sARGB_4444:
765 break;
766 case VG_lXRGB_8888:
767 break;
768 case VG_lARGB_8888: {
769 VGint *src = (VGint *)data;
770 src += offset;
771 for (i = 0; i < n; ++i) {
772 VGubyte r, g, b ,a;
773 a = (*src >> 24) & 0xff;
774 r = (*src >> 16) & 0xff;
775 g = (*src >> 8) & 0xff;
776 b = (*src >> 0) & 0xff;
777
778 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
779 rgba[i]);
780 ++src;
781 }
782 return;
783 }
784 break;
785 case VG_lARGB_8888_PRE: {
786 VGint *src = (VGint *)data;
787 src += offset;
788 for (i = 0; i < n; ++i) {
789 VGubyte r, g, b ,a;
790 a = (*src >> 24) & 0xff;
791 r = (*src >> 16) & 0xff;
792 g = (*src >> 8) & 0xff;
793 b = (*src >> 0) & 0xff;
794
795 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
796 rgba[i]);
797 ++src;
798 }
799 return;
800 }
801 break;
802 case VG_sBGRX_8888:
803 break;
804 case VG_sBGRA_8888: {
805 VGuint *src = (VGuint *)data;
806 src += offset;
807 for (i = 0; i < n; ++i) {
808 VGubyte r, g, b ,a;
809 b = (*src >> 24) & 0xff;
810 g = (*src >> 16) & 0xff;
811 r = (*src >> 8) & 0xff;
812 a = (*src >> 0) & 0xff;
813
814 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
815 rgba[i]);
816 ++src;
817 }
818 return;
819 }
820 break;
821 case VG_sBGRA_8888_PRE: {
822 VGuint *src = (VGuint *)data;
823 src += offset;
824 for (i = 0; i < n; ++i) {
825 VGubyte r, g, b ,a;
826 b = (*src >> 24) & 0xff;
827 g = (*src >> 16) & 0xff;
828 r = (*src >> 8) & 0xff;
829 a = (*src >> 0) & 0xff;
830
831 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
832 rgba[i]);
833 ++src;
834 }
835 return;
836 }
837 break;
838 case VG_sBGR_565:
839 break;
840 case VG_sBGRA_5551:
841 break;
842 case VG_sBGRA_4444:
843 break;
844 case VG_lBGRX_8888:
845 break;
846 case VG_lBGRA_8888: {
847 VGuint *src = (VGuint *)data;
848 src += offset;
849 for (i = 0; i < n; ++i) {
850 VGubyte r, g, b ,a;
851 b = (*src >> 24) & 0xff;
852 g = (*src >> 16) & 0xff;
853 r = (*src >> 8) & 0xff;
854 a = (*src >> 0) & 0xff;
855
856 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
857 rgba[i]);
858 ++src;
859 }
860 return;
861 }
862 break;
863 case VG_lBGRA_8888_PRE: {
864 VGuint *src = (VGuint *)data;
865 src += offset;
866 for (i = 0; i < n; ++i) {
867 VGubyte r, g, b ,a;
868 b = (*src >> 24) & 0xff;
869 g = (*src >> 16) & 0xff;
870 r = (*src >> 8) & 0xff;
871 a = (*src >> 0) & 0xff;
872
873 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
874 rgba[i]);
875 ++src;
876 }
877 return;
878 }
879 break;
880 case VG_sXBGR_8888:
881 break;
882 case VG_sABGR_8888: {
883 VGuint *src = (VGuint *)data;
884 src += offset;
885 for (i = 0; i < n; ++i) {
886 VGubyte r, g, b ,a;
887 a = (*src >> 24) & 0xff;
888 b = (*src >> 16) & 0xff;
889 g = (*src >> 8) & 0xff;
890 r = (*src >> 0) & 0xff;
891
892 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
893 rgba[i]);
894 ++src;
895 }
896 return;
897 }
898 break;
899 case VG_sABGR_8888_PRE: {
900 VGuint *src = (VGuint *)data;
901 src += offset;
902 for (i = 0; i < n; ++i) {
903 VGubyte r, g, b ,a;
904 a = (*src >> 24) & 0xff;
905 b = (*src >> 16) & 0xff;
906 g = (*src >> 8) & 0xff;
907 r = (*src >> 0) & 0xff;
908
909 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
910 rgba[i]);
911 ++src;
912 }
913 return;
914 }
915 break;
916 case VG_sABGR_1555:
917 break;
918 case VG_sABGR_4444:
919 break;
920 case VG_lXBGR_8888:
921 break;
922 case VG_lABGR_8888: {
923 VGuint *src = (VGuint *)data;
924 src += offset;
925 for (i = 0; i < n; ++i) {
926 VGubyte r, g, b ,a;
927 a = (*src >> 24) & 0xff;
928 b = (*src >> 16) & 0xff;
929 g = (*src >> 8) & 0xff;
930 r = (*src >> 0) & 0xff;
931
932 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
933 rgba[i]);
934 ++src;
935 }
936 return;
937 }
938 break;
939 case VG_lABGR_8888_PRE: {
940 VGuint *src = (VGuint *)data;
941 src += offset;
942 for (i = 0; i < n; ++i) {
943 VGubyte r, g, b ,a;
944 a = (*src >> 24) & 0xff;
945 b = (*src >> 16) & 0xff;
946 g = (*src >> 8) & 0xff;
947 r = (*src >> 0) & 0xff;
948
949 util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT,
950 rgba[i]);
951 ++src;
952 }
953 return;
954 }
955 break;
956 default:
957 assert(!"Unknown ReadPixels format");
958 break;
959 }
960 assert(!"Not implemented ReadPixels format");
961 }
962
963 VGint _vega_size_for_format(VGImageFormat dataFormat)
964 {
965 switch (dataFormat) {
966 case VG_sRGBX_8888:
967 case VG_sRGBA_8888:
968 case VG_sRGBA_8888_PRE:
969 return 4;
970 case VG_sRGB_565:
971 case VG_sRGBA_5551:
972 case VG_sRGBA_4444:
973 return 2;
974 case VG_sL_8:
975 return 1;
976 case VG_lRGBX_8888:
977 case VG_lRGBA_8888:
978 case VG_lRGBA_8888_PRE:
979 return 4;
980 case VG_lL_8:
981 return 1;
982 case VG_A_8:
983 return 1;
984 case VG_BW_1:
985 return 1;
986 #ifdef OPENVG_VERSION_1_1
987 case VG_A_1:
988 break;
989 case VG_A_4:
990 break;
991 #endif
992 case VG_sXRGB_8888:
993 case VG_sARGB_8888:
994 case VG_sARGB_8888_PRE:
995 return 4;
996 case VG_sARGB_1555:
997 case VG_sARGB_4444:
998 return 2;
999 case VG_lXRGB_8888:
1000 case VG_lARGB_8888:
1001 case VG_lARGB_8888_PRE:
1002 case VG_sBGRX_8888:
1003 case VG_sBGRA_8888:
1004 case VG_sBGRA_8888_PRE:
1005 return 4;
1006 case VG_sBGR_565:
1007 case VG_sBGRA_5551:
1008 case VG_sBGRA_4444:
1009 return 2;
1010 case VG_lBGRX_8888:
1011 case VG_lBGRA_8888:
1012 case VG_lBGRA_8888_PRE:
1013 case VG_sXBGR_8888:
1014 case VG_sABGR_8888:
1015 case VG_sABGR_8888_PRE:
1016 return 4;
1017 case VG_sABGR_1555:
1018 case VG_sABGR_4444:
1019 return 2;
1020 case VG_lXBGR_8888:
1021 case VG_lABGR_8888:
1022 case VG_lABGR_8888_PRE:
1023 return 4;
1024 default:
1025 assert(!"Unknown ReadPixels format");
1026 break;
1027 }
1028 assert(!"Not implemented ReadPixels format");
1029 return 0;
1030 }