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