Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define for SAVE_PNG support #235

Closed
1bsyl opened this issue May 14, 2022 · 12 comments
Closed

Define for SAVE_PNG support #235

1bsyl opened this issue May 14, 2022 · 12 comments

Comments

@1bsyl
Copy link
Contributor

1bsyl commented May 14, 2022

It would be nice to re-add the define to compile out the PNG support:

eg:

diff --git a/Android.mk b/Android.mk
index c6d83db..7e9ab1c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -127,6 +136,11 @@ ifeq ($(SUPPORT_PNG),true)
     LOCAL_CFLAGS += -DLOAD_PNG
     LOCAL_STATIC_LIBRARIES += png
     LOCAL_LDLIBS += -lz
+ifeq ($(SUPPORT_SAVE_PNG),true)
+    LOCAL_CFLAGS += -DSDL_IMAGE_SAVE_PNG=1
+else
+    LOCAL_CFLAGS += -DSDL_IMAGE_SAVE_PNG=0
+endif
 endif
 
 ifeq ($(SUPPORT_WEBP),true)
diff --git a/IMG_png.c b/IMG_png.c
index 462fe2f..61b5621 100644
--- a/IMG_png.c
+++ b/IMG_png.c
@@ -23,9 +23,8 @@
 
 #include "SDL_image.h"
 
-/* We'll have PNG save support by default */
-#ifndef SAVE_PNG
-#define SAVE_PNG    1
+#if !defined(SDL_IMAGE_SAVE_PNG)
+#  define SDL_IMAGE_SAVE_PNG 1
 #endif
 
 #if defined(USE_STBIMAGE)
@@ -115,7 +116,7 @@ static struct {
     jmp_buf* (*png_set_longjmp_fn) (png_structrp, png_longjmp_ptr, size_t);
 #endif
 #endif
-#if SAVE_PNG
+#if SDL_IMAGE_SAVE_PNG
     png_structp (*png_create_write_struct) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);
     void (*png_destroy_write_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr);
     void (*png_set_write_fn) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn);
@@ -170,7 +173,7 @@ int IMG_InitPNG()
         FUNCTION_LOADER(png_set_longjmp_fn, jmp_buf* (*) (png_structrp, png_longjmp_ptr, size_t))
 #endif
 #endif
-#if SAVE_PNG
+#if SDL_IMAGE_SAVE_PNG
         FUNCTION_LOADER(png_create_write_struct, png_structp (*) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn))
         FUNCTION_LOADER(png_destroy_write_struct, void (*) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr))
         FUNCTION_LOADER(png_set_write_fn, void (*) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn))

@@ -540,7 +599,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
 
 #endif /* LOAD_PNG */
 
-#if SAVE_PNG
+#if SDL_IMAGE_SAVE_PNG
 
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
 static const Uint32 png_format = SDL_PIXELFORMAT_ABGR8888;
@@ -732,7 +791,7 @@ static int IMG_SavePNG_RW_miniz(SDL_Surface *surface, SDL_RWops *dst, int freeds
 }
 #endif /* LOAD_PNG_DYNAMIC || !WANT_LIBPNG */
 
