SDL  2.0
SDL_surface.c File Reference
#include "../SDL_internal.h"
#include "SDL_video.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
#include "SDL_RLEaccel_c.h"
#include "SDL_pixels_c.h"
#include "SDL_yuv_c.h"
+ Include dependency graph for SDL_surface.c:

Go to the source code of this file.

Functions

 SDL_COMPILE_TIME_ASSERT (surface_size_assumptions, sizeof(int)==sizeof(Sint32) &&sizeof(size_t) >=sizeof(Sint32))
 
static Sint64 SDL_CalculatePitch (Uint32 format, int width)
 
SDL_SurfaceSDL_CreateRGBSurfaceWithFormat (Uint32 flags, int width, int height, int depth, Uint32 format)
 
SDL_SurfaceSDL_CreateRGBSurface (Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
 
SDL_SurfaceSDL_CreateRGBSurfaceFrom (void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
 
SDL_SurfaceSDL_CreateRGBSurfaceWithFormatFrom (void *pixels, int width, int height, int depth, int pitch, Uint32 format)
 
int SDL_SetSurfacePalette (SDL_Surface *surface, SDL_Palette *palette)
 Set the palette used by a surface. More...
 
int SDL_SetSurfaceRLE (SDL_Surface *surface, int flag)
 Sets the RLE acceleration hint for a surface. More...
 
SDL_bool SDL_HasSurfaceRLE (SDL_Surface *surface)
 Returns whether the surface is RLE enabled. More...
 
int SDL_SetColorKey (SDL_Surface *surface, int flag, Uint32 key)
 Sets the color key (transparent pixel) in a blittable surface. More...
 
SDL_bool SDL_HasColorKey (SDL_Surface *surface)
 Returns whether the surface has a color key. More...
 
int SDL_GetColorKey (SDL_Surface *surface, Uint32 *key)
 Gets the color key (transparent pixel) in a blittable surface. More...
 
static void SDL_ConvertColorkeyToAlpha (SDL_Surface *surface, SDL_bool ignore_alpha)
 
int SDL_SetSurfaceColorMod (SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
 Set an additional color value used in blit operations. More...
 
int SDL_GetSurfaceColorMod (SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
 Get the additional color value used in blit operations. More...
 
int SDL_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
 Set an additional alpha value used in blit operations. More...
 
int SDL_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
 Get the additional alpha value used in blit operations. More...
 
int SDL_SetSurfaceBlendMode (SDL_Surface *surface, SDL_BlendMode blendMode)
 Set the blend mode used for blit operations. More...
 
int SDL_GetSurfaceBlendMode (SDL_Surface *surface, SDL_BlendMode *blendMode)
 Get the blend mode used for blit operations. More...
 
SDL_bool SDL_SetClipRect (SDL_Surface *surface, const SDL_Rect *rect)
 
void SDL_GetClipRect (SDL_Surface *surface, SDL_Rect *rect)
 
int SDL_LowerBlit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 
int SDL_UpperBlit (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 
int SDL_UpperBlitScaled (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 
int SDL_LowerBlitScaled (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 
int SDL_LockSurface (SDL_Surface *surface)
 Sets up a surface for directly accessing the pixels. More...
 
void SDL_UnlockSurface (SDL_Surface *surface)
 
SDL_SurfaceSDL_DuplicateSurface (SDL_Surface *surface)
 
SDL_SurfaceSDL_ConvertSurface (SDL_Surface *surface, const SDL_PixelFormat *format, Uint32 flags)
 
SDL_SurfaceSDL_ConvertSurfaceFormat (SDL_Surface *surface, Uint32 pixel_format, Uint32 flags)
 
static SDL_INLINE SDL_bool SDL_CreateSurfaceOnStack (int width, int height, Uint32 pixel_format, void *pixels, int pitch, SDL_Surface *surface, SDL_PixelFormat *format, SDL_BlitMap *blitmap)
 
int SDL_ConvertPixels (int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
 Copy a block of pixels of one format to another format. More...
 
void SDL_FreeSurface (SDL_Surface *surface)
 

Function Documentation

◆ SDL_CalculatePitch()

static Sint64 SDL_CalculatePitch ( Uint32  format,
int  width 
)
static

Definition at line 41 of file SDL_surface.c.

42 {
43  Sint64 pitch;
44 
46  pitch = ((Sint64)width * SDL_BYTESPERPIXEL(format));
47  } else {
48  pitch = (((Sint64)width * SDL_BITSPERPIXEL(format)) + 7) / 8;
49  }
50  pitch = (pitch + 3) & ~3; /* 4-byte aligning for speed */
51  return pitch;
52 }
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
#define SDL_BITSPERPIXEL(X)
Definition: SDL_pixels.h:127
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
int64_t Sint64
Definition: SDL_stdinc.h:216

References SDL_BITSPERPIXEL, SDL_BYTESPERPIXEL, and SDL_ISPIXELFORMAT_FOURCC.

Referenced by SDL_CreateRGBSurfaceWithFormat().

◆ SDL_COMPILE_TIME_ASSERT()

SDL_COMPILE_TIME_ASSERT ( surface_size_assumptions  ,
sizeof(int = =sizeof(Sint32) &&sizeof(size_t) >=sizeof(Sint32) 
)

◆ SDL_ConvertColorkeyToAlpha()

static void SDL_ConvertColorkeyToAlpha ( SDL_Surface surface,
SDL_bool  ignore_alpha 
)
static

Definition at line 330 of file SDL_surface.c.

331 {
332  int x, y;
333 
334  if (!surface) {
335  return;
336  }
337 
338  if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
339  !surface->format->Amask) {
340  return;
341  }
342 
344 
345  switch (surface->format->BytesPerPixel) {
346  case 2:
347  {
348  Uint16 *row, *spot;
349  Uint16 ckey = (Uint16) surface->map->info.colorkey;
350  Uint16 mask = (Uint16) (~surface->format->Amask);
351 
352  /* Ignore, or not, alpha in colorkey comparison */
353  if (ignore_alpha) {
354  ckey &= mask;
355  row = (Uint16 *) surface->pixels;
356  for (y = surface->h; y--;) {
357  spot = row;
358  for (x = surface->w; x--;) {
359  if ((*spot & mask) == ckey) {
360  *spot &= mask;
361  }
362  ++spot;
363  }
364  row += surface->pitch / 2;
365  }
366  } else {
367  row = (Uint16 *) surface->pixels;
368  for (y = surface->h; y--;) {
369  spot = row;
370  for (x = surface->w; x--;) {
371  if (*spot == ckey) {
372  *spot &= mask;
373  }
374  ++spot;
375  }
376  row += surface->pitch / 2;
377  }
378  }
379  }
380  break;
381  case 3:
382  /* FIXME */
383  break;
384  case 4:
385  {
386  Uint32 *row, *spot;
387  Uint32 ckey = surface->map->info.colorkey;
388  Uint32 mask = ~surface->format->Amask;
389 
390  /* Ignore, or not, alpha in colorkey comparison */
391  if (ignore_alpha) {
392  ckey &= mask;
393  row = (Uint32 *) surface->pixels;
394  for (y = surface->h; y--;) {
395  spot = row;
396  for (x = surface->w; x--;) {
397  if ((*spot & mask) == ckey) {
398  *spot &= mask;
399  }
400  ++spot;
401  }
402  row += surface->pitch / 4;
403  }
404  } else {
405  row = (Uint32 *) surface->pixels;
406  for (y = surface->h; y--;) {
407  spot = row;
408  for (x = surface->w; x--;) {
409  if (*spot == ckey) {
410  *spot &= mask;
411  }
412  ++spot;
413  }
414  row += surface->pitch / 4;
415  }
416  }
417  }
418  break;
419  }
420 
422 
423  SDL_SetColorKey(surface, 0, 0);
425 }
@ SDL_BLENDMODE_BLEND
Definition: SDL_blendmode.h:44
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:40
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLenum GLenum void * row
GLenum GLint GLuint mask
uint16_t Uint16
Definition: SDL_stdinc.h:197
uint32_t Uint32
Definition: SDL_stdinc.h:209
int SDL_LockSurface(SDL_Surface *surface)
Sets up a surface for directly accessing the pixels.
Definition: SDL_surface.c:927
void SDL_UnlockSurface(SDL_Surface *surface)
Definition: SDL_surface.c:950
int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key)
Sets the color key (transparent pixel) in a blittable surface.
Definition: SDL_surface.c:267
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL_surface.c:509
EGLSurface surface
Definition: eglext.h:248

References SDL_BLENDMODE_BLEND, SDL_COPY_COLORKEY, SDL_LockSurface(), SDL_SetColorKey(), SDL_SetSurfaceBlendMode(), and SDL_UnlockSurface().

Referenced by SDL_ConvertSurface().

◆ SDL_ConvertPixels()

int SDL_ConvertPixels ( int  width,
int  height,
Uint32  src_format,
const void src,
int  src_pitch,
Uint32  dst_format,
void dst,
int  dst_pitch 
)

Copy a block of pixels of one format to another format.

Returns
0 on success, or -1 if there was an error

Definition at line 1267 of file SDL_surface.c.

1270 {
1271  SDL_Surface src_surface, dst_surface;
1272  SDL_PixelFormat src_fmt, dst_fmt;
1273  SDL_BlitMap src_blitmap, dst_blitmap;
1274  SDL_Rect rect;
1275  void *nonconst_src = (void *) src;
1276  int ret;
1277 
1278  /* Check to make sure we are blitting somewhere, so we don't crash */
1279  if (!dst) {
1280  return SDL_InvalidParamError("dst");
1281  }
1282  if (!dst_pitch) {
1283  return SDL_InvalidParamError("dst_pitch");
1284  }
1285 
1286 #if SDL_HAVE_YUV
1287  if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1288  return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1289  } else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
1290  return SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1291  } else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1292  return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1293  }
1294 #else
1295  if (SDL_ISPIXELFORMAT_FOURCC(src_format) || SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1296  SDL_SetError("SDL not built with YUV support");
1297  return -1;
1298  }
1299 #endif
1300 
1301  /* Fast path for same format copy */
1302  if (src_format == dst_format) {
1303  int i;
1304  const int bpp = SDL_BYTESPERPIXEL(src_format);
1305  width *= bpp;
1306  for (i = height; i--;) {
1307  SDL_memcpy(dst, src, width);
1308  src = (const Uint8*)src + src_pitch;
1309  dst = (Uint8*)dst + dst_pitch;
1310  }
1311  return 0;
1312  }
1313 
1314  if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
1315  src_pitch,
1316  &src_surface, &src_fmt, &src_blitmap)) {
1317  return -1;
1318  }
1319  if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
1320  &dst_surface, &dst_fmt, &dst_blitmap)) {
1321  return -1;
1322  }
1323 
1324  /* Set up the rect and go! */
1325  rect.x = 0;
1326  rect.y = 0;
1327  rect.w = width;
1328  rect.h = height;
1329  ret = SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
1330 
1331  /* Free blitmap reference, after blitting between stack'ed surfaces */
1332  SDL_InvalidateMap(src_surface.map);
1333 
1334  return ret;
1335 }
#define SDL_SetError
#define SDL_memcpy
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:90
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
GLenum src
GLenum GLenum dst
void SDL_InvalidateMap(SDL_BlitMap *map)
Definition: SDL_pixels.c:1083
uint8_t Uint8
Definition: SDL_stdinc.h:185
int SDL_LowerBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:624
static SDL_INLINE SDL_bool SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format, void *pixels, int pitch, SDL_Surface *surface, SDL_PixelFormat *format, SDL_BlitMap *blitmap)
Definition: SDL_surface.c:1229
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
int SDL_ConvertPixels_RGB_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:786
int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:397
int SDL_ConvertPixels_YUV_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:1817
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79
A collection of pixels used in software blitting.
Definition: SDL_surface.h:71
struct SDL_BlitMap * map
Definition: SDL_surface.h:91
SDL_Rect rect
Definition: testrelative.c:27

