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...
 
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 513 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 484 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 201 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 224 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 98 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 104 of file SDL_surface.h.

105 {
106  SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
107  SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
108  SDL_YUV_CONVERSION_BT709, /**< BT.709 */
109  SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */

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 1178 of file SDL_surface.c.

1181 {
1182  SDL_Surface src_surface, dst_surface;
1183  SDL_PixelFormat src_fmt, dst_fmt;
1184  SDL_BlitMap src_blitmap, dst_blitmap;
1185  SDL_Rect rect;
1186  void *nonconst_src = (void *) src;
1187 
1188  /* Check to make sure we are blitting somewhere, so we don't crash */
1189  if (!dst) {
1190  return SDL_InvalidParamError("dst");
1191  }
1192  if (!dst_pitch) {
1193  return SDL_InvalidParamError("dst_pitch");
1194  }
1195 
1196  if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1197  return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1198  } else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
1199  return SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1200  } else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1201  return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1202  }
1203 
1204  /* Fast path for same format copy */
1205  if (src_format == dst_format) {
1206  int i;
1207  const int bpp = SDL_BYTESPERPIXEL(src_format);
1208  width *= bpp;
1209  for (i = height; i--;) {
1210  SDL_memcpy(dst, src, width);
1211  src = (const Uint8*)src + src_pitch;
1212  dst = (Uint8*)dst + dst_pitch;
1213  }
1214  return 0;
1215  }
1216 
1217  if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
1218  src_pitch,
1219  &src_surface, &src_fmt, &src_blitmap)) {
1220  return -1;
1221  }
1222  if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
1223  &dst_surface, &dst_fmt, &dst_blitmap)) {
1224  return -1;
1225  }
1226 
1227  /* Set up the rect and go! */
1228  rect.x = 0;
1229  rect.y = 0;
1230  rect.w = width;
1231  rect.h = height;
1232  return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
1233 }

References SDL_Rect::h, i, rect, SDL_BYTESPERPIXEL, SDL_ConvertPixels_RGB_to_YUV(), SDL_ConvertPixels_YUV_to_RGB(), SDL_ConvertPixels_YUV_to_YUV(), SDL_CreateSurfaceOnStack(), SDL_InvalidParamError, SDL_ISPIXELFORMAT_FOURCC, SDL_LowerBlit(), SDL_memcpy, 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 955 of file SDL_surface.c.

957 {
958  SDL_Surface *convert;
959  Uint32 copy_flags;
960  SDL_Color copy_color;
961  SDL_Rect bounds;
962  int ret;
963 
964  if (!surface) {
965  SDL_InvalidParamError("surface");
966  return NULL;
967  }
968  if (!format) {
969  SDL_InvalidParamError("format");
970  return NULL;
971  }
972 
973  /* Check for empty destination palette! (results in empty image) */
974  if (format->palette != NULL) {
975  int i;
976  for (i = 0; i < format->palette->ncolors; ++i) {
977  if ((format->palette->colors[i].r != 0xFF) ||
978  (format->palette->colors[i].g != 0xFF) ||
979  (format->palette->colors[i].b != 0xFF))
980  break;
981  }
982  if (i == format->palette->ncolors) {
983  SDL_SetError("Empty destination palette");
984  return (NULL);
985  }
986  }
987 
988  /* Create a new surface with the desired format */
989  convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
990  format->BitsPerPixel, format->Rmask,
991  format->Gmask, format->Bmask,
992  format->Amask);
993  if (convert == NULL) {
994  return (NULL);
995  }
996 
997  /* Copy the palette if any */
998  if (format->palette && convert->format->palette) {
999  SDL_memcpy(convert->format->palette->colors,
1000  format->palette->colors,
1001  format->palette->ncolors * sizeof(SDL_Color));
1002  convert->format->palette->ncolors = format->palette->ncolors;
1003  }
1004 
1005  /* Save the original copy flags */
1006  copy_flags = surface->map->info.flags;
1007  copy_color.r = surface->map->info.r;
1008  copy_color.g = surface->map->info.g;
1009  copy_color.b = surface->map->info.b;
1010  copy_color.a = surface->map->info.a;
1011  surface->map->info.r = 0xFF;
1012  surface->map->info.g = 0xFF;
1013  surface->map->info.b = 0xFF;
1014  surface->map->info.a = 0xFF;
1015  surface->map->info.flags = 0;
1016  SDL_InvalidateMap(surface->map);
1017 
1018  /* Copy over the image data */
1019  bounds.x = 0;
1020  bounds.y = 0;
1021  bounds.w = surface->w;
1022  bounds.h = surface->h;
1023  ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);
1024 
1025  /* Clean up the original surface, and update converted surface */
1026  convert->map->info.r = copy_color.r;
1027  convert->map->info.g = copy_color.g;
1028  convert->map->info.b = copy_color.b;
1029  convert->map->info.a = copy_color.a;
1030  convert->map->info.flags =
1031  (copy_flags &
1035  surface->map->info.r = copy_color.r;
1036  surface->map->info.g = copy_color.g;
1037  surface->map->info.b = copy_color.b;
1038  surface->map->info.a = copy_color.a;
1039  surface->map->info.flags = copy_flags;
1040  SDL_InvalidateMap(surface->map);
1041 
1042  /* SDL_LowerBlit failed, and so the conversion */
1043  if (ret < 0) {
1044  SDL_FreeSurface(convert);
1045  return NULL;
1046  }
1047 
1048  if (copy_flags & SDL_COPY_COLORKEY) {
1049  SDL_bool set_colorkey_by_color = SDL_FALSE;
1050  SDL_bool ignore_alpha = SDL_TRUE; /* Ignore, or not, alpha in colorkey comparison */
1051 
1052  if (surface->format->palette) {
1053  if (format->palette &&
1054  surface->format->palette->ncolors <= format->palette->ncolors &&
1055  (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
1056  surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
1057  /* The palette is identical, just set the same colorkey */
1058  SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
1059  } else if (format->Amask) {
1060  set_colorkey_by_color = SDL_TRUE;
1061  ignore_alpha = SDL_FALSE;
1062  } else {
1063  set_colorkey_by_color = SDL_TRUE;
1064  }
1065  } else {
1066  set_colorkey_by_color = SDL_TRUE;
1067  }
1068 
1069  if (set_colorkey_by_color) {
1070  SDL_Surface *tmp;
1071  SDL_Surface *tmp2;
1072  int converted_colorkey = 0;
1073 
1074  /* Create a dummy surface to get the colorkey converted */
1075  tmp = SDL_CreateRGBSurface(0, 1, 1,
1076  surface->format->BitsPerPixel, surface->format->Rmask,
1077  surface->format->Gmask, surface->format->Bmask,
1078  surface->format->Amask);
1079 
1080  /* Share the palette, if any */
1081  if (surface->format->palette) {
1082  SDL_SetSurfacePalette(tmp, surface->format->palette);
1083  }
1084 
1085  SDL_FillRect(tmp, NULL, surface->map->info.colorkey);
1086 
1087  tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
1088 
1089  /* Convertion of the colorkey */
1090  tmp2 = SDL_ConvertSurface(tmp, format, 0);
1091 
1092  /* Get the converted colorkey */
1093  SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);
1094 
1095  SDL_FreeSurface(tmp);
1096  SDL_FreeSurface(tmp2);
1097 
1098  /* Set the converted colorkey on the new surface */
1099  SDL_SetColorKey(convert, 1, converted_colorkey);
1100 
1101  /* This is needed when converting for 3D texture upload */
1102  SDL_ConvertColorkeyToAlpha(convert, ignore_alpha);
1103  }
1104  }
1105  SDL_SetClipRect(convert, &surface->clip_rect);
1106 
1107  /* Enable alpha blending by default if the new surface has an
1108  * alpha channel or alpha modulation */
1109  if ((surface->format->Amask && format->Amask) ||
1110  (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
1112  }
1113  if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
1114  SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
1115  }
1116 
1117  /* We're ready to go! */
1118  return (convert);
1119 }

