comparison src/video/SDL_blit.h @ 1162:2651158f59b8

Enable altivec blitters on PowerPC Linux, and some fixes for recent GCCs versions.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 20 Oct 2005 06:55:26 +0000
parents ffaaf7ecf685
children c9b51268668f
comparison
equal deleted inserted replaced
1161:05d4b93b911e 1162:2651158f59b8
88 ((A)->BitsPerPixel == (B)->BitsPerPixel \ 88 ((A)->BitsPerPixel == (B)->BitsPerPixel \
89 && ((A)->Rmask == (B)->Rmask) && ((A)->Amask == (B)->Amask)) 89 && ((A)->Rmask == (B)->Rmask) && ((A)->Amask == (B)->Amask))
90 90
91 /* Load pixel of the specified format from a buffer and get its R-G-B values */ 91 /* Load pixel of the specified format from a buffer and get its R-G-B values */
92 /* FIXME: rescale values to 0..255 here? */ 92 /* FIXME: rescale values to 0..255 here? */
93 #define RGB_FROM_PIXEL(pixel, fmt, r, g, b) \ 93 #define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \
94 { \ 94 { \
95 r = (((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss); \ 95 r = (((Pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss); \
96 g = (((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss); \ 96 g = (((Pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss); \
97 b = (((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss); \ 97 b = (((Pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss); \
98 } 98 }
99 #define RGB_FROM_RGB565(pixel, r, g, b) \ 99 #define RGB_FROM_RGB565(Pixel, r, g, b) \
100 { \ 100 { \
101 r = (((pixel&0xF800)>>11)<<3); \ 101 r = (((Pixel&0xF800)>>11)<<3); \
102 g = (((pixel&0x07E0)>>5)<<2); \ 102 g = (((Pixel&0x07E0)>>5)<<2); \
103 b = ((pixel&0x001F)<<3); \ 103 b = ((Pixel&0x001F)<<3); \
104 } 104 }
105 #define RGB_FROM_RGB555(pixel, r, g, b) \ 105 #define RGB_FROM_RGB555(Pixel, r, g, b) \
106 { \ 106 { \
107 r = (((pixel&0x7C00)>>10)<<3); \ 107 r = (((Pixel&0x7C00)>>10)<<3); \
108 g = (((pixel&0x03E0)>>5)<<3); \ 108 g = (((Pixel&0x03E0)>>5)<<3); \
109 b = ((pixel&0x001F)<<3); \ 109 b = ((Pixel&0x001F)<<3); \
110 } 110 }
111 #define RGB_FROM_RGB888(pixel, r, g, b) \ 111 #define RGB_FROM_RGB888(Pixel, r, g, b) \
112 { \ 112 { \
113 r = ((pixel&0xFF0000)>>16); \ 113 r = ((Pixel&0xFF0000)>>16); \
114 g = ((pixel&0xFF00)>>8); \ 114 g = ((Pixel&0xFF00)>>8); \
115 b = (pixel&0xFF); \ 115 b = (Pixel&0xFF); \
116 } 116 }
117 #define RETRIEVE_RGB_PIXEL(buf, bpp, pixel) \ 117 #define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \
118 do { \ 118 do { \
119 switch (bpp) { \ 119 switch (bpp) { \
120 case 2: \ 120 case 2: \
121 pixel = *((Uint16 *)(buf)); \ 121 Pixel = *((Uint16 *)(buf)); \
122 break; \ 122 break; \
123 \ 123 \
124 case 3: { \ 124 case 3: { \
125 Uint8 *B = (Uint8 *)(buf); \ 125 Uint8 *B = (Uint8 *)(buf); \
126 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ 126 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
127 pixel = B[0] + (B[1] << 8) + (B[2] << 16); \ 127 Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
128 } else { \ 128 } else { \
129 pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \ 129 Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
130 } \ 130 } \
131 } \ 131 } \
132 break; \ 132 break; \
133 \ 133 \
134 case 4: \ 134 case 4: \
135 pixel = *((Uint32 *)(buf)); \ 135 Pixel = *((Uint32 *)(buf)); \
136 break; \ 136 break; \
137 \ 137 \
138 default: \ 138 default: \
139 pixel = 0; /* appease gcc */ \ 139 Pixel = 0; /* appease gcc */ \
140 break; \ 140 break; \
141 } \ 141 } \
142 } while(0) 142 } while(0)
143 143
144 #define DISEMBLE_RGB(buf, bpp, fmt, pixel, r, g, b) \ 144 #define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \
145 do { \ 145 do { \
146 switch (bpp) { \ 146 switch (bpp) { \
147 case 2: \ 147 case 2: \
148 pixel = *((Uint16 *)(buf)); \ 148 Pixel = *((Uint16 *)(buf)); \
149 break; \ 149 break; \
150 \ 150 \
151 case 3: { \ 151 case 3: { \
152 Uint8 *B = (Uint8 *)buf; \ 152 Uint8 *B = (Uint8 *)buf; \
153 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ 153 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
154 pixel = B[0] + (B[1] << 8) + (B[2] << 16); \ 154 Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
155 } else { \ 155 } else { \
156 pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \ 156 Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
157 } \ 157 } \
158 } \ 158 } \
159 break; \ 159 break; \
160 \ 160 \
161 case 4: \ 161 case 4: \
162 pixel = *((Uint32 *)(buf)); \ 162 Pixel = *((Uint32 *)(buf)); \
163 break; \ 163 break; \
164 \ 164 \
165 default: \ 165 default: \
166 pixel = 0; /* prevent gcc from complaining */ \ 166 Pixel = 0; /* prevent gcc from complaining */ \
167 break; \ 167 break; \
168 } \ 168 } \
169 RGB_FROM_PIXEL(pixel, fmt, r, g, b); \ 169 RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
170 } while(0) 170 } while(0)
171 171
172 /* Assemble R-G-B values into a specified pixel format and store them */ 172 /* Assemble R-G-B values into a specified pixel format and store them */
173 #define PIXEL_FROM_RGB(pixel, fmt, r, g, b) \ 173 #define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \
174 { \ 174 { \
175 pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ 175 Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
176 ((g>>fmt->Gloss)<<fmt->Gshift)| \ 176 ((g>>fmt->Gloss)<<fmt->Gshift)| \
177 ((b>>fmt->Bloss)<<fmt->Bshift); \ 177 ((b>>fmt->Bloss)<<fmt->Bshift); \
178 } 178 }
179 #define RGB565_FROM_RGB(pixel, r, g, b) \ 179 #define RGB565_FROM_RGB(Pixel, r, g, b) \
180 { \ 180 { \
181 pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \ 181 Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \
182 } 182 }
183 #define RGB555_FROM_RGB(pixel, r, g, b) \ 183 #define RGB555_FROM_RGB(Pixel, r, g, b) \
184 { \ 184 { \
185 pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \ 185 Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \
186 } 186 }
187 #define RGB888_FROM_RGB(pixel, r, g, b) \ 187 #define RGB888_FROM_RGB(Pixel, r, g, b) \
188 { \ 188 { \
189 pixel = (r<<16)|(g<<8)|b; \ 189 Pixel = (r<<16)|(g<<8)|b; \
190 } 190 }
191 #define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \ 191 #define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \
192 { \ 192 { \
193 switch (bpp) { \ 193 switch (bpp) { \
194 case 2: { \ 194 case 2: { \
195 Uint16 pixel; \ 195 Uint16 Pixel; \
196 \ 196 \
197 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ 197 PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
198 *((Uint16 *)(buf)) = pixel; \ 198 *((Uint16 *)(buf)) = Pixel; \
199 } \ 199 } \
200 break; \ 200 break; \
201 \ 201 \
202 case 3: { \ 202 case 3: { \
203 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ 203 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
211 } \ 211 } \
212 } \ 212 } \
213 break; \ 213 break; \
214 \ 214 \
215 case 4: { \ 215 case 4: { \
216 Uint32 pixel; \ 216 Uint32 Pixel; \
217 \ 217 \
218 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ 218 PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
219 *((Uint32 *)(buf)) = pixel; \ 219 *((Uint32 *)(buf)) = Pixel; \
220 } \ 220 } \
221 break; \ 221 break; \
222 } \ 222 } \
223 } 223 }
224 #define ASSEMBLE_RGB_AMASK(buf, bpp, fmt, r, g, b, Amask) \ 224 #define ASSEMBLE_RGB_AMASK(buf, bpp, fmt, r, g, b, Amask) \
225 { \ 225 { \
226 switch (bpp) { \ 226 switch (bpp) { \
227 case 2: { \ 227 case 2: { \
228 Uint16 *bufp; \ 228 Uint16 *bufp; \
229 Uint16 pixel; \ 229 Uint16 Pixel; \
230 \ 230 \
231 bufp = (Uint16 *)buf; \ 231 bufp = (Uint16 *)buf; \
232 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ 232 PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
233 *bufp = pixel | (*bufp & Amask); \ 233 *bufp = Pixel | (*bufp & Amask); \
234 } \ 234 } \
235 break; \ 235 break; \
236 \ 236 \
237 case 3: { \ 237 case 3: { \
238 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ 238 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
247 } \ 247 } \
248 break; \ 248 break; \
249 \ 249 \
250 case 4: { \ 250 case 4: { \
251 Uint32 *bufp; \ 251 Uint32 *bufp; \
252 Uint32 pixel; \ 252 Uint32 Pixel; \
253 \ 253 \
254 bufp = (Uint32 *)buf; \ 254 bufp = (Uint32 *)buf; \
255 PIXEL_FROM_RGB(pixel, fmt, r, g, b); \ 255 PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
256 *bufp = pixel | (*bufp & Amask); \ 256 *bufp = Pixel | (*bufp & Amask); \
257 } \ 257 } \
258 break; \ 258 break; \
259 } \ 259 } \
260 } 260 }
261 261
262 /* FIXME: Should we rescale alpha into 0..255 here? */ 262 /* FIXME: Should we rescale alpha into 0..255 here? */
263 #define RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a) \ 263 #define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a) \
264 { \ 264 { \
265 r = ((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; \ 265 r = ((Pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; \
266 g = ((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; \ 266 g = ((Pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; \
267 b = ((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; \ 267 b = ((Pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; \
268 a = ((pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss; \ 268 a = ((Pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss; \
269 } 269 }
270 #define RGBA_FROM_8888(pixel, fmt, r, g, b, a) \ 270 #define RGBA_FROM_8888(Pixel, fmt, r, g, b, a) \
271 { \ 271 { \
272 r = (pixel&fmt->Rmask)>>fmt->Rshift; \ 272 r = (Pixel&fmt->Rmask)>>fmt->Rshift; \
273 g = (pixel&fmt->Gmask)>>fmt->Gshift; \ 273 g = (Pixel&fmt->Gmask)>>fmt->Gshift; \
274 b = (pixel&fmt->Bmask)>>fmt->Bshift; \ 274 b = (Pixel&fmt->Bmask)>>fmt->Bshift; \
275 a = (pixel&fmt->Amask)>>fmt->Ashift; \ 275 a = (Pixel&fmt->Amask)>>fmt->Ashift; \
276 } 276 }
277 #define RGBA_FROM_RGBA8888(pixel, r, g, b, a) \ 277 #define RGBA_FROM_RGBA8888(Pixel, r, g, b, a) \
278 { \ 278 { \
279 r = (pixel>>24); \ 279 r = (Pixel>>24); \
280 g = ((pixel>>16)&0xFF); \ 280 g = ((Pixel>>16)&0xFF); \
281 b = ((pixel>>8)&0xFF); \ 281 b = ((Pixel>>8)&0xFF); \
282 a = (pixel&0xFF); \ 282 a = (Pixel&0xFF); \
283 } 283 }
284 #define RGBA_FROM_ARGB8888(pixel, r, g, b, a) \ 284 #define RGBA_FROM_ARGB8888(Pixel, r, g, b, a) \
285 { \ 285 { \
286 r = ((pixel>>16)&0xFF); \ 286 r = ((Pixel>>16)&0xFF); \
287 g = ((pixel>>8)&0xFF); \ 287 g = ((Pixel>>8)&0xFF); \
288 b = (pixel&0xFF); \ 288 b = (Pixel&0xFF); \
289 a = (pixel>>24); \ 289 a = (Pixel>>24); \
290 } 290 }
291 #define RGBA_FROM_ABGR8888(pixel, r, g, b, a) \ 291 #define RGBA_FROM_ABGR8888(Pixel, r, g, b, a) \
292 { \ 292 { \
293 r = (pixel&0xFF); \ 293 r = (Pixel&0xFF); \
294 g = ((pixel>>8)&0xFF); \ 294 g = ((Pixel>>8)&0xFF); \
295 b = ((pixel>>16)&0xFF); \ 295 b = ((Pixel>>16)&0xFF); \
296 a = (pixel>>24); \ 296 a = (Pixel>>24); \
297 } 297 }
298 #define DISEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a) \ 298 #define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a) \
299 do { \ 299 do { \
300 switch (bpp) { \ 300 switch (bpp) { \
301 case 2: \ 301 case 2: \
302 pixel = *((Uint16 *)(buf)); \ 302 Pixel = *((Uint16 *)(buf)); \
303 break; \ 303 break; \
304 \ 304 \
305 case 3: {/* FIXME: broken code (no alpha) */ \ 305 case 3: {/* FIXME: broken code (no alpha) */ \
306 Uint8 *b = (Uint8 *)buf; \ 306 Uint8 *b = (Uint8 *)buf; \
307 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ 307 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
308 pixel = b[0] + (b[1] << 8) + (b[2] << 16); \ 308 Pixel = b[0] + (b[1] << 8) + (b[2] << 16); \
309 } else { \ 309 } else { \
310 pixel = (b[0] << 16) + (b[1] << 8) + b[2]; \ 310 Pixel = (b[0] << 16) + (b[1] << 8) + b[2]; \
311 } \ 311 } \
312 } \ 312 } \
313 break; \ 313 break; \
314 \ 314 \
315 case 4: \ 315 case 4: \
316 pixel = *((Uint32 *)(buf)); \ 316 Pixel = *((Uint32 *)(buf)); \
317 break; \ 317 break; \
318 \ 318 \
319 default: \ 319 default: \
320 pixel = 0; /* stop gcc complaints */ \ 320 Pixel = 0; /* stop gcc complaints */ \
321 break; \ 321 break; \
322 } \ 322 } \
323 RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a); \ 323 RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
324 pixel &= ~fmt->Amask; \ 324 Pixel &= ~fmt->Amask; \
325 } while(0) 325 } while(0)
326 326
327 /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */ 327 /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
328 #define PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a) \ 328 #define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
329 { \ 329 { \
330 pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ 330 Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
331 ((g>>fmt->Gloss)<<fmt->Gshift)| \ 331 ((g>>fmt->Gloss)<<fmt->Gshift)| \
332 ((b>>fmt->Bloss)<<fmt->Bshift)| \ 332 ((b>>fmt->Bloss)<<fmt->Bshift)| \
333 ((a>>fmt->Aloss)<<fmt->Ashift); \ 333 ((a>>fmt->Aloss)<<fmt->Ashift); \
334 } 334 }
335 #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \ 335 #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
336 { \ 336 { \
337 switch (bpp) { \ 337 switch (bpp) { \
338 case 2: { \ 338 case 2: { \
339 Uint16 pixel; \ 339 Uint16 Pixel; \
340 \ 340 \
341 PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \ 341 PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a); \
342 *((Uint16 *)(buf)) = pixel; \ 342 *((Uint16 *)(buf)) = Pixel; \
343 } \ 343 } \
344 break; \ 344 break; \
345 \ 345 \
346 case 3: { /* FIXME: broken code (no alpha) */ \ 346 case 3: { /* FIXME: broken code (no alpha) */ \
347 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ 347 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
355 } \ 355 } \
356 } \ 356 } \
357 break; \ 357 break; \
358 \ 358 \
359 case 4: { \ 359 case 4: { \
360 Uint32 pixel; \ 360 Uint32 Pixel; \
361 \ 361 \
362 PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \ 362 PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a); \
363 *((Uint32 *)(buf)) = pixel; \ 363 *((Uint32 *)(buf)) = Pixel; \
364 } \ 364 } \
365 break; \ 365 break; \
366 } \ 366 } \
367 } 367 }
368 368
369 /* Blend the RGB values of two pixels based on a source alpha value */ 369 /* Blend the RGB values of two Pixels based on a source alpha value */
370 #define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \ 370 #define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \
371 do { \ 371 do { \
372 dR = (((sR-dR)*(A))>>8)+dR; \ 372 dR = (((sR-dR)*(A))>>8)+dR; \
373 dG = (((sG-dG)*(A))>>8)+dG; \ 373 dG = (((sG-dG)*(A))>>8)+dG; \
374 dB = (((sB-dB)*(A))>>8)+dB; \ 374 dB = (((sB-dB)*(A))>>8)+dB; \
375 } while(0) 375 } while(0)
376 376
377 /* Blend the RGB values of two pixels based on a source alpha value */ 377 /* Blend the RGB values of two Pixels based on a source alpha value */
378 #define ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB) \ 378 #define ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB) \
379 do { \ 379 do { \
380 unsigned tR, tG, tB, tA; \ 380 unsigned tR, tG, tB, tA; \
381 tA = 255 - sA; \ 381 tA = 255 - sA; \
382 tR = 1 + (sR * sA) + (dR * tA); \ 382 tR = 1 + (sR * sA) + (dR * tA); \