References bpp, SDL_Rect::h, i, SDL_Surface::map, rect, SDL_BYTESPERPIXEL, SDL_ConvertPixels_RGB_to_YUV(), SDL_ConvertPixels_YUV_to_RGB(), SDL_ConvertPixels_YUV_to_YUV(), SDL_CreateSurfaceOnStack(), SDL_InvalidateMap(), SDL_InvalidParamError, SDL_ISPIXELFORMAT_FOURCC, SDL_LowerBlit(), SDL_memcpy, SDL_SetError, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

◆ SDL_ConvertSurface()

SDL_Surface* SDL_ConvertSurface ( SDL_Surface src,
const SDL_PixelFormat fmt,
Uint32  flags 
)

Creates a new surface of the specified format, and then copies and maps the given surface to it so the blit of the converted surface will be as fast as possible. If this function fails, it returns NULL.

The flags parameter is passed to SDL_CreateRGBSurface() and has those semantics. You can also pass SDL_RLEACCEL in the flags parameter and SDL will try to RLE accelerate colorkey and alpha blits in the resulting surface.

Definition at line 979 of file SDL_surface.c.

981 {
982  SDL_Surface *convert;
983  Uint32 copy_flags;
984  SDL_Color copy_color;
985  SDL_Rect bounds;
986  int ret;
987  SDL_bool palette_ck_transform = SDL_FALSE;
988  int palette_ck_value = 0;
989  SDL_bool palette_has_alpha = SDL_FALSE;
990  Uint8 *palette_saved_alpha = NULL;
991 
992  if (!surface) {
993  SDL_InvalidParamError("surface");
994  return NULL;
995  }
996  if (!format) {
997  SDL_InvalidParamError("format");
998  return NULL;
999  }
1000 
1001  /* Check for empty destination palette! (results in empty image) */
1002  if (format->palette != NULL) {
1003  int i;
1004  for (i = 0; i < format->palette->ncolors; ++i) {
1005  if ((format->palette->colors[i].r != 0xFF) ||
1006  (format->palette->colors[i].g != 0xFF) ||
1007  (format->palette->colors[i].b != 0xFF))
1008  break;
1009  }
1010  if (i == format->palette->ncolors) {
1011  SDL_SetError("Empty destination palette");
1012  return (NULL);
1013  }
1014  }
1015 
1016  /* Create a new surface with the desired format */
1017  convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
1018  format->BitsPerPixel, format->Rmask,
1019  format->Gmask, format->Bmask,
1020  format->Amask);
1021  if (convert == NULL) {
1022  return (NULL);
1023  }
1024 
1025  /* Copy the palette if any */
1026  if (format->palette && convert->format->palette) {
1027  SDL_memcpy(convert->format->palette->colors,
1028  format->palette->colors,
1029  format->palette->ncolors * sizeof(SDL_Color));
1030  convert->format->palette->ncolors = format->palette->ncolors;
1031  }
1032 
1033  /* Save the original copy flags */
1034  copy_flags = surface->map->info.flags;
1035  copy_color.r = surface->map->info.r;
1036  copy_color.g = surface->map->info.g;
1037  copy_color.b = surface->map->info.b;
1038  copy_color.a = surface->map->info.a;
1039  surface->map->info.r = 0xFF;
1040  surface->map->info.g = 0xFF;
1041  surface->map->info.b = 0xFF;
1042  surface->map->info.a = 0xFF;
1043  surface->map->info.flags = (copy_flags & (SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY));
1044  SDL_InvalidateMap(surface->map);
1045 
1046  /* Copy over the image data */
1047  bounds.x = 0;
1048  bounds.y = 0;
1049  bounds.w = surface->w;
1050  bounds.h = surface->h;
1051 
1052  /* Source surface has a palette with no real alpha (0 or OPAQUE).
1053  * Destination format has alpha.
1054  * -> set alpha channel to be opaque */
1055  if (surface->format->palette && format->Amask) {
1056  SDL_bool set_opaque = SDL_FALSE;
1057 
1058  SDL_bool is_opaque, has_alpha_channel;
1059  SDL_DetectPalette(surface->format->palette, &is_opaque, &has_alpha_channel);
1060 
1061  if (is_opaque) {
1062  if (!has_alpha_channel) {
1063  set_opaque = SDL_TRUE;
1064  }
1065  } else {
1066  palette_has_alpha = SDL_TRUE;
1067  }
1068 
1069  /* Set opaque and backup palette alpha values */
1070  if (set_opaque) {
1071  int i;
1072  palette_saved_alpha = SDL_stack_alloc(Uint8, surface->format->palette->ncolors);
1073  for (i = 0; i < surface->format->palette->ncolors; i++) {
1074  palette_saved_alpha[i] = surface->format->palette->colors[i].a;
1075  surface->format->palette->colors[i].a = SDL_ALPHA_OPAQUE;
1076  }
1077  }
1078  }
1079 
1080  /* Transform colorkey to alpha. for cases where source palette has duplicate values, and colorkey is one of them */
1081  if (copy_flags & SDL_COPY_COLORKEY) {
1082  if (surface->format->palette && !format->palette) {
1083  palette_ck_transform = SDL_TRUE;
1084  palette_has_alpha = SDL_TRUE;
1085  palette_ck_value = surface->format->palette->colors[surface->map->info.colorkey].a;
1086  surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
1087  }
1088  }
1089 
1090  ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);
1091 
1092  /* Restore colorkey alpha value */
1093  if (palette_ck_transform) {
1094  surface->format->palette->colors[surface->map->info.colorkey].a = palette_ck_value;
1095  }
1096 
1097  /* Restore palette alpha values */
1098  if (palette_saved_alpha) {
1099  int i;
1100  for (i = 0; i < surface->format->palette->ncolors; i++) {
1101  surface->format->palette->colors[i].a = palette_saved_alpha[i];
1102  }
1103  SDL_stack_free(palette_saved_alpha);
1104  }
1105 
1106  /* Clean up the original surface, and update converted surface */
1107  convert->map->info.r = copy_color.r;
1108  convert->map->info.g = copy_color.g;
1109  convert->map->info.b = copy_color.b;
1110  convert->map->info.a = copy_color.a;
1111  convert->map->info.flags =
1112  (copy_flags &
1116  surface->map->info.r = copy_color.r;
1117  surface->map->info.g = copy_color.g;
1118  surface->map->info.b = copy_color.b;
1119  surface->map->info.a = copy_color.a;
1120  surface->map->info.flags = copy_flags;
1121  SDL_InvalidateMap(surface->map);
1122 
1123  /* SDL_LowerBlit failed, and so the conversion */
1124  if (ret < 0) {
1125  SDL_FreeSurface(convert);
1126  return NULL;
1127  }
1128 
1129  if (copy_flags & SDL_COPY_COLORKEY) {
1130  SDL_bool set_colorkey_by_color = SDL_FALSE;
1131  SDL_bool convert_colorkey = SDL_TRUE;
1132 
1133  if (surface->format->palette) {
1134  if (format->palette &&
1135  surface->format->palette->ncolors <= format->palette->ncolors &&
1136  (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
1137  surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
1138  /* The palette is identical, just set the same colorkey */
1139  SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
1140  } else if (!format->palette) {
1141  if (format->Amask) {
1142  /* No need to add the colorkey, transparency is in the alpha channel*/
1143  } else {
1144  /* Only set the colorkey information */
1145  set_colorkey_by_color = SDL_TRUE;
1146  convert_colorkey = SDL_FALSE;
1147  }
1148  } else {
1149  set_colorkey_by_color = SDL_TRUE;
1150  }
1151  } else {
1152  set_colorkey_by_color = SDL_TRUE;
1153  }
1154 
1155  if (set_colorkey_by_color) {
1156  SDL_Surface *tmp;
1157  SDL_Surface *tmp2;
1158  int converted_colorkey = 0;
1159 
1160  /* Create a dummy surface to get the colorkey converted */
1161  tmp = SDL_CreateRGBSurface(0, 1, 1,
1162  surface->format->BitsPerPixel, surface->format->Rmask,
1163  surface->format->Gmask, surface->format->Bmask,
1164  surface->format->Amask);
1165 
1166  /* Share the palette, if any */
1167  if (surface->format->palette) {
1168  SDL_SetSurfacePalette(tmp, surface->format->palette);
1169  }
1170 
1171  SDL_FillRect(tmp, NULL, surface->map->info.colorkey);
1172 
1173  tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
1174 
1175  /* Convertion of the colorkey */
1176  tmp2 = SDL_ConvertSurface(tmp, format, 0);
1177 
1178  /* Get the converted colorkey */
1179  SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);
1180 
1181  SDL_FreeSurface(tmp);
1182  SDL_FreeSurface(tmp2);
1183 
1184  /* Set the converted colorkey on the new surface */
1185  SDL_SetColorKey(convert, 1, converted_colorkey);
1186 
1187  /* This is needed when converting for 3D texture upload */
1188  if (convert_colorkey) {
1190  }
1191  }
1192  }
1193  SDL_SetClipRect(convert, &surface->clip_rect);
1194 
1195  /* Enable alpha blending by default if the new surface has an
1196  * alpha channel or alpha modulation */
1197  if ((surface->format->Amask && format->Amask) ||
1198  (palette_has_alpha && format->Amask) ||
1199  (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
1201  }
1202  if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
1203  SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
1204  }
1205 
1206  /* We're ready to go! */
1207  return (convert);
1208 }
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:44
#define SDL_COPY_RLE_DESIRED
Definition: SDL_blit.h:42
#define SDL_COPY_MODULATE_ALPHA
Definition: SDL_blit.h:35
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:43
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
#define SDL_memcmp
#define SDL_FillRect
GLbitfield flags
void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel)
Definition: SDL_pixels.c:806
#define SDL_ALPHA_OPAQUE
Definition: SDL_pixels.h:46
#define SDL_ALPHA_TRANSPARENT
Definition: SDL_pixels.h:47
SDL_bool
Definition: SDL_stdinc.h:168
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:360
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:361
static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface, SDL_bool ignore_alpha)
Definition: SDL_surface.c:330
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
Set the palette used by a surface.
Definition: SDL_surface.c:218
SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
Definition: SDL_surface.c:581
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
Sets the RLE acceleration hint for a surface.
Definition: SDL_surface.c:232
SDL_Surface * SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format, Uint32 flags)
Definition: SDL_surface.c:979
void SDL_FreeSurface(SDL_Surface *surface)
Definition: SDL_surface.c:1341
SDL_Surface * SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
Definition: SDL_surface.c:155
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
#define NULL
Definition: begin_code.h:163
Uint8 r
Definition: SDL_blit.h:71
Uint8 a
Definition: SDL_blit.h:71
Uint8 g
Definition: SDL_blit.h:71
Uint8 b
Definition: SDL_blit.h:71
SDL_BlitInfo info
Definition: SDL_blit.h:93
Uint8 r
Definition: SDL_pixels.h:306
Uint8 b
Definition: SDL_pixels.h:308
Uint8 a
Definition: SDL_pixels.h:309
Uint8 g
Definition: SDL_pixels.h:307
SDL_Color * colors
Definition: SDL_pixels.h:316
Uint8 BytesPerPixel
Definition: SDL_pixels.h:329
SDL_Palette * palette
Definition: SDL_pixels.h:327
SDL_PixelFormat * format
Definition: SDL_surface.h:73
void * pixels
Definition: SDL_surface.h:76