References SDL_BlitInfo::a, SDL_Color::a, SDL_BlitInfo::b, SDL_Color::b, SDL_PixelFormat::BytesPerPixel, SDL_Surface::clip_rect, SDL_BlitInfo::colorkey, SDL_Palette::colors, SDL_BlitInfo::flags, SDL_Surface::format, SDL_BlitInfo::g, SDL_Color::g, SDL_Rect::h, i, SDL_BlitMap::info, SDL_Surface::map, SDL_Palette::ncolors, NULL, SDL_PixelFormat::palette, SDL_Surface::pixels, SDL_BlitInfo::r, SDL_Color::r, SDL_BLENDMODE_BLEND, SDL_ConvertColorkeyToAlpha(), 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_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_TRUE, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_ConvertSurfaceFormat(), and SDL_DuplicateSurface().

◆ SDL_ConvertSurfaceFormat()

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

Definition at line 1122 of file SDL_surface.c.

1124 {
1125  SDL_PixelFormat *fmt;
1126  SDL_Surface *convert = NULL;
1127 
1128  fmt = SDL_AllocFormat(pixel_format);
1129  if (fmt) {
1130  convert = SDL_ConvertSurface(surface, fmt, flags);
1131  SDL_FreeFormat(fmt);
1132  }
1133  return convert;
1134 }

References NULL, 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 }

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 }

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 }

References SDL_Color::b, SDL_Palette::colors, SDL_Color::g, 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 946 of file SDL_surface.c.

947 {
948  return SDL_ConvertSurface(surface, surface->format, surface->flags);
949 }

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 237 of file SDL_fillrect.c.

238 {
239  SDL_Rect clipped;
240  Uint8 *pixels;
241 
242  if (!dst) {
243  return SDL_SetError("Passed NULL destination surface");
244  }
245 
246  /* This function doesn't work on surfaces < 8 bpp */
247  if (dst->format->BitsPerPixel < 8) {
248  return SDL_SetError("SDL_FillRect(): Unsupported surface format");
249  }
250 
251  /* If 'rect' == NULL, then fill the whole surface */
252  if (rect) {
253  /* Perform clipping */
254  if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
255  return 0;
256  }
257  rect = &clipped;
258  } else {
259  rect = &dst->clip_rect;
260  /* Don't attempt to fill if the surface's clip_rect is empty */
261  if (SDL_RectEmpty(rect)) {
262  return 0;
263  }
264  }
265 
266  /* Perform software fill */
267  if (!dst->pixels) {
268  return SDL_SetError("SDL_FillRect(): You must lock the surface");
269  }
270 
271  pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
272  rect->x * dst->format->BytesPerPixel;
273 
274  switch (dst->format->BytesPerPixel) {
275  case 1:
276  {
277  color |= (color << 8);
278  color |= (color << 16);
279 #ifdef __SSE__
280  if (SDL_HasSSE()) {
281  SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
282  break;
283  }
284 #endif
285  SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
286  break;
287  }
288 
289  case 2:
290  {
291  color |= (color << 16);
292 #ifdef __SSE__
293  if (SDL_HasSSE()) {
294  SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
295  break;
296  }
297 #endif
298  SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
299  break;
300  }
301 
302  case 3:
303  /* 24-bit RGB is a slow path, at least for now. */
304  {
305  SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h);
306  break;
307  }
308 
309  case 4:
310  {
311 #ifdef __SSE__
312  if (SDL_HasSSE()) {
313  SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
314  break;
315  }
316 #endif
317  SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
318  break;
319  }
320  }
321 
322  /* We're done! */
323  return 0;
324 }

References SDL_Rect::h, rect, SDL_FillRect1(), SDL_FillRect2(), SDL_FillRect3(), SDL_FillRect4(), SDL_HasSSE, SDL_IntersectRect, SDL_RectEmpty(), SDL_SetError, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_FillRects().

◆ SDL_FillRects()

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

Definition at line 327 of file SDL_fillrect.c.

329 {
330  int i;
331  int status = 0;
332 
333  if (!rects) {
334  return SDL_SetError("SDL_FillRects() passed NULL rects");
335  }
336 
337  for (i = 0; i < count; ++i) {
338  status += SDL_FillRect(dst, &rects[i], color);
339  }
340  return status;
341 }

References i, SDL_FillRect(), and SDL_SetError.

◆ SDL_FreeSurface()

void SDL_FreeSurface ( SDL_Surface surface)

Definition at line 1239 of file SDL_surface.c.

1240 {
1241  if (surface == NULL) {
1242  return;
1243  }
1244  if (surface->flags & SDL_DONTFREE) {
1245  return;
1246  }
1247  SDL_InvalidateMap(surface->map);
1248 
1249  if (--surface->refcount > 0) {
1250  return;
1251  }
1252  while (surface->locked > 0) {
1254  }
1255  if (surface->flags & SDL_RLEACCEL) {
1257  }
1258  if (surface->format) {
1260  SDL_FreeFormat(surface->format);
1261  surface->format = NULL;
1262  }
1263  if (surface->flags & SDL_PREALLOC) {
1264  /* Don't free */
1265  } else if (surface->flags & SDL_SIMD_ALIGNED) {
1266  /* Free aligned */
1267  SDL_SIMDFree(surface->pixels);
1268  } else {
1269  /* Normal */
1270  SDL_free(surface->pixels);
1271  }
1272  if (surface->map) {
1273  SDL_FreeBlitMap(surface->map);
1274  }
1275  SDL_free(surface);
1276 }

References NULL, SDL_DONTFREE, SDL_free, SDL_FreeBlitMap(), SDL_FreeFormat, 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 585 of file SDL_surface.c.

586 {
587  if (surface && rect) {
588  *rect = surface->clip_rect;
589  }
590 }

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 298 of file SDL_surface.c.

299 {
300  if (!surface) {
301  return SDL_InvalidParamError("surface");
302  }
303 
304  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
305  return SDL_SetError("Surface doesn't have a colorkey");
306  }
307 
308  if (key) {
309  *key = surface->map->info.colorkey;
310  }
311  return 0;
312 }

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 482 of file SDL_surface.c.

483 {
484  if (!surface) {
485  return -1;
486  }
487 
488  if (alpha) {
489  *alpha = surface->map->info.a;
490  }
491  return 0;
492 }

◆ 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 532 of file SDL_surface.c.

533 {
534  if (!surface) {
535  return -1;
536  }
537 
538  if (!blendMode) {
539  return 0;
540  }
541 
542  switch (surface->map->
543  info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)) {
544  case SDL_COPY_BLEND:
546  break;
547  case SDL_COPY_ADD:
549  break;
550  case SDL_COPY_MOD:
552  break;
553  default:
555  break;
556  }
557  return 0;
558 }

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

◆ 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 440 of file SDL_surface.c.

441 {
442  if (!surface) {
443  return -1;
444  }
445 
446  if (r) {
447  *r = surface->map->info.r;
448  }
449  if (g) {
450  *g = surface->map->info.g;
451  }
452  if (b) {
453  *b = surface->map->info.b;
454  }
455  return 0;
456 }

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

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 284 of file SDL_surface.c.

285 {
286  if (!surface) {
287  return SDL_FALSE;
288  }
289 
290  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
291  return SDL_FALSE;
292  }
293 
294  return SDL_TRUE;
295 }

References SDL_COPY_COLORKEY, 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 87 of file SDL_bmp.c.

