Skip to content

Commit ca94ac8

Browse files
committed
Made format save options consistent
Also added new format save options to the Android build
1 parent 432d5e7 commit ca94ac8

File tree

7 files changed

+92
-36
lines changed

7 files changed

+92
-36
lines changed

Android.mk

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ USE_STBIMAGE ?= true
1010
# Enable this if you want to support loading AVIF images
1111
# The library path should be a relative path to this directory.
1212
SUPPORT_AVIF ?= false
13+
SUPPORT_SAVE_AVIF ?= true
1314
AVIF_LIBRARY_PATH := external/libavif
1415
DAV1D_LIBRARY_PATH := external/dav1d
1516

@@ -33,6 +34,7 @@ PNG_LIBRARY_PATH := external/libpng
3334
# Enable this if you want to support loading WebP images
3435
# The library path should be a relative path to this directory.
3536
SUPPORT_WEBP ?= false
37+
SUPPORT_SAVE_WEBP ?= true
3638
WEBP_LIBRARY_PATH := external/libwebp
3739

3840

@@ -95,9 +97,9 @@ LOCAL_SRC_FILES := \
9597

9698
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
9799

98-
LOCAL_CFLAGS := -DLOAD_BMP -DLOAD_GIF -DLOAD_LBM -DLOAD_PCX -DLOAD_PNM \
99-
-DLOAD_SVG -DLOAD_TGA -DLOAD_XCF -DLOAD_XPM -DLOAD_XV \
100-
-DLOAD_QOI
100+
LOCAL_CFLAGS := -DLOAD_BMP -DLOAD_GIF -DSAVE_GIF -DLOAD_LBM -DLOAD_PCX \
101+
-DLOAD_PNM -DLOAD_SVG -DLOAD_TGA -DSAVE_TGA -DLOAD_XCF \
102+
-DLOAD_XPM -DLOAD_XV -DLOAD_QOI
101103
LOCAL_LDLIBS :=
102104
LOCAL_LDFLAGS := -Wl,--no-undefined -Wl,--version-script=$(LOCAL_PATH)/src/SDL_image.sym
103105
LOCAL_STATIC_LIBRARIES :=
@@ -112,6 +114,11 @@ ifeq ($(SUPPORT_AVIF),true)
112114
LOCAL_CFLAGS += -DLOAD_AVIF
113115
LOCAL_STATIC_LIBRARIES += avif
114116
LOCAL_WHOLE_STATIC_LIBRARIES += dav1d dav1d-8bit dav1d-16bit
117+
ifeq ($(SUPPORT_SAVE_AVIF),true)
118+
LOCAL_CFLAGS += -DSAVE_AVIF=1
119+
else
120+
LOCAL_CFLAGS += -DSAVE_AVIF=0
121+
endif
115122
endif
116123

117124
ifeq ($(SUPPORT_JPG),true)
@@ -120,9 +127,9 @@ ifeq ($(SUPPORT_JPG),true)
120127
LOCAL_CFLAGS += -DLOAD_JPG
121128
LOCAL_STATIC_LIBRARIES += jpeg
122129
ifeq ($(SUPPORT_SAVE_JPG),true)
123-
LOCAL_CFLAGS += -DSDL_IMAGE_SAVE_JPG=1
130+
LOCAL_CFLAGS += -DSAVE_JPG=1
124131
else
125-
LOCAL_CFLAGS += -DSDL_IMAGE_SAVE_JPG=0
132+
LOCAL_CFLAGS += -DSAVE_JPG=0
126133
endif
127134
endif
128135

@@ -140,9 +147,9 @@ ifeq ($(SUPPORT_PNG),true)
140147
LOCAL_STATIC_LIBRARIES += png
141148
LOCAL_LDLIBS += -lz
142149
ifeq ($(SUPPORT_SAVE_PNG),true)
143-
LOCAL_CFLAGS += -DSDL_IMAGE_SAVE_PNG=1
150+
LOCAL_CFLAGS += -DSAVE_PNG=1
144151
else
145-
LOCAL_CFLAGS += -DSDL_IMAGE_SAVE_PNG=0
152+
LOCAL_CFLAGS += -DSAVE_PNG=0
146153
endif
147154
endif
148155

@@ -151,6 +158,11 @@ ifeq ($(SUPPORT_WEBP),true)
151158
LOCAL_CFLAGS += -DLOAD_WEBP
152159
LOCAL_STATIC_LIBRARIES += webpdemux
153160
LOCAL_STATIC_LIBRARIES += webp
161+
ifeq ($(SUPPORT_SAVE_WEBP),true)
162+
LOCAL_CFLAGS += -DSAVE_WEBP=1
163+
else
164+
LOCAL_CFLAGS += -DSAVE_WEBP=0
165+
endif
154166
endif
155167

156168
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/include

CMakeLists.txt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ option(SDLIMAGE_XPM "Support loading XPM images" ON)
129129
option(SDLIMAGE_XV "Support loading XV images" ON)
130130

131131
cmake_dependent_option(SDLIMAGE_AVIF_SAVE "Add AVIF save support" ON SDLIMAGE_AVIF OFF)
132+
cmake_dependent_option(SDLIMAGE_GIF_SAVE "Add GIF save support" ON SDLIMAGE_GIF OFF)
132133
cmake_dependent_option(SDLIMAGE_JPG_SAVE "Add JPEG save support" ON SDLIMAGE_JPG OFF)
133134
cmake_dependent_option(SDLIMAGE_PNG_SAVE "Add PNG save support" ON SDLIMAGE_PNG OFF)
135+
cmake_dependent_option(SDLIMAGE_TGA_SAVE "Add TGA save support" ON SDLIMAGE_TGA OFF)
136+
cmake_dependent_option(SDLIMAGE_WEBP_SAVE "Add WEBP save support" ON SDLIMAGE_WEBP OFF)
134137

135138
set(LIBAVIF_MINIMUM_VERSION "1.0")
136139
if(SDLIMAGE_VENDORED AND SDLIMAGE_AVIF)
@@ -599,7 +602,15 @@ list(APPEND SDLIMAGE_BACKENDS GIF)
599602
set(SDLIMAGE_GIF_ENABLED FALSE)
600603
if(SDLIMAGE_GIF)
601604
set(SDLIMAGE_GIF_ENABLED TRUE)
602-
target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_GIF)
605+
if(SDLIMAGE_GIF_ENABLED)
606+
target_compile_definitions(${sdl3_image_target_name} PRIVATE
607+
LOAD_GIF
608+
SAVE_GIF=$<BOOL:${SDLIMAGE_GIF_SAVE}>
609+
)
610+
else()
611+
# Variable is used by test suite
612+
set(SDLIMAGE_GIF_SAVE OFF)
613+
endif()
603614
endif()
604615