References SDL_Color::a, SDL_BlitInfo::a, SDL_Color::b, SDL_BlitInfo::b, SDL_PixelFormat::BytesPerPixel, SDL_Surface::clip_rect, SDL_BlitInfo::colorkey, SDL_Palette::colors, SDL_BlitInfo::flags, SDL_Surface::format, SDL_Color::g, SDL_BlitInfo::g, SDL_Rect::h, i, SDL_BlitMap::info, SDL_Surface::map, SDL_Palette::ncolors, NULL, SDL_PixelFormat::palette, SDL_Surface::pixels, SDL_Color::r, SDL_BlitInfo::r, SDL_ALPHA_OPAQUE, SDL_ALPHA_TRANSPARENT, SDL_BLENDMODE_BLEND, SDL_ConvertColorkeyToAlpha(), SDL_ConvertSurface(), SDL_COPY_BLEND, SDL_COPY_COLORKEY, SDL_COPY_MODULATE_ALPHA, SDL_COPY_RLE_ALPHAKEY, SDL_COPY_RLE_COLORKEY, SDL_COPY_RLE_DESIRED, SDL_CreateRGBSurface(), SDL_DetectPalette(), SDL_FALSE, SDL_FillRect, SDL_FreeSurface(), SDL_InvalidateMap(), SDL_InvalidParamError, SDL_LowerBlit(), SDL_memcmp, SDL_memcpy, SDL_RLEACCEL, SDL_SetClipRect(), SDL_SetColorKey(), SDL_SetError, SDL_SetSurfaceBlendMode(), SDL_SetSurfacePalette(), SDL_SetSurfaceRLE(), SDL_stack_alloc, SDL_stack_free, SDL_TRUE, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_ConvertSurface(), SDL_ConvertSurfaceFormat(), and SDL_DuplicateSurface().

