SDL  2.0
SDL_surface.h File Reference
#include "SDL_stdinc.h"
#include "SDL_pixels.h"
#include "SDL_rect.h"
#include "SDL_blendmode.h"
#include "SDL_rwops.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_surface.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Surface
 A collection of pixels used in software blitting. More...
 

Surface flags

These are the currently supported flags for the SDL_Surface.

Used internally (read-only).

#define SDL_SWSURFACE   0
 
#define SDL_PREALLOC   0x00000001
 
#define SDL_RLEACCEL   0x00000002
 
#define SDL_DONTFREE   0x00000004
 
#define SDL_SIMD_ALIGNED   0x00000008
 
#define SDL_MUSTLOCK(S)   (((S)->flags & SDL_RLEACCEL) != 0)
 
#define SDL_LoadBMP(file)   SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
 
#define SDL_SaveBMP(surface, file)    SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
 
#define SDL_BlitSurface   SDL_UpperBlit
 
#define SDL_BlitScaled   SDL_UpperBlitScaled
 
enum  SDL_YUV_CONVERSION_MODE {
  SDL_YUV_CONVERSION_JPEG ,
  SDL_YUV_CONVERSION_BT601 ,
  SDL_YUV_CONVERSION_BT709 ,
  SDL_YUV_CONVERSION_AUTOMATIC
}
 The formula used for converting between YUV and RGB. More...
 
typedef int(* SDL_blit) (struct SDL_Surface *src, SDL_Rect *srcrect, struct SDL_Surface *dst, SDL_Rect *dstrect)
 The type of function used for surface blitting functions. More...
 
SDL_SurfaceSDL_CreateRGBSurface (Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
 
SDL_SurfaceSDL_CreateRGBSurfaceWithFormat (Uint32 flags, int width, int height, int depth, Uint32 format)
 
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)
 
void SDL_FreeSurface (SDL_Surface *surface)
 
int SDL_SetSurfacePalette (SDL_Surface *surface, SDL_Palette *palette)
 Set the palette used by a surface. More...
 
int SDL_LockSurface (SDL_Surface *surface)
 Sets up a surface for directly accessing the pixels. More...
 
void SDL_UnlockSurface (SDL_Surface *surface)
 
SDL_SurfaceSDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
 
int SDL_SaveBMP_RW (SDL_Surface *surface, SDL_RWops *dst, int freedst)
 
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...
 
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)
 
SDL_SurfaceSDL_DuplicateSurface (SDL_Surface *surface)
 
SDL_SurfaceSDL_ConvertSurface (SDL_Surface *src, const SDL_PixelFormat *fmt, Uint32 flags)
 
SDL_SurfaceSDL_ConvertSurfaceFormat (SDL_Surface *src, Uint32 pixel_format, Uint32 flags)
 
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...
 
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)
 
int SDL_UpperBlit (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 
int SDL_LowerBlit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 
int SDL_SoftStretch (SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
 Perform a fast, low quality, stretch blit between two surfaces of the same pixel format. More...
 
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)
 
void SDL_SetYUVConversionMode (SDL_YUV_CONVERSION_MODE mode)
 Set the YUV conversion mode. More...
 
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode (void)
 Get the YUV conversion mode. More...
 
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution (int width, int height)
 Get the YUV conversion mode, returning the correct mode for the resolution when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC. More...
 

Detailed Description

Header file for SDL_Surface definition and management functions.

Definition in file SDL_surface.h.

Macro Definition Documentation

◆ SDL_BlitScaled

#define SDL_BlitScaled   SDL_UpperBlitScaled

Definition at line 522 of file SDL_surface.h.

◆ SDL_BlitSurface

#define SDL_BlitSurface   SDL_UpperBlit

Performs a fast blit from the source surface to the destination surface.

This assumes that the source and destination rectangles are the same size. If either srcrect or dstrect are NULL, the entire surface (src or dst) is copied. The final blit rectangles are saved in srcrect and dstrect after all clipping is performed.

Returns
If the blit is successful, it returns 0, otherwise it returns -1.

The blit function should not be called on a locked surface.

The blit semantics for surfaces with and without blending and colorkey are defined as follows:

RGBA->RGB:
  Source surface blend mode set to SDL_BLENDMODE_BLEND:
    alpha-blend (using the source alpha-channel and per-surface alpha)
    SDL_SRCCOLORKEY ignored.
  Source surface blend mode set to SDL_BLENDMODE_NONE:
    copy RGB.
    if SDL_SRCCOLORKEY set, only copy the pixels matching the
    RGB values of the source color key, ignoring alpha in the
    comparison.

RGB->RGBA:
  Source surface blend mode set to SDL_BLENDMODE_BLEND:
    alpha-blend (using the source per-surface alpha)
  Source surface blend mode set to SDL_BLENDMODE_NONE:
    copy RGB, set destination alpha to source per-surface alpha value.
  both:
    if SDL_SRCCOLORKEY set, only copy the pixels matching the
    source color key.

RGBA->RGBA:
  Source surface blend mode set to SDL_BLENDMODE_BLEND:
    alpha-blend (using the source alpha-channel and per-surface alpha)
    SDL_SRCCOLORKEY ignored.
  Source surface blend mode set to SDL_BLENDMODE_NONE:
    copy all of RGBA to the destination.
    if SDL_SRCCOLORKEY set, only copy the pixels matching the
    RGB values of the source color key, ignoring alpha in the
    comparison.

RGB->RGB:
  Source surface blend mode set to SDL_BLENDMODE_BLEND:
    alpha-blend (using the source per-surface alpha)
  Source surface blend mode set to SDL_BLENDMODE_NONE:
    copy RGB.
  both:
    if SDL_SRCCOLORKEY set, only copy the pixels matching the
    source color key.

You should call SDL_BlitSurface() unless you know exactly how SDL blitting works internally and how to use the other blit functions.

Definition at line 493 of file SDL_surface.h.

◆ SDL_DONTFREE

#define SDL_DONTFREE   0x00000004

Surface is referenced internally

Definition at line 55 of file SDL_surface.h.

◆ SDL_LoadBMP

#define SDL_LoadBMP (   file)    SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)

Load a surface from a file.

Convenience macro.

Definition at line 203 of file SDL_surface.h.

◆ SDL_MUSTLOCK

#define SDL_MUSTLOCK (   S)    (((S)->flags & SDL_RLEACCEL) != 0)

Evaluates to true if the surface needs to be locked before access.

Definition at line 62 of file SDL_surface.h.

◆ SDL_PREALLOC

#define SDL_PREALLOC   0x00000001

Surface uses preallocated memory

Definition at line 53 of file SDL_surface.h.

◆ SDL_RLEACCEL

#define SDL_RLEACCEL   0x00000002

Surface is RLE encoded

Definition at line 54 of file SDL_surface.h.

◆ SDL_SaveBMP

#define SDL_SaveBMP (   surface,
  file 
)     SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)

