Skip to content

Commit

Permalink
Updated to the latest version of SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 13, 2024
1 parent 004aedb commit e56f550
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 36 deletions.
2 changes: 1 addition & 1 deletion external/SDL
Submodule SDL updated 114 files
4 changes: 1 addition & 3 deletions src/IMG_ImageIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
size_t i;

if (num_entries > 0) {
SDL_Palette* palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(surface->format));
SDL_Palette* palette = SDL_CreateSurfacePalette(surface);
if (palette) {
if (num_entries > (size_t)palette->ncolors) {
num_entries = (size_t)palette->ncolors;
Expand All @@ -331,8 +331,6 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
palette->colors[i].b = entry[2];
entry += num_components;
}
SDL_SetSurfacePalette(surface, palette);
SDL_DestroyPalette(palette);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/IMG_gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ ReadImage(SDL_IOStream * src, int len, int height, int cmapSize,
return NULL;
}

palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(image->format));
palette = SDL_CreateSurfacePalette(image);
if (!palette) {
return NULL;
}
Expand All @@ -656,8 +656,6 @@ ReadImage(SDL_IOStream * src, int len, int height, int cmapSize,
for (i = 0; i < cmapSize; i++) {
ImageSetCmap(image, i, cmap[CM_RED][i], cmap[CM_GREEN][i], cmap[CM_BLUE][i]);
}
SDL_SetSurfacePalette(image, palette);
SDL_DestroyPalette(palette);

while ((v = LWZReadByte(src, FALSE, c, state)) >= 0) {
((Uint8 *)image->pixels)[xpos + ypos * image->pitch] = (Uint8)v;
Expand Down
5 changes: 1 addition & 4 deletions src/IMG_lbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src )
int nbrcolorsfinal = 1 << (nbplanes + stencil);
ptr = &colormap[0];

palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(Image->format));
palette = SDL_CreateSurfacePalette(Image);
if (!palette) {
goto done;
}
Expand Down Expand Up @@ -320,9 +320,6 @@ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src )
}
if ( !pbm )
palette->ncolors = nbrcolorsfinal;

SDL_SetSurfacePalette(Image, palette);
SDL_DestroyPalette(palette);
}

/* Get the bitmap */
Expand Down
4 changes: 1 addition & 3 deletions src/IMG_pcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ SDL_Surface *IMG_LoadPCX_IO(SDL_IOStream *src)
SDL_Palette *palette;
int i;

palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(surface->format));
palette = SDL_CreateSurfacePalette(surface);
if (!palette) {
error = "Couldn't create palette";
goto done;
Expand Down Expand Up @@ -276,8 +276,6 @@ SDL_Surface *IMG_LoadPCX_IO(SDL_IOStream *src)
palette->colors[i].b = pcxh.Colormap[i * 3 + 2];
}
}
SDL_SetSurfacePalette(surface, palette);
SDL_DestroyPalette(palette);
}

done:
Expand Down
8 changes: 2 additions & 6 deletions src/IMG_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ static void LIBPNG_LoadPNG_IO(SDL_IOStream *src, struct loadpng_vars *vars)
png_colorp png_palette;
lib.png_get_PLTE(vars->png_ptr, vars->info_ptr, &png_palette, &png_num_palette);
if (color_type == PNG_COLOR_TYPE_GRAY) {
palette = SDL_CreatePalette(256);
palette = SDL_CreateSurfacePalette(vars->surface);
if (!palette) {
vars->error = SDL_GetError();
return;
Expand All @@ -441,7 +441,7 @@ static void LIBPNG_LoadPNG_IO(SDL_IOStream *src, struct loadpng_vars *vars)
palette->colors[i].b = (Uint8)i;
}
} else if (png_num_palette > 0 ) {
palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(vars->surface->format));
palette = SDL_CreateSurfacePalette(vars->surface);
if (!palette) {
vars->error = SDL_GetError();
return;
Expand All @@ -457,10 +457,6 @@ static void LIBPNG_LoadPNG_IO(SDL_IOStream *src, struct loadpng_vars *vars)
palette->colors[i].r = png_palette[i].red;
}
}
if (palette) {
SDL_SetSurfacePalette(vars->surface, palette);
SDL_DestroyPalette(palette);
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/IMG_pnm.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ SDL_Surface *IMG_LoadPNM_IO(SDL_IOStream *src)
ERROR("Out of memory");
bpl = width * SDL_BYTESPERPIXEL(surface->format);
if(kind == PGM) {
SDL_Palette *palette = SDL_CreatePalette(256);
SDL_Palette *palette = SDL_CreateSurfacePalette(surface);
SDL_Color *c;
int i;
if (!palette) {
Expand All @@ -173,8 +173,6 @@ SDL_Surface *IMG_LoadPNM_IO(SDL_IOStream *src)
c = palette->colors;
for(i = 0; i < 256; i++)
c[i].r = c[i].g = c[i].b = i;
SDL_SetSurfacePalette(surface, palette);
SDL_DestroyPalette(palette);
} else if(kind == PBM) {
/* for some reason PBM has 1=black, 0=white */
SDL_Palette *palette = SDL_CreatePalette(2);
Expand Down
8 changes: 2 additions & 6 deletions src/IMG_stb.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src)
SDL_bool has_colorkey = SDL_FALSE;
int colorkey_index = -1;
SDL_bool has_alpha = SDL_FALSE;
SDL_Palette *palette = SDL_CreatePalette(256);
SDL_Palette *palette = SDL_CreateSurfacePalette(surface);
if (palette) {
int i;
Uint8 *palette_bytes = (Uint8 *)palette_colors;
Expand All @@ -171,8 +171,6 @@ SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src)
}
}
}
SDL_SetSurfacePalette(surface, palette);
SDL_DestroyPalette(palette);
}
if (has_alpha) {
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
Expand Down Expand Up @@ -201,7 +199,7 @@ SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src)
if (surface) {
/* Set a grayscale palette for gray images */
if (surface->format == SDL_PIXELFORMAT_INDEX8) {
SDL_Palette *palette = SDL_CreatePalette(256);
SDL_Palette *palette = SDL_CreateSurfacePalette(surface);
if (palette) {
int i;

Expand All @@ -211,8 +209,6 @@ SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src)
palette->colors[i].b = (Uint8)i;
}
}
SDL_SetSurfacePalette(surface, palette);
SDL_DestroyPalette(palette);
}

/* FIXME: This sucks. It'd be better to allocate the surface first, then
Expand Down
8 changes: 4 additions & 4 deletions src/IMG_tga.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,15 @@ SDL_Surface *IMG_LoadTGA_IO(SDL_IOStream *src)
size_t palsiz = ncols * ((hdr.cmap_bits + 7) >> 3);
if (indexed && !grey) {
Uint8 *pal = (Uint8 *)SDL_malloc(palsiz), *p = pal;
SDL_Palette *palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(img->format));
SDL_Palette *palette = SDL_CreateSurfacePalette(img);
if (!palette) {
error = "Couldn't create palette";
SDL_free(pal);
goto error;
}
if (SDL_ReadIO(src, pal, palsiz) != palsiz) {
error = "Error reading TGA data";
SDL_free(pal);
goto error;
}
if (ncols > palette->ncolors) {
Expand Down Expand Up @@ -226,8 +228,6 @@ SDL_Surface *IMG_LoadTGA_IO(SDL_IOStream *src)
}
}
SDL_free(pal);
SDL_SetSurfacePalette(img, palette);
SDL_DestroyPalette(palette);

if (ckey >= 0)
SDL_SetSurfaceColorKey(img, SDL_TRUE, ckey);
Expand All @@ -238,7 +238,7 @@ SDL_Surface *IMG_LoadTGA_IO(SDL_IOStream *src)
}

if (grey) {
SDL_Palette *palette = SDL_CreatePalette(256);
SDL_Palette *palette = SDL_CreateSurfacePalette(img);
SDL_Color *colors;
if (!palette) {
error = "Couldn't create palette";
Expand Down
4 changes: 1 addition & 3 deletions src/IMG_xpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ static SDL_Surface *load_xpm(char **xpm, SDL_IOStream *src, SDL_bool force_32bit
indexed = 1;
image = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_INDEX8);
if (image) {
SDL_Palette *palette = SDL_CreatePalette(1 << SDL_BITSPERPIXEL(image->format));
SDL_Palette *palette = SDL_CreateSurfacePalette(image);
if (!palette) {
error = "Couldn't create palette";
goto done;
Expand All @@ -1066,8 +1066,6 @@ static SDL_Surface *load_xpm(char **xpm, SDL_IOStream *src, SDL_bool force_32bit
}
palette->ncolors = ncolors;
im_colors = palette->colors;
SDL_SetSurfacePalette(image, palette);
SDL_DestroyPalette(palette);
}
} else {
indexed = 0;
Expand Down

0 comments on commit e56f550

Please sign in to comment.