◆ SDL_ConvertSurfaceFormat()

SDL_Surface* SDL_ConvertSurfaceFormat ( SDL_Surface surface,
Uint32  pixel_format,
Uint32  flags 
)

Definition at line 1211 of file SDL_surface.c.

1213 {
1214  SDL_PixelFormat *fmt;
1215  SDL_Surface *convert = NULL;
1216 
1218  if (fmt) {
1219  convert = SDL_ConvertSurface(surface, fmt, flags);
1220  SDL_FreeFormat(fmt);
1221  }
1222  return convert;
1223 }
#define SDL_FreeFormat
#define SDL_AllocFormat
int uint32_t uint32_t uint32_t pixel_format
Definition: SDL_kmsdrmsym.h:52

References NULL, pixel_format, SDL_AllocFormat, SDL_ConvertSurface(), and SDL_FreeFormat.

◆ SDL_CreateRGBSurface()

SDL_Surface* SDL_CreateRGBSurface ( Uint32  flags,
int  width,
int  height,
int  depth,
Uint32  Rmask,
Uint32  Gmask,
Uint32  Bmask,
Uint32  Amask 
)

Allocate and free an RGB surface.

If the depth is 4 or 8 bits, an empty palette is allocated for the surface. If the depth is greater than 8 bits, the pixel format is set using the flags '[RGB]mask'.

If the function runs out of memory, it will return NULL.

Parameters
flagsThe flags are obsolete and should be set to 0.
widthThe width in pixels of the surface to create.
heightThe height in pixels of the surface to create.
depthThe depth in bits of the surface to create.
RmaskThe red mask of the surface to create.
GmaskThe green mask of the surface to create.
BmaskThe blue mask of the surface to create.
AmaskThe alpha mask of the surface to create.

Definition at line 155 of file SDL_surface.c.

158 {
159  Uint32 format;
160 
161  /* Get the pixel format */
162  format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
164  SDL_SetError("Unknown pixel format");
165  return NULL;
166  }
167 
169 }
#define SDL_MasksToPixelFormatEnum
GLint GLint GLsizei GLsizei GLsizei depth
Definition: SDL_opengl.h:1572
@ SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:173
SDL_Surface * SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
Definition: SDL_surface.c:59

References NULL, SDL_CreateRGBSurfaceWithFormat(), SDL_MasksToPixelFormatEnum, SDL_PIXELFORMAT_UNKNOWN, and SDL_SetError.

Referenced by SDL_ConvertSurface(), and SDL_CreateRGBSurfaceFrom().

◆ SDL_CreateRGBSurfaceFrom()

SDL_Surface* SDL_CreateRGBSurfaceFrom ( void pixels,
int  width,
int  height,
int  depth,
int  pitch,
Uint32  Rmask,
Uint32  Gmask,
Uint32  Bmask,
Uint32  Amask 
)

Definition at line 175 of file SDL_surface.c.

179 {
181 
182  surface = SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
183  if (surface != NULL) {
184  surface->flags |= SDL_PREALLOC;
185  surface->pixels = pixels;
186  surface->w = width;
187  surface->h = height;
188  surface->pitch = pitch;
190  }
191  return surface;
192 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
#define SDL_PREALLOC
Definition: SDL_surface.h:53

References NULL, SDL_CreateRGBSurface(), SDL_PREALLOC, and SDL_SetClipRect().

◆ SDL_CreateRGBSurfaceWithFormat()

SDL_Surface* SDL_CreateRGBSurfaceWithFormat ( Uint32  flags,
int  width,
int  height,
int  depth,
Uint32  format 
)

Definition at line 59 of file SDL_surface.c.

61 {
62  Sint64 pitch;
64 
65  /* The flags are no longer used, make the compiler happy */
66  (void)flags;
67 
69  if (pitch < 0 || pitch > SDL_MAX_SINT32) {
70  /* Overflow... */
72  return NULL;
73  }
74 
75  /* Allocate the surface */
76  surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
77  if (surface == NULL) {
79  return NULL;
80  }
81 
82  surface->format = SDL_AllocFormat(format);
83  if (!surface->format) {
85  return NULL;
86  }
87  surface->w = width;
88  surface->h = height;
89  surface->pitch = (int)pitch;
91 
92  if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
93  SDL_Palette *palette =
94  SDL_AllocPalette((1 << surface->format->BitsPerPixel));
95  if (!palette) {
97  return NULL;
98  }
99  if (palette->ncolors == 2) {
100  /* Create a black and white bitmap palette */
101  palette->colors[0].r = 0xFF;
102  palette->colors[0].g = 0xFF;
103  palette->colors[0].b = 0xFF;
104  palette->colors[1].r = 0x00;
105  palette->colors[1].g = 0x00;
106  palette->colors[1].b = 0x00;
107  }
108  SDL_SetSurfacePalette(surface, palette);
109  SDL_FreePalette(palette);
110  }
111 
112  /* Get the pixels */
113  if (surface->w && surface->h) {
114  /* Assumptions checked in surface_size_assumptions assert above */
115  Sint64 size = ((Sint64)surface->h * surface->pitch);
117  /* Overflow... */
119  SDL_OutOfMemory();
120  return NULL;
121  }
122 
123  surface->pixels = SDL_SIMDAlloc((size_t)size);
124  if (!surface->pixels) {
126  SDL_OutOfMemory();
127  return NULL;
128  }
129  surface->flags |= SDL_SIMD_ALIGNED;
130  /* This is important for bitmaps */
131  SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
132  }
133 
134  /* Allocate an empty mapping */
135  surface->map = SDL_AllocBlitMap();
136  if (!surface->map) {
138  return NULL;
139  }
140 
141  /* By default surface with an alpha mask are set up for blending */
142  if (surface->format->Amask) {
144  }
145 
146  /* The surface is ready to go */
147  surface->refcount = 1;
148  return surface;
149 }
#define SDL_memset
#define SDL_AllocPalette
#define SDL_FreePalette
#define SDL_SIMDAlloc
#define SDL_calloc
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
GLsizeiptr size
SDL_BlitMap * SDL_AllocBlitMap(void)
Definition: SDL_pixels.c:1007
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
#define SDL_MAX_SINT32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:201
static Sint64 SDL_CalculatePitch(Uint32 format, int width)
Definition: SDL_surface.c:41
#define SDL_SIMD_ALIGNED
Definition: SDL_surface.h:56
typedef int(__stdcall *FARPROC)()

References SDL_Color::b, SDL_Palette::colors, SDL_Color::g, int(), SDL_Palette::ncolors, NULL, SDL_Color::r, SDL_AllocBlitMap(), SDL_AllocFormat, SDL_AllocPalette, SDL_BLENDMODE_BLEND, SDL_CalculatePitch(), SDL_calloc, SDL_FreePalette, SDL_FreeSurface(), SDL_ISPIXELFORMAT_INDEXED, SDL_MAX_SINT32, SDL_memset, SDL_OutOfMemory, SDL_SetClipRect(), SDL_SetSurfaceBlendMode(), SDL_SetSurfacePalette(), SDL_SIMD_ALIGNED, SDL_SIMDAlloc, and void.

Referenced by SDL_CreateRGBSurface(), and SDL_CreateRGBSurfaceWithFormatFrom().

◆ SDL_CreateRGBSurfaceWithFormatFrom()

SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom ( void pixels,
int  width,
int  height,
int  depth,
int  pitch,
Uint32  format 
)

Definition at line 199 of file SDL_surface.c.

