SDL_fillrect.c File Reference
`#include "../SDL_internal.h"`
`#include "SDL_video.h"`
`#include "SDL_blit.h"`
Include dependency graph for SDL_fillrect.c:

Go to the source code of this file.

## Functions

static void | SDL_FillRect1 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
static void | SDL_FillRect2 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
static void | SDL_FillRect3 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
static void | SDL_FillRect4 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
int | SDL_FillRect (SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
int | SDL_FillRects (SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)

## Function Documentation

## SDL_FillRect()

int SDL_FillRect | ( | SDL_Surface * | dst,
|  | const SDL_Rect * | rect,
|  | Uint32 | color
| ) |  |

Performs a fast fill of the given rectangle with `color`.

If `rect` is NULL, the whole surface will be filled with `color`.

The color should be a pixel of the format used by the surface, and can be generated by the SDL_MapRGB() function.

Returns
  0 on success, or -1 on error.

Definition at line 237 of file SDL_fillrect.c.

References SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::BytesPerPixel, SDL_Surface::clip_rect, SDL_Surface::format, SDL_Rect::h, SDL_Surface::pitch, SDL_Surface::pixels, SDL_FillRect1(), SDL_FillRect2(), SDL_FillRect3(), SDL_FillRect4(), SDL_HasSSE, SDL_IntersectRect, SDL_RectEmpty(), SDL_SetError, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_FillRects().

{
SDL_Rect clipped;
Uint8 *pixels;
if (!dst) {
return SDL_SetError("Passed NULL destination surface");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) {
return SDL_SetError("SDL_FillRect(): Unsupported surface format");
}
/* If 'rect' == NULL, then fill the whole surface */
if (rect) {
/* Perform clipping */
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
return 0;
}
rect = &clipped;
} else {
rect = &dst->clip_rect;
/* Don't attempt to fill if the surface's clip_rect is empty */
if (SDL_RectEmpty(rect)) {
return 0;
}
}
/* Perform software fill */
if (!dst->pixels) {
return SDL_SetError("SDL_FillRect(): You must lock the surface");
}
pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
rect->x * dst->format->BytesPerPixel;
switch (dst->format->BytesPerPixel) {
case 1:
{
color |= (color << 8);
color |= (color << 16);
#ifdef __SSE__
if (SDL_HasSSE()) {
SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
break;
}
#endif
SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
break;
}
case 2:
{
color |= (color << 16);
#ifdef __SSE__
if (SDL_HasSSE()) {
SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
break;
}
#endif
SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
break;
}
case 3:
/* 24-bit RGB is a slow path, at least for now. */
{
SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h);
break;
}
case 4:
{
#ifdef __SSE__
if (SDL_HasSSE()) {
SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
break;
}
#endif
SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
break;
}
}
/* We're done! */
return 0;
}
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
SDL_IntersectRect
#define SDL_IntersectRect
Definition: SDL_dynapi_overrides.h:294
SDL_RectEmpty
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
Definition: SDL_rect.h:82
SDL_FillRect3
static void SDL_FillRect3(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:197
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:75
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
SDL_PixelFormat::BitsPerPixel
Uint8 BitsPerPixel
Definition: SDL_pixels.h:319
SDL_Rect::x
int x
Definition: SDL_rect.h:66
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_Surface::clip_rect
SDL_Rect clip_rect
Definition: SDL_surface.h:85
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_FillRect2
static void SDL_FillRect2(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:173
SDL_Rect::h
int h
Definition: SDL_rect.h:67
color
GLuint color
Definition: SDL_opengl_glext.h:1148
SDL_Surface::pitch
int pitch
Definition: SDL_surface.h:74
SDL_FillRect4
static void SDL_FillRect4(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:225
SDL_FillRect1
static void SDL_FillRect1(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:134
SDL_HasSSE
#define SDL_HasSSE
Definition: SDL_dynapi_overrides.h:107
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

## SDL_FillRect1()

static void SDL_FillRect1 | ( | Uint8 * | pixels,
|  | int | pitch,
|  | Uint32 | color,
|  | int | w,
|  | int | h
| ) |  |

static

Definition at line 134 of file SDL_fillrect.c.

References NULL, and SDL_memset4().

Referenced by SDL_FillRect().

{
int n;
Uint8 *p = NULL;
while (h--) {
n = w;
p = pixels;
if (n > 3) {
switch ((uintptr_t) p & 3) {
case 1:
*p++ = (Uint8) color;
--n; /* fallthrough */
case 2:
*p++ = (Uint8) color;
--n; /* fallthrough */
case 3:
*p++ = (Uint8) color;
--n; /* fallthrough */
}
SDL_memset4(p, color, (n >> 2));
}
if (n & 3) {
p += (n & ~3);
switch (n & 3) {
case 3:
*p++ = (Uint8) color; /* fallthrough */
case 2:
*p++ = (Uint8) color; /* fallthrough */
case 1:
*p++ = (Uint8) color; /* fallthrough */
}
}
pixels += pitch;
}
}
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
SDL_memset4
SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
Definition: SDL_stdinc.h:420
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
uintptr_t
unsigned int uintptr_t
Definition: SDL_config_windows.h:70
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
NULL
#define NULL
Definition: begin_code.h:164
color
GLuint color
Definition: SDL_opengl_glext.h:1148
n
GLdouble n
Definition: SDL_opengl_glext.h:1952

## SDL_FillRect2()

static void SDL_FillRect2 | ( | Uint8 * | pixels,
|  | int | pitch,
|  | Uint32 | color,
|  | int | w,
|  | int | h
| ) |  |

static

Definition at line 173 of file SDL_fillrect.c.

References NULL, and SDL_memset4().

Referenced by SDL_FillRect().

{
int n;
Uint16 *p = NULL;
while (h--) {
n = w;
p = (Uint16 *) pixels;
if (n > 1) {
if ((uintptr_t) p & 2) {
*p++ = (Uint16) color;
--n;
}
SDL_memset4(p, color, (n >> 1));
}
if (n & 1) {
p[n - 1] = (Uint16) color;
}
pixels += pitch;
}
}
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
SDL_memset4
SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
Definition: SDL_stdinc.h:420
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
uintptr_t
unsigned int uintptr_t
Definition: SDL_config_windows.h:70
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
NULL
#define NULL
Definition: begin_code.h:164
color
GLuint color
Definition: SDL_opengl_glext.h:1148
n
GLdouble n
Definition: SDL_opengl_glext.h:1952
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:169

## SDL_FillRect3()

static void SDL_FillRect3 | ( | Uint8 * | pixels,
|  | int | pitch,
|  | Uint32 | color,
|  | int | w,
|  | int | h
| ) |  |

static

Definition at line 197 of file SDL_fillrect.c.

References NULL.

Referenced by SDL_FillRect().

{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Uint8 b1 = (Uint8) (color & 0xFF);
Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
Uint8 b3 = (Uint8) ((color >> 16) & 0xFF);
#elif SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint8 b1 = (Uint8) ((color >> 16) & 0xFF);
Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
Uint8 b3 = (Uint8) (color & 0xFF);
#endif
int n;
Uint8 *p = NULL;
while (h--) {
n = w;
p = pixels;
while (n--) {
*p++ = b1;
*p++ = b2;
*p++ = b3;
}
pixels += pitch;
}
}
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
NULL
#define NULL
Definition: begin_code.h:164
color
GLuint color
Definition: SDL_opengl_glext.h:1148
n
GLdouble n
Definition: SDL_opengl_glext.h:1952

## SDL_FillRect4()

static void SDL_FillRect4 | ( | Uint8 * | pixels,
|  | int | pitch,
|  | Uint32 | color,
|  | int | w,
|  | int | h
| ) |  |

static

Definition at line 225 of file SDL_fillrect.c.

References SDL_memset4().

Referenced by SDL_FillRect().

{
while (h--) {
SDL_memset4(pixels, color, w);
pixels += pitch;
}
}
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_memset4
SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
Definition: SDL_stdinc.h:420
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
color
GLuint color
Definition: SDL_opengl_glext.h:1148

## SDL_FillRects()

int SDL_FillRects | ( | SDL_Surface * | dst,
|  | const SDL_Rect * | rects,
|  | int | count,
|  | Uint32 | color
| ) |  |

Definition at line 327 of file SDL_fillrect.c.

References i, SDL_FillRect(), and SDL_SetError.

{
int i;
int status = 0;
if (!rects) {
return SDL_SetError("SDL_FillRects() passed NULL rects");
}
for (i = 0; i < count; ++i) {
status += SDL_FillRect(dst, &rects[i], color);
}
return status;
}
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
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_FillRect
int SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
Definition: SDL_fillrect.c:237
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
color
GLuint color
Definition: SDL_opengl_glext.h:1148