include/SDL_surface.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 07 Oct 2016 17:04:58 -0700
changeset 10482 f99f58ef8363
parent 10404 a990b0da18cc
child 10638 d11daa346140
permissions -rw-r--r--
Fixed bug 2924 - SDL_CreateRGBSurface[From] versions that take SDL_PIXELFORMAT enum

Daniel Gibson

Currently, SDL_CreateRGBSurface() and SDL_CreateRGBSurfaceFrom() take Uint32 masks for RGBA to "describe" the Pixelformat of the surface.
Internally those value are only used to map to one of the SDL_PIXELFORMAT_* enum values that are used for further processing.

I think it would be both handy and more efficient to be able to specify SDL_PIXELFORMAT_* yourself without using SDL_PixelFormatEnumToMasks() to create masks first, so I implemented functions that do that:
SDL_CreateRGBSurfaceWithFormat() and SDL_CreateRGBSurfaceWithFormatFrom() which are like the versions without "WithFormat" but instead of taking 4 Uint32s for R/G/B/A masks, they take one for a SDL_PIXELFORMAT_* enum value.

Together with https://bugzilla.libsdl.org/show_bug.cgi?id=2923 creating a SDL_Surface* from RGBA data (e.g. from stb_image) is as easy as
surf = SDL_SDL_CreateRGBSurfaceWithFormat(0, w, h, bppToUse*8, SDL_PIXELFORMAT_RGBA32);
slouken@2275
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9998
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
slouken@2275
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@2275
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@2275
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@2275
    20
*/
slouken@2275
    21
slouken@2275
    22
/**
slouken@3407
    23
 *  \file SDL_surface.h
slouken@7191
    24
 *
philipp@7278
    25
 *  Header file for ::SDL_Surface definition and management functions.
slouken@2275
    26
 */
slouken@2275
    27
slouken@2275
    28
#ifndef _SDL_surface_h
slouken@2275
    29
#define _SDL_surface_h
slouken@2275
    30
slouken@2275
    31
#include "SDL_stdinc.h"
slouken@2275
    32
#include "SDL_pixels.h"
slouken@2275
    33
#include "SDL_rect.h"
slouken@4929
    34
#include "SDL_blendmode.h"
slouken@2275
    35
#include "SDL_rwops.h"
slouken@2275
    36
slouken@2275
    37
#include "begin_code.h"
slouken@2275
    38
/* Set up for C function definitions, even when using C++ */
slouken@2275
    39
#ifdef __cplusplus
slouken@2275
    40
extern "C" {
slouken@2275
    41
#endif
slouken@2275
    42
slouken@3407
    43
/**
slouken@3407
    44
 *  \name Surface flags
slouken@7191
    45
 *
philipp@7278
    46
 *  These are the currently supported flags for the ::SDL_Surface.
slouken@7191
    47
 *
slouken@3407
    48
 *  \internal
slouken@3407
    49
 *  Used internally (read-only).
slouken@3341
    50
 */
gabomdq@7678
    51
/* @{ */
slouken@6257
    52
#define SDL_SWSURFACE       0           /**< Just here for compatibility */
slouken@3341
    53
#define SDL_PREALLOC        0x00000001  /**< Surface uses preallocated memory */
slouken@3341
    54
#define SDL_RLEACCEL        0x00000002  /**< Surface is RLE encoded */
slouken@5288
    55
#define SDL_DONTFREE        0x00000004  /**< Surface is referenced internally */
gabomdq@7678
    56
/* @} *//* Surface flags */
slouken@2275
    57
slouken@3407
    58
/**
slouken@3407
    59
 *  Evaluates to true if the surface needs to be locked before access.
slouken@3407
    60
 */
slouken@7191
    61
#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
slouken@2275
    62
slouken@2275
    63
/**
slouken@3407
    64
 * \brief A collection of pixels used in software blitting.
slouken@2275
    65
 *
slouken@3407
    66
 * \note  This structure should be treated as read-only, except for \c pixels,
slouken@2275
    67
 *        which, if not NULL, contains the raw pixel data for the surface.
slouken@2275
    68
 */
slouken@2275
    69
typedef struct SDL_Surface
slouken@2275
    70
{
slouken@2275
    71
    Uint32 flags;               /**< Read-only */
slouken@2275
    72
    SDL_PixelFormat *format;    /**< Read-only */
slouken@2275
    73
    int w, h;                   /**< Read-only */
slouken@2275
    74
    int pitch;                  /**< Read-only */
slouken@2275
    75
    void *pixels;               /**< Read-write */
slouken@2275
    76
slouken@3708
    77
    /** Application data associated with the surface */
slouken@2275
    78
    void *userdata;             /**< Read-write */
slouken@2275
    79
slouken@3407
    80
    /** information needed for surfaces requiring locks */
slouken@2275
    81
    int locked;                 /**< Read-only */
slouken@2275
    82
    void *lock_data;            /**< Read-only */
slouken@2275
    83
slouken@3407
    84
    /** clipping information */
slouken@2275
    85
    SDL_Rect clip_rect;         /**< Read-only */
slouken@2275
    86
slouken@3407
    87
    /** info for fast blit mapping to other surfaces */
slouken@2275
    88
    struct SDL_BlitMap *map;    /**< Private */
slouken@2275
    89
slouken@3407
    90
    /** Reference count -- used when freeing surface */
slouken@2275
    91
    int refcount;               /**< Read-mostly */
slouken@2275
    92
} SDL_Surface;
slouken@2275
    93
slouken@2275
    94
/**
slouken@3407
    95
 * \brief The type of function used for surface blitting functions.
slouken@2275
    96
 */
slouken@2275
    97
typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
slouken@2275
    98
                         struct SDL_Surface * dst, SDL_Rect * dstrect);