202 {
204 
206  if (surface != NULL) {
207  surface->flags |= SDL_PREALLOC;
208  surface->pixels = pixels;
209  surface->w = width;
210  surface->h = height;
211  surface->pitch = pitch;
213  }
214  return surface;
215 }

References NULL, SDL_CreateRGBSurfaceWithFormat(), SDL_PREALLOC, and SDL_SetClipRect().

◆ SDL_CreateSurfaceOnStack()

static SDL_INLINE SDL_bool SDL_CreateSurfaceOnStack ( int  width,
int  height,
Uint32  pixel_format,
void pixels,
int  pitch,
SDL_Surface surface,
SDL_PixelFormat format,
SDL_BlitMap blitmap 
)
static

Definition at line 1229 of file SDL_surface.c.

1232 {
1234  SDL_SetError("Indexed pixel formats not supported");
1235  return SDL_FALSE;
1236  }
1237  if (SDL_InitFormat(format, pixel_format) < 0) {
1238  return SDL_FALSE;
1239  }
1240 
1241  SDL_zerop(surface);
1242  surface->flags = SDL_PREALLOC;
1243  surface->format = format;
1244  surface->pixels = pixels;
1245  surface->w = width;
1246  surface->h = height;
1247  surface->pitch = pitch;
1248  /* We don't actually need to set up the clip rect for our purposes */
1249  /* SDL_SetClipRect(surface, NULL); */
1250 
1251  /* Allocate an empty mapping */
1252  SDL_zerop(blitmap);
1253  blitmap->info.r = 0xFF;
1254  blitmap->info.g = 0xFF;
1255  blitmap->info.b = 0xFF;
1256  blitmap->info.a = 0xFF;
1257  surface->map = blitmap;
1258 
1259  /* The surface is ready to go */
1260  surface->refcount = 1;
1261  return SDL_TRUE;
1262 }
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
Definition: SDL_pixels.c:544
#define SDL_zerop(x)
Definition: SDL_stdinc.h:427

References SDL_BlitInfo::a, SDL_BlitInfo::b, SDL_BlitInfo::g, SDL_BlitMap::info, pixel_format, SDL_BlitInfo::r, SDL_FALSE, SDL_InitFormat(), SDL_ISPIXELFORMAT_INDEXED, SDL_PREALLOC, SDL_SetError, SDL_TRUE, and SDL_zerop.

Referenced by SDL_ConvertPixels().

◆ SDL_DuplicateSurface()

SDL_Surface* SDL_DuplicateSurface ( SDL_Surface surface)

Definition at line 970 of file SDL_surface.c.

971 {
972  return SDL_ConvertSurface(surface, surface->format, surface->flags);
973 }

References SDL_ConvertSurface().

◆ SDL_FreeSurface()

void SDL_FreeSurface ( SDL_Surface surface)

Definition at line 1341 of file SDL_surface.c.

1342 {
1343  if (surface == NULL) {
1344  return;
1345  }
1346  if (surface->flags & SDL_DONTFREE) {
1347  return;
1348  }
1349  SDL_InvalidateMap(surface->map);
1350 
1352 
1353  if (--surface->refcount > 0) {
1354  return;
1355  }
1356  while (surface->locked > 0) {
1358  }
1359 #if SDL_HAVE_RLE
1360  if (surface->flags & SDL_RLEACCEL) {
1362  }
1363 #endif
1364  if (surface->format) {
1366  SDL_FreeFormat(surface->format);
1367  surface->format = NULL;
1368  }
1369  if (surface->flags & SDL_PREALLOC) {
1370  /* Don't free */
1371  } else if (surface->flags & SDL_SIMD_ALIGNED) {
1372  /* Free aligned */
1373  SDL_SIMDFree(surface->pixels);
1374  } else {
1375  /* Normal */
1376  SDL_free(surface->pixels);
1377  }
1378  if (surface->map) {
1379  SDL_FreeBlitMap(surface->map);
1380  }
1381  SDL_free(surface);
1382 }
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
#define SDL_free
#define SDL_SIMDFree
void SDL_FreeBlitMap(SDL_BlitMap *map)
Definition: SDL_pixels.c:1182
void SDL_InvalidateAllBlitMap(SDL_Surface *surface)
Definition: SDL_pixels.c:1034
#define SDL_DONTFREE
Definition: SDL_surface.h:55

References NULL, SDL_DONTFREE, SDL_free, SDL_FreeBlitMap(), SDL_FreeFormat, SDL_InvalidateAllBlitMap(), SDL_InvalidateMap(), SDL_PREALLOC, SDL_RLEACCEL, SDL_SetSurfacePalette(), SDL_SIMD_ALIGNED, SDL_SIMDFree, SDL_UnlockSurface(), and SDL_UnRLESurface().

Referenced by SDL_ConvertSurface(), and SDL_CreateRGBSurfaceWithFormat().

◆ SDL_GetClipRect()

void SDL_GetClipRect ( SDL_Surface surface,
SDL_Rect rect 
)

Gets the clipping rectangle for the destination surface in a blit.

rect must be a pointer to a valid rectangle which will be filled with the correct values.

Definition at line 605 of file SDL_surface.c.

606 {
607  if (surface && rect) {
608  *rect = surface->clip_rect;
609  }
610 }

References rect.

◆ SDL_GetColorKey()

int SDL_GetColorKey ( SDL_Surface surface,
Uint32 key 
)

Gets the color key (transparent pixel) in a blittable surface.

Parameters
surfaceThe surface to update
keyA pointer filled in with the transparent pixel in the native surface format
Returns
0 on success, or -1 if the surface is not valid or colorkey is not enabled.

Definition at line 312 of file SDL_surface.c.

313 {
314  if (!surface) {
315  return SDL_InvalidParamError("surface");
316  }
317 
318  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
319  return SDL_SetError("Surface doesn't have a colorkey");
320  }
321 
322  if (key) {
323  *key = surface->map->info.colorkey;
324  }
325  return 0;
326 }
GLuint64 key
Definition: gl2ext.h:2192

References SDL_COPY_COLORKEY, SDL_InvalidParamError, and SDL_SetError.

◆ SDL_GetSurfaceAlphaMod()

int SDL_GetSurfaceAlphaMod ( SDL_Surface surface,
Uint8 alpha 
)

Get the additional alpha value used in blit operations.

Parameters
surfaceThe surface to query.
alphaA pointer filled in with the current alpha value.
Returns
0 on success, or -1 if the surface is not valid.
See also
SDL_SetSurfaceAlphaMod()

Definition at line 496 of file SDL_surface.c.

497 {
498  if (!surface) {
499  return -1;
500  }
501 
502  if (alpha) {
503  *alpha = surface->map->info.a;
504  }
505  return 0;
506 }
GLfloat GLfloat GLfloat alpha

◆ SDL_GetSurfaceBlendMode()

int SDL_GetSurfaceBlendMode ( SDL_Surface surface,
SDL_BlendMode blendMode 
)

Get the blend mode used for blit operations.

Parameters
surfaceThe surface to query.
blendModeA pointer filled in with the current blend mode.
Returns
0 on success, or -1 if the surface is not valid.
See also
SDL_SetSurfaceBlendMode()

Definition at line 549 of file SDL_surface.c.

550 {
551  if (!surface) {
552  return -1;
553  }
554 
555  if (!blendMode) {
556  return 0;
557  }
558 
559  switch (surface->map->
560  info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
561  case SDL_COPY_BLEND:
563  break;
564  case SDL_COPY_ADD:
566  break;
567  case SDL_COPY_MOD:
569  break;
570  case SDL_COPY_MUL:
572  break;
573  default:
575  break;
576  }
577  return 0;
578 }
@ SDL_BLENDMODE_NONE
Definition: SDL_blendmode.h:42
@ SDL_BLENDMODE_ADD
Definition: SDL_blendmode.h:47
@ SDL_BLENDMODE_MUL
Definition: SDL_blendmode.h:53
@ SDL_BLENDMODE_MOD
Definition: SDL_blendmode.h:50
#define SDL_COPY_MUL
Definition: SDL_blit.h:39
#define SDL_COPY_ADD
Definition: SDL_blit.h:37
#define SDL_COPY_MOD
Definition: SDL_blit.h:38
static SDL_BlendMode blendMode
Definition: testdraw2.c:34