-#endif /* SAVE_PNG */
+#endif /* SDL_IMAGE_SAVE_PNG */
 
 int IMG_SavePNG(SDL_Surface *surface, const char *file)
 {
@@ -746,7 +805,7 @@ int IMG_SavePNG(SDL_Surface *surface, const char *file)
 
 int IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
 {
-#if SAVE_PNG
+#if SDL_IMAGE_SAVE_PNG
 #ifdef USE_LIBPNG
     if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != 0) {
         if (IMG_SavePNG_RW_libpng(surface, dst, freedst) == 0) {
@@ -763,5 +822,5 @@ int IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
 #else
     return IMG_SetError("SDL_image built without PNG save support");
 
-#endif /* SAVE_PNG */
+#endif /* SDL_IMAGE_SAVE_PNG */
 }
@sezero
Copy link
Contributor

sezero commented May 14, 2022

If you do that, you should do an equivalent of it in autotools too.

@1bsyl
Copy link
Contributor Author

1bsyl commented May 14, 2022

Ok thanks, I'll try that later!

@sezero
Copy link
Contributor

sezero commented May 14, 2022

Haven't looked at it, but if we do this we may do a similar thing for SAVE_JPG for consistency.

@1bsyl
Copy link
Contributor Author

1bsyl commented May 14, 2022

@sezero I think this is quite ok, but not really used to updating autotools !?
(Should all file be regenerated ? I think I have more diff )

@sezero
Copy link
Contributor

sezero commented May 14, 2022

I will regenerate configure shortly

@1bsyl
Copy link
Contributor Author

1bsyl commented May 14, 2022

Fixed 2f5c99c thanks !

@sezero
Copy link
Contributor

sezero commented May 14, 2022

This can be closed now?

@1bsyl
Copy link
Contributor Author

1bsyl commented May 14, 2022

still need:

  • CMake update
  • Re-gen configure files

@sezero
Copy link
Contributor

sezero commented May 14, 2022

* Re-gen configure files

That I already did

@a-hurst
Copy link

a-hurst commented May 15, 2022

@1bsyl @sezero If PNG and/or JPG save are optional, and this can be configured separately from PNG/JPEG load support, is there a method of checking whether SDL_image has been built with/without those options? If not, is there at least an informative error message set when SavePNG/SaveJPG are called indicating that the linked version of image was compiled without those options?

@slouken
Copy link
Collaborator

slouken commented May 16, 2022

@1bsyl @sezero If PNG and/or JPG save are optional, and this can be configured separately from PNG/JPEG load support, is there a method of checking whether SDL_image has been built with/without those options? If not, is there at least an informative error message set when SavePNG/SaveJPG are called indicating that the linked version of image was compiled without those options?

Yes, the functions will return -1 and the error will indicate that SDL_image was built without save support. However, the default public builds will always have save support enabled. This option is only available for custom builds made by developers that want to minimize the code size and don't need save support.

@slouken slouken closed this as completed May 16, 2022
@a-hurst
Copy link

a-hurst commented May 16, 2022

Yes, the functions will return -1 and the error will indicate that SDL_image was built without save support. However, the default public builds will always have save support enabled. This option is only available for custom builds made by developers that want to minimize the code size and don't need save support.

Ah, good to know. Thanks!

smcv added a commit to smcv/SDL_image that referenced this issue May 23, 2022
This wasn't updated when the SAVE_PNG macro was renamed to
SDL_IMAGE_SAVE_PNG.

Fixes: 3af38ea "Fixed bug libsdl-org#235: add options to disable saving png/jpg images"
Signed-off-by: Simon McVittie <smcv@collabora.com>
smcv added a commit to smcv/SDL_image that referenced this issue May 23, 2022
This wasn't updated when the SAVE_PNG macro was renamed to
SDL_IMAGE_SAVE_PNG.

Fixes: 3af38ea "Fixed bug libsdl-org#235: add options to disable saving png/jpg images"
Signed-off-by: Simon McVittie <smcv@collabora.com>
smcv added a commit to smcv/SDL_image that referenced this issue May 23, 2022
This wasn't updated when the SAVE_PNG macro was renamed to
SDL_IMAGE_SAVE_PNG.

Fixes: 3af38ea "Fixed bug libsdl-org#235: add options to disable saving png/jpg images"
Signed-off-by: Simon McVittie <smcv@collabora.com>
smcv added a commit to smcv/SDL_image that referenced this issue May 23, 2022
This wasn't updated when the SAVE_PNG macro was renamed to
SDL_IMAGE_SAVE_PNG.

Fixes: 3af38ea "Fixed bug libsdl-org#235: add options to disable saving png/jpg images"
Signed-off-by: Simon McVittie <smcv@collabora.com>
slouken pushed a commit that referenced this issue May 24, 2022
This wasn't updated when the SAVE_PNG macro was renamed to
SDL_IMAGE_SAVE_PNG.

Fixes: 3af38ea "Fixed bug #235: add options to disable saving png/jpg images"
Signed-off-by: Simon McVittie <smcv@collabora.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants