mirror of
				https://github.com/HomeworldSDL/HomeworldSDL.git
				synced 2025-10-30 03:58:27 +00:00 
			
		
		
		
	Remove SDL2 image and use stb_image instead
This commit is contained in:
		
							parent
							
								
									0eb31e67cf
								
							
						
					
					
						commit
						4857514dbb
					
				| @ -12,7 +12,6 @@ dep_sdl = dependency('sdl2') | |||||||
| base_deps = [ | base_deps = [ | ||||||
| 	dependency('gl'), | 	dependency('gl'), | ||||||
| 	dep_sdl, | 	dep_sdl, | ||||||
| 	dependency('SDL2_image'), |  | ||||||
| 	meson.get_compiler('c').find_library('m', required: false), | 	meson.get_compiler('c').find_library('m', required: false), | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -55,11 +55,12 @@ COMMONFLAGS = -MMD \ | |||||||
|               -I ../src/ThirdParty/CRC/ \
 |               -I ../src/ThirdParty/CRC/ \
 | ||||||
|               -I ../src/ThirdParty/LZSS/ \
 |               -I ../src/ThirdParty/LZSS/ \
 | ||||||
|               -I ../src/ThirdParty/Titan/ \
 |               -I ../src/ThirdParty/Titan/ \
 | ||||||
|  |               -I ../src/ThirdParty/stb/ \
 | ||||||
|               -I . |               -I . | ||||||
| 
 | 
 | ||||||
| EMXX = gcc | EMXX = gcc | ||||||
| EMXXFLAGS = $(COMMONFLAGS) -O0 -ggdb3 `sdl2-config --cflags` -mconsole | 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 | KAS2CFLAGS = -O0 -ggdb3 `sdl2-config --cflags` -lSDL2main -lSDL2 `sdl2-config --libs` -mconsole | ||||||
|  | |||||||
| @ -7,11 +7,7 @@ | |||||||
| =============================================================================*/ | =============================================================================*/ | ||||||
| 
 | 
 | ||||||
| #include <SDL2/SDL.h> | #include <SDL2/SDL.h> | ||||||
| #ifdef __APPLE__ | #include "stb_image.h" | ||||||
| #include <SDL2_image/SDL_image.h> |  | ||||||
| #else |  | ||||||
| #include <SDL2/SDL_image.h> |  | ||||||
| #endif |  | ||||||
| 
 | 
 | ||||||
| #include "HorseRace.h" | #include "HorseRace.h" | ||||||
| 
 | 
 | ||||||
| @ -748,6 +744,7 @@ void hrInitBackground(void) | |||||||
|     filehandle handle; |     filehandle handle; | ||||||
|     ubyte *fileData; |     ubyte *fileData; | ||||||
|     udword i; |     udword i; | ||||||
|  |     int width, height, channels; | ||||||
| 
 | 
 | ||||||
|     getcwd(CurDir, PATH_MAX); |     getcwd(CurDir, PATH_MAX); | ||||||
| 
 | 
 | ||||||
| @ -769,11 +766,10 @@ void hrInitBackground(void) | |||||||
|     { |     { | ||||||
|         uint32_t fileSize = fileLoadAlloc(hrImageName, (void**)&fileData, 0); |         uint32_t fileSize = fileLoadAlloc(hrImageName, (void**)&fileData, 0); | ||||||
| 
 | 
 | ||||||
|         SDL_RWops *rwOp = SDL_RWFromMem(fileData, fileSize); |         unsigned char *pixels = stbi_load_from_memory(fileData, fileSize, &width, &height, &channels, 3); | ||||||
|         SDL_Surface *surface = IMG_Load_RW(rwOp, 0); |  | ||||||
|          |          | ||||||
|         hrBackXSize = surface->w; |         hrBackXSize = width; | ||||||
|         hrBackYSize = surface->h; |         hrBackYSize = height; | ||||||
| 
 | 
 | ||||||
|         glGenTextures(1, &hrBackgroundTexture); |         glGenTextures(1, &hrBackgroundTexture); | ||||||
|         trClearCurrent(); |         trClearCurrent(); | ||||||
| @ -783,10 +779,9 @@ void hrInitBackground(void) | |||||||
|         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||||||
|         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||||
|         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, hrBackXSize, hrBackYSize, |         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); |         stbi_image_free(pixels); | ||||||
|         SDL_FreeSurface(surface); |  | ||||||
|         memFree(fileData); |         memFree(fileData); | ||||||
|          |          | ||||||
|         hrBackXFrac = 1.0f; |         hrBackXFrac = 1.0f; | ||||||
|  | |||||||
| @ -6,11 +6,7 @@ | |||||||
|     Copyright Relic Entertainment, Inc.  All rights reserved. |     Copyright Relic Entertainment, Inc.  All rights reserved. | ||||||
| =============================================================================*/ | =============================================================================*/ | ||||||
| #include <SDL2/SDL.h> | #include <SDL2/SDL.h> | ||||||
| #ifdef __APPLE__ | #include "stb_image.h" | ||||||
| #include <SDL2_image/SDL_image.h> |  | ||||||
| #else |  | ||||||
| #include <SDL2/SDL_image.h> |  | ||||||
| #endif |  | ||||||
| 
 | 
 | ||||||
| #include "PlugScreen.h" | #include "PlugScreen.h" | ||||||
| 
 | 
 | ||||||
| @ -341,6 +337,7 @@ void psImageLoad(psimage *destImage, char *directory, char *imageName) | |||||||
|     color quiltBuffer[PS_QuiltPieceHeight * PS_QuiltPieceWidth]; |     color quiltBuffer[PS_QuiltPieceHeight * PS_QuiltPieceWidth]; | ||||||
|     char fileName[80]; |     char fileName[80]; | ||||||
|     sdword bFilterSave; |     sdword bFilterSave; | ||||||
|  |     int width, height, channels; | ||||||
| 
 | 
 | ||||||
|     strcpy(fileName, directory);                            //prepare file name
 |     strcpy(fileName, directory);                            //prepare file name
 | ||||||
|     if (bitTest(psGlobalFlags, PMF_LanguageSpecific)) |     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); |     uint32_t fileSize = fileLoadAlloc(fileName, (void**)&fileData, 0); | ||||||
| 
 | 
 | ||||||
|     SDL_RWops *rwOp = SDL_RWFromMem(fileData, fileSize); |     unsigned char *pixels = stbi_load_from_memory(fileData, fileSize, &width, &height, &channels, 3); | ||||||
|     SDL_Surface *surface = IMG_Load_RW(rwOp, 0); |  | ||||||
|                                                             //alloc a buffer to load the image to
 |  | ||||||
|     imageBuffer = surface->pixels; |  | ||||||
| 
 | 
 | ||||||
|     destImage->width = surface->w; |                                                             //alloc a buffer to load the image to
 | ||||||
|     destImage->height = surface->h; |     imageBuffer = pixels; | ||||||
|  | 
 | ||||||
|  |     destImage->width = width; | ||||||
|  |     destImage->height = height; | ||||||
|      |      | ||||||
|     SDL_RWclose(rwOp); |  | ||||||
|     memFree(fileData); |     memFree(fileData); | ||||||
| 
 | 
 | ||||||
|     bFilterSave = texLinearFiltering; |     bFilterSave = texLinearFiltering; | ||||||
| @ -396,7 +392,7 @@ void psImageLoad(psimage *destImage, char *directory, char *imageName) | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     texLinearFiltering = bFilterSave; |     texLinearFiltering = bFilterSave; | ||||||
|     SDL_FreeSurface(surface); |     stbi_image_free(pixels); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /*-----------------------------------------------------------------------------
 | /*-----------------------------------------------------------------------------
 | ||||||
|  | |||||||
| @ -30,6 +30,6 @@ lib_sdl = static_library('hw_sdl', | |||||||
|                          src_sdl, |                          src_sdl, | ||||||
|                          c_args: c_args, |                          c_args: c_args, | ||||||
|                          dependencies: [dep_sdl], |                          dependencies: [dep_sdl], | ||||||
|                          include_directories: ['../Game', '../Ships', '../ThirdParty/CRC']) |                          include_directories: ['../Game', '../Ships', '../ThirdParty/CRC', '../ThirdParty/stb']) | ||||||
| 
 | 
 | ||||||
| inc_src_sdl = include_directories('.') | inc_src_sdl = include_directories('.') | ||||||
|  | |||||||
| @ -7,11 +7,11 @@ | |||||||
| // =============================================================================
 | // =============================================================================
 | ||||||
| 
 | 
 | ||||||
| #include <SDL2/SDL.h> | #include <SDL2/SDL.h> | ||||||
| #ifdef __APPLE__ | 
 | ||||||
| #include <SDL2_image/SDL_image.h> | #define STB_IMAGE_IMPLEMENTATION | ||||||
| #else | #include "stb_image.h" | ||||||
| #include <SDL2/SDL_image.h> | #define STB_IMAGE_WRITE_IMPLEMENTATION | ||||||
| #endif | #include "stb_image_write.h"         | ||||||
| 
 | 
 | ||||||
| #include "screenshot.h" | #include "screenshot.h" | ||||||
| 
 | 
 | ||||||
| @ -119,11 +119,7 @@ static void _ssSaveScreenshot(ubyte* buf, const char* targetFilename) | |||||||
|     } |     } | ||||||
|     free(pTempLine); |     free(pTempLine); | ||||||
| 
 | 
 | ||||||
|     SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(buf, MAIN_WindowWidth, MAIN_WindowHeight, 24, 3 * MAIN_WindowWidth, 0x0000FF, 0x00FF00, 0xFF0000, 0); |     stbi_write_jpg(fname, MAIN_WindowWidth, MAIN_WindowHeight, 3, buf, 100); | ||||||
|      |  | ||||||
|     IMG_SaveJPG(surface, fname, 100); |  | ||||||
|      |  | ||||||
|     SDL_FreeSurface(surface); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								src/ThirdParty/meson.build
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								src/ThirdParty/meson.build
									
									
									
									
										vendored
									
									
								
							| @ -1,7 +1,8 @@ | |||||||
| subdir('CRC') | subdir('CRC') | ||||||
| subdir('LZSS') | subdir('LZSS') | ||||||
| subdir('Titan') | subdir('Titan') | ||||||
|  | subdir('stb') | ||||||
| 
 | 
 | ||||||
| src_third_party = [src_third_party_crc, src_third_party_lzss] | 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
									
								
							
							
						
						
									
										1
									
								
								src/ThirdParty/stb/meson.build
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | inc_src_third_party_stb = include_directories('.') | ||||||
							
								
								
									
										7985
									
								
								src/ThirdParty/stb/stb_image.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										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
									
								
							
							
						
						
									
										1724
									
								
								src/ThirdParty/stb/stb_image_write.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user