5

我正在编写一个使用DevIL进行图像处理的 Android 应用程序。我从这个项目中得到了 DevIL 的端口和它的依赖库。我编辑并提取了我需要的东西。它编译得很好,并且库可以工作,但是当我尝试加载JPEG文件时它不会...

使用 DevIL 错误代码,我发现错误号是 1506,它转换为IL_LIB_JPEG_ERROR,这意味着我的 JPEG 库中存在问题。我尝试更新到最新的 JPEG 库,但都失败了。我也尝试了其他 JPEG 文件,但没有任何成功。

这是android.mk显示 JPEG 和 DevIL 模块片段的文件:

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)

恶魔模块

#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)

我的 C++ 文件的模块在文件中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)

这是com_myproject_MainActivity.cpp调用 DevIL 的文件,也链接到 Android 部分:

//#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;
    }
};
4

2 回答 2

0

您指定-DFT2_BUILD_LIBRARY=1何时构建DevIL库本身。这是对的。

但是,当您构建自己的与 DevIL 链接的应用程序时,您需要-DFT2_BUILD_LIBRARY=1再次指定该标志。这意味着 DevIL 标头将被误导,认为它们是为库本身而不是为第三方应用程序构建的。

于 2013-08-07T16:55:24.343 回答
0

原来我编译的 JPEG 库是错误的……以下是android.mk文件中 JPEG 模块的正确顺序。它工作正常。

#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)
于 2013-12-20T08:15:14.920 回答