88 {
89  SDL_bool was_error;
90  Sint64 fp_offset = 0;
91  int bmpPitch;
92  int i, pad;
94  Uint32 Rmask = 0;
95  Uint32 Gmask = 0;
96  Uint32 Bmask = 0;
97  Uint32 Amask = 0;
98  SDL_Palette *palette;
99  Uint8 *bits;
100  Uint8 *top, *end;
101  SDL_bool topDown;
102  int ExpandBMP;
103  SDL_bool haveRGBMasks = SDL_FALSE;
104  SDL_bool haveAlphaMask = SDL_FALSE;
105  SDL_bool correctAlpha = SDL_FALSE;
106 
107  /* The Win32 BMP file header (14 bytes) */
108  char magic[2];
109  /* Uint32 bfSize = 0; */
110  /* Uint16 bfReserved1 = 0; */
111  /* Uint16 bfReserved2 = 0; */
112  Uint32 bfOffBits = 0;
113 
114  /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
115  Uint32 biSize = 0;
116  Sint32 biWidth = 0;
117  Sint32 biHeight = 0;
118  /* Uint16 biPlanes = 0; */
119  Uint16 biBitCount = 0;
120  Uint32 biCompression = 0;
121  /* Uint32 biSizeImage = 0; */
122  /* Sint32 biXPelsPerMeter = 0; */
123  /* Sint32 biYPelsPerMeter = 0; */
124  Uint32 biClrUsed = 0;
125  /* Uint32 biClrImportant = 0; */
126 
127  (void) haveRGBMasks;
128  (void) haveAlphaMask;
129 
130  /* Make sure we are passed a valid data source */
131  surface = NULL;
132  was_error = SDL_FALSE;
133  if (src == NULL) {
134  was_error = SDL_TRUE;
135  goto done;
136  }
137 
138  /* Read in the BMP file header */
139  fp_offset = SDL_RWtell(src);
140  SDL_ClearError();
141  if (SDL_RWread(src, magic, 1, 2) != 2) {
143  was_error = SDL_TRUE;
144  goto done;
145  }
146  if (SDL_strncmp(magic, "BM", 2) != 0) {
147  SDL_SetError("File is not a Windows BMP file");
148  was_error = SDL_TRUE;
149  goto done;
150  }
151  /* bfSize = */ SDL_ReadLE32(src);
152  /* bfReserved1 = */ SDL_ReadLE16(src);
153  /* bfReserved2 = */ SDL_ReadLE16(src);
154  bfOffBits = SDL_ReadLE32(src);
155 
156  /* Read the Win32 BITMAPINFOHEADER */
157  biSize = SDL_ReadLE32(src);
158  if (biSize == 12) { /* really old BITMAPCOREHEADER */
159  biWidth = (Uint32) SDL_ReadLE16(src);
160  biHeight = (Uint32) SDL_ReadLE16(src);
161  /* biPlanes = */ SDL_ReadLE16(src);
162  biBitCount = SDL_ReadLE16(src);
163  biCompression = BI_RGB;
164  } else if (biSize >= 40) { /* some version of BITMAPINFOHEADER */
165  Uint32 headerSize;
166  biWidth = SDL_ReadLE32(src);
167  biHeight = SDL_ReadLE32(src);
168  /* biPlanes = */ SDL_ReadLE16(src);
169  biBitCount = SDL_ReadLE16(src);
170  biCompression = SDL_ReadLE32(src);
171  /* biSizeImage = */ SDL_ReadLE32(src);
172  /* biXPelsPerMeter = */ SDL_ReadLE32(src);
173  /* biYPelsPerMeter = */ SDL_ReadLE32(src);
174  biClrUsed = SDL_ReadLE32(src);
175  /* biClrImportant = */ SDL_ReadLE32(src);
176 
177  /* 64 == BITMAPCOREHEADER2, an incompatible OS/2 2.x extension. Skip this stuff for now. */
178  if (biSize == 64) {
179  /* ignore these extra fields. */
180  if (biCompression == BI_BITFIELDS) {
181  /* this value is actually huffman compression in this variant. */
182  SDL_SetError("Compressed BMP files not supported");
183  was_error = SDL_TRUE;
184  goto done;
185  }
186  } else {
187  /* This is complicated. If compression is BI_BITFIELDS, then
188  we have 3 DWORDS that specify the RGB masks. This is either
189  stored here in an BITMAPV2INFOHEADER (which only differs in
190  that it adds these RGB masks) and biSize >= 52, or we've got
191  these masks stored in the exact same place, but strictly
192  speaking, this is the bmiColors field in BITMAPINFO immediately
193  following the legacy v1 info header, just past biSize. */
194  if (biCompression == BI_BITFIELDS) {
195  haveRGBMasks = SDL_TRUE;
196  Rmask = SDL_ReadLE32(src);
197  Gmask = SDL_ReadLE32(src);
198  Bmask = SDL_ReadLE32(src);
199 
200  /* ...v3 adds an alpha mask. */
201  if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
202  haveAlphaMask = SDL_TRUE;
203  Amask = SDL_ReadLE32(src);
204  }
205  } else {
206  /* the mask fields are ignored for v2+ headers if not BI_BITFIELD. */
207  if (biSize >= 52) { /* BITMAPV2INFOHEADER; adds RGB masks */
208  /*Rmask = */ SDL_ReadLE32(src);
209  /*Gmask = */ SDL_ReadLE32(src);
210  /*Bmask = */ SDL_ReadLE32(src);
211  }
212  if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
213  /*Amask = */ SDL_ReadLE32(src);
214  }
215  }
216 
217  /* Insert other fields here; Wikipedia and MSDN say we're up to
218  v5 of this header, but we ignore those for now (they add gamma,
219  color spaces, etc). Ignoring the weird OS/2 2.x format, we
220  currently parse up to v3 correctly (hopefully!). */
221  }
222 
223  /* skip any header bytes we didn't handle... */
224  headerSize = (Uint32) (SDL_RWtell(src) - (fp_offset + 14));
225  if (biSize > headerSize) {
226  SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
227  }
228  }
229  if (biWidth <= 0 || biHeight == 0) {
230  SDL_SetError("BMP file with bad dimensions (%dx%d)", biWidth, biHeight);
231  was_error = SDL_TRUE;
232  goto done;
233  }
234  if (biHeight < 0) {
235  topDown = SDL_TRUE;
236  biHeight = -biHeight;
237  } else {
238  topDown = SDL_FALSE;
239  }
240 
241  /* Check for read error */
242  if (SDL_strcmp(SDL_GetError(), "") != 0) {
243  was_error = SDL_TRUE;
244  goto done;
245  }
246 
247  /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
248  switch (biBitCount) {
249  case 1:
250  case 4:
251  ExpandBMP = biBitCount;
252  biBitCount = 8;
253  break;
254  case 2:
255  case 3:
256  case 5:
257  case 6:
258  case 7:
259  SDL_SetError("%d-bpp BMP images are not supported", biBitCount);
260  was_error = SDL_TRUE;
261  goto done;
262  default:
263  ExpandBMP = 0;
264  break;
265  }
266 
267  /* We don't support any BMP compression right now */
268  switch (biCompression) {
269  case BI_RGB:
270  /* If there are no masks, use the defaults */
271  SDL_assert(!haveRGBMasks);
272  SDL_assert(!haveAlphaMask);
273  /* Default values for the BMP format */
274  switch (biBitCount) {
275  case 15:
276  case 16:
277  Rmask = 0x7C00;
278  Gmask = 0x03E0;
279  Bmask = 0x001F;
280  break;
281  case 24:
282 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
283  Rmask = 0x000000FF;
284  Gmask = 0x0000FF00;
285  Bmask = 0x00FF0000;
286 #else
287  Rmask = 0x00FF0000;
288  Gmask = 0x0000FF00;
289  Bmask = 0x000000FF;
290 #endif
291  break;
292  case 32:
293  /* We don't know if this has alpha channel or not */
294  correctAlpha = SDL_TRUE;
295  Amask = 0xFF000000;
296  Rmask = 0x00FF0000;
297  Gmask = 0x0000FF00;
298  Bmask = 0x000000FF;
299  break;
300  default:
301  break;
302  }
303  break;
304 
305  case BI_BITFIELDS:
306  break; /* we handled this in the info header. */
307 
308  default:
309  SDL_SetError("Compressed BMP files not supported");
310  was_error = SDL_TRUE;
311  goto done;
312  }
313 
314  /* Create a compatible surface, note that the colors are RGB ordered */
315  surface =
316  SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
317  Bmask, Amask);
318  if (surface == NULL) {
319  was_error = SDL_TRUE;
320  goto done;
321  }
322 
323  /* Load the palette, if any */
324  palette = (surface->format)->palette;
325  if (palette) {
326  SDL_assert(biBitCount <= 8);
327  if (biClrUsed == 0) {
328  biClrUsed = 1 << biBitCount;
329  } else if (biClrUsed > (Uint32)(1 << biBitCount)) {
330  SDL_SetError("BMP file has an invalid number of colors");
331  was_error = SDL_TRUE;
332  goto done;
333  }
334  if ((int) biClrUsed > palette->ncolors) {
335  SDL_Color *colors;
336  int ncolors = biClrUsed;
337  colors =
338  (SDL_Color *) SDL_realloc(palette->colors,
339  ncolors *
340  sizeof(*palette->colors));
341  if (!colors) {
342  SDL_OutOfMemory();
343  was_error = SDL_TRUE;
344  goto done;
345  }
346  palette->ncolors = ncolors;
347  palette->colors = colors;
348  } else if ((int) biClrUsed < palette->ncolors) {
349  palette->ncolors = biClrUsed;
350  }
351  if (biSize == 12) {
352  for (i = 0; i < (int) biClrUsed; ++i) {
353  SDL_RWread(src, &palette->colors[i].b, 1, 1);
354  SDL_RWread(src, &palette->colors[i].g, 1, 1);
355  SDL_RWread(src, &palette->colors[i].r, 1, 1);
356  palette->colors[i].a = SDL_ALPHA_OPAQUE;
357  }
358  } else {
359  for (i = 0; i < (int) biClrUsed; ++i) {
360  SDL_RWread(src, &palette->colors[i].b, 1, 1);
361  SDL_RWread(src, &palette->colors[i].g, 1, 1);
362  SDL_RWread(src, &palette->colors[i].r, 1, 1);
363  SDL_RWread(src, &palette->colors[i].a, 1, 1);
364 
365  /* According to Microsoft documentation, the fourth element
366  is reserved and must be zero, so we shouldn't treat it as
367  alpha.
368  */
369  palette->colors[i].a = SDL_ALPHA_OPAQUE;
370  }
371  }
372  }
373 
374  /* Read the surface pixels. Note that the bmp image is upside down */
375  if (SDL_RWseek(src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
377  was_error = SDL_TRUE;
378  goto done;
379  }
380  top = (Uint8 *)surface->pixels;
381  end = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
382  switch (ExpandBMP) {
383  case 1:
384  bmpPitch = (biWidth + 7) >> 3;
385  pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
386  break;
387  case 4:
388  bmpPitch = (biWidth + 1) >> 1;
389  pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
390  break;
391  default:
392  pad = ((surface->pitch % 4) ? (4 - (surface->pitch % 4)) : 0);
393  break;
394  }
395  if (topDown) {
396  bits = top;
397  } else {
398  bits = end - surface->pitch;
399  }
400  while (bits >= top && bits < end) {
401  switch (ExpandBMP) {
402  case 1:
403  case 4:{
404  Uint8 pixel = 0;
405  int shift = (8 - ExpandBMP);
406  for (i = 0; i < surface->w; ++i) {
407  if (i % (8 / ExpandBMP) == 0) {
408  if (!SDL_RWread(src, &pixel, 1, 1)) {
409  SDL_SetError("Error reading from BMP");
410  was_error = SDL_TRUE;
411  goto done;
412  }
413  }
414  bits[i] = (pixel >> shift);
415  if (bits[i] >= biClrUsed) {
416  SDL_SetError("A BMP image contains a pixel with a color out of the palette");
417  was_error = SDL_TRUE;
418  goto done;
419  }
420  pixel <<= ExpandBMP;
421  }
422  }
423  break;
424 
425  default:
426  if (SDL_RWread(src, bits, 1, surface->pitch) != surface->pitch) {
428  was_error = SDL_TRUE;
429  goto done;
430  }
431  if (biBitCount == 8 && palette && biClrUsed < (Uint32)(1 << biBitCount)) {
432  for (i = 0; i < surface->w; ++i) {
433  if (bits[i] >= biClrUsed) {
434  SDL_SetError("A BMP image contains a pixel with a color out of the palette");
435  was_error = SDL_TRUE;
436  goto done;
437  }
438  }
439  }
440 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
441  /* Byte-swap the pixels if needed. Note that the 24bpp
442  case has already been taken care of above. */
443  switch (biBitCount) {
444  case 15:
445  case 16:{
446  Uint16 *pix = (Uint16 *) bits;
447  for (i = 0; i < surface->w; i++)
448  pix[i] = SDL_Swap16(pix[i]);
449  break;
450  }
451 
452  case 32:{
453  Uint32 *pix = (Uint32 *) bits;
454  for (i = 0; i < surface->w; i++)
455  pix[i] = SDL_Swap32(pix[i]);
456  break;
457  }
458  }
459 #endif
460  break;
461  }
462  /* Skip padding bytes, ugh */
463  if (pad) {
464  Uint8 padbyte;
465  for (i = 0; i < pad; ++i) {
466  SDL_RWread(src, &padbyte, 1, 1);
467  }
468  }
469  if (topDown) {
470  bits += surface->pitch;
471  } else {
472  bits -= surface->pitch;
473  }
474  }
475  if (correctAlpha) {
477  }
478  done:
479  if (was_error) {
480  if (src) {
481  SDL_RWseek(src, fp_offset, RW_SEEK_SET);
482  }
484  surface = NULL;
485  }
486  if (freesrc && src) {
487  SDL_RWclose(src);
488  }
489  return (surface);
490 }

