Build OpenJPEG for Android

I have a question.

What should I do with OpenJPEG on Android? (I just want to use j2k_to_image.)

I want you to tell me how to write a make file. Thanks in advance.

+4
source share
1 answer

I was able to create + use OpenJPEG to upload JPEG2000 images to my application using the following outline. You will have to customize it to suit your environment and how you want to use it. My answer contains rough recommendations along with specific answers to the main stumbling blocks that I encountered (which should be Android.mk and Application.mk files, as well as how to deal with the fact that the OpenJPEG library requires cmake).

Since we're talking about OpenJPEG, this answer assumes that you are familiar and plan to use the Android NDK for your application. It is also assumed that you are using the Eclipse version of the Android IDE. The answer also assumes that you are familiar with how static libraries work with Android NDK and how to reference them in the main application. You can expand my answer below to create a shared library or include code directly in your application. If you are not familiar with these premises, stackoverflow and Google can help.

I succeeded Android NDK r8e and OpenJPEG 2.0.0.

Steps:

  • Download and open OpenJPEG 2.0.0 from http://www.openjpeg.org/index.php?menu=download
  • Create your own project in Eclipse. I created a project that allows me to use OpenJPEG as a static library.
  • In the jni folder of my project, I used the following for my Application.mk and my Android.mk files. See below.
  • Create a custom opj_config.h. OpenJPEG is designed to be compiled using cmake. I did not want to deal with this for a number of reasons: none of my other materials relies on it (so it will add another level of complexity), I am on Windows (which has no built-in, and this postoverflow post is referenced by android-cmake , docs for android-cmake indicate that it may not work on Windows). See below my opj_config.h. This should work for you. Make sure you put it somewhere in your inclusion paths.
  • Create an Android NDK Static Library Project
  • Link to your static library in your main project

With this, I was able to successfully upload the JPEG2000 image to my Android NDK-based application.

Application.mk:

APP_ABI := all APP_PLATFORM := android-9 APP_MODULES := openjpeg 

Android.mk (you will need to configure all 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 (usually cmake creates this for the platform for which you are building, but, as I mentioned above, I did not want to deal with cmake, so I manually 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 
+3
source

Source: https://habr.com/ru/post/1436051/


All Articles