@ -0,0 +1,26 @@
|
||||
include(FetchContent_MakeAvailableExcludeFromAll) |
||||
|
||||
include(FetchContent) |
||||
if(USE_SDL1) |
||||
FetchContent_Declare(SDL_image |
||||
URL https://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.12.tar.gz |
||||
URL_HASH MD5=a0f9098ebe5400f0bdc9b62e60797ecb |
||||
) |
||||
else() |
||||
FetchContent_Declare(SDL_image |
||||
URL https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.tar.gz |
||||
URL_HASH MD5=f26f3a153360a8f09ed5220ef7b07aea |
||||
) |
||||
endif() |
||||
FetchContent_MakeAvailableExcludeFromAll(SDL_image) |
||||
|
||||
add_library(SDL_image STATIC ${CMAKE_CURRENT_LIST_DIR}/IMG.c ${sdl_image_SOURCE_DIR}/IMG_png.c) |
||||
target_include_directories(SDL_image PRIVATE ${sdl_image_SOURCE_DIR}) |
||||
target_compile_definitions(SDL_image PRIVATE LOAD_PNG SDL_IMAGE_USE_COMMON_BACKEND) |
||||
target_link_libraries(SDL_image PNG::PNG) |
||||
|
||||
if(USE_SDL1) |
||||
target_link_libraries(SDL_image ${SDL_LIBRARY}) |
||||
else() |
||||
target_link_libraries(SDL_image SDL2::SDL2) |
||||
endif() |
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
SDL_image: An example image loading library for use with SDL |
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org> |
||||
This software is provided 'as-is', without any express or implied |
||||
warranty. In no event will the authors be held liable for any damages |
||||
arising from the use of this software. |
||||
Permission is granted to anyone to use this software for any purpose, |
||||
including commercial applications, and to alter it and redistribute it |
||||
freely, subject to the following restrictions: |
||||
1. The origin of this software must not be misrepresented; you must not |
||||
claim that you wrote the original software. If you use this software |
||||
in a product, an acknowledgment in the product documentation would be |
||||
appreciated but is not required. |
||||
2. Altered source versions must be plainly marked as such, and must not be |
||||
misrepresented as being the original software. |
||||
3. This notice may not be removed or altered from any source distribution. |
||||
*/ |
||||
|
||||
/* This is a heavily reduced version of IMG.c including only PNG support */ |
||||
|
||||
#include "SDL_image.h" |
||||
|
||||
extern int IMG_InitPNG(void); |
||||
extern void IMG_QuitPNG(void); |
||||
|
||||
static int initialized = 0; |
||||
|
||||
int IMG_Init(int flags) { |
||||
int result = 0; |
||||
|
||||
/* Passing 0 returns the currently initialized loaders */ |
||||
if (!flags) { |
||||
return initialized; |
||||
} |
||||
|
||||
if (flags & IMG_INIT_PNG) { |
||||
if ((initialized & IMG_INIT_PNG) || IMG_InitPNG() == 0) { |
||||
result |= IMG_INIT_PNG; |
||||
} |
||||
} |
||||
initialized |= result; |
||||
|
||||
return result; |
||||
} |
||||
|
||||
void IMG_Quit() { |
||||
if (initialized & IMG_INIT_PNG) { |
||||
IMG_QuitPNG(); |
||||
} |
||||
initialized = 0; |
||||
} |
||||
@ -0,0 +1,31 @@
|
||||
include(FetchContent_MakeAvailableExcludeFromAll) |
||||
|
||||
if(NOT DISABLE_LTO) |
||||
# Force CMake to raise an error if INTERPROCEDURAL_OPTIMIZATION |
||||
# is enabled and compiler does not support IPO |
||||
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) |
||||
endif() |
||||
|
||||
if(DEVILUTIONX_STATIC_LIBPNG) |
||||
set(PNG_LIBRARY png_static) |
||||
set(PNG_STATIC ON CACHE BOOL "Build static lib" FORCE) |
||||
set(PNG_SHARED OFF CACHE BOOL "Build shared lib" FORCE) |
||||
else() |
||||
set(PNG_LIBRARY png) |
||||
set(PNG_STATIC OFF CACHE BOOL "Build static lib" FORCE) |
||||
set(PNG_SHARED ON CACHE BOOL "Build shared lib" FORCE) |
||||
endif() |
||||
set(PNG_TESTS OFF CACHE BOOL "Build libpng tests") |
||||
|
||||
include(FetchContent) |
||||
FetchContent_Declare(png |
||||
URL https://github.com/StephenCWills/libpng/archive/5cfc16530ae7f2c1f1c88ecd08b0fde2e2a4cd93.tar.gz |
||||
URL_HASH MD5=e98756c6316f51ca9c045bb2f1bdf307 |
||||
) |
||||
FetchContent_MakeAvailableExcludeFromAll(png) |
||||
|
||||
target_include_directories(${PNG_LIBRARY} INTERFACE |
||||
$<BUILD_INTERFACE:${png_SOURCE_DIR}> |
||||
$<BUILD_INTERFACE:${png_BINARY_DIR}>) |
||||
|
||||
add_library(PNG::PNG ALIAS ${PNG_LIBRARY}) |
||||
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 16 KiB |
@ -0,0 +1,50 @@
|
||||
#pragma once |
||||
|
||||
#include <SDL.h> |
||||
|
||||
#include "miniwin/miniwin.h" |
||||
#include "storm/storm.h" |
||||
#include "storm/storm_sdl_rw.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
const int IMG_INIT_PNG = 0x00000002; |
||||
|
||||
int IMG_Init(int flags); |
||||
void IMG_Quit(void); |
||||
int IMG_isPNG(SDL_RWops *src); |
||||
SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src); |
||||
int IMG_SavePNG(SDL_Surface *surface, const char *file); |
||||
int IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst); |
||||
|
||||
inline SDL_Surface *IMG_LoadPNG(const char *file) |
||||
{ |
||||
SDL_RWops *src = SDL_RWFromFile(file, "rb"); |
||||
return IMG_LoadPNG_RW(src); |
||||
} |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
namespace devilution { |
||||
|
||||
inline int InitPNG() |
||||
{ |
||||
return IMG_Init(IMG_INIT_PNG); |
||||
} |
||||
|
||||
inline void QuitPNG() |
||||
{ |
||||
IMG_Quit(); |
||||
} |
||||
|
||||
inline SDL_Surface *LoadPNG(const char *file) |
||||
{ |
||||
SDL_RWops *rwops = SFileOpenRw(file); |
||||
return IMG_LoadPNG_RW(rwops); |
||||
} |
||||
|
||||
} // namespace devilution
|
||||