References SDL_Color::a, SDL_Color::b, BI_BITFIELDS, BI_RGB, colors, SDL_Palette::colors, CorrectAlphaChannel(), done, SDL_Color::g, i, SDL_Palette::ncolors, NULL, SDL_Color::r, 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_OutOfMemory, SDL_ReadLE16, SDL_ReadLE32, SDL_realloc, SDL_RWclose, SDL_RWread, SDL_RWseek, SDL_RWtell, SDL_SetError, SDL_strcmp, SDL_strncmp, SDL_Swap16(), SDL_Swap32(), SDL_TRUE, and void.

◆ 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 907 of file SDL_surface.c.

908 {
909  if (!surface->locked) {
910  /* Perform the lock */
911  if (surface->flags & SDL_RLEACCEL) {
913  surface->flags |= SDL_RLEACCEL; /* save accel'd state */
914  }
915  }
916 
917  /* Increment the surface lock count, for recursive locks */
918  ++surface->locked;
919 
920  /* Ready to go.. */
921  return (0);
922 }

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 604 of file SDL_surface.c.

606 {
607  /* Check to make sure the blit mapping is valid */
608  if ((src->map->dst != dst) ||
609  (dst->format->palette &&
610  src->map->dst_palette_version != dst->format->palette->version) ||
611  (src->format->palette &&
612  src->map->src_palette_version != src->format->palette->version)) {
613  if (SDL_MapSurface(src, dst) < 0) {
614  return (-1);
615  }
616  /* just here for debugging */
617 /* printf */
618 /* ("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", */
619 /* src, dst->flags, src->map->info.flags, dst, dst->flags, */
620 /* dst->map->info.flags, src->map->blit); */
621  }
622  return (src->map->blit(src, srcrect, dst, dstrect));
623 }

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 880 of file SDL_surface.c.