Save a surface to a file.

Convenience macro.

Definition at line 226 of file SDL_surface.h.

◆ SDL_SIMD_ALIGNED

#define SDL_SIMD_ALIGNED   0x00000008

Surface uses aligned memory

Definition at line 56 of file SDL_surface.h.

◆ SDL_SWSURFACE

#define SDL_SWSURFACE   0

Just here for compatibility

Definition at line 52 of file SDL_surface.h.

Typedef Documentation

◆ SDL_blit

typedef int( * SDL_blit) (struct SDL_Surface *src, SDL_Rect *srcrect, struct SDL_Surface *dst, SDL_Rect *dstrect)

The type of function used for surface blitting functions.

Definition at line 100 of file SDL_surface.h.

Enumeration Type Documentation

◆ SDL_YUV_CONVERSION_MODE

The formula used for converting between YUV and RGB.

Enumerator
SDL_YUV_CONVERSION_JPEG 

Full range JPEG

SDL_YUV_CONVERSION_BT601 

BT.601 (the default)

SDL_YUV_CONVERSION_BT709 

BT.709

SDL_YUV_CONVERSION_AUTOMATIC 

BT.601 for SD content, BT.709 for HD content

Definition at line 106 of file SDL_surface.h.

107 {
108  SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
109  SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
110  SDL_YUV_CONVERSION_BT709, /**< BT.709 */
111  SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
SDL_YUV_CONVERSION_MODE
The formula used for converting between YUV and RGB.
Definition: SDL_surface.h:107
@ SDL_YUV_CONVERSION_BT601
Definition: SDL_surface.h:109
@ SDL_YUV_CONVERSION_JPEG
Definition: SDL_surface.h:108
@ SDL_YUV_CONVERSION_BT709
Definition: SDL_surface.h:110
@ SDL_YUV_CONVERSION_AUTOMATIC
Definition: SDL_surface.h:111

Function Documentation

◆ 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 width
Definition: SDL_opengl.h:1572
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
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
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 }
@ SDL_BLENDMODE_BLEND
Definition: SDL_blendmode.h:44
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:44
#define SDL_COPY_RLE_DESIRED
Definition: SDL_blit.h:42
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:40
#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
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
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
uint32_t Uint32
Definition: SDL_stdinc.h:209
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
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
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
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL_surface.c:509
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
#define NULL
Definition: begin_code.h:163
EGLSurface surface
Definition: eglext.h:248
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 src,
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
int64_t Sint64
Definition: SDL_stdinc.h:216
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_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_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 238 of file SDL_fillrect.c.

239 {
240  if (!dst) {
241  return SDL_SetError("Passed NULL destination surface");
242  }
243 
244  /* If 'rect' == NULL, then fill the whole surface */
245  if (!rect) {
246  rect = &dst->clip_rect;
247  /* Don't attempt to fill if the surface's clip_rect is empty */
248  if (SDL_RectEmpty(rect)) {
249  return 0;
250  }
251  }
252 
253  return SDL_FillRects(dst, rect, 1, color);
254 }
int SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
Definition: SDL_fillrect.c:299
GLuint color
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
Definition: SDL_rect.h:108

References rect, SDL_FillRects(), SDL_RectEmpty(), and SDL_SetError.

◆ SDL_FillRects()

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

Definition at line 299 of file SDL_fillrect.c.