References blendMode, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, SDL_BLENDMODE_MUL, SDL_BLENDMODE_NONE, SDL_COPY_ADD, SDL_COPY_BLEND, SDL_COPY_MOD, and SDL_COPY_MUL.

◆ SDL_GetSurfaceColorMod()

int SDL_GetSurfaceColorMod ( SDL_Surface surface,
Uint8 r,
Uint8 g,
Uint8 b 
)

Get the additional color value used in blit operations.

Parameters
surfaceThe surface to query.
rA pointer filled in with the current red color value.
gA pointer filled in with the current green color value.
bA pointer filled in with the current blue color value.
Returns
0 on success, or -1 if the surface is not valid.
See also
SDL_SetSurfaceColorMod()

Definition at line 454 of file SDL_surface.c.

455 {
456  if (!surface) {
457  return -1;
458  }
459 
460  if (r) {
461  *r = surface->map->info.r;
462  }
463  if (g) {
464  *g = surface->map->info.g;
465  }
466  if (b) {
467  *b = surface->map->info.b;
468  }
469  return 0;
470 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
GLboolean GLboolean GLboolean b
GLboolean GLboolean g

◆ SDL_HasColorKey()

SDL_bool SDL_HasColorKey ( SDL_Surface surface)

Returns whether the surface has a color key.

Returns
SDL_TRUE if the surface has a color key, or SDL_FALSE if the surface is NULL or has no color key

Definition at line 298 of file SDL_surface.c.

299 {
300  if (!surface) {
301  return SDL_FALSE;
302  }
303 
304  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
305  return SDL_FALSE;
306  }
307 
308  return SDL_TRUE;
309 }

References SDL_COPY_COLORKEY, SDL_FALSE, and SDL_TRUE.

◆ SDL_HasSurfaceRLE()

SDL_bool SDL_HasSurfaceRLE ( SDL_Surface surface)

Returns whether the surface is RLE enabled.

Returns
SDL_TRUE if the surface is RLE enabled, or SDL_FALSE if the surface is NULL or not RLE enabled

Definition at line 253 of file SDL_surface.c.

254 {
255  if (!surface) {
256  return SDL_FALSE;
257  }
258 
259  if (!(surface->map->info.flags & SDL_COPY_RLE_DESIRED)) {
260  return SDL_FALSE;
261  }
262 
263  return SDL_TRUE;
264 }

References SDL_COPY_RLE_DESIRED, SDL_FALSE, and SDL_TRUE.

◆ SDL_LockSurface()

int SDL_LockSurface ( SDL_Surface surface)

Sets up a surface for directly accessing the pixels.

Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write to and read from surface->pixels, using the pixel format stored in surface->format. Once you are done accessing the surface, you should use SDL_UnlockSurface() to release it.

Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates to 0, then you can read and write to the surface at any time, and the pixel format of the surface will not change.

No operating system or library calls should be made between lock/unlock pairs, as critical system locks may be held during this time.

SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.

See also
SDL_UnlockSurface()

Definition at line 927 of file SDL_surface.c.

928 {
929  if (!surface->locked) {
930 #if SDL_HAVE_RLE
931  /* Perform the lock */
932  if (surface->flags & SDL_RLEACCEL) {
934  surface->flags |= SDL_RLEACCEL; /* save accel'd state */
935  }
936 #endif
937  }
938 
939  /* Increment the surface lock count, for recursive locks */
940  ++surface->locked;
941 
942  /* Ready to go.. */
943  return (0);
944 }

References SDL_RLEACCEL, and SDL_UnRLESurface().

Referenced by SDL_ConvertColorkeyToAlpha().

◆ SDL_LowerBlit()

int SDL_LowerBlit ( SDL_Surface src,
SDL_Rect srcrect,
SDL_Surface dst,
SDL_Rect dstrect 
)

This is a semi-private blit function and it performs low-level surface blitting only.

Definition at line 624 of file SDL_surface.c.

626 {
627  /* Check to make sure the blit mapping is valid */
628  if ((src->map->dst != dst) ||
629  (dst->format->palette &&
630  src->map->dst_palette_version != dst->format->palette->version) ||
631  (src->format->palette &&
632  src->map->src_palette_version != src->format->palette->version)) {
633  if (SDL_MapSurface(src, dst) < 0) {
634  return (-1);
635  }
636  /* just here for debugging */
637 /* printf */
638 /* ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */
639 /* src, dst->flags, src->map->info.flags, dst, dst->flags, */
640 /* dst->map->info.flags, src->map->blit); */
641  }
642  return (src->map->blit(src, srcrect, dst, dstrect));
643 }
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
Definition: SDL_pixels.c:1100

References SDL_MapSurface().

Referenced by SDL_ConvertPixels(), SDL_ConvertSurface(), SDL_LowerBlitScaled(), and SDL_UpperBlit().

◆ SDL_LowerBlitScaled()

int SDL_LowerBlitScaled ( SDL_Surface src,
SDL_Rect srcrect,
SDL_Surface dst,
SDL_Rect dstrect 
)

This is a semi-private blit function and it performs low-level surface scaled blitting only.

Definition at line 900 of file SDL_surface.c.

902 {
903  static const Uint32 complex_copy_flags = (
907  );
908 
909  if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
910  src->map->info.flags |= SDL_COPY_NEAREST;
911  SDL_InvalidateMap(src->map);
912  }
913 
914  if ( !(src->map->info.flags & complex_copy_flags) &&
915  src->format->format == dst->format->format &&
916  !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
917  return SDL_SoftStretch( src, srcrect, dst, dstrect );
918  } else {
919  return SDL_LowerBlit( src, srcrect, dst, dstrect );
920  }
921 }
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:41
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
#define SDL_SoftStretch

References SDL_COPY_ADD, SDL_COPY_BLEND, SDL_COPY_COLORKEY, SDL_COPY_MOD, SDL_COPY_MODULATE_ALPHA, SDL_COPY_MODULATE_COLOR, SDL_COPY_MUL, SDL_COPY_NEAREST, SDL_InvalidateMap(), SDL_ISPIXELFORMAT_INDEXED, SDL_LowerBlit(), and SDL_SoftStretch.

Referenced by SDL_UpperBlitScaled().

◆ SDL_SetClipRect()

SDL_bool SDL_SetClipRect ( SDL_Surface surface,
const SDL_Rect rect 
)

Sets the clipping rectangle for the destination surface in a blit.

If the clip rectangle is NULL, clipping will be disabled.

If the clip rectangle doesn't intersect the surface, the function will return SDL_FALSE and blits will be completely clipped. Otherwise the function returns SDL_TRUE and blits to the surface will be clipped to the intersection of the surface area and the clipping rectangle.

Note that blits are automatically clipped to the edges of the source and destination surfaces.

Definition at line 581 of file SDL_surface.c.

582 {
583  SDL_Rect full_rect;
584 
585  /* Don't do anything if there's no surface to act on */
586  if (!surface) {
587  return SDL_FALSE;
588  }
589 
590  /* Set up the full surface rectangle */
591  full_rect.x = 0;
592  full_rect.y = 0;
593  full_rect.w = surface->w;
594  full_rect.h = surface->h;
595 
596  /* Set the clipping rectangle */
597  if (!rect) {
598  surface->clip_rect = full_rect;
599  return SDL_TRUE;
600  }
601  return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
602 }
#define SDL_IntersectRect

References SDL_Rect::h, rect, SDL_FALSE, SDL_IntersectRect, SDL_TRUE, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_ConvertSurface(), SDL_CreateRGBSurfaceFrom(), SDL_CreateRGBSurfaceWithFormat(), and SDL_CreateRGBSurfaceWithFormatFrom().

◆ SDL_SetColorKey()

int SDL_SetColorKey ( SDL_Surface surface,
int  flag,
Uint32  key 
)

Sets the color key (transparent pixel) in a blittable surface.

Parameters
surfaceThe surface to update
flagNon-zero to enable colorkey and 0 to disable colorkey
keyThe transparent pixel in the native surface format
Returns
0 on success, or -1 if the surface is not valid

You can pass SDL_RLEACCEL to enable RLE accelerated blits.

