Remove SDL2 image and use stb_image instead

This commit is contained in:
Rafael Brune 2024-04-24 23:32:20 +02:00
parent 0eb31e67cf
commit 4857514dbb
10 changed files with 9737 additions and 39 deletions

View File

@ -12,7 +12,6 @@ dep_sdl = dependency('sdl2')
base_deps = [
dependency('gl'),
dep_sdl,
dependency('SDL2_image'),
meson.get_compiler('c').find_library('m', required: false),
]

View File

@ -55,11 +55,12 @@ COMMONFLAGS = -MMD \
-I ../src/ThirdParty/CRC/ \
-I ../src/ThirdParty/LZSS/ \
-I ../src/ThirdParty/Titan/ \
-I ../src/ThirdParty/stb/ \
-I .
EMXX = gcc
EMXXFLAGS = $(COMMONFLAGS) -O0 -ggdb3 `sdl2-config --cflags` -mconsole
EMXXLINK = -O0 -ggdb3 -lSDL2main -lSDL2 -lSDL2_image `sdl2-config --libs` -lopengl32 -mconsole
EMXXLINK = -O0 -ggdb3 -lSDL2main -lSDL2 `sdl2-config --libs` -lopengl32 -mconsole
KAS2CFLAGS = -O0 -ggdb3 `sdl2-config --cflags` -lSDL2main -lSDL2 `sdl2-config --libs` -mconsole

View File

@ -7,11 +7,7 @@
=============================================================================*/
#include <SDL2/SDL.h>
#ifdef __APPLE__
#include <SDL2_image/SDL_image.h>
#else
#include <SDL2/SDL_image.h>
#endif
#include "stb_image.h"
#include "HorseRace.h"
@ -748,6 +744,7 @@ void hrInitBackground(void)
filehandle handle;
ubyte *fileData;
udword i;
int width, height, channels;
getcwd(CurDir, PATH_MAX);
@ -769,11 +766,10 @@ void hrInitBackground(void)
{
uint32_t fileSize = fileLoadAlloc(hrImageName, (void**)&fileData, 0);
SDL_RWops *rwOp = SDL_RWFromMem(fileData, fileSize);
SDL_Surface *surface = IMG_Load_RW(rwOp, 0);
unsigned char *pixels = stbi_load_from_memory(fileData, fileSize, &width, &height, &channels, 3);
hrBackXSize = surface->w;
hrBackYSize = surface->h;
hrBackXSize = width;
hrBackYSize = height;
glGenTextures(1, &hrBackgroundTexture);
trClearCurrent();
@ -783,10 +779,9 @@ void hrInitBackground(void)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, hrBackXSize, hrBackYSize,
0, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
SDL_RWclose(rwOp);
SDL_FreeSurface(surface);
stbi_image_free(pixels);
memFree(fileData);
hrBackXFrac = 1.0f;

View File

@ -6,11 +6,7 @@
Copyright Relic Entertainment, Inc. All rights reserved.
=============================================================================*/
#include <SDL2/SDL.h>
#ifdef __APPLE__
#include <SDL2_image/SDL_image.h>
#else
#include <SDL2/SDL_image.h>
#endif
#include "stb_image.h"
#include "PlugScreen.h"
@ -341,6 +337,7 @@ void psImageLoad(psimage *destImage, char *directory, char *imageName)
color quiltBuffer[PS_QuiltPieceHeight * PS_QuiltPieceWidth];
char fileName[80];
sdword bFilterSave;
int width, height, channels;
strcpy(fileName, directory); //prepare file name
if (bitTest(psGlobalFlags, PMF_LanguageSpecific))
@ -351,15 +348,14 @@ void psImageLoad(psimage *destImage, char *directory, char *imageName)
uint32_t fileSize = fileLoadAlloc(fileName, (void**)&fileData, 0);
SDL_RWops *rwOp = SDL_RWFromMem(fileData, fileSize);
SDL_Surface *surface = IMG_Load_RW(rwOp, 0);
//alloc a buffer to load the image to
imageBuffer = surface->pixels;
unsigned char *pixels = stbi_load_from_memory(fileData, fileSize, &width, &height, &channels, 3);
destImage->width = surface->w;
destImage->height = surface->h;
//alloc a buffer to load the image to
imageBuffer = pixels;
destImage->width = width;
destImage->height = height;
SDL_RWclose(rwOp);
memFree(fileData);
bFilterSave = texLinearFiltering;
@ -396,7 +392,7 @@ void psImageLoad(psimage *destImage, char *directory, char *imageName)
}
}
texLinearFiltering = bFilterSave;
SDL_FreeSurface(surface);
stbi_image_free(pixels);
}
/*-----------------------------------------------------------------------------

View File

@ -30,6 +30,6 @@ lib_sdl = static_library('hw_sdl',
src_sdl,
c_args: c_args,
dependencies: [dep_sdl],
include_directories: ['../Game', '../Ships', '../ThirdParty/CRC'])
include_directories: ['../Game', '../Ships', '../ThirdParty/CRC', '../ThirdParty/stb'])
inc_src_sdl = include_directories('.')

View File

@ -7,11 +7,11 @@
// =============================================================================
#include <SDL2/SDL.h>
#ifdef __APPLE__
#include <SDL2_image/SDL_image.h>
#else
#include <SDL2/SDL_image.h>
#endif
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include "screenshot.h"
@ -119,11 +119,7 @@ static void _ssSaveScreenshot(ubyte* buf, const char* targetFilename)
}
free(pTempLine);
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(buf, MAIN_WindowWidth, MAIN_WindowHeight, 24, 3 * MAIN_WindowWidth, 0x0000FF, 0x00FF00, 0xFF0000, 0);
IMG_SaveJPG(surface, fname, 100);
SDL_FreeSurface(surface);
stbi_write_jpg(fname, MAIN_WindowWidth, MAIN_WindowHeight, 3, buf, 100);
}

View File

@ -1,7 +1,8 @@
subdir('CRC')
subdir('LZSS')
subdir('Titan')
subdir('stb')
src_third_party = [src_third_party_crc, src_third_party_lzss]
inc_src_third_party = [inc_src_third_party_crc, inc_src_third_party_lzss, inc_src_third_party_titan]
inc_src_third_party = [inc_src_third_party_crc, inc_src_third_party_lzss, inc_src_third_party_titan, inc_src_third_party_stb]

1
src/ThirdParty/stb/meson.build vendored Normal file
View File

@ -0,0 +1 @@
inc_src_third_party_stb = include_directories('.')

7985
src/ThirdParty/stb/stb_image.h vendored Normal file

File diff suppressed because it is too large Load Diff

1724
src/ThirdParty/stb/stb_image_write.h vendored Normal file

File diff suppressed because it is too large Load Diff