605616
list(APPEND SDLIMAGE_BACKENDS JPG)
@@ -661,7 +672,7 @@ if(SDLIMAGE_JPG)
661672
if(SDLIMAGE_JPG_ENABLED)
662673
target_compile_definitions(${sdl3_image_target_name} PRIVATE
663674
LOAD_JPG
664-
SDL_IMAGE_SAVE_JPG=$<BOOL:${SDLIMAGE_JPG_SAVE}>
675+
SAVE_JPG=$<BOOL:${SDLIMAGE_JPG_SAVE}>
665676
)
666677
else()
667678
# Variable is used by test suite
@@ -844,7 +855,7 @@ if(SDLIMAGE_PNG)
844855
if(SDLIMAGE_PNG_ENABLED)
845856
target_compile_definitions(${sdl3_image_target_name} PRIVATE
846857
LOAD_PNG
847-
SDL_IMAGE_SAVE_PNG=$<BOOL:${SDLIMAGE_PNG_SAVE}>
858+
SAVE_PNG=$<BOOL:${SDLIMAGE_PNG_SAVE}>
848859
)
849860
if(NOT(SDLIMAGE_BACKEND_STB OR SDLIMAGE_BACKEND_WIC OR SDLIMAGE_BACKEND_IMAGEIO))
850861
target_compile_definitions(${sdl3_image_target_name} PRIVATE
@@ -882,7 +893,15 @@ list(APPEND SDLIMAGE_BACKENDS TGA)
882893
set(SDLIMAGE_TGA_ENABLED FALSE)
883894
if(SDLIMAGE_TGA)
884895
set(SDLIMAGE_TGA_ENABLED TRUE)
885-
target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_TGA)
896+
if(SDLIMAGE_TGA_ENABLED)
897+
target_compile_definitions(${sdl3_image_target_name} PRIVATE
898+
LOAD_TGA
899+
SAVE_TGA=$<BOOL:${SDLIMAGE_TGA_SAVE}>
900+
)
901+
else()
902+
# Variable is used by test suite
903+
set(SDLIMAGE_TGA_SAVE OFF)
904+
endif()
886905
endif()
887906

888907
list(APPEND SDLIMAGE_BACKENDS TIF)
@@ -1019,7 +1038,10 @@ if(SDLIMAGE_WEBP)
10191038
endif()
10201039
endif()
10211040
if(SDLIMAGE_WEBP_ENABLED)
1022-
target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_WEBP)
1041+
target_compile_definitions(${sdl3_image_target_name} PRIVATE
1042+
LOAD_WEBP
1043+
SAVE_WEBP=$<BOOL:${SDLIMAGE_WEBP_SAVE}>
1044+
)
10231045
if(SDLIMAGE_WEBP_SHARED)
10241046
if(NOT DEFINED SDLIMAGE_DYNAMIC_WEBP AND NOT DEFINED SDLIMAGE_DYNAMIC_WEBPDEMUX AND NOT DEFINED SDLIMAGE_DYNAMIC_WEBPMUX)
10251047
target_include_directories(${sdl3_image_target_name} PRIVATE
@@ -1049,6 +1071,9 @@ if(SDLIMAGE_WEBP)
10491071
else()
10501072
target_link_libraries(${sdl3_image_target_name} PRIVATE WebP::webp WebP::webpdemux WebP::libwebpmux)
10511073
endif()
1074+
else()
1075+
# Variable is used by test suite
1076+
set(SDLIMAGE_WEBP_SAVE OFF)
10521077
endif()
10531078
endif()
10541079

src/IMG_gif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// We will have the saving GIF feature by default
2828
#if !defined(SAVE_GIF)
2929
#define SAVE_GIF 1
30-
#endif /*!defined(SAVE_GIF)*/
30+
#endif
3131

3232
// By default, non-indexed surfaces will be converted to indexed pixels using octree quantization.
3333
#if defined(SAVE_GIF)

src/IMG_jpg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929

3030
/* We'll have JPG save support by default */
31-
#ifndef SDL_IMAGE_SAVE_JPG
32-
#define SDL_IMAGE_SAVE_JPG 1
31+
#ifndef SAVE_JPG
32+
#define SAVE_JPG 1
3333
#endif
3434

3535
#if defined(USE_STBIMAGE)
@@ -681,7 +681,7 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src)
681681
#endif /* LOAD_JPG */
682682

683683
/* Use tinyjpeg as a fallback if we don't have a hard dependency on libjpeg */
684-
#if SDL_IMAGE_SAVE_JPG && (defined(LOAD_JPG_DYNAMIC) || !defined(WANT_JPEGLIB))
684+
#if SAVE_JPG && (defined(LOAD_JPG_DYNAMIC) || !defined(WANT_JPEGLIB))
685685

