2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * George Sapountzis <gsap7@yahoo.gr>
30 #include "swrast_priv.h"
32 #define YFLIP(_xrb, Y) ((_xrb)->Base.Height - (Y) - 1)
35 * Pixel macros shared across front/back buffer span functions.
39 #define STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE) \
40 DST[3] = VALUE[ACOMP]; \
41 DST[2] = VALUE[RCOMP]; \
42 DST[1] = VALUE[GCOMP]; \
44 #define STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE) \
46 DST[2] = VALUE[RCOMP]; \
47 DST[1] = VALUE[GCOMP]; \
49 #define FETCH_PIXEL_A8R8G8B8(DST, SRC) \
50 DST[ACOMP] = SRC[3]; \
51 DST[RCOMP] = SRC[2]; \
52 DST[GCOMP] = SRC[1]; \
57 #define STORE_PIXEL_R5G6B5(DST, X, Y, VALUE) \
59 GLushort *p = (GLushort *)DST; \
60 *p = ( (((VALUE[RCOMP]) & 0xf8) << 8) | \
61 (((VALUE[GCOMP]) & 0xfc) << 3) | \
62 (((VALUE[BCOMP]) & 0xf8) >> 3) ); \
64 #define FETCH_PIXEL_R5G6B5(DST, SRC) \
66 GLushort p = *(GLushort *)SRC; \
68 DST[RCOMP] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
69 DST[GCOMP] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
70 DST[BCOMP] = ((p << 3) & 0xf8) * 255 / 0xf8; \
75 * Generate code for image span functions.
79 #define NAME(FUNC) FUNC##_A8R8G8B8
80 #define RB_TYPE GLubyte
82 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
83 #define INIT_PIXEL_PTR(P, X, Y) \
84 GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X) * 4;
85 #define INC_PIXEL_PTR(P) P += 4
86 #define STORE_PIXEL(DST, X, Y, VALUE) \
87 STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE)
88 #define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
89 STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE)
90 #define FETCH_PIXEL(DST, SRC) \
91 FETCH_PIXEL_A8R8G8B8(DST, SRC)
93 #include "swrast/s_spantemp.h"
97 #define NAME(FUNC) FUNC##_R5G6B5
98 #define RB_TYPE GLubyte
100 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
101 #define INIT_PIXEL_PTR(P, X, Y) \
102 GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X) * 2;
103 #define INC_PIXEL_PTR(P) P += 2
104 #define STORE_PIXEL(DST, X, Y, VALUE) \
105 STORE_PIXEL_R5G6B5(DST, X, Y, VALUE)
106 #define FETCH_PIXEL(DST, SRC) \
107 FETCH_PIXEL_R5G6B5(DST, SRC)
109 #include "swrast/s_spantemp.h"
112 /* 8-bit color index */
113 #define NAME(FUNC) FUNC##_CI8
115 #define RB_TYPE GLubyte
117 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
118 #define INIT_PIXEL_PTR(P, X, Y) \
119 GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X);
120 #define INC_PIXEL_PTR(P) P += 1
121 #define STORE_PIXEL(DST, X, Y, VALUE) \
123 #define FETCH_PIXEL(DST, SRC) \
126 #include "swrast/s_spantemp.h"
130 * Generate code for pixmap span functions.
134 #define NAME(FUNC) FUNC##_A8R8G8B8_pixmap
135 #define RB_TYPE GLubyte
137 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
138 #define INIT_PIXEL_PTR(P, X, Y) \
139 GLubyte *P = (GLubyte *)row;
140 #define INC_PIXEL_PTR(P) P += 4
141 #define STORE_PIXEL(DST, X, Y, VALUE) \
142 STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE)
143 #define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
144 STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE)
145 #define FETCH_PIXEL(DST, SRC) \
146 FETCH_PIXEL_A8R8G8B8(DST, SRC)
148 #include "swrast_spantemp.h"
152 #define NAME(FUNC) FUNC##_R5G6B5_pixmap
153 #define RB_TYPE GLubyte
155 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
156 #define INIT_PIXEL_PTR(P, X, Y) \
157 GLubyte *P = (GLubyte *)row;
158 #define INC_PIXEL_PTR(P) P += 2
159 #define STORE_PIXEL(DST, X, Y, VALUE) \
160 STORE_PIXEL_R5G6B5(DST, X, Y, VALUE)
161 #define FETCH_PIXEL(DST, SRC) \
162 FETCH_PIXEL_R5G6B5(DST, SRC)
164 #include "swrast_spantemp.h"
167 /* 8-bit color index */
168 #define NAME(FUNC) FUNC##_CI8_pixmap
170 #define RB_TYPE GLubyte
172 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
173 #define INIT_PIXEL_PTR(P, X, Y) \
174 GLubyte *P = (GLubyte *)row;
175 #define INC_PIXEL_PTR(P) P += 1
176 #define STORE_PIXEL(DST, X, Y, VALUE) \
178 #define FETCH_PIXEL(DST, SRC) \
181 #include "swrast_spantemp.h"
185 * Images are malloced memory used for private back-buffers.
187 * BACK_PIXMAP (not supported)
191 swrast_set_span_funcs_ximage(struct swrast_renderbuffer
*xrb
,
194 switch (pixel_format
) {
196 xrb
->Base
.GetRow
= get_row_A8R8G8B8
;
197 xrb
->Base
.GetValues
= get_values_A8R8G8B8
;
198 xrb
->Base
.PutRow
= put_row_A8R8G8B8
;
199 xrb
->Base
.PutRowRGB
= put_row_rgb_A8R8G8B8
;
200 xrb
->Base
.PutMonoRow
= put_mono_row_A8R8G8B8
;
201 xrb
->Base
.PutValues
= put_values_A8R8G8B8
;
202 xrb
->Base
.PutMonoValues
= put_mono_values_A8R8G8B8
;
205 xrb
->Base
.GetRow
= get_row_R5G6B5
;
206 xrb
->Base
.GetValues
= get_values_R5G6B5
;
207 xrb
->Base
.PutRow
= put_row_R5G6B5
;
208 xrb
->Base
.PutRowRGB
= put_row_rgb_R5G6B5
;
209 xrb
->Base
.PutMonoRow
= put_mono_row_R5G6B5
;
210 xrb
->Base
.PutValues
= put_values_R5G6B5
;
211 xrb
->Base
.PutMonoValues
= put_mono_values_R5G6B5
;
214 xrb
->Base
.GetRow
= get_row_CI8
;
215 xrb
->Base
.GetValues
= get_values_CI8
;
216 xrb
->Base
.PutRow
= put_row_CI8
;
217 xrb
->Base
.PutMonoRow
= put_mono_row_CI8
;
218 xrb
->Base
.PutValues
= put_values_CI8
;
219 xrb
->Base
.PutMonoValues
= put_mono_values_CI8
;
229 * Pixmaps are used for front-buffers.
231 * WINDOW, An X window
232 * GLXWINDOW, GLX window
234 * PBUFFER GLX Pbuffer
237 swrast_set_span_funcs_pixmap(struct swrast_renderbuffer
*xrb
,
240 switch (pixel_format
) {
242 xrb
->Base
.GetRow
= get_row_A8R8G8B8_pixmap
;
243 xrb
->Base
.GetValues
= get_values_A8R8G8B8_pixmap
;
244 xrb
->Base
.PutRow
= put_row_A8R8G8B8_pixmap
;
245 xrb
->Base
.PutRowRGB
= put_row_rgb_A8R8G8B8_pixmap
;
246 xrb
->Base
.PutMonoRow
= put_mono_row_A8R8G8B8_pixmap
;
247 xrb
->Base
.PutValues
= put_values_A8R8G8B8_pixmap
;
248 xrb
->Base
.PutMonoValues
= put_mono_values_A8R8G8B8_pixmap
;
251 xrb
->Base
.GetRow
= get_row_R5G6B5_pixmap
;
252 xrb
->Base
.GetValues
= get_values_R5G6B5_pixmap
;
253 xrb
->Base
.PutRow
= put_row_R5G6B5_pixmap
;
254 xrb
->Base
.PutRowRGB
= put_row_rgb_R5G6B5_pixmap
;
255 xrb
->Base
.PutMonoRow
= put_mono_row_R5G6B5_pixmap
;
256 xrb
->Base
.PutValues
= put_values_R5G6B5_pixmap
;
257 xrb
->Base
.PutMonoValues
= put_mono_values_R5G6B5_pixmap
;
260 xrb
->Base
.GetRow
= get_row_CI8_pixmap
;
261 xrb
->Base
.GetValues
= get_values_CI8_pixmap
;
262 xrb
->Base
.PutRow
= put_row_CI8_pixmap
;
263 xrb
->Base
.PutMonoRow
= put_mono_row_CI8_pixmap
;
264 xrb
->Base
.PutValues
= put_values_CI8_pixmap
;
265 xrb
->Base
.PutMonoValues
= put_mono_values_CI8_pixmap
;