annotate src/video/SDL_blendline.c @ 2896:1ef2f1e75ff7

Date: Sat, 20 Dec 2008 23:25:19 +0100 From: Couriersud Subject: 32 & 16 bit versions of blendrect and blendline attached are 32, 16 and 15 bit versions of the blendrect and blendline functionality. There was an issue with the bresenham alg. in drawline which I also fixed.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 20 Dec 2008 23:19:20 +0000
parents 32e8bbba1e94
children e40448bc7727
rev   line source
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_video.h"
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_blit.h"
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
27 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
28
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
29 #define SWAP(_x, _y) do { int tmp; tmp = _x; _x = _y; _y = tmp; } while (0)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
30
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
31 #define BRESENHAM(x0, y0, x1, y1, op) \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
32 { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
33 int deltax, deltay, steep, error, xstep, ystep, x, y; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
34 \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
35 deltax = ABS(x1 - x0); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
36 deltay = ABS(y1 - y0); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
37 steep = (deltay > deltax); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
38 if (steep) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
39 SWAP(x0, y0); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
40 SWAP(x1, y1); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
41 SWAP(deltax, deltay); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
42 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
43 error = (x1 - x0) / 2; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
44 y = y0; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
45 if (x0 > x1) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
46 xstep = -1; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
47 } else { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
48 xstep = 1; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
49 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
50 if (y0 < y1) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
51 ystep = 1; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
52 } else { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
53 ystep = -1; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
54 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
55 if (!steep) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
56 for (x = x0; x != x1; x += xstep) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
57 op(x, y); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
58 error -= deltay; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
59 if (error < 0) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
60 y += ystep; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
61 error += deltax; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
62 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
63 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
64 } else { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
65 for (x = x0; x != x1; x += xstep) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
66 op(y, x); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
67 error -= deltay; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
68 if (error < 0) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
69 y += ystep; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
70 error += deltax; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
71 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
72 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
73 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
74 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
75
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
76 #define MUL(_a, _b) (((Uint16)(_a)*(Uint16)(_b))/255)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
77 #define SHIFTAND(_v, _s, _a) (((_v)>>(_s)) & _a)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
78
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
79 #define SETPIXEL_MASK(x, y, type, bpp, rshift, gshift, bshift, rmask, gmask, bmask) \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
80 do { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
81 type *pixel = (type *)(dst->pixels + y * dst->pitch + x * bpp); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
82 if (a) { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
83 *pixel = (r<<rshift) | (g<<gshift) | (b<<bshift); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
84 } \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
85 } while (0)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
86
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
87 #define SETPIXEL_BLEND(x, y, type, bpp, rshift, gshift, bshift, rmask, gmask, bmask) \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
88 do { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
89 type *pixel = (type *)(dst->pixels + y * dst->pitch + x * bpp); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
90 Uint8 sr = MUL(inva, SHIFTAND(*pixel, rshift, rmask)) + (Uint16) r; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
91 Uint8 sg = MUL(inva, SHIFTAND(*pixel, gshift, gmask)) + (Uint16) g; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
92 Uint8 sb = MUL(inva, SHIFTAND(*pixel, bshift, bmask)) + (Uint16) b; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
93 *pixel = (sr<<rshift) | (sg<<gshift) | (sb<<bshift); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
94 } while (0)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
95
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
96 #define SETPIXEL_ADD(x, y, type, bpp, rshift, gshift, bshift, rmask, gmask, bmask) \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
97 do { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
98 type *pixel = (type *)(dst->pixels + y * dst->pitch + x * bpp); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
99 Uint16 sr = SHIFTAND(*pixel, rshift, rmask) + (Uint16) r; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
100 Uint16 sg = SHIFTAND(*pixel, gshift, gmask) + (Uint16) g; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
101 Uint16 sb = SHIFTAND(*pixel, bshift, bmask) + (Uint16) b; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
102 if (sr>rmask) sr = rmask; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
103 if (sg>gmask) sg = gmask; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
104 if (sb>bmask) sb = bmask; \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
105 *pixel = (sr<<rshift) | (sg<<gshift) | (sb<<bshift); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
106 } while (0)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
107
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
108 #define SETPIXEL_MOD(x, y, type, bpp, rshift, gshift, bshift, rmask, gmask, bmask) \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
109 do { \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
110 type *pixel = (type *)(dst->pixels + y * dst->pitch + x * bpp); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
111 Uint8 sr = MUL(SHIFTAND(*pixel, rshift, rmask), r); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
112 Uint8 sg = MUL(SHIFTAND(*pixel, gshift, gmask), g); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
113 Uint8 sb = MUL(SHIFTAND(*pixel, bshift, bmask), b); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
114 *pixel = (sr<<rshift) | (sg<<gshift) | (sb<<bshift); \
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
115 } while (0)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
116
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
117
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
118 #define SETPIXEL15_MASK(x, y) SETPIXEL_MASK(x, y, Uint16, 2, 10, 5, 0, 0x1f, 0x1f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
119 #define SETPIXEL15_BLEND(x, y) SETPIXEL_BLEND(x, y, Uint16, 2, 10, 5, 0, 0x1f, 0x1f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
120 #define SETPIXEL15_ADD(x, y) SETPIXEL_ADD(x, y, Uint16, 2, 10, 5, 0, 0x1f, 0x1f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
121 #define SETPIXEL15_MOD(x, y) SETPIXEL_MOD(x, y, Uint16, 2, 10, 5, 0, 0x1f, 0x1f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
122
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
123 #define SETPIXEL16_MASK(x, y) SETPIXEL_MASK(x, y, Uint16, 2, 11, 5, 0, 0x1f, 0x3f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
124 #define SETPIXEL16_BLEND(x, y) SETPIXEL_BLEND(x, y, Uint16, 2, 11, 5, 0, 0x1f, 0x3f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
125 #define SETPIXEL16_ADD(x, y) SETPIXEL_ADD(x, y, Uint16, 2, 11, 5, 0, 0x1f, 0x3f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
126 #define SETPIXEL16_MOD(x, y) SETPIXEL_MOD(x, y, Uint16, 2, 11, 5, 0, 0x1f, 0x3f, 0x1f);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
127
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
128 #define SETPIXEL32_MASK(x, y) SETPIXEL_MASK(x, y, Uint32, 4, 16, 8, 0, 0xff, 0xff, 0xff);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
129 #define SETPIXEL32_BLEND(x, y) SETPIXEL_BLEND(x, y, Uint32, 4, 16, 8, 0, 0xff, 0xff, 0xff);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
130 #define SETPIXEL32_ADD(x, y) SETPIXEL_ADD(x, y, Uint32, 4, 16, 8, 0, 0xff, 0xff, 0xff);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
131 #define SETPIXEL32_MOD(x, y) SETPIXEL_MOD(x, y, Uint32, 4, 16, 8, 0, 0xff, 0xff, 0xff);
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 int
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 {
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
137 Uint8 inva = 0xff - a;
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 /* This function doesn't work on surfaces < 8 bpp */
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 if (dst->format->BitsPerPixel < 8) {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 SDL_SetError("SDL_BlendLine(): Unsupported surface format");
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 return (-1);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 /* Perform clipping */
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 /* FIXME
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) {
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 return (0);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 */
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
151 if ((blendMode == SDL_BLENDMODE_BLEND)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
152 || (blendMode == SDL_BLENDMODE_ADD)) {
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
153 r = MUL(r, a);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
154 g = MUL(g, a);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
155 b = MUL(b, a);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
156 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
157 switch (dst->format->BitsPerPixel) {
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
158 case 15:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
159 switch (blendMode) {
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
160 case SDL_BLENDMODE_MASK:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
161 BRESENHAM(x1, y1, x2, y2, SETPIXEL15_MASK);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
162 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
163 case SDL_BLENDMODE_BLEND:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
164 BRESENHAM(x1, y1, x2, y2, SETPIXEL15_BLEND);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
165 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
166 case SDL_BLENDMODE_ADD:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
167 BRESENHAM(x1, y1, x2, y2, SETPIXEL15_ADD);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
168 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
169 case SDL_BLENDMODE_MOD:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
170 BRESENHAM(x1, y1, x2, y2, SETPIXEL15_MOD);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
171 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
172 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
173 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
174 case 16:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
175 switch (blendMode) {
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
176 case SDL_BLENDMODE_MASK:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
177 BRESENHAM(x1, y1, x2, y2, SETPIXEL16_MASK);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
178 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
179 case SDL_BLENDMODE_BLEND:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
180 BRESENHAM(x1, y1, x2, y2, SETPIXEL16_BLEND);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
181 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
182 case SDL_BLENDMODE_ADD:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
183 BRESENHAM(x1, y1, x2, y2, SETPIXEL16_ADD);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
184 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
185 case SDL_BLENDMODE_MOD:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
186 BRESENHAM(x1, y1, x2, y2, SETPIXEL16_MOD);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
187 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
188 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
189 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
190 case 24:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
191 case 32:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
192 if (dst->format->BytesPerPixel != 4) {
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
193 SDL_Unsupported();
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
194 return -1;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
195 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
196 switch (blendMode) {
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
197 case SDL_BLENDMODE_MASK:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
198 BRESENHAM(x1, y1, x2, y2, SETPIXEL32_MASK);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
199 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
200 case SDL_BLENDMODE_BLEND:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
201 BRESENHAM(x1, y1, x2, y2, SETPIXEL32_BLEND);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
202 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
203 case SDL_BLENDMODE_ADD:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
204 BRESENHAM(x1, y1, x2, y2, SETPIXEL32_ADD);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
205 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
206 case SDL_BLENDMODE_MOD:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
207 BRESENHAM(x1, y1, x2, y2, SETPIXEL32_MOD);
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
208 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
209 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
210 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
211 default:
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
212 SDL_Unsupported();
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
213 return -1;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
214 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
215 return 0;
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 /* vi: set ts=4 sw=4 expandtab: */