MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_CreateRGBSurfaceWithFormat

Function SDL_CreateRGBSurfaceWithFormat

deps/SDL2/src/video/SDL_surface.c:58–141  ·  view source on GitHub ↗

* Create an empty RGB surface of the appropriate depth using the given * enum SDL_PIXELFORMAT_* format */

Source from the content-addressed store, hash-verified

56 * enum SDL_PIXELFORMAT_* format
57 */
58SDL_Surface *
59SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
60 Uint32 format)
61{
62 SDL_Surface *surface;
63
64 /* The flags are no longer used, make the compiler happy */
65 (void)flags;
66
67 /* Allocate the surface */
68 surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
69 if (surface == NULL) {
70 SDL_OutOfMemory();
71 return NULL;
72 }
73
74 surface->format = SDL_AllocFormat(format);
75 if (!surface->format) {
76 SDL_FreeSurface(surface);
77 return NULL;
78 }
79 surface->w = width;
80 surface->h = height;
81 surface->pitch = SDL_CalculatePitch(format, width);
82 SDL_SetClipRect(surface, NULL);
83
84 if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
85 SDL_Palette *palette =
86 SDL_AllocPalette((1 << surface->format->BitsPerPixel));
87 if (!palette) {
88 SDL_FreeSurface(surface);
89 return NULL;
90 }
91 if (palette->ncolors == 2) {
92 /* Create a black and white bitmap palette */
93 palette->colors[0].r = 0xFF;
94 palette->colors[0].g = 0xFF;
95 palette->colors[0].b = 0xFF;
96 palette->colors[1].r = 0x00;
97 palette->colors[1].g = 0x00;
98 palette->colors[1].b = 0x00;
99 }
100 SDL_SetSurfacePalette(surface, palette);
101 SDL_FreePalette(palette);
102 }
103
104 /* Get the pixels */
105 if (surface->w && surface->h) {
106 /* Assumptions checked in surface_size_assumptions assert above */
107 Sint64 size = ((Sint64)surface->h * surface->pitch);
108 if (size < 0 || size > SDL_MAX_SINT32) {
109 /* Overflow... */
110 SDL_FreeSurface(surface);
111 SDL_OutOfMemory();
112 return NULL;
113 }
114
115 surface->pixels = SDL_SIMDAlloc((size_t)size);

Callers 5

generate_test_patternFunction · 0.85
mainFunction · 0.85
SDL_CreateRGBSurfaceFunction · 0.85

Calls 12

SDL_callocFunction · 0.85
SDL_AllocFormatFunction · 0.85
SDL_FreeSurfaceFunction · 0.85
SDL_CalculatePitchFunction · 0.85
SDL_SetClipRectFunction · 0.85
SDL_AllocPaletteFunction · 0.85
SDL_SetSurfacePaletteFunction · 0.85
SDL_FreePaletteFunction · 0.85
SDL_SIMDAllocFunction · 0.85
SDL_memsetFunction · 0.85
SDL_AllocBlitMapFunction · 0.85
SDL_SetSurfaceBlendModeFunction · 0.85

Tested by 2

generate_test_patternFunction · 0.68
mainFunction · 0.68