301 {
302  SDL_Rect clipped;
303  Uint8 *pixels;
304  const SDL_Rect* rect;
305  void (*fill_function)(Uint8 * pixels, int pitch, Uint32 color, int w, int h) = NULL;
306  int i;
307 
308  if (!dst) {
309  return SDL_SetError("Passed NULL destination surface");
310  }
311 
312  /* This function doesn't work on surfaces < 8 bpp */
313  if (dst->format->BitsPerPixel < 8) {
314  return SDL_SetError("SDL_FillRect(): Unsupported surface format");
315  }
316 
317  /* Nothing to do */
318  if (dst->w == 0 || dst->h == 0) {
319  return 0;
320  }
321 
322  /* Perform software fill */
323  if (!dst->pixels) {
324  return SDL_SetError("SDL_FillRect(): You must lock the surface");
325  }
326 
327  if (!rects) {
328  return SDL_SetError("SDL_FillRects() passed NULL rects");
329  }
330 
331 #if SDL_ARM_NEON_BLITTERS
332  if (SDL_HasNEON() && dst->format->BytesPerPixel != 3 && fill_function == NULL) {
333  switch (dst->format->BytesPerPixel) {
334  case 1:
335  fill_function = fill_8_neon;
336  break;
337  case 2:
338  fill_function = fill_16_neon;
339  break;
340  case 4:
341  fill_function = fill_32_neon;
342  break;
343  }
344  }
345 #endif
346 #if SDL_ARM_SIMD_BLITTERS
347  if (SDL_HasARMSIMD() && dst->format->BytesPerPixel != 3 && fill_function == NULL) {
348  switch (dst->format->BytesPerPixel) {
349  case 1:
350  fill_function = fill_8_simd;
351  break;
352  case 2:
353  fill_function = fill_16_simd;
354  break;
355  case 4:
356  fill_function = fill_32_simd;
357  break;
358  }
359  }
360 #endif
361 
362  if (fill_function == NULL) {
363  switch (dst->format->BytesPerPixel) {
364  case 1:
365  {
366  color |= (color << 8);
367  color |= (color << 16);
368 #ifdef __SSE__
369  if (SDL_HasSSE()) {
370  fill_function = SDL_FillRect1SSE;
371  break;
372  }
373 #endif
374  fill_function = SDL_FillRect1;
375  break;
376  }
377 
378  case 2:
379  {
380  color |= (color << 16);
381 #ifdef __SSE__
382  if (SDL_HasSSE()) {
383  fill_function = SDL_FillRect2SSE;
384  break;
385  }
386 #endif
387  fill_function = SDL_FillRect2;
388  break;
389  }
390 
391  case 3:
392  /* 24-bit RGB is a slow path, at least for now. */
393  {
394  fill_function = SDL_FillRect3;
395  break;
396  }
397 
398  case 4:
399  {
400 #ifdef __SSE__
401  if (SDL_HasSSE()) {
402  fill_function = SDL_FillRect4SSE;
403  break;
404  }
405 #endif
406  fill_function = SDL_FillRect4;
407  break;
408  }
409 
410  default:
411  return SDL_SetError("Unsupported pixel format");
412  }
413  }
414 
415  for (i = 0; i < count; ++i) {
416  rect = &rects[i];
417  /* Perform clipping */
418  if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
419  continue;
420  }
421  rect = &clipped;
422 
423  pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
424  rect->x * dst->format->BytesPerPixel;
425 
426  fill_function(pixels, dst->pitch, color, rect->w, rect->h);
427  }
428 
429  /* We're done! */
430  return 0;
431 }
#define SDL_HasSSE
#define SDL_HasNEON
#define SDL_IntersectRect
#define SDL_HasARMSIMD
static void SDL_FillRect2(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:174
static void SDL_FillRect3(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:198
static void SDL_FillRect1(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:135
static void SDL_FillRect4(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:226
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
EGLSurface EGLint * rects
Definition: eglext.h:282

References SDL_Rect::h, i, NULL, rect, SDL_FillRect1(), SDL_FillRect2(), SDL_FillRect3(), SDL_FillRect4(), SDL_HasARMSIMD, SDL_HasNEON, SDL_HasSSE, SDL_IntersectRect, SDL_SetError, void, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_FillRect().

◆ 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
void SDL_UnlockSurface(SDL_Surface *surface)
Definition: SDL_surface.c:950
#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_GetYUVConversionMode()

SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode ( void  )

Get the YUV conversion mode.

Definition at line 698 of file SDL_dynapi_procs.h.

References SDL_YUV_ConversionMode.

Referenced by SDL_GetYUVConversionModeForResolution().

◆ SDL_GetYUVConversionModeForResolution()

SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution ( int  width,
int  height 
)

Get the YUV conversion mode, returning the correct mode for the resolution when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC.

Definition at line 46 of file SDL_yuv.c.

47 {
52  } else {
54  }
55  }
56  return mode;
57 }
GLenum mode
#define SDL_YUV_SD_THRESHOLD
Definition: SDL_yuv.c:30
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode()
Get the YUV conversion mode.
Definition: SDL_yuv.c:41

References SDL_GetYUVConversionMode(), SDL_YUV_CONVERSION_AUTOMATIC, SDL_YUV_CONVERSION_BT601, SDL_YUV_CONVERSION_BT709, and SDL_YUV_SD_THRESHOLD.

Referenced by GetYUVConversionType(), and SDL_ConvertPixels_ARGB8888_to_YUV().

◆ 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_LoadBMP_RW()

SDL_Surface* SDL_LoadBMP_RW ( SDL_RWops src,
int  freesrc 
)

Load a surface from a seekable SDL data stream (memory or file).

If freesrc is non-zero, the stream will be closed after being read.

The new surface should be freed with SDL_FreeSurface().

Returns
the new surface, or NULL if there was an error.

Definition at line 172 of file SDL_bmp.c.

173 {
174  SDL_bool was_error;
175  Sint64 fp_offset = 0;
176  int bmpPitch;
177  int i, pad;
179  Uint32 Rmask = 0;
180  Uint32 Gmask = 0;
181  Uint32 Bmask = 0;
182  Uint32 Amask = 0;
183  SDL_Palette *palette;
184  Uint8 *bits;
185  Uint8 *top, *end;
186  SDL_bool topDown;
187  int ExpandBMP;
188  SDL_bool haveRGBMasks = SDL_FALSE;
189  SDL_bool haveAlphaMask = SDL_FALSE;
190  SDL_bool correctAlpha = SDL_FALSE;
191 
192  /* The Win32 BMP file header (14 bytes) */
193  char magic[2];
194  /* Uint32 bfSize; */
195  /* Uint16 bfReserved1; */
196  /* Uint16 bfReserved2; */
197  Uint32 bfOffBits;
198 
199  /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
200  Uint32 biSize;
201  Sint32 biWidth = 0;
202  Sint32 biHeight = 0;
203  /* Uint16 biPlanes; */
204  Uint16 biBitCount = 0;
205  Uint32 biCompression = 0;
206  /* Uint32 biSizeImage; */
207  /* Sint32 biXPelsPerMeter; */
208  /* Sint32 biYPelsPerMeter; */
209  Uint32 biClrUsed = 0;
210  /* Uint32 biClrImportant; */
211 
212  /* Make sure we are passed a valid data source */
213  surface = NULL;
214  was_error = SDL_FALSE;
215  if (src == NULL) {
216  was_error = SDL_TRUE;
217  goto done;
218  }
219 
220  /* Read in the BMP file header */
221  fp_offset = SDL_RWtell(src);
222  SDL_ClearError();
223  if (SDL_RWread(src, magic, 1, 2) != 2) {
225  was_error = SDL_TRUE;
226  goto done;
227  }
228  if (SDL_strncmp(magic, "BM", 2) != 0) {
229  SDL_SetError("File is not a Windows BMP file");
230  was_error = SDL_TRUE;
231  goto done;
232  }
233  /* bfSize = */ SDL_ReadLE32(src);
234  /* bfReserved1 = */ SDL_ReadLE16(src);
235  /* bfReserved2 = */ SDL_ReadLE16(src);
236  bfOffBits = SDL_ReadLE32(src);
237 
238  /* Read the Win32 BITMAPINFOHEADER */
239  biSize = SDL_ReadLE32(src);
240  if (biSize == 12) { /* really old BITMAPCOREHEADER */
241  biWidth = (Uint32) SDL_ReadLE16(src);
242  biHeight = (Uint32) SDL_ReadLE16(src);
243  /* biPlanes = */ SDL_ReadLE16(src);
244  biBitCount = SDL_ReadLE16(src);
245  biCompression = BI_RGB;
246  /* biSizeImage = 0; */
247  /* biXPelsPerMeter = 0; */
248  /* biYPelsPerMeter = 0; */
249  biClrUsed = 0;
250  /* biClrImportant = 0; */
251  } else if (biSize >= 40) { /* some version of BITMAPINFOHEADER */
252  Uint32 headerSize;
253  biWidth = SDL_ReadLE32(src);
254  biHeight = SDL_ReadLE32(src);
255  /* biPlanes = */ SDL_ReadLE16(src);
256  biBitCount = SDL_ReadLE16(src);
257  biCompression = SDL_ReadLE32(src);
258  /* biSizeImage = */ SDL_ReadLE32(src);
259  /* biXPelsPerMeter = */ SDL_ReadLE32(src);
260  /* biYPelsPerMeter = */ SDL_ReadLE32(src);
261  biClrUsed = SDL_ReadLE32(src);
262  /* biClrImportant = */ SDL_ReadLE32(src);
263 
264  /* 64 == BITMAPCOREHEADER2, an incompatible OS/2 2.x extension. Skip this stuff for now. */
265  if (biSize != 64) {
266  /* This is complicated. If compression is BI_BITFIELDS, then
267  we have 3 DWORDS that specify the RGB masks. This is either
268  stored here in an BITMAPV2INFOHEADER (which only differs in
269  that it adds these RGB masks) and biSize >= 52, or we've got
270  these masks stored in the exact same place, but strictly
271  speaking, this is the bmiColors field in BITMAPINFO immediately
272  following the legacy v1 info header, just past biSize. */
273  if (biCompression == BI_BITFIELDS) {
274  haveRGBMasks = SDL_TRUE;
275  Rmask = SDL_ReadLE32(src);
276  Gmask = SDL_ReadLE32(src);
277  Bmask = SDL_ReadLE32(src);
278 
279  /* ...v3 adds an alpha mask. */
280  if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
281  haveAlphaMask = SDL_TRUE;
282  Amask = SDL_ReadLE32(src);
283  }
284  } else {
285  /* the mask fields are ignored for v2+ headers if not BI_BITFIELD. */
286  if (biSize >= 52) { /* BITMAPV2INFOHEADER; adds RGB masks */
287  /*Rmask = */ SDL_ReadLE32(src);
288  /*Gmask = */ SDL_ReadLE32(src);
289  /*Bmask = */ SDL_ReadLE32(src);
290  }
291  if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
292  /*Amask = */ SDL_ReadLE32(src);
293  }
294  }
295 
296  /* Insert other fields here; Wikipedia and MSDN say we're up to
297  v5 of this header, but we ignore those for now (they add gamma,
298  color spaces, etc). Ignoring the weird OS/2 2.x format, we
299  currently parse up to v3 correctly (hopefully!). */
300  }
301 
302  /* skip any header bytes we didn't handle... */
303  headerSize = (Uint32) (SDL_RWtell(src) - (fp_offset + 14));
304  if (biSize > headerSize) {
305  SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
306  }
307  }
308  if (biWidth <= 0 || biHeight == 0) {
309  SDL_SetError("BMP file with bad dimensions (%dx%d)", biWidth, biHeight);
310  was_error = SDL_TRUE;
311  goto done;
312  }
313  if (biHeight < 0) {
314  topDown = SDL_TRUE;
315  biHeight = -biHeight;
316  } else {
317  topDown = SDL_FALSE;
318  }
319 
320  /* Check for read error */
321  if (SDL_strcmp(SDL_GetError(), "") != 0) {
322  was_error = SDL_TRUE;
323  goto done;
324  }
325 
326  /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
327  switch (biBitCount) {
328  case 1:
329  case 4:
330  ExpandBMP = biBitCount;
331  biBitCount = 8;
332  break;
333  case 0:
334  case 2:
335  case 3:
336  case 5:
337  case 6:
338  case 7:
339  SDL_SetError("%d-bpp BMP images are not supported", biBitCount);
340  was_error = SDL_TRUE;
341  goto done;
342  default:
343  ExpandBMP = 0;
344  break;
345  }
346 
347  /* RLE4 and RLE8 BMP compression is supported */
348  switch (biCompression) {
349  case BI_RGB:
350  /* If there are no masks, use the defaults */
351  SDL_assert(!haveRGBMasks);
352  SDL_assert(!haveAlphaMask);
353  /* Default values for the BMP format */
354  switch (biBitCount) {
355  case 15:
356  case 16:
357  Rmask = 0x7C00;
358  Gmask = 0x03E0;
359  Bmask = 0x001F;
360  break;
361  case 24:
362 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
363  Rmask = 0x000000FF;
364  Gmask = 0x0000FF00;
365  Bmask = 0x00FF0000;
366 #else
367  Rmask = 0x00FF0000;
368  Gmask = 0x0000FF00;
369  Bmask = 0x000000FF;
370 #endif
371  break;
372  case 32:
373  /* We don't know if this has alpha channel or not */
374  correctAlpha = SDL_TRUE;
375  Amask = 0xFF000000;
376  Rmask = 0x00FF0000;
377  Gmask = 0x0000FF00;
378  Bmask = 0x000000FF;
379  break;
380  default:
381  break;
382  }
383  break;
384 
385  case BI_BITFIELDS:
386  break; /* we handled this in the info header. */
387 
388  default:
389  break;
390  }
391 
392  /* Create a compatible surface, note that the colors are RGB ordered */
393  surface =
394  SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
395  Bmask, Amask);
396  if (surface == NULL) {
397  was_error = SDL_TRUE;
398  goto done;
399  }
400 
401  /* Load the palette, if any */
402  palette = (surface->format)->palette;
403  if (palette) {
404  if (SDL_RWseek(src, fp_offset+14+biSize, RW_SEEK_SET) < 0) {
406  was_error = SDL_TRUE;
407  goto done;
408  }
409 
410  /*
411  | guich: always use 1<<bpp b/c some bitmaps can bring wrong information
412  | for colorsUsed
413  */
414  /* if (biClrUsed == 0) { */
415  biClrUsed = 1 << biBitCount;
416  /* } */
417  if (biSize == 12) {
418  for (i = 0; i < (int) biClrUsed; ++i) {
419  SDL_RWread(src, &palette->colors[i].b, 1, 1);
420  SDL_RWread(src, &palette->colors[i].g, 1, 1);
421  SDL_RWread(src, &palette->colors[i].r, 1, 1);
422  palette->colors[i].a = SDL_ALPHA_OPAQUE;
423  }
424  } else {
425  for (i = 0; i < (int) biClrUsed; ++i) {
426  SDL_RWread(src, &palette->colors[i].b, 1, 1);
427  SDL_RWread(src, &palette->colors[i].g, 1, 1);
428  SDL_RWread(src, &palette->colors[i].r, 1, 1);
429  SDL_RWread(src, &palette->colors[i].a, 1, 1);
430 
431  /* According to Microsoft documentation, the fourth element
432  is reserved and must be zero, so we shouldn't treat it as
433  alpha.
434  */
435  palette->colors[i].a = SDL_ALPHA_OPAQUE;
436  }
437  }
438  palette->ncolors = biClrUsed;
439  }
440 
441  /* Read the surface pixels. Note that the bmp image is upside down */
442  if (SDL_RWseek(src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
444  was_error = SDL_TRUE;
445  goto done;
446  }
447  if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
448  was_error = (SDL_bool)readRlePixels(surface, src, biCompression == BI_RLE8);
449  if (was_error) SDL_SetError("Error reading from BMP");
450  goto done;
451  }
452  top = (Uint8 *)surface->pixels;
453  end = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
454  switch (ExpandBMP) {
455  case 1:
456  bmpPitch = (biWidth + 7) >> 3;
457  pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
458  break;
459  case 4:
460  bmpPitch = (biWidth + 1) >> 1;
461  pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
462  break;
463  default:
464  pad = ((surface->pitch % 4) ? (4 - (surface->pitch % 4)) : 0);
465  break;
466  }
467  if (topDown) {
468  bits = top;
469  } else {
470  bits = end - surface->pitch;
471  }
472  while (bits >= top && bits < end) {
473  switch (ExpandBMP) {
474  case 1:
475  case 4:{
476  Uint8 pixel = 0;
477  int shift = (8 - ExpandBMP);
478  for (i = 0; i < surface->w; ++i) {
479  if (i % (8 / ExpandBMP) == 0) {
480  if (!SDL_RWread(src, &pixel, 1, 1)) {
481  SDL_SetError("Error reading from BMP");
482  was_error = SDL_TRUE;
483  goto done;
484  }
485  }
486  bits[i] = (pixel >> shift);
487  if (bits[i] >= biClrUsed) {
488  SDL_SetError("A BMP image contains a pixel with a color out of the palette");
489  was_error = SDL_TRUE;
490  goto done;
491  }
492  pixel <<= ExpandBMP;
493  }
494  }
495  break;
496 
497  default:
498  if (SDL_RWread(src, bits, 1, surface->pitch) != surface->pitch) {
500  was_error = SDL_TRUE;
501  goto done;
502  }
503  if (biBitCount == 8 && palette && biClrUsed < (1u << biBitCount)) {
504  for (i = 0; i < surface->w; ++i) {
505  if (bits[i] >= biClrUsed) {
506  SDL_SetError("A BMP image contains a pixel with a color out of the palette");
507  was_error = SDL_TRUE;
508  goto done;
509  }
510  }
511  }
512 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
513  /* Byte-swap the pixels if needed. Note that the 24bpp
514  case has already been taken care of above. */
515  switch (biBitCount) {
516  case 15:
517  case 16:{
518  Uint16 *pix = (Uint16 *) bits;
519  for (i = 0; i < surface->w; i++)
520  pix[i] = SDL_Swap16(pix[i]);
521  break;
522  }
523 
524  case 32:{
525  Uint32 *pix = (Uint32 *) bits;
526  for (i = 0; i < surface->w; i++)
527  pix[i] = SDL_Swap32(pix[i]);
528  break;
529  }
530  }
531 #endif
532  break;
533  }
534  /* Skip padding bytes, ugh */
535  if (pad) {
536  Uint8 padbyte;
537  for (i = 0; i < pad; ++i) {
538  SDL_RWread(src, &padbyte, 1, 1);
539  }
540  }
541  if (topDown) {
542  bits += surface->pitch;
543  } else {
544  bits -= surface->pitch;
545  }
546  }
547  if (correctAlpha) {
549  }
550  done:
551  if (was_error) {
552  if (src) {
553  SDL_RWseek(src, fp_offset, RW_SEEK_SET);
554  }
555  if (surface) {
557  }
558  surface = NULL;
559  }
560  if (freesrc && src) {
561  SDL_RWclose(src);
562  }
563  return (surface);
564 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
#define BI_RLE4
Definition: SDL_bmp.c:46
#define BI_BITFIELDS
Definition: SDL_bmp.c:47
#define BI_RGB
Definition: SDL_bmp.c:44
static void CorrectAlphaChannel(SDL_Surface *surface)
Definition: SDL_bmp.c:142
#define BI_RLE8
Definition: SDL_bmp.c:45
static int readRlePixels(SDL_Surface *surface, SDL_RWops *src, int isRle8)
Definition: SDL_bmp.c:56
#define SDL_GetError
#define SDL_ReadLE16
#define SDL_strncmp
#define SDL_ReadLE32
#define SDL_Error
#define SDL_RWtell
#define SDL_RWread
#define SDL_RWseek
#define SDL_ClearError
#define SDL_strcmp
#define SDL_CreateRGBSurface
#define SDL_FreeSurface
#define SDL_RWclose
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
Definition: SDL_endian.h:165
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
Definition: SDL_endian.h:110
@ SDL_EFSEEK
Definition: SDL_error.h:96
@ SDL_EFREAD
Definition: SDL_error.h:94
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLdouble GLdouble GLdouble GLdouble top
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
#define RW_SEEK_CUR
Definition: SDL_rwops.h:167
#define RW_SEEK_SET
Definition: SDL_rwops.h:166
uint16_t Uint16
Definition: SDL_stdinc.h:197
int32_t Sint32
Definition: SDL_stdinc.h:203
int done
Definition: checkkeys.c:28

References SDL_Color::a, SDL_Color::b, BI_BITFIELDS, BI_RGB, BI_RLE4, BI_RLE8, SDL_Palette::colors, CorrectAlphaChannel(), done, SDL_Color::g, i, int(), SDL_Palette::ncolors, NULL, SDL_Color::r, readRlePixels(), RW_SEEK_CUR, RW_SEEK_SET, SDL_ALPHA_OPAQUE, SDL_assert, SDL_ClearError, SDL_CreateRGBSurface, SDL_EFREAD, SDL_EFSEEK, SDL_Error, SDL_FALSE, SDL_FreeSurface, SDL_GetError, SDL_ReadLE16, SDL_ReadLE32, SDL_RWclose, SDL_RWread, SDL_RWseek, SDL_RWtell, SDL_SetError, SDL_strcmp, SDL_strncmp, SDL_Swap16(), SDL_Swap32(), 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_SaveBMP_RW()

int SDL_SaveBMP_RW ( SDL_Surface surface,
SDL_RWops dst,
int  freedst 
)

Save a surface to a seekable SDL data stream (memory or file).

Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the BMP directly. Other RGB formats with 8-bit or higher get converted to a 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit surface before they are saved. YUV and paletted 1-bit and 4-bit formats are not supported.

If freedst is non-zero, the stream will be closed after being written.

