From 662c1c0d9cdcd027ba13ce311de3b93696247ffe Mon Sep 17 00:00:00 2001 From: seven332 Date: Tue, 8 Mar 2016 21:06:41 +0800 Subject: [PATCH] Update Image --- app/src/main/jni/Application.mk | 6 ++--- app/src/main/jni/image/image.c | 24 ++++++++++---------- app/src/main/jni/image/image_gif.c | 14 ++++++------ app/src/main/jni/image/image_jpeg.c | 4 ++-- app/src/main/jni/image/image_png.c | 16 ++++++------- app/src/main/jni/image/java_wrapper.c | 4 ++-- app/src/main/jni/libjpeg-turbo/Android.mk | 4 ++-- app/src/main/jni/log.h | 6 ++--- app/src/main/jni/stream/input_stream.c | 10 ++++---- app/src/main/jni/stream/input_stream_pipe.c | 6 ++--- app/src/main/jni/stream/output_stream.c | 10 ++++---- app/src/main/jni/stream/output_stream_pipe.c | 6 ++--- 12 files changed, 55 insertions(+), 55 deletions(-) diff --git a/app/src/main/jni/Application.mk b/app/src/main/jni/Application.mk index 77dddfa52..4c66f912f 100644 --- a/app/src/main/jni/Application.mk +++ b/app/src/main/jni/Application.mk @@ -16,8 +16,8 @@ APP_ABI := all APP_PLATFORM := android-15 APP_OPTIM := release -APP_CFLAGS += -ffunction-sections -fdata-sections -APP_CPPFLAGS += -ffunction-sections -fdata-sections -fvisibility=hidden -APP_LDFLAGS += -Wl,--gc-sections +APP_CFLAGS += -ffunction-sections -fdata-sections -fPIC +APP_CPPFLAGS += -ffunction-sections -fdata-sections -fvisibility=hidden -fPIC +APP_LDFLAGS += -Wl,--gc-sections -fPIC NDK_TOOLCHAIN_VERSION := 4.9 diff --git a/app/src/main/jni/image/image.c b/app/src/main/jni/image/image.c index 47387f967..d1d8e9491 100644 --- a/app/src/main/jni/image/image.c +++ b/app/src/main/jni/image/image.c @@ -78,7 +78,7 @@ void* decode(JNIEnv* env, InputStream* stream, bool partially, int* format) break; #endif default: - LOGE(EMSG("Can't detect format %d"), *format); + LOGE(MSG("Can't detect format %d"), *format); destroy_input_stream(get_env(), &stream); return NULL; } @@ -104,7 +104,7 @@ void* decode(JNIEnv* env, InputStream* stream, bool partially, int* format) return GIF_decode(env, patch_head_input_stream, partially); #endif default: - LOGE(EMSG("Can't detect format %d"), *format); + LOGE(MSG("Can't detect format %d"), *format); close_patch_head_input_stream(get_env(), patch_head_input_stream); destroy_patch_head_input_stream(get_env(), &patch_head_input_stream); return NULL; @@ -127,7 +127,7 @@ bool complete(void* image, int format) return GIF_complete((GIF*) image); #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); return false; } } @@ -148,7 +148,7 @@ bool is_completed(void* image, int format) return GIF_is_completed((GIF*) image); #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); return false; } } @@ -169,7 +169,7 @@ int get_width(void* image, int format) return GIF_get_width((GIF*) image); #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); return -1; } } @@ -190,7 +190,7 @@ int get_height(void* image, int format) return GIF_get_height((GIF*) image); #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); return -1; } } @@ -222,7 +222,7 @@ void render(void* image, int format, int src_x, int src_y, break; #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); break; } } @@ -246,7 +246,7 @@ void advance(void* image, int format) break; #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); } } @@ -266,7 +266,7 @@ int get_delay(void* image, int format) return GIF_get_delay((GIF*) image); #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); return false; } } @@ -287,7 +287,7 @@ int get_frame_count(void* image, int format) return GIF_get_frame_count((GIF*) image); #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); return false; } } @@ -308,7 +308,7 @@ bool is_opaque(void* image, int format) return GIF_is_opaque((GIF*) image); #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); return false; } } @@ -332,6 +332,6 @@ void recycle(void* image, int format) break; #endif default: - LOGE(EMSG("Can't detect format %d"), format); + LOGE(MSG("Can't detect format %d"), format); } } diff --git a/app/src/main/jni/image/image_gif.c b/app/src/main/jni/image/image_gif.c index 60f057d9c..4ce11b6c3 100644 --- a/app/src/main/jni/image/image_gif.c +++ b/app/src/main/jni/image/image_gif.c @@ -43,7 +43,7 @@ static int custom_read_fun(GifFileType* gif, GifByteType* bytes, int size) { JNIEnv *env = get_env(); if (env == NULL) { - LOGE(EMSG("Can't get JNIEnv")); + LOGE(MSG("Can't get JNIEnv")); return 0; } @@ -152,7 +152,7 @@ void* GIF_decode(JNIEnv* env, PatchHeadInputStream* patch_head_input_stream, boo if (partially) { // Glance if (DGifGlance(gif_file) != GIF_OK) { - LOGE(EMSG("GIF error code %d"), error_code); + LOGE(MSG("GIF error code %d"), error_code); DGifCloseFile(gif_file, &error_code); free(buffer); free(gif); @@ -184,7 +184,7 @@ void* GIF_decode(JNIEnv* env, PatchHeadInputStream* patch_head_input_stream, boo fix_gif_file(gif_file); } if (gif_file->ImageCount <= 0) { - LOGE(EMSG("No frame")); + LOGE(MSG("No frame")); DGifCloseFile(gif_file, &error_code); free(buffer); free(gif); @@ -241,7 +241,7 @@ bool GIF_complete(GIF* gif) } if (gif->gif_file == NULL || gif->patch_head_input_stream == NULL) { - LOGE(EMSG("Some stuff is NULL")); + LOGE(MSG("Some stuff is NULL")); return false; } @@ -313,7 +313,7 @@ static void backup(GIF* gif) static void restore(GIF* gif) { if (gif->backup == NULL) { - LOGE(EMSG("Backup is NULL")); + LOGE(MSG("Backup is NULL")); } else { memcpy(gif->buffer, gif->backup, (size_t) (gif->gif_file->SWidth * gif->gif_file->SHeight * 4)); } @@ -404,7 +404,7 @@ static void blend(GifFileType* gif_file, int index, void* pixels, int tran) copy_line(src_ptr, dst_ptr, cmap, tran, len); } } else { - LOGW(EMSG("Can't find color map")); + LOGW(MSG("Can't find color map")); } } @@ -415,7 +415,7 @@ void GIF_advance(GIF* gif) index = (gif->buffer_index + 1) % gif->gif_file->ImageCount; if (index != 0 && gif->partially) { - LOGE(EMSG("The png is only decoded partially. Only the first frame can be shown.")); + LOGE(MSG("The png is only decoded partially. Only the first frame can be shown.")); return; } diff --git a/app/src/main/jni/image/image_jpeg.c b/app/src/main/jni/image/image_jpeg.c index 2aa8d0062..d0dedf1b6 100644 --- a/app/src/main/jni/image/image_jpeg.c +++ b/app/src/main/jni/image/image_jpeg.c @@ -51,7 +51,7 @@ static size_t custom_read(void * custom_stuff, unsigned char * buffer, size_t si JNIEnv *env = get_env(); if (env == NULL) { - LOGE(EMSG("Can't get JNIEnv")); + LOGE(MSG("Can't get JNIEnv")); return 0; } @@ -80,7 +80,7 @@ void* JPEG_decode(JNIEnv* env, PatchHeadInputStream* patch_head_input_stream, bo cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { - LOGE(EMSG("%s"), emsg); + LOGE(MSG("%s"), emsg); free(jpeg); free(buffer); jpeg_destroy_decompress(&cinfo); diff --git a/app/src/main/jni/image/image_png.c b/app/src/main/jni/image/image_png.c index e2c0d9da1..51faff396 100644 --- a/app/src/main/jni/image/image_png.c +++ b/app/src/main/jni/image/image_png.c @@ -36,7 +36,7 @@ static void user_read_fn(png_structp png_ptr, JNIEnv *env = get_env(); if (env == NULL) { - LOGE(EMSG("Can't get JNIEnv")); + LOGE(MSG("Can't get JNIEnv")); } read_patch_head_input_stream(env, patch_head_input_stream, data, 0, length); @@ -45,13 +45,13 @@ static void user_read_fn(png_structp png_ptr, static void user_error_fn(png_structp png_ptr, png_const_charp error_msg) { - LOGE(EMSG("%s"), error_msg); + LOGE(MSG("%s"), error_msg); } static void user_warn_fn(png_structp png_ptr, png_const_charp error_msg) { - LOGW(EMSG("%s"), error_msg); + LOGW(MSG("%s"), error_msg); } static void free_frame_info_array(PNG_FRAME_INFO* frame_info_array, unsigned int count) @@ -195,7 +195,7 @@ void* PNG_decode(JNIEnv* env, PatchHeadInputStream* patch_head_input_stream, boo } if (setjmp(png_jmpbuf(png_ptr))) { - LOGE(EMSG("Error in png decode")); + LOGE(MSG("Error in png decode")); free_frame_info_array(frame_info_array, frame_count); frame_info_array = NULL; free(buffer); @@ -368,7 +368,7 @@ bool PNG_complete(PNG* png) } if (png->png_ptr == NULL || png->info_ptr == NULL || png->patch_head_input_stream == NULL) { - LOGE(EMSG("Some stuff is NULL")); + LOGE(MSG("Some stuff is NULL")); return false; } @@ -434,7 +434,7 @@ static void backup(PNG* png) static void restore(PNG* png) { if (png->backup == NULL) { - LOGE(EMSG("Backup is NULL")); + LOGE(MSG("Backup is NULL")); } else { memcpy(png->buffer, png->backup, png->width * png->height * 4); } @@ -505,13 +505,13 @@ void PNG_advance(PNG* png) int index; if (!png->apng) { - LOGW(EMSG("It is not apng, no need to advance")); + LOGW(MSG("It is not apng, no need to advance")); return; } index = (png->buffer_index + 1) % png->frame_count; if (index != 0 && png->partially) { - LOGE(EMSG("The png is only decoded partially. Only the first frame can be shown.")); + LOGE(MSG("The png is only decoded partially. Only the first frame can be shown.")); return; } diff --git a/app/src/main/jni/image/java_wrapper.c b/app/src/main/jni/image/java_wrapper.c index 6831804a1..8e4951cc5 100644 --- a/app/src/main/jni/image/java_wrapper.c +++ b/app/src/main/jni/image/java_wrapper.c @@ -50,7 +50,7 @@ jobject create_image_object(JNIEnv* env, void* ptr, int format, int width, int h image_clazz = (*env)->FindClass(env, "com/hippo/image/Image"); constructor = (*env)->GetMethodID(env, image_clazz, "", "(JIII)V"); if (constructor == 0) { - LOGE(EMSG("Can't find Image object constructor")); + LOGE(MSG("Can't find Image object constructor")); return NULL; } else { return (*env)->NewObject(env, image_clazz, constructor, @@ -113,7 +113,7 @@ Java_com_hippo_image_Image_nativeRender(JNIEnv* env, AndroidBitmap_getInfo(env, dst, &info); AndroidBitmap_lockPixels(env, dst, &pixels); if (pixels == NULL) { - LOGE(EMSG("Can't lock bitmap pixels")); + LOGE(MSG("Can't lock bitmap pixels")); return; } diff --git a/app/src/main/jni/libjpeg-turbo/Android.mk b/app/src/main/jni/libjpeg-turbo/Android.mk index 712d7f8eb..9dc16e615 100644 --- a/app/src/main/jni/libjpeg-turbo/Android.mk +++ b/app/src/main/jni/libjpeg-turbo/Android.mk @@ -100,7 +100,7 @@ else ifeq ($(TARGET_ARCH_ABI), x86) simd/jidctred-sse2.asm \ simd/jquantf-sse2.asm \ simd/jquanti-sse2.asm - LOCAL_ASMFLAGS := -DELF + LOCAL_ASMFLAGS := -DELF -DPIC else ifeq ($(TARGET_ARCH_ABI), x86_64) LOCAL_SRC_FILES += \ simd/jsimd_x86_64.c \ @@ -119,7 +119,7 @@ else ifeq ($(TARGET_ARCH_ABI), x86_64) simd/jidctred-sse2-64.asm \ simd/jquantf-sse2-64.asm \ simd/jquanti-sse2-64.asm - LOCAL_ASMFLAGS := -D__x86_64__ -DELF + LOCAL_ASMFLAGS := -D__x86_64__ -DELF -DPIC else LOCAL_SRC_FILES += jsimd_none.c endif diff --git a/app/src/main/jni/log.h b/app/src/main/jni/log.h index 9853f7153..cb2c4e060 100644 --- a/app/src/main/jni/log.h +++ b/app/src/main/jni/log.h @@ -23,7 +23,7 @@ #include -#define TAG "EhViewer" +#define TAG "Image" #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG ,__VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG ,__VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG ,__VA_ARGS__) @@ -34,10 +34,10 @@ #define STRINGIZE(L) #L #define MAKESTRING(M, L) M(L) #define FILE_LINE MAKESTRING(STRINGIZE, __LINE__ ) -#define EMSG(msg) __FILE__ "(" FILE_LINE "): "msg +#define MSG(msg) __FILE__ "(" FILE_LINE "): "msg #define OUT_OF_MEMORY "Out of memory" -#define WTF_OM LOGE(EMSG(OUT_OF_MEMORY)) +#define WTF_OM LOGE(MSG(OUT_OF_MEMORY)) #endif //LOG_H diff --git a/app/src/main/jni/stream/input_stream.c b/app/src/main/jni/stream/input_stream.c index a58b9669b..67913ea8a 100644 --- a/app/src/main/jni/stream/input_stream.c +++ b/app/src/main/jni/stream/input_stream.c @@ -36,20 +36,20 @@ InputStream* create_input_stream(JNIEnv* env, jobject is) jbyteArray buffer; if (readMID == NULL || closeMID == NULL) { - LOGE(EMSG("Can't get read or close method id")); + LOGE(MSG("Can't get read or close method id")); return NULL; } buffer = (*env)->NewByteArray(env, BUFFER_SIZE); buffer = (*env)->NewGlobalRef(env, buffer); if (buffer == NULL) { - LOGE(EMSG("Can't create buffer")); + LOGE(MSG("Can't create buffer")); return NULL; } InputStream* inputStream = (InputStream*) malloc(sizeof(InputStream)); if (inputStream == NULL) { - LOGE(EMSG("Out of memory")); + LOGE(MSG("Out of memory")); return NULL; } @@ -83,7 +83,7 @@ size_t read_input_stream(JNIEnv* env, InputStream* inputStream, unsigned char* b len = (*env)->CallIntMethod(env, inputStream->is, inputStream->readMID, inputStream->buffer, 0, len); if ((*env)->ExceptionCheck(env)) { - LOGE(EMSG("Catch exception")); + LOGE(MSG("Catch exception")); (*env)->ExceptionClear(env); len = -1; } @@ -107,7 +107,7 @@ void close_input_stream(JNIEnv* env, InputStream* inputStream) { (*env)->CallVoidMethod(env, inputStream->is, inputStream->closeMID); if ((*env)->ExceptionCheck(env)) { - LOGE(EMSG("Catch exception")); + LOGE(MSG("Catch exception")); (*env)->ExceptionClear(env); } } diff --git a/app/src/main/jni/stream/input_stream_pipe.c b/app/src/main/jni/stream/input_stream_pipe.c index 1d917dab9..926314df7 100644 --- a/app/src/main/jni/stream/input_stream_pipe.c +++ b/app/src/main/jni/stream/input_stream_pipe.c @@ -35,13 +35,13 @@ InputStreamPipe* create_input_stream_pipe(JNIEnv* env, jobject isPipe) jmethodID closeMID = (*env)->GetMethodID(env, streamPipeCls, "close", "()V"); if (obtainMID == NULL || releaseMID == NULL || openMID == NULL || closeMID == NULL) { - LOGE(EMSG("Can't get method id")); + LOGE(MSG("Can't get method id")); return NULL; } InputStreamPipe* inputStreamPipe = (InputStreamPipe*) malloc(sizeof(InputStreamPipe)); if (inputStreamPipe == NULL) { - LOGE(EMSG("Out of memory")); + LOGE(MSG("Out of memory")); return NULL; } @@ -77,7 +77,7 @@ InputStream* open_input_stream_from_pipe(JNIEnv* env, InputStreamPipe* inputStre { jobject is = (*env)->CallObjectMethod(env, inputStreamPipe->isPipe, inputStreamPipe->openMID); if ((*env)->ExceptionCheck(env)) { - LOGE(EMSG("Catch exception")); + LOGE(MSG("Catch exception")); (*env)->ExceptionClear(env); return NULL; } diff --git a/app/src/main/jni/stream/output_stream.c b/app/src/main/jni/stream/output_stream.c index 079d86919..303aba4be 100644 --- a/app/src/main/jni/stream/output_stream.c +++ b/app/src/main/jni/stream/output_stream.c @@ -36,20 +36,20 @@ OutputStream* create_output_stream(JNIEnv* env, jobject os) jbyteArray buffer; if (writeMID == NULL || closeMID == NULL) { - LOGE(EMSG("Can't get write or close method id")); + LOGE(MSG("Can't get write or close method id")); return NULL; } buffer = (*env)->NewByteArray(env, BUFFER_SIZE); buffer = (*env)->NewGlobalRef(env, buffer); if (buffer == NULL) { - LOGE(EMSG("Can't create buffer")); + LOGE(MSG("Can't create buffer")); return NULL; } OutputStream* outputStream = (OutputStream*) malloc(sizeof(OutputStream)); if (outputStream == NULL) { - LOGE(EMSG("Out of memory")); + LOGE(MSG("Out of memory")); return NULL; } @@ -89,7 +89,7 @@ size_t write_output_stream(JNIEnv* env, OutputStream* outputStream, const unsign // Catch exception if ((*env)->ExceptionCheck(env)) { - LOGE(EMSG("Catch exception")); + LOGE(MSG("Catch exception")); (*env)->ExceptionClear(env); break; } @@ -106,7 +106,7 @@ void close_output_stream(JNIEnv* env, OutputStream* outputStream) { (*env)->CallVoidMethod(env, outputStream->os, outputStream->closeMID); if ((*env)->ExceptionCheck(env)) { - LOGE(EMSG("Catch exception")); + LOGE(MSG("Catch exception")); (*env)->ExceptionClear(env); } } diff --git a/app/src/main/jni/stream/output_stream_pipe.c b/app/src/main/jni/stream/output_stream_pipe.c index d9b3e5f24..b6f61e161 100644 --- a/app/src/main/jni/stream/output_stream_pipe.c +++ b/app/src/main/jni/stream/output_stream_pipe.c @@ -35,13 +35,13 @@ OutputStreamPipe* create_output_stream_pipe(JNIEnv* env, jobject osPipe) jmethodID closeMID = (*env)->GetMethodID(env, streamPipeCls, "close", "()V"); if (obtainMID == NULL || releaseMID == NULL || openMID == NULL || closeMID == NULL) { - LOGE(EMSG("Can't get method id")); + LOGE(MSG("Can't get method id")); return NULL; } OutputStreamPipe* outputStreamPipe = (OutputStreamPipe*) malloc(sizeof(OutputStreamPipe)); if (outputStreamPipe == NULL) { - LOGE(EMSG("Out of memory")); + LOGE(MSG("Out of memory")); return NULL; } @@ -77,7 +77,7 @@ OutputStream* open_output_stream_from_pipe(JNIEnv* env, OutputStreamPipe* output { jobject os = (*env)->CallObjectMethod(env, outputStreamPipe->osPipe, outputStreamPipe->openMID); if ((*env)->ExceptionCheck(env)) { - LOGE(EMSG("Catch exception")); + LOGE(MSG("Catch exception")); (*env)->ExceptionClear(env); return NULL; }