SDL Library

Dependents:   H261_decoder

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SDL_surface.h Source File

SDL_surface.h

Go to the documentation of this file.
00001 /*
00002   Simple DirectMedia Layer
00003   Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
00004 
00005   This software is provided 'as-is', without any express or implied
00006   warranty.  In no event will the authors be held liable for any damages
00007   arising from the use of this software.
00008 
00009   Permission is granted to anyone to use this software for any purpose,
00010   including commercial applications, and to alter it and redistribute it
00011   freely, subject to the following restrictions:
00012 
00013   1. The origin of this software must not be misrepresented; you must not
00014      claim that you wrote the original software. If you use this software
00015      in a product, an acknowledgment in the product documentation would be
00016      appreciated but is not required.
00017   2. Altered source versions must be plainly marked as such, and must not be
00018      misrepresented as being the original software.
00019   3. This notice may not be removed or altered from any source distribution.
00020 */
00021 
00022 /**
00023  *  \file SDL_surface.h
00024  *
00025  *  Header file for ::SDL_Surface definition and management functions.
00026  */
00027 
00028 #ifndef _SDL_surface_h
00029 #define _SDL_surface_h
00030 
00031 #include "SDL_stdinc.h"
00032 #include "SDL_pixels.h"
00033 #include "SDL_rect.h"
00034 #include "SDL_blendmode.h"
00035 #include "SDL_rwops.h"
00036 
00037 #include "begin_code.h"
00038 /* Set up for C function definitions, even when using C++ */
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042 
00043 /**
00044  *  \name Surface flags
00045  *
00046  *  These are the currently supported flags for the ::SDL_Surface.
00047  *
00048  *  \internal
00049  *  Used internally (read-only).
00050  */
00051 /* @{ */
00052 #define SDL_SWSURFACE       0           /**< Just here for compatibility */
00053 #define SDL_PREALLOC        0x00000001  /**< Surface uses preallocated memory */
00054 #define SDL_RLEACCEL        0x00000002  /**< Surface is RLE encoded */
00055 #define SDL_DONTFREE        0x00000004  /**< Surface is referenced internally */
00056 /* @} *//* Surface flags */
00057 
00058 /**
00059  *  Evaluates to true if the surface needs to be locked before access.
00060  */
00061 #define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
00062 
00063 /**
00064  * \brief A collection of pixels used in software blitting.
00065  *
00066  * \note  This structure should be treated as read-only, except for \c pixels,
00067  *        which, if not NULL, contains the raw pixel data for the surface.
00068  */
00069 typedef struct SDL_Surface
00070 {
00071     Uint32 flags;               /**< Read-only */
00072     SDL_PixelFormat  *format;    /**< Read-only */
00073     int w, h;                   /**< Read-only */
00074     int pitch;                  /**< Read-only */
00075     void *pixels;               /**< Read-write */
00076 
00077     /** Application data associated with the surface */
00078     void *userdata;             /**< Read-write */
00079 
00080     /** information needed for surfaces requiring locks */
00081     int locked;                 /**< Read-only */
00082     void *lock_data;            /**< Read-only */
00083 
00084     /** clipping information */
00085     SDL_Rect clip_rect;         /**< Read-only */
00086 
00087     /** info for fast blit mapping to other surfaces */
00088     struct SDL_BlitMap *map;    /**< Private */
00089 
00090     /** Reference count -- used when freeing surface */
00091     int refcount;               /**< Read-mostly */
00092 } SDL_Surface;
00093 
00094 /**
00095  * \brief The type of function used for surface blitting functions.
00096  */
00097 typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
00098                          struct SDL_Surface * dst, SDL_Rect * dstrect);
00099 
00100 /**
00101  *  Allocate and free an RGB surface.
00102  *
00103  *  If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
00104  *  If the depth is greater than 8 bits, the pixel format is set using the
00105  *  flags '[RGB]mask'.
00106  *
00107  *  If the function runs out of memory, it will return NULL.
00108  *
00109  *  \param flags The \c flags are obsolete and should be set to 0.
00110  *  \param width The width in pixels of the surface to create.
00111  *  \param height The height in pixels of the surface to create.
00112  *  \param depth The depth in bits of the surface to create.
00113  *  \param Rmask The red mask of the surface to create.
00114  *  \param Gmask The green mask of the surface to create.
00115  *  \param Bmask The blue mask of the surface to create.
00116  *  \param Amask The alpha mask of the surface to create.
00117  */
00118 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
00119     (Uint32 flags, int width, int height, int depth,
00120      Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
00121 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
00122                                                               int width,
00123                                                               int height,
00124                                                               int depth,
00125                                                               int pitch,
00126                                                               Uint32 Rmask,
00127                                                               Uint32 Gmask,
00128                                                               Uint32 Bmask,
00129                                                               Uint32 Amask);
00130 extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
00131 
00132 /**
00133  *  \brief Set the palette used by a surface.
00134  *
00135  *  \return 0, or -1 if the surface format doesn't use a palette.
00136  *
00137  *  \note A single palette can be shared with many surfaces.
00138  */
00139 extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
00140                                                   SDL_Palette * palette);
00141 
00142 /**
00143  *  \brief Sets up a surface for directly accessing the pixels.
00144  *
00145  *  Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
00146  *  to and read from \c surface->pixels, using the pixel format stored in
00147  *  \c surface->format.  Once you are done accessing the surface, you should
00148  *  use SDL_UnlockSurface() to release it.
00149  *
00150  *  Not all surfaces require locking.  If SDL_MUSTLOCK(surface) evaluates
00151  *  to 0, then you can read and write to the surface at any time, and the
00152  *  pixel format of the surface will not change.
00153  *
00154  *  No operating system or library calls should be made between lock/unlock
00155  *  pairs, as critical system locks may be held during this time.
00156  *
00157  *  SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
00158  *
00159  *  \sa SDL_UnlockSurface()
00160  */
00161 extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
00162 /** \sa SDL_LockSurface() */
00163 extern DECLSPEC void SDLCALL SDL_UnlockSurface (SDL_Surface * surface);
00164 
00165 /**
00166  *  Load a surface from a seekable SDL data stream (memory or file).
00167  *
00168  *  If \c freesrc is non-zero, the stream will be closed after being read.
00169  *
00170  *  The new surface should be freed with SDL_FreeSurface().
00171  *
00172  *  \return the new surface, or NULL if there was an error.
00173  */
00174 extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
00175                                                     int freesrc);
00176 
00177 /**
00178  *  Load a surface from a file.
00179  *
00180  *  Convenience macro.
00181  */
00182 #define SDL_LoadBMP(file)   SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
00183 
00184 /**
00185  *  Save a surface to a seekable SDL data stream (memory or file).
00186  *
00187  *  If \c freedst is non-zero, the stream will be closed after being written.
00188  *
00189  *  \return 0 if successful or -1 if there was an error.
00190  */
00191 extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
00192     (SDL_Surface * surface, SDL_RWops * dst, int freedst);
00193 
00194 /**
00195  *  Save a surface to a file.
00196  *
00197  *  Convenience macro.
00198  */
00199 #define SDL_SaveBMP(surface, file) \
00200         SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
00201 
00202 /**
00203  *  \brief Sets the RLE acceleration hint for a surface.
00204  *
00205  *  \return 0 on success, or -1 if the surface is not valid
00206  *
00207  *  \note If RLE is enabled, colorkey and alpha blending blits are much faster,
00208  *        but the surface must be locked before directly accessing the pixels.
00209  */
00210 extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
00211                                               int flag);
00212 
00213 /**
00214  *  \brief Sets the color key (transparent pixel) in a blittable surface.
00215  *
00216  *  \param surface The surface to update
00217  *  \param flag Non-zero to enable colorkey and 0 to disable colorkey
00218  *  \param key The transparent pixel in the native surface format
00219  *
00220  *  \return 0 on success, or -1 if the surface is not valid
00221  *
00222  *  You can pass SDL_RLEACCEL to enable RLE accelerated blits.
00223  */
00224 extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
00225                                             int flag, Uint32 key);
00226 
00227 /**
00228  *  \brief Gets the color key (transparent pixel) in a blittable surface.
00229  *
00230  *  \param surface The surface to update
00231  *  \param key A pointer filled in with the transparent pixel in the native
00232  *             surface format
00233  *
00234  *  \return 0 on success, or -1 if the surface is not valid or colorkey is not
00235  *          enabled.
00236  */
00237 extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
00238                                             Uint32 * key);
00239 
00240 /**
00241  *  \brief Set an additional color value used in blit operations.
00242  *
00243  *  \param surface The surface to update.
00244  *  \param r The red color value multiplied into blit operations.
00245  *  \param g The green color value multiplied into blit operations.
00246  *  \param b The blue color value multiplied into blit operations.
00247  *
00248  *  \return 0 on success, or -1 if the surface is not valid.
00249  *
00250  *  \sa SDL_GetSurfaceColorMod()
00251  */
00252 extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
00253                                                    Uint8 r, Uint8 g, Uint8 b);
00254 
00255 
00256 /**
00257  *  \brief Get the additional color value used in blit operations.
00258  *
00259  *  \param surface The surface to query.
00260  *  \param r A pointer filled in with the current red color value.
00261  *  \param g A pointer filled in with the current green color value.
00262  *  \param b A pointer filled in with the current blue color value.
00263  *
00264  *  \return 0 on success, or -1 if the surface is not valid.
00265  *
00266  *  \sa SDL_SetSurfaceColorMod()
00267  */
00268 extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
00269                                                    Uint8 * r, Uint8 * g,
00270                                                    Uint8 * b);
00271 
00272 /**
00273  *  \brief Set an additional alpha value used in blit operations.
00274  *
00275  *  \param surface The surface to update.
00276  *  \param alpha The alpha value multiplied into blit operations.
00277  *
00278  *  \return 0 on success, or -1 if the surface is not valid.
00279  *
00280  *  \sa SDL_GetSurfaceAlphaMod()
00281  */
00282 extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
00283                                                    Uint8 alpha);
00284 
00285 /**
00286  *  \brief Get the additional alpha value used in blit operations.
00287  *
00288  *  \param surface The surface to query.
00289  *  \param alpha A pointer filled in with the current alpha value.
00290  *
00291  *  \return 0 on success, or -1 if the surface is not valid.
00292  *
00293  *  \sa SDL_SetSurfaceAlphaMod()
00294  */
00295 extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
00296                                                    Uint8 * alpha);
00297 
00298 /**
00299  *  \brief Set the blend mode used for blit operations.
00300  *
00301  *  \param surface The surface to update.
00302  *  \param blendMode ::SDL_BlendMode to use for blit blending.
00303  *
00304  *  \return 0 on success, or -1 if the parameters are not valid.
00305  *
00306  *  \sa SDL_GetSurfaceBlendMode()
00307  */
00308 extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
00309                                                     SDL_BlendMode blendMode);
00310 
00311 /**
00312  *  \brief Get the blend mode used for blit operations.
00313  *
00314  *  \param surface   The surface to query.
00315  *  \param blendMode A pointer filled in with the current blend mode.
00316  *
00317  *  \return 0 on success, or -1 if the surface is not valid.
00318  *
00319  *  \sa SDL_SetSurfaceBlendMode()
00320  */
00321 extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
00322                                                     SDL_BlendMode *blendMode);
00323 
00324 /**
00325  *  Sets the clipping rectangle for the destination surface in a blit.
00326  *
00327  *  If the clip rectangle is NULL, clipping will be disabled.
00328  *
00329  *  If the clip rectangle doesn't intersect the surface, the function will
00330  *  return SDL_FALSE and blits will be completely clipped.  Otherwise the
00331  *  function returns SDL_TRUE and blits to the surface will be clipped to
00332  *  the intersection of the surface area and the clipping rectangle.
00333  *
00334  *  Note that blits are automatically clipped to the edges of the source
00335  *  and destination surfaces.
00336  */
00337 extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
00338                                                  const SDL_Rect * rect);
00339 
00340 /**
00341  *  Gets the clipping rectangle for the destination surface in a blit.
00342  *
00343  *  \c rect must be a pointer to a valid rectangle which will be filled
00344  *  with the correct values.
00345  */
00346 extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
00347                                              SDL_Rect * rect);
00348 
00349 /**
00350  *  Creates a new surface of the specified format, and then copies and maps
00351  *  the given surface to it so the blit of the converted surface will be as
00352  *  fast as possible.  If this function fails, it returns NULL.
00353  *
00354  *  The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
00355  *  semantics.  You can also pass ::SDL_RLEACCEL in the flags parameter and
00356  *  SDL will try to RLE accelerate colorkey and alpha blits in the resulting
00357  *  surface.
00358  */
00359 extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
00360     (SDL_Surface * src, const SDL_PixelFormat  * fmt, Uint32 flags);
00361 extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
00362     (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
00363 
00364 /**
00365  * \brief Copy a block of pixels of one format to another format
00366  *
00367  *  \return 0 on success, or -1 if there was an error
00368  */
00369 extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
00370                                               Uint32 src_format,
00371                                               const void * src, int src_pitch,
00372                                               Uint32 dst_format,
00373                                               void * dst, int dst_pitch);
00374 
00375 /**
00376  *  Performs a fast fill of the given rectangle with \c color.
00377  *
00378  *  If \c rect is NULL, the whole surface will be filled with \c color.
00379  *
00380  *  The color should be a pixel of the format used by the surface, and
00381  *  can be generated by the SDL_MapRGB() function.
00382  *
00383  *  \return 0 on success, or -1 on error.
00384  */
00385 extern DECLSPEC int SDLCALL SDL_FillRect
00386     (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
00387 extern DECLSPEC int SDLCALL SDL_FillRects
00388     (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
00389 
00390 /**
00391  *  Performs a fast blit from the source surface to the destination surface.
00392  *
00393  *  This assumes that the source and destination rectangles are
00394  *  the same size.  If either \c srcrect or \c dstrect are NULL, the entire
00395  *  surface (\c src or \c dst) is copied.  The final blit rectangles are saved
00396  *  in \c srcrect and \c dstrect after all clipping is performed.
00397  *
00398  *  \return If the blit is successful, it returns 0, otherwise it returns -1.
00399  *
00400  *  The blit function should not be called on a locked surface.
00401  *
00402  *  The blit semantics for surfaces with and without blending and colorkey
00403  *  are defined as follows:
00404  *  \verbatim
00405     RGBA->RGB:
00406       Source surface blend mode set to SDL_BLENDMODE_BLEND:
00407         alpha-blend (using the source alpha-channel and per-surface alpha)
00408         SDL_SRCCOLORKEY ignored.
00409       Source surface blend mode set to SDL_BLENDMODE_NONE:
00410         copy RGB.
00411         if SDL_SRCCOLORKEY set, only copy the pixels matching the
00412         RGB values of the source color key, ignoring alpha in the
00413         comparison.
00414 
00415     RGB->RGBA:
00416       Source surface blend mode set to SDL_BLENDMODE_BLEND:
00417         alpha-blend (using the source per-surface alpha)
00418       Source surface blend mode set to SDL_BLENDMODE_NONE:
00419         copy RGB, set destination alpha to source per-surface alpha value.
00420       both:
00421         if SDL_SRCCOLORKEY set, only copy the pixels matching the
00422         source color key.
00423 
00424     RGBA->RGBA:
00425       Source surface blend mode set to SDL_BLENDMODE_BLEND:
00426         alpha-blend (using the source alpha-channel and per-surface alpha)
00427         SDL_SRCCOLORKEY ignored.
00428       Source surface blend mode set to SDL_BLENDMODE_NONE:
00429         copy all of RGBA to the destination.
00430         if SDL_SRCCOLORKEY set, only copy the pixels matching the
00431         RGB values of the source color key, ignoring alpha in the
00432         comparison.
00433 
00434     RGB->RGB:
00435       Source surface blend mode set to SDL_BLENDMODE_BLEND:
00436         alpha-blend (using the source per-surface alpha)
00437       Source surface blend mode set to SDL_BLENDMODE_NONE:
00438         copy RGB.
00439       both:
00440         if SDL_SRCCOLORKEY set, only copy the pixels matching the
00441         source color key.
00442     \endverbatim
00443  *
00444  *  You should call SDL_BlitSurface() unless you know exactly how SDL
00445  *  blitting works internally and how to use the other blit functions.
00446  */
00447 #define SDL_BlitSurface SDL_UpperBlit
00448 
00449 /**
00450  *  This is the public blit function, SDL_BlitSurface(), and it performs
00451  *  rectangle validation and clipping before passing it to SDL_LowerBlit()
00452  */
00453 extern DECLSPEC int SDLCALL SDL_UpperBlit
00454     (SDL_Surface * src, const SDL_Rect * srcrect,
00455      SDL_Surface * dst, SDL_Rect * dstrect);
00456 
00457 /**
00458  *  This is a semi-private blit function and it performs low-level surface
00459  *  blitting only.
00460  */
00461 extern DECLSPEC int SDLCALL SDL_LowerBlit
00462     (SDL_Surface * src, SDL_Rect * srcrect,
00463      SDL_Surface * dst, SDL_Rect * dstrect);
00464 
00465 /**
00466  *  \brief Perform a fast, low quality, stretch blit between two surfaces of the
00467  *         same pixel format.
00468  *
00469  *  \note This function uses a static buffer, and is not thread-safe.
00470  */
00471 extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
00472                                             const SDL_Rect * srcrect,
00473                                             SDL_Surface * dst,
00474                                             const SDL_Rect * dstrect);
00475 
00476 #define SDL_BlitScaled SDL_UpperBlitScaled
00477 
00478 /**
00479  *  This is the public scaled blit function, SDL_BlitScaled(), and it performs
00480  *  rectangle validation and clipping before passing it to SDL_LowerBlitScaled()
00481  */
00482 extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
00483     (SDL_Surface * src, const SDL_Rect * srcrect,
00484     SDL_Surface * dst, SDL_Rect * dstrect);
00485 
00486 /**
00487  *  This is a semi-private blit function and it performs low-level surface
00488  *  scaled blitting only.
00489  */
00490 extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
00491     (SDL_Surface * src, SDL_Rect * srcrect,
00492     SDL_Surface * dst, SDL_Rect * dstrect);
00493 
00494 
00495 /* Ends C function definitions when using C++ */
00496 #ifdef __cplusplus
00497 }
00498 #endif
00499 #include "close_code.h"
00500 
00501 #endif /* _SDL_surface_h */
00502 
00503 /* vi: set ts=4 sw=4 expandtab: */