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 514 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 485 of file SDL_surface.h.

◆ SDL_DONTFREE

#define SDL_DONTFREE   0x00000004

Surface is referenced internally

Definition at line 56 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 202 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 63 of file SDL_surface.h.

◆ SDL_PREALLOC

#define SDL_PREALLOC   0x00000001

Surface uses preallocated memory

Definition at line 54 of file SDL_surface.h.

◆ SDL_RLEACCEL

#define SDL_RLEACCEL   0x00000002

Surface is RLE encoded

Definition at line 55 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 225 of file SDL_surface.h.

◆ SDL_SIMD_ALIGNED

#define SDL_SIMD_ALIGNED   0x00000008

Surface uses aligned memory

Definition at line 57 of file SDL_surface.h.

◆ SDL_SWSURFACE

#define SDL_SWSURFACE   0

Just here for compatibility

Definition at line 53 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 1242 of file SDL_surface.c.

1245 {
1246  SDL_Surface src_surface, dst_surface;
1247  SDL_PixelFormat src_fmt, dst_fmt;
1248  SDL_BlitMap src_blitmap, dst_blitmap;
1249  SDL_Rect rect;
1250  void *nonconst_src = (void *) src;
1251 
1252  /* Check to make sure we are blitting somewhere, so we don't crash */
1253  if (!dst) {
1254  return SDL_InvalidParamError("dst");
1255  }
1256  if (!dst_pitch) {
1257  return SDL_InvalidParamError("dst_pitch");
1258  }
1259 
1260 #if SDL_HAVE_YUV
1261  if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1262  return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1263  } else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
1264  return SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1265  } else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1266  return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1267  }
1268 #else
1269  if (SDL_ISPIXELFORMAT_FOURCC(src_format) || SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1270  SDL_SetError("SDL not built with YUV support");
1271  return -1;
1272  }
1273 #endif
1274 
1275  /* Fast path for same format copy */
1276  if (src_format == dst_format) {
1277  int i;
1278  const int bpp = SDL_BYTESPERPIXEL(src_format);
1279  width *= bpp;
1280  for (i = height; i--;) {
1281  SDL_memcpy(dst, src, width);
1282  src = (const Uint8*)src + src_pitch;
1283  dst = (Uint8*)dst + dst_pitch;
1284  }
1285  return 0;
1286  }
1287 
1288  if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
1289  src_pitch,
1290  &src_surface, &src_fmt, &src_blitmap)) {
1291  return -1;
1292  }
1293  if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
1294  &dst_surface, &dst_fmt, &dst_blitmap)) {
1295  return -1;
1296  }
1297 
1298  /* Set up the rect and go! */
1299  rect.x = 0;
1300  rect.y = 0;
1301  rect.w = width;
1302  rect.h = height;
1303  return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
1304 }

References bpp, 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_SetError, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

◆ SDL_ConvertSurface()

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

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

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

Definition at line 957 of file SDL_surface.c.

959 {
960  SDL_Surface *convert;
961  Uint32 copy_flags;
962  SDL_Color copy_color;
963  SDL_Rect bounds;
964  int ret;
965  SDL_bool palette_ck_transform = SDL_FALSE;
966  int palette_ck_value = 0;
967  SDL_bool palette_has_alpha = SDL_FALSE;
968  Uint8 *palette_saved_alpha = NULL;
969 
970  if (!surface) {
971  SDL_InvalidParamError("surface");
972  return NULL;
973  }
974  if (!format) {
975  SDL_InvalidParamError("format");
976  return NULL;
977  }
978 
979  /* Check for empty destination palette! (results in empty image) */
980  if (format->palette != NULL) {
981  int i;
982  for (i = 0; i < format->palette->ncolors; ++i) {
983  if ((format->palette->colors[i].r != 0xFF) ||
984  (format->palette->colors[i].g != 0xFF) ||
985  (format->palette->colors[i].b != 0xFF))
986  break;
987  }
988  if (i == format->palette->ncolors) {
989  SDL_SetError("Empty destination palette");
990  return (NULL);
991  }
992  }
993 
994  /* Create a new surface with the desired format */
995  convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
996  format->BitsPerPixel, format->Rmask,
997  format->Gmask, format->Bmask,
998  format->Amask);
999  if (convert == NULL) {
1000  return (NULL);
1001  }
1002 
1003  /* Copy the palette if any */
1004  if (format->palette && convert->format->palette) {
1005  SDL_memcpy(convert->format->palette->colors,
1006  format->palette->colors,
1007  format->palette->ncolors * sizeof(SDL_Color));
1008  convert->format->palette->ncolors = format->palette->ncolors;
1009  }
1010 
1011  /* Save the original copy flags */
1012  copy_flags = surface->map->info.flags;
1013  copy_color.r = surface->map->info.r;
1014  copy_color.g = surface->map->info.g;
1015  copy_color.b = surface->map->info.b;
1016  copy_color.a = surface->map->info.a;
1017  surface->map->info.r = 0xFF;
1018  surface->map->info.g = 0xFF;
1019  surface->map->info.b = 0xFF;
1020  surface->map->info.a = 0xFF;
1021  surface->map->info.flags = 0;
1022  SDL_InvalidateMap(surface->map);
1023 
1024  /* Copy over the image data */
1025  bounds.x = 0;
1026  bounds.y = 0;
1027  bounds.w = surface->w;
1028  bounds.h = surface->h;
1029 
1030  /* Source surface has a palette with no real alpha (0 or OPAQUE).
1031  * Destination format has alpha.
1032  * -> set alpha channel to be opaque */
1033  if (surface->format->palette && format->Amask) {
1034  SDL_bool set_opaque = SDL_FALSE;
1035  {
1036  int i;
1037  for (i = 0; i < surface->format->palette->ncolors; i++) {
1038  Uint8 alpha_value = surface->format->palette->colors[i].a;
1039 
1040  if (alpha_value != 0 && alpha_value != SDL_ALPHA_OPAQUE) {
1041  /* Palette has at least one alpha value. Don't do anything */
1042  set_opaque = SDL_FALSE;
1043  palette_has_alpha = SDL_TRUE;
1044  break;
1045  }
1046 
1047  if (alpha_value == 0) {
1048  set_opaque = SDL_TRUE;
1049  }
1050  }
1051  }
1052 
1053  /* Set opaque and backup palette alpha values */
1054  if (set_opaque) {
1055  int i;
1056  palette_saved_alpha = SDL_stack_alloc(Uint8, surface->format->palette->ncolors);
1057  for (i = 0; i < surface->format->palette->ncolors; i++) {
1058  palette_saved_alpha[i] = surface->format->palette->colors[i].a;
1059  surface->format->palette->colors[i].a = SDL_ALPHA_OPAQUE;
1060  }
1061  }
1062  }
1063 
1064  /* Transform colorkey to alpha. for cases where source palette has duplicate values, and colorkey is one of them */
1065  if (copy_flags & SDL_COPY_COLORKEY) {
1066  if (surface->format->palette && !format->palette) {
1067  palette_ck_transform = SDL_TRUE;
1068  palette_has_alpha = SDL_TRUE;
1069  palette_ck_value = surface->format->palette->colors[surface->map->info.colorkey].a;
1070  surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
1071  }
1072  }
1073 
1074  ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);
1075 
1076  /* Restore colorkey alpha value */
1077  if (palette_ck_transform) {
1078  surface->format->palette->colors[surface->map->info.colorkey].a = palette_ck_value;
1079  }
1080 
1081  /* Restore palette alpha values */
1082  if (palette_saved_alpha) {
1083  int i;
1084  for (i = 0; i < surface->format->palette->ncolors; i++) {
1085  surface->format->palette->colors[i].a = palette_saved_alpha[i];
1086  }
1087  SDL_stack_free(palette_saved_alpha);
1088  }
1089 
1090  /* Clean up the original surface, and update converted surface */
1091  convert->map->info.r = copy_color.r;
1092  convert->map->info.g = copy_color.g;
1093  convert->map->info.b = copy_color.b;
1094  convert->map->info.a = copy_color.a;
1095  convert->map->info.flags =
1096  (copy_flags &
1100  surface->map->info.r = copy_color.r;
1101  surface->map->info.g = copy_color.g;
1102  surface->map->info.b = copy_color.b;
1103  surface->map->info.a = copy_color.a;
1104  surface->map->info.flags = copy_flags;
1105  SDL_InvalidateMap(surface->map);
1106 
1107  /* SDL_LowerBlit failed, and so the conversion */
1108  if (ret < 0) {
1109  SDL_FreeSurface(convert);
1110  return NULL;
1111  }
1112 
1113  if (copy_flags & SDL_COPY_COLORKEY) {
1114  SDL_bool set_colorkey_by_color = SDL_FALSE;
1115 
1116  if (surface->format->palette) {
1117  if (format->palette &&
1118  surface->format->palette->ncolors <= format->palette->ncolors &&
1119  (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
1120  surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
1121  /* The palette is identical, just set the same colorkey */
1122  SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
1123  } else if (!format->palette) {
1124  /* Was done by 'palette_ck_transform' */
1125  } else {
1126  set_colorkey_by_color = SDL_TRUE;
1127  }
1128  } else {
1129  set_colorkey_by_color = SDL_TRUE;
1130  }
1131 
1132  if (set_colorkey_by_color) {
1133  SDL_Surface *tmp;
1134  SDL_Surface *tmp2;
1135  int converted_colorkey = 0;
1136 
1137  /* Create a dummy surface to get the colorkey converted */
1138  tmp = SDL_CreateRGBSurface(0, 1, 1,
1139  surface->format->BitsPerPixel, surface->format->Rmask,
1140  surface->format->Gmask, surface->format->Bmask,
1141  surface->format->Amask);
1142 
1143  /* Share the palette, if any */
1144  if (surface->format->palette) {
1145  SDL_SetSurfacePalette(tmp, surface->format->palette);
1146  }
1147 
1148  SDL_FillRect(tmp, NULL, surface->map->info.colorkey);
1149 
1150  tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
1151 
1152  /* Convertion of the colorkey */
1153  tmp2 = SDL_ConvertSurface(tmp, format, 0);
1154 
1155  /* Get the converted colorkey */
1156  SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);
1157 
1158  SDL_FreeSurface(tmp);
1159  SDL_FreeSurface(tmp2);
1160 
1161  /* Set the converted colorkey on the new surface */
1162  SDL_SetColorKey(convert, 1, converted_colorkey);
1163 
1164  /* This is needed when converting for 3D texture upload */
1166  }
1167  }
1168  SDL_SetClipRect(convert, &surface->clip_rect);
1169 
1170  /* Enable alpha blending by default if the new surface has an
1171  * alpha channel or alpha modulation */
1172  if ((surface->format->Amask && format->Amask) ||
1173  (palette_has_alpha && format->Amask) ||
1174  (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
1176  }
1177  if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
1178  SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
1179  }
1180 
1181  /* We're ready to go! */
1182  return (convert);
1183 }

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_ALPHA_OPAQUE, SDL_ALPHA_TRANSPARENT, 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_stack_alloc, SDL_stack_free, 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 1186 of file SDL_surface.c.

1188 {
1189  SDL_PixelFormat *fmt;
1190  SDL_Surface *convert = NULL;
1191 
1192  fmt = SDL_AllocFormat(pixel_format);
1193  if (fmt) {
1194  convert = SDL_ConvertSurface(surface, fmt, flags);
1195  SDL_FreeFormat(fmt);
1196  }
1197  return convert;
1198 }

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

150 {
151  Uint32 format;
152 
153  /* Get the pixel format */
154  format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
156  SDL_SetError("Unknown pixel format");
157  return NULL;
158  }
159 
161 }

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

171 {
173 
174  surface = SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
175  if (surface != NULL) {
176  surface->flags |= SDL_PREALLOC;
177  surface->pixels = pixels;
178  surface->w = width;
179  surface->h = height;
180  surface->pitch = pitch;
182  }
183  return surface;
184 }

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 {
63 
64  /* The flags are no longer used, make the compiler happy */
65  (void)flags;
66 
67  /* Allocate the surface */
68  surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
69  if (surface == NULL) {
71  return NULL;
72  }
73 
74  surface->format = SDL_AllocFormat(format);
75  if (!surface->format) {
77  return NULL;
78  }
79  surface->w = width;
80  surface->h = height;
83 
84  if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
85  SDL_Palette *palette =
86  SDL_AllocPalette((1 << surface->format->BitsPerPixel));
87  if (!palette) {
89  return NULL;
90  }
91  if (palette->ncolors == 2) {
92  /* Create a black and white bitmap palette */
93  palette->colors[0].r = 0xFF;
94  palette->colors[0].g = 0xFF;
95  palette->colors[0].b = 0xFF;
96  palette->colors[1].r = 0x00;
97  palette->colors[1].g = 0x00;
98  palette->colors[1].b = 0x00;
99  }
100  SDL_SetSurfacePalette(surface, palette);
101  SDL_FreePalette(palette);
102  }
103 
104  /* Get the pixels */
105  if (surface->w && surface->h) {
106  /* Assumptions checked in surface_size_assumptions assert above */
107  Sint64 size = ((Sint64)surface->h * surface->pitch);
109  /* Overflow... */
111  SDL_OutOfMemory();
112  return NULL;
113  }
114 
115  surface->pixels = SDL_SIMDAlloc((size_t)size);
116  if (!surface->pixels) {
118  SDL_OutOfMemory();
119  return NULL;
120  }
121  surface->flags |= SDL_SIMD_ALIGNED;
122  /* This is important for bitmaps */
123  SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
124  }
125 
126  /* Allocate an empty mapping */
127  surface->map = SDL_AllocBlitMap();
128  if (!surface->map) {
130  return NULL;
131  }
132 
133  /* By default surface with an alpha mask are set up for blending */
134  if (surface->format->Amask) {
136  }
137 
138  /* The surface is ready to go */
139  surface->refcount = 1;
140  return surface;
141 }

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

194 {
196 
198  if (surface != NULL) {
199  surface->flags |= SDL_PREALLOC;
200  surface->pixels = pixels;
201  surface->w = width;
202  surface->h = height;
203  surface->pitch = pitch;
205  }
206  return surface;
207 }

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

◆ SDL_DuplicateSurface()

SDL_Surface* SDL_DuplicateSurface ( SDL_Surface surface)

Definition at line 948 of file SDL_surface.c.

949 {
950  return SDL_ConvertSurface(surface, surface->format, surface->flags);
951 }

References SDL_ConvertSurface().

◆ SDL_FillRect()

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

Performs a fast fill of the given rectangle with color.

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

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

Returns
0 on success, or -1 on error.

Definition at line 238 of file SDL_fillrect.c.

239 {
240  if (!dst) {
241  return SDL_SetError("Passed NULL destination surface");
242  }
243 
244  /* If 'rect' == NULL, then fill the whole surface */
245  if (!rect) {
246  rect = &dst->clip_rect;
247  /* Don't attempt to fill if the surface's clip_rect is empty */
248  if (SDL_RectEmpty(rect)) {
249  return 0;
250  }
251  }
252 
253  return SDL_FillRects(dst, rect, 1, color);
254 }

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

◆ SDL_FillRects()

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

Definition at line 299 of file SDL_fillrect.c.

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

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

Referenced by SDL_FillRect().

◆ SDL_FreeSurface()

void SDL_FreeSurface ( SDL_Surface surface)

Definition at line 1310 of file SDL_surface.c.

1311 {
1312  if (surface == NULL) {
1313  return;
1314  }
1315  if (surface->flags & SDL_DONTFREE) {
1316  return;
1317  }
1318  SDL_InvalidateMap(surface->map);
1319 
1320  if (--surface->refcount > 0) {
1321  return;
1322  }
1323  while (surface->locked > 0) {
1325  }
1326 #if SDL_HAVE_RLE
1327  if (surface->flags & SDL_RLEACCEL) {
1329  }
1330 #endif
1331  if (surface->format) {
1333  SDL_FreeFormat(surface->format);
1334  surface->format = NULL;
1335  }
1336  if (surface->flags & SDL_PREALLOC) {
1337  /* Don't free */
1338  } else if (surface->flags & SDL_SIMD_ALIGNED) {
1339  /* Free aligned */
1340  SDL_SIMDFree(surface->pixels);
1341  } else {
1342  /* Normal */
1343  SDL_free(surface->pixels);
1344  }
1345  if (surface->map) {
1346  SDL_FreeBlitMap(surface->map);
1347  }
1348  SDL_free(surface);
1349 }

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

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

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

291 {
292  if (!surface) {
293  return SDL_InvalidParamError("surface");
294  }
295 
296  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
297  return SDL_SetError("Surface doesn't have a colorkey");
298  }
299 
300  if (key) {
301  *key = surface->map->info.colorkey;
302  }
303  return 0;
304 }

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

475 {
476  if (!surface) {
477  return -1;
478  }
479 
480  if (alpha) {
481  *alpha = surface->map->info.a;
482  }
483  return 0;
484 }

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

528 {
529  if (!surface) {
530  return -1;
531  }
532 
533  if (!blendMode) {
534  return 0;
535  }
536 
537  switch (surface->map->
538  info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
539  case SDL_COPY_BLEND:
541  break;
542  case SDL_COPY_ADD:
544  break;
545  case SDL_COPY_MOD:
547  break;
548  case SDL_COPY_MUL:
550  break;
551  default:
553  break;
554  }
555  return 0;
556 }

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

◆ SDL_GetSurfaceColorMod()

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

Get the additional color value used in blit operations.

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

Definition at line 432 of file SDL_surface.c.

433 {
434  if (!surface) {
435  return -1;
436  }
437 
438  if (r) {
439  *r = surface->map->info.r;
440  }
441  if (g) {
442  *g = surface->map->info.g;
443  }
444  if (b) {
445  *b = surface->map->info.b;
446  }
447  return 0;
448 }

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

277 {
278  if (!surface) {
279  return SDL_FALSE;
280  }
281 
282  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
283  return SDL_FALSE;
284  }
285 
286  return SDL_TRUE;
287 }

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 173 of file SDL_bmp.c.

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

References SDL_Color::a, SDL_Color::b, BI_BITFIELDS, BI_RGB, BI_RLE4, BI_RLE8, SDL_Palette::colors, CorrectAlphaChannel(), done, SDL_Color::g, i, SDL_Palette::ncolors, NULL, SDL_Color::r, readRlePixels(), RW_SEEK_CUR, RW_SEEK_SET, SDL_ALPHA_OPAQUE, SDL_assert, SDL_ClearError, SDL_CreateRGBSurface, SDL_EFREAD, SDL_EFSEEK, SDL_Error, SDL_FALSE, SDL_FreeSurface, SDL_GetError, SDL_ReadLE16, SDL_ReadLE32, SDL_RWclose, SDL_RWread, SDL_RWseek, SDL_RWtell, SDL_SetError, SDL_strcmp, SDL_strncmp, SDL_Swap16(), SDL_Swap32(), and SDL_TRUE.

◆ SDL_LockSurface()

int SDL_LockSurface ( SDL_Surface surface)

Sets up a surface for directly accessing the pixels.

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

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

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

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

See also
SDL_UnlockSurface()

Definition at line 905 of file SDL_surface.c.

906 {
907  if (!surface->locked) {
908 #if SDL_HAVE_RLE
909  /* Perform the lock */
910  if (surface->flags & SDL_RLEACCEL) {
912  surface->flags |= SDL_RLEACCEL; /* save accel'd state */
913  }
914 #endif
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 602 of file SDL_surface.c.

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

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

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

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

Referenced by SDL_UpperBlitScaled().

◆ SDL_SaveBMP_RW()

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

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

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

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

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

Definition at line 568 of file SDL_bmp.c.

569 {
570  Sint64 fp_offset;
571  int i, pad;
573  Uint8 *bits;
574  SDL_bool save32bit = SDL_FALSE;
575  SDL_bool saveLegacyBMP = SDL_FALSE;
576 
577  /* The Win32 BMP file header (14 bytes) */
578  char magic[2] = { 'B', 'M' };
579  Uint32 bfSize;
580  Uint16 bfReserved1;
581  Uint16 bfReserved2;
582  Uint32 bfOffBits;
583 
584  /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
585  Uint32 biSize;
586  Sint32 biWidth;
587  Sint32 biHeight;
588  Uint16 biPlanes;
589  Uint16 biBitCount;
590  Uint32 biCompression;
591  Uint32 biSizeImage;
592  Sint32 biXPelsPerMeter;
593  Sint32 biYPelsPerMeter;
594  Uint32 biClrUsed;
595  Uint32 biClrImportant;
596 
597  /* The additional header members from the Win32 BITMAPV4HEADER struct (108 bytes in total) */
598  Uint32 bV4RedMask = 0;
599  Uint32 bV4GreenMask = 0;
600  Uint32 bV4BlueMask = 0;
601  Uint32 bV4AlphaMask = 0;
602  Uint32 bV4CSType = 0;
603  Sint32 bV4Endpoints[3 * 3] = {0};
604  Uint32 bV4GammaRed = 0;
605  Uint32 bV4GammaGreen = 0;
606  Uint32 bV4GammaBlue = 0;
607 
608  /* Make sure we have somewhere to save */
609  surface = NULL;
610  if (dst) {
611 #ifdef SAVE_32BIT_BMP
612  /* We can save alpha information in a 32-bit BMP */
613  if (saveme->format->BitsPerPixel >= 8 && (saveme->format->Amask ||
614  saveme->map->info.flags & SDL_COPY_COLORKEY)) {
615  save32bit = SDL_TRUE;
616  }
617 #endif /* SAVE_32BIT_BMP */
618 
619  if (saveme->format->palette && !save32bit) {
620  if (saveme->format->BitsPerPixel == 8) {
621  surface = saveme;
622  } else {
623  SDL_SetError("%d bpp BMP files not supported",
624  saveme->format->BitsPerPixel);
625  }
626  } else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
628  (saveme->format->Rmask == 0x00FF0000) &&
629  (saveme->format->Gmask == 0x0000FF00) &&
630  (saveme->format->Bmask == 0x000000FF)
631 #else
632  (saveme->format->Rmask == 0x000000FF) &&
633  (saveme->format->Gmask == 0x0000FF00) &&
634  (saveme->format->Bmask == 0x00FF0000)
635 #endif
636  ) {
637  surface = saveme;
638  } else {
640 
641  /* If the surface has a colorkey or alpha channel we'll save a
642  32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
643  if (save32bit) {
645  } else {
647  }
648  surface = SDL_ConvertSurface(saveme, &format, 0);
649  if (!surface) {
650  SDL_SetError("Couldn't convert image to %d bpp",
651  format.BitsPerPixel);
652  }
653  }
654  } else {
655  /* Set no error here because it may overwrite a more useful message from
656  SDL_RWFromFile() if SDL_SaveBMP_RW() is called from SDL_SaveBMP(). */
657  return -1;
658  }
659 
660  if (save32bit) {
662  }
663 
664  if (surface && (SDL_LockSurface(surface) == 0)) {
665  const int bw = surface->w * surface->format->BytesPerPixel;
666 
667  /* Set the BMP file header values */
668  bfSize = 0; /* We'll write this when we're done */
669  bfReserved1 = 0;
670  bfReserved2 = 0;
671  bfOffBits = 0; /* We'll write this when we're done */
672 
673  /* Write the BMP file header values */
674  fp_offset = SDL_RWtell(dst);
675  SDL_ClearError();
676  SDL_RWwrite(dst, magic, 2, 1);
677  SDL_WriteLE32(dst, bfSize);
678  SDL_WriteLE16(dst, bfReserved1);
679  SDL_WriteLE16(dst, bfReserved2);
680  SDL_WriteLE32(dst, bfOffBits);
681 
682  /* Set the BMP info values */
683  biSize = 40;
684  biWidth = surface->w;
685  biHeight = surface->h;
686  biPlanes = 1;
687  biBitCount = surface->format->BitsPerPixel;
688  biCompression = BI_RGB;
689  biSizeImage = surface->h * surface->pitch;
690  biXPelsPerMeter = 0;
691  biYPelsPerMeter = 0;
692  if (surface->format->palette) {
693  biClrUsed = surface->format->palette->ncolors;
694  } else {
695  biClrUsed = 0;
696  }
697  biClrImportant = 0;
698 
699  /* Set the BMP info values for the version 4 header */
700  if (save32bit && !saveLegacyBMP) {
701  biSize = 108;
702  biCompression = BI_BITFIELDS;
703  /* The BMP format is always little endian, these masks stay the same */
704  bV4RedMask = 0x00ff0000;
705  bV4GreenMask = 0x0000ff00;
706  bV4BlueMask = 0x000000ff;
707  bV4AlphaMask = 0xff000000;
708  bV4CSType = LCS_WINDOWS_COLOR_SPACE;
709  bV4GammaRed = 0;
710  bV4GammaGreen = 0;
711  bV4GammaBlue = 0;
712  }
713 
714  /* Write the BMP info values */
715  SDL_WriteLE32(dst, biSize);
716  SDL_WriteLE32(dst, biWidth);
717  SDL_WriteLE32(dst, biHeight);
718  SDL_WriteLE16(dst, biPlanes);
719  SDL_WriteLE16(dst, biBitCount);
720  SDL_WriteLE32(dst, biCompression);
721  SDL_WriteLE32(dst, biSizeImage);
722  SDL_WriteLE32(dst, biXPelsPerMeter);
723  SDL_WriteLE32(dst, biYPelsPerMeter);
724  SDL_WriteLE32(dst, biClrUsed);
725  SDL_WriteLE32(dst, biClrImportant);
726 
727  /* Write the BMP info values for the version 4 header */
728  if (save32bit && !saveLegacyBMP) {
729  SDL_WriteLE32(dst, bV4RedMask);
730  SDL_WriteLE32(dst, bV4GreenMask);
731  SDL_WriteLE32(dst, bV4BlueMask);
732  SDL_WriteLE32(dst, bV4AlphaMask);
733  SDL_WriteLE32(dst, bV4CSType);
734  for (i = 0; i < 3 * 3; i++) {
735  SDL_WriteLE32(dst, bV4Endpoints[i]);
736  }
737  SDL_WriteLE32(dst, bV4GammaRed);
738  SDL_WriteLE32(dst, bV4GammaGreen);
739  SDL_WriteLE32(dst, bV4GammaBlue);
740  }
741 
742  /* Write the palette (in BGR color order) */
743  if (surface->format->palette) {
744  SDL_Color *colors;
745  int ncolors;
746 
747  colors = surface->format->palette->colors;
748  ncolors = surface->format->palette->ncolors;
749  for (i = 0; i < ncolors; ++i) {
750  SDL_RWwrite(dst, &colors[i].b, 1, 1);
751  SDL_RWwrite(dst, &colors[i].g, 1, 1);
752  SDL_RWwrite(dst, &colors[i].r, 1, 1);
753  SDL_RWwrite(dst, &colors[i].a, 1, 1);
754  }
755  }
756 
757  /* Write the bitmap offset */
758  bfOffBits = (Uint32)(SDL_RWtell(dst) - fp_offset);
759  if (SDL_RWseek(dst, fp_offset + 10, RW_SEEK_SET) < 0) {
761  }
762  SDL_WriteLE32(dst, bfOffBits);
763  if (SDL_RWseek(dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
765  }
766 
767  /* Write the bitmap image upside down */
768  bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
769  pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
770  while (bits > (Uint8 *) surface->pixels) {
771  bits -= surface->pitch;
772  if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
774  break;
775  }
776  if (pad) {
777  const Uint8 padbyte = 0;
778  for (i = 0; i < pad; ++i) {
779  SDL_RWwrite(dst, &padbyte, 1, 1);
780  }
781  }
782  }
783 
784  /* Write the BMP file size */
785  bfSize = (Uint32)(SDL_RWtell(dst) - fp_offset);
786  if (SDL_RWseek(dst, fp_offset + 2, RW_SEEK_SET) < 0) {
788  }
789  SDL_WriteLE32(dst, bfSize);
790  if (SDL_RWseek(dst, fp_offset + bfSize, RW_SEEK_SET) < 0) {
792  }
793 
794  /* Close it up.. */
796  if (surface != saveme) {
798  }
799  }
800 
801  if (freedst && dst) {
802  SDL_RWclose(dst);
803  }
804  return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
805 }

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

◆ SDL_SetClipRect()

SDL_bool SDL_SetClipRect ( SDL_Surface surface,
const SDL_Rect rect 
)

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

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

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

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

Definition at line 559 of file SDL_surface.c.

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

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

246 {
247  int flags;
248 
249  if (!surface) {
250  return SDL_InvalidParamError("surface");
251  }
252 
253  if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
254  return SDL_InvalidParamError("key");
255  }
256 
257  if (flag & SDL_RLEACCEL) {
259  }
260 
261  flags = surface->map->info.flags;
262  if (flag) {
263  surface->map->info.flags |= SDL_COPY_COLORKEY;
264  surface->map->info.colorkey = key;
265  } else {
266  surface->map->info.flags &= ~SDL_COPY_COLORKEY;
267  }
268  if (surface->map->info.flags != flags) {
270  }
271 
272  return 0;
273 }

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

452 {
453  int flags;
454 
455  if (!surface) {
456  return -1;
457  }
458 
459  surface->map->info.a = alpha;
460 
461  flags = surface->map->info.flags;
462  if (alpha != 0xFF) {
463  surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
464  } else {
465  surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
466  }
467  if (surface->map->info.flags != flags) {
469  }
470  return 0;
471 }

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

488 {
489  int flags, status;
490 
491  if (!surface) {
492  return -1;
493  }
494 
495  status = 0;
496  flags = surface->map->info.flags;
497  surface->map->info.flags &=
499  switch (blendMode) {
500  case SDL_BLENDMODE_NONE:
501  break;
502  case SDL_BLENDMODE_BLEND:
503  surface->map->info.flags |= SDL_COPY_BLEND;
504  break;
505  case SDL_BLENDMODE_ADD:
506  surface->map->info.flags |= SDL_COPY_ADD;
507  break;
508  case SDL_BLENDMODE_MOD:
509  surface->map->info.flags |= SDL_COPY_MOD;
510  break;
511  case SDL_BLENDMODE_MUL:
512  surface->map->info.flags |= SDL_COPY_MUL;
513  break;
514  default:
515  status = SDL_Unsupported();
516  break;
517  }
518 
519  if (surface->map->info.flags != flags) {
521  }
522 
523  return status;
524 }

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

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

◆ SDL_SetSurfaceColorMod()

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

Set an additional color value used in blit operations.

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

Definition at line 406 of file SDL_surface.c.

407 {
408  int flags;
409 
410  if (!surface) {
411  return -1;
412  }
413 
414  surface->map->info.r = r;
415  surface->map->info.g = g;
416  surface->map->info.b = b;
417 
418  flags = surface->map->info.flags;
419  if (r != 0xFF || g != 0xFF || b != 0xFF) {
420  surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
421  } else {
422  surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
423  }
424  if (surface->map->info.flags != flags) {
426  }
427  return 0;
428 }

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

211 {
212  if (!surface) {
213  return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
214  }
215  if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
216  return -1;
217  }
219 
220  return 0;
221 }

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

225 {
226  int flags;
227 
228  if (!surface) {
229  return -1;
230  }
231 
232  flags = surface->map->info.flags;
233  if (flag) {
234  surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
235  } else {
236  surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
237  }
238  if (surface->map->info.flags != flags) {
240  }
241  return 0;
242 }

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 bpp, copy_row3(), SDL_Rect::h, if, mov, NULL, pop, ptr, SDL_FALSE, SDL_LockSurface, SDL_MUSTLOCK, SDL_SetError, SDL_TRUE, SDL_UnlockSurface, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

◆ SDL_UnlockSurface()

void SDL_UnlockSurface ( SDL_Surface surface)
See also
SDL_LockSurface()

Definition at line 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 #if SDL_HAVE_RLE
936  /* Update RLE encoded surface with new data */
937  if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
938  surface->flags &= ~SDL_RLEACCEL; /* stop lying */
940  }
941 #endif
942 }

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

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

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

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

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
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:386
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
Sint32
int32_t Sint32
Definition: SDL_stdinc.h:197
Sint64
int64_t Sint64
Definition: SDL_stdinc.h:210
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:323
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
SDL_Palette::ncolors
int ncolors
Definition: SDL_pixels.h:309
blendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
SDL_Color::b
Uint8 b
Definition: SDL_pixels.h:302
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:71
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:602
SDL_BlitMap
Definition: SDL_blit.h:88
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
if
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Definition: pixman-arm-neon-asm.h:469
copy_row3
static void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w)
Definition: SDL_stretch.c:177
end
GLuint GLuint end
Definition: SDL_opengl.h:1571
SDL_COPY_RLE_COLORKEY
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:43
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
BI_RLE8
#define BI_RLE8
Definition: SDL_bmp.c:46
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1112
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
endif
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld endif[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if
Definition: pixman-arm-neon-asm.h:549
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:76
SDL_Swap16
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
Definition: SDL_endian.h:110
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1112
mode
GLenum mode
Definition: SDL_opengl_glext.h:1125
SDL_BlitInfo::b
Uint8 b
Definition: SDL_blit.h:71
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:1547
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_BLENDMODE_BLEND
@ SDL_BLENDMODE_BLEND
Definition: SDL_blendmode.h:44
SDL_Color::r
Uint8 r
Definition: SDL_pixels.h:300
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:1204
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:226
SDL_MasksToPixelFormatEnum
#define SDL_MasksToPixelFormatEnum
Definition: SDL_dynapi_overrides.h:279
SDL_ConvertSurface
#define SDL_ConvertSurface
Definition: SDL_dynapi_overrides.h:463
top
GLdouble GLdouble GLdouble GLdouble top
Definition: SDL_opengl_glext.h:6106
SDL_AllocBlitMap
SDL_BlitMap * SDL_AllocBlitMap(void)
Definition: SDL_pixels.c:959
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:878
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:40
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
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_ISPIXELFORMAT_INDEXED
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
SDL_BlitMap::info
SDL_BlitInfo info
Definition: SDL_blit.h:93
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:1112
SDL_ReadLE32
#define SDL_ReadLE32
Definition: SDL_dynapi_overrides.h:359
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1949
SDL_Rect::x
int x
Definition: SDL_rect.h:79
readRlePixels
static int readRlePixels(SDL_Surface *surface, SDL_RWops *src, int isRle8)
Definition: SDL_bmp.c:57
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:957
SDL_Rect::w
int w
Definition: SDL_rect.h:80
SDL_stack_alloc
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:354
SDL_Color::a
Uint8 a
Definition: SDL_pixels.h:303
SDL_COPY_RLE_DESIRED
#define SDL_COPY_RLE_DESIRED
Definition: SDL_blit.h:42
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:415
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1740
SDL_SetSurfaceBlendMode
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL_surface.c:487
SDL_Error
#define SDL_Error
Definition: SDL_dynapi_overrides.h:115
u2
GLfixed GLfixed u2
Definition: SDL_opengl_glext.h:4561
SDL_RWwrite
#define SDL_RWwrite
Definition: SDL_dynapi_overrides.h:724
SDL_LIL_ENDIAN
#define SDL_LIL_ENDIAN
Definition: SDL_endian.h:37
SDL_COPY_MUL
#define SDL_COPY_MUL
Definition: SDL_blit.h:39
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
SDL_GetHintBoolean
#define SDL_GetHintBoolean
Definition: SDL_dynapi_overrides.h:608
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:310
SDL_MapSurface
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
Definition: SDL_pixels.c:998
SDL_FillRect1
static void SDL_FillRect1(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:135
SDL_FillRect2
static void SDL_FillRect2(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:174
color
GLuint color
Definition: SDL_opengl_glext.h:1151
SDL_Color::g
Uint8 g
Definition: SDL_pixels.h:301
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:147
SDL_BLENDMODE_NONE
@ SDL_BLENDMODE_NONE
Definition: SDL_blendmode.h:42
SDL_PIXELFORMAT_BGRA32
@ SDL_PIXELFORMAT_BGRA32
Definition: SDL_pixels.h:276
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:1407
SDL_RWseek
#define SDL_RWseek
Definition: SDL_dynapi_overrides.h:721
rect
SDL_Rect rect
Definition: testrelative.c:27
mov
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF PF lsl PF PF PF else PF mov
Definition: pixman-arm-simd-asm.h:214
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:105
SDL_PixelFormat::palette
SDL_Palette * palette
Definition: SDL_pixels.h:321
SDL_Swap32
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
Definition: SDL_endian.h:165
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:245
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:196
SDL_HasNEON
#define SDL_HasNEON
Definition: SDL_dynapi_overrides.h:618
SDL_BlitInfo::g
Uint8 g
Definition: SDL_blit.h:71
SDL_Surface::map
struct SDL_BlitMap * map
Definition: SDL_surface.h:89
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_PixelFormat
Definition: SDL_pixels.h:319
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:1035
SDL_BlitInfo::a
Uint8 a
Definition: SDL_blit.h:71
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
SDL_BLENDMODE_MUL
@ SDL_BLENDMODE_MUL
Definition: SDL_blendmode.h:53
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:559
CorrectAlphaChannel
static void CorrectAlphaChannel(SDL_Surface *surface)
Definition: SDL_bmp.c:143
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_FillRect3
static void SDL_FillRect3(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:198
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:540
SDL_COPY_RLE_ALPHAKEY
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:44
BI_RGB
#define BI_RGB
Definition: SDL_bmp.c:45
bpp
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
Definition: pixman-arm-neon-asm.h:146
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:210
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:1817
SDL_CalculatePitch
static int SDL_CalculatePitch(Uint32 format, int width)
Definition: SDL_surface.c:41
SDL_Palette
Definition: SDL_pixels.h:308
src
GLenum src
Definition: SDL_opengl_glext.h:1740
SDL_SetSurfaceRLE
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
Sets the RLE acceleration hint for a surface.
Definition: SDL_surface.c:224
SDL_stack_free
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:355
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:979
SDL_COPY_NEAREST
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:41
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
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:71
SDL_HasARMSIMD
#define SDL_HasARMSIMD
Definition: SDL_dynapi_overrides.h:730
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:299
SDL_FreeSurface
void SDL_FreeSurface(SDL_Surface *surface)
Definition: SDL_surface.c:1310
u1
GLfixed u1
Definition: SDL_opengl_glext.h:4561
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:236
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
SDL_BlitInfo::flags
int flags
Definition: SDL_blit.h:69
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:6179
SDL_HasSSE
#define SDL_HasSSE
Definition: SDL_dynapi_overrides.h:107
BI_RLE4
#define BI_RLE4
Definition: SDL_bmp.c:47
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:786
SDL_ALPHA_TRANSPARENT
#define SDL_ALPHA_TRANSPARENT
Definition: SDL_pixels.h:47
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
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:1086
SDL_ConvertColorkeyToAlpha
static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface, SDL_bool ignore_alpha)
Definition: SDL_surface.c:308
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:417
void
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
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:1483
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
ptr
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
Definition: pixman-arm-simd-asm.h:171
SDL_Surface::format
SDL_PixelFormat * format
Definition: SDL_surface.h:73
SDL_SIMD_ALIGNED
#define SDL_SIMD_ALIGNED
Definition: SDL_surface.h:56
SDL_FillRects
int SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
Definition: SDL_fillrect.c:299
SDL_BLENDMODE_MOD
@ SDL_BLENDMODE_MOD
Definition: SDL_blendmode.h:50
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_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_BLENDMODE_ADD
@ SDL_BLENDMODE_ADD
Definition: SDL_blendmode.h:47
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:397
SDL_YUV_CONVERSION_AUTOMATIC
@ SDL_YUV_CONVERSION_AUTOMATIC
Definition: SDL_surface.h:109
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:734
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:544