androidc++android-ndkjpegdevil

Error 'IL_LIB_JPEG_ERROR 1506' using DevIL


I'm writing an Android app that uses DevIL for image processing. I got the port of DevIL and its dependent libraries from this project. I edited and extracted what I needed. It compiles fine, and the library works, but it doesn't when I try to load JPEG files...

Using the DevIL error code, I found the error number to be 1506 which translates to IL_LIB_JPEG_ERROR, meaning there is a problem in my JPEG library. I've tried updating to the latest JPEG library, but all has failed. I also tried other JPEG files, but I didn't have any success.

Here is my android.mk file showing the JPEG and DevIL modules snippets:

JPEG

#libjpeg
include $(CLEAR_VARS)

LOCAL_MODULE    := libjpeg
LOCAL_CFLAGS    := -g -Dlinux -DFT2_BUILD_LIBRARY=1 -DPHYSFS_NO_CDROM_SUPPORT=1 -DAL_ALEXT_PROTOTYPES=1 -DHAVE_GCC_DESTRUCTOR=1 -DOPT_GENERIC -DREAL_IS_FLOAT
LOCAL_CPPFLAGS  := ${LOCAL_CFLAGS}

LOCAL_C_INCLUDES  :=  \
    ${JPEG_SRC_PATH}

LOCAL_SRC_FILES := \
    ${JPEG_SRC_PATH}jquant1.c \
    ${JPEG_SRC_PATH}jdtrans.c \
    ${JPEG_SRC_PATH}jerror.c \
    ${JPEG_SRC_PATH}wrppm.c \
    ${JPEG_SRC_PATH}jcparam.c \
    ${JPEG_SRC_PATH}jdmarker.c \
    ${JPEG_SRC_PATH}jidctfst.c \
    ${JPEG_SRC_PATH}jctrans.c \
    ${JPEG_SRC_PATH}cdjpeg.c \
    ${JPEG_SRC_PATH}jcomapi.c \
    ${JPEG_SRC_PATH}jmemansi.c \
    ${JPEG_SRC_PATH}jquant2.c \
    ${JPEG_SRC_PATH}wrtarga.c \
    ${JPEG_SRC_PATH}transupp.c \
    ${JPEG_SRC_PATH}jdmerge.c \
    ${JPEG_SRC_PATH}jdhuff.c \
    ${JPEG_SRC_PATH}jdmaster.c \
    ${JPEG_SRC_PATH}jcprepct.c \
    ${JPEG_SRC_PATH}jutils.c \
    ${JPEG_SRC_PATH}jccoefct.c \
    ${JPEG_SRC_PATH}jccolor.c \
    ${JPEG_SRC_PATH}jdatasrc.c \
    ${JPEG_SRC_PATH}jcdctmgr.c \
    ${JPEG_SRC_PATH}wrrle.c \
    ${JPEG_SRC_PATH}jcapimin.c \
    ${JPEG_SRC_PATH}jfdctfst.c \
    ${JPEG_SRC_PATH}rdrle.c \
    ${JPEG_SRC_PATH}wrbmp.c \
    ${JPEG_SRC_PATH}jdarith.c \
    ${JPEG_SRC_PATH}jidctint.c \
    ${JPEG_SRC_PATH}jcsample.c \
    ${JPEG_SRC_PATH}jaricom.c \
    ${JPEG_SRC_PATH}jdcolor.c \
    ${JPEG_SRC_PATH}jdapistd.c \
    ${JPEG_SRC_PATH}jdmainct.c \
    ${JPEG_SRC_PATH}jddctmgr.c \
    ${JPEG_SRC_PATH}jcmaster.c \
    ${JPEG_SRC_PATH}jfdctflt.c \
    ${JPEG_SRC_PATH}rdgif.c \
    ${JPEG_SRC_PATH}jcarith.c \
    ${JPEG_SRC_PATH}rdcolmap.c \
    ${JPEG_SRC_PATH}wrgif.c \
    ${JPEG_SRC_PATH}jdcoefct.c \
    ${JPEG_SRC_PATH}rdbmp.c \
    ${JPEG_SRC_PATH}jdapimin.c \
    ${JPEG_SRC_PATH}jdsample.c \
    ${JPEG_SRC_PATH}jidctflt.c \
    ${JPEG_SRC_PATH}rdppm.c \
    ${JPEG_SRC_PATH}rdtarga.c \
    ${JPEG_SRC_PATH}jchuff.c \
    ${JPEG_SRC_PATH}jcmarker.c \
    ${JPEG_SRC_PATH}jdpostct.c \
    ${JPEG_SRC_PATH}jfdctint.c \
    ${JPEG_SRC_PATH}jcinit.c \
    ${JPEG_SRC_PATH}jmemmgr.c \
    ${JPEG_SRC_PATH}jcmainct.c \
    ${JPEG_SRC_PATH}jcapistd.c \
    ${JPEG_SRC_PATH}rdswitch.c \
    ${JPEG_SRC_PATH}jdatadst.c \
    ${JPEG_SRC_PATH}jdinput.c

