comparison src/video/SDL_blendpoint.c @ 3536:0267b8b1595c

Added interfaces for batch drawing of points, lines and rects: SDL_DrawPoints() SDL_BlendPoints() SDL_BlendLines() SDL_DrawLines() SDL_FillRects() SDL_BlendRects() SDL_RenderPoints() SDL_RenderLines() SDL_RenderRects() Renamed SDL_RenderFill() to SDL_RenderRect()
author Sam Lantinga <slouken@libsdl.org>
date Wed, 09 Dec 2009 15:56:56 +0000
parents 133601e3b255
children f7b03b6838cb
comparison
equal deleted inserted replaced
3535:b403f790df65 3536:0267b8b1595c
193 193
194 int 194 int
195 SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r, 195 SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
196 Uint8 g, Uint8 b, Uint8 a) 196 Uint8 g, Uint8 b, Uint8 a)
197 { 197 {
198 SDL_PixelFormat *fmt = dst->format; 198 if (!dst) {
199 SDL_SetError("Passed NULL destination surface");
200 return -1;
201 }
199 202
200 /* This function doesn't work on surfaces < 8 bpp */ 203 /* This function doesn't work on surfaces < 8 bpp */
201 if (dst->format->BitsPerPixel < 8) { 204 if (dst->format->BitsPerPixel < 8) {
202 SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); 205 SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
203 return (-1); 206 return -1;
204 } 207 }
205 208
206 /* Perform clipping */ 209 /* Perform clipping */
207 if (x < dst->clip_rect.x || y < dst->clip_rect.y || 210 if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
208 x >= (dst->clip_rect.x + dst->clip_rect.w) || 211 x >= (dst->clip_rect.x + dst->clip_rect.w) ||
209 y >= (dst->clip_rect.y + dst->clip_rect.h)) { 212 y >= (dst->clip_rect.y + dst->clip_rect.h)) {
210 return 0; 213 return 0;
211 } 214 }
212 215
213 if ((blendMode == SDL_BLENDMODE_BLEND) 216 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
214 || (blendMode == SDL_BLENDMODE_ADD)) {
215 r = DRAW_MUL(r, a); 217 r = DRAW_MUL(r, a);
216 g = DRAW_MUL(g, a); 218 g = DRAW_MUL(g, a);
217 b = DRAW_MUL(b, a); 219 b = DRAW_MUL(b, a);
218 } 220 }
219 221
220 switch (fmt->BitsPerPixel) { 222 switch (dst->format->BitsPerPixel) {
221 case 15: 223 case 15:
222 switch (fmt->Rmask) { 224 switch (dst->format->Rmask) {
223 case 0x7C00: 225 case 0x7C00:
224 return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a); 226 return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
225 } 227 }
226 break; 228 break;
227 case 16: 229 case 16:
228 switch (fmt->Rmask) { 230 switch (dst->format->Rmask) {
229 case 0xF800: 231 case 0xF800:
230 return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a); 232 return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
231 } 233 }
232 break; 234 break;
233 case 32: 235 case 32:
234 switch (fmt->Rmask) { 236 switch (dst->format->Rmask) {
235 case 0x00FF0000: 237 case 0x00FF0000:
236 if (!fmt->Amask) { 238 if (!dst->format->Amask) {
237 return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b, 239 return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b,
238 a); 240 a);
239 } else { 241 } else {
240 return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, 242 return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b,
241 a); 243 a);
242 } 244 }
243 break; 245 break;
244 } 246 }
245 default: 247 break;
246 break; 248 default:
247 } 249 break;
248 250 }
249 if (!fmt->Amask) { 251
252 if (!dst->format->Amask) {
250 return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a); 253 return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
251 } else { 254 } else {
252 return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a); 255 return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
253 } 256 }
254 } 257 }
255 258
259 int
260 SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
261 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
262 {
263 int minx, miny;
264 int maxx, maxy;
265 int i;
266 int x, y;
267 int (*func)(SDL_Surface * dst, int x, int y,
268 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
269 int status = 0;
270
271 if (!dst) {
272 SDL_SetError("Passed NULL destination surface");
273 return -1;
274 }
275
276 /* This function doesn't work on surfaces < 8 bpp */
277 if (dst->format->BitsPerPixel < 8) {
278 SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
279 return (-1);
280 }
281
282 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
283 r = DRAW_MUL(r, a);
284 g = DRAW_MUL(g, a);
285 b = DRAW_MUL(b, a);
286 }
287
288 /* FIXME: Does this function pointer slow things down significantly? */
289 switch (dst->format->BitsPerPixel) {
290 case 15:
291 switch (dst->format->Rmask) {
292 case 0x7C00:
293 func = SDL_BlendPoint_RGB555;
294 break;
295 }
296 break;
297 case 16:
298 switch (dst->format->Rmask) {
299 case 0xF800:
300 func = SDL_BlendPoint_RGB565;
301 break;
302 }
303 break;
304 case 32:
305 switch (dst->format->Rmask) {
306 case 0x00FF0000:
307 if (!dst->format->Amask) {
308 func = SDL_BlendPoint_RGB888;
309 } else {
310 func = SDL_BlendPoint_ARGB8888;
311 }
312 break;
313 }
314 break;
315 default:
316 break;
317 }
318
319 if (!func) {
320 if (!dst->format->Amask) {
321 func = SDL_BlendPoint_RGB;
322 } else {
323 func = SDL_BlendPoint_RGBA;
324 }
325 }
326
327 minx = dst->clip_rect.x;
328 maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
329 miny = dst->clip_rect.y;
330 maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
331
332 for (i = 0; i < count; ++i) {
333 x = points[i].x;
334 y = points[i].y;
335
336 if (x < minx || x > maxx || y < miny || y > maxy) {
337 continue;
338 }
339 status = func(dst, x, y, blendMode, r, g, b, a);
340 }
341 return status;
342 }
343
256 /* vi: set ts=4 sw=4 expandtab: */ 344 /* vi: set ts=4 sw=4 expandtab: */