Definition at line 267 of file SDL_surface.c.

268 {
269  int flags;
270 
271  if (!surface) {
272  return SDL_InvalidParamError("surface");
273  }
274 
275  if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
276  return SDL_InvalidParamError("key");
277  }
278 
279  if (flag & SDL_RLEACCEL) {
281  }
282 
283  flags = surface->map->info.flags;
284  if (flag) {
285  surface->map->info.flags |= SDL_COPY_COLORKEY;
286  surface->map->info.colorkey = key;
287  } else {
288  surface->map->info.flags &= ~SDL_COPY_COLORKEY;
289  }
290  if (surface->map->info.flags != flags) {
292  }
293 
294  return 0;
295 }

References SDL_COPY_COLORKEY, SDL_InvalidateMap(), SDL_InvalidParamError, SDL_RLEACCEL, and SDL_SetSurfaceRLE().

Referenced by SDL_ConvertColorkeyToAlpha(), and SDL_ConvertSurface().

◆ SDL_SetSurfaceAlphaMod()

int SDL_SetSurfaceAlphaMod ( SDL_Surface surface,
Uint8  alpha 
)

Set an additional alpha value used in blit operations.

Parameters
surfaceThe surface to update.
alphaThe alpha value multiplied into blit operations.
Returns
0 on success, or -1 if the surface is not valid.
See also
SDL_GetSurfaceAlphaMod()

Definition at line 473 of file SDL_surface.c.

474 {
475  int flags;
476 
477  if (!surface) {
478  return -1;
479  }
480 
481  surface->map->info.a = alpha;
482 
483  flags = surface->map->info.flags;
484  if (alpha != 0xFF) {
485  surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
486  } else {
487  surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
488  }
489  if (surface->map->info.flags != flags) {
491  }
492  return 0;
493 }

References SDL_COPY_MODULATE_ALPHA, and SDL_InvalidateMap().

◆ SDL_SetSurfaceBlendMode()

int SDL_SetSurfaceBlendMode ( SDL_Surface surface,
SDL_BlendMode  blendMode 
)

Set the blend mode used for blit operations.

Parameters
surfaceThe surface to update.
blendModeSDL_BlendMode to use for blit blending.
Returns
0 on success, or -1 if the parameters are not valid.
See also
SDL_GetSurfaceBlendMode()

Definition at line 509 of file SDL_surface.c.

510 {
511  int flags, status;
512 
513  if (!surface) {
514  return -1;
515  }
516 
517  status = 0;
518  flags = surface->map->info.flags;
519  surface->map->info.flags &=
521  switch (blendMode) {
522  case SDL_BLENDMODE_NONE:
523  break;
524  case SDL_BLENDMODE_BLEND:
525  surface->map->info.flags |= SDL_COPY_BLEND;
526  break;
527  case SDL_BLENDMODE_ADD:
528  surface->map->info.flags |= SDL_COPY_ADD;
529  break;
530  case SDL_BLENDMODE_MOD:
531  surface->map->info.flags |= SDL_COPY_MOD;
532  break;
533  case SDL_BLENDMODE_MUL:
534  surface->map->info.flags |= SDL_COPY_MUL;
535  break;
536  default:
537  status = SDL_Unsupported();
538  break;
539  }
540 
541  if (surface->map->info.flags != flags) {
543  }
544 
545  return status;
546 }
#define SDL_Unsupported()
Definition: SDL_error.h:89

References blendMode, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, SDL_BLENDMODE_MUL, SDL_BLENDMODE_NONE, SDL_COPY_ADD, SDL_COPY_BLEND, SDL_COPY_MOD, SDL_COPY_MUL, SDL_InvalidateMap(), and SDL_Unsupported.

Referenced by SDL_ConvertColorkeyToAlpha(), SDL_ConvertSurface(), and SDL_CreateRGBSurfaceWithFormat().

◆ SDL_SetSurfaceColorMod()

int SDL_SetSurfaceColorMod ( SDL_Surface surface,
Uint8  r,
Uint8  g,
Uint8  b 
)

Set an additional color value used in blit operations.

Parameters
surfaceThe surface to update.
rThe red color value multiplied into blit operations.
gThe green color value multiplied into blit operations.
bThe blue color value multiplied into blit operations.
Returns
0 on success, or -1 if the surface is not valid.
See also
SDL_GetSurfaceColorMod()

Definition at line 428 of file SDL_surface.c.

429 {
430  int flags;
431 
432  if (!surface) {
433  return -1;
434  }
435 
436  surface->map->info.r = r;
437  surface->map->info.g = g;
438  surface->map->info.b = b;
439 
440  flags = surface->map->info.flags;
441  if (r != 0xFF || g != 0xFF || b != 0xFF) {
442  surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
443  } else {
444  surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
445  }
446  if (surface->map->info.flags != flags) {
448  }
449  return 0;
450 }

References SDL_COPY_MODULATE_COLOR, and SDL_InvalidateMap().

◆ SDL_SetSurfacePalette()

int SDL_SetSurfacePalette ( SDL_Surface surface,
SDL_Palette palette 
)

Set the palette used by a surface.

Returns
0, or -1 if the surface format doesn't use a palette.
Note
A single palette can be shared with many surfaces.

Definition at line 218 of file SDL_surface.c.

219 {
220  if (!surface) {
221  return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
222  }
223  if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
224  return -1;
225  }
227 
228  return 0;
229 }
#define SDL_SetPixelFormatPalette

References SDL_InvalidateMap(), SDL_SetError, and SDL_SetPixelFormatPalette.

Referenced by SDL_ConvertSurface(), SDL_CreateRGBSurfaceWithFormat(), and SDL_FreeSurface().

◆ SDL_SetSurfaceRLE()

int SDL_SetSurfaceRLE ( SDL_Surface surface,
int  flag 
)

Sets the RLE acceleration hint for a surface.

Returns
0 on success, or -1 if the surface is not valid
Note
If RLE is enabled, colorkey and alpha blending blits are much faster, but the surface must be locked before directly accessing the pixels.

Definition at line 232 of file SDL_surface.c.

233 {
234  int flags;
235 
236  if (!surface) {
237  return -1;
238  }
239 
240  flags = surface->map->info.flags;
241  if (flag) {
242  surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
243  } else {
244  surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
245  }
246  if (surface->map->info.flags != flags) {
248  }
249  return 0;
250 }

References SDL_COPY_RLE_DESIRED, and SDL_InvalidateMap().

Referenced by SDL_ConvertSurface(), and SDL_SetColorKey().

◆ SDL_UnlockSurface()

void SDL_UnlockSurface ( SDL_Surface surface)
See also
SDL_LockSurface()

Definition at line 950 of file SDL_surface.c.

951 {
952  /* Only perform an unlock if we are locked */
953  if (!surface->locked || (--surface->locked > 0)) {
954  return;
955  }
956 
957 #if SDL_HAVE_RLE
958  /* Update RLE encoded surface with new data */
959  if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
960  surface->flags &= ~SDL_RLEACCEL; /* stop lying */
962  }
963 #endif
964 }
int SDL_RLESurface(SDL_Surface *surface)

References SDL_RLEACCEL, and SDL_RLESurface().

Referenced by SDL_ConvertColorkeyToAlpha(), and SDL_FreeSurface().

◆ SDL_UpperBlit()

int SDL_UpperBlit ( SDL_Surface src,
const SDL_Rect srcrect,
SDL_Surface dst,
SDL_Rect dstrect 
)

This is the public blit function, SDL_BlitSurface(), and it performs rectangle validation and clipping before passing it to SDL_LowerBlit()

Definition at line 647 of file SDL_surface.c.

