Integration and test of libjpeg-turbo in Android (ICS)

libjpeg-turbo is high performance instance of standard jpeg library.

This page describe how use and test it in Android.

Add libjpeg-turbo in Android

You must clone libjpeg-turbo in external/ directory in your Android source tree.

For now Android branch of libjpeg-turbo is hosted on git.linaro.org

git clone git://git.linaro.org/people/tomgall/libjpeg-turbo/libjpeg-turbo.git -b linaro-android

Make Android use libjpeg-turbo

The vanilla Android jpeg library is in external/jpeg directory.

With libjpeg-turbo we don't want to use it anymore, to do that we remane external/jpeg/Android.mk to external/jpeg/Android.mk.old.

If you have already compile Android sources, don't forget to remove all intermediates jpeg build files. They should by located in out/target/product/productname/obj/SHARED_LIBRARIES/libjpeg_intermediates directory

The last step is to make skia use libjpeg-turbo, patch external/skia/Android.mk like this:

@@ -243,7 +243,7 @@ LOCAL_C_INCLUDES += \
        external/zlib \
        external/libpng \
        external/giflib \
-       external/jpeg \
+       external/libjpeg-turbo \
        external/webp/include \
        frameworks/opt/emoji \
        external/expat/lib

Now you can compile your Android sources with libjpeg-turbo.

TIPS: You can compile only the needed libraries by setting in Android build command the libraries names: 
jpeg skia skia_bench
For example snowball build command line is:
make TARGET_PRODUCT=snowball TARGET_TOOLS_PREFIX=./prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi- libjpeg libskia skia_bench

Test libjpeg-turbo performance in Android

To test libjpeg-turbo performance you can use skia_bench tool provided with skia.

The command line to test jpeg decoding is:

skia_bench -repeat 10 -Ddecode-filename yourimage.jpg

The bench results are in Android log ($logcat -d) and look like this:

running bench [640 480] decode_XXXX_yourimage.jpg

8888: cmsecs = yyyy

565: cmsecs = yyyy

skia_bench log

By default skia_bench results output go in Android log.

If you want to change this, and for example, piut them into a file you have to configure Android log systeme with logcat command. The example below clean the log, redirect it to "/sdcard/skia_bench.log" and setup a filter in skia tag.

To have more detail about logcat: Android wiki page

logcat -c
logcat -f /sdcard/skia_bench.log skia:D *:S &
skia_bench -repeat 10 -Ddecode-filename /sdcard/yourimage.jpg

skia_bench segfault (fixed)

skia_bench generate a segfault at the end of the test, a bug has been filled to track it: https://bugs.launchpad.net/libjpeg-turbo/+bug/912035

The segfault doesn't influence the test and bench values are available in log.

bug fix : https://github.com/CyanogenMod/android_external_skia/commit/f25df1f7228ef8151ec6633c649e5081d4c28f67


CategoryAndroidTips

BenjaminGaignard/libjpeg-turboAndSkia (last modified 2012-01-05 16:33:59)