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 10, 2024
1 parent b10d7cd commit 9c8ba95
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 78 deletions.
2 changes: 1 addition & 1 deletion examples/showimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int main(int argc, char *argv[])

/* Use the tonemap operator to convert to SDR output */
SDL_SetStringProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING, tonemap);
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32);
temp = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
SDL_DestroySurface(surface);
if (!temp) {
SDL_Log("Couldn't convert surface: %s\n", SDL_GetError());
Expand Down
2 changes: 1 addition & 1 deletion external/SDL
Submodule SDL updated 217 files
2 changes: 1 addition & 1 deletion 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)
const uint8_t* bytes = [data bytes];
size_t i;

palette = surface->format->palette;
palette = SDL_GetSurfacePalette(surface);
for (i = 0, entry = entries; i < num_entries; ++i) {
palette->colors[i].r = entry[0];
palette->colors[i].g = entry[1];
Expand Down
22 changes: 10 additions & 12 deletions src/IMG_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int
avifEncoder *encoder = NULL;
avifRWData avifOutput = AVIF_DATA_EMPTY;
avifResult rc;
const Uint32 surface_format = surface->format->format;
SDL_Colorspace colorspace;
Uint16 maxCLL, maxFALL;
SDL_PropertiesID props;
Expand Down Expand Up @@ -557,7 +556,7 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int
SDL_zero(rgb);
lib.avifRGBImageSetDefaults(&rgb, image);

if (SDL_ISPIXELFORMAT_10BIT(surface_format)) {
if (SDL_ISPIXELFORMAT_10BIT(surface->format)) {
const Uint16 expand_alpha[] = {
0, 0x155, 0x2aa, 0x3ff
};
Expand All @@ -571,13 +570,13 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int
image->depth = 10;
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_IDENTITY;

if (SDL_PIXELORDER(surface_format) == SDL_PACKEDORDER_XRGB ||
SDL_PIXELORDER(surface_format) == SDL_PACKEDORDER_ARGB) {
if (SDL_PIXELORDER(surface->format) == SDL_PACKEDORDER_XRGB ||
SDL_PIXELORDER(surface->format) == SDL_PACKEDORDER_ARGB) {
rgb.format = AVIF_RGB_FORMAT_RGBA;
} else {
rgb.format = AVIF_RGB_FORMAT_BGRA;
}
rgb.ignoreAlpha = SDL_ISPIXELFORMAT_ALPHA(surface_format) ? SDL_FALSE : SDL_TRUE;
rgb.ignoreAlpha = SDL_ISPIXELFORMAT_ALPHA(surface->format) ? SDL_FALSE : SDL_TRUE;
rgb.depth = 10;
rgb.rowBytes = (uint32_t)image->width * 4 * sizeof(Uint16);
rgb.pixels = (uint8_t *)SDL_malloc(image->height * rgb.rowBytes);
Expand Down Expand Up @@ -612,7 +611,7 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int
SDL_Surface *temp = NULL;

rgb.depth = 8;
switch (surface_format) {
switch (surface->format) {
case SDL_PIXELFORMAT_RGBX32:
case SDL_PIXELFORMAT_RGBA32:
rgb.format = AVIF_RGB_FORMAT_RGBA;
Expand All @@ -636,17 +635,17 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int
default:
/* Need to convert to a format libavif understands */
rgb.format = AVIF_RGB_FORMAT_RGBA;
if (SDL_ISPIXELFORMAT_ALPHA(surface_format)) {
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32);
if (SDL_ISPIXELFORMAT_ALPHA(surface->format)) {
temp = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
} else {
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBX32);
temp = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBX32);
}
if (!temp) {
goto done;
}
break;
}
rgb.ignoreAlpha = SDL_ISPIXELFORMAT_ALPHA(surface_format) ? SDL_FALSE : SDL_TRUE;
rgb.ignoreAlpha = SDL_ISPIXELFORMAT_ALPHA(surface->format) ? SDL_FALSE : SDL_TRUE;
rgb.pixels = (uint8_t *)temp->pixels;
rgb.rowBytes = (uint32_t)temp->pitch;

Expand Down Expand Up @@ -755,11 +754,10 @@ int IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int qu
return IMG_SetError("Passed NULL dst");
}

#if SDL_IMAGE_SAVE_AVIF
#ifdef SDL_IMAGE_SAVE_AVIF
if (result < 0) {
result = IMG_SaveAVIF_IO_libavif(surface, dst, quality);
}

#else
(void) surface;
(void) quality;
Expand Down
14 changes: 8 additions & 6 deletions src/IMG_gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
#define RWSetMsg IMG_SetError
#define ImageNewCmap(w, h, s) SDL_CreateSurface(w, h, SDL_PIXELFORMAT_INDEX8)
#define ImageSetCmap(s, i, R, G, B) do { \
s->format->palette->colors[i].r = R; \
s->format->palette->colors[i].g = G; \
s->format->palette->colors[i].b = B; \
palette->colors[i].r = R; \
palette->colors[i].g = G; \
palette->colors[i].b = B; \
} while (0)
/* * * * * */

Expand Down Expand Up @@ -149,15 +149,15 @@ static SDL_bool NormalizeFrames(Frame_t *frames, int count)


if (SDL_SurfaceHasColorKey(frames[0].image)) {
image = SDL_ConvertSurfaceFormat(frames[0].image, SDL_PIXELFORMAT_ARGB8888);
image = SDL_ConvertSurface(frames[0].image, SDL_PIXELFORMAT_ARGB8888);
} else {
image = SDL_ConvertSurfaceFormat(frames[0].image, SDL_PIXELFORMAT_XRGB8888);
image = SDL_ConvertSurface(frames[0].image, SDL_PIXELFORMAT_XRGB8888);
}
if (!image) {
return SDL_FALSE;
}

fill = SDL_MapRGBA(image->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
fill = SDL_MapSurfaceRGBA(image, 0, 0, 0, SDL_ALPHA_TRANSPARENT);

rect.x = 0;
rect.y = 0;
Expand Down Expand Up @@ -614,6 +614,7 @@ ReadImage(SDL_IOStream * src, int len, int height, int cmapSize,
int gray, int interlace, int ignore, State_t * state)
{
Image *image;
SDL_Palette *palette;
unsigned char c;
int i, v;
int xpos = 0, ypos = 0, pass = 0;
Expand Down Expand Up @@ -647,6 +648,7 @@ ReadImage(SDL_IOStream * src, int len, int height, int cmapSize,
SDL_DestroySurface(image);
return NULL;
}
palette = SDL_GetSurfacePalette(image);

for (i = 0; i < cmapSize; i++)
ImageSetCmap(image, i, cmap[CM_RED][i],
Expand Down
8 changes: 4 additions & 4 deletions src/IMG_jpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ static int IMG_SaveJPG_IO_jpeglib(SDL_Surface *surface, SDL_IOStream *dst, int q
}

/* Convert surface to format we can save */
if (surface->format->format != jpg_format) {
jpeg_surface = SDL_ConvertSurfaceFormat(surface, jpg_format);
if (surface->format != jpg_format) {
jpeg_surface = SDL_ConvertSurface(surface, jpg_format);
if (!jpeg_surface) {
return -1;
}
Expand Down Expand Up @@ -715,8 +715,8 @@ static int IMG_SaveJPG_IO_tinyjpeg(SDL_Surface *surface, SDL_IOStream *dst, int
int result = -1;

/* Convert surface to format we can save */
if (surface->format->format != jpg_format) {
jpeg_surface = SDL_ConvertSurfaceFormat(surface, jpg_format);
if (surface->format != jpg_format) {
jpeg_surface = SDL_ConvertSurface(surface, jpg_format);
if (!jpeg_surface) {
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/IMG_jxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src)
break;
case JXL_DEC_SUCCESS:
/* All done! */
surface = SDL_CreateSurfaceFrom(pixels, info.xsize, info.ysize, pitch, SDL_PIXELFORMAT_RGBA32);
surface = SDL_CreateSurfaceFrom(info.xsize, info.ysize, SDL_PIXELFORMAT_RGBA32, pixels, pitch);
if (surface) {
/* Let SDL manage the memory now */
pixels = NULL;
surface->flags &= ~SDL_PREALLOC;
surface->flags &= ~SDL_SURFACE_PREALLOCATED;
}
goto done;
default:
Expand Down
21 changes: 11 additions & 10 deletions src/IMG_lbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,16 @@ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src )
/* There is no palette in 24 bits ILBM file */
if ( nbcolors>0 && flagHAM==0 )
{
SDL_Palette *palette = SDL_GetSurfacePalette(Image);
/* FIXME: Should this include the stencil? See comment below */
int nbrcolorsfinal = 1 << (nbplanes + stencil);
ptr = &colormap[0];

for ( i=0; i<nbcolors; i++ )
{
Image->format->palette->colors[i].r = *ptr++;
Image->format->palette->colors[i].g = *ptr++;
Image->format->palette->colors[i].b = *ptr++;
palette->colors[i].r = *ptr++;
palette->colors[i].g = *ptr++;
palette->colors[i].b = *ptr++;
}

/* Amiga EHB mode (Extra-Half-Bright) */
Expand All @@ -295,9 +296,9 @@ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src )
ptr = &colormap[0];
for ( i=32; i<64; i++ )
{
Image->format->palette->colors[i].r = (*ptr++)/2;
Image->format->palette->colors[i].g = (*ptr++)/2;
Image->format->palette->colors[i].b = (*ptr++)/2;
palette->colors[i].r = (*ptr++)/2;
palette->colors[i].g = (*ptr++)/2;
palette->colors[i].b = (*ptr++)/2;
}
}

Expand All @@ -308,12 +309,12 @@ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src )
}
for ( i=nbcolors; i < (Uint32)nbrcolorsfinal; i++ )
{
Image->format->palette->colors[i].r = Image->format->palette->colors[i%nbcolors].r;
Image->format->palette->colors[i].g = Image->format->palette->colors[i%nbcolors].g;
Image->format->palette->colors[i].b = Image->format->palette->colors[i%nbcolors].b;
palette->colors[i].r = palette->colors[i%nbcolors].r;
palette->colors[i].g = palette->colors[i%nbcolors].g;
palette->colors[i].b = palette->colors[i%nbcolors].b;
}
if ( !pbm )
Image->format->palette->ncolors = nbrcolorsfinal;
palette->ncolors = nbrcolorsfinal;
}

/* Get the bitmap */
Expand Down
5 changes: 3 additions & 2 deletions src/IMG_pcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,12 @@ SDL_Surface *IMG_LoadPCX_IO(SDL_IOStream *src)
}

if ( bits == 8 ) {
SDL_Color *colors = surface->format->palette->colors;
SDL_Palette *palette = SDL_GetSurfacePalette(surface);
SDL_Color *colors = palette->colors;
int nc = 1 << src_bits;
int i;

surface->format->palette->ncolors = nc;
palette->ncolors = nc;
if ( src_bits == 8 ) {
Uint8 pch;
Uint8 colormap[768];
Expand Down
24 changes: 12 additions & 12 deletions src/IMG_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static void LIBPNG_LoadPNG_IO(SDL_IOStream *src, struct loadpng_vars *vars)
if (ckey != -1) {
if (color_type != PNG_COLOR_TYPE_PALETTE) {
/* FIXME: Should these be truncated or shifted down? */
ckey = SDL_MapRGB(vars->surface->format,
ckey = SDL_MapSurfaceRGB(vars->surface,
(Uint8)transv->red,
(Uint8)transv->green,
(Uint8)transv->blue);
Expand Down Expand Up @@ -425,7 +425,7 @@ static void LIBPNG_LoadPNG_IO(SDL_IOStream *src, struct loadpng_vars *vars)
*/

/* Load the palette, if any */
palette = vars->surface->format->palette;
palette = SDL_GetSurfacePalette(vars->surface);
if ( palette ) {
int png_num_palette;
png_colorp png_palette;
Expand Down Expand Up @@ -621,7 +621,7 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD
return -1;
}

palette = surface->format->palette;
palette = SDL_GetSurfacePalette(surface);
if (palette) {
const int ncolors = palette->ncolors;
int i;
Expand Down Expand Up @@ -650,21 +650,21 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD
lib.png_set_tRNS(vars->png_ptr, vars->info_ptr, transparent_table, last_transparent + 1, NULL);
}
}
else if (surface->format->format == SDL_PIXELFORMAT_RGB24) {
else if (surface->format == SDL_PIXELFORMAT_RGB24) {
/* If the surface is exactly the right RGB format it is just passed through */
png_color_type = PNG_COLOR_TYPE_RGB;
}
else if (!SDL_ISPIXELFORMAT_ALPHA(surface->format->format)) {
else if (!SDL_ISPIXELFORMAT_ALPHA(surface->format)) {
/* If the surface is not exactly the right RGB format but does not have alpha
information, it should be converted to RGB24 before being passed through */
png_color_type = PNG_COLOR_TYPE_RGB;
vars->source = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGB24);
vars->source = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGB24);
}
else if (surface->format->format != png_format) {
else if (surface->format != png_format) {
/* Otherwise, (surface has alpha data), and it is not in the exact right
format , so it should be converted to that */
png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
vars->source = SDL_ConvertSurfaceFormat(surface, png_format);
vars->source = SDL_ConvertSurface(surface, png_format);
} else {
png_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
}
Expand Down Expand Up @@ -759,12 +759,12 @@ static int IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst)
return IMG_SetError("Passed NULL dst");
}

if (surface->format->format == png_format) {
png = tdefl_write_image_to_png_file_in_memory(surface->pixels, surface->w, surface->h, surface->format->bytes_per_pixel, surface->pitch, &size);
if (surface->format == png_format) {
png = tdefl_write_image_to_png_file_in_memory(surface->pixels, surface->w, surface->h, SDL_BYTESPERPIXEL(surface->format), surface->pitch, &size);
} else {
SDL_Surface *cvt = SDL_ConvertSurfaceFormat(surface, png_format);
SDL_Surface *cvt = SDL_ConvertSurface(surface, png_format);
if (cvt) {
png = tdefl_write_image_to_png_file_in_memory(cvt->pixels, cvt->w, cvt->h, cvt->format->bytes_per_pixel, cvt->pitch, &size);
png = tdefl_write_image_to_png_file_in_memory(cvt->pixels, cvt->w, cvt->h, SDL_BYTESPERPIXEL(cvt->format), cvt->pitch, &size);
SDL_DestroySurface(cvt);
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/IMG_pnm.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,21 @@ SDL_Surface *IMG_LoadPNM_IO(SDL_IOStream *src)
}
if ( surface == NULL )
ERROR("Out of memory");
bpl = width * surface->format->bytes_per_pixel;
bpl = width * SDL_BYTESPERPIXEL(surface->format);
if(kind == PGM) {
SDL_Color *c = surface->format->palette->colors;
SDL_Palette *palette = SDL_GetSurfacePalette(surface);
SDL_Color *c = palette->colors;
int i;
for(i = 0; i < 256; i++)
c[i].r = c[i].g = c[i].b = i;
surface->format->palette->ncolors = 256;
palette->ncolors = 256;
} else if(kind == PBM) {
/* for some reason PBM has 1=black, 0=white */
SDL_Color *c = surface->format->palette->colors;
SDL_Palette *palette = SDL_GetSurfacePalette(surface);
SDL_Color *c = palette->colors;
c[0].r = c[0].g = c[0].b = 255;
c[1].r = c[1].g = c[1].b = 0;
surface->format->palette->ncolors = 2;
palette->ncolors = 2;
bpl = (width + 7) >> 3;
buf = (Uint8 *)SDL_malloc(bpl);
if(buf == NULL)
Expand Down
10 changes: 5 additions & 5 deletions src/IMG_qoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ SDL_Surface *IMG_LoadQOI_IO(SDL_IOStream *src)
return NULL;
}

surface = SDL_CreateSurfaceFrom(pixel_data,
image_info.width,
surface = SDL_CreateSurfaceFrom(image_info.width,
image_info.height,
(image_info.width * 4),
SDL_PIXELFORMAT_RGBA32);
SDL_PIXELFORMAT_RGBA32,
pixel_data,
(image_info.width * 4));
if ( !surface ) {
QOI_FREE(pixel_data);
IMG_SetError("Couldn't create SDL_Surface");
return NULL;
}

/* Let SDL manage the memory now */
surface->flags &= ~SDL_PREALLOC;
surface->flags &= ~SDL_SURFACE_PREALLOCATED;

return surface;
}
Expand Down
Loading

0 comments on commit 9c8ba95

Please sign in to comment.