LOCAL_LDLIBS    := -llog -L../lib -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := libphysfs

include $(BUILD_SHARED_LIBRARY)

DeviL module

#libdevil
include $(CLEAR_VARS)

LOCAL_MODULE    := libdevil
LOCAL_CFLAGS    := -g -Dlinux -DFT2_BUILD_LIBRARY=1 -DPHYSFS_NO_CDROM_SUPPORT=1 -DAL_ALEXT_PROTOTYPES=1 -DHAVE_GCC_DESTRUCTOR=1 -DOPT_GENERIC -DREAL_IS_FLOAT -fexceptions
LOCAL_CPPFLAGS  := ${LOCAL_CFLAGS}

LOCAL_C_INCLUDES  :=  \
    ${DEVIL_SRC_PATH}include \
    ${DEVIL_SRC_PATH}src-IL/include \
    ${DEVIL_SRC_PATH}src-ILU/include \
    ${JASPER_SRC_PATH}src/libjasper/include \
    ${PHYSFS_SRC_PATH} \
    ${PHYSFS_SRC_PATH}zlib123 \
    ${PNG_SRC_PATH} \
    ${MNG_SRC_PATH} \
    ${JPEG_SRC_PATH} \
    ${LCMS_SRC_PATH}include/ \
    ${TIFF_SRC_PATH}libtiff/ \

LOCAL_SRC_FILES := \
    ${DEVIL_SRC_PATH}src-IL/src/il_sun.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_wdp.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_doom.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_jp2.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_tpl.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_size.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_rle.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_gif.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_states.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_psp.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_devil.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_convbuff.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_ftx.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_vtf.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_iff.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_lif.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_pcx.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_io.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_files.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_fastconv.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_error.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_main.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_utx.cpp \
    ${DEVIL_SRC_PATH}src-IL/src/il_pcd.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_neuquant.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_dds.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_dicom.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_wal.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_icon.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_blp.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_mp3.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_header.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_alloc.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_sgi.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_stack.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_texture.c \
    ${DEVIL_SRC_PATH}src-IL/src/altivec_typeconversion.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_targa.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_bmp.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_mdl.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_pix.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_pnm.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_ilbm.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_icns.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_cut.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_profiles.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_hdr.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_register.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_exr.cpp \
    ${DEVIL_SRC_PATH}src-IL/src/il_iwi.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_mng.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_rot.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_jpeg.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_png.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_pxr.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_nvidia.cpp \
    ${DEVIL_SRC_PATH}src-IL/src/il_squish.cpp \
    ${DEVIL_SRC_PATH}src-IL/src/il_utility.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_internal.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_psd.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_endian.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_quantizer.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_wbmp.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_manip.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_pic.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_tiff.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_pal.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_dds-save.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_raw.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_convert.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_dcx.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_fits.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_xpm.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_bits.c \
    ${DEVIL_SRC_PATH}src-IL/src/altivec_common.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_dpx.c \
    ${DEVIL_SRC_PATH}src-IL/src/il_rawdata.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_alloc.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_error.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_filter_rcg.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_filter.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_internal.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_main.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_manip.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_mipmap.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_noise.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_region.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_rotate.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_scale.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_scale2d.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_scale3d.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_scaling.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_states.c \
    ${DEVIL_SRC_PATH}src-ILU/src/ilu_utilities.c \

