SDL  2.0
SDL_surface.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2017 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 #include "../SDL_internal.h"
22 
23 #include "SDL_video.h"
24 #include "SDL_sysvideo.h"
25 #include "SDL_blit.h"
26 #include "SDL_RLEaccel_c.h"
27 #include "SDL_pixels_c.h"
28 
29 /* Check to make sure we can safely check multiplication of surface w and pitch and it won't overflow size_t */
30 SDL_COMPILE_TIME_ASSERT(surface_size_assumptions,
31  sizeof(int) == sizeof(Sint32) && sizeof(size_t) >= sizeof(Sint32));
32 
33 /* Public routines */
34 
35 /*
36  * Create an empty RGB surface of the appropriate depth using the given
37  * enum SDL_PIXELFORMAT_* format
38  */
41  Uint32 format)
42 {
44 
45  /* The flags are no longer used, make the compiler happy */
46  (void)flags;
47 
48  /* Allocate the surface */
49  surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
50  if (surface == NULL) {
52  return NULL;
53  }
54 
55  surface->format = SDL_AllocFormat(format);
56  if (!surface->format) {
57  SDL_FreeSurface(surface);
58  return NULL;
59  }
60  surface->w = width;
61  surface->h = height;
62  surface->pitch = SDL_CalculatePitch(surface);
63  SDL_SetClipRect(surface, NULL);
64 
65  if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
66  SDL_Palette *palette =
67  SDL_AllocPalette((1 << surface->format->BitsPerPixel));
68  if (!palette) {
69  SDL_FreeSurface(surface);
70  return NULL;
71  }
72  if (palette->ncolors == 2) {
73  /* Create a black and white bitmap palette */
74  palette->colors[0].r = 0xFF;
75  palette->colors[0].g = 0xFF;
76  palette->colors[0].b = 0xFF;
77  palette->colors[1].r = 0x00;
78  palette->colors[1].g = 0x00;
79  palette->colors[1].b = 0x00;
80  }
81  SDL_SetSurfacePalette(surface, palette);
82  SDL_FreePalette(palette);
83  }
84 
85  /* Get the pixels */
86  if (surface->w && surface->h) {
87  /* Assumptions checked in surface_size_assumptions assert above */
88  Sint64 size = ((Sint64)surface->h * surface->pitch);
90  /* Overflow... */
91  SDL_FreeSurface(surface);
93  return NULL;
94  }
95 
96  surface->pixels = SDL_malloc((size_t)size);
97  if (!surface->pixels) {
98  SDL_FreeSurface(surface);
100  return NULL;
101  }
102  /* This is important for bitmaps */
103  SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
104  }
105 
106  /* Allocate an empty mapping */
107  surface->map = SDL_AllocBlitMap();
108  if (!surface->map) {
109  SDL_FreeSurface(surface);
110  return NULL;
111  }
112 
113  /* By default surface with an alpha mask are set up for blending */
114  if (surface->format->Amask) {
116  }
117 
118  /* The surface is ready to go */
119  surface->refcount = 1;
120  return surface;
121 }
122 
123 /*
124  * Create an empty RGB surface of the appropriate depth
125  */
126 SDL_Surface *
128  int width, int height, int depth,
129  Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
130 {
131  Uint32 format;
132 
133  /* Get the pixel format */
134  format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
135  if (format == SDL_PIXELFORMAT_UNKNOWN) {
136  SDL_SetError("Unknown pixel format");
137  return NULL;
138  }
139 
140  return SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format);
141 }
142 
143 /*
144  * Create an RGB surface from an existing memory buffer
145  */
146 SDL_Surface *
148  int width, int height, int depth, int pitch,
149  Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
150  Uint32 Amask)
151 {
153 
154  surface = SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
155  if (surface != NULL) {
156  surface->flags |= SDL_PREALLOC;
157  surface->pixels = pixels;
158  surface->w = width;
159  surface->h = height;
160  surface->pitch = pitch;
161  SDL_SetClipRect(surface, NULL);
162  }
163  return surface;
164 }
165 
166 /*
167  * Create an RGB surface from an existing memory buffer using the given given
168  * enum SDL_PIXELFORMAT_* format
169  */
170 SDL_Surface *
172  int width, int height, int depth, int pitch,
173  Uint32 format)
174 {
176 
177  surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, format);
178  if (surface != NULL) {
179  surface->flags |= SDL_PREALLOC;
180  surface->pixels = pixels;
181  surface->w = width;
182  surface->h = height;
183  surface->pitch = pitch;
184  SDL_SetClipRect(surface, NULL);
185  }
186  return surface;
187 }
188 
189 int
191 {
192  if (!surface) {
193  return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
194  }
195  if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
196  return -1;
197  }
198  SDL_InvalidateMap(surface->map);
199 
200  return 0;
201 }
202 
203 int
205 {
206  int flags;
207 
208  if (!surface) {
209  return -1;
210  }
211 
212  flags = surface->map->info.flags;
213  if (flag) {
214  surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
215  } else {
216  surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
217  }
218  if (surface->map->info.flags != flags) {
219  SDL_InvalidateMap(surface->map);
220  }
221  return 0;
222 }
223 
224 int
226 {
227  int flags;
228 
229  if (!surface) {
230  return SDL_InvalidParamError("surface");
231  }
232 
233  if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
234  return SDL_InvalidParamError("key");
235  }
236 
237  if (flag & SDL_RLEACCEL) {
238  SDL_SetSurfaceRLE(surface, 1);
239  }
240 
241  flags = surface->map->info.flags;
242  if (flag) {
243  surface->map->info.flags |= SDL_COPY_COLORKEY;
244  surface->map->info.colorkey = key;
245  if (surface->format->palette) {
246  surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
247  ++surface->format->palette->version;
248  if (!surface->format->palette->version) {
249  surface->format->palette->version = 1;
250  }
251  }
252  } else {
253  if (surface->format->palette) {
254  surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE;
255  ++surface->format->palette->version;
256  if (!surface->format->palette->version) {
257  surface->format->palette->version = 1;
258  }
259  }
260  surface->map->info.flags &= ~SDL_COPY_COLORKEY;
261  }
262  if (surface->map->info.flags != flags) {
263  SDL_InvalidateMap(surface->map);
264  }
265 
266  return 0;
267 }
268 
269 int
271 {
272  if (!surface) {
273  return -1;
274  }
275 
276  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
277  return -1;
278  }
279 
280  if (key) {
281  *key = surface->map->info.colorkey;
282  }
283  return 0;
284 }
285 
286 /* This is a fairly slow function to switch from colorkey to alpha */
287 static void
289 {
290  int x, y;
291 
292  if (!surface) {
293  return;
294  }
295 
296  if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
297  !surface->format->Amask) {
298  return;
299  }
300 
301  SDL_LockSurface(surface);
302 
303  switch (surface->format->BytesPerPixel) {
304  case 2:
305  {
306  Uint16 *row, *spot;
307  Uint16 ckey = (Uint16) surface->map->info.colorkey;
308  Uint16 mask = (Uint16) (~surface->format->Amask);
309 
310  /* Ignore alpha in colorkey comparison */
311  ckey &= mask;
312  row = (Uint16 *) surface->pixels;
313  for (y = surface->h; y--;) {
314  spot = row;
315  for (x = surface->w; x--;) {
316  if ((*spot & mask) == ckey) {
317  *spot &= mask;
318  }
319  ++spot;
320  }
321  row += surface->pitch / 2;
322  }
323  }
324  break;
325  case 3:
326  /* FIXME */
327  break;
328  case 4:
329  {
330  Uint32 *row, *spot;
331  Uint32 ckey = surface->map->info.colorkey;
332  Uint32 mask = ~surface->format->Amask;
333 
334  /* Ignore alpha in colorkey comparison */
335  ckey &= mask;
336  row = (Uint32 *) surface->pixels;
337  for (y = surface->h; y--;) {
338  spot = row;
339  for (x = surface->w; x--;) {
340  if ((*spot & mask) == ckey) {
341  *spot &= mask;
342  }
343  ++spot;
344  }
345  row += surface->pitch / 4;
346  }
347  }
348  break;
349  }
350 
351  SDL_UnlockSurface(surface);
352 
353  SDL_SetColorKey(surface, 0, 0);
355 }
356 
357 int
359 {
360  int flags;
361 
362  if (!surface) {
363  return -1;
364  }
365 
366  surface->map->info.r = r;
367  surface->map->info.g = g;
368  surface->map->info.b = b;
369 
370  flags = surface->map->info.flags;
371  if (r != 0xFF || g != 0xFF || b != 0xFF) {
372  surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
373  } else {
374  surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
375  }
376  if (surface->map->info.flags != flags) {
377  SDL_InvalidateMap(surface->map);
378  }
379  return 0;
380 }
381 
382 
383 int
385 {
386  if (!surface) {
387  return -1;
388  }
389 
390  if (r) {
391  *r = surface->map->info.r;
392  }
393  if (g) {
394  *g = surface->map->info.g;
395  }
396  if (b) {
397  *b = surface->map->info.b;
398  }
399  return 0;
400 }
401 
402 int
404 {
405  int flags;
406 
407  if (!surface) {
408  return -1;
409  }
410 
411  surface->map->info.a = alpha;
412 
413  flags = surface->map->info.flags;
414  if (alpha != 0xFF) {
415  surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
416  } else {
417  surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
418  }
419  if (surface->map->info.flags != flags) {
420  SDL_InvalidateMap(surface->map);
421  }
422  return 0;
423 }
424 
425 int
427 {
428  if (!surface) {
429  return -1;
430  }
431 
432  if (alpha) {
433  *alpha = surface->map->info.a;
434  }
435  return 0;
436 }
437 
438 int
440 {
441  int flags, status;
442 
443  if (!surface) {
444  return -1;
445  }
446 
447  status = 0;
448  flags = surface->map->info.flags;
449  surface->map->info.flags &=
451  switch (blendMode) {
452  case SDL_BLENDMODE_NONE:
453  break;
454  case SDL_BLENDMODE_BLEND:
455  surface->map->info.flags |= SDL_COPY_BLEND;
456  break;
457  case SDL_BLENDMODE_ADD:
458  surface->map->info.flags |= SDL_COPY_ADD;
459  break;
460  case SDL_BLENDMODE_MOD:
461  surface->map->info.flags |= SDL_COPY_MOD;
462  break;
463  default:
464  status = SDL_Unsupported();
465  break;
466  }
467 
468  if (surface->map->info.flags != flags) {
469  SDL_InvalidateMap(surface->map);
470  }
471 
472  return status;
473 }
474 
475 int
477 {
478  if (!surface) {
479  return -1;
480  }
481 
482  if (!blendMode) {
483  return 0;
484  }
485 
486  switch (surface->map->
487  info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)) {
488  case SDL_COPY_BLEND:
489  *blendMode = SDL_BLENDMODE_BLEND;
490  break;
491  case SDL_COPY_ADD:
492  *blendMode = SDL_BLENDMODE_ADD;
493  break;
494  case SDL_COPY_MOD:
495  *blendMode = SDL_BLENDMODE_MOD;
496  break;
497  default:
498  *blendMode = SDL_BLENDMODE_NONE;
499  break;
500  }
501  return 0;
502 }
503 
504 SDL_bool
506 {
507  SDL_Rect full_rect;
508 
509  /* Don't do anything if there's no surface to act on */
510  if (!surface) {
511  return SDL_FALSE;
512  }
513 
514  /* Set up the full surface rectangle */
515  full_rect.x = 0;
516  full_rect.y = 0;
517  full_rect.w = surface->w;
518  full_rect.h = surface->h;
519 
520  /* Set the clipping rectangle */
521  if (!rect) {
522  surface->clip_rect = full_rect;
523  return SDL_TRUE;
524  }
525  return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
526 }
527 
528 void
530 {
531  if (surface && rect) {
532  *rect = surface->clip_rect;
533  }
534 }
535 
536 /*
537  * Set up a blit between two surfaces -- split into three parts:
538  * The upper part, SDL_UpperBlit(), performs clipping and rectangle
539  * verification. The lower part is a pointer to a low level
540  * accelerated blitting function.
541  *
542  * These parts are separated out and each used internally by this
543  * library in the optimimum places. They are exported so that if
544  * you know exactly what you are doing, you can optimize your code
545  * by calling the one(s) you need.
546  */
547 int
549  SDL_Surface * dst, SDL_Rect * dstrect)
550 {
551  /* Check to make sure the blit mapping is valid */
552  if ((src->map->dst != dst) ||
553  (dst->format->palette &&
554  src->map->dst_palette_version != dst->format->palette->version) ||
555  (src->format->palette &&
556  src->map->src_palette_version != src->format->palette->version)) {
557  if (SDL_MapSurface(src, dst) < 0) {
558  return (-1);
559  }
560  /* just here for debugging */
561 /* printf */
562 /* ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */
563 /* src, dst->flags, src->map->info.flags, dst, dst->flags, */
564 /* dst->map->info.flags, src->map->blit); */
565  }
566  return (src->map->blit(src, srcrect, dst, dstrect));
567 }
568 
569 
570 int
572  SDL_Surface * dst, SDL_Rect * dstrect)
573 {
574  SDL_Rect fulldst;
575  int srcx, srcy, w, h;
576 
577  /* Make sure the surfaces aren't locked */
578  if (!src || !dst) {
579  return SDL_SetError("SDL_UpperBlit: passed a NULL surface");
580  }
581  if (src->locked || dst->locked) {
582  return SDL_SetError("Surfaces must not be locked during blit");
583  }
584 
585  /* If the destination rectangle is NULL, use the entire dest surface */
586  if (dstrect == NULL) {
587  fulldst.x = fulldst.y = 0;
588  fulldst.w = dst->w;
589  fulldst.h = dst->h;
590  dstrect = &fulldst;
591  }
592 
593  /* clip the source rectangle to the source surface */
594  if (srcrect) {
595  int maxw, maxh;
596 
597  srcx = srcrect->x;
598  w = srcrect->w;
599  if (srcx < 0) {
600  w += srcx;
601  dstrect->x -= srcx;
602  srcx = 0;
603  }
604  maxw = src->w - srcx;
605  if (maxw < w)
606  w = maxw;
607 
608  srcy = srcrect->y;
609  h = srcrect->h;
610  if (srcy < 0) {
611  h += srcy;
612  dstrect->y -= srcy;
613  srcy = 0;
614  }
615  maxh = src->h - srcy;
616  if (maxh < h)
617  h = maxh;
618 
619  } else {
620  srcx = srcy = 0;
621  w = src->w;
622  h = src->h;
623  }
624 
625  /* clip the destination rectangle against the clip rectangle */
626  {
627  SDL_Rect *clip = &dst->clip_rect;
628  int dx, dy;
629 
630  dx = clip->x - dstrect->x;
631  if (dx > 0) {
632  w -= dx;
633  dstrect->x += dx;
634  srcx += dx;
635  }
636  dx = dstrect->x + w - clip->x - clip->w;
637  if (dx > 0)
638  w -= dx;
639 
640  dy = clip->y - dstrect->y;
641  if (dy > 0) {
642  h -= dy;
643  dstrect->y += dy;
644  srcy += dy;
645  }
646  dy = dstrect->y + h - clip->y - clip->h;
647  if (dy > 0)
648  h -= dy;
649  }
650 
651  /* Switch back to a fast blit if we were previously stretching */
652  if (src->map->info.flags & SDL_COPY_NEAREST) {
653  src->map->info.flags &= ~SDL_COPY_NEAREST;
654  SDL_InvalidateMap(src->map);
655  }
656 
657  if (w > 0 && h > 0) {
658  SDL_Rect sr;
659  sr.x = srcx;
660  sr.y = srcy;
661  sr.w = dstrect->w = w;
662  sr.h = dstrect->h = h;
663  return SDL_LowerBlit(src, &sr, dst, dstrect);
664  }
665  dstrect->w = dstrect->h = 0;
666  return 0;
667 }
668 
669 int
671  SDL_Surface * dst, SDL_Rect * dstrect)
672 {
673  double src_x0, src_y0, src_x1, src_y1;
674  double dst_x0, dst_y0, dst_x1, dst_y1;
675  SDL_Rect final_src, final_dst;
676  double scaling_w, scaling_h;
677  int src_w, src_h;
678  int dst_w, dst_h;
679 
680  /* Make sure the surfaces aren't locked */
681  if (!src || !dst) {
682  return SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface");
683  }
684  if (src->locked || dst->locked) {
685  return SDL_SetError("Surfaces must not be locked during blit");
686  }
687 
688  if (NULL == srcrect) {
689  src_w = src->w;
690  src_h = src->h;
691  } else {
692  src_w = srcrect->w;
693  src_h = srcrect->h;
694  }
695 
696  if (NULL == dstrect) {
697  dst_w = dst->w;
698  dst_h = dst->h;
699  } else {
700  dst_w = dstrect->w;
701  dst_h = dstrect->h;
702  }
703 
704  if (dst_w == src_w && dst_h == src_h) {
705  /* No scaling, defer to regular blit */
706  return SDL_BlitSurface(src, srcrect, dst, dstrect);
707  }
708 
709  scaling_w = (double)dst_w / src_w;
710  scaling_h = (double)dst_h / src_h;
711 
712  if (NULL == dstrect) {
713  dst_x0 = 0;
714  dst_y0 = 0;
715  dst_x1 = dst_w - 1;
716  dst_y1 = dst_h - 1;
717  } else {
718  dst_x0 = dstrect->x;
719  dst_y0 = dstrect->y;
720  dst_x1 = dst_x0 + dst_w - 1;
721  dst_y1 = dst_y0 + dst_h - 1;
722  }
723 
724  if (NULL == srcrect) {
725  src_x0 = 0;
726  src_y0 = 0;
727  src_x1 = src_w - 1;
728  src_y1 = src_h - 1;
729  } else {
730  src_x0 = srcrect->x;
731  src_y0 = srcrect->y;
732  src_x1 = src_x0 + src_w - 1;
733  src_y1 = src_y0 + src_h - 1;
734 
735  /* Clip source rectangle to the source surface */
736 
737  if (src_x0 < 0) {
738  dst_x0 -= src_x0 * scaling_w;
739  src_x0 = 0;
740  }
741 
742  if (src_x1 >= src->w) {
743  dst_x1 -= (src_x1 - src->w + 1) * scaling_w;
744  src_x1 = src->w - 1;
745  }
746 
747  if (src_y0 < 0) {
748  dst_y0 -= src_y0 * scaling_h;
749  src_y0 = 0;
750  }
751 
752  if (src_y1 >= src->h) {
753  dst_y1 -= (src_y1 - src->h + 1) * scaling_h;
754  src_y1 = src->h - 1;
755  }
756  }
757 
758  /* Clip destination rectangle to the clip rectangle */
759 
760  /* Translate to clip space for easier calculations */
761  dst_x0 -= dst->clip_rect.x;
762  dst_x1 -= dst->clip_rect.x;
763  dst_y0 -= dst->clip_rect.y;
764  dst_y1 -= dst->clip_rect.y;
765 
766  if (dst_x0 < 0) {
767  src_x0 -= dst_x0 / scaling_w;
768  dst_x0 = 0;
769  }
770 
771  if (dst_x1 >= dst->clip_rect.w) {
772  src_x1 -= (dst_x1 - dst->clip_rect.w + 1) / scaling_w;
773  dst_x1 = dst->clip_rect.w - 1;
774  }
775 
776  if (dst_y0 < 0) {
777  src_y0 -= dst_y0 / scaling_h;
778  dst_y0 = 0;
779  }
780 
781  if (dst_y1 >= dst->clip_rect.h) {
782  src_y1 -= (dst_y1 - dst->clip_rect.h + 1) / scaling_h;
783  dst_y1 = dst->clip_rect.h - 1;
784  }
785 
786  /* Translate back to surface coordinates */
787  dst_x0 += dst->clip_rect.x;
788  dst_x1 += dst->clip_rect.x;
789  dst_y0 += dst->clip_rect.y;
790  dst_y1 += dst->clip_rect.y;
791 
792  final_src.x = (int)SDL_floor(src_x0 + 0.5);
793  final_src.y = (int)SDL_floor(src_y0 + 0.5);
794  final_src.w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5);
795  final_src.h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5);
796 
797  final_dst.x = (int)SDL_floor(dst_x0 + 0.5);
798  final_dst.y = (int)SDL_floor(dst_y0 + 0.5);
799  final_dst.w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5);
800  final_dst.h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5);
801 
802  if (final_dst.w < 0)
803  final_dst.w = 0;
804  if (final_dst.h < 0)
805  final_dst.h = 0;
806 
807  if (dstrect)
808  *dstrect = final_dst;
809 
810  if (final_dst.w == 0 || final_dst.h == 0 ||
811  final_src.w <= 0 || final_src.h <= 0) {
812  /* No-op. */
813  return 0;
814  }
815 
816  return SDL_LowerBlitScaled(src, &final_src, dst, &final_dst);
817 }
818 
819 /**
820  * This is a semi-private blit function and it performs low-level surface
821  * scaled blitting only.
822  */
823 int
825  SDL_Surface * dst, SDL_Rect * dstrect)
826 {
827  static const Uint32 complex_copy_flags = (
831  );
832 
833  if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
834  src->map->info.flags |= SDL_COPY_NEAREST;
835  SDL_InvalidateMap(src->map);
836  }
837 
838  if ( !(src->map->info.flags & complex_copy_flags) &&
839  src->format->format == dst->format->format &&
841  return SDL_SoftStretch( src, srcrect, dst, dstrect );
842  } else {
843  return SDL_LowerBlit( src, srcrect, dst, dstrect );
844  }
845 }
846 
847 /*
848  * Lock a surface to directly access the pixels
849  */
850 int
852 {
853  if (!surface->locked) {
854  /* Perform the lock */
855  if (surface->flags & SDL_RLEACCEL) {
856  SDL_UnRLESurface(surface, 1);
857  surface->flags |= SDL_RLEACCEL; /* save accel'd state */
858  }
859  }
860 
861  /* Increment the surface lock count, for recursive locks */
862  ++surface->locked;
863 
864  /* Ready to go.. */
865  return (0);
866 }
867 
868 /*
869  * Unlock a previously locked surface
870  */
871 void
873 {
874  /* Only perform an unlock if we are locked */
875  if (!surface->locked || (--surface->locked > 0)) {
876  return;
877  }
878 
879  /* Update RLE encoded surface with new data */
880  if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
881  surface->flags &= ~SDL_RLEACCEL; /* stop lying */
882  SDL_RLESurface(surface);
883  }
884 }
885 
886 /*
887  * Creates a new surface identical to the existing surface
888  */
889 SDL_Surface *
891 {
892  return SDL_ConvertSurface(surface, surface->format, surface->flags);
893 }
894 
895 /*
896  * Convert a surface into the specified pixel format.
897  */
898 SDL_Surface *
900  Uint32 flags)
901 {
902  SDL_Surface *convert;
903  Uint32 copy_flags;
904  SDL_Color copy_color;
905  SDL_Rect bounds;
906 
907  if (!surface) {
908  SDL_InvalidParamError("surface");
909  return NULL;
910  }
911  if (!format) {
912  SDL_InvalidParamError("format");
913  return NULL;
914  }
915 
916  /* Check for empty destination palette! (results in empty image) */
917  if (format->palette != NULL) {
918  int i;
919  for (i = 0; i < format->palette->ncolors; ++i) {
920  if ((format->palette->colors[i].r != 0xFF) ||
921  (format->palette->colors[i].g != 0xFF) ||
922  (format->palette->colors[i].b != 0xFF))
923  break;
924  }
925  if (i == format->palette->ncolors) {
926  SDL_SetError("Empty destination palette");
927  return (NULL);
928  }
929  }
930 
931  /* Create a new surface with the desired format */
932  convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
933  format->BitsPerPixel, format->Rmask,
934  format->Gmask, format->Bmask,
935  format->Amask);
936  if (convert == NULL) {
937  return (NULL);
938  }
939 
940  /* Copy the palette if any */
941  if (format->palette && convert->format->palette) {
942  SDL_memcpy(convert->format->palette->colors,
943  format->palette->colors,
944  format->palette->ncolors * sizeof(SDL_Color));
945  convert->format->palette->ncolors = format->palette->ncolors;
946  }
947 
948  /* Save the original copy flags */
949  copy_flags = surface->map->info.flags;
950  copy_color.r = surface->map->info.r;
951  copy_color.g = surface->map->info.g;
952  copy_color.b = surface->map->info.b;
953  copy_color.a = surface->map->info.a;
954  surface->map->info.r = 0xFF;
955  surface->map->info.g = 0xFF;
956  surface->map->info.b = 0xFF;
957  surface->map->info.a = 0xFF;
958  surface->map->info.flags = 0;
959  SDL_InvalidateMap(surface->map);
960 
961  /* Copy over the image data */
962  bounds.x = 0;
963  bounds.y = 0;
964  bounds.w = surface->w;
965  bounds.h = surface->h;
966  SDL_LowerBlit(surface, &bounds, convert, &bounds);
967 
968  /* Clean up the original surface, and update converted surface */
969  convert->map->info.r = copy_color.r;
970  convert->map->info.g = copy_color.g;
971  convert->map->info.b = copy_color.b;
972  convert->map->info.a = copy_color.a;
973  convert->map->info.flags =
974  (copy_flags &
978  surface->map->info.r = copy_color.r;
979  surface->map->info.g = copy_color.g;
980  surface->map->info.b = copy_color.b;
981  surface->map->info.a = copy_color.a;
982  surface->map->info.flags = copy_flags;
983  SDL_InvalidateMap(surface->map);
984  if (copy_flags & SDL_COPY_COLORKEY) {
985  SDL_bool set_colorkey_by_color = SDL_FALSE;
986 
987  if (surface->format->palette) {
988  if (format->palette &&
989  surface->format->palette->ncolors <= format->palette->ncolors &&
990  (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
991  surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
992  /* The palette is identical, just set the same colorkey */
993  SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
994  } else if (format->Amask) {
995  /* The alpha was set in the destination from the palette */
996  } else {
997  set_colorkey_by_color = SDL_TRUE;
998  }
999  } else {
1000  set_colorkey_by_color = SDL_TRUE;
1001  }
1002 
1003  if (set_colorkey_by_color) {
1004  SDL_Surface *tmp;
1005  SDL_Surface *tmp2;
1006  int converted_colorkey = 0;
1007 
1008  /* Create a dummy surface to get the colorkey converted */
1009  tmp = SDL_CreateRGBSurface(0, 1, 1,
1010  surface->format->BitsPerPixel, surface->format->Rmask,
1011  surface->format->Gmask, surface->format->Bmask,
1012  surface->format->Amask);
1013 
1014  /* Share the palette, if any */
1015  if (surface->format->palette) {
1016  SDL_SetSurfacePalette(tmp, surface->format->palette);
1017  }
1018 
1019  SDL_FillRect(tmp, NULL, surface->map->info.colorkey);
1020 
1021  tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
1022 
1023  /* Convertion of the colorkey */
1024  tmp2 = SDL_ConvertSurface(tmp, format, 0);
1025 
1026  /* Get the converted colorkey */
1027  SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);
1028 
1029  SDL_FreeSurface(tmp);
1030  SDL_FreeSurface(tmp2);
1031 
1032  /* Set the converted colorkey on the new surface */
1033  SDL_SetColorKey(convert, 1, converted_colorkey);
1034 
1035  /* This is needed when converting for 3D texture upload */
1036  SDL_ConvertColorkeyToAlpha(convert);
1037  }
1038  }
1039  SDL_SetClipRect(convert, &surface->clip_rect);
1040 
1041  /* Enable alpha blending by default if the new surface has an
1042  * alpha channel or alpha modulation */
1043  if ((surface->format->Amask && format->Amask) ||
1044  (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
1046  }
1047  if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
1048  SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
1049  }
1050 
1051  /* We're ready to go! */
1052  return (convert);
1053 }
1054 
1055 SDL_Surface *
1057  Uint32 flags)
1058 {
1059  SDL_PixelFormat *fmt;
1060  SDL_Surface *convert = NULL;
1061 
1062  fmt = SDL_AllocFormat(pixel_format);
1063  if (fmt) {
1064  convert = SDL_ConvertSurface(surface, fmt, flags);
1065  SDL_FreeFormat(fmt);
1066  }
1067  return convert;
1068 }
1069 
1070 /*
1071  * Create a surface on the stack for quick blit operations
1072  */
1073 static SDL_INLINE SDL_bool
1075  void * pixels, int pitch, SDL_Surface * surface,
1076  SDL_PixelFormat * format, SDL_BlitMap * blitmap)
1077 {
1078  if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
1079  SDL_SetError("Indexed pixel formats not supported");
1080  return SDL_FALSE;
1081  }
1082  if (SDL_InitFormat(format, pixel_format) < 0) {
1083  return SDL_FALSE;
1084  }
1085 
1086  SDL_zerop(surface);
1087  surface->flags = SDL_PREALLOC;
1088  surface->format = format;
1089  surface->pixels = pixels;
1090  surface->w = width;
1091  surface->h = height;
1092  surface->pitch = pitch;
1093  /* We don't actually need to set up the clip rect for our purposes */
1094  /* SDL_SetClipRect(surface, NULL); */
1095 
1096  /* Allocate an empty mapping */
1097  SDL_zerop(blitmap);
1098  blitmap->info.r = 0xFF;
1099  blitmap->info.g = 0xFF;
1100  blitmap->info.b = 0xFF;
1101  blitmap->info.a = 0xFF;
1102  surface->map = blitmap;
1103 
1104  /* The surface is ready to go */
1105  surface->refcount = 1;
1106  return SDL_TRUE;
1107 }
1108 
1109 /*
1110  * Copy a block of pixels of one format to another format
1111  */
1113  Uint32 src_format, const void * src, int src_pitch,
1114  Uint32 dst_format, void * dst, int dst_pitch)
1115 {
1116  SDL_Surface src_surface, dst_surface;
1117  SDL_PixelFormat src_fmt, dst_fmt;
1118  SDL_BlitMap src_blitmap, dst_blitmap;
1119  SDL_Rect rect;
1120  void *nonconst_src = (void *) src;
1121 
1122  /* Check to make sure we are blitting somewhere, so we don't crash */
1123  if (!dst) {
1124  return SDL_InvalidParamError("dst");
1125  }
1126  if (!dst_pitch) {
1127  return SDL_InvalidParamError("dst_pitch");
1128  }
1129 
1130  /* Fast path for same format copy */
1131  if (src_format == dst_format) {
1132  int bpp, i;
1133 
1134  if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
1135  switch (src_format) {
1136  case SDL_PIXELFORMAT_YUY2:
1137  case SDL_PIXELFORMAT_UYVY:
1138  case SDL_PIXELFORMAT_YVYU:
1139  bpp = 2;
1140  break;
1141  case SDL_PIXELFORMAT_YV12:
1142  case SDL_PIXELFORMAT_IYUV:
1143  case SDL_PIXELFORMAT_NV12:
1144  case SDL_PIXELFORMAT_NV21:
1145  bpp = 1;
1146  break;
1147  default:
1148  return SDL_SetError("Unknown FOURCC pixel format");
1149  }
1150  } else {
1151  bpp = SDL_BYTESPERPIXEL(src_format);
1152  }
1153  width *= bpp;
1154 
1155  for (i = height; i--;) {
1156  SDL_memcpy(dst, src, width);
1157  src = (Uint8*)src + src_pitch;
1158  dst = (Uint8*)dst + dst_pitch;
1159  }
1160 
1161  if (src_format == SDL_PIXELFORMAT_YV12 || src_format == SDL_PIXELFORMAT_IYUV) {
1162  /* U and V planes are a quarter the size of the Y plane */
1163  width /= 2;
1164  height /= 2;
1165  src_pitch /= 2;
1166  dst_pitch /= 2;
1167  for (i = height * 2; i--;) {
1168  SDL_memcpy(dst, src, width);
1169  src = (Uint8*)src + src_pitch;
1170  dst = (Uint8*)dst + dst_pitch;
1171  }
1172  } else if (src_format == SDL_PIXELFORMAT_NV12 || src_format == SDL_PIXELFORMAT_NV21) {
1173  /* U/V plane is half the height of the Y plane */
1174  height /= 2;
1175  for (i = height; i--;) {
1176  SDL_memcpy(dst, src, width);
1177  src = (Uint8*)src + src_pitch;
1178  dst = (Uint8*)dst + dst_pitch;
1179  }
1180  }
1181  return 0;
1182  }
1183 
1184  if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
1185  src_pitch,
1186  &src_surface, &src_fmt, &src_blitmap)) {
1187  return -1;
1188  }
1189  if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
1190  &dst_surface, &dst_fmt, &dst_blitmap)) {
1191  return -1;
1192  }
1193 
1194  /* Set up the rect and go! */
1195  rect.x = 0;
1196  rect.y = 0;
1197  rect.w = width;
1198  rect.h = height;
1199  return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
1200 }
1201 
1202 /*
1203  * Free a surface created by the above function.
1204  */
1205 void
1207 {
1208  if (surface == NULL) {
1209  return;
1210  }
1211  if (surface->flags & SDL_DONTFREE) {
1212  return;
1213  }
1214  if (surface->map != NULL) {
1215  SDL_FreeBlitMap(surface->map);
1216  surface->map = NULL;
1217  }
1218  if (--surface->refcount > 0) {
1219  return;
1220  }
1221  while (surface->locked > 0) {
1222  SDL_UnlockSurface(surface);
1223  }
1224  if (surface->flags & SDL_RLEACCEL) {
1225  SDL_UnRLESurface(surface, 0);
1226  }
1227  if (surface->format) {
1228  SDL_SetSurfacePalette(surface, NULL);
1229  SDL_FreeFormat(surface->format);
1230  surface->format = NULL;
1231  }
1232  if (!(surface->flags & SDL_PREALLOC)) {
1233  SDL_free(surface->pixels);
1234  }
1235  SDL_free(surface);
1236 }
1237 
1238 /* vi: set ts=4 sw=4 expandtab: */
int SDL_GetColorKey(SDL_Surface *surface, Uint32 *key)
Gets the color key (transparent pixel) in a blittable surface.
Definition: SDL_surface.c:270
Uint8 r
Definition: SDL_blit.h:70
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
void SDL_UnlockSurface(SDL_Surface *surface)
Definition: SDL_surface.c:872
Uint32 version
Definition: SDL_pixels.h:306
Uint8 b
Definition: SDL_blit.h:70
SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
Definition: SDL_surface.c:505
#define SDL_COPY_COLORKEY
Definition: SDL_blit.h:39
SDL_blit blit
Definition: SDL_blit.h:90
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
Sets the RLE acceleration hint for a surface.
Definition: SDL_surface.c:204
Uint8 g
Definition: SDL_pixels.h:296
GLenum GLenum dst
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
#define SDL_SoftStretch
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
int SDL_LockSurface(SDL_Surface *surface)
Sets up a surface for directly accessing the pixels.
Definition: SDL_surface.c:851
SDL_Surface * SDL_ConvertSurfaceFormat(SDL_Surface *surface, Uint32 pixel_format, Uint32 flags)
Definition: SDL_surface.c:1056
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
Uint8 BytesPerPixel
Definition: SDL_pixels.h:318
SDL_Rect rect
Definition: testrelative.c:27
Uint8 g
Definition: SDL_blit.h:70
#define SDL_MasksToPixelFormatEnum
SDL_Surface * SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format, Uint32 flags)
Definition: SDL_surface.c:899
GLfloat GLfloat GLfloat GLfloat h
static SDL_INLINE SDL_bool SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format, void *pixels, int pitch, SDL_Surface *surface, SDL_PixelFormat *format, SDL_BlitMap *blitmap)
Definition: SDL_surface.c:1074
#define SDL_COPY_MOD
Definition: SDL_blit.h:38
EGLSurface surface
Definition: eglext.h:248
int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value used in blit operations.
Definition: SDL_surface.c:358
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
Definition: SDL_surface.c:403
#define SDL_DONTFREE
Definition: SDL_surface.h:55
int SDL_UpperBlitScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:670
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL_surface.c:439
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
#define SDL_BlitSurface
Definition: SDL_surface.h:465
static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface)
Definition: SDL_surface.c:288
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
Uint32 dst_palette_version
Definition: SDL_blit.h:96
Uint8 b
Definition: SDL_pixels.h:297
SDL_Surface * SDL_DuplicateSurface(SDL_Surface *surface)
Definition: SDL_surface.c:890
#define SDL_AllocFormat
#define SDL_COPY_RLE_COLORKEY
Definition: SDL_blit.h:42
#define SDL_MAX_SINT32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:173
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
GLenum src
#define SDL_IntersectRect
#define SDL_floor
int SDL_LowerBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:548
#define SDL_zerop(x)
Definition: SDL_stdinc.h:386
int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key)
Sets the color key (transparent pixel) in a blittable surface.
Definition: SDL_surface.c:225
int SDL_UpperBlit(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:571
GLfloat GLfloat GLfloat alpha
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
#define SDL_COPY_ADD
Definition: SDL_blit.h:37
Uint32 colorkey
Definition: SDL_blit.h:69
Uint32 flags
Definition: SDL_surface.h:71
void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
Definition: SDL_surface.c:529
Uint32 src_palette_version
Definition: SDL_blit.h:97
#define SDL_COPY_RLE_DESIRED
Definition: SDL_blit.h:41
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
void SDL_InvalidateMap(SDL_BlitMap *map)
Definition: SDL_pixels.c:981
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define SDL_COPY_NEAREST
Definition: SDL_blit.h:40
#define SDL_ALPHA_TRANSPARENT
Definition: SDL_pixels.h:47
SDL_Surface * SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
Definition: SDL_surface.c:40
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
#define SDL_memcpy
void * SDL_calloc(size_t nmemb, size_t size)
GLuint64 key
Definition: gl2ext.h:2192
Uint8 r
Definition: SDL_pixels.h:295
SDL_COMPILE_TIME_ASSERT(surface_size_assumptions, sizeof(int)==sizeof(Sint32) &&sizeof(size_t) >=sizeof(Sint32))
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
Definition: SDL_pixels.c:1000
void * pixels
Definition: SDL_surface.h:75
Uint8 a
Definition: SDL_pixels.h:298
uint8_t Uint8
Definition: SDL_stdinc.h:157
Uint8 BitsPerPixel
Definition: SDL_pixels.h:317
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
Set the palette used by a surface.
Definition: SDL_surface.c:190
void SDL_free(void *mem)
int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
Get the blend mode used for blit operations.
Definition: SDL_surface.c:476
int SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Copy a block of pixels of one format to another format.
Definition: SDL_surface.c:1112
#define SDL_FreeFormat
#define SDL_memcmp
GLenum GLint GLuint mask
GLubyte GLubyte GLubyte GLubyte w
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_Surface * SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format)
Definition: SDL_surface.c:171
int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
Get the additional alpha value used in blit operations.
Definition: SDL_surface.c:426
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
int32_t Sint32
Definition: SDL_stdinc.h:175
int w
Definition: SDL_rect.h:67
GLsizeiptr size
#define SDL_AllocPalette
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
Definition: SDL_pixels.c:528
SDL_Rect clip_rect
Definition: SDL_surface.h:85
void SDL_FreeSurface(SDL_Surface *surface)
Definition: SDL_surface.c:1206
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
int SDL_RLESurface(SDL_Surface *surface)
SDL_Surface * dst
Definition: SDL_blit.h:88
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
Definition: SDL_stdinc.h:139
SDL_Color * colors
Definition: SDL_pixels.h:305
SDL_PixelFormat * format
Definition: SDL_surface.h:72
GLint GLint GLsizei GLsizei GLsizei depth
Definition: SDL_opengl.h:1572
#define SDL_FreePalette
#define SDL_SetError
SDL_Surface * SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
Definition: SDL_surface.c:127
GLbitfield flags
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
#define SDL_COPY_MODULATE_ALPHA
Definition: SDL_blit.h:35
int h
Definition: SDL_rect.h:67
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
#define SDL_COPY_RLE_ALPHAKEY
Definition: SDL_blit.h:43
#define SDL_FillRect
int SDL_LowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:824
SDL_BlitMap * SDL_AllocBlitMap(void)
Definition: SDL_pixels.c:961
uint16_t Uint16
Definition: SDL_stdinc.h:169
Uint32 pixel_format
Definition: testoverlay2.c:152
#define SDL_INLINE
Definition: begin_code.h:131
int SDL_CalculatePitch(SDL_Surface *surface)
Definition: SDL_pixels.c:755
#define SDL_malloc
SDL_Palette * palette
Definition: SDL_pixels.h:316
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
SDL_Surface * SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
Definition: SDL_surface.c:147
int64_t Sint64
Definition: SDL_stdinc.h:188
#define SDL_ALPHA_OPAQUE
Definition: SDL_pixels.h:46
GLboolean GLboolean g
GLboolean GLboolean GLboolean b
void SDL_FreeBlitMap(SDL_BlitMap *map)
Definition: SDL_pixels.c:1086
int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
Get the additional color value used in blit operations.
Definition: SDL_surface.c:384
GLenum GLenum void * row
int y
Definition: SDL_rect.h:66
#define SDL_SetPixelFormatPalette
#define SDL_Unsupported()
Definition: SDL_error.h:53
#define SDL_COPY_BLEND
Definition: SDL_blit.h:36
SDL_BlitInfo info
Definition: SDL_blit.h:92
#define SDL_memset
#define SDL_PREALLOC
Definition: SDL_surface.h:53
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
Uint8 a
Definition: SDL_blit.h:70