1 /*
2  * Copyright © 2012 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 static void
FN_NAME(struct gl_context * ctx,DST_TYPE * dst,GLenum dstFormat,SRC_TYPE rgba[][4],int n)25 FN_NAME(struct gl_context *ctx,
26 	DST_TYPE *dst,
27 	GLenum dstFormat,
28 	SRC_TYPE rgba[][4],
29 	int n)
30 {
31    int i;
32 
33    switch (dstFormat) {
34    case GL_RED_INTEGER_EXT:
35       for (i=0;i<n;i++) {
36 	 dst[i] = SRC_CONVERT(rgba[i][RCOMP]);
37       }
38       break;
39 
40    case GL_GREEN_INTEGER_EXT:
41       for (i=0;i<n;i++) {
42 	 dst[i] = SRC_CONVERT(rgba[i][GCOMP]);
43       }
44       break;
45 
46    case GL_BLUE_INTEGER_EXT:
47       for (i=0;i<n;i++) {
48 	 dst[i] = SRC_CONVERT(rgba[i][BCOMP]);
49       };
50       break;
51 
52    case GL_ALPHA_INTEGER_EXT:
53       for (i=0;i<n;i++) {
54 	 dst[i] = SRC_CONVERT(rgba[i][ACOMP]);
55       }
56       break;
57 
58    case GL_RG_INTEGER:
59       for (i=0;i<n;i++) {
60 	 dst[i*2+0] = SRC_CONVERT(rgba[i][RCOMP]);
61 	 dst[i*2+1] = SRC_CONVERT(rgba[i][GCOMP]);
62       }
63       break;
64 
65    case GL_RGB_INTEGER_EXT:
66       for (i=0;i<n;i++) {
67 	 dst[i*3+0] = SRC_CONVERT(rgba[i][RCOMP]);
68 	 dst[i*3+1] = SRC_CONVERT(rgba[i][GCOMP]);
69 	 dst[i*3+2] = SRC_CONVERT(rgba[i][BCOMP]);
70       }
71       break;
72 
73    case GL_RGBA_INTEGER_EXT:
74       for (i=0;i<n;i++) {
75 	 dst[i*4+0] = SRC_CONVERT(rgba[i][RCOMP]);
76 	 dst[i*4+1] = SRC_CONVERT(rgba[i][GCOMP]);
77 	 dst[i*4+2] = SRC_CONVERT(rgba[i][BCOMP]);
78 	 dst[i*4+3] = SRC_CONVERT(rgba[i][ACOMP]);
79       }
80       break;
81 
82    case GL_BGR_INTEGER_EXT:
83       for (i=0;i<n;i++) {
84 	 dst[i*3+0] = SRC_CONVERT(rgba[i][BCOMP]);
85 	 dst[i*3+1] = SRC_CONVERT(rgba[i][GCOMP]);
86 	 dst[i*3+2] = SRC_CONVERT(rgba[i][RCOMP]);
87       }
88       break;
89 
90    case GL_BGRA_INTEGER_EXT:
91       for (i=0;i<n;i++) {
92 	 dst[i*4+0] = SRC_CONVERT(rgba[i][BCOMP]);
93 	 dst[i*4+1] = SRC_CONVERT(rgba[i][GCOMP]);
94 	 dst[i*4+2] = SRC_CONVERT(rgba[i][RCOMP]);
95 	 dst[i*4+3] = SRC_CONVERT(rgba[i][ACOMP]);
96       }
97       break;
98 
99    case GL_LUMINANCE_INTEGER_EXT:
100       for (i=0;i<n;i++) {
101 	 dst[i] = SRC_CONVERT(rgba[i][RCOMP] +
102 			      rgba[i][GCOMP] +
103 			      rgba[i][BCOMP]);
104       }
105       break;
106 
107    case GL_LUMINANCE_ALPHA_INTEGER_EXT:
108       for (i=0;i<n;i++) {
109 	 dst[i*2+0] = SRC_CONVERT(rgba[i][RCOMP] +
110 				  rgba[i][GCOMP] +
111 				  rgba[i][BCOMP]);
112 	 dst[i*2+1] = SRC_CONVERT(rgba[i][ACOMP]);
113       }
114       break;
115 
116    default:
117       _mesa_problem(ctx,
118          "Unsupported format (%s)",
119          _mesa_lookup_enum_by_nr(dstFormat));
120       break;
121    }
122 }
123