LOCAL_LDLIBS    := -llog -L../lib -lGLESv1_CM

LOCAL_STATIC_LIBRARIES := \
    libjasper \
    libpng \
    libmng \
    libjpeg \
    liblcms \
    libphysfs \
    libtiff

include $(BUILD_SHARED_LIBRARY)

My C++ file's module in file android.mk:

#mylib
include $(CLEAR_VARS)
LOCAL_MODULE    := libmylib
LOCAL_CFLAGS    := -g -Dlinux -DFT2_BUILD_LIBRARY=1 -DPHYSFS_NO_CDROM_SUPPORT=1 -DAL_ALEXT_PROTOTYPES=1 -DHAVE_GCC_DESTRUCTOR=1 -DOPT_GENERIC -DREAL_IS_FLOAT -fexceptions
LOCAL_CPPFLAGS  := ${LOCAL_CFLAGS}
LOCAL_C_INCLUDES  :=  \
    ${DEVIL_SRC_PATH}include \
    ${DEVIL_SRC_PATH}src-IL/include \
    ${DEVIL_SRC_PATH}src-ILU/include \
    ${JASPER_SRC_PATH}src/libjasper/include \
    ${PHYSFS_SRC_PATH} \
    ${PHYSFS_SRC_PATH}zlib123 \
    ${PNG_SRC_PATH} \
    ${MNG_SRC_PATH} \
    ${JPEG_SRC_PATH} \
    ${LCMS_SRC_PATH}include/ \
    ${TIFF_SRC_PATH}libtiff/ \


LOCAL_SRC_FILES := com_myproject_MainActivity.cpp

LOCAL_LDLIBS    := -llog -lGLESv2

LOCAL_STATIC_LIBRARIES := \
    libjasper \
    libpng \
    libmng \
    libjpeg \
    liblcms \
    libphysfs \
    libtiff \
    libdevil \

include $(BUILD_SHARED_LIBRARY)

Here is the com_myproject_MainActivity.cpp file that calls DevIL and also links to the Android part:

//#include "com_myproject_MainActivity.h"
#include <string.h>
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifdef HAVE_CONFIG_H
#include <devil-1.7.8/include/IL/config.h>
#endif /* HAVE_CONFIG_H */

#include <devil-1.7.8/include/IL/il.h>
#include <devil-1.7.8/include/IL/ilu.h>
#include <devil-1.7.8/include/IL/ilut.h>

/* We would need ILU just because of iluErrorString() function... */
/* So make it possible for both with and without ILU!  */

#ifdef ILU_ENABLED
#include <devil-1.7.8/include/IL/ilu.h>
/*#define PRINT_ERROR_MACRO printf("Error: %s\n", iluErrorString(Error))
#else /* not ILU_ENABLED */
#define PRINT_ERROR_MACRO printf("Error: 0x%X\n", (unsigned int)Error)
#endif /* not ILU_ENABLED */

