annotate src/video/SDL_blendline.c @ 2898:e40448bc7727

Share code between fill and line drawing Added general RGB surface format fallbacks to drawing code Fixed issues with destination surface alpha channel
author Sam Lantinga <slouken@libsdl.org>
date Sun, 21 Dec 2008 08:28:25 +0000
parents 1ef2f1e75ff7
children a0c837a16e4c
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
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
24 #include "SDL_draw.h"
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
25
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
26 static int
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
27 SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
28 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
29 {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
30 unsigned inva = 0xff - a;
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
32 switch (blendMode) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
33 case SDL_BLENDMODE_BLEND:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
34 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB555);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
35 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
36 case SDL_BLENDMODE_ADD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
37 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB555);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
38 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
39 case SDL_BLENDMODE_MOD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
40 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB555);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
41 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
42 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
43 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB555);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
44 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
45 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
46 return 0;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
47 }
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
48
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
49 static int
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
50 SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
51 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
52 {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
53 unsigned inva = 0xff - a;
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
54
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
55 switch (blendMode) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
56 case SDL_BLENDMODE_BLEND:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
57 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB565);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
58 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
59 case SDL_BLENDMODE_ADD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
60 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB565);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
61 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
62 case SDL_BLENDMODE_MOD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
63 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB565);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
64 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
65 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
66 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB565);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
67 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
68 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
69 return 0;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
70 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
71
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
72 static int
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
73 SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
74 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
75 {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
76 unsigned inva = 0xff - a;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
77
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
78 switch (blendMode) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
79 case SDL_BLENDMODE_BLEND:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
80 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB888);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
81 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
82 case SDL_BLENDMODE_ADD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
83 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB888);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
84 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
85 case SDL_BLENDMODE_MOD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
86 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB888);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
87 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
88 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
89 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB888);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
90 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
91 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
92 return 0;
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
93 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
94
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
95 static int
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
96 SDL_BlendLine_RGB(SDL_Surface * dst, int x1, int y1, int x2, int y2,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
97 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
98 {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
99 SDL_PixelFormat *fmt = dst->format;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
100 unsigned inva = 0xff - a;
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
101
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
102 switch (fmt->BytesPerPixel) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
103 case 2:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
104 switch (blendMode) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
105 case SDL_BLENDMODE_BLEND:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
106 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY2_BLEND_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
107 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
108 case SDL_BLENDMODE_ADD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
109 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY2_ADD_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
110 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
111 case SDL_BLENDMODE_MOD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
112 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY2_MOD_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
113 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
114 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
115 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY2_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
116 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
117 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
118 return 0;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
119 case 4:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
120 switch (blendMode) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
121 case SDL_BLENDMODE_BLEND:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
122 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
123 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
124 case SDL_BLENDMODE_ADD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
125 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
126 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
127 case SDL_BLENDMODE_MOD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
128 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
129 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
130 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
131 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGB);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
132 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
133 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
134 return 0;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
135 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
136 SDL_Unsupported();
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
137 return -1;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
138 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
139 }
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
140
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
141 static int
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
142 SDL_BlendLine_RGBA(SDL_Surface * dst, int x1, int y1, int x2, int y2,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
143 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
144 {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
145 SDL_PixelFormat *fmt = dst->format;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
146 unsigned inva = 0xff - a;
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
147
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
148 switch (fmt->BytesPerPixel) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
149 case 4:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
150 switch (blendMode) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
151 case SDL_BLENDMODE_BLEND:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
152 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGBA);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
153 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
154 case SDL_BLENDMODE_ADD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
155 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGBA);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
156 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
157 case SDL_BLENDMODE_MOD:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
158 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGBA);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
159 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
160 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
161 BRESENHAM(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGBA);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
162 break;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
163 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
164 return 0;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
165 default:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
166 SDL_Unsupported();
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
167 return -1;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
168 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
169 }
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 int
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 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
173 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
174 {
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
175 SDL_PixelFormat *fmt = dst->format;
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
176
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 /* 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
178 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
179 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
180 return (-1);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 /* Perform clipping */
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 /* FIXME
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 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
186 return (0);
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 */
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
190 if ((blendMode == SDL_BLENDMODE_BLEND)
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
191 || (blendMode == SDL_BLENDMODE_ADD)) {
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
192 r = DRAW_MUL(r, a);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
193 g = DRAW_MUL(g, a);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
194 b = DRAW_MUL(b, a);
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
195 }
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
196
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
197 switch (fmt->BitsPerPixel) {
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
198 case 15:
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
199 switch (fmt->Rmask) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
200 case 0x7C00:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
201 return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
202 b, a);
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
203 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
204 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
205 case 16:
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
206 switch (fmt->Rmask) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
207 case 0xF800:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
208 return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
209 b, a);
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
210 }
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
211 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
212 case 32:
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
213 switch (fmt->Rmask) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
214 case 0x00FF0000:
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
215 if (!fmt->Amask) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
216 return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
217 g, b, a);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
218 }
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
219 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
220 }
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
221 default:
2896
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
222 break;
1ef2f1e75ff7 Date: Sat, 20 Dec 2008 23:25:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2888
diff changeset
223 }
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
224
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
225 if (!fmt->Amask) {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
226 return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
227 } else {
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
228 return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2896
diff changeset
229 }
2888
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 }
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231
32e8bbba1e94 Added stubs for software implementations of blending fills and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 /* vi: set ts=4 sw=4 expandtab: */