SDL2_image for Android with JPEG image format

In the previous article, we were discussing how to add support for PNG image format to SDL2 application for Android. Let’s add another more common format. What about JPEG?

The first step is to enable JPEG in SDL2_image. Just add a proper definition to SDL2_image/build.gradle.

Then it is necessary to add C implementation of JPEG library. There is one big catch. Do not call it jpeg. The problem is that the name will collide with another library in Android system and function jpeg_create_decompress(&cinfo) will crash. Thanks to DevMultiTech for a hint about the solution.

Let’s call the jpeg library SDL2_jpeg.

Register modules in settings.gradle:

Build all libraries:

Here is a sample code for loading and displaying JPEG image:

Result looks like this:

You can find whole source code at https://github.com/georgik/sdl2-android-example.

You can find about SDL2 and libraries more under the topic SDL2.