882 {
883  static const Uint32 complex_copy_flags = (
887  );
888 
889  if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
890  src->map->info.flags |= SDL_COPY_NEAREST;
891  SDL_InvalidateMap(src->map);
892  }
893 
894  if ( !(src->map->info.flags & complex_copy_flags) &&
895  src->format->format == dst->format->format &&
896  !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
897  return SDL_SoftStretch( src, srcrect, dst, dstrect );
898  } else {
899  return SDL_LowerBlit( src, srcrect, dst, dstrect );
900  }
901 }

References SDL_COPY_ADD, SDL_COPY_BLEND, SDL_COPY_COLORKEY, SDL_COPY_MOD, SDL_COPY_MODULATE_ALPHA, SDL_COPY_MODULATE_COLOR, 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 493 of file SDL_bmp.c.

494 {
495  Sint64 fp_offset;
496  int i, pad;
498  Uint8 *bits;
499  SDL_bool save32bit = SDL_FALSE;
500  SDL_bool saveLegacyBMP = SDL_FALSE;
501 
502  /* The Win32 BMP file header (14 bytes) */
503  char magic[2] = { 'B', 'M' };
504  Uint32 bfSize;
505  Uint16 bfReserved1;
506  Uint16 bfReserved2;
507  Uint32 bfOffBits;
508 
509  /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
510  Uint32 biSize;
511  Sint32 biWidth;
512  Sint32 biHeight;
513  Uint16 biPlanes;
514  Uint16 biBitCount;
515  Uint32 biCompression;
516  Uint32 biSizeImage;
517  Sint32 biXPelsPerMeter;
518  Sint32 biYPelsPerMeter;
519  Uint32 biClrUsed;
520  Uint32 biClrImportant;
521 
522  /* The additional header members from the Win32 BITMAPV4HEADER struct (108 bytes in total) */
523  Uint32 bV4RedMask = 0;
524  Uint32 bV4GreenMask = 0;
525  Uint32 bV4BlueMask = 0;
526  Uint32 bV4AlphaMask = 0;
527  Uint32 bV4CSType = 0;
528  Sint32 bV4Endpoints[3 * 3] = {0};
529  Uint32 bV4GammaRed = 0;
530  Uint32 bV4GammaGreen = 0;
531  Uint32 bV4GammaBlue = 0;
532 
533  /* Make sure we have somewhere to save */
534  surface = NULL;
535  if (dst) {
536 #ifdef SAVE_32BIT_BMP
537  /* We can save alpha information in a 32-bit BMP */
538  if (saveme->format->BitsPerPixel >= 8 && (saveme->format->Amask ||
539  saveme->map->info.flags & SDL_COPY_COLORKEY)) {
540  save32bit = SDL_TRUE;
541  }
542 #endif /* SAVE_32BIT_BMP */
543 
544  if (saveme->format->palette && !save32bit) {
545  if (saveme->format->BitsPerPixel == 8) {
546  surface = saveme;
547  } else {
548  SDL_SetError("%d bpp BMP files not supported",
549  saveme->format->BitsPerPixel);
550  }
551  } else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
553  (saveme->format->Rmask == 0x00FF0000) &&
554  (saveme->format->Gmask == 0x0000FF00) &&
555  (saveme->format->Bmask == 0x000000FF)
556 #else
557  (saveme->format->Rmask == 0x000000FF) &&
558  (saveme->format->Gmask == 0x0000FF00) &&
559  (saveme->format->Bmask == 0x00FF0000)
560 #endif
561  ) {
562  surface = saveme;
563  } else {
565 
566  /* If the surface has a colorkey or alpha channel we'll save a
567  32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
568  if (save32bit) {
570  } else {
572  }
573  surface = SDL_ConvertSurface(saveme, &format, 0);
574  if (!surface) {
575  SDL_SetError("Couldn't convert image to %d bpp",
576  format.BitsPerPixel);
577  }
578  }
579  } else {
580  /* Set no error here because it may overwrite a more useful message from
581  SDL_RWFromFile() if SDL_SaveBMP_RW() is called from SDL_SaveBMP(). */
582  return -1;
583  }
584 
585  if (save32bit) {
587  }
588 
589  if (surface && (SDL_LockSurface(surface) == 0)) {
590  const int bw = surface->w * surface->format->BytesPerPixel;
591 
592  /* Set the BMP file header values */
593  bfSize = 0; /* We'll write this when we're done */
594  bfReserved1 = 0;
595  bfReserved2 = 0;
596  bfOffBits = 0; /* We'll write this when we're done */
597 
598  /* Write the BMP file header values */
599  fp_offset = SDL_RWtell(dst);
600  SDL_ClearError();
601  SDL_RWwrite(dst, magic, 2, 1);
602  SDL_WriteLE32(dst, bfSize);
603  SDL_WriteLE16(dst, bfReserved1);
604  SDL_WriteLE16(dst, bfReserved2);
605  SDL_WriteLE32(dst, bfOffBits);
606 
607  /* Set the BMP info values */
608  biSize = 40;
609  biWidth = surface->w;
610  biHeight = surface->h;
611  biPlanes = 1;
612  biBitCount = surface->format->BitsPerPixel;
613  biCompression = BI_RGB;
614  biSizeImage = surface->h * surface->pitch;
615  biXPelsPerMeter = 0;
616  biYPelsPerMeter = 0;
617  if (surface->format->palette) {
618  biClrUsed = surface->format->palette->ncolors;
619  } else {
620  biClrUsed = 0;
621  }
622  biClrImportant = 0;
623 
624  /* Set the BMP info values for the version 4 header */
625  if (save32bit && !saveLegacyBMP) {
626  biSize = 108;
627  biCompression = BI_BITFIELDS;
628  /* The BMP format is always little endian, these masks stay the same */
629  bV4RedMask = 0x00ff0000;
630  bV4GreenMask = 0x0000ff00;
631  bV4BlueMask = 0x000000ff;
632  bV4AlphaMask = 0xff000000;
633  bV4CSType = LCS_WINDOWS_COLOR_SPACE;
634  bV4GammaRed = 0;
635  bV4GammaGreen = 0;
636  bV4GammaBlue = 0;
637  }
638 
639  /* Write the BMP info values */
640  SDL_WriteLE32(dst, biSize);
641  SDL_WriteLE32(dst, biWidth);
642  SDL_WriteLE32(dst, biHeight);
643  SDL_WriteLE16(dst, biPlanes);
644  SDL_WriteLE16(dst, biBitCount);
645  SDL_WriteLE32(dst, biCompression);
646  SDL_WriteLE32(dst, biSizeImage);
647  SDL_WriteLE32(dst, biXPelsPerMeter);
648  SDL_WriteLE32(dst, biYPelsPerMeter);
649  SDL_WriteLE32(dst, biClrUsed);
650  SDL_WriteLE32(dst, biClrImportant);
651 
652  /* Write the BMP info values for the version 4 header */
653  if (save32bit && !saveLegacyBMP) {
654  SDL_WriteLE32(dst, bV4RedMask);
655  SDL_WriteLE32(dst, bV4GreenMask);
656  SDL_WriteLE32(dst, bV4BlueMask);
657  SDL_WriteLE32(dst, bV4AlphaMask);
658  SDL_WriteLE32(dst, bV4CSType);
659  for (i = 0; i < 3 * 3; i++) {
660  SDL_WriteLE32(dst, bV4Endpoints[i]);
661  }
662  SDL_WriteLE32(dst, bV4GammaRed);
663  SDL_WriteLE32(dst, bV4GammaGreen);
664  SDL_WriteLE32(dst, bV4GammaBlue);
665  }
666 
667  /* Write the palette (in BGR color order) */
668  if (surface->format->palette) {
669  SDL_Color *colors;
670  int ncolors;
671 
672  colors = surface->format->palette->colors;
673  ncolors = surface->format->palette->ncolors;
674  for (i = 0; i < ncolors; ++i) {
675  SDL_RWwrite(dst, &colors[i].b, 1, 1);
676  SDL_RWwrite(dst, &colors[i].g, 1, 1);
677  SDL_RWwrite(dst, &colors[i].r, 1, 1);
678  SDL_RWwrite(dst, &colors[i].a, 1, 1);
679  }
680  }
681 
682  /* Write the bitmap offset */
683  bfOffBits = (Uint32)(SDL_RWtell(dst) - fp_offset);
684  if (SDL_RWseek(dst, fp_offset + 10, RW_SEEK_SET) < 0) {
686  }
687  SDL_WriteLE32(dst, bfOffBits);
688  if (SDL_RWseek(dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
690  }
691 
692  /* Write the bitmap image upside down */
693  bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
694  pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
695  while (bits > (Uint8 *) surface->pixels) {
696  bits -= surface->pitch;
697  if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
699  break;
700  }
701  if (pad) {
702  const Uint8 padbyte = 0;
703  for (i = 0; i < pad; ++i) {
704  SDL_RWwrite(dst, &padbyte, 1, 1);
705  }
706  }
707  }
708 
709  /* Write the BMP file size */
710  bfSize = (Uint32)(SDL_RWtell(dst) - fp_offset);
711  if (SDL_RWseek(dst, fp_offset + 2, RW_SEEK_SET) < 0) {
713  }
714  SDL_WriteLE32(dst, bfSize);
715  if (SDL_RWseek(dst, fp_offset + bfSize, RW_SEEK_SET) < 0) {
717  }
718 
719  /* Close it up.. */
721  if (surface != saveme) {
723  }
724  }
725 
726  if (freedst && dst) {
727  SDL_RWclose(dst);
728  }
729  return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
730 }