extern "C" {
    JNIEXPORT jint JNICALL Java_com_myproject_MainActivity_convert
    (JNIEnv * env, jclass c, jstring file, jstring file2){
        //'file' is the path to incoming file, and 'file2' is the path to the file to be created.

        const char * cfile = env->GetStringUTFChars(file, NULL);
        const char * cfile2 = env->GetStringUTFChars(file2, NULL);
        ILuint    ImgId ;
        ILenum    Error;

        // Initialize DevIL.
        ilInit();
        #ifdef ILU_ENABLED
            iluInit();
        #endif

        int x= 0;

        // Generate the main image name to use.
        ilGenImages(1, &ImgId);

        ilBindImage(ImgId);

        ILboolean result = ilLoadImage(cfile); //Loads the file. Returns boolean.

        if (result == true) //x is 1 if operation was successful
        {
            x = 1;
        }
        else
        {
            ILenum err = ilGetError() ;
            x = err; //x becomes error number if fails e.g 1506 if there is an error in LIB_JPEG
            //printf( "string is %s\n", ilGetString( err ) );
        }
        /*ilEnable(IL_FILE_OVERWRITE);

        ILboolean result2 = ilSaveImage(cfile2);

        if( result2 == true )
        {
            x = 2;
        }
        else
        {
            ILenum err = ilGetError() ;
            x = err;
            //printf( "string is %s\n", ilGetString( err ) );
        }
        ilDeleteImages(1, &ImgId);*/

        env->ReleaseStringUTFChars(file, cfile);
        env->ReleaseStringUTFChars(file2, cfile2);

        return x;
    }
};

Solution

  • It turns out I was compiling the JPEG library wrong.... The following was the correct order for the JPEG module in the android.mk file. It works fine.

    #libjpeg
    include $(CLEAR_VARS)
    
    LOCAL_MODULE    := libjpeg
    LOCAL_MODULE_FILENAME := libjpeg
    
    LOCAL_SRC_FILES := \
            ${JPEG_SRC_PATH}jcapimin.c ${JPEG_SRC_PATH}jcapistd.c ${JPEG_SRC_PATH}jccoefct.c ${JPEG_SRC_PATH}jccolor.c ${JPEG_SRC_PATH}jcdctmgr.c ${JPEG_SRC_PATH}jchuff.c \
            ${JPEG_SRC_PATH}jcinit.c ${JPEG_SRC_PATH}jcmainct.c ${JPEG_SRC_PATH}jcmarker.c ${JPEG_SRC_PATH}jcmaster.c ${JPEG_SRC_PATH}jcomapi.c ${JPEG_SRC_PATH}jcparam.c \
            ${JPEG_SRC_PATH}jcprepct.c ${JPEG_SRC_PATH}jcsample.c ${JPEG_SRC_PATH}jctrans.c ${JPEG_SRC_PATH}jdapimin.c ${JPEG_SRC_PATH}jdapistd.c \
            ${JPEG_SRC_PATH}jdatadst.c ${JPEG_SRC_PATH}jdatasrc.c ${JPEG_SRC_PATH}jdcoefct.c ${JPEG_SRC_PATH}jdcolor.c ${JPEG_SRC_PATH}jddctmgr.c ${JPEG_SRC_PATH}jdhuff.c \
            ${JPEG_SRC_PATH}jdinput.c ${JPEG_SRC_PATH}jdmainct.c ${JPEG_SRC_PATH}jdmarker.c ${JPEG_SRC_PATH}jdmaster.c ${JPEG_SRC_PATH}jdmerge.c \
            ${JPEG_SRC_PATH}jdpostct.c ${JPEG_SRC_PATH}jdsample.c ${JPEG_SRC_PATH}jdtrans.c ${JPEG_SRC_PATH}jerror.c ${JPEG_SRC_PATH}jfdctflt.c ${JPEG_SRC_PATH}jfdctfst.c \
            ${JPEG_SRC_PATH}jfdctint.c ${JPEG_SRC_PATH}jidctflt.c ${JPEG_SRC_PATH}jidctfst.c ${JPEG_SRC_PATH}jidctint.c ${JPEG_SRC_PATH}jquant1.c \
            ${JPEG_SRC_PATH}jquant2.c ${JPEG_SRC_PATH}jutils.c ${JPEG_SRC_PATH}jmemmgr.c ${JPEG_SRC_PATH}jcarith.c ${JPEG_SRC_PATH}jdarith.c ${JPEG_SRC_PATH}jaricom.c
    
    # Use the no backing store memory manager provided by
    # libjpeg. See install.txt
    LOCAL_SRC_FILES += \
            ${JPEG_SRC_PATH}jmemnobs.c
    
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
    
    include $(BUILD_STATIC_LIBRARY)