649 {
650  SDL_Rect fulldst;
651  int srcx, srcy, w, h;
652 
653  /* Make sure the surfaces aren't locked */
654  if (!src || !dst) {
655  return SDL_SetError("SDL_UpperBlit: passed a NULL surface");
656  }
657  if (src->locked || dst->locked) {
658  return SDL_SetError("Surfaces must not be locked during blit");
659  }
660 
661  /* If the destination rectangle is NULL, use the entire dest surface */
662  if (dstrect == NULL) {
663  fulldst.x = fulldst.y = 0;
664  fulldst.w = dst->w;
665  fulldst.h = dst->h;
666  dstrect = &fulldst;
667  }
668 
669  /* clip the source rectangle to the source surface */
670  if (srcrect) {
671  int maxw, maxh;
672 
673  srcx = srcrect->x;
674  w = srcrect->w;
675  if (srcx < 0) {
676  w += srcx;
677  dstrect->x -= srcx;
678  srcx = 0;
679  }
680  maxw = src->w - srcx;
681  if (maxw < w)
682  w = maxw;
683 
684  srcy = srcrect->y;
685  h = srcrect->h;
686  if (srcy < 0) {
687  h += srcy;
688  dstrect->y -= srcy;
689  srcy = 0;
690  }
691  maxh = src->h - srcy;
692  if (maxh < h)
693  h = maxh;
694 
695  } else {
696  srcx = srcy = 0;
697  w = src->w;
698  h = src->h;
699  }
700 
701  /* clip the destination rectangle against the clip rectangle */
702  {
703  SDL_Rect *clip = &dst->clip_rect;
704  int dx, dy;
705 
706  dx = clip->x - dstrect->x;
707  if (dx > 0) {
708  w -= dx;
709  dstrect->x += dx;
710  srcx += dx;
711  }
712  dx = dstrect->x + w - clip->x - clip->w;
713  if (dx > 0)
714  w -= dx;
715 
716  dy = clip->y - dstrect->y;
717  if (dy > 0) {
718  h -= dy;
719  dstrect->y += dy;
720  srcy += dy;
721  }
722  dy = dstrect->y + h - clip->y - clip->h;
723  if (dy > 0)
724  h -= dy;
725  }
726 
727  /* Switch back to a fast blit if we were previously stretching */
728  if (src->map->info.flags & SDL_COPY_NEAREST) {
729  src->map->info.flags &= ~SDL_COPY_NEAREST;
730  SDL_InvalidateMap(src->map);
731  }
732 
733  if (w > 0 && h > 0) {
734  SDL_Rect sr;
735  sr.x = srcx;
736  sr.y = srcy;
737  sr.w = dstrect->w = w;
738  sr.h = dstrect->h = h;
739  return SDL_LowerBlit(src, &sr, dst, dstrect);
740  }
741  dstrect->w = dstrect->h = 0;
742  return 0;
743 }
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w

References SDL_Rect::h, NULL, SDL_COPY_NEAREST, SDL_InvalidateMap(), SDL_LowerBlit(), SDL_SetError, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

◆ SDL_UpperBlitScaled()

int SDL_UpperBlitScaled ( SDL_Surface src,
const SDL_Rect srcrect,
SDL_Surface dst,
SDL_Rect dstrect 
)

This is the public scaled blit function, SDL_BlitScaled(), and it performs rectangle validation and clipping before passing it to SDL_LowerBlitScaled()

Definition at line 746 of file SDL_surface.c.

748 {
749  double src_x0, src_y0, src_x1, src_y1;
750  double dst_x0, dst_y0, dst_x1, dst_y1;
751  SDL_Rect final_src, final_dst;
752  double scaling_w, scaling_h;
753  int src_w, src_h;
754  int dst_w, dst_h;
755 
756  /* Make sure the surfaces aren't locked */
757  if (!src || !dst) {
758  return SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface");
759  }
760  if (src->locked || dst->locked) {
761  return SDL_SetError("Surfaces must not be locked during blit");
762  }
763 
764  if (NULL == srcrect) {
765  src_w = src->w;
766  src_h = src->h;
767  } else {
768  src_w = srcrect->w;
769  src_h = srcrect->h;
770  }
771 
772  if (NULL == dstrect) {
773  dst_w = dst->w;
774  dst_h = dst->h;
775  } else {
776  dst_w = dstrect->w;
777  dst_h = dstrect->h;
778  }
779 
780  if (dst_w == src_w && dst_h == src_h) {
781  /* No scaling, defer to regular blit */
782  return SDL_BlitSurface(src, srcrect, dst, dstrect);
783  }
784 
785  scaling_w = (double)dst_w / src_w;
786  scaling_h = (double)dst_h / src_h;
787 
788  if (NULL == dstrect) {
789  dst_x0 = 0;
790  dst_y0 = 0;
791  dst_x1 = dst_w - 1;
792  dst_y1 = dst_h - 1;
793  } else {
794  dst_x0 = dstrect->x;
795  dst_y0 = dstrect->y;
796  dst_x1 = dst_x0 + dst_w - 1;
797  dst_y1 = dst_y0 + dst_h - 1;
798  }
799 
800  if (NULL == srcrect) {
801  src_x0 = 0;
802  src_y0 = 0;
803  src_x1 = src_w - 1;
804  src_y1 = src_h - 1;
805  } else {
806  src_x0 = srcrect->x;
807  src_y0 = srcrect->y;
808  src_x1 = src_x0 + src_w - 1;
809  src_y1 = src_y0 + src_h - 1;
810 
811  /* Clip source rectangle to the source surface */
812 
813  if (src_x0 < 0) {
814  dst_x0 -= src_x0 * scaling_w;
815  src_x0 = 0;
816  }
817 
818  if (src_x1 >= src->w) {
819  dst_x1 -= (src_x1 - src->w + 1) * scaling_w;
820  src_x1 = src->w - 1;
821  }
822 
823  if (src_y0 < 0) {
824  dst_y0 -= src_y0 * scaling_h;
825  src_y0 = 0;
826  }
827 
828  if (src_y1 >= src->h) {
829  dst_y1 -= (src_y1 - src->h + 1) * scaling_h;
830  src_y1 = src->h - 1;
831  }
832  }
833 
834  /* Clip destination rectangle to the clip rectangle */
835 
836  /* Translate to clip space for easier calculations */
837  dst_x0 -= dst->clip_rect.x;
838  dst_x1 -= dst->clip_rect.x;
839  dst_y0 -= dst->clip_rect.y;
840  dst_y1 -= dst->clip_rect.y;
841 
842  if (dst_x0 < 0) {
843  src_x0 -= dst_x0 / scaling_w;
844  dst_x0 = 0;
845  }
846 
847  if (dst_x1 >= dst->clip_rect.w) {
848  src_x1 -= (dst_x1 - dst->clip_rect.w + 1) / scaling_w;
849  dst_x1 = dst->clip_rect.w - 1;
850  }
851 
852  if (dst_y0 < 0) {
853  src_y0 -= dst_y0 / scaling_h;
854  dst_y0 = 0;
855  }
856 
857  if (dst_y1 >= dst->clip_rect.h) {
858  src_y1 -= (dst_y1 - dst->clip_rect.h + 1) / scaling_h;
859  dst_y1 = dst->clip_rect.h - 1;
860  }
861 
862  /* Translate back to surface coordinates */
863  dst_x0 += dst->clip_rect.x;
864  dst_x1 += dst->clip_rect.x;
865  dst_y0 += dst->clip_rect.y;
866  dst_y1 += dst->clip_rect.y;
867 
868  final_src.x = (int)SDL_floor(src_x0 + 0.5);
869  final_src.y = (int)SDL_floor(src_y0 + 0.5);
870  final_src.w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5);
871  final_src.h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5);
872 
873  final_dst.x = (int)SDL_floor(dst_x0 + 0.5);
874  final_dst.y = (int)SDL_floor(dst_y0 + 0.5);
875  final_dst.w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5);
876  final_dst.h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5);
877 
878  if (final_dst.w < 0)
879  final_dst.w = 0;
880  if (final_dst.h < 0)
881  final_dst.h = 0;
882 
883  if (dstrect)
884  *dstrect = final_dst;
885 
886  if (final_dst.w == 0 || final_dst.h == 0 ||
887  final_src.w <= 0 || final_src.h <= 0) {
888  /* No-op. */
889  return 0;
890  }
891 
892  return SDL_LowerBlitScaled(src, &final_src, dst, &final_dst);
893 }
#define SDL_floor
int SDL_LowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:900
#define SDL_BlitSurface
Definition: SDL_surface.h:493

References SDL_Rect::h, int(), NULL, SDL_BlitSurface, SDL_floor, SDL_LowerBlitScaled(), SDL_SetError, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.