References SDL_PixelFormat::Amask, BI_BITFIELDS, BI_RGB, SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::Bmask, colors, 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 561 of file SDL_surface.c.

562 {
563  SDL_Rect full_rect;
564 
565  /* Don't do anything if there's no surface to act on */
566  if (!surface) {
567  return SDL_FALSE;
568  }
569 
570  /* Set up the full surface rectangle */
571  full_rect.x = 0;
572  full_rect.y = 0;
573  full_rect.w = surface->w;
574  full_rect.h = surface->h;
575 
576  /* Set the clipping rectangle */
577  if (!rect) {
578  surface->clip_rect = full_rect;
579  return SDL_TRUE;
580  }
581  return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
582 }

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 253 of file SDL_surface.c.

254 {
255  int flags;
256 
257  if (!surface) {
258  return SDL_InvalidParamError("surface");
259  }
260 
261  if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
262  return SDL_InvalidParamError("key");
263  }
264 
265  if (flag & SDL_RLEACCEL) {
267  }
268 
269  flags = surface->map->info.flags;
270  if (flag) {
271  surface->map->info.flags |= SDL_COPY_COLORKEY;
272  surface->map->info.colorkey = key;
273  } else {
274  surface->map->info.flags &= ~SDL_COPY_COLORKEY;
275  }
276  if (surface->map->info.flags != flags) {
278  }
279 
280  return 0;
281 }

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 459 of file SDL_surface.c.

460 {
461  int flags;
462 
463  if (!surface) {
464  return -1;
465  }
466 
467  surface->map->info.a = alpha;
468 
469  flags = surface->map->info.flags;
470  if (alpha != 0xFF) {
471  surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
472  } else {
473  surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
474  }
475  if (surface->map->info.flags != flags) {
477  }
478  return 0;
479 }

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 495 of file SDL_surface.c.

496 {
497  int flags, status;
498 
499  if (!surface) {
500  return -1;
501  }
502 
503  status = 0;
504  flags = surface->map->info.flags;
505  surface->map->info.flags &=
507  switch (blendMode) {
508  case SDL_BLENDMODE_NONE:
509  break;
510  case SDL_BLENDMODE_BLEND:
511  surface->map->info.flags |= SDL_COPY_BLEND;
512  break;
513  case SDL_BLENDMODE_ADD:
514  surface->map->info.flags |= SDL_COPY_ADD;
515  break;
516  case SDL_BLENDMODE_MOD:
517  surface->map->info.flags |= SDL_COPY_MOD;
518  break;
519  default:
520  status = SDL_Unsupported();
521  break;
522  }
523 
524  if (surface->map->info.flags != flags) {
526  }
527 
528  return status;
529 }

References blendMode, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, SDL_BLENDMODE_NONE, SDL_COPY_ADD, SDL_COPY_BLEND, SDL_COPY_MOD, 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 414 of file SDL_surface.c.

415 {
416  int flags;
417 
418  if (!surface) {
419  return -1;
420  }
421 
422  surface->map->info.r = r;
423  surface->map->info.g = g;
424  surface->map->info.b = b;
425 
426  flags = surface->map->info.flags;
427  if (r != 0xFF || g != 0xFF || b != 0xFF) {
428  surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
429  } else {
430  surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
431  }
432  if (surface->map->info.flags != flags) {
434  }
435  return 0;
436 }

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 }

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 }

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 }

References copy_row3(), SDL_Rect::h, NULL, pop, 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 928 of file SDL_surface.c.

929 {
930  /* Only perform an unlock if we are locked */
931  if (!surface->locked || (--surface->locked > 0)) {
932  return;
933  }
934 
935  /* Update RLE encoded surface with new data */
936  if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
937  surface->flags &= ~SDL_RLEACCEL; /* stop lying */
939  }
940 }

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 627 of file SDL_surface.c.

629 {
630  SDL_Rect fulldst;
631  int srcx, srcy, w, h;
632 
633  /* Make sure the surfaces aren't locked */
634  if (!src || !dst) {
635  return SDL_SetError("SDL_UpperBlit: passed a NULL surface");
636  }
637  if (src->locked || dst->locked) {
638  return SDL_SetError("Surfaces must not be locked during blit");
639  }
640 
641  /* If the destination rectangle is NULL, use the entire dest surface */
642  if (dstrect == NULL) {
643  fulldst.x = fulldst.y = 0;
644  fulldst.w = dst->w;
645  fulldst.h = dst->h;
646  dstrect = &fulldst;
647  }
648 
649  /* clip the source rectangle to the source surface */
650  if (srcrect) {
651  int maxw, maxh;
652 
653  srcx = srcrect->x;
654  w = srcrect->w;
655  if (srcx < 0) {
656  w += srcx;
657  dstrect->x -= srcx;
658  srcx = 0;
659  }
660  maxw = src->w - srcx;
661  if (maxw < w)
662  w = maxw;
663 
664  srcy = srcrect->y;
665  h = srcrect->h;
666  if (srcy < 0) {
667  h += srcy;
668  dstrect->y -= srcy;
669  srcy = 0;
670  }
671  maxh = src->h - srcy;
672  if (maxh < h)
673  h = maxh;
674 
675  } else {
676  srcx = srcy = 0;
677  w = src->w;
678  h = src->h;
679  }
680 
681  /* clip the destination rectangle against the clip rectangle */
682  {
683  SDL_Rect *clip = &dst->clip_rect;
684  int dx, dy;
685 
686  dx = clip->x - dstrect->x;
687  if (dx > 0) {
688  w -= dx;
689  dstrect->x += dx;
690  srcx += dx;
691  }
692  dx = dstrect->x + w - clip->x - clip->w;
693  if (dx > 0)
694  w -= dx;
695 
696  dy = clip->y - dstrect->y;
697  if (dy > 0) {
698  h -= dy;
699  dstrect->y += dy;
700  srcy += dy;
701  }
702  dy = dstrect->y + h - clip->y - clip->h;
703  if (dy > 0)
704  h -= dy;
705  }
706 
707  /* Switch back to a fast blit if we were previously stretching */
708  if (src->map->info.flags & SDL_COPY_NEAREST) {
709  src->map->info.flags &= ~SDL_COPY_NEAREST;
710  SDL_InvalidateMap(src->map);
711  }
712 
713  if (w > 0 && h > 0) {
714  SDL_Rect sr;
715  sr.x = srcx;
716  sr.y = srcy;
717  sr.w = dstrect->w = w;
718  sr.h = dstrect->h = h;
719  return SDL_LowerBlit(src, &sr, dst, dstrect);
720  }
721  dstrect->w = dstrect->h = 0;
722  return 0;
723 }

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 726 of file SDL_surface.c.

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

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

