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 /* Private routines */
30 static int
32  Uint32 src_format, const void *src,
33  void *dst, int dst_pitch);
34 
35 static int
37  const void *src, int src_pitch,
38  Uint32 dst_format, void *dst);
39 
40 /* Check to make sure we can safely check multiplication of surface w and pitch and it won't overflow size_t */
41 SDL_COMPILE_TIME_ASSERT(surface_size_assumptions,
42  sizeof(int) == sizeof(Sint32) && sizeof(size_t) >= sizeof(Sint32));
43 
44 /* Public routines */
45 
46 /*
47  * Create an empty RGB surface of the appropriate depth using the given
48  * enum SDL_PIXELFORMAT_* format
49  */
52  Uint32 format)
53 {
55 
56  /* The flags are no longer used, make the compiler happy */
57  (void)flags;
58 
59  /* Allocate the surface */
60  surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
61  if (surface == NULL) {
63  return NULL;
64  }
65 
66  surface->format = SDL_AllocFormat(format);
67  if (!surface->format) {
68  SDL_FreeSurface(surface);
69  return NULL;
70  }
71  surface->w = width;
72  surface->h = height;
73  surface->pitch = SDL_CalculatePitch(surface);
74  SDL_SetClipRect(surface, NULL);
75 
76  if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
77  SDL_Palette *palette =
78  SDL_AllocPalette((1 << surface->format->BitsPerPixel));
79  if (!palette) {
80  SDL_FreeSurface(surface);
81  return NULL;
82  }
83  if (palette->ncolors == 2) {
84  /* Create a black and white bitmap palette */
85  palette->colors[0].r = 0xFF;
86  palette->colors[0].g = 0xFF;
87  palette->colors[0].b = 0xFF;
88  palette->colors[1].r = 0x00;
89  palette->colors[1].g = 0x00;
90  palette->colors[1].b = 0x00;
91  }
92  SDL_SetSurfacePalette(surface, palette);
93  SDL_FreePalette(palette);
94  }
95 
96  /* Get the pixels */
97  if (surface->w && surface->h) {
98  /* Assumptions checked in surface_size_assumptions assert above */
99  Sint64 size = ((Sint64)surface->h * surface->pitch);
101  /* Overflow... */
102  SDL_FreeSurface(surface);
103  SDL_OutOfMemory();
104  return NULL;
105  }
106 
107  surface->pixels = SDL_malloc((size_t)size);
108  if (!surface->pixels) {
109  SDL_FreeSurface(surface);
110  SDL_OutOfMemory();
111  return NULL;
112  }
113  /* This is important for bitmaps */
114  SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
115  }
116 
117  /* Allocate an empty mapping */
118  surface->map = SDL_AllocBlitMap();
119  if (!surface->map) {
120  SDL_FreeSurface(surface);
121  return NULL;
122  }
123 
124  /* By default surface with an alpha mask are set up for blending */
125  if (surface->format->Amask) {
127  }
128 
129  /* The surface is ready to go */
130  surface->refcount = 1;
131  return surface;
132 }
133 
134 /*
135  * Create an empty RGB surface of the appropriate depth
136  */
137 SDL_Surface *
139  int width, int height, int depth,
140  Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
141 {
142  Uint32 format;
143 
144  /* Get the pixel format */
145  format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
146  if (format == SDL_PIXELFORMAT_UNKNOWN) {
147  SDL_SetError("Unknown pixel format");
148  return NULL;
149  }
150 
151  return SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format);
152 }
153 
154 /*
155  * Create an RGB surface from an existing memory buffer
156  */
157 SDL_Surface *
159  int width, int height, int depth, int pitch,
160  Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
161  Uint32 Amask)
162 {
164 
165  surface = SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
166  if (surface != NULL) {
167  surface->flags |= SDL_PREALLOC;
168  surface->pixels = pixels;
169  surface->w = width;
170  surface->h = height;
171  surface->pitch = pitch;
172  SDL_SetClipRect(surface, NULL);
173  }
174  return surface;
175 }
176 
177 /*
178  * Create an RGB surface from an existing memory buffer using the given given
179  * enum SDL_PIXELFORMAT_* format
180  */
181 SDL_Surface *
183  int width, int height, int depth, int pitch,
184  Uint32 format)
185 {
187 
188  surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, format);
189  if (surface != NULL) {
190  surface->flags |= SDL_PREALLOC;
191  surface->pixels = pixels;
192  surface->w = width;
193  surface->h = height;
194  surface->pitch = pitch;
195  SDL_SetClipRect(surface, NULL);
196  }
197  return surface;
198 }
199 
200 int
202 {
203  if (!surface) {
204  return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
205  }
206  if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
207  return -1;
208  }
209  SDL_InvalidateMap(surface->map);
210 
211  return 0;
212 }
213 
214 int
216 {
217  int flags;
218 
219  if (!surface) {
220  return -1;
221  }
222 
223  flags = surface->map->info.flags;
224  if (flag) {
225  surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
226  } else {
227  surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
228  }
229  if (surface->map->info.flags != flags) {
230  SDL_InvalidateMap(surface->map);
231  }
232  return 0;
233 }
234 
235 int
237 {
238  int flags;
239 
240  if (!surface) {
241  return SDL_InvalidParamError("surface");
242  }
243 
244  if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
245  return SDL_InvalidParamError("key");
246  }
247 
248  if (flag & SDL_RLEACCEL) {
249  SDL_SetSurfaceRLE(surface, 1);
250  }
251 
252  flags = surface->map->info.flags;
253  if (flag) {
254  surface->map->info.flags |= SDL_COPY_COLORKEY;
255  surface->map->info.colorkey = key;
256  if (surface->format->palette) {
257  surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
258  ++surface->format->palette->version;
259  if (!surface->format->palette->version) {
260  surface->format->palette->version = 1;
261  }
262  }
263  } else {
264  if (surface->format->palette) {
265  surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE;
266  ++surface->format->palette->version;
267  if (!surface->format->palette->version) {
268  surface->format->palette->version = 1;
269  }
270  }
271  surface->map->info.flags &= ~SDL_COPY_COLORKEY;
272  }
273  if (surface->map->info.flags != flags) {
274  SDL_InvalidateMap(surface->map);
275  }
276 
277  return 0;
278 }
279 
280 int
282 {
283  if (!surface) {
284  return -1;
285  }
286 
287  if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
288  return -1;
289  }
290 
291  if (key) {
292  *key = surface->map->info.colorkey;
293  }
294  return 0;
295 }
296 
297 /* This is a fairly slow function to switch from colorkey to alpha */
298 static void
300 {
301  int x, y;
302 
303  if (!surface) {
304  return;
305  }
306 
307  if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
308  !surface->format->Amask) {
309  return;
310  }
311 
312  SDL_LockSurface(surface);
313 
314  switch (surface->format->BytesPerPixel) {
315  case 2:
316  {
317  Uint16 *row, *spot;
318  Uint16 ckey = (Uint16) surface->map->info.colorkey;
319  Uint16 mask = (Uint16) (~surface->format->Amask);
320 
321  /* Ignore alpha in colorkey comparison */
322  ckey &= mask;
323  row = (Uint16 *) surface->pixels;
324  for (y = surface->h; y--;) {
325  spot = row;
326  for (x = surface->w; x--;) {
327  if ((*spot & mask) == ckey) {
328  *spot &= mask;
329  }
330  ++spot;
331  }
332  row += surface->pitch / 2;
333  }
334  }
335  break;
336  case 3:
337  /* FIXME */
338  break;
339  case 4:
340  {
341  Uint32 *row, *spot;
342  Uint32 ckey = surface->map->info.colorkey;
343  Uint32 mask = ~surface->format->Amask;
344 
345  /* Ignore alpha in colorkey comparison */
346  ckey &= mask;
347  row = (Uint32 *) surface->pixels;
348  for (y = surface->h; y--;) {
349  spot = row;
350  for (x = surface->w; x--;) {
351  if ((*spot & mask) == ckey) {
352  *spot &= mask;
353  }
354  ++spot;
355  }
356  row += surface->pitch / 4;
357  }
358  }
359  break;
360  }
361 
362  SDL_UnlockSurface(surface);
363 
364  SDL_SetColorKey(surface, 0, 0);
366 }
367 
368 int
370 {
371  int flags;
372 
373  if (!surface) {
374  return -1;
375  }
376 
377  surface->map->info.r = r;
378  surface->map->info.g = g;
379  surface->map->info.b = b;
380 
381  flags = surface->map->info.flags;
382  if (r != 0xFF || g != 0xFF || b != 0xFF) {
383  surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
384  } else {
385  surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
386  }
387  if (surface->map->info.flags != flags) {
388  SDL_InvalidateMap(surface->map);
389  }
390  return 0;
391 }
392 
393 
394 int
396 {
397  if (!surface) {
398  return -1;
399  }
400 
401  if (r) {
402  *r = surface->map->info.r;
403  }
404  if (g) {
405  *g = surface->map->info.g;
406  }
407  if (b) {
408  *b = surface->map->info.b;
409  }
410  return 0;
411 }
412 
413 int
415 {
416  int flags;
417 
418  if (!surface) {
419  return -1;
420  }
421 
422  surface->map->info.a = alpha;
423 
424  flags = surface->map->info.flags;
425  if (alpha != 0xFF) {
426  surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
427  } else {
428  surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
429  }
430  if (surface->map->info.flags != flags) {
431  SDL_InvalidateMap(surface->map);
432  }
433  return 0;
434 }
435 
436 int
438 {
439  if (!surface) {
440  return -1;
441  }
442 
443  if (alpha) {
444  *alpha = surface->map->info.a;
445  }
446  return 0;
447 }
448 
449 int
451 {
452  int flags, status;
453 
454  if (!surface) {
455  return -1;
456  }
457 
458  status = 0;
459  flags = surface->map->info.flags;
460  surface->map->info.flags &=
462  switch (blendMode) {
463  case SDL_BLENDMODE_NONE:
464  break;
465  case SDL_BLENDMODE_BLEND:
466  surface->map->info.flags |= SDL_COPY_BLEND;
467  break;
468  case SDL_BLENDMODE_ADD:
469  surface->map->info.flags |= SDL_COPY_ADD;
470  break;
471  case SDL_BLENDMODE_MOD:
472  surface->map->info.flags |= SDL_COPY_MOD;
473  break;
474  default:
475  status = SDL_Unsupported();
476  break;
477  }
478 
479  if (surface->map->info.flags != flags) {
480  SDL_InvalidateMap(surface->map);
481  }
482 
483  return status;
484 }
485 
486 int
488 {
489  if (!surface) {
490  return -1;
491  }
492 
493  if (!blendMode) {
494  return 0;
495  }
496 
497  switch (surface->map->
498  info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)) {
499  case SDL_COPY_BLEND:
500  *blendMode = SDL_BLENDMODE_BLEND;
501  break;
502  case SDL_COPY_ADD:
503  *blendMode = SDL_BLENDMODE_ADD;
504  break;
505  case SDL_COPY_MOD:
506  *blendMode = SDL_BLENDMODE_MOD;
507  break;
508  default:
509  *blendMode = SDL_BLENDMODE_NONE;
510  break;
511  }
512  return 0;
513 }
514 
515 SDL_bool
517 {
518  SDL_Rect full_rect;
519 
520  /* Don't do anything if there's no surface to act on */
521  if (!surface) {
522  return SDL_FALSE;
523  }
524 
525  /* Set up the full surface rectangle */
526  full_rect.x = 0;
527  full_rect.y = 0;
528  full_rect.w = surface->w;
529  full_rect.h = surface->h;
530 
531  /* Set the clipping rectangle */
532  if (!rect) {
533  surface->clip_rect = full_rect;
534  return SDL_TRUE;
535  }
536  return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
537 }
538 
539 void
541 {
542  if (surface && rect) {
543  *rect = surface->clip_rect;
544  }
545 }
546 
547 /*
548  * Set up a blit between two surfaces -- split into three parts:
549  * The upper part, SDL_UpperBlit(), performs clipping and rectangle
550  * verification. The lower part is a pointer to a low level
551  * accelerated blitting function.
552  *
553  * These parts are separated out and each used internally by this
554  * library in the optimimum places. They are exported so that if
555  * you know exactly what you are doing, you can optimize your code
556  * by calling the one(s) you need.
557  */
558 int
560  SDL_Surface * dst, SDL_Rect * dstrect)
561 {
562  /* Check to make sure the blit mapping is valid */
563  if ((src->map->dst != dst) ||
564  (dst->format->palette &&
565  src->map->dst_palette_version != dst->format->palette->version) ||
566  (src->format->palette &&
567  src->map->src_palette_version != src->format->palette->version)) {
568  if (SDL_MapSurface(src, dst) < 0) {
569  return (-1);
570  }
571  /* just here for debugging */
572 /* printf */
573 /* ("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", */
574 /* src, dst->flags, src->map->info.flags, dst, dst->flags, */
575 /* dst->map->info.flags, src->map->blit); */
576  }
577  return (src->map->blit(src, srcrect, dst, dstrect));
578 }
579 
580 
581 int
583  SDL_Surface * dst, SDL_Rect * dstrect)
584 {
585  SDL_Rect fulldst;
586  int srcx, srcy, w, h;
587 
588  /* Make sure the surfaces aren't locked */
589  if (!src || !dst) {
590  return SDL_SetError("SDL_UpperBlit: passed a NULL surface");
591  }
592  if (src->locked || dst->locked) {
593  return SDL_SetError("Surfaces must not be locked during blit");
594  }
595 
596  /* If the destination rectangle is NULL, use the entire dest surface */
597  if (dstrect == NULL) {
598  fulldst.x = fulldst.y = 0;
599  fulldst.w = dst->w;
600  fulldst.h = dst->h;
601  dstrect = &fulldst;
602  }
603 
604  /* clip the source rectangle to the source surface */
605  if (srcrect) {
606  int maxw, maxh;
607 
608  srcx = srcrect->x;
609  w = srcrect->w;
610  if (srcx < 0) {
611  w += srcx;
612  dstrect->x -= srcx;
613  srcx = 0;
614  }
615  maxw = src->w - srcx;
616  if (maxw < w)
617  w = maxw;
618 
619  srcy = srcrect->y;
620  h = srcrect->h;
621  if (srcy < 0) {
622  h += srcy;
623  dstrect->y -= srcy;
624  srcy = 0;
625  }
626  maxh = src->h - srcy;
627  if (maxh < h)
628  h = maxh;
629 
630  } else {
631  srcx = srcy = 0;
632  w = src->w;
633  h = src->h;
634  }
635 
636  /* clip the destination rectangle against the clip rectangle */
637  {
638  SDL_Rect *clip = &dst->clip_rect;
639  int dx, dy;
640 
641  dx = clip->x - dstrect->x;
642  if (dx > 0) {
643  w -= dx;
644  dstrect->x += dx;
645  srcx += dx;
646  }
647  dx = dstrect->x + w - clip->x - clip->w;
648  if (dx > 0)
649  w -= dx;
650 
651  dy = clip->y - dstrect->y;
652  if (dy > 0) {
653  h -= dy;
654  dstrect->y += dy;
655  srcy += dy;
656  }
657  dy = dstrect->y + h - clip->y - clip->h;
658  if (dy > 0)
659  h -= dy;
660  }
661 
662  /* Switch back to a fast blit if we were previously stretching */
663  if (src->map->info.flags & SDL_COPY_NEAREST) {
664  src->map->info.flags &= ~SDL_COPY_NEAREST;
665  SDL_InvalidateMap(src->map);
666  }
667 
668  if (w > 0 && h > 0) {
669  SDL_Rect sr;
670  sr.x = srcx;
671  sr.y = srcy;
672  sr.w = dstrect->w = w;
673  sr.h = dstrect->h = h;
674  return SDL_LowerBlit(src, &sr, dst, dstrect);
675  }
676  dstrect->w = dstrect->h = 0;
677  return 0;
678 }
679 
680 int
682  SDL_Surface * dst, SDL_Rect * dstrect)
683 {
684  double src_x0, src_y0, src_x1, src_y1;
685  double dst_x0, dst_y0, dst_x1, dst_y1;
686  SDL_Rect final_src, final_dst;
687  double scaling_w, scaling_h;
688  int src_w, src_h;
689  int dst_w, dst_h;
690 
691  /* Make sure the surfaces aren't locked */
692  if (!src || !dst) {
693  return SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface");
694  }
695  if (src->locked || dst->locked) {
696  return SDL_SetError("Surfaces must not be locked during blit");
697  }
698 
699  if (NULL == srcrect) {
700  src_w = src->w;
701  src_h = src->h;
702  } else {
703  src_w = srcrect->w;
704  src_h = srcrect->h;
705  }
706 
707  if (NULL == dstrect) {
708  dst_w = dst->w;
709  dst_h = dst->h;
710  } else {
711  dst_w = dstrect->w;
712  dst_h = dstrect->h;
713  }
714 
715  if (dst_w == src_w && dst_h == src_h) {
716  /* No scaling, defer to regular blit */
717  return SDL_BlitSurface(src, srcrect, dst, dstrect);
718  }
719 
720  scaling_w = (double)dst_w / src_w;
721  scaling_h = (double)dst_h / src_h;
722 
723  if (NULL == dstrect) {
724  dst_x0 = 0;
725  dst_y0 = 0;
726  dst_x1 = dst_w - 1;
727  dst_y1 = dst_h - 1;
728  } else {
729  dst_x0 = dstrect->x;
730  dst_y0 = dstrect->y;
731  dst_x1 = dst_x0 + dst_w - 1;
732  dst_y1 = dst_y0 + dst_h - 1;
733  }
734 
735  if (NULL == srcrect) {
736  src_x0 = 0;
737  src_y0 = 0;
738  src_x1 = src_w - 1;
739  src_y1 = src_h - 1;
740  } else {
741  src_x0 = srcrect->x;
742  src_y0 = srcrect->y;
743  src_x1 = src_x0 + src_w - 1;
744  src_y1 = src_y0 + src_h - 1;
745 
746  /* Clip source rectangle to the source surface */
747 
748  if (src_x0 < 0) {
749  dst_x0 -= src_x0 * scaling_w;
750  src_x0 = 0;
751  }
752 
753  if (src_x1 >= src->w) {
754  dst_x1 -= (src_x1 - src->w + 1) * scaling_w;
755  src_x1 = src->w - 1;
756  }
757 
758  if (src_y0 < 0) {
759  dst_y0 -= src_y0 * scaling_h;
760  src_y0 = 0;
761  }
762 
763  if (src_y1 >= src->h) {
764  dst_y1 -= (src_y1 - src->h + 1) * scaling_h;
765  src_y1 = src->h - 1;
766  }
767  }
768 
769  /* Clip destination rectangle to the clip rectangle */
770 
771  /* Translate to clip space for easier calculations */
772  dst_x0 -= dst->clip_rect.x;
773  dst_x1 -= dst->clip_rect.x;
774  dst_y0 -= dst->clip_rect.y;
775  dst_y1 -= dst->clip_rect.y;
776 
777  if (dst_x0 < 0) {
778  src_x0 -= dst_x0 / scaling_w;
779  dst_x0 = 0;
780  }
781 
782  if (dst_x1 >= dst->clip_rect.w) {
783  src_x1 -= (dst_x1 - dst->clip_rect.w + 1) / scaling_w;
784  dst_x1 = dst->clip_rect.w - 1;
785  }
786 
787  if (dst_y0 < 0) {
788  src_y0 -= dst_y0 / scaling_h;
789  dst_y0 = 0;
790  }
791 
792  if (dst_y1 >= dst->clip_rect.h) {
793  src_y1 -= (dst_y1 - dst->clip_rect.h + 1) / scaling_h;
794  dst_y1 = dst->clip_rect.h - 1;
795  }
796 
797  /* Translate back to surface coordinates */
798  dst_x0 += dst->clip_rect.x;
799  dst_x1 += dst->clip_rect.x;
800  dst_y0 += dst->clip_rect.y;
801  dst_y1 += dst->clip_rect.y;
802 
803  final_src.x = (int)SDL_floor(src_x0 + 0.5);
804  final_src.y = (int)SDL_floor(src_y0 + 0.5);
805  final_src.w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5);
806  final_src.h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5);
807 
808  final_dst.x = (int)SDL_floor(dst_x0 + 0.5);
809  final_dst.y = (int)SDL_floor(dst_y0 + 0.5);
810  final_dst.w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5);
811  final_dst.h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5);
812 
813  if (final_dst.w < 0)
814  final_dst.w = 0;
815  if (final_dst.h < 0)
816  final_dst.h = 0;
817 
818  if (dstrect)
819  *dstrect = final_dst;
820 
821  if (final_dst.w == 0 || final_dst.h == 0 ||
822  final_src.w <= 0 || final_src.h <= 0) {
823  /* No-op. */
824  return 0;
825  }
826 
827  return SDL_LowerBlitScaled(src, &final_src, dst, &final_dst);
828 }
829 
830 /**
831  * This is a semi-private blit function and it performs low-level surface
832  * scaled blitting only.
833  */
834 int
836  SDL_Surface * dst, SDL_Rect * dstrect)
837 {
838  static const Uint32 complex_copy_flags = (
842  );
843 
844  if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
845  src->map->info.flags |= SDL_COPY_NEAREST;
846  SDL_InvalidateMap(src->map);
847  }
848 
849  if ( !(src->map->info.flags & complex_copy_flags) &&
850  src->format->format == dst->format->format &&
852  return SDL_SoftStretch( src, srcrect, dst, dstrect );
853  } else {
854  return SDL_LowerBlit( src, srcrect, dst, dstrect );
855  }
856 }
857 
858 /*
859  * Lock a surface to directly access the pixels
860  */
861 int
863 {
864  if (!surface->locked) {
865  /* Perform the lock */
866  if (surface->flags & SDL_RLEACCEL) {
867  SDL_UnRLESurface(surface, 1);
868  surface->flags |= SDL_RLEACCEL; /* save accel'd state */
869  }
870  }
871 
872  /* Increment the surface lock count, for recursive locks */
873  ++surface->locked;
874 
875  /* Ready to go.. */
876  return (0);
877 }
878 
879 /*
880  * Unlock a previously locked surface
881  */
882 void
884 {
885  /* Only perform an unlock if we are locked */
886  if (!surface->locked || (--surface->locked > 0)) {
887  return;
888  }
889 
890  /* Update RLE encoded surface with new data */
891  if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
892  surface->flags &= ~SDL_RLEACCEL; /* stop lying */
893  SDL_RLESurface(surface);
894  }
895 }
896 
897 /*
898  * Creates a new surface identical to the existing surface
899  */
900 SDL_Surface *
902 {
903  return SDL_ConvertSurface(surface, surface->format, surface->flags);
904 }
905 
906 /*
907  * Convert a surface into the specified pixel format.
908  */
909 SDL_Surface *
911  Uint32 flags)
912 {
913  SDL_Surface *convert;
914  Uint32 copy_flags;
915  SDL_Color copy_color;
916  SDL_Rect bounds;
917 
918  if (!surface) {
919  SDL_InvalidParamError("surface");
920  return NULL;
921  }
922  if (!format) {
923  SDL_InvalidParamError("format");
924  return NULL;
925  }
926 
927  /* Check for empty destination palette! (results in empty image) */
928  if (format->palette != NULL) {
929  int i;
930  for (i = 0; i < format->palette->ncolors; ++i) {
931  if ((format->palette->colors[i].r != 0xFF) ||
932  (format->palette->colors[i].g != 0xFF) ||
933  (format->palette->colors[i].b != 0xFF))
934  break;
935  }
936  if (i == format->palette->ncolors) {
937  SDL_SetError("Empty destination palette");
938  return (NULL);
939  }
940  }
941 
942  /* Create a new surface with the desired format */
943  convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
944  format->BitsPerPixel, format->Rmask,
945  format->Gmask, format->Bmask,
946  format->Amask);
947  if (convert == NULL) {
948  return (NULL);
949  }
950 
951  /* Copy the palette if any */
952  if (format->palette && convert->format->palette) {
953  SDL_memcpy(convert->format->palette->colors,
954  format->palette->colors,
955  format->palette->ncolors * sizeof(SDL_Color));
956  convert->format->palette->ncolors = format->palette->ncolors;
957  }
958 
959  /* Save the original copy flags */
960  copy_flags = surface->map->info.flags;
961  copy_color.r = surface->map->info.r;
962  copy_color.g = surface->map->info.g;
963  copy_color.b = surface->map->info.b;
964  copy_color.a = surface->map->info.a;
965  surface->map->info.r = 0xFF;
966  surface->map->info.g = 0xFF;
967  surface->map->info.b = 0xFF;
968  surface->map->info.a = 0xFF;
969  surface->map->info.flags = 0;
970  SDL_InvalidateMap(surface->map);
971 
972  /* Copy over the image data */
973  bounds.x = 0;
974  bounds.y = 0;
975  bounds.w = surface->w;
976  bounds.h = surface->h;
977  SDL_LowerBlit(surface, &bounds, convert, &bounds);
978 
979  /* Clean up the original surface, and update converted surface */
980  convert->map->info.r = copy_color.r;
981  convert->map->info.g = copy_color.g;
982  convert->map->info.b = copy_color.b;
983  convert->map->info.a = copy_color.a;
984  convert->map->info.flags =
985  (copy_flags &
989  surface->map->info.r = copy_color.r;
990  surface->map->info.g = copy_color.g;
991  surface->map->info.b = copy_color.b;
992  surface->map->info.a = copy_color.a;
993  surface->map->info.flags = copy_flags;
994  SDL_InvalidateMap(surface->map);
995  if (copy_flags & SDL_COPY_COLORKEY) {
996  SDL_bool set_colorkey_by_color = SDL_FALSE;
997 
998  if (surface->format->palette) {
999  if (format->palette &&
1000  surface->format->palette->ncolors <= format->palette->ncolors &&
1001  (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
1002  surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
1003  /* The palette is identical, just set the same colorkey */
1004  SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
1005  } else if (format->Amask) {
1006  /* The alpha was set in the destination from the palette */
1007  } else {
1008  set_colorkey_by_color = SDL_TRUE;
1009  }
1010  } else {
1011  set_colorkey_by_color = SDL_TRUE;
1012  }
1013 
1014  if (set_colorkey_by_color) {
1015  SDL_Surface *tmp;
1016  SDL_Surface *tmp2;
1017  int converted_colorkey = 0;
1018 
1019  /* Create a dummy surface to get the colorkey converted */
1020  tmp = SDL_CreateRGBSurface(0, 1, 1,
1021  surface->format->BitsPerPixel, surface->format->Rmask,
1022  surface->format->Gmask, surface->format->Bmask,
1023  surface->format->Amask);
1024 
1025  /* Share the palette, if any */
1026  if (surface->format->palette) {
1027  SDL_SetSurfacePalette(tmp, surface->format->palette);
1028  }
1029 
1030  SDL_FillRect(tmp, NULL, surface->map->info.colorkey);
1031 
1032  tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
1033 
1034  /* Convertion of the colorkey */
1035  tmp2 = SDL_ConvertSurface(tmp, format, 0);
1036 
1037  /* Get the converted colorkey */
1038  SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);
1039 
1040  SDL_FreeSurface(tmp);
1041  SDL_FreeSurface(tmp2);
1042 
1043  /* Set the converted colorkey on the new surface */
1044  SDL_SetColorKey(convert, 1, converted_colorkey);
1045 
1046  /* This is needed when converting for 3D texture upload */
1047  SDL_ConvertColorkeyToAlpha(convert);
1048  }
1049  }
1050  SDL_SetClipRect(convert, &surface->clip_rect);
1051 
1052  /* Enable alpha blending by default if the new surface has an
1053  * alpha channel or alpha modulation */
1054  if ((surface->format->Amask && format->Amask) ||
1055  (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
1057  }
1058  if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
1059  SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
1060  }
1061 
1062  /* We're ready to go! */
1063  return (convert);
1064 }
1065 
1066 SDL_Surface *
1068  Uint32 flags)
1069 {
1070  SDL_PixelFormat *fmt;
1071  SDL_Surface *convert = NULL;
1072 
1073  fmt = SDL_AllocFormat(pixel_format);
1074  if (fmt) {
1075  convert = SDL_ConvertSurface(surface, fmt, flags);
1076  SDL_FreeFormat(fmt);
1077  }
1078  return convert;
1079 }
1080 
1081 /*
1082  * Create a surface on the stack for quick blit operations
1083  */
1084 static SDL_INLINE SDL_bool
1086  void * pixels, int pitch, SDL_Surface * surface,
1087  SDL_PixelFormat * format, SDL_BlitMap * blitmap)
1088 {
1089  if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
1090  SDL_SetError("Indexed pixel formats not supported");
1091  return SDL_FALSE;
1092  }
1093  if (SDL_InitFormat(format, pixel_format) < 0) {
1094  return SDL_FALSE;
1095  }
1096 
1097  SDL_zerop(surface);
1098  surface->flags = SDL_PREALLOC;
1099  surface->format = format;
1100  surface->pixels = pixels;
1101  surface->w = width;
1102  surface->h = height;
1103  surface->pitch = pitch;
1104  /* We don't actually need to set up the clip rect for our purposes */
1105  /* SDL_SetClipRect(surface, NULL); */
1106 
1107  /* Allocate an empty mapping */
1108  SDL_zerop(blitmap);
1109  blitmap->info.r = 0xFF;
1110  blitmap->info.g = 0xFF;
1111  blitmap->info.b = 0xFF;
1112  blitmap->info.a = 0xFF;
1113  surface->map = blitmap;
1114 
1115  /* The surface is ready to go */
1116  surface->refcount = 1;
1117  return SDL_TRUE;
1118 }
1119 
1120 /*
1121  * Copy a block of pixels of one format to another format
1122  */
1124  Uint32 src_format, const void * src, int src_pitch,
1125  Uint32 dst_format, void * dst, int dst_pitch)
1126 {
1127  SDL_Surface src_surface, dst_surface;
1128  SDL_PixelFormat src_fmt, dst_fmt;
1129  SDL_BlitMap src_blitmap, dst_blitmap;
1130  SDL_Rect rect;
1131  void *nonconst_src = (void *) src;
1132 
1133  /* Check to make sure we are blitting somewhere, so we don't crash */
1134  if (!dst) {
1135  return SDL_InvalidParamError("dst");
1136  }
1137  if (!dst_pitch) {
1138  return SDL_InvalidParamError("dst_pitch");
1139  }
1140 
1141  /* Fast path for same format copy */
1142  if (src_format == dst_format) {
1143  int i;
1144 
1145  if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
1146  switch (src_format) {
1147  case SDL_PIXELFORMAT_YUY2:
1148  case SDL_PIXELFORMAT_UYVY:
1149  case SDL_PIXELFORMAT_YVYU:
1150  /* Packed planes */
1151  width = 4 * ((width + 1) / 2);
1152  for (i = height; i--;) {
1153  SDL_memcpy(dst, src, width);
1154  src = (const Uint8*)src + src_pitch;
1155  dst = (Uint8*)dst + dst_pitch;
1156  }
1157  break;
1158  case SDL_PIXELFORMAT_YV12:
1159  case SDL_PIXELFORMAT_IYUV:
1160  case SDL_PIXELFORMAT_NV12:
1161  case SDL_PIXELFORMAT_NV21:
1162  {
1163  /* Y plane */
1164  for (i = height; i--;) {
1165  SDL_memcpy(dst, src, width);
1166  src = (const Uint8*)src + src_pitch;
1167  dst = (Uint8*)dst + dst_pitch;
1168  }
1169 
1170  /* not sure the pitch is relevant here.
1171  this also works to add the size of two chroma planes */
1172 #if 0
1173  SDL_memcpy(dst, src, 2 * ((width + 1)/2) * ((height+1)/2));
1174 #else
1175 
1176  if (src_format == SDL_PIXELFORMAT_YV12 || src_format == SDL_PIXELFORMAT_IYUV) {
1177  /* U and V planes are a quarter the size of the Y plane */
1178  width = (width + 1) / 2;
1179  height = (height + 1) / 2;
1180  src_pitch = (src_pitch + 1) / 2;
1181  dst_pitch = (dst_pitch + 1) / 2;
1182  for (i = height * 2; i--;) {
1183  SDL_memcpy(dst, src, width);
1184  src = (const Uint8*)src + src_pitch;
1185  dst = (Uint8*)dst + dst_pitch;
1186  }
1187  } else if (src_format == SDL_PIXELFORMAT_NV12 || src_format == SDL_PIXELFORMAT_NV21) {
1188  /* U/V plane is half the height of the Y plane */
1189  height = (height + 1) / 2;
1190  width = (width + 1) / 2;
1191  src_pitch = (src_pitch + 1) / 2;
1192  dst_pitch = (dst_pitch + 1) / 2;
1193  for (i = height; i--;) {
1194  SDL_memcpy(dst, src, 2 * width);
1195  src = (const Uint8*)src + 2 * src_pitch;
1196  dst = (Uint8*)dst + 2 * dst_pitch;
1197  }
1198  }
1199 #endif
1200  }
1201  break;
1202  default:
1203  return SDL_SetError("Unknown FOURCC pixel format");
1204  }
1205  } else {
1206  const int bpp = SDL_BYTESPERPIXEL(src_format);
1207  width *= bpp;
1208  for (i = height; i--;) {
1209  SDL_memcpy(dst, src, width);
1210  src = (const Uint8*)src + src_pitch;
1211  dst = (Uint8*)dst + dst_pitch;
1212  }
1213  }
1214  return 0;
1215  }
1216 
1217  /* FOURCC to Any */
1218  if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
1219  /* FOURCC to ARGB8888 */
1220  if (dst_format == SDL_PIXELFORMAT_ARGB8888) {
1221  SDL_ConvertPixels_YUV_to_ARGB8888(width, height, src_format, src, dst, dst_pitch);
1222  return 0;
1223  }
1224  else /* FOURCC to not(ARGB8888) : need an intermediate conversion */
1225  {
1226  int ret;
1227  void *tmp = SDL_malloc(width * height * 4);
1228  if (tmp == NULL) {
1229  return -1;
1230  }
1231 
1232  /* convert src/FOURCC to tmp/ARGB8888 */
1233  SDL_ConvertPixels_YUV_to_ARGB8888(width, height, src_format, src, tmp, width * 4);
1234 
1235  /* convert tmp/ARGB8888 to dst/dst_format */
1236  ret = SDL_ConvertPixels(width, height, SDL_PIXELFORMAT_ARGB8888, tmp, width * 4, dst_format, dst, dst_pitch);
1237  SDL_free(tmp);
1238  return ret;
1239  }
1240  }
1241 
1242  /* Any to FOURCC */
1243  if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
1244  /* ARGB8888 to FOURCC */
1245  if (src_format == SDL_PIXELFORMAT_ARGB8888) {
1246  SDL_ConvertPixels_ARGB8888_to_YUV(width, height, src, src_pitch, dst_format, dst);
1247  return 0;
1248  }
1249  else /* not(ARGB8888) to FOURCC : need an intermediate conversion */
1250  {
1251  int ret;
1252  void *tmp = SDL_malloc(width * height * 4);
1253  if (tmp == NULL) {
1254  return -1;
1255  }
1256  /* convert src/src_format to tmp/ARGB8888 */
1257  ret = SDL_ConvertPixels(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, width * 4);
1258  if (ret == -1) {
1259  SDL_free(tmp);
1260  return ret;
1261  }
1262  /* convert tmp/ARGB8888 to dst/FOURCC */
1263  SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, width * 4, dst_format, dst);
1264 
1265  SDL_free(tmp);
1266  return 0;
1267  }
1268  }
1269 
1270  if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
1271  src_pitch,
1272  &src_surface, &src_fmt, &src_blitmap)) {
1273  return -1;
1274  }
1275  if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
1276  &dst_surface, &dst_fmt, &dst_blitmap)) {
1277  return -1;
1278  }
1279 
1280  /* Set up the rect and go! */
1281  rect.x = 0;
1282  rect.y = 0;
1283  rect.w = width;
1284  rect.h = height;
1285  return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
1286 }
1287 
1288 /*
1289  * Free a surface created by the above function.
1290  */
1291 void
1293 {
1294  if (surface == NULL) {
1295  return;
1296  }
1297  if (surface->flags & SDL_DONTFREE) {
1298  return;
1299  }
1300  SDL_InvalidateMap(surface->map);
1301 
1302  if (--surface->refcount > 0) {
1303  return;
1304  }
1305  while (surface->locked > 0) {
1306  SDL_UnlockSurface(surface);
1307  }
1308  if (surface->flags & SDL_RLEACCEL) {
1309  SDL_UnRLESurface(surface, 0);
1310  }
1311  if (surface->format) {
1312  SDL_SetSurfacePalette(surface, NULL);
1313  SDL_FreeFormat(surface->format);
1314  surface->format = NULL;
1315  }
1316  if (!(surface->flags & SDL_PREALLOC)) {
1317  SDL_free(surface->pixels);
1318  }
1319  if (surface->map) {
1320  SDL_FreeBlitMap(surface->map);
1321  }
1322  SDL_free(surface);
1323 }
1324 
1325 
1326 /* YUV-RGB conversion */
1327 #define CLAMP(val) ((val) > 0 ? ((val) < 255 ? (val) : 255) : 0)
1328 
1329 #if 1
1330 
1331 /* Coefficients from CCIR 601 */
1332 #define MAKE_Y(r, g, b) (int)( 0.29900f * (r) + 0.58700f * (g) + 0.11400f * (b))
1333 #define MAKE_U(r, g, b) (int)(-0.16874f * (r) - 0.33126f * (g) + 0.50000f * (b) + 128)
1334 #define MAKE_V(r, g, b) (int)( 0.50000f * (r) - 0.41869f * (g) - 0.08131f * (b) + 128)
1335 
1336 #define MAKE_R(y, u, v) CLAMP((int)((y) + 1.40200f * ((v) - 128)))
1337 #define MAKE_G(y, u, v) CLAMP((int)((y) - 0.34414f * ((u) - 128) - 0.71414f * ((v) - 128)))
1338 #define MAKE_B(y, u, v) CLAMP((int)((y) + 1.77200f * ((u) - 128) ))
1339 
1340 #else
1341 
1342 /* Coefficients from Video Demystified */
1343 #define MAKE_Y(r, g, b) ((( 66 * (r) + 129 * (g) + 25 * (b) + 128) >> 8) + 16)
1344 #define MAKE_U(r, g, b) ((( -38 * (r) - 74 * (g) + 112 * (b) + 128) >> 8) + 128)
1345 #define MAKE_V(r, g, b) ((( 112 * (r) - 94 * (g) - 18 * (b) + 128) >> 8) + 128)
1346 
1347 #define MAKE_R(y, u, v) CLAMP(( 298 * ((y) - 16) + 409 * ((v) - 128) + 128) >> 8)
1348 #define MAKE_G(y, u, v) CLAMP(( 298 * ((y) - 16) - 100 * ((u) - 128) - 208 * ((v) - 128) + 128) >> 8)
1349 #define MAKE_B(y, u, v) CLAMP(( 298 * ((y) - 16) + 516 * ((u) - 128) + 128) >> 8)
1350 
1351 #endif
1352 
1353 
1354 static int
1356  Uint32 src_format, const void *src,
1357  void *dst, int dst_pitch)
1358 {
1359  const int sz_plane = width * height;
1360  const int sz_plane_chroma = ((width + 1) / 2) * ((height + 1) / 2);
1361  const int width_remainder = (width & 0x1);
1362  const int width_half = width / 2;
1363  const int curr_row_padding = dst_pitch - 4 * width;
1364  int i, j;
1365  Uint8 *curr_row = (Uint8*)dst;
1366 
1367  // SDL_Log("SDL_ConvertPixels_YUV_to_ARGB8888 (from %s)", SDL_GetPixelFormatName(src_format));
1368 
1369 #define WRITE_RGB_PIXEL(y, u, v) \
1370  *((Uint32*)curr_row) = \
1371  (MAKE_B((y), (u), (v)) \
1372  | (MAKE_G((y), (u), (v)) << 8) \
1373  | (MAKE_R((y), (u), (v)) << 16) \
1374  | 0xff000000); \
1375  curr_row += 4; \
1376 
1377  switch (src_format)
1378  {
1379  case SDL_PIXELFORMAT_YV12:
1380  case SDL_PIXELFORMAT_IYUV:
1381  case SDL_PIXELFORMAT_NV12:
1382  case SDL_PIXELFORMAT_NV21:
1383  {
1384  const Uint8 *plane_y = (const Uint8*)src;
1385 
1386  if (src_format == SDL_PIXELFORMAT_YV12 || src_format == SDL_PIXELFORMAT_IYUV)
1387  {
1388  const Uint8 *plane_u = (src_format == SDL_PIXELFORMAT_YV12 ? plane_y + sz_plane + sz_plane_chroma : plane_y + sz_plane);
1389  const Uint8 *plane_v = (src_format == SDL_PIXELFORMAT_YV12 ? plane_y + sz_plane : plane_y + sz_plane + sz_plane_chroma);
1390 
1391  for (j = 0; j < height; j++) {
1392  for (i = 0; i < width_half; i++) {
1393  const Uint8 u = *plane_u++;
1394  const Uint8 v = *plane_v++;
1395  const Uint8 y = *plane_y++;
1396  const Uint8 y1 = *plane_y++;
1397  WRITE_RGB_PIXEL(y, u, v);
1398  WRITE_RGB_PIXEL(y1, u, v);
1399  }
1400  if (width_remainder) {
1401  const Uint8 u = *plane_u++;
1402  const Uint8 v = *plane_v++;
1403  const Uint8 y = *plane_y++;
1404  WRITE_RGB_PIXEL(y, u, v);
1405  }
1406  /* Re-use the same line of chroma planes */
1407  if ((j & 0x1) == 0x0) {
1408  plane_u -= width_half + width_remainder;
1409  plane_v -= width_half + width_remainder;
1410  }
1411  curr_row += curr_row_padding;
1412  }
1413  }
1414  else if (src_format == SDL_PIXELFORMAT_NV12)
1415  {
1416  const Uint8 *plane_interleaved_uv = plane_y + sz_plane;
1417  for (j = 0; j < height; j++) {
1418  for (i = 0; i < width_half; i++) {
1419  const Uint8 y = *plane_y++;
1420  const Uint8 y1 = *plane_y++;
1421  const Uint8 u = *plane_interleaved_uv++;
1422  const Uint8 v = *plane_interleaved_uv++;
1423  WRITE_RGB_PIXEL(y, u, v);
1424  WRITE_RGB_PIXEL(y1, u, v);
1425  }
1426  if (width_remainder) {
1427  const Uint8 y = *plane_y++;
1428  const Uint8 u = *plane_interleaved_uv++;
1429  const Uint8 v = *plane_interleaved_uv++;
1430  WRITE_RGB_PIXEL(y, u, v);
1431  }
1432  /* Re-use the same line of chroma planes */
1433  if ((j & 0x1) == 0x0) {
1434  plane_interleaved_uv -= 2 * (width_half + width_remainder);
1435  }
1436  curr_row += curr_row_padding;
1437  }
1438  }
1439  else /* src_format == SDL_PIXELFORMAT_NV21 */
1440  {
1441  const Uint8 *plane_interleaved_uv = plane_y + sz_plane;
1442  for (j = 0; j < height; j++) {
1443  for (i = 0; i < width_half; i++) {
1444  const Uint8 y = *plane_y++;
1445  const Uint8 y1 = *plane_y++;
1446  const Uint8 v = *plane_interleaved_uv++;
1447  const Uint8 u = *plane_interleaved_uv++;
1448  WRITE_RGB_PIXEL(y, u, v);
1449  WRITE_RGB_PIXEL(y1, u, v);
1450  }
1451  if (width_remainder) {
1452  const Uint8 y = *plane_y++;
1453  const Uint8 v = *plane_interleaved_uv++;
1454  const Uint8 u = *plane_interleaved_uv++;
1455  WRITE_RGB_PIXEL(y, u, v);
1456  }
1457  /* Re-use the same line of chroma planes */
1458  if ((j & 0x1) == 0x0) {
1459  plane_interleaved_uv -= 2 * (width_half + width_remainder);
1460  }
1461  curr_row += curr_row_padding;
1462  }
1463  }
1464  }
1465  break;
1466 
1467  case SDL_PIXELFORMAT_YUY2:
1468  case SDL_PIXELFORMAT_UYVY:
1469  case SDL_PIXELFORMAT_YVYU:
1470  {
1471  const Uint8 *plane = (const Uint8 *)src;
1472 
1473 #define READ_PACKED_YUV(var1, var2, var3, var4) \
1474  const Uint8 var1 = plane[0]; \
1475  const Uint8 var2 = plane[1]; \
1476  const Uint8 var3 = plane[2]; \
1477  const Uint8 var4 = plane[3]; \
1478  plane += 4; \
1479 
1480  if (src_format == SDL_PIXELFORMAT_YUY2) /* Y U Y1 V */
1481  {
1482  for (j = 0; j < height; j++) {
1483  for (i = 0; i < width_half; i++) {
1484  READ_PACKED_YUV(y, u, y1, v);
1485  WRITE_RGB_PIXEL(y, u, v);
1486  WRITE_RGB_PIXEL(y1, u, v);
1487  }
1488  if (width_remainder) {
1489  READ_PACKED_YUV(y, u, y1, v);
1490  (void)y1; /* y1 unused */
1491  WRITE_RGB_PIXEL(y, u, v);
1492  }
1493  curr_row += curr_row_padding;
1494  }
1495  }
1496  else if (src_format == SDL_PIXELFORMAT_UYVY) /* U Y V Y1 */
1497  {
1498  for (j = 0; j < height; j++) {
1499  for (i = 0; i < width_half; i++) {
1500  READ_PACKED_YUV(u, y, v, y1);
1501  WRITE_RGB_PIXEL(y, u, v);
1502  WRITE_RGB_PIXEL(y1, u, v);
1503  }
1504  if (width_remainder) {
1505  READ_PACKED_YUV(u, y, v, y1);
1506  (void) y1; /* y1 unused */
1507  WRITE_RGB_PIXEL(y, u, v);
1508  }
1509  curr_row += curr_row_padding;
1510  }
1511  }
1512  else if (src_format == SDL_PIXELFORMAT_YVYU) /* Y V Y1 U */
1513  {
1514  for (j = 0; j < height; j++) {
1515  for (i = 0; i < width_half; i++) {
1516  READ_PACKED_YUV(y, v, y1, u);
1517  WRITE_RGB_PIXEL(y, u, v);
1518  WRITE_RGB_PIXEL(y1, u, v);
1519  }
1520  if (width_remainder) {
1521  READ_PACKED_YUV(y, v, y1, u);
1522  (void) y1; /* y1 unused */
1523  WRITE_RGB_PIXEL(y, u, v);
1524  }
1525  curr_row += curr_row_padding;
1526  }
1527  }
1528 #undef READ_PACKED_YUV
1529  }
1530  break;
1531  }
1532 #undef WRITE_RGB_PIXEL
1533  return 0;
1534 }
1535 
1536 static int
1537 SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, Uint32 dst_format, void *dst)
1538 {
1539  const int src_pitch_x_2 = src_pitch * 2;
1540  const int sz_plane = width * height;
1541  const int sz_plane_chroma = ((width + 1) / 2) * ((height + 1) / 2);
1542  const int height_half = height / 2;
1543  const int height_remainder = (height & 0x1);
1544  const int width_half = width / 2;
1545  const int width_remainder = (width & 0x1);
1546  int i, j;
1547 
1548  // SDL_Log("SDL_ConvertPixels_ARGB8888_to_YUV (to %s)", SDL_GetPixelFormatName(dst_format));
1549 
1550  switch (dst_format)
1551  {
1552  case SDL_PIXELFORMAT_YV12:
1553  case SDL_PIXELFORMAT_IYUV:
1554  case SDL_PIXELFORMAT_NV12:
1555  case SDL_PIXELFORMAT_NV21:
1556  {
1557  const Uint8 *curr_row, *next_row;
1558 
1559  Uint8 *plane_y = (Uint8*) dst;
1560  Uint8 *plane_u = (dst_format == SDL_PIXELFORMAT_YV12 ? plane_y + sz_plane + sz_plane_chroma : plane_y + sz_plane);
1561  Uint8 *plane_v = (dst_format == SDL_PIXELFORMAT_YV12 ? plane_y + sz_plane : plane_y + sz_plane + sz_plane_chroma);
1562  Uint8 *plane_interleaved_uv = plane_y + sz_plane;
1563 
1564  curr_row = (const Uint8*)src;
1565 
1566  /* Write Y plane */
1567  for (j = 0; j < height; j++) {
1568  for (i = 0; i < width; i++) {
1569  const Uint8 b = curr_row[4 * i + 0];
1570  const Uint8 g = curr_row[4 * i + 1];
1571  const Uint8 r = curr_row[4 * i + 2];
1572  *plane_y++ = MAKE_Y(r, g, b);
1573  }
1574  curr_row += src_pitch;
1575  }
1576 
1577  curr_row = (const Uint8*)src;
1578  next_row = (const Uint8*)src;
1579  next_row += src_pitch;
1580 
1581 #if 1
1582 /* slightly faster */
1583 #define READ_2x2_PIXELS \
1584  const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i]; \
1585  const Uint32 p2 = ((const Uint32 *)curr_row)[2 * i + 1]; \
1586  const Uint32 p3 = ((const Uint32 *)next_row)[2 * i]; \
1587  const Uint32 p4 = ((const Uint32 *)next_row)[2 * i + 1]; \
1588  const Uint32 b = ((p1 & 0x000000ff) + (p2 & 0x000000ff) + (p3 & 0x000000ff) + (p4 & 0x000000ff)) >> 2; \
1589  const Uint32 g = ((p1 & 0x0000ff00) + (p2 & 0x0000ff00) + (p3 & 0x0000ff00) + (p4 & 0x0000ff00)) >> 10; \
1590  const Uint32 r = ((p1 & 0x00ff0000) + (p2 & 0x00ff0000) + (p3 & 0x00ff0000) + (p4 & 0x00ff0000)) >> 18; \
1591 
1592 #else
1593 
1594 #define READ_2x2_PIXELS \
1595  const Uint8 b = (curr_row[8 * i + 0] + curr_row[8 * i + 4] \
1596  + next_row[8 * i + 0] + next_row[8 * i + 4] ) >> 2; \
1597  const Uint8 g = (curr_row[8 * i + 1] + curr_row[8 * i + 5] \
1598  + next_row[8 * i + 1] + next_row[8 * i + 5] ) >> 2; \
1599  const Uint8 r = (curr_row[8 * i + 2] + curr_row[8 * i + 6] \
1600  + next_row[8 * i + 2] + next_row[8 * i + 6] ) >> 2; \
1601 
1602 #endif
1603 
1604 #define READ_2x1_PIXELS \
1605  const Uint8 b = (curr_row[8 * i + 0] + next_row[8 * i + 0]) >> 1; \
1606  const Uint8 g = (curr_row[8 * i + 1] + next_row[8 * i + 1]) >> 1; \
1607  const Uint8 r = (curr_row[8 * i + 2] + next_row[8 * i + 2]) >> 1; \
1608 
1609 #define READ_1x2_PIXELS \
1610  const Uint8 b = (curr_row[8 * i + 0] + curr_row[8 * i + 4]) >> 1; \
1611  const Uint8 g = (curr_row[8 * i + 1] + curr_row[8 * i + 5]) >> 1; \
1612  const Uint8 r = (curr_row[8 * i + 2] + curr_row[8 * i + 6]) >> 1; \
1613 
1614 #define READ_1x1_PIXEL \
1615  const Uint8 b = curr_row[8 * i + 0]; \
1616  const Uint8 g = curr_row[8 * i + 1]; \
1617  const Uint8 r = curr_row[8 * i + 2]; \
1618 
1619  if (dst_format == SDL_PIXELFORMAT_YV12 || dst_format == SDL_PIXELFORMAT_IYUV)
1620  {
1621  /* Write UV planes, not interleaved */
1622  for (j = 0; j < height_half; j++) {
1623  for (i = 0; i < width_half; i++) {
1625  *plane_u++ = MAKE_U(r, g, b);
1626  *plane_v++ = MAKE_V(r, g, b);
1627  }
1628  if (width_remainder) {
1630  *plane_u++ = MAKE_U(r, g, b);
1631  *plane_v++ = MAKE_V(r, g, b);
1632  }
1633  curr_row += src_pitch_x_2;
1634  next_row += src_pitch_x_2;
1635  }
1636  if (height_remainder) {
1637  for (i = 0; i < width_half; i++) {
1639  *plane_u++ = MAKE_U(r, g, b);
1640  *plane_v++ = MAKE_V(r, g, b);
1641  }
1642  if (width_remainder) {
1644  *plane_u++ = MAKE_U(r, g, b);
1645  *plane_v++ = MAKE_V(r, g, b);
1646  }
1647  }
1648  }
1649  else if (dst_format == SDL_PIXELFORMAT_NV12)
1650  {
1651  for (j = 0; j < height_half; j++) {
1652  for (i = 0; i < width_half; i++) {
1654  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1655  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1656  }
1657  if (width_remainder) {
1659  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1660  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1661  }
1662  curr_row += src_pitch_x_2;
1663  next_row += src_pitch_x_2;
1664  }
1665  if (height_remainder) {
1666  for (i = 0; i < width_half; i++) {
1668  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1669  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1670  }
1671  if (width_remainder) {
1673  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1674  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1675  }
1676  }
1677  }
1678  else /* dst_format == SDL_PIXELFORMAT_NV21 */
1679  {
1680  for (j = 0; j < height_half; j++) {
1681  for (i = 0; i < width_half; i++) {
1683  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1684  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1685  }
1686  if (width_remainder) {
1688  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1689  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1690  }
1691  curr_row += src_pitch_x_2;
1692  next_row += src_pitch_x_2;
1693  }
1694  if (height_remainder) {
1695  for (i = 0; i < width_half; i++) {
1697  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1698  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1699  }
1700  if (width_remainder) {
1702  *plane_interleaved_uv++ = MAKE_V(r, g, b);
1703  *plane_interleaved_uv++ = MAKE_U(r, g, b);
1704  }
1705  }
1706  }
1707 #undef READ_2x2_PIXELS
1708 #undef READ_2x1_PIXELS
1709 #undef READ_1x2_PIXELS
1710 #undef READ_1x1_PIXEL
1711  }
1712  break;
1713 
1714  case SDL_PIXELFORMAT_YUY2:
1715  case SDL_PIXELFORMAT_UYVY:
1716  case SDL_PIXELFORMAT_YVYU:
1717  {
1718  const Uint8 *curr_row = (const Uint8*) src;
1719  Uint8 *plane = (Uint8*) dst;
1720 
1721 #define READ_TWO_RGB_PIXELS \
1722  const Uint8 b = curr_row[8 * i + 0]; \
1723  const Uint8 g = curr_row[8 * i + 1]; \
1724  const Uint8 r = curr_row[8 * i + 2]; \
1725  const Uint8 b1 = curr_row[8 * i + 4]; \
1726  const Uint8 g1 = curr_row[8 * i + 5]; \
1727  const Uint8 r1 = curr_row[8 * i + 6]; \
1728  const Uint8 B = (b + b1) >> 1; \
1729  const Uint8 G = (g + g1) >> 1; \
1730  const Uint8 R = (r + r1) >> 1; \
1731 
1732 #define READ_ONE_RGB_PIXEL \
1733  const Uint8 b = curr_row[8 * i + 0]; \
1734  const Uint8 g = curr_row[8 * i + 1]; \
1735  const Uint8 r = curr_row[8 * i + 2]; \
1736 
1737  /* Write YUV plane, packed */
1738  if (dst_format == SDL_PIXELFORMAT_YUY2)
1739  {
1740  for (j = 0; j < height; j++) {
1741  for (i = 0; i < width_half; i++) {
1743  /* Y U Y1 V */
1744  *plane++ = MAKE_Y(r, g, b);
1745  *plane++ = MAKE_U(R, G, B);
1746  *plane++ = MAKE_Y(r1, g1, b1);
1747  *plane++ = MAKE_V(R, G, B);
1748  }
1749  if (width_remainder) {
1751  /* Y U Y V */
1752  *plane++ = MAKE_Y(r, g, b);
1753  *plane++ = MAKE_U(r, g, b);
1754  *plane++ = MAKE_Y(r, g, b);
1755  *plane++ = MAKE_V(r, g, b);
1756  }
1757  curr_row += src_pitch;
1758  }
1759  }
1760  else if (dst_format == SDL_PIXELFORMAT_UYVY)
1761  {
1762  for (j = 0; j < height; j++) {
1763  for (i = 0; i < width_half; i++) {
1765  /* U Y V Y1 */
1766  *plane++ = MAKE_U(R, G, B);
1767  *plane++ = MAKE_Y(r, g, b);
1768  *plane++ = MAKE_V(R, G, B);
1769  *plane++ = MAKE_Y(r1, g1, b1);
1770  }
1771  if (width_remainder) {
1773  /* U Y V Y */
1774  *plane++ = MAKE_U(r, g, b);
1775  *plane++ = MAKE_Y(r, g, b);
1776  *plane++ = MAKE_V(r, g, b);
1777  *plane++ = MAKE_Y(r, g, b);
1778  }
1779  curr_row += src_pitch;
1780  }
1781  }
1782  else if (dst_format == SDL_PIXELFORMAT_YVYU)
1783  {
1784  for (j = 0; j < height; j++) {
1785  for (i = 0; i < width_half; i++) {
1787  /* Y V Y1 U */
1788  *plane++ = MAKE_Y(r, g, b);
1789  *plane++ = MAKE_V(R, G, B);
1790  *plane++ = MAKE_Y(r1, g1, b1);
1791  *plane++ = MAKE_U(R, G, B);
1792  }
1793  if (width_remainder) {
1795  /* Y V Y U */
1796  *plane++ = MAKE_Y(r, g, b);
1797  *plane++ = MAKE_V(r, g, b);
1798  *plane++ = MAKE_Y(r, g, b);
1799  *plane++ = MAKE_U(r, g, b);
1800  }
1801  curr_row += src_pitch;
1802  }
1803  }
1804 #undef READ_TWO_RGB_PIXELS
1805 #undef READ_ONE_RGB_PIXEL
1806  }
1807  break;
1808  }
1809  return 0;
1810 }
1811 
1812 /* 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:281
Uint8 r
Definition: SDL_blit.h:70
#define SDL_COPY_MODULATE_COLOR
Definition: SDL_blit.h:34
static int SDL_ConvertPixels_YUV_to_ARGB8888(int width, int height, Uint32 src_format, const void *src, void *dst, int dst_pitch)
Definition: SDL_surface.c:1355
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
void SDL_UnlockSurface(SDL_Surface *surface)
Definition: SDL_surface.c:883
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:516
#define READ_TWO_RGB_PIXELS
GLuint GLfloat GLfloat GLfloat x1
#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:215
Uint8 g
Definition: SDL_pixels.h:296
const GLdouble * v
Definition: SDL_opengl.h:2064
GLenum GLenum dst
#define WRITE_RGB_PIXEL(y, u, v)
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
#define SDL_SoftStretch
#define READ_2x2_PIXELS
#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:862
SDL_Surface * SDL_ConvertSurfaceFormat(SDL_Surface *surface, Uint32 pixel_format, Uint32 flags)
Definition: SDL_surface.c:1067
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
Uint8 BytesPerPixel
Definition: SDL_pixels.h:318
#define READ_PACKED_YUV(var1, var2, var3, var4)
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:910
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:1085
#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:369
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:414
#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:681
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
Set the blend mode used for blit operations.
Definition: SDL_surface.c:450
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:299
#define READ_2x1_PIXELS
#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:901
#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 MAKE_U(r, g, b)
Definition: SDL_surface.c:1333
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
#define MAKE_Y(r, g, b)
Definition: SDL_surface.c:1332
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:559
#define SDL_zerop(x)
Definition: SDL_stdinc.h:417
int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key)
Sets the color key (transparent pixel) in a blittable surface.
Definition: SDL_surface.c:236
int SDL_UpperBlit(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:582
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
GLfixed y1
void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
Definition: SDL_surface.c:540
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
#define READ_1x1_PIXEL
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define READ_ONE_RGB_PIXEL
#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:51
struct SDL_BlitMap * map
Definition: SDL_surface.h:88
#define SDL_memcpy
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
#define READ_1x2_PIXELS
void * pixels
Definition: SDL_surface.h:75
Uint8 a
Definition: SDL_pixels.h:298
uint8_t Uint8
Definition: SDL_stdinc.h:157
#define SDL_free
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:201
int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
Get the blend mode used for blit operations.
Definition: SDL_surface.c:487
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:1123
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 int in j)
Definition: SDL_x11sym.h:50
#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:182
int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
Get the additional alpha value used in blit operations.
Definition: SDL_surface.c:437
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:1292
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:138
GLbitfield flags
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
#define SDL_calloc
#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 G(x, y, z)
Definition: SDL_test_md5.c:74
#define SDL_FillRect
int SDL_LowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
Definition: SDL_surface.c:835
SDL_BlitMap * SDL_AllocBlitMap(void)
Definition: SDL_pixels.c:961
GLuint GLfloat x0
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:158
#define MAKE_V(r, g, b)
Definition: SDL_surface.c:1334
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:395
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
static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, Uint32 dst_format, void *dst)
Definition: SDL_surface.c:1537
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
Uint8 a
Definition: SDL_blit.h:70