2 Simple DirectMedia Layer
3 Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
21 #include "../../SDL_internal.h"
23 #if !SDL_RENDER_DISABLED
26 #include "SDL_blendpoint.h"
30 SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
31 Uint8 g, Uint8 b, Uint8 a)
33 unsigned inva = 0xff - a;
36 case SDL_BLENDMODE_BLEND:
37 DRAW_SETPIXELXY_BLEND_RGB555(x, y);
39 case SDL_BLENDMODE_ADD:
40 DRAW_SETPIXELXY_ADD_RGB555(x, y);
42 case SDL_BLENDMODE_MOD:
43 DRAW_SETPIXELXY_MOD_RGB555(x, y);
46 DRAW_SETPIXELXY_RGB555(x, y);
53 SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
54 Uint8 g, Uint8 b, Uint8 a)
56 unsigned inva = 0xff - a;
59 case SDL_BLENDMODE_BLEND:
60 DRAW_SETPIXELXY_BLEND_RGB565(x, y);
62 case SDL_BLENDMODE_ADD:
63 DRAW_SETPIXELXY_ADD_RGB565(x, y);
65 case SDL_BLENDMODE_MOD:
66 DRAW_SETPIXELXY_MOD_RGB565(x, y);
69 DRAW_SETPIXELXY_RGB565(x, y);
76 SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
77 Uint8 g, Uint8 b, Uint8 a)
79 unsigned inva = 0xff - a;
82 case SDL_BLENDMODE_BLEND:
83 DRAW_SETPIXELXY_BLEND_RGB888(x, y);
85 case SDL_BLENDMODE_ADD:
86 DRAW_SETPIXELXY_ADD_RGB888(x, y);
88 case SDL_BLENDMODE_MOD:
89 DRAW_SETPIXELXY_MOD_RGB888(x, y);
92 DRAW_SETPIXELXY_RGB888(x, y);
99 SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
100 Uint8 r, Uint8 g, Uint8 b, Uint8 a)
102 unsigned inva = 0xff - a;
105 case SDL_BLENDMODE_BLEND:
106 DRAW_SETPIXELXY_BLEND_ARGB8888(x, y);
108 case SDL_BLENDMODE_ADD:
109 DRAW_SETPIXELXY_ADD_ARGB8888(x, y);
111 case SDL_BLENDMODE_MOD:
112 DRAW_SETPIXELXY_MOD_ARGB8888(x, y);
115 DRAW_SETPIXELXY_ARGB8888(x, y);
122 SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
123 Uint8 g, Uint8 b, Uint8 a)
125 SDL_PixelFormat *fmt = dst->format;
126 unsigned inva = 0xff - a;
128 switch (fmt->BytesPerPixel) {
131 case SDL_BLENDMODE_BLEND:
132 DRAW_SETPIXELXY2_BLEND_RGB(x, y);
134 case SDL_BLENDMODE_ADD:
135 DRAW_SETPIXELXY2_ADD_RGB(x, y);
137 case SDL_BLENDMODE_MOD:
138 DRAW_SETPIXELXY2_MOD_RGB(x, y);
141 DRAW_SETPIXELXY2_RGB(x, y);
147 case SDL_BLENDMODE_BLEND:
148 DRAW_SETPIXELXY4_BLEND_RGB(x, y);
150 case SDL_BLENDMODE_ADD:
151 DRAW_SETPIXELXY4_ADD_RGB(x, y);
153 case SDL_BLENDMODE_MOD:
154 DRAW_SETPIXELXY4_MOD_RGB(x, y);
157 DRAW_SETPIXELXY4_RGB(x, y);
162 return SDL_Unsupported();
167 SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
168 Uint8 g, Uint8 b, Uint8 a)
170 SDL_PixelFormat *fmt = dst->format;
171 unsigned inva = 0xff - a;
173 switch (fmt->BytesPerPixel) {
176 case SDL_BLENDMODE_BLEND:
177 DRAW_SETPIXELXY4_BLEND_RGBA(x, y);
179 case SDL_BLENDMODE_ADD:
180 DRAW_SETPIXELXY4_ADD_RGBA(x, y);
182 case SDL_BLENDMODE_MOD:
183 DRAW_SETPIXELXY4_MOD_RGBA(x, y);
186 DRAW_SETPIXELXY4_RGBA(x, y);
191 return SDL_Unsupported();
196 SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
197 Uint8 g, Uint8 b, Uint8 a)
200 return SDL_SetError("Passed NULL destination surface");
203 /* This function doesn't work on surfaces < 8 bpp */
204 if (dst->format->BitsPerPixel < 8) {
205 return SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
208 /* Perform clipping */
209 if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
210 x >= (dst->clip_rect.x + dst->clip_rect.w) ||
211 y >= (dst->clip_rect.y + dst->clip_rect.h)) {
215 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
221 switch (dst->format->BitsPerPixel) {
223 switch (dst->format->Rmask) {
225 return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
229 switch (dst->format->Rmask) {
231 return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
235 switch (dst->format->Rmask) {
237 if (!dst->format->Amask) {
238 return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b, a);
240 return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, a);
242 /* break; -Wunreachable-code-break */
249 if (!dst->format->Amask) {
250 return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
252 return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
257 SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
258 SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
264 int (*func)(SDL_Surface * dst, int x, int y,
265 SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
269 return SDL_SetError("Passed NULL destination surface");
272 /* This function doesn't work on surfaces < 8 bpp */
273 if (dst->format->BitsPerPixel < 8) {
274 return SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
277 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
283 /* FIXME: Does this function pointer slow things down significantly? */
284 switch (dst->format->BitsPerPixel) {
286 switch (dst->format->Rmask) {
288 func = SDL_BlendPoint_RGB555;
293 switch (dst->format->Rmask) {
295 func = SDL_BlendPoint_RGB565;
300 switch (dst->format->Rmask) {
302 if (!dst->format->Amask) {
303 func = SDL_BlendPoint_RGB888;
305 func = SDL_BlendPoint_ARGB8888;
315 if (!dst->format->Amask) {
316 func = SDL_BlendPoint_RGB;
318 func = SDL_BlendPoint_RGBA;
322 minx = dst->clip_rect.x;
323 maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
324 miny = dst->clip_rect.y;
325 maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
327 for (i = 0; i < count; ++i) {
331 if (x < minx || x > maxx || y < miny || y > maxy) {
334 status = func(dst, x, y, blendMode, r, g, b, a);
339 #endif /* !SDL_RENDER_DISABLED */
341 /* vi: set ts=4 sw=4 expandtab: */