Returns
0 if successful or -1 if there was an error.

Definition at line 567 of file SDL_bmp.c.

568 {
569  Sint64 fp_offset;
570  int i, pad;
572  Uint8 *bits;
573  SDL_bool save32bit = SDL_FALSE;
574  SDL_bool saveLegacyBMP = SDL_FALSE;
575 
576  /* The Win32 BMP file header (14 bytes) */
577  char magic[2] = { 'B', 'M' };
578  Uint32 bfSize;
579  Uint16 bfReserved1;
580  Uint16 bfReserved2;
581  Uint32 bfOffBits;
582 
583  /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
584  Uint32 biSize;
585  Sint32 biWidth;
586  Sint32 biHeight;
587  Uint16 biPlanes;
588  Uint16 biBitCount;
589  Uint32 biCompression;
590  Uint32 biSizeImage;
591  Sint32 biXPelsPerMeter;
592  Sint32 biYPelsPerMeter;
593  Uint32 biClrUsed;
594  Uint32 biClrImportant;
595 
596  /* The additional header members from the Win32 BITMAPV4HEADER struct (108 bytes in total) */
597  Uint32 bV4RedMask = 0;
598  Uint32 bV4GreenMask = 0;
599  Uint32 bV4BlueMask = 0;
600  Uint32 bV4AlphaMask = 0;
601  Uint32 bV4CSType = 0;
602  Sint32 bV4Endpoints[3 * 3] = {0};
603  Uint32 bV4GammaRed = 0;
604  Uint32 bV4GammaGreen = 0;
605  Uint32 bV4GammaBlue = 0;
606 
607  /* Make sure we have somewhere to save */
608  surface = NULL;
609  if (dst) {
610 #ifdef SAVE_32BIT_BMP
611  /* We can save alpha information in a 32-bit BMP */
612  if (saveme->format->BitsPerPixel >= 8 && (saveme->format->Amask ||
613  saveme->map->info.flags & SDL_COPY_COLORKEY)) {
614  save32bit = SDL_TRUE;
615  }
616 #endif /* SAVE_32BIT_BMP */
617 
618  if (saveme->format->palette && !save32bit) {
619  if (saveme->format->BitsPerPixel == 8) {
620  surface = saveme;
621  } else {
622  SDL_SetError("%d bpp BMP files not supported",
623  saveme->format->BitsPerPixel);
624  }
625  } else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
627  (saveme->format->Rmask == 0x00FF0000) &&
628  (saveme->format->Gmask == 0x0000FF00) &&
629  (saveme->format->Bmask == 0x000000FF)
630 #else
631  (saveme->format->Rmask == 0x000000FF) &&
632  (saveme->format->Gmask == 0x0000FF00) &&
633  (saveme->format->Bmask == 0x00FF0000)
634 #endif
635  ) {
636  surface = saveme;
637  } else {
639 
640  /* If the surface has a colorkey or alpha channel we'll save a
641  32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
642  if (save32bit) {
644  } else {
646  }
647  surface = SDL_ConvertSurface(saveme, &format, 0);
648  if (!surface) {
649  SDL_SetError("Couldn't convert image to %d bpp",
650  format.BitsPerPixel);
651  }
652  }
653  } else {
654  /* Set no error here because it may overwrite a more useful message from
655  SDL_RWFromFile() if SDL_SaveBMP_RW() is called from SDL_SaveBMP(). */
656  return -1;
657  }
658 
659  if (save32bit) {
661  }
662 
663  if (surface && (SDL_LockSurface(surface) == 0)) {
664  const int bw = surface->w * surface->format->BytesPerPixel;
665 
666  /* Set the BMP file header values */
667  bfSize = 0; /* We'll write this when we're done */
668  bfReserved1 = 0;
669  bfReserved2 = 0;
670  bfOffBits = 0; /* We'll write this when we're done */
671 
672  /* Write the BMP file header values */
673  fp_offset = SDL_RWtell(dst);
674  SDL_ClearError();
675  SDL_RWwrite(dst, magic, 2, 1);
676  SDL_WriteLE32(dst, bfSize);
677  SDL_WriteLE16(dst, bfReserved1);
678  SDL_WriteLE16(dst, bfReserved2);
679  SDL_WriteLE32(dst, bfOffBits);
680 
681  /* Set the BMP info values */
682  biSize = 40;
683  biWidth = surface->w;
684  biHeight = surface->h;
685  biPlanes = 1;
686  biBitCount = surface->format->BitsPerPixel;
687  biCompression = BI_RGB;
688  biSizeImage = surface->h * surface->pitch;
689  biXPelsPerMeter = 0;
690  biYPelsPerMeter = 0;
691  if (surface->format->palette) {
692  biClrUsed = surface->format->palette->ncolors;
693  } else {
694  biClrUsed = 0;
695  }
696  biClrImportant = 0;
697 
698  /* Set the BMP info values for the version 4 header */
699  if (save32bit && !saveLegacyBMP) {
700  biSize = 108;
701  biCompression = BI_BITFIELDS;
702  /* The BMP format is always little endian, these masks stay the same */
703  bV4RedMask = 0x00ff0000;
704  bV4GreenMask = 0x0000ff00;
705  bV4BlueMask = 0x000000ff;
706  bV4AlphaMask = 0xff000000;
707  bV4CSType = LCS_WINDOWS_COLOR_SPACE;
708  bV4GammaRed = 0;
709  bV4GammaGreen = 0;
710  bV4GammaBlue = 0;
711  }
712 
713  /* Write the BMP info values */
714  SDL_WriteLE32(dst, biSize);
715  SDL_WriteLE32(dst, biWidth);
716  SDL_WriteLE32(dst, biHeight);
717  SDL_WriteLE16(dst, biPlanes);
718  SDL_WriteLE16(dst, biBitCount);
719  SDL_WriteLE32(dst, biCompression);
720  SDL_WriteLE32(dst, biSizeImage);
721  SDL_WriteLE32(dst, biXPelsPerMeter);
722  SDL_WriteLE32(dst, biYPelsPerMeter);
723  SDL_WriteLE32(dst, biClrUsed);
724  SDL_WriteLE32(dst, biClrImportant);
725 
726  /* Write the BMP info values for the version 4 header */
727  if (save32bit && !saveLegacyBMP) {
728  SDL_WriteLE32(dst, bV4RedMask);
729  SDL_WriteLE32(dst, bV4GreenMask);
730  SDL_WriteLE32(dst, bV4BlueMask);
731  SDL_WriteLE32(dst, bV4AlphaMask);
732  SDL_WriteLE32(dst, bV4CSType);
733  for (i = 0; i < 3 * 3; i++) {
734  SDL_WriteLE32(dst, bV4Endpoints[i]);
735  }
736  SDL_WriteLE32(dst, bV4GammaRed);
737  SDL_WriteLE32(dst, bV4GammaGreen);
738  SDL_WriteLE32(dst, bV4GammaBlue);
739  }
740 
741  /* Write the palette (in BGR color order) */
742  if (surface->format->palette) {
743  SDL_Color *colors;
744  int ncolors;
745 
746  colors = surface->format->palette->colors;
747  ncolors = surface->format->palette->ncolors;
748  for (i = 0; i < ncolors; ++i) {
749  SDL_RWwrite(dst, &colors[i].b, 1, 1);
750  SDL_RWwrite(dst, &colors[i].g, 1, 1);
751  SDL_RWwrite(dst, &colors[i].r, 1, 1);
752  SDL_RWwrite(dst, &colors[i].a, 1, 1);
753  }
754  }
755 
756  /* Write the bitmap offset */
757  bfOffBits = (Uint32)(SDL_RWtell(dst) - fp_offset);
758  if (SDL_RWseek(dst, fp_offset + 10, RW_SEEK_SET) < 0) {
760  }
761  SDL_WriteLE32(dst, bfOffBits);
762  if (SDL_RWseek(dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
764  }
765 
766  /* Write the bitmap image upside down */
767  bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
768  pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
769  while (bits > (Uint8 *) surface->pixels) {
770  bits -= surface->pitch;
771  if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
773  break;
774  }
775  if (pad) {
776  const Uint8 padbyte = 0;
777  for (i = 0; i < pad; ++i) {
778  SDL_RWwrite(dst, &padbyte, 1, 1);
779  }
780  }
781  }
782 
783  /* Write the BMP file size */
784  bfSize = (Uint32)(SDL_RWtell(dst) - fp_offset);
785  if (SDL_RWseek(dst, fp_offset + 2, RW_SEEK_SET) < 0) {
787  }
788  SDL_WriteLE32(dst, bfSize);
789  if (SDL_RWseek(dst, fp_offset + bfSize, RW_SEEK_SET) < 0) {
791  }
792 
793  /* Close it up.. */
795  if (surface != saveme) {
797  }
798  }
799 
800  if (freedst && dst) {
801  SDL_RWclose(dst);
802  }
803  return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
804 }
#define LCS_WINDOWS_COLOR_SPACE
Definition: SDL_bmp.c:53
#define SDL_BYTEORDER
#define SDL_RWwrite
#define SDL_WriteLE16
#define SDL_UnlockSurface
#define SDL_GetHintBoolean
#define SDL_LockSurface
#define SDL_WriteLE32
#define SDL_ConvertSurface
#define SDL_LIL_ENDIAN
Definition: SDL_endian.h:37
@ SDL_EFWRITE
Definition: SDL_error.h:95
#define SDL_HINT_BMP_SAVE_LEGACY_FORMAT
Prevent SDL from using version 4 of the bitmap header when saving BMPs.
Definition: SDL_hints.h:1166
GLboolean GLboolean GLboolean GLboolean a
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
Definition: SDL_pixels.c:544
@ SDL_PIXELFORMAT_BGR24
Definition: SDL_pixels.h:240
@ SDL_PIXELFORMAT_BGRA32
Definition: SDL_pixels.h:282
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 *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld endif[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if
static int colors[7]
Definition: testgesture.c:41

References SDL_PixelFormat::Amask, BI_BITFIELDS, BI_RGB, SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::Bmask, colors, endif, SDL_BlitInfo::flags, SDL_Surface::format, SDL_PixelFormat::Gmask, i, SDL_BlitMap::info, LCS_WINDOWS_COLOR_SPACE, SDL_Surface::map, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::Rmask, RW_SEEK_SET, SDL_BYTEORDER, SDL_ClearError, SDL_ConvertSurface, SDL_COPY_COLORKEY, SDL_EFSEEK, SDL_EFWRITE, SDL_Error, SDL_FALSE, SDL_FreeSurface, SDL_GetError, SDL_GetHintBoolean, SDL_HINT_BMP_SAVE_LEGACY_FORMAT, SDL_InitFormat(), SDL_LIL_ENDIAN, SDL_LockSurface, SDL_PIXELFORMAT_BGR24, SDL_PIXELFORMAT_BGRA32, SDL_RWclose, SDL_RWseek, SDL_RWtell, SDL_RWwrite, SDL_SetError, SDL_strcmp, SDL_TRUE, SDL_UnlockSurface, SDL_WriteLE16, and SDL_WriteLE32.

◆ 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 }

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_SetYUVConversionMode()