slouken@2275
    99
slouken@3341
   100
/**
slouken@4424
   101
 *  Allocate and free an RGB surface.
slouken@7191
   102
 *
slouken@3407
   103
 *  If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
slouken@3407
   104
 *  If the depth is greater than 8 bits, the pixel format is set using the
slouken@3407
   105
 *  flags '[RGB]mask'.
slouken@7191
   106
 *
slouken@3407
   107
 *  If the function runs out of memory, it will return NULL.
slouken@7191
   108
 *
slouken@3407
   109
 *  \param flags The \c flags are obsolete and should be set to 0.
philipp@7188
   110
 *  \param width The width in pixels of the surface to create.
philipp@7188
   111
 *  \param height The height in pixels of the surface to create.
philipp@7188
   112
 *  \param depth The depth in bits of the surface to create.
philipp@7188
   113
 *  \param Rmask The red mask of the surface to create.
philipp@7188
   114
 *  \param Gmask The green mask of the surface to create.
philipp@7188
   115
 *  \param Bmask The blue mask of the surface to create.
philipp@7188
   116
 *  \param Amask The alpha mask of the surface to create.
slouken@2275
   117
 */
slouken@2275
   118
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
slouken@2275
   119
    (Uint32 flags, int width, int height, int depth,
slouken@2275
   120
     Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
slouken@10482
   121
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat
slouken@10482
   122
    (Uint32 flags, int width, int height, int depth, Uint32 format);
slouken@2275
   123
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
slouken@2275
   124
                                                              int width,
slouken@2275
   125
                                                              int height,
slouken@2275
   126
                                                              int depth,
slouken@2275
   127
                                                              int pitch,
slouken@2275
   128
                                                              Uint32 Rmask,
slouken@2275
   129
                                                              Uint32 Gmask,
slouken@2275
   130
                                                              Uint32 Bmask,
slouken@2275
   131
                                                              Uint32 Amask);
slouken@10482
   132
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
slouken@10482
   133
    (void *pixels, int width, int height, int depth, int pitch, Uint32 format);
slouken@2275
   134
extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
slouken@2275
   135
slouken@2275
   136
/**
slouken@3407
   137
 *  \brief Set the palette used by a surface.
slouken@7191
   138
 *
slouken@3407
   139
 *  \return 0, or -1 if the surface format doesn't use a palette.
slouken@7191
   140
 *
slouken@3407
   141
 *  \note A single palette can be shared with many surfaces.
slouken@2275
   142
 */
slouken@2275
   143
extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
slouken@2275
   144
                                                  SDL_Palette * palette);
slouken@2275
   145
slouken@3341
   146
/**
slouken@3407
   147
 *  \brief Sets up a surface for directly accessing the pixels.
slouken@7191
   148
 *
slouken@3407
   149
 *  Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
slouken@7191
   150
 *  to and read from \c surface->pixels, using the pixel format stored in
slouken@7191
   151
 *  \c surface->format.  Once you are done accessing the surface, you should
slouken@3407
   152
 *  use SDL_UnlockSurface() to release it.
slouken@7191
   153
 *
slouken@3407
   154
 *  Not all surfaces require locking.  If SDL_MUSTLOCK(surface) evaluates
slouken@3407
   155
 *  to 0, then you can read and write to the surface at any time, and the
slouken@3407
   156
 *  pixel format of the surface will not change.
slouken@7191
   157
 *
slouken@3407
   158
 *  No operating system or library calls should be made between lock/unlock
slouken@3407
   159
 *  pairs, as critical system locks may be held during this time.
slouken@7191
   160
 *
slouken@3407
   161
 *  SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
slouken@7191
   162
 *
slouken@3407
   163
 *  \sa SDL_UnlockSurface()
slouken@2275
   164
 */
slouken@2275
   165
extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
slouken@3341
   166
/** \sa SDL_LockSurface() */
slouken@2275
   167
extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
slouken@2275
   168
slouken@3341
   169
/**
slouken@4971
   170
 *  Load a surface from a seekable SDL data stream (memory or file).
slouken@7191
   171
 *
slouken@4971
   172
 *  If \c freesrc is non-zero, the stream will be closed after being read.
slouken@7191
   173
 *
slouken@3407
   174
 *  The new surface should be freed with SDL_FreeSurface().
slouken@7191
   175
 *
slouken@3407
   176
 *  \return the new surface, or NULL if there was an error.
slouken@2275
   177
 */
slouken@2275
   178
extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
slouken@2275
   179
                                                    int freesrc);
slouken@2275
   180
slouken@3407
   181
/**
slouken@3407
   182
 *  Load a surface from a file.
slouken@7191
   183
 *
slouken@3407
   184
 *  Convenience macro.
slouken@3407
   185
 */
slouken@7191
   186
#define SDL_LoadBMP(file)   SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
slouken@2275
   187
slouken@3341
   188
/**
slouken@4971
   189
 *  Save a surface to a seekable SDL data stream (memory or file).
slouken@7191
   190
 *
slouken@10404
   191
 *  Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
slouken@10404
   192
 *  BMP directly. Other RGB formats with 8-bit or higher get converted to a
slouken@10404
   193
 *  24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
slouken@10404
   194
 *  surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
slouken@10404
   195
 *  not supported.
slouken@10404
   196
 *
slouken@4971
   197
 *  If \c freedst is non-zero, the stream will be closed after being written.
slouken@7191
   198
 *
slouken@3407
   199
 *  \return 0 if successful or -1 if there was an error.
slouken@2275
   200
 */
slouken@2275
   201
extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
slouken@2275
   202
    (SDL_Surface * surface, SDL_RWops * dst, int freedst);
slouken@2275
   203
slouken@7191
   204
/**
slouken@3407
   205
 *  Save a surface to a file.
slouken@7191
   206
 *
slouken@3407
   207
 *  Convenience macro.
slouken@3407
   208
 */
slouken@2275
   209
#define SDL_SaveBMP(surface, file) \
slouken@7191
   210
        SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
slouken@2275
   211
slouken@3341
   212
/**
slouken@3407
   213
 *  \brief Sets the RLE acceleration hint for a surface.
slouken@7191
   214
 *
slouken@3407
   215
 *  \return 0 on success, or -1 if the surface is not valid
slouken@7191
   216
 *
slouken@3407
   217
 *  \note If RLE is enabled, colorkey and alpha blending blits are much faster,
slouken@3407
   218
 *        but the surface must be locked before directly accessing the pixels.
slouken@2275
   219
 */
slouken@2275
   220
extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
slouken@2275
   221
                                              int flag);
slouken@2275
   222
slouken@3341
   223
/**
slouken@3407
   224
 *  \brief Sets the color key (transparent pixel) in a blittable surface.
slouken@7191
   225
 *
slouken@3407
   226
 *  \param surface The surface to update
slouken@6257
   227
 *  \param flag Non-zero to enable colorkey and 0 to disable colorkey
slouken@3407
   228
 *  \param key The transparent pixel in the native surface format
slouken@7191
   229
 *
slouken@3407
   230
 *  \return 0 on success, or -1 if the surface is not valid
slouken@6257
   231
 *
slouken@6257
   232
 *  You can pass SDL_RLEACCEL to enable RLE accelerated blits.
slouken@2275
   233
 */
slouken@2275
   234
extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
slouken@3560
   235
                                            int flag, Uint32 key);
slouken@2275
   236
slouken@3341
   237
/**
slouken@3550
   238
 *  \brief Gets the color key (transparent pixel) in a blittable surface.
slouken@7191
   239
 *
slouken@3407
   240
 *  \param surface The surface to update
slouken@7191
   241
 *  \param key A pointer filled in with the transparent pixel in the native
slouken@3407
   242
 *             surface format
slouken@7191
   243
 *
slouken@7191
   244
 *  \return 0 on success, or -1 if the surface is not valid or colorkey is not
slouken@3407
   245
 *          enabled.
slouken@3103
   246
 */
slouken@3103
   247
extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
slouken@3103
   248
                                            Uint32 * key);
slouken@3103
   249
slouken@2275
   250
/**
slouken@3407
   251
 *  \brief Set an additional color value used in blit operations.
slouken@7191
   252
 *
slouken@3407
   253
 *  \param surface The surface to update.
slouken@4971
   254
 *  \param r The red color value multiplied into blit operations.
slouken@4971
   255
 *  \param g The green color value multiplied into blit operations.
slouken@4971
   256
 *  \param b The blue color value multiplied into blit operations.
slouken@7191
   257
 *
slouken@3407
   258
 *  \return 0 on success, or -1 if the surface is not valid.
slouken@7191
   259
 *
slouken@3407
   260
 *  \sa SDL_GetSurfaceColorMod()
slouken@2275
   261
 */
slouken@2275
   262
extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
slouken@2275
   263
                                                   Uint8 r, Uint8 g, Uint8 b);
slouken@2275
   264
slouken@2275
   265
slouken@2275
   266
/**
slouken@3407
   267
 *  \brief Get the additional color value used in blit operations.
slouken@7191
   268
 *
slouken@3407
   269
 *  \param surface The surface to query.
slouken@4971
   270
 *  \param r A pointer filled in with the current red color value.
slouken@4971
   271
 *  \param g A pointer filled in with the current green color value.
slouken@4971
   272
 *  \param b A pointer filled in with the current blue color value.
slouken@7191
   273
 *
slouken@3407
   274
 *  \return 0 on success, or -1 if the surface is not valid.
slouken@7191
   275
 *
slouken@3407
   276
 *  \sa SDL_SetSurfaceColorMod()
slouken@2275
   277
 */
slouken@2275
   278
extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
slouken@2275
   279
                                                   Uint8 * r, Uint8 * g,
slouken@2275
   280
                                                   Uint8 * b);
slouken@2275
   281
slouken@2275
   282
/**
slouken@3407
   283
 *  \brief Set an additional alpha value used in blit operations.
slouken@7191
   284
 *
slouken@3407
   285
 *  \param surface The surface to update.
slouken@4971
   286
 *  \param alpha The alpha value multiplied into blit operations.
slouken@7191
   287
 *
slouken@3407
   288
 *  \return 0 on success, or -1 if the surface is not valid.
slouken@7191
   289
 *
slouken@3407
   290
 *  \sa SDL_GetSurfaceAlphaMod()
slouken@2275
   291
 */
slouken@2275
   292
extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
slouken@2275
   293
                                                   Uint8 alpha);
slouken@2275
   294
slouken@2275
   295
