Tizen 2.0 Release
[profile/ivi/osmesa.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    union util_color uc;
478
479    switch (dataFormat) {
480    case VG_sRGBX_8888: {
481       VGuint *src = (VGuint *)data;
482       src += offset;
483       for (i = 0; i < n; ++i) {
484          VGubyte r, g, b ,a;
485          r = (*src >> 24) & 0xff;
486          g = (*src >> 16) & 0xff;
487          b = (*src >>  8) & 0xff;
488          a = 0xff;
489
490          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
491          rgba[i][0] = uc.f[0];
492          rgba[i][1] = uc.f[1];
493          rgba[i][2] = uc.f[2];
494          rgba[i][3] = uc.f[3];
495          ++src;
496       }
497    }
498       return;
499    case VG_sRGBA_8888: {
500       VGuint *src = (VGuint *)data;
501       src += offset;
502       for (i = 0; i < n; ++i) {
503          VGubyte r, g, b ,a;
504          r = (*src >> 24) & 0xff;
505          g = (*src >> 16) & 0xff;
506          b = (*src >>  8) & 0xff;
507          a = (*src >>  0) & 0xff;
508
509          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
510          rgba[i][0] = uc.f[0];
511          rgba[i][1] = uc.f[1];
512          rgba[i][2] = uc.f[2];
513          rgba[i][3] = uc.f[3];
514          ++src;
515       }
516       return;
517    }
518       break;
519    case VG_sRGBA_8888_PRE: {
520       VGint *src = (VGint *)data;
521       src += offset;
522       for (i = 0; i < n; ++i) {
523          VGubyte r, g, b ,a;
524          r = (*src >> 24) & 0xff;
525          g = (*src >> 16) & 0xff;
526          b = (*src >>  8) & 0xff;
527          a = (*src >>  0) & 0xff;
528
529          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
530          rgba[i][0] = uc.f[0];
531          rgba[i][1] = uc.f[1];
532          rgba[i][2] = uc.f[2];
533          rgba[i][3] = uc.f[3];
534          ++src;
535       }
536       return;
537    }
538       break;
539    case VG_sRGB_565: {
540       VGshort *src = (VGshort *)data;
541       src += offset;
542       for (i = 0; i < n; ++i) {
543          VGfloat clr[4];
544          clr[0] = ((*src >> 10) & 31)/31.;
545          clr[1] = ((*src >>  5) & 95)/95.;
546          clr[2] = ((*src >>  0) & 31)/31.;
547          clr[3] = 1.f;
548
549          util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
550          rgba[i][0] = uc.f[0];
551          rgba[i][1] = uc.f[1];
552          rgba[i][2] = uc.f[2];
553          rgba[i][3] = uc.f[3];
554          ++src;
555       }
556    }
557       return;
558    case VG_sRGBA_5551: {
559       VGshort *src = (VGshort *)data;
560       src += offset;
561       for (i = 0; i < n; ++i) {
562          VGfloat clr[4];
563          clr[0] = ((*src >> 10) & 31)/31.;
564          clr[1] = ((*src >>  5) & 31)/31.;
565          clr[2] = ((*src >>  1) & 31)/31.;
566          clr[3] = ((*src >>  0) & 1)/1.;
567
568          util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
569          rgba[i][0] = uc.f[0];
570          rgba[i][1] = uc.f[1];
571          rgba[i][2] = uc.f[2];
572          rgba[i][3] = uc.f[3];
573          ++src;
574       }
575    }
576       return;
577    case VG_sRGBA_4444: {
578       VGshort *src = (VGshort *)data;
579       src += offset;
580       for (i = 0; i < n; ++i) {
581          VGfloat clr[4];
582          clr[0] = ((*src >> 12) & 15)/15.;
583          clr[1] = ((*src >>  8) & 15)/15.;
584          clr[2] = ((*src >>  4) & 15)/15.;
585          clr[3] = ((*src >>  0) & 15)/15.;
586
587          util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
588          rgba[i][0] = uc.f[0];
589          rgba[i][1] = uc.f[1];
590          rgba[i][2] = uc.f[2];
591          rgba[i][3] = uc.f[3];
592          ++src;
593       }
594    }
595       return;
596    case VG_sL_8: {
597       VGubyte *src = (VGubyte *)data;
598       src += offset;
599       for (i = 0; i < n; ++i) {
600          util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
601          rgba[i][0] = uc.f[0];
602          rgba[i][1] = uc.f[1];
603          rgba[i][2] = uc.f[2];
604          rgba[i][3] = uc.f[3];
605          ++src;
606       }
607    }
608       return;
609    case VG_lRGBX_8888: {
610       VGuint *src = (VGuint *)data;
611       src += offset;
612       for (i = 0; i < n; ++i) {
613          VGubyte r, g, b ,a;
614          r = (*src >> 24) & 0xff;
615          g = (*src >> 16) & 0xff;
616          b = (*src >>  8) & 0xff;
617          a = 0xff;
618
619          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
620          rgba[i][0] = uc.f[0];
621          rgba[i][1] = uc.f[1];
622          rgba[i][2] = uc.f[2];
623          rgba[i][3] = uc.f[3];
624          ++src;
625       }
626    }
627       return;
628    case VG_lRGBA_8888: {
629       VGint *src = (VGint *)data;
630       src += offset;
631       for (i = 0; i < n; ++i) {
632          VGubyte r, g, b ,a;
633          r = (*src >> 24) & 0xff;
634          g = (*src >> 16) & 0xff;
635          b = (*src >>  8) & 0xff;
636          a = (*src >>  0) & 0xff;
637
638          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
639          rgba[i][0] = uc.f[0];
640          rgba[i][1] = uc.f[1];
641          rgba[i][2] = uc.f[2];
642          rgba[i][3] = uc.f[3];
643          ++src;
644       }
645       return;
646    }
647       break;
648    case VG_lRGBA_8888_PRE: {
649       VGint *src = (VGint *)data;
650       src += offset;
651       for (i = 0; i < n; ++i) {
652          VGubyte r, g, b ,a;
653          r = (*src >> 24) & 0xff;
654          g = (*src >> 16) & 0xff;
655          b = (*src >>  8) & 0xff;
656          a = (*src >>  0) & 0xff;
657
658          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
659          rgba[i][0] = uc.f[0];
660          rgba[i][1] = uc.f[1];
661          rgba[i][2] = uc.f[2];
662          rgba[i][3] = uc.f[3];
663          ++src;
664       }
665       return;
666    }
667       break;
668    case VG_lL_8: {
669       VGubyte *src = (VGubyte *)data;
670       src += offset;
671       for (i = 0; i < n; ++i) {
672          util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
673          rgba[i][0] = uc.f[0];
674          rgba[i][1] = uc.f[1];
675          rgba[i][2] = uc.f[2];
676          rgba[i][3] = uc.f[3];
677          ++src;
678       }
679    }
680       return;
681    case VG_A_8: {
682       VGubyte *src = (VGubyte *)data;
683       src += offset;
684       for (i = 0; i < n; ++i) {
685          util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
686          rgba[i][0] = uc.f[0];
687          rgba[i][1] = uc.f[1];
688          rgba[i][2] = uc.f[2];
689          rgba[i][3] = uc.f[3];
690          ++src;
691       }
692    }
693       return;
694    case VG_BW_1: {
695       VGubyte *src = (VGubyte *)data;
696       src += offset;
697       for (i = 0; i < n; i += 8) {
698          VGfloat clr[4];
699          VGint j;
700          for (j = 0; j < 8 && j < n ; ++j) {
701             VGint shift = j;
702             clr[0] = (((*src) & (1<<shift)) >> shift);
703             clr[1] = clr[0];
704             clr[2] = clr[0];
705             clr[3] = 1.f;
706
707             util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
708             rgba[i+j][0] = uc.f[0];
709             rgba[i+j][1] = uc.f[1];
710             rgba[i+j][2] = uc.f[2];
711             rgba[i+j][3] = uc.f[3];
712          }
713          ++src;
714       }
715    }
716       return;
717 #ifdef OPENVG_VERSION_1_1
718    case VG_A_1: {
719       VGubyte *src = (VGubyte *)data;
720       src += offset;
721       for (i = 0; i < n; i += 8) {
722          VGfloat clr[4];
723          VGint j;
724          for (j = 0; j < 8 && j < n ; ++j) {
725             VGint shift = j;
726             clr[0] = 0.f;
727             clr[1] = 0.f;
728             clr[2] = 0.f;
729             clr[3] = (((*src) & (1<<shift)) >> shift);
730
731             util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
732             rgba[i+j][0] = uc.f[0];
733             rgba[i+j][1] = uc.f[1];
734             rgba[i+j][2] = uc.f[2];
735             rgba[i+j][3] = uc.f[3];
736          }
737          ++src;
738       }
739    }
740       return;
741    case VG_A_4: {
742       VGubyte *src = (VGubyte *)data;
743       src += offset/2;
744       for (i = 0; i < n; i += 2) {
745          VGfloat clr[4];
746          VGint j;
747          for (j = 0; j < n && j < 2; ++j) {
748             VGint bitter, shift;
749             if (j == 0) {
750                bitter = 0x0f;
751                shift = 0;
752             } else {
753                bitter = 0xf0;
754                shift = 4;
755             }
756             clr[0] = 0.f;
757             clr[1] = 0.f;
758             clr[2] = 0.f;
759             clr[3] = ((*src) & (bitter)) >> shift;
760
761             util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
762             rgba[i+j][0] = uc.f[0];
763             rgba[i+j][1] = uc.f[1];
764             rgba[i+j][2] = uc.f[2];
765             rgba[i+j][3] = uc.f[3];
766          }
767          ++src;
768       }
769    }
770       return;
771 #endif
772    case VG_sXRGB_8888:
773       break;
774    case VG_sARGB_8888: {
775       VGuint *src = (VGuint *)data;
776       src += offset;
777       for (i = 0; i < n; ++i) {
778          VGubyte r, g, b ,a;
779          a = (*src >> 24) & 0xff;
780          r = (*src >> 16) & 0xff;
781          g = (*src >>  8) & 0xff;
782          b = (*src >>  0) & 0xff;
783
784          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
785          rgba[i][0] = uc.f[0];
786          rgba[i][1] = uc.f[1];
787          rgba[i][2] = uc.f[2];
788          rgba[i][3] = uc.f[3];
789          ++src;
790       }
791       return;
792    }
793       break;
794    case VG_sARGB_8888_PRE: {
795       VGuint *src = (VGuint *)data;
796       src += offset;
797       for (i = 0; i < n; ++i) {
798          VGubyte r, g, b ,a;
799          a = (*src >> 24) & 0xff;
800          r = (*src >> 16) & 0xff;
801          g = (*src >>  8) & 0xff;
802          b = (*src >>  0) & 0xff;
803
804          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
805          rgba[i][0] = uc.f[0];
806          rgba[i][1] = uc.f[1];
807          rgba[i][2] = uc.f[2];
808          rgba[i][3] = uc.f[3];
809          ++src;
810       }
811       return;
812    }
813       break;
814    case VG_sARGB_1555:
815       break;
816    case VG_sARGB_4444:
817       break;
818    case VG_lXRGB_8888:
819       break;
820    case VG_lARGB_8888: {
821       VGint *src = (VGint *)data;
822       src += offset;
823       for (i = 0; i < n; ++i) {
824          VGubyte r, g, b ,a;
825          a = (*src >> 24) & 0xff;
826          r = (*src >> 16) & 0xff;
827          g = (*src >>  8) & 0xff;
828          b = (*src >>  0) & 0xff;
829
830          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
831          rgba[i][0] = uc.f[0];
832          rgba[i][1] = uc.f[1];
833          rgba[i][2] = uc.f[2];
834          rgba[i][3] = uc.f[3];
835          ++src;
836       }
837       return;
838    }
839       break;
840    case VG_lARGB_8888_PRE: {
841       VGint *src = (VGint *)data;
842       src += offset;
843       for (i = 0; i < n; ++i) {
844          VGubyte r, g, b ,a;
845          a = (*src >> 24) & 0xff;
846          r = (*src >> 16) & 0xff;
847          g = (*src >>  8) & 0xff;
848          b = (*src >>  0) & 0xff;
849
850          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
851          rgba[i][0] = uc.f[0];
852          rgba[i][1] = uc.f[1];
853          rgba[i][2] = uc.f[2];
854          rgba[i][3] = uc.f[3];
855          ++src;
856       }
857       return;
858    }
859       break;
860    case VG_sBGRX_8888:
861       break;
862    case VG_sBGRA_8888:  {
863       VGuint *src = (VGuint *)data;
864       src += offset;
865       for (i = 0; i < n; ++i) {
866          VGubyte r, g, b ,a;
867          b = (*src >> 24) & 0xff;
868          g = (*src >> 16) & 0xff;
869          r = (*src >>  8) & 0xff;
870          a = (*src >>  0) & 0xff;
871
872          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
873          rgba[i][0] = uc.f[0];
874          rgba[i][1] = uc.f[1];
875          rgba[i][2] = uc.f[2];
876          rgba[i][3] = uc.f[3];
877          ++src;
878       }
879       return;
880    }
881       break;
882    case VG_sBGRA_8888_PRE:  {
883       VGuint *src = (VGuint *)data;
884       src += offset;
885       for (i = 0; i < n; ++i) {
886          VGubyte r, g, b ,a;
887          b = (*src >> 24) & 0xff;
888          g = (*src >> 16) & 0xff;
889          r = (*src >>  8) & 0xff;
890          a = (*src >>  0) & 0xff;
891
892          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
893          rgba[i][0] = uc.f[0];
894          rgba[i][1] = uc.f[1];
895          rgba[i][2] = uc.f[2];
896          rgba[i][3] = uc.f[3];
897          ++src;
898       }
899       return;
900    }
901       break;
902    case VG_sBGR_565:
903       break;
904    case VG_sBGRA_5551:
905       break;
906    case VG_sBGRA_4444:
907       break;
908    case VG_lBGRX_8888:
909       break;
910    case VG_lBGRA_8888:  {
911       VGuint *src = (VGuint *)data;
912       src += offset;
913       for (i = 0; i < n; ++i) {
914          VGubyte r, g, b ,a;
915          b = (*src >> 24) & 0xff;
916          g = (*src >> 16) & 0xff;
917          r = (*src >>  8) & 0xff;
918          a = (*src >>  0) & 0xff;
919
920          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
921          rgba[i][0] = uc.f[0];
922          rgba[i][1] = uc.f[1];
923          rgba[i][2] = uc.f[2];
924          rgba[i][3] = uc.f[3];
925          ++src;
926       }
927       return;
928    }
929       break;
930    case VG_lBGRA_8888_PRE:  {
931       VGuint *src = (VGuint *)data;
932       src += offset;
933       for (i = 0; i < n; ++i) {
934          VGubyte r, g, b ,a;
935          b = (*src >> 24) & 0xff;
936          g = (*src >> 16) & 0xff;
937          r = (*src >>  8) & 0xff;
938          a = (*src >>  0) & 0xff;
939
940          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
941          rgba[i][0] = uc.f[0];
942          rgba[i][1] = uc.f[1];
943          rgba[i][2] = uc.f[2];
944          rgba[i][3] = uc.f[3];
945          ++src;
946       }
947       return;
948    }
949       break;
950    case VG_sXBGR_8888:
951       break;
952    case VG_sABGR_8888: {
953       VGuint *src = (VGuint *)data;
954       src += offset;
955       for (i = 0; i < n; ++i) {
956          VGubyte r, g, b ,a;
957          a = (*src >> 24) & 0xff;
958          b = (*src >> 16) & 0xff;
959          g = (*src >>  8) & 0xff;
960          r = (*src >>  0) & 0xff;
961
962          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
963          rgba[i][0] = uc.f[0];
964          rgba[i][1] = uc.f[1];
965          rgba[i][2] = uc.f[2];
966          rgba[i][3] = uc.f[3];
967          ++src;
968       }
969       return;
970    }
971       break;
972    case VG_sABGR_8888_PRE: {
973       VGuint *src = (VGuint *)data;
974       src += offset;
975       for (i = 0; i < n; ++i) {
976          VGubyte r, g, b ,a;
977          a = (*src >> 24) & 0xff;
978          b = (*src >> 16) & 0xff;
979          g = (*src >>  8) & 0xff;
980          r = (*src >>  0) & 0xff;
981
982          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
983          rgba[i][0] = uc.f[0];
984          rgba[i][1] = uc.f[1];
985          rgba[i][2] = uc.f[2];
986          rgba[i][3] = uc.f[3];
987          ++src;
988       }
989       return;
990    }
991       break;
992    case VG_sABGR_1555:
993       break;
994    case VG_sABGR_4444:
995       break;
996    case VG_lXBGR_8888:
997       break;
998    case VG_lABGR_8888: {
999       VGuint *src = (VGuint *)data;
1000       src += offset;
1001       for (i = 0; i < n; ++i) {
1002          VGubyte r, g, b ,a;
1003          a = (*src >> 24) & 0xff;
1004          b = (*src >> 16) & 0xff;
1005          g = (*src >>  8) & 0xff;
1006          r = (*src >>  0) & 0xff;
1007
1008          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
1009          rgba[i][0] = uc.f[0];
1010          rgba[i][1] = uc.f[1];
1011          rgba[i][2] = uc.f[2];
1012          rgba[i][3] = uc.f[3];
1013          ++src;
1014       }
1015       return;
1016    }
1017       break;
1018    case VG_lABGR_8888_PRE: {
1019       VGuint *src = (VGuint *)data;
1020       src += offset;
1021       for (i = 0; i < n; ++i) {
1022          VGubyte r, g, b ,a;
1023          a = (*src >> 24) & 0xff;
1024          b = (*src >> 16) & 0xff;
1025          g = (*src >>  8) & 0xff;
1026          r = (*src >>  0) & 0xff;
1027
1028          util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc);
1029          rgba[i][0] = uc.f[0];
1030          rgba[i][1] = uc.f[1];
1031          rgba[i][2] = uc.f[2];
1032          rgba[i][3] = uc.f[3];
1033          ++src;
1034       }
1035       return;
1036    }
1037       break;
1038    default:
1039       assert(!"Unknown ReadPixels format");
1040       break;
1041    }
1042    assert(!"Not implemented ReadPixels format");
1043 }
1044
1045 VGint _vega_size_for_format(VGImageFormat dataFormat)
1046 {
1047    switch (dataFormat) {
1048    case VG_sRGBX_8888:
1049    case VG_sRGBA_8888:
1050    case VG_sRGBA_8888_PRE:
1051       return 4;
1052    case VG_sRGB_565:
1053    case VG_sRGBA_5551:
1054    case VG_sRGBA_4444:
1055       return 2;
1056    case VG_sL_8:
1057       return 1;
1058    case VG_lRGBX_8888:
1059    case VG_lRGBA_8888:
1060    case VG_lRGBA_8888_PRE:
1061       return 4;
1062    case VG_lL_8:
1063       return 1;
1064    case VG_A_8:
1065       return 1;
1066    case VG_BW_1:
1067       return 1;
1068 #ifdef OPENVG_VERSION_1_1
1069    case VG_A_1:
1070       break;
1071    case VG_A_4:
1072       break;
1073 #endif
1074    case VG_sXRGB_8888:
1075    case VG_sARGB_8888:
1076    case VG_sARGB_8888_PRE:
1077       return 4;
1078    case VG_sARGB_1555:
1079    case VG_sARGB_4444:
1080       return 2;
1081    case VG_lXRGB_8888:
1082    case VG_lARGB_8888:
1083    case VG_lARGB_8888_PRE:
1084    case VG_sBGRX_8888:
1085    case VG_sBGRA_8888:
1086    case VG_sBGRA_8888_PRE:
1087       return 4;
1088    case VG_sBGR_565:
1089    case VG_sBGRA_5551:
1090    case VG_sBGRA_4444:
1091       return 2;
1092    case VG_lBGRX_8888:
1093    case VG_lBGRA_8888:
1094    case VG_lBGRA_8888_PRE:
1095    case VG_sXBGR_8888:
1096    case VG_sABGR_8888:
1097    case VG_sABGR_8888_PRE:
1098       return 4;
1099    case VG_sABGR_1555:
1100    case VG_sABGR_4444:
1101       return 2;
1102    case VG_lXBGR_8888:
1103    case VG_lABGR_8888:
1104    case VG_lABGR_8888_PRE:
1105       return 4;
1106    default:
1107       assert(!"Unknown ReadPixels format");
1108       break;
1109    }
1110    assert(!"Not implemented ReadPixels format");
1111    return 0;
1112 }