diff --git a/external/SDL b/external/SDL index f437fe75..c80665a6 160000 --- a/external/SDL +++ b/external/SDL @@ -1 +1 @@ -Subproject commit f437fe75f24d89f3fb1c40d2c30e6a406a00f8db +Subproject commit c80665a6968e6274b978846ba77b47c9c61c2618 diff --git a/src/IMG_ImageIO.m b/src/IMG_ImageIO.m index 5f41ae8e..e071d5dd 100644 --- a/src/IMG_ImageIO.m +++ b/src/IMG_ImageIO.m @@ -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; @@ -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); } } diff --git a/src/IMG_gif.c b/src/IMG_gif.c index 09f1ca87..45aa69b1 100644 --- a/src/IMG_gif.c +++ b/src/IMG_gif.c @@ -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; } @@ -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; diff --git a/src/IMG_lbm.c b/src/IMG_lbm.c index eb5adbcd..14269c82 100644 --- a/src/IMG_lbm.c +++ b/src/IMG_lbm.c @@ -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; } @@ -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 */ diff --git a/src/IMG_pcx.c b/src/IMG_pcx.c index ef3aa0e0..b262042b 100644 --- a/src/IMG_pcx.c +++ b/src/IMG_pcx.c @@ -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; @@ -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: diff --git a/src/IMG_png.c b/src/IMG_png.c index 3ccd04cd..3d211d4c 100644 --- a/src/IMG_png.c +++ b/src/IMG_png.c @@ -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; @@ -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; @@ -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); - } } } diff --git a/src/IMG_pnm.c b/src/IMG_pnm.c index b3619a78..48d17515 100644 --- a/src/IMG_pnm.c +++ b/src/IMG_pnm.c @@ -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) { @@ -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); diff --git a/src/IMG_stb.c b/src/IMG_stb.c index 1f772da3..34231527 100644 --- a/src/IMG_stb.c +++ b/src/IMG_stb.c @@ -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; @@ -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); @@ -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; @@ -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 diff --git a/src/IMG_tga.c b/src/IMG_tga.c index 4ce6fb70..cf37e6ca 100644 --- a/src/IMG_tga.c +++ b/src/IMG_tga.c @@ -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) { @@ -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); @@ -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"; diff --git a/src/IMG_xpm.c b/src/IMG_xpm.c index e6c83cef..e5aa4fe1 100644 --- a/src/IMG_xpm.c +++ b/src/IMG_xpm.c @@ -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; @@ -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;