SDL  2.0
SDL_blendfillrect.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
24 
25 #include "SDL_draw.h"
26 #include "SDL_blendfillrect.h"
27 
28 
29 static int
32 {
33  unsigned inva = 0xff - a;
34 
35  switch (blendMode) {
38  break;
39  case SDL_BLENDMODE_ADD:
41  break;
42  case SDL_BLENDMODE_MOD:
44  break;
45  case SDL_BLENDMODE_MUL:
47  break;
48  default:
50  break;
51  }
52  return 0;
53 }
54 
55 static int
58 {
59  unsigned inva = 0xff - a;
60 
61  switch (blendMode) {
64  break;
65  case SDL_BLENDMODE_ADD:
67  break;
68  case SDL_BLENDMODE_MOD:
70  break;
71  case SDL_BLENDMODE_MUL:
73  break;
74  default:
76  break;
77  }
78  return 0;
79 }
80 
81 static int
84 {
85  unsigned inva = 0xff - a;
86 
87  switch (blendMode) {
90  break;
91  case SDL_BLENDMODE_ADD:
93  break;
94  case SDL_BLENDMODE_MOD:
96  break;
97  case SDL_BLENDMODE_MUL:
99  break;
100  default:
102  break;
103  }
104  return 0;
105 }
106 
107 static int
110 {
111  unsigned inva = 0xff - a;
112 
113  switch (blendMode) {
114  case SDL_BLENDMODE_BLEND:
116  break;
117  case SDL_BLENDMODE_ADD:
119  break;
120  case SDL_BLENDMODE_MOD:
122  break;
123  case SDL_BLENDMODE_MUL:
125  break;
126  default:
128  break;
129  }
130  return 0;
131 }
132 
133 static int
136 {
137  SDL_PixelFormat *fmt = dst->format;
138  unsigned inva = 0xff - a;
139 
140  switch (fmt->BytesPerPixel) {
141  case 2:
142  switch (blendMode) {
143  case SDL_BLENDMODE_BLEND:
145  break;
146  case SDL_BLENDMODE_ADD:
148  break;
149  case SDL_BLENDMODE_MOD:
151  break;
152  case SDL_BLENDMODE_MUL:
154  break;
155  default:
157  break;
158  }
159  return 0;
160  case 4:
161  switch (blendMode) {
162  case SDL_BLENDMODE_BLEND:
164  break;
165  case SDL_BLENDMODE_ADD:
167  break;
168  case SDL_BLENDMODE_MOD:
170  break;
171  case SDL_BLENDMODE_MUL:
173  break;
174  default:
176  break;
177  }
178  return 0;
179  default:
180  return SDL_Unsupported();
181  }
182 }
183 
184 static int
187 {
188  SDL_PixelFormat *fmt = dst->format;
189  unsigned inva = 0xff - a;
190 
191  switch (fmt->BytesPerPixel) {
192  case 4:
193  switch (blendMode) {
194  case SDL_BLENDMODE_BLEND:
196  break;
197  case SDL_BLENDMODE_ADD:
199  break;
200  case SDL_BLENDMODE_MOD:
202  break;
203  case SDL_BLENDMODE_MUL:
205  break;
206  default:
208  break;
209  }
210  return 0;
211  default:
212  return SDL_Unsupported();
213  }
214 }
215 
216 int
219 {
220  SDL_Rect clipped;
221 
222  if (!dst) {
223  return SDL_SetError("Passed NULL destination surface");
224  }
225 
226  /* This function doesn't work on surfaces < 8 bpp */
227  if (dst->format->BitsPerPixel < 8) {
228  return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
229  }
230 
231  /* If 'rect' == NULL, then fill the whole surface */
232  if (rect) {
233  /* Perform clipping */
234  if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
235  return 0;
236  }
237  rect = &clipped;
238  } else {
239  rect = &dst->clip_rect;
240  }
241 
243  r = DRAW_MUL(r, a);
244  g = DRAW_MUL(g, a);
245  b = DRAW_MUL(b, a);
246  }
247 
248  switch (dst->format->BitsPerPixel) {
249  case 15:
250  switch (dst->format->Rmask) {
251  case 0x7C00:
253  }
254  break;
255  case 16:
256  switch (dst->format->Rmask) {
257  case 0xF800:
259  }
260  break;
261  case 32:
262  switch (dst->format->Rmask) {
263  case 0x00FF0000:
264  if (!dst->format->Amask) {
266  } else {
268  }
269  /* break; -Wunreachable-code-break */
270  }
271  break;
272  default:
273  break;
274  }
275 
276  if (!dst->format->Amask) {
277  return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
278  } else {
279  return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
280  }
281 }
282 
283 int
286 {
287  SDL_Rect rect;
288  int i;
289  int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
291  int status = 0;
292 
293  if (!dst) {
294  return SDL_SetError("Passed NULL destination surface");
295  }
296 
297  /* This function doesn't work on surfaces < 8 bpp */
298  if (dst->format->BitsPerPixel < 8) {
299  return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
300  }
301 
303  r = DRAW_MUL(r, a);
304  g = DRAW_MUL(g, a);
305  b = DRAW_MUL(b, a);
306  }
307 
308  /* FIXME: Does this function pointer slow things down significantly? */
309  switch (dst->format->BitsPerPixel) {
310  case 15:
311  switch (dst->format->Rmask) {
312  case 0x7C00:
314  }
315  break;
316  case 16:
317  switch (dst->format->Rmask) {
318  case 0xF800:
320  }
321  break;
322  case 32:
323  switch (dst->format->Rmask) {
324  case 0x00FF0000:
325  if (!dst->format->Amask) {
327  } else {
329  }
330  break;
331  }
332  break;
333  default:
334  break;
335  }
336 
337  if (!func) {
338  if (!dst->format->Amask) {
340  } else {
342  }
343  }
344 
345  for (i = 0; i < count; ++i) {
346  /* Perform clipping */
347  if (!SDL_IntersectRect(&rects[i], &dst->clip_rect, &rect)) {
348  continue;
349  }
350  status = func(dst, &rect, blendMode, r, g, b, a);
351  }
352  return status;
353 }
354 
355 #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
356 
357 /* vi: set ts=4 sw=4 expandtab: */
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179
DRAW_SETPIXEL_ARGB8888
#define DRAW_SETPIXEL_ARGB8888
Definition: SDL_draw.h:219
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:323
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
blendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:71
DRAW_SETPIXEL_RGB
#define DRAW_SETPIXEL_RGB
Definition: SDL_draw.h:257
SDL_BlendFillRects
int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:284
NULL
#define NULL
Definition: begin_code.h:167
SDL_PixelFormat::format
Uint32 format
Definition: SDL_pixels.h:320
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1112
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1112
DRAW_SETPIXEL_MUL_RGB555
#define DRAW_SETPIXEL_MUL_RGB555
Definition: SDL_draw.h:120
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_BLENDMODE_BLEND
@ SDL_BLENDMODE_BLEND
Definition: SDL_blendmode.h:44
DRAW_SETPIXEL_BLEND_ARGB8888
#define DRAW_SETPIXEL_BLEND_ARGB8888
Definition: SDL_draw.h:222
DRAW_SETPIXEL_BLEND_RGB888
#define DRAW_SETPIXEL_BLEND_RGB888
Definition: SDL_draw.h:184
DRAW_SETPIXEL_MUL_RGB565
#define DRAW_SETPIXEL_MUL_RGB565
Definition: SDL_draw.h:158
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
DRAW_SETPIXEL_MUL_RGB888
#define DRAW_SETPIXEL_MUL_RGB888
Definition: SDL_draw.h:196
SDL_IntersectRect
#define SDL_IntersectRect
Definition: SDL_dynapi_overrides.h:294
DRAW_SETPIXEL_BLEND_RGB555
#define DRAW_SETPIXEL_BLEND_RGB555
Definition: SDL_draw.h:108
DRAW_SETPIXEL_BLEND_RGB565
#define DRAW_SETPIXEL_BLEND_RGB565
Definition: SDL_draw.h:146
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_BlendFillRect_ARGB8888
static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:108
DRAW_SETPIXEL_RGB555
#define DRAW_SETPIXEL_RGB555
Definition: SDL_draw.h:105
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1112
func
GLenum func
Definition: SDL_opengl_glext.h:660
DRAW_SETPIXEL_BLEND_RGBA
#define DRAW_SETPIXEL_BLEND_RGBA
Definition: SDL_draw.h:314
DRAW_SETPIXEL_ADD_RGB
#define DRAW_SETPIXEL_ADD_RGB
Definition: SDL_draw.h:264
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1740
DRAW_SETPIXEL_MOD_ARGB8888
#define DRAW_SETPIXEL_MOD_ARGB8888
Definition: SDL_draw.h:230
DRAW_SETPIXEL_MUL_RGB
#define DRAW_SETPIXEL_MUL_RGB
Definition: SDL_draw.h:272
DRAW_SETPIXEL_MOD_RGB888
#define DRAW_SETPIXEL_MOD_RGB888
Definition: SDL_draw.h:192
SDL_BlendFillRect_RGB888
static int SDL_BlendFillRect_RGB888(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:82
SDL_draw.h
DRAW_SETPIXEL_RGB565
#define DRAW_SETPIXEL_RGB565
Definition: SDL_draw.h:143
DRAW_SETPIXEL_ADD_RGB888
#define DRAW_SETPIXEL_ADD_RGB888
Definition: SDL_draw.h:188
rect
SDL_Rect rect
Definition: testrelative.c:27
SDL_BlendFillRect
int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:217
SDL_BlendFillRect_RGB555
static int SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:30
DRAW_SETPIXEL_ADD_RGB565
#define DRAW_SETPIXEL_ADD_RGB565
Definition: SDL_draw.h:150
DRAW_SETPIXEL_MOD_RGB
#define DRAW_SETPIXEL_MOD_RGB
Definition: SDL_draw.h:268
SDL_BlendFillRect_RGB
static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:134
DRAW_SETPIXEL_ADD_RGBA
#define DRAW_SETPIXEL_ADD_RGBA
Definition: SDL_draw.h:318
DRAW_SETPIXEL_MOD_RGB565
#define DRAW_SETPIXEL_MOD_RGB565
Definition: SDL_draw.h:154
FILLRECT
#define FILLRECT(type, op)
Definition: SDL_draw.h:601
SDL_PixelFormat
Definition: SDL_pixels.h:319
DRAW_SETPIXEL_BLEND_RGB
#define DRAW_SETPIXEL_BLEND_RGB
Definition: SDL_draw.h:260
SDL_BLENDMODE_MUL
@ SDL_BLENDMODE_MUL
Definition: SDL_blendmode.h:53
DRAW_MUL
#define DRAW_MUL(_a, _b)
Definition: SDL_draw.h:29
DRAW_SETPIXEL_ADD_ARGB8888
#define DRAW_SETPIXEL_ADD_ARGB8888
Definition: SDL_draw.h:226
DRAW_SETPIXEL_MUL_RGBA
#define DRAW_SETPIXEL_MUL_RGBA
Definition: SDL_draw.h:326
DRAW_SETPIXEL_MOD_RGBA
#define DRAW_SETPIXEL_MOD_RGBA
Definition: SDL_draw.h:322
SDL_blendfillrect.h
SDL_BlendFillRect_RGBA
static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:185
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
DRAW_SETPIXEL_RGBA
#define DRAW_SETPIXEL_RGBA
Definition: SDL_draw.h:311
DRAW_SETPIXEL_RGB888
#define DRAW_SETPIXEL_RGB888
Definition: SDL_draw.h:181
SDL_Unsupported
#define SDL_Unsupported()
Definition: SDL_error.h:53
rects
EGLSurface EGLint * rects
Definition: eglext.h:282
SDL_BLENDMODE_MOD
@ SDL_BLENDMODE_MOD
Definition: SDL_blendmode.h:50
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_BlendFillRect_RGB565
static int SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_blendfillrect.c:56
SDL_BLENDMODE_ADD
@ SDL_BLENDMODE_ADD
Definition: SDL_blendmode.h:47
SDL_BlendMode
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:41
DRAW_SETPIXEL_MOD_RGB555
#define DRAW_SETPIXEL_MOD_RGB555
Definition: SDL_draw.h:116
DRAW_SETPIXEL_ADD_RGB555
#define DRAW_SETPIXEL_ADD_RGB555
Definition: SDL_draw.h:112
DRAW_SETPIXEL_MUL_ARGB8888
#define DRAW_SETPIXEL_MUL_ARGB8888
Definition: SDL_draw.h:234