Я пишу приложение для Android, которое использует DevIL для обработки изображений. Я получил порт DevIL и его зависимые библиотеки от этот проект. Я отредактировал и извлек то, что мне было нужно. Он прекрасно компилируется, и библиотека работает, но это не так, когда я пытаюсь загрузить JPEG файлы …
Используя код ошибки DevIL, я нашел номер ошибки 1506, который переводится в IL_LIB_JPEG_ERROR
Это означает, что в моей библиотеке JPEG есть проблема. Я попытался обновить до последней библиотеки JPEG, но все не удалось. Я также попробовал другие файлы JPEG, но у меня не было никакого успеха.
Вот мой android.mk
файл, показывающий фрагменты модулей JPEG и DevIL:
#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;
}
};
Вы указываете -DFT2_BUILD_LIBRARY=1
когда вы строите DevIL сама библиотека. Это правильно.
Однако, когда вы создаете свои собственные приложения, связанные с DevIL, вы указываете флаг -DFT2_BUILD_LIBRARY=1
снова. Это означает, что заголовки DevIL будут введены в заблуждение, полагая, что они создаются для самой библиотеки, а не для стороннего приложения.
Оказывается, я неправильно скомпилировал библиотеку JPEG …. Ниже был правильный порядок для модуля JPEG в android.mk
файл. Работает нормально.
#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)