SDL  2.0
SDL_blendline.c File Reference
#include "../../SDL_internal.h"
#include "SDL_draw.h"
#include "SDL_blendline.h"
#include "SDL_blendpoint.h"
+ Include dependency graph for SDL_blendline.c:

Go to the source code of this file.

Typedefs

typedef void(* BlendLineFunc )(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_bool draw_end)

Functions

static void SDL_BlendLine_RGB2 (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end)
static void SDL_BlendLine_RGB555 (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end)
static void SDL_BlendLine_RGB565 (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end)
static void SDL_BlendLine_RGB4 (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end)
static void SDL_BlendLine_RGBA4 (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end)
static void SDL_BlendLine_RGB888 (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end)
static void SDL_BlendLine_ARGB8888 (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end)
static BlendLineFunc SDL_CalculateBlendLineFunc (const SDL_PixelFormat *fmt)
int SDL_BlendLine (SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int SDL_BlendLines (SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)

Typedef Documentation

typedef void(* BlendLineFunc)(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_bool draw_end)

Definition at line 670 of file SDL_blendline.c.

Function Documentation

int SDL_BlendLine ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)

Definition at line 708 of file SDL_blendline.c.

References SDL_Surface::clip_rect, SDL_Surface::format, SDL_CalculateBlendLineFunc(), SDL_IntersectRectAndLine, SDL_SetError, and SDL_TRUE.

{
if (!dst) {
return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
}
if (!func) {
return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
}
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
}
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
return 0;
}
static void SDL_BlendLine_ARGB8888 ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  _r,
Uint8  _g,
Uint8  _b,
Uint8  _a,
SDL_bool  draw_end 
)
static

Definition at line 580 of file SDL_blendline.c.

References AALINE, ABS, DLINE, DRAW_MUL, DRAW_SETPIXEL_ADD_ARGB8888, DRAW_SETPIXEL_ARGB8888, DRAW_SETPIXEL_BLEND_ARGB8888, DRAW_SETPIXEL_MOD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888, HLINE, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, and VLINE.

Referenced by SDL_CalculateBlendLineFunc().

{
unsigned r, g, b, a, inva;
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (x1 == x2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else {
switch (blendMode) {
draw_end);
break;
draw_end);
break;
draw_end);
break;
default:
draw_end);
break;
}
}
}
static void SDL_BlendLine_RGB2 ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  _r,
Uint8  _g,
Uint8  _b,
Uint8  _a,
SDL_bool  draw_end 
)
static

Definition at line 31 of file SDL_blendline.c.

References AALINE, ABS, DLINE, DRAW_MUL, DRAW_SETPIXEL_ADD_RGB, DRAW_SETPIXEL_BLEND_RGB, DRAW_SETPIXEL_MOD_RGB, DRAW_SETPIXEL_RGB, DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_RGB, SDL_Surface::format, HLINE, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, and VLINE.

Referenced by SDL_CalculateBlendLineFunc().

{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (x1 == x2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else {
switch (blendMode) {
draw_end);
break;
draw_end);
break;
draw_end);
break;
default:
draw_end);
break;
}
}
}
static void SDL_BlendLine_RGB4 ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  _r,
Uint8  _g,
Uint8  _b,
Uint8  _a,
SDL_bool  draw_end 
)
static

Definition at line 305 of file SDL_blendline.c.

References AALINE, ABS, DLINE, DRAW_MUL, DRAW_SETPIXEL_ADD_RGB, DRAW_SETPIXEL_BLEND_RGB, DRAW_SETPIXEL_MOD_RGB, DRAW_SETPIXEL_RGB, DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_RGB, SDL_Surface::format, HLINE, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, and VLINE.

Referenced by SDL_CalculateBlendLineFunc().

{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (x1 == x2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else {
switch (blendMode) {
draw_end);
break;
draw_end);
break;
draw_end);
break;
default:
draw_end);
break;
}
}
}
static void SDL_BlendLine_RGB555 ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  _r,
Uint8  _g,
Uint8  _b,
Uint8  _a,
SDL_bool  draw_end 
)
static

Definition at line 123 of file SDL_blendline.c.

References AALINE, ABS, DLINE, DRAW_MUL, DRAW_SETPIXEL_ADD_RGB555, DRAW_SETPIXEL_BLEND_RGB555, DRAW_SETPIXEL_MOD_RGB555, DRAW_SETPIXEL_RGB555, DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_RGB555, HLINE, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, and VLINE.

Referenced by SDL_CalculateBlendLineFunc().

{
unsigned r, g, b, a, inva;
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (x1 == x2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else {
switch (blendMode) {
draw_end);
break;
draw_end);
break;
draw_end);
break;
default:
draw_end);
break;
}
}
}
static void SDL_BlendLine_RGB565 ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  _r,
Uint8  _g,
Uint8  _b,
Uint8  _a,
SDL_bool  draw_end 
)
static

Definition at line 214 of file SDL_blendline.c.

References AALINE, ABS, DLINE, DRAW_MUL, DRAW_SETPIXEL_ADD_RGB565, DRAW_SETPIXEL_BLEND_RGB565, DRAW_SETPIXEL_MOD_RGB565, DRAW_SETPIXEL_RGB565, DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_RGB565, HLINE, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, and VLINE.

Referenced by SDL_CalculateBlendLineFunc().

{
unsigned r, g, b, a, inva;
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (x1 == x2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else {
switch (blendMode) {
draw_end);
break;
draw_end);
break;
draw_end);
break;
default:
draw_end);
break;
}
}
}
static void SDL_BlendLine_RGB888 ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  _r,
Uint8  _g,
Uint8  _b,
Uint8  _a,
SDL_bool  draw_end 
)
static

Definition at line 489 of file SDL_blendline.c.

References AALINE, ABS, DLINE, DRAW_MUL, DRAW_SETPIXEL_ADD_RGB888, DRAW_SETPIXEL_BLEND_RGB888, DRAW_SETPIXEL_MOD_RGB888, DRAW_SETPIXEL_RGB888, DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_RGB888, HLINE, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, and VLINE.

Referenced by SDL_CalculateBlendLineFunc().

{
unsigned r, g, b, a, inva;
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (x1 == x2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else {
switch (blendMode) {
draw_end);
break;
draw_end);
break;
draw_end);
break;
default:
draw_end);
break;
}
}
}
static void SDL_BlendLine_RGBA4 ( SDL_Surface dst,
int  x1,
int  y1,
int  x2,
int  y2,
SDL_BlendMode  blendMode,
Uint8  _r,
Uint8  _g,
Uint8  _b,
Uint8  _a,
SDL_bool  draw_end 
)
static

Definition at line 397 of file SDL_blendline.c.

References AALINE, ABS, DLINE, DRAW_MUL, DRAW_SETPIXEL_ADD_RGBA, DRAW_SETPIXEL_BLEND_RGBA, DRAW_SETPIXEL_MOD_RGBA, DRAW_SETPIXEL_RGBA, DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_RGBA, SDL_Surface::format, HLINE, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, and VLINE.

Referenced by SDL_CalculateBlendLineFunc().

{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (x1 == x2) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
break;
break;
break;
default:
break;
}
} else {
switch (blendMode) {
draw_end);
break;
draw_end);
break;
draw_end);
break;
default:
draw_end);
break;
}
}
}
int SDL_BlendLines ( SDL_Surface dst,
const SDL_Point points,
int  count,
SDL_BlendMode  blendMode,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)

Definition at line 733 of file SDL_blendline.c.

References SDL_Surface::clip_rect, SDL_Surface::format, i, SDL_BlendPoint(), SDL_CalculateBlendLineFunc(), SDL_IntersectRectAndLine, SDL_SetError, SDL_Point::x, and SDL_Point::y.

Referenced by SW_RenderDrawLines().

{
int i;
int x1, y1;
int x2, y2;
SDL_bool draw_end;
if (!dst) {
return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
}
if (!func) {
return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
}
for (i = 1; i < count; ++i) {
x1 = points[i-1].x;
y1 = points[i-1].y;
x2 = points[i].x;
y2 = points[i].y;
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}
/* Draw the end if it was clipped */
draw_end = (x2 != points[i].x || y2 != points[i].y);
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
}
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
blendMode, r, g, b, a);
}
return 0;
}
static BlendLineFunc SDL_CalculateBlendLineFunc ( const SDL_PixelFormat fmt)
static

Definition at line 677 of file SDL_blendline.c.

References SDL_PixelFormat::Amask, SDL_PixelFormat::BytesPerPixel, NULL, SDL_PixelFormat::Rmask, SDL_BlendLine_ARGB8888(), SDL_BlendLine_RGB2(), SDL_BlendLine_RGB4(), SDL_BlendLine_RGB555(), SDL_BlendLine_RGB565(), SDL_BlendLine_RGB888(), and SDL_BlendLine_RGBA4().

Referenced by SDL_BlendLine(), and SDL_BlendLines().

{
switch (fmt->BytesPerPixel) {
case 2:
if (fmt->Rmask == 0x7C00) {
} else if (fmt->Rmask == 0xF800) {
} else {
}
/* break; -Wunreachable-code-break */
case 4:
if (fmt->Rmask == 0x00FF0000) {
if (fmt->Amask) {
} else {
}
} else {
if (fmt->Amask) {
} else {
}
}
}
return NULL;
}