Reputation: 41
I have a question.
What would I do I use the OpenJPEG on Android? (I'm "j2k_to_image" is primarily want to use.)
I would like you to tell me how do I write a makefile. Thanks in advance.
Upvotes: 4
Views: 1827
Reputation: 163
I was able to build + use OpenJPEG to load JPEG2000 images into my app using the following outline. You'll have to customize it according to your environment and how you want to utilize it. My answer provides rough guidelines along with specific answers to the major stumbling blocks I encountered (what my Android.mk and Application.mk files should be, as well as how to deal with the fact that the OpenJPEG library requires cmake).
Since we're talking OpenJPEG, this answer assumes you are familiar with and plan to use the Android NDK for your app. It also assumes you are using the Eclipse version of the Android IDE. The answer also assumes you are familiar with how static libraries work with the Android NDK and how to reference them into your main app. You can extend my answer below to create a shared library or to include the code directly into your app. If you are unfamiliar with these prerequisites, stackoverflow and Google can help.
I was successful with Android NDK r8e and OpenJPEG 2.0.0.
Steps:
With that, I was able to successfully load a JPEG2000 image into my Android NDK-based app.
Application.mk:
APP_ABI := all
APP_PLATFORM := android-9
APP_MODULES := openjpeg
Android.mk (you will have to customize all of the paths below):
# Taken from https://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile
# The trailing slash is required.
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
ALL_CPPS := $(call rwildcard,../../openjpeg-2.0.0/src/lib/openjp2,*.c)
ALL_CPPS += $(call rwildcard,../../openjpeg-2.0.0/src/lib/openjpip,*.c)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := openjpeg
LOCAL_C_INCLUDES := /path/to/openjpeg-2.0.0/src/lib/openjp2
LOCAL_SRC_FILES := $(addprefix ../,$(ALL_CPPS))
LOCAL_CFLAGS = -DUSE_JPIP
include $(BUILD_STATIC_LIBRARY)
opj_config.h (normally cmake creates this for the platform you're building for -- but as I mention above, I didn't want to deal with cmake, so I hand-created this file):
#ifndef OPJ_CONFIG_H
#define OPJ_CONFIG_H
#define OPJ_PACKAGE_VERSION "2.0.0"
#define HAVE_INTTYPES_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STDINT_H 1
#ifndef HAVE_STDLIB_H // I had a conflict with this somewhere else in my project -- good form dictates that I should probably ifndef guard the other defines in this file as well....that is a TODO for later
#define HAVE_STDLIB_H 1
#endif
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_UNISTD_H 1
// I'm not utilizing libpng or libtiff, so don't set these
//#cmakedefine HAVE_LIBPNG @HAVE_LIBPNG@
//#cmakedefine HAVE_PNG_H @HAVE_PNG_H@
//#cmakedefine HAVE_LIBTIFF @HAVE_LIBTIFF@
//#cmakedefine HAVE_TIFF_H @HAVE_TIFF_H@
#define HAVE_SSIZE_T 1
//#cmakedefine _LARGEFILE_SOURCE
//#cmakedefine _LARGE_FILES
//#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
#define HAVE_FSEEKO 1
//#cmakedefine HAVE_LIBLCMS1
//#cmakedefine HAVE_LIBLCMS2
//#cmakedefine HAVE_LCMS1_H
//#cmakedefine HAVE_LCMS2_H
#endif // OPJ_CONFIG_H
Upvotes: 4