void SDL_SetYUVConversionMode ( SDL_YUV_CONVERSION_MODE  mode)

Set the YUV conversion mode.

Definition at line 36 of file SDL_yuv.c.

37 {
39 }
static SDL_YUV_CONVERSION_MODE SDL_YUV_ConversionMode
Definition: SDL_yuv.c:33

References SDL_YUV_ConversionMode.

◆ SDL_SoftStretch()

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

Perform a fast, low quality, stretch blit between two surfaces of the same pixel format.

Note
This function uses a static buffer, and is not thread-safe.

Definition at line 203 of file SDL_stretch.c.

205 {
206  int src_locked;
207  int dst_locked;
208  int pos, inc;
209  int dst_maxrow;
210  int src_row, dst_row;
211  Uint8 *srcp = NULL;
212  Uint8 *dstp;
213  SDL_Rect full_src;
214  SDL_Rect full_dst;
215 #ifdef USE_ASM_STRETCH
216  SDL_bool use_asm = SDL_TRUE;
217 #ifdef __GNUC__
218  int u1, u2;
219 #endif
220 #endif /* USE_ASM_STRETCH */
221  const int bpp = dst->format->BytesPerPixel;
222 
223  if (src->format->format != dst->format->format) {
224  return SDL_SetError("Only works with same format surfaces");
225  }
226 
227  /* Verify the blit rectangles */
228  if (srcrect) {
229  if ((srcrect->x < 0) || (srcrect->y < 0) ||
230  ((srcrect->x + srcrect->w) > src->w) ||
231  ((srcrect->y + srcrect->h) > src->h)) {
232  return SDL_SetError("Invalid source blit rectangle");
233  }
234  } else {
235  full_src.x = 0;
236  full_src.y = 0;
237  full_src.w = src->w;
238  full_src.h = src->h;
239  srcrect = &full_src;
240  }
241  if (dstrect) {
242  if ((dstrect->x < 0) || (dstrect->y < 0) ||
243  ((dstrect->x + dstrect->w) > dst->w) ||
244  ((dstrect->y + dstrect->h) > dst->h)) {
245  return SDL_SetError("Invalid destination blit rectangle");
246  }
247  } else {
248  full_dst.x = 0;
249  full_dst.y = 0;
250  full_dst.w = dst->w;
251  full_dst.h = dst->h;
252  dstrect = &full_dst;
253  }
254 
255  /* Lock the destination if it's in hardware */
256  dst_locked = 0;
257  if (SDL_MUSTLOCK(dst)) {
258  if (SDL_LockSurface(dst) < 0) {
259  return SDL_SetError("Unable to lock destination surface");
260  }
261  dst_locked = 1;
262  }
263  /* Lock the source if it's in hardware */
264  src_locked = 0;
265  if (SDL_MUSTLOCK(src)) {
266  if (SDL_LockSurface(src) < 0) {
267  if (dst_locked) {
269  }
270  return SDL_SetError("Unable to lock source surface");
271  }
272  src_locked = 1;
273  }
274 
275  /* Set up the data... */
276  pos = 0x10000;
277  inc = (srcrect->h << 16) / dstrect->h;
278  src_row = srcrect->y;
279  dst_row = dstrect->y;
280 
281 #ifdef USE_ASM_STRETCH
282  /* Write the opcodes for this stretch */
283  if ((bpp == 3) || (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0)) {
284  use_asm = SDL_FALSE;
285  }
286 #endif
287 
288  /* Perform the stretch blit */
289  for (dst_maxrow = dst_row + dstrect->h; dst_row < dst_maxrow; ++dst_row) {
290  dstp = (Uint8 *) dst->pixels + (dst_row * dst->pitch)
291  + (dstrect->x * bpp);
292  while (pos >= 0x10000L) {
293  srcp = (Uint8 *) src->pixels + (src_row * src->pitch)
294  + (srcrect->x * bpp);
295  ++src_row;
296  pos -= 0x10000L;
297  }
298 #ifdef USE_ASM_STRETCH
299  if (use_asm) {
300 #ifdef __GNUC__
301  __asm__ __volatile__("call *%4":"=&D"(u1), "=&S"(u2)
302  :"0"(dstp), "1"(srcp), "r"(copy_row)
303  :"memory");
304 #elif defined(_MSC_VER) || defined(__WATCOMC__)
305  /* *INDENT-OFF* */
306  {
307  void *code = copy_row;
308  __asm {
309  push edi
310  push esi
311  mov edi, dstp
312  mov esi, srcp
313  call dword ptr code
314  pop esi
315  pop edi
316  }
317  }
318  /* *INDENT-ON* */
319 #else
320 #error Need inline assembly for this compiler
321 #endif
322  } else
323 #endif
324  switch (bpp) {
325  case 1:
326  copy_row1(srcp, srcrect->w, dstp, dstrect->w);
327  break;
328  case 2:
329  copy_row2((Uint16 *) srcp, srcrect->w,
330  (Uint16 *) dstp, dstrect->w);
331  break;
332  case 3:
333  copy_row3(srcp, srcrect->w, dstp, dstrect->w);
334  break;
335  case 4:
336  copy_row4((Uint32 *) srcp, srcrect->w,
337  (Uint32 *) dstp, dstrect->w);
338  break;
339  }
340  pos += inc;
341  }
342 
343  /* We need to unlock the surfaces if they're locked */
344  if (dst_locked) {
346  }
347  if (src_locked) {
349  }
350  return (0);
351 }
GLfixed u1
GLfixed GLfixed u2
#define pop
Definition: SDL_qsort.c:195
static void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w)
Definition: SDL_stretch.c:177
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:62
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 *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF PF lsl PF PF PF else PF mov
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr

References bpp, copy_row3(), SDL_Rect::h, if, mov, NULL, pop, ptr, SDL_FALSE, SDL_LockSurface, SDL_MUSTLOCK, SDL_SetError, SDL_TRUE, SDL_UnlockSurface, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

◆ 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 }

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.