686686
#ifdef assert
687687
#undef assert
@@ -755,7 +755,7 @@ static bool IMG_SaveJPG_IO_tinyjpeg(SDL_Surface *surface, SDL_IOStream *dst, int
755755
return result;
756756
}
757757

758-
#endif /* SDL_IMAGE_SAVE_JPG && (defined(LOAD_JPG_DYNAMIC) || !defined(WANT_JPEGLIB)) */
758+
#endif /* SAVE_JPG && (defined(LOAD_JPG_DYNAMIC) || !defined(WANT_JPEGLIB)) */
759759

760760
bool IMG_SaveJPG(SDL_Surface *surface, const char *file, int quality)
761761
{
@@ -777,7 +777,7 @@ bool IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, int q
777777
return SDL_SetError("Passed NULL dst");
778778
}
779779

780-
#if SDL_IMAGE_SAVE_JPG
780+
#if SAVE_JPG
781781
#ifdef USE_JPEGLIB
782782
if (!result) {
783783
result = IMG_SaveJPG_IO_jpeglib(surface, dst, quality);

src/IMG_libpng.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
#endif
5757

5858
// We will have the PNG saving feature by default
59-
#ifndef SDL_IMAGE_SAVE_PNG
60-
#define SDL_IMAGE_SAVE_PNG 1
59+
#ifndef SAVE_PNG
60+
#define SAVE_PNG 1
6161
#endif
6262

6363
/* Check for the older version of libpng */
@@ -550,7 +550,7 @@ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src)
550550
}
551551
}
552552

553-
#if SDL_IMAGE_SAVE_PNG
553+
#if SAVE_PNG
554554

555555
struct png_save_vars
556556
{
@@ -661,11 +661,11 @@ static bool LIBPNG_SavePNG_IO_Internal(struct png_save_vars *vars, SDL_Surface *
661661

662662
return true;
663663
}
664-
#endif // SDL_IMAGE_SAVE_PNG
664+
#endif // SAVE_PNG
665665

666666
bool IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
667667
{
668-
#if !SDL_IMAGE_SAVE_PNG
668+
#if !SAVE_PNG
669669
return false;
670670
#else
671671
if (!surface || !dst) {
@@ -1537,7 +1537,7 @@ IMG_Animation *IMG_LoadAPNGAnimation_IO(SDL_IOStream *src)
15371537
return NULL;
15381538
}
15391539

1540-
#if SDL_IMAGE_SAVE_PNG
1540+
#if SAVE_PNG
15411541
struct IMG_AnimationStreamContext
15421542
{
15431543
png_structp png_write_ptr;
@@ -2156,11 +2156,11 @@ static bool SaveAPNGAnimationEnd(IMG_AnimationStream *stream)
21562156
return false;
21572157
}
21582158

2159-
#endif /* SDL_IMAGE_SAVE_PNG */
2159+
#endif /* SAVE_PNG */
21602160

21612161
bool IMG_CreateAPNGAnimationStream(IMG_AnimationStream *stream, SDL_PropertiesID props)
21622162
{
2163-
#if !SDL_IMAGE_SAVE_PNG
2163+
#if !SAVE_PNG
21642164
return SDL_SetError("SDL_image built without PNG save support");
21652165
#else
21662166

@@ -2230,7 +2230,7 @@ bool IMG_CreateAPNGAnimationStream(IMG_AnimationStream *stream, SDL_PropertiesID
22302230
}
22312231
SDL_free(ctx);
22322232
return false;
2233-
#endif /* !SDL_IMAGE_SAVE_PNG */
2233+
#endif /* !SAVE_PNG */
22342234
}
22352235

22362236
#else

src/IMG_png.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#if !defined(SDL_IMAGE_LIBPNG)
2727

2828
/* We'll have PNG save support by default */
29-
#if !defined(SDL_IMAGE_SAVE_PNG)
30-
#define SDL_IMAGE_SAVE_PNG 1
29+
#if !defined(SAVE_PNG)
30+
#define SAVE_PNG 1
3131
#endif
3232

3333
#if defined(LOAD_PNG) && defined(USE_STBIMAGE)
@@ -84,7 +84,7 @@ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src)
8484

8585
#endif /* LOAD_PNG */
8686

87-
#if SDL_IMAGE_SAVE_PNG
87+
#if SAVE_PNG
8888

8989
static const Uint32 png_format = SDL_PIXELFORMAT_RGBA32;
9090

@@ -136,7 +136,7 @@ static bool IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst)
136136
return result;
137137
}
138138