SDL_UnlockSurface
#define SDL_UnlockSurface
Definition: SDL_dynapi_overrides.h:449
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:386
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
Sint32
int32_t Sint32
Definition: SDL_stdinc.h:197
SDL_GetYUVConversionMode
SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode()
Get the YUV conversion mode.
Definition: SDL_yuv.c:41
SDL_PixelFormat::BytesPerPixel
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
SDL_FillRect
int SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
Definition: SDL_fillrect.c:237
Sint64
int64_t Sint64
Definition: SDL_stdinc.h:210
SDL_Palette::ncolors
int ncolors
Definition: SDL_pixels.h:306
blendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
SDL_Color::b
Uint8 b
Definition: SDL_pixels.h:299
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:70
SDL_ClearError
#define SDL_ClearError
Definition: SDL_dynapi_overrides.h:114
SDL_LowerBlit
int SDL_LowerBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:604
SDL_BlitMap
Definition: SDL_blit.h:86
SDL_SoftStretch
#define SDL_SoftStretch
Definition: SDL_dynapi_overrides.h:470
SDL_YUV_SD_THRESHOLD
#define SDL_YUV_SD_THRESHOLD
Definition: SDL_yuv.c:30
copy_row3
static void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w)
Definition: SDL_stretch.c:177
SDL_BLENDMODE_ADD
@ SDL_BLENDMODE_ADD
Definition: SDL_blendmode.h:47
end
GLuint GLuint end
Definition: SDL_opengl.h:1571
SDL_COPY_RLE_COLORKEY
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:42
SDL_RLEACCEL
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
NULL
#define NULL
Definition: begin_code.h:167
surface
EGLSurface surface
Definition: eglext.h:248
SDL_ALPHA_OPAQUE
#define SDL_ALPHA_OPAQUE
Definition: SDL_pixels.h:46
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:76
SDL_Swap16
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
Definition: SDL_endian.h:107
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1109
mode
GLenum mode
Definition: SDL_opengl_glext.h:1122
SDL_BlitInfo::b
Uint8 b
Definition: SDL_blit.h:70
SDL_WriteLE16
#define SDL_WriteLE16
Definition: SDL_dynapi_overrides.h:364
SDL_UnRLESurface
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
Definition: SDL_RLEaccel.c:1545
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_Color::r
Uint8 r
Definition: SDL_pixels.h:297
SDL_CreateSurfaceOnStack
static SDL_INLINE SDL_bool SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format, void *pixels, int pitch, SDL_Surface *surface, SDL_PixelFormat *format, SDL_BlitMap *blitmap)
Definition: SDL_surface.c:1140
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
SDL_FillRect4
static void SDL_FillRect4(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:225
SDL_MasksToPixelFormatEnum
#define SDL_MasksToPixelFormatEnum
Definition: SDL_dynapi_overrides.h:279
SDL_ConvertSurface
#define SDL_ConvertSurface
Definition: SDL_dynapi_overrides.h:463
SDL_realloc
#define SDL_realloc
Definition: SDL_dynapi_overrides.h:376
top
GLdouble GLdouble GLdouble GLdouble top
Definition: SDL_opengl_glext.h:6103
SDL_AllocBlitMap
SDL_BlitMap * SDL_AllocBlitMap(void)
Definition: SDL_pixels.c:952
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_LowerBlitScaled
int SDL_LowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:880
SDL_MUSTLOCK
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:62
SDL_IntersectRect
#define SDL_IntersectRect
Definition: SDL_dynapi_overrides.h:294
SDL_floor
#define SDL_floor
Definition: SDL_dynapi_overrides.h:431
SDL_DONTFREE
#define SDL_DONTFREE
Definition: SDL_surface.h:55
SDL_COPY_COLORKEY
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:39
SDL_RectEmpty
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
Definition: SDL_rect.h:108
SDL_ISPIXELFORMAT_INDEXED
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
SDL_BlitMap::info
SDL_BlitInfo info
Definition: SDL_blit.h:92
SDL_RWread
#define SDL_RWread
Definition: SDL_dynapi_overrides.h:723
SDL_strncmp
#define SDL_strncmp
Definition: SDL_dynapi_overrides.h:418
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
SDL_ReadLE32
#define SDL_ReadLE32
Definition: SDL_dynapi_overrides.h:359
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_Rect::x
int x
Definition: SDL_rect.h:79
SDL_AllocFormat
#define SDL_AllocFormat
Definition: SDL_dynapi_overrides.h:280
SDL_ConvertSurface
SDL_Surface * SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format, Uint32 flags)
Definition: SDL_surface.c:955
SDL_Rect::w
int w
Definition: SDL_rect.h:80
SDL_Color::a
Uint8 a
Definition: SDL_pixels.h:300
SDL_COPY_RLE_DESIRED
#define SDL_COPY_RLE_DESIRED
Definition: SDL_blit.h:41
SDL_PREALLOC
#define SDL_PREALLOC
Definition: SDL_surface.h:53
SDL_YUV_CONVERSION_JPEG
@ SDL_YUV_CONVERSION_JPEG
Definition: SDL_surface.h:106
alpha
GLfloat GLfloat GLfloat alpha
Definition: SDL_opengl_glext.h:412
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
SDL_SetSurfaceBlendMode
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL_surface.c:495
SDL_Error
#define SDL_Error
Definition: SDL_dynapi_overrides.h:115
u2
GLfixed GLfixed u2
Definition: SDL_opengl_glext.h:4558
SDL_RWwrite
#define SDL_RWwrite
Definition: SDL_dynapi_overrides.h:724
SDL_BLENDMODE_MOD
@ SDL_BLENDMODE_MOD
Definition: SDL_blendmode.h:50
SDL_LIL_ENDIAN
#define SDL_LIL_ENDIAN
Definition: SDL_endian.h:37
SDL_BLENDMODE_NONE
@ SDL_BLENDMODE_NONE
Definition: SDL_blendmode.h:42
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
SDL_GetHintBoolean
#define SDL_GetHintBoolean
Definition: SDL_dynapi_overrides.h:608
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
done
int done
Definition: checkkeys.c:28
SDL_ReadLE16
#define SDL_ReadLE16
Definition: SDL_dynapi_overrides.h:357
SDL_Palette::colors
SDL_Color * colors
Definition: SDL_pixels.h:307
SDL_MapSurface
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
Definition: SDL_pixels.c:991
SDL_FillRect1
static void SDL_FillRect1(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:134
SDL_FillRect2
static void SDL_FillRect2(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:173
color
GLuint color
Definition: SDL_opengl_glext.h:1148
SDL_Color::g
Uint8 g
Definition: SDL_pixels.h:298
SDL_Rect::y
int y
Definition: SDL_rect.h:79
SDL_memcmp
#define SDL_memcmp
Definition: SDL_dynapi_overrides.h:389
SDL_Rect::h
int h
Definition: SDL_rect.h:80
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_BlitSurface
#define SDL_BlitSurface
Definition: SDL_surface.h:484
SDL_CreateRGBSurface
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
SDL_PIXELFORMAT_BGRA32
@ SDL_PIXELFORMAT_BGRA32
Definition: SDL_pixels.h:273
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
SDL_COPY_BLEND
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
SDL_RLESurface
int SDL_RLESurface(SDL_Surface *surface)
Definition: SDL_RLEaccel.c:1405
SDL_RWseek
#define SDL_RWseek
Definition: SDL_dynapi_overrides.h:721
rect
SDL_Rect rect
Definition: testrelative.c:27
SDL_FreeSurface
#define SDL_FreeSurface
Definition: SDL_dynapi_overrides.h:446
SDL_YUV_CONVERSION_MODE
SDL_YUV_CONVERSION_MODE
The formula used for converting between YUV and RGB.
Definition: SDL_surface.h:104
SDL_PixelFormat::palette
SDL_Palette * palette
Definition: SDL_pixels.h:318
SDL_Swap32
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
Definition: SDL_endian.h:162
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
key
GLuint64 key
Definition: gl2ext.h:2192
SDL_SetColorKey
int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key)
Sets the color key (transparent pixel) in a blittable surface.
Definition: SDL_surface.c:253
LCS_WINDOWS_COLOR_SPACE
#define LCS_WINDOWS_COLOR_SPACE
Definition: SDL_bmp.c:54
SDL_FreeFormat
#define SDL_FreeFormat
Definition: SDL_dynapi_overrides.h:281
pop
#define pop
Definition: SDL_qsort.c:192
SDL_BlitInfo::g
Uint8 g
Definition: SDL_blit.h:70
SDL_Surface::map
struct SDL_BlitMap * map
Definition: SDL_surface.h:89
SDL_PixelFormat
Definition: SDL_pixels.h:315
SDL_HINT_BMP_SAVE_LEGACY_FORMAT
#define SDL_HINT_BMP_SAVE_LEGACY_FORMAT
Prevent SDL from using version 4 of the bitmap header when saving BMPs.
Definition: SDL_hints.h:951
SDL_BlitInfo::a
Uint8 a
Definition: SDL_blit.h:70
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
depth
GLint GLint GLsizei GLsizei GLsizei depth
Definition: SDL_opengl.h:1572
SDL_UnlockSurface
void SDL_UnlockSurface(SDL_Surface *surface)
Definition: SDL_surface.c:928
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
SDL_COPY_MODULATE_ALPHA
#define SDL_COPY_MODULATE_ALPHA
Definition: SDL_blit.h:35
SDL_SetClipRect
SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
Definition: SDL_surface.c:561
CorrectAlphaChannel
static void CorrectAlphaChannel(SDL_Surface *surface)
Definition: SDL_bmp.c:57
SDL_CreateRGBSurfaceWithFormat
SDL_Surface * SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
Definition: SDL_surface.c:59
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_FreePalette
#define SDL_FreePalette
Definition: SDL_dynapi_overrides.h:285
SDL_BLENDMODE_BLEND
@ SDL_BLENDMODE_BLEND
Definition: SDL_blendmode.h:44
SDL_FillRect3
static void SDL_FillRect3(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:197
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
SDL_COPY_RLE_ALPHAKEY
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:43
BI_RGB
#define BI_RGB
Definition: SDL_bmp.c:45
SDL_LockSurface
#define SDL_LockSurface
Definition: SDL_dynapi_overrides.h:448
SDL_CreateRGBSurface
#define SDL_CreateRGBSurface
Definition: SDL_dynapi_overrides.h:444
SDL_SetSurfacePalette
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
Set the palette used by a surface.
Definition: SDL_surface.c:218
SDL_CalculatePitch
static Sint64 SDL_CalculatePitch(Uint32 format, int width)
Definition: SDL_surface.c:41
SDL_RWtell
#define SDL_RWtell
Definition: SDL_dynapi_overrides.h:722
SDL_AllocPalette
#define SDL_AllocPalette
Definition: SDL_dynapi_overrides.h:282
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_ConvertPixels_YUV_to_YUV
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:1810
SDL_Palette
Definition: SDL_pixels.h:304
src
GLenum src
Definition: SDL_opengl_glext.h:1737
SDL_SetSurfaceRLE
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
Sets the RLE acceleration hint for a surface.
Definition: SDL_surface.c:232
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_ISPIXELFORMAT_FOURCC
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
RW_SEEK_SET
#define RW_SEEK_SET
Definition: SDL_rwops.h:174
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_InvalidateMap
void SDL_InvalidateMap(SDL_BlitMap *map)
Definition: SDL_pixels.c:972
SDL_COPY_NEAREST
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:40
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
SDL_MAX_SINT32
#define SDL_MAX_SINT32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:195
SDL_BlitInfo::r
Uint8 r
Definition: SDL_blit.h:70
SDL_RWclose
#define SDL_RWclose
Definition: SDL_dynapi_overrides.h:725
RW_SEEK_CUR
#define RW_SEEK_CUR
Definition: SDL_rwops.h:175
SDL_SIMDAlloc
#define SDL_SIMDAlloc
Definition: SDL_dynapi_overrides.h:718
SDL_PIXELFORMAT_UNKNOWN
@ SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:173
SDL_COPY_ADD
#define SDL_COPY_ADD
Definition: SDL_blit.h:37
SDL_Color
Definition: SDL_pixels.h:295
SDL_FreeSurface
void SDL_FreeSurface(SDL_Surface *surface)
Definition: SDL_surface.c:1239
u1
GLfixed u1
Definition: SDL_opengl_glext.h:4558
SDL_COPY_MOD
#define SDL_COPY_MOD
Definition: SDL_blit.h:38
SDL_FillRect
#define SDL_FillRect
Definition: SDL_dynapi_overrides.h:466
SDL_PIXELFORMAT_BGR24
@ SDL_PIXELFORMAT_BGR24
Definition: SDL_pixels.h:233
SDL_BlitInfo::flags
int flags
Definition: SDL_blit.h:68
SDL_WriteLE32
#define SDL_WriteLE32
Definition: SDL_dynapi_overrides.h:366
bits
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
Definition: SDL_opengl_glext.h:6176
SDL_HasSSE
#define SDL_HasSSE
Definition: SDL_dynapi_overrides.h:107
SDL_COPY_MODULATE_COLOR
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
SDL_ConvertPixels_RGB_to_YUV
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:784
SDL_YUV_ConversionMode
static SDL_YUV_CONVERSION_MODE SDL_YUV_ConversionMode
Definition: SDL_yuv.c:33
SDL_Unsupported
#define SDL_Unsupported()
Definition: SDL_error.h:53
SDL_EFSEEK
@ SDL_EFSEEK
Definition: SDL_error.h:60
SDL_YUV_CONVERSION_BT709
@ SDL_YUV_CONVERSION_BT709
Definition: SDL_surface.h:108
SDL_FreeBlitMap
void SDL_FreeBlitMap(SDL_BlitMap *map)
Definition: SDL_pixels.c:1077
SDL_ConvertColorkeyToAlpha
static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface, SDL_bool ignore_alpha)
Definition: SDL_surface.c:316
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:417
void
const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char const char const SDL_SCANF_FORMAT_STRING char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:89
SDL_BYTEORDER
#define SDL_BYTEORDER
Definition: SDL_config_pandora.h:37
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
BI_BITFIELDS
#define BI_BITFIELDS
Definition: SDL_bmp.c:48
SDL_SetPixelFormatPalette
#define SDL_SetPixelFormatPalette
Definition: SDL_dynapi_overrides.h:283
rects
EGLSurface EGLint * rects
Definition: eglext.h:282
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:73
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_SIMD_ALIGNED
#define SDL_SIMD_ALIGNED
Definition: SDL_surface.h:56
SDL_EFWRITE
@ SDL_EFWRITE
Definition: SDL_error.h:59
SDL_EFREAD
@ SDL_EFREAD
Definition: SDL_error.h:58
SDL_YUV_CONVERSION_BT601
@ SDL_YUV_CONVERSION_BT601
Definition: SDL_surface.h:107
SDL_ConvertPixels_YUV_to_RGB
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:395
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
SDL_YUV_CONVERSION_AUTOMATIC
@ SDL_YUV_CONVERSION_AUTOMATIC
Definition: SDL_surface.h:109
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
SDL_SIMDFree
#define SDL_SIMDFree
Definition: SDL_dynapi_overrides.h:719
colors
static int colors[7]
Definition: testgesture.c:41
SDL_InitFormat
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
Definition: SDL_pixels.c:537
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179