We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2051 - Android : size of the library could be reduced.
Summary: Android : size of the library could be reduced.
Status: RESOLVED FIXED
Alias: None
Product: SDL_image
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: ARM Android (All)
: P2 minor
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-21 15:59 UTC by Sylvain
Modified: 2017-10-22 20:39 UTC (History)
2 users (show)

See Also:


Attachments
patch on Android.mk (4.86 KB, patch)
2014-10-24 11:12 UTC, Sylvain
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain 2013-08-21 15:59:40 UTC
Hi,

On Android, I noticed the current size of the shared library is about 450 ko with JPEG and PNG support included.
With Pelya's porting, it's only 230 ko - also with JPEG and PNG.

Maybe it is worth looking at the differences!

Thanks,

Sylvain
Comment 1 Gabriel Jacobo 2013-08-22 13:05:11 UTC
If you can contribute a patch I would gladly look at it.
Comment 2 Sylvain 2013-08-23 15:47:02 UTC
I looked at it, find no real difference.

Replacing -O3 by -Os would make the library go from 460ko to 320ko.

-fprefetch-loop-arrays could be removed as it produced a warning saying the option is ignored.

BTW, there are three Android.mk
SDL_image/Android.mk
SDL_image/externals/libpng/Android.mk
SDL_image/externals/jpeg/Android.mk

But the SDL_image/Android.mk includes directly the png/jpg source, 
so, the presence of the other Android.mk is confusing.
... 

To be confirmed, but it seems that compiling 
separatly SDL_image (shared) / jpeg (static) and libpng (static) make an even smaller library 320 ko -> 250 ko.
---
It is also possible to remove the WRITE support from PNG (pnglibconf.h & scripts) for 30 ko ...
---
Then the libraries png/jpeg from Pelya are older and also smaller.
Comment 3 Sylvain 2013-08-27 06:41:24 UTC
Hello,

Here's what I am doing to get the SDL_image compiled with libraries :

externals libraries are built independently with : 

ndk-build APP_BUILD_SCRIPT=jni/SDL_image_hg/external/libpng-1.6.2/Android.mk
ndk-build APP_BUILD_SCRIPT=jni/SDL_image_hg/external/jpeg-9/Android.mk 

For jpeg/Android.mk and libpng/Android.mk : 
 add -Os flags

For SDL_image/Android.mk:
remove : LOCAL_SRC_FILES of png and jpeg

LOCAL_LDLIBS := -Lobj/local/armeabi -ljpeg -lpng

The correct way should be to use LOCAL_STATIC_LIBRARIES but it does not work !

Also, I would like to trigger the build of jpeg/png automatically from the SDL_image Android.mk.

Any idea ? 

thanks
Comment 4 Sylvain 2014-10-24 11:05:53 UTC
So, the trick is to save the local path, then to call the .mk files. 

  1 my_LOCAL_PATH := $(call my-dir)
  2 
  3 include $(my_LOCAL_PATH)/external/jpeg-9/Android.mk
  4 include $(my_LOCAL_PATH)/external/libpng-1.6.2/Android.mk
  5 
  6 LOCAL_PATH := $(my_LOCAL_PATH)
  7 include $(CLEAR_VARS)
  8 ...
Comment 5 Sylvain 2014-10-24 11:12:48 UTC
Created attachment 1915 [details]
patch on Android.mk

Here's a patch to build the png/jpeg/webp lib independently with their own Android.mk file.
Comment 6 Sylvain 2014-10-24 11:20:33 UTC
In addition to the previous patch, if you add -Os:

+++ external/jpeg-9/Android.mk	
-LOCAL_CFLAGS += -O3 -fstrict-aliasing -fprefetch-loop-arrays
+LOCAL_CFLAGS += -Os -fstrict-aliasing -fprefetch-loop-arrays

+++ external/libpng-1.6.2/Android.mk	
-common_CFLAGS := ## -fomit-frame-pointer
+common_CFLAGS := -Os ## -fomit-frame-pointer


You will get a libSDL2_image of 275 ko instead of 460 ko.

Curiously, you wouldn't get this by only adding -Os to the old Android.mk!

I admit this is not so much important now that android libs are heavy, but the Android.mk file is now smaller, and it's not required anymore to make symlink of png/jpeg/webp to the jni directory.
Comment 7 Sylvain 2017-10-22 20:39:19 UTC
can be close with https://hg.libsdl.org/SDL_image/rev/0c24466d7d81