139-
#endif /* SDL_IMAGE_SAVE_PNG */
139+
#endif /* SAVE_PNG */
140140

141141
bool IMG_SavePNG(SDL_Surface *surface, const char *file)
142142
{
@@ -156,7 +156,7 @@ bool IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
156156
return SDL_SetError("Passed NULL dst");
157157
}
158158

159-
#if SDL_IMAGE_SAVE_PNG
159+
#if SAVE_PNG
160160
if (!result) {
161161
result = IMG_SavePNG_IO_miniz(surface, dst);
162162
}

src/IMG_webp.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
#include "IMG_anim.h"
2727
#include "IMG_webp.h"
2828

29+
// We will have the saving WEBP feature by default
30+
#if !defined(SAVE_WEBP)
31+
#ifdef LOAD_WEBP
32+
#define SAVE_WEBP 1
33+
#else
34+
#define SAVE_WEBP 0
35+
#endif
36+
#endif
37+
2938
#ifdef LOAD_WEBP
3039

3140
/*=============================================================================
@@ -37,8 +46,6 @@
3746
3847
=============================================================================*/
3948

40-
#include <SDL3/SDL_endian.h>
41-
4249
#ifdef macintosh
4350
#define MACOS
4451
#endif
@@ -542,6 +549,8 @@ IMG_Animation *IMG_LoadWEBPAnimation_IO(SDL_IOStream *src)
542549
return IMG_LoadWEBPAnimation_IO_Internal(src, 0);
543550
}
544551

552+
#if SAVE_WEBP
553+
545554
static const char *GetWebPEncodingErrorStringInternal(WebPEncodingError error_code)
546555
{
547556
switch (error_code) {
@@ -866,7 +875,11 @@ static bool IMG_CloseWEBPAnimationStream(IMG_AnimationStream *stream)
866875
return true;
867876
}
868877

869-
#else
878+
#endif // SAVE_WEBP
879+
880+
#endif // LOAD_WEBP
881+
882+
#if !LOAD_WEBP
870883

871884
/* See if an image is contained in a data source */
872885
bool IMG_isWEBP(SDL_IOStream *src)
@@ -879,15 +892,21 @@ bool IMG_isWEBP(SDL_IOStream *src)
879892
SDL_Surface *IMG_LoadWEBP_IO(SDL_IOStream *src)
880893
{
881894
(void)src;
895+
SDL_SetError("SDL_image was not built with WEBP support");
882896
return NULL;
883897
}
884898

885899
IMG_Animation *IMG_LoadWEBPAnimation_IO(SDL_IOStream *src)
886900
{
887901
(void)src;
902+
SDL_SetError("SDL_image was not built with WEBP support");
888903
return NULL;
889904
}
890905

906+
#endif // !LOAD_WEBP
907+
908+
#if !SAVE_WEBP
909+
891910
bool IMG_SaveWEBP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, float quality)
892911
{
893912
(void)surface;
@@ -912,4 +931,4 @@ bool IMG_CreateWEBPAnimationStream(IMG_AnimationStream *stream, SDL_PropertiesID
912931
return SDL_SetError("SDL_image was not built with WEBP save support");
913932
}
914933

915-
#endif /* LOAD_WEBP */
934+
#endif // !SAVE_WEBP

0 commit comments

Comments
 (0)