/**
slouken@3407
   296
 *  \brief Get the additional alpha value used in blit operations.
slouken@7191
   297
 *
slouken@3407
   298
 *  \param surface The surface to query.
slouken@4971
   299
 *  \param alpha A pointer filled in with the current alpha value.
slouken@7191
   300
 *
slouken@3407
   301
 *  \return 0 on success, or -1 if the surface is not valid.
slouken@7191
   302
 *
slouken@3407
   303
 *  \sa SDL_SetSurfaceAlphaMod()
slouken@2275
   304
 */
slouken@2275
   305
extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
slouken@2275
   306
                                                   Uint8 * alpha);
slouken@2275
   307
slouken@2275
   308
/**
slouken@3407
   309
 *  \brief Set the blend mode used for blit operations.
slouken@7191
   310
 *
slouken@3407
   311
 *  \param surface The surface to update.
slouken@3407
   312
 *  \param blendMode ::SDL_BlendMode to use for blit blending.
slouken@7191
   313
 *
slouken@3407
   314
 *  \return 0 on success, or -1 if the parameters are not valid.
slouken@7191
   315
 *
slouken@3407
   316
 *  \sa SDL_GetSurfaceBlendMode()
slouken@2275
   317
 */
slouken@2275
   318
extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
slouken@4929
   319
                                                    SDL_BlendMode blendMode);
slouken@2275
   320
slouken@2275
   321
/**
slouken@3407
   322
 *  \brief Get the blend mode used for blit operations.
slouken@7191
   323
 *
slouken@3407
   324
 *  \param surface   The surface to query.
slouken@3407
   325
 *  \param blendMode A pointer filled in with the current blend mode.
slouken@7191
   326
 *
slouken@3407
   327
 *  \return 0 on success, or -1 if the surface is not valid.
slouken@7191
   328
 *
slouken@3407
   329
 *  \sa SDL_SetSurfaceBlendMode()
slouken@2275
   330
 */
slouken@2275
   331
extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
slouken@4929
   332
                                                    SDL_BlendMode *blendMode);
slouken@2275
   333
slouken@2275
   334
/**
slouken@3407
   335
 *  Sets the clipping rectangle for the destination surface in a blit.
slouken@7191
   336
 *
slouken@3407
   337
 *  If the clip rectangle is NULL, clipping will be disabled.
slouken@7191
   338
 *
slouken@3407
   339
 *  If the clip rectangle doesn't intersect the surface, the function will
slouken@3407
   340
 *  return SDL_FALSE and blits will be completely clipped.  Otherwise the
slouken@3407
   341
 *  function returns SDL_TRUE and blits to the surface will be clipped to
slouken@3407
   342
 *  the intersection of the surface area and the clipping rectangle.
slouken@7191
   343
 *
slouken@3407
   344
 *  Note that blits are automatically clipped to the edges of the source
slouken@3407
   345
 *  and destination surfaces.
slouken@2275
   346
 */
slouken@2275
   347
extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
slouken@2275
   348
                                                 const SDL_Rect * rect);
slouken@2275
   349
slouken@3341
   350
/**
slouken@3407
   351
 *  Gets the clipping rectangle for the destination surface in a blit.
slouken@7191
   352
 *
slouken@3407
   353
 *  \c rect must be a pointer to a valid rectangle which will be filled
slouken@3407
   354
 *  with the correct values.
slouken@2275
   355
 */
slouken@2275
   356
extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
slouken@2275
   357
                                             SDL_Rect * rect);
slouken@2275
   358
slouken@3341
   359
/**
slouken@7191
   360
 *  Creates a new surface of the specified format, and then copies and maps
slouken@7191
   361
 *  the given surface to it so the blit of the converted surface will be as
slouken@3407
   362
 *  fast as possible.  If this function fails, it returns NULL.
slouken@7191
   363
 *
slouken@7191
   364
 *  The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
slouken@3407
   365
 *  semantics.  You can also pass ::SDL_RLEACCEL in the flags parameter and
slouken@3407
   366
 *  SDL will try to RLE accelerate colorkey and alpha blits in the resulting
slouken@3407
   367
 *  surface.
slouken@2275
   368
 */
slouken@2275
   369
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
icculus@7725
   370
    (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags);
slouken@5375
   371
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
slouken@5375
   372
    (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
slouken@2275
   373
slouken@3341
   374
/**
slouken@3434
   375
 * \brief Copy a block of pixels of one format to another format
slouken@7191
   376
 *
slouken@6041
   377
 *  \return 0 on success, or -1 if there was an error
slouken@3434
   378
 */
slouken@3434
   379
extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
slouken@3434
   380
                                              Uint32 src_format,
slouken@3434
   381
                                              const void * src, int src_pitch,
slouken@3434
   382
                                              Uint32 dst_format,
slouken@3434
   383
                                              void * dst, int dst_pitch);
slouken@3434
   384
slouken@3434
   385
/**
slouken@3407
   386
 *  Performs a fast fill of the given rectangle with \c color.
slouken@7191
   387
 *
slouken@3536
   388
 *  If \c rect is NULL, the whole surface will be filled with \c color.
slouken@7191
   389
 *
slouken@7191
   390
 *  The color should be a pixel of the format used by the surface, and
slouken@3407
   391
 *  can be generated by the SDL_MapRGB() function.
slouken@7191
   392
 *
slouken@3407
   393
 *  \return 0 on success, or -1 on error.
slouken@2275
   394
 */
slouken@2275
   395
extern DECLSPEC int SDLCALL SDL_FillRect
slouken@3536
   396
    (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
slouken@3536
   397
extern DECLSPEC int SDLCALL SDL_FillRects
slouken@5297
   398
    (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
slouken@2275
   399
slouken@3341
   400
/**
slouken@3407
   401
 *  Performs a fast blit from the source surface to the destination surface.
slouken@7191
   402
 *
slouken@3407
   403
 *  This assumes that the source and destination rectangles are
slouken@3407
   404
 *  the same size.  If either \c srcrect or \c dstrect are NULL, the entire
slouken@3407
   405
 *  surface (\c src or \c dst) is copied.  The final blit rectangles are saved
slouken@3407
   406
 *  in \c srcrect and \c dstrect after all clipping is performed.
slouken@7191
   407
 *
slouken@3407
   408
 *  \return If the blit is successful, it returns 0, otherwise it returns -1.
slouken@2275
   409
 *
slouken@3407
   410
 *  The blit function should not be called on a locked surface.
slouken@2275
   411
 *
slouken@7502
   412
 *  The blit semantics for surfaces with and without blending and colorkey
slouken@3407
   413
 *  are defined as follows:
slouken@3407
   414
 *  \verbatim
slouken@3407
   415
    RGBA->RGB:
slouken@7502
   416
      Source surface blend mode set to SDL_BLENDMODE_BLEND:
slouken@7502
   417
        alpha-blend (using the source alpha-channel and per-surface alpha)
slouken@3407
   418
        SDL_SRCCOLORKEY ignored.
slouken@7502
   419
      Source surface blend mode set to SDL_BLENDMODE_NONE:
slouken@3407
   420
        copy RGB.
slouken@3407
   421
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
philipp@7125
   422
        RGB values of the source color key, ignoring alpha in the
slouken@3407
   423
        comparison.
slouken@7191
   424
slouken@3407
   425
    RGB->RGBA:
slouken@7502
   426
      Source surface blend mode set to SDL_BLENDMODE_BLEND:
slouken@7502
   427
        alpha-blend (using the source per-surface alpha)
slouken@7502
   428
      Source surface blend mode set to SDL_BLENDMODE_NONE:
slouken@3407
   429
        copy RGB, set destination alpha to source per-surface alpha value.
slouken@3407
   430
      both:
slouken@3407
   431
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
philipp@7125
   432
        source color key.
slouken@7191
   433
slouken@3407
   434
    RGBA->RGBA:
slouken@7502
   435
      Source surface blend mode set to SDL_BLENDMODE_BLEND:
slouken@7502
   436
        alpha-blend (using the source alpha-channel and per-surface alpha)
slouken@3407
   437
        SDL_SRCCOLORKEY ignored.
slouken@7502
   438
      Source surface blend mode set to SDL_BLENDMODE_NONE:
slouken@3407
   439
        copy all of RGBA to the destination.
slouken@3407
   440
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
philipp@7125
   441
        RGB values of the source color key, ignoring alpha in the
slouken@7502
   442
        comparison.
slouken@7191
   443
slouken@7191
   444
    RGB->RGB:
slouken@7502
   445
      Source surface blend mode set to SDL_BLENDMODE_BLEND:
slouken@7502
   446
        alpha-blend (using the source per-surface alpha)
slouken@7502
   447
      Source surface blend mode set to SDL_BLENDMODE_NONE:
slouken@3407
   448
        copy RGB.
slouken@3407
   449
      both:
slouken@3407
   450
        if SDL_SRCCOLORKEY set, only copy the pixels matching the
philipp@7125
   451
        source color key.
slouken@3407
   452
    \endverbatim
slouken@7191
   453
 *
slouken@3407
   454
 *  You should call SDL_BlitSurface() unless you know exactly how SDL
slouken@3407
   455
 *  blitting works internally and how to use the other blit functions.
slouken@2275
   456
 */
slouken@2275
   457
#define SDL_BlitSurface SDL_UpperBlit
slouken@2275
   458
slouken@3407
   459
/**
slouken@3407
   460
 *  This is the public blit function, SDL_BlitSurface(), and it performs
slouken@3341
   461
 *  rectangle validation and clipping before passing it to SDL_LowerBlit()
slouken@3341
   462
 */
slouken@2275
   463
extern DECLSPEC int SDLCALL SDL_UpperBlit
slouken@4949
   464
    (SDL_Surface * src, const SDL_Rect * srcrect,
slouken@2275
   465
     SDL_Surface * dst, SDL_Rect * dstrect);
slouken@3341
   466
slouken@3407
   467
/**
slouken@3407
   468
 *  This is a semi-private blit function and it performs low-level surface
slouken@3341
   469
 *  blitting only.
slouken@3341
   470
 */
slouken@2275
   471
extern DECLSPEC int SDLCALL SDL_LowerBlit
slouken@2275
   472
    (SDL_Surface * src, SDL_Rect * srcrect,
slouken@2275
   473
     SDL_Surface * dst, SDL_Rect * dstrect);
slouken@2275
   474
slouken@2275
   475
/**
slouken@3407
   476
 *  \brief Perform a fast, low quality, stretch blit between two surfaces of the
slouken@3407
   477
 *         same pixel format.
slouken@7191
   478
 *
slouken@3407
   479
 *  \note This function uses a static buffer, and is not thread-safe.
slouken@2275
   480
 */
slouken@2275
   481
extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
slouken@2828
   482
                                            const SDL_Rect * srcrect,
slouken@2275
   483
                                            SDL_Surface * dst,
slouken@2828
   484
                                            const SDL_Rect * dstrect);
slouken@2275
   485
ken@5499
   486
#define SDL_BlitScaled SDL_UpperBlitScaled
ken@5499
   487
ken@5296
   488
/**
ken@5499
   489
 *  This is the public scaled blit function, SDL_BlitScaled(), and it performs
ken@5499
   490
 *  rectangle validation and clipping before passing it to SDL_LowerBlitScaled()
ken@5296
   491
 */
ken@5499
   492
extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
ken@5296
   493
    (SDL_Surface * src, const SDL_Rect * srcrect,
ken@5499
   494
    SDL_Surface * dst, SDL_Rect * dstrect);
ken@5499
   495
ken@5499
   496
/**
ken@5499
   497
 *  This is a semi-private blit function and it performs low-level surface
ken@5499
   498
 *  scaled blitting only.
ken@5499
   499
 */
ken@5499
   500
extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
ken@5499
   501
    (SDL_Surface * src, SDL_Rect * srcrect,
ken@5499
   502
    SDL_Surface * dst, SDL_Rect * dstrect);
ken@5296
   503
ken@5296
   504
slouken@2275
   505
/* Ends C function definitions when using C++ */
slouken@2275
   506
#ifdef __cplusplus
slouken@2275
   507
}
slouken@2275
   508
#endif
slouken@2275
   509
#include "close_code.h"
slouken@2275
   510
slouken@2275
   511
#endif /* _SDL_surface_h */
slouken@2275
   512
slouken@2275
   513
/* vi: set ts=4 sw=4 expandtab: */