comparison include/SDL_surface.h @ 2275:12ea0fdc0df2

Split out the SDL_rect and SDL_surface functions into their own headers. Removed unused count from the dirty rect list.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Sep 2007 12:20:02 +0000
parents
children 365fe1a2aad5
comparison
equal deleted inserted replaced
2274:aedfcdeb69b6 2275:12ea0fdc0df2
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 /**
24 * \file SDL_surface.h
25 *
26 * Header file for SDL_surface definition and management functions
27 */
28
29 #ifndef _SDL_surface_h
30 #define _SDL_surface_h
31
32 #include "SDL_stdinc.h"
33 #include "SDL_pixels.h"
34 #include "SDL_rect.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 /* These are the currently supported flags for the SDL_surface */
46 /* Used internally (read-only) */
47 #define SDL_PREALLOC 0x00000001 /* Surface uses preallocated memory */
48 #define SDL_RLEACCEL 0x00000002 /* Surface is RLE encoded */
49
50 /* Evaluates to true if the surface needs to be locked before access */
51 #define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
52
53 /**
54 * \struct SDL_Surface
55 *
56 * \brief A collection of pixels used in software blitting
57 *
58 * \note This structure should be treated as read-only, except for 'pixels',
59 * which, if not NULL, contains the raw pixel data for the surface.
60 */
61 typedef struct SDL_Surface
62 {
63 Uint32 flags; /**< Read-only */
64 SDL_PixelFormat *format; /**< Read-only */
65 int w, h; /**< Read-only */
66 int pitch; /**< Read-only */
67 void *pixels; /**< Read-write */
68
69 /* Application data associated with the surfade */
70 void *userdata; /**< Read-write */
71
72 /* information needed for surfaces requiring locks */
73 int locked; /**< Read-only */
74 void *lock_data; /**< Read-only */
75
76 /* clipping information */
77 SDL_Rect clip_rect; /**< Read-only */
78
79 /* info for fast blit mapping to other surfaces */
80 struct SDL_BlitMap *map; /**< Private */
81
82 /* format version, bumped at every change to invalidate blit maps */
83 unsigned int format_version; /**< Private */
84
85 /* Reference count -- used when freeing surface */
86 int refcount; /**< Read-mostly */
87 } SDL_Surface;
88
89 /**
90 * \typedef SDL_blit
91 *
92 * \brief The type of function used for surface blitting functions
93 */
94 typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
95 struct SDL_Surface * dst, SDL_Rect * dstrect);
96
97 /*
98 * Allocate and free an RGB surface (must be called after SDL_SetVideoMode)
99 * If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
100 * If the depth is greater than 8 bits, the pixel format is set using the
101 * flags '[RGB]mask'.
102 * If the function runs out of memory, it will return NULL.
103 *
104 * The 'flags' tell what kind of surface to create.
105 * SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits.
106 * SDL_SRCALPHA means that the surface will be used for alpha blits.
107 */
108 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
109 (Uint32 flags, int width, int height, int depth,
110 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
111 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
112 int width,
113 int height,
114 int depth,
115 int pitch,
116 Uint32 Rmask,
117 Uint32 Gmask,
118 Uint32 Bmask,
119 Uint32 Amask);
120 extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
121
122 /**
123 * \fn int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
124 *
125 * \brief Set the palette used by a surface.
126 *
127 * \return 0, or -1 if the surface format doesn't use a palette.
128 *
129 * \note A single palette can be shared with many surfaces.
130 */
131 extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
132 SDL_Palette * palette);
133
134 /*
135 * SDL_LockSurface() sets up a surface for directly accessing the pixels.
136 * Between calls to SDL_LockSurface()/SDL_UnlockSurface(), you can write
137 * to and read from 'surface->pixels', using the pixel format stored in
138 * 'surface->format'. Once you are done accessing the surface, you should
139 * use SDL_UnlockSurface() to release it.
140 *
141 * Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
142 * to 0, then you can read and write to the surface at any time, and the
143 * pixel format of the surface will not change.
144 *
145 * No operating system or library calls should be made between lock/unlock
146 * pairs, as critical system locks may be held during this time.
147 *
148 * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
149 */
150 extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
151 extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
152
153 /*
154 * Load a surface from a seekable SDL data source (memory or file.)
155 * If 'freesrc' is non-zero, the source will be closed after being read.
156 * Returns the new surface, or NULL if there was an error.
157 * The new surface should be freed with SDL_FreeSurface().
158 */
159 extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
160 int freesrc);
161
162 /* Convenience macro -- load a surface from a file */
163 #define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
164
165 /*
166 * Save a surface to a seekable SDL data source (memory or file.)
167 * If 'freedst' is non-zero, the source will be closed after being written.
168 * Returns 0 if successful or -1 if there was an error.
169 */
170 extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
171 (SDL_Surface * surface, SDL_RWops * dst, int freedst);
172
173 /* Convenience macro -- save a surface to a file */
174 #define SDL_SaveBMP(surface, file) \
175 SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
176
177 /*
178 * \fn int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
179 *
180 * \brief Sets the RLE acceleration hint for a surface.
181 *
182 * \return 0 on success, or -1 if the surface is not valid
183 *
184 * \note If RLE is enabled, colorkey and alpha blending blits are much faster,
185 * but the surface must be locked before directly accessing the pixels.
186 */
187 extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
188 int flag);
189
190 /*
191 * \fn int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
192 *
193 * \brief Sets the color key (transparent pixel) in a blittable surface.
194 *
195 * \param surface The surface to update
196 * \param flag Non-zero to enable colorkey and 0 to disable colorkey
197 * \param key The transparent pixel in the native surface format
198 *
199 * \return 0 on success, or -1 if the surface is not valid
200 */
201 extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
202 Uint32 flag, Uint32 key);
203
204 /**
205 * \fn int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
206 *
207 * \brief Set an additional color value used in blit operations
208 *
209 * \param surface The surface to update
210 * \param r The red source color value multiplied into blit operations
211 * \param g The green source color value multiplied into blit operations
212 * \param b The blue source color value multiplied into blit operations
213 *
214 * \return 0 on success, or -1 if the surface is not valid
215 *
216 * \sa SDL_GetSurfaceColorMod()
217 */
218 extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
219 Uint8 r, Uint8 g, Uint8 b);
220
221
222 /**
223 * \fn int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
224 *
225 * \brief Get the additional color value used in blit operations
226 *
227 * \param surface The surface to query
228 * \param r A pointer filled in with the source red color value
229 * \param g A pointer filled in with the source green color value
230 * \param b A pointer filled in with the source blue color value
231 *
232 * \return 0 on success, or -1 if the surface is not valid
233 *
234 * \sa SDL_SetSurfaceColorMod()
235 */
236 extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
237 Uint8 * r, Uint8 * g,
238 Uint8 * b);
239
240 /**
241 * \fn int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
242 *
243 * \brief Set an additional alpha value used in blit operations
244 *
245 * \param surface The surface to update
246 * \param alpha The source alpha value multiplied into blit operations.
247 *
248 * \return 0 on success, or -1 if the surface is not valid
249 *
250 * \sa SDL_GetSurfaceAlphaMod()
251 */
252 extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
253 Uint8 alpha);
254
255 /**
256 * \fn int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
257 *
258 * \brief Get the additional alpha value used in blit operations
259 *
260 * \param surface The surface to query
261 * \param alpha A pointer filled in with the source alpha value
262 *
263 * \return 0 on success, or -1 if the surface is not valid
264 *
265 * \sa SDL_SetSurfaceAlphaMod()
266 */
267 extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
268 Uint8 * alpha);
269
270 /**
271 * \fn int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode)
272 *
273 * \brief Set the blend mode used for blit operations
274 *
275 * \param surface The surface to update
276 * \param blendMode SDL_TextureBlendMode to use for blit blending
277 *
278 * \return 0 on success, or -1 if the parameters are not valid
279 *
280 * \sa SDL_GetSurfaceBlendMode()
281 */
282 extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
283 int blendMode);
284
285 /**
286 * \fn int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode)
287 *
288 * \brief Get the blend mode used for blit operations
289 *
290 * \param surface The surface to query
291 * \param blendMode A pointer filled in with the current blend mode
292 *
293 * \return 0 on success, or -1 if the surface is not valid
294 *
295 * \sa SDL_SetSurfaceBlendMode()
296 */
297 extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
298 int *blendMode);
299
300 /**
301 * \fn int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode)
302 *
303 * \brief Set the scale mode used for blit operations
304 *
305 * \param surface The surface to update
306 * \param scaleMode SDL_TextureScaleMode to use for blit scaling
307 *
308 * \return 0 on success, or -1 if the surface is not valid or the scale mode is not supported
309 *
310 * \note If the scale mode is not supported, the closest supported mode is chosen. Currently only SDL_TEXTURESCALEMODE_FAST is supported on surfaces.
311 *
312 * \sa SDL_GetSurfaceScaleMode()
313 */
314 extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface * surface,
315 int scaleMode);
316
317 /**
318 * \fn int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode)
319 *
320 * \brief Get the scale mode used for blit operations
321 *
322 * \param surface The surface to query
323 * \param scaleMode A pointer filled in with the current scale mode
324 *
325 * \return 0 on success, or -1 if the surface is not valid
326 *
327 * \sa SDL_SetSurfaceScaleMode()
328 */
329 extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface * surface,
330 int *scaleMode);
331
332 /*
333 * Sets the clipping rectangle for the destination surface in a blit.
334 *
335 * If the clip rectangle is NULL, clipping will be disabled.
336 * If the clip rectangle doesn't intersect the surface, the function will
337 * return SDL_FALSE and blits will be completely clipped. Otherwise the
338 * function returns SDL_TRUE and blits to the surface will be clipped to
339 * the intersection of the surface area and the clipping rectangle.
340 *
341 * Note that blits are automatically clipped to the edges of the source
342 * and destination surfaces.
343 */
344 extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
345 const SDL_Rect * rect);
346
347 /*
348 * Gets the clipping rectangle for the destination surface in a blit.
349 * 'rect' must be a pointer to a valid rectangle which will be filled
350 * with the correct values.
351 */
352 extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
353 SDL_Rect * rect);
354
355 /*
356 * Creates a new surface of the specified format, and then copies and maps
357 * the given surface to it so the blit of the converted surface will be as
358 * fast as possible. If this function fails, it returns NULL.
359 *
360 * The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those
361 * semantics. You can also pass SDL_RLEACCEL in the flags parameter and
362 * SDL will try to RLE accelerate colorkey and alpha blits in the resulting
363 * surface.
364 *
365 * This function is used internally by SDL_DisplayFormat().
366 */
367 extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
368 (SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);
369
370 /*
371 * This function performs a fast fill of the given rectangle with 'color'
372 * The given rectangle is clipped to the destination surface clip area
373 * and the final fill rectangle is saved in the passed in pointer.
374 * If 'dstrect' is NULL, the whole surface will be filled with 'color'
375 * The color should be a pixel of the format used by the surface, and
376 * can be generated by the SDL_MapRGB() function.
377 * This function returns 0 on success, or -1 on error.
378 */
379 extern DECLSPEC int SDLCALL SDL_FillRect
380 (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color);
381
382 /*
383 * This performs a fast blit from the source surface to the destination
384 * surface. It assumes that the source and destination rectangles are
385 * the same size. If either 'srcrect' or 'dstrect' are NULL, the entire
386 * surface (src or dst) is copied. The final blit rectangles are saved
387 * in 'srcrect' and 'dstrect' after all clipping is performed.
388 * If the blit is successful, it returns 0, otherwise it returns -1.
389 *
390 * The blit function should not be called on a locked surface.
391 *
392 * The blit semantics for surfaces with and without alpha and colorkey
393 * are defined as follows:
394 *
395 * RGBA->RGB:
396 * SDL_SRCALPHA set:
397 * alpha-blend (using alpha-channel).
398 * SDL_SRCCOLORKEY ignored.
399 * SDL_SRCALPHA not set:
400 * copy RGB.
401 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
402 * RGB values of the source colour key, ignoring alpha in the
403 * comparison.
404 *
405 * RGB->RGBA:
406 * SDL_SRCALPHA set:
407 * alpha-blend (using the source per-surface alpha value);
408 * set destination alpha to opaque.
409 * SDL_SRCALPHA not set:
410 * copy RGB, set destination alpha to source per-surface alpha value.
411 * both:
412 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
413 * source colour key.
414 *
415 * RGBA->RGBA:
416 * SDL_SRCALPHA set:
417 * alpha-blend (using the source alpha channel) the RGB values;
418 * leave destination alpha untouched. [Note: is this correct?]
419 * SDL_SRCCOLORKEY ignored.
420 * SDL_SRCALPHA not set:
421 * copy all of RGBA to the destination.
422 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
423 * RGB values of the source colour key, ignoring alpha in the
424 * comparison.
425 *
426 * RGB->RGB:
427 * SDL_SRCALPHA set:
428 * alpha-blend (using the source per-surface alpha value).
429 * SDL_SRCALPHA not set:
430 * copy RGB.
431 * both:
432 * if SDL_SRCCOLORKEY set, only copy the pixels matching the
433 * source colour key.
434 *
435 * If either of the surfaces were in video memory, and the blit returns -2,
436 * the video memory was lost, so it should be reloaded with artwork and
437 * re-blitted:
438 while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) {
439 while ( SDL_LockSurface(image) < 0 )
440 Sleep(10);
441 -- Write image pixels to image->pixels --
442 SDL_UnlockSurface(image);
443 }
444 * This happens under DirectX 5.0 when the system switches away from your
445 * fullscreen application. The lock will also fail until you have access
446 * to the video memory again.
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 /* This is the public blit function, SDL_BlitSurface(), and it performs
454 rectangle validation and clipping before passing it to SDL_LowerBlit()
455 */
456 extern DECLSPEC int SDLCALL SDL_UpperBlit
457 (SDL_Surface * src, SDL_Rect * srcrect,
458 SDL_Surface * dst, SDL_Rect * dstrect);
459 /* This is a semi-private blit function and it performs low-level surface
460 blitting only.
461 */
462 extern DECLSPEC int SDLCALL SDL_LowerBlit
463 (SDL_Surface * src, SDL_Rect * srcrect,
464 SDL_Surface * dst, SDL_Rect * dstrect);
465
466 /**
467 * \fn int SDL_SoftStretch(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect)
468 *
469 * \brief Perform a fast, low quality, stretch blit between two surfaces of the same pixel format.
470 *
471 * \note This function uses a static buffer, and is not thread-safe.
472 */
473 extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
474 SDL_Rect * srcrect,
475 SDL_Surface * dst,
476 SDL_Rect * dstrect);
477
478 /* Ends C function definitions when using C++ */
479 #ifdef __cplusplus
480 /* *INDENT-OFF* */
481 }
482 /* *INDENT-ON* */
483 #endif
484 #include "close_code.h"
485
486 #endif /* _SDL_surface_h */
487
488 /* vi: set ts=4 sw=4 expandtab: */