├── .gitignore ├── README.md ├── app ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── libs │ └── armeabi │ │ ├── libeffective-bitmap.so │ │ └── libjpegbither.so ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── effective │ │ └── bitmap │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── cpp │ │ ├── effective-bitmap.c │ │ └── jpeg │ │ │ ├── android │ │ │ ├── config.h │ │ │ └── jconfig.h │ │ │ ├── cderror.h │ │ │ ├── cdjpeg.h │ │ │ ├── jconfig.h │ │ │ ├── jerror.h │ │ │ ├── jinclude.h │ │ │ ├── jmorecfg.h │ │ │ ├── jpeglib.h │ │ │ └── jversion.h │ ├── java │ │ └── com │ │ │ └── effective │ │ │ └── bitmap │ │ │ ├── MainActivity.java │ │ │ └── utils │ │ │ ├── EffectiveBitmapUtils.java │ │ │ └── UriToPathUtils.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── effective │ └── bitmap │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image ├── img1.jpg ├── img2.jpg ├── jni_278KB.png ├── quality_484KB.png ├── result.png ├── sample_199KB.png └── size_238KB.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## EffectiveBitmap 2 | 3 | #### 通过JNI实现对图片文件的压缩,到达质量、大小、清晰度综合最优。 4 | 5 | 6 | 7 | 8 | 9 | #### jni_278KB 10 | 11 | 12 | #### quality_484KB 13 | 14 | 15 | #### sample_199KB 16 | 17 | 18 | #### size_238KB 19 | 20 | 21 | - 采样率、尺寸压缩不是我们要的结果 22 | - JNI、质量压缩设置的压缩质量值均为30,JNI是278KB,直接质量压缩是484KB,综合起来,JNI最优 23 | 24 | ## 使用方法 25 | 1.将libs包中libeffective-bitmap.so、libjpegbither.so到项目中并加载即可。但是你必须使用类的限定名为“com.effective.bitmap.utils.EffectiveBitmapUtils”并添加: 26 | ``` 27 | public static native String compressBitmap(Bitmap bit, int w, int h, int quality, byte[] fileNameBytes, 28 | boolean optimize); 29 | ``` 30 | 2.download项目,构建修改自己想要的abi,以及使用类的限定名。 31 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | add_library( effective-bitmap 4 | SHARED 5 | src/main/cpp/effective-bitmap.c ) 6 | 7 | 8 | include_directories( src/main/cpp/jpeg/ 9 | ) 10 | 11 | add_library(jpegbither SHARED IMPORTED) 12 | set_target_properties(jpegbither 13 | PROPERTIES IMPORTED_LOCATION 14 | ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libjpegbither.so) 15 | 16 | 17 | find_library( log-lib 18 | log ) 19 | 20 | find_library( jnigraphics-lib jnigraphics ) 21 | 22 | target_link_libraries( effective-bitmap 23 | jpegbither 24 | ${log-lib} 25 | ${jnigraphics-lib}) -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.effective.bitmap" 7 | minSdkVersion 19 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | // externalNativeBuild { 13 | // cmake { 14 | // cppFlags "" 15 | // } 16 | // } 17 | // 18 | // ndk { 19 | // abiFilters 'armeabi' 20 | // } 21 | } 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | 29 | sourceSets { 30 | main { 31 | jni.srcDirs = [] 32 | jniLibs.srcDirs = ['libs'] 33 | } 34 | } 35 | 36 | // externalNativeBuild { 37 | // cmake { 38 | // path "CMakeLists.txt" 39 | // } 40 | // } 41 | } 42 | 43 | dependencies { 44 | implementation fileTree(dir: 'libs', include: ['*.jar']) 45 | implementation 'com.android.support:appcompat-v7:26.1.0' 46 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 47 | testImplementation 'junit:junit:4.12' 48 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 49 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 50 | } 51 | -------------------------------------------------------------------------------- /app/libs/armeabi/libeffective-bitmap.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zengfw/EffectiveBitmap/cdc76a8d103d3066e197390a168baf1170ea94e0/app/libs/armeabi/libeffective-bitmap.so -------------------------------------------------------------------------------- /app/libs/armeabi/libjpegbither.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zengfw/EffectiveBitmap/cdc76a8d103d3066e197390a168baf1170ea94e0/app/libs/armeabi/libjpegbither.so -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/effective/bitmap/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.effective.bitmap; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.effective.bitmap", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/cpp/effective-bitmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "jpeg/android/config.h" 12 | 13 | #include "jpeg/jpeglib.h" 14 | #include "jpeg/cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ 15 | 16 | 17 | #define LOG_TAG "jni" 18 | //#define LOGW(...) __android_log_write(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) 19 | //#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) 20 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) 21 | 22 | #define true 1 23 | #define false 0 24 | 25 | typedef uint8_t BYTE; 26 | 27 | char *error; 28 | struct my_error_mgr { 29 | struct jpeg_error_mgr pub; 30 | jmp_buf setjmp_buffer; 31 | }; 32 | 33 | typedef struct my_error_mgr * my_error_ptr; 34 | 35 | METHODDEF(void) 36 | my_error_exit (j_common_ptr cinfo) 37 | { 38 | my_error_ptr myerr = (my_error_ptr) cinfo->err; 39 | (*cinfo->err->output_message) (cinfo); 40 | error=(char*)myerr->pub.jpeg_message_table[myerr->pub.msg_code]; 41 | LOGE("jpeg_message_table[%d]:%s", myerr->pub.msg_code,myerr->pub.jpeg_message_table[myerr->pub.msg_code]); 42 | // LOGE("addon_message_table:%s", myerr->pub.addon_message_table); 43 | // LOGE("SIZEOF:%d",myerr->pub.msg_parm.i[0]); 44 | // LOGE("sizeof:%d",myerr->pub.msg_parm.i[1]); 45 | longjmp(myerr->setjmp_buffer, 1); 46 | } 47 | 48 | int generateJPEG(BYTE* data, int w, int h, int quality, 49 | const char* outfilename, jboolean optimize) { 50 | int nComponent = 3; 51 | // jpeg的结构体,保存的比如宽、高、位深、图片格式等信息 52 | struct jpeg_compress_struct jcs; 53 | 54 | struct my_error_mgr jem; 55 | 56 | jcs.err = jpeg_std_error(&jem.pub); 57 | jem.pub.error_exit = my_error_exit; 58 | if (setjmp(jem.setjmp_buffer)) { 59 | return 0; 60 | } 61 | jpeg_create_compress(&jcs); 62 | // 打开输出文件 wb:可写byte 63 | FILE* f = fopen(outfilename, "wb"); 64 | if (f == NULL) { 65 | return 0; 66 | } 67 | // 设置结构体的文件路径 68 | jpeg_stdio_dest(&jcs, f); 69 | jcs.image_width = w; 70 | jcs.image_height = h; 71 | 72 | // 设置哈夫曼编码 73 | jcs.arith_code = false; 74 | jcs.input_components = nComponent; 75 | if (nComponent == 1) 76 | jcs.in_color_space = JCS_GRAYSCALE; 77 | else 78 | jcs.in_color_space = JCS_RGB; 79 | 80 | jpeg_set_defaults(&jcs); 81 | jcs.optimize_coding = optimize; 82 | jpeg_set_quality(&jcs, quality, true); 83 | // 开始压缩,写入全部像素 84 | jpeg_start_compress(&jcs, TRUE); 85 | 86 | JSAMPROW row_pointer[1]; 87 | int row_stride; 88 | row_stride = jcs.image_width * nComponent; 89 | while (jcs.next_scanline < jcs.image_height) { 90 | row_pointer[0] = &data[jcs.next_scanline * row_stride]; 91 | jpeg_write_scanlines(&jcs, row_pointer, 1); 92 | } 93 | 94 | jpeg_finish_compress(&jcs); 95 | jpeg_destroy_compress(&jcs); 96 | fclose(f); 97 | 98 | return 1; 99 | } 100 | 101 | typedef struct { 102 | uint8_t r; 103 | uint8_t g; 104 | uint8_t b; 105 | } rgb; 106 | 107 | char* jstrinTostring(JNIEnv* env, jbyteArray barr) { 108 | char* rtn = NULL; 109 | jsize alen = (*env)->GetArrayLength(env, barr); 110 | jbyte* ba = (*env)->GetByteArrayElements(env, barr, 0); 111 | if (alen > 0) { 112 | rtn = (char*) malloc(alen + 1); 113 | memcpy(rtn, ba, alen); 114 | rtn[alen] = 0; 115 | } 116 | (*env)->ReleaseByteArrayElements(env, barr, ba, 0); 117 | return rtn; 118 | } 119 | 120 | jstring Java_com_effective_bitmap_utils_EffectiveBitmapUtils_compressBitmap(JNIEnv* env, 121 | jobject thiz, jobject bitmapcolor, int w, int h, int quality, 122 | jbyteArray fileNameStr, jboolean optimize) { 123 | 124 | AndroidBitmapInfo infocolor; 125 | BYTE* pixelscolor; 126 | int ret; 127 | BYTE * data; 128 | BYTE *tmpdata; 129 | char * fileName = jstrinTostring(env, fileNameStr); 130 | if ((ret = AndroidBitmap_getInfo(env, bitmapcolor, &infocolor)) < 0) { 131 | LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret); 132 | return (*env)->NewStringUTF(env, "0");; 133 | } 134 | if ((ret = AndroidBitmap_lockPixels(env, bitmapcolor, (void**)&pixelscolor)) < 0) { 135 | LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret); 136 | } 137 | 138 | BYTE r, g, b; 139 | data = NULL; 140 | data = malloc(w * h * 3); 141 | tmpdata = data; 142 | int j = 0, i = 0; 143 | int color; 144 | for (i = 0; i < h; i++) { 145 | for (j = 0; j < w; j++) { 146 | color = *((int *) pixelscolor); 147 | r = ((color & 0x00FF0000) >> 16); 148 | g = ((color & 0x0000FF00) >> 8); 149 | b = color & 0x000000FF; 150 | *data = b; 151 | *(data + 1) = g; 152 | *(data + 2) = r; 153 | data = data + 3; 154 | pixelscolor += 4; 155 | 156 | } 157 | 158 | } 159 | AndroidBitmap_unlockPixels(env, bitmapcolor); 160 | int resultCode= generateJPEG(tmpdata, w, h, quality, fileName, optimize); 161 | free(tmpdata); 162 | if(resultCode==0){ 163 | jstring result=(*env)->NewStringUTF(env, error); 164 | error=NULL; 165 | return result; 166 | } 167 | return (*env)->NewStringUTF(env, "1"); //success 168 | } -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/android/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Build number */ 5 | #define BUILD "20110829" 6 | 7 | /* Support arithmetic encoding */ 8 | #define C_ARITH_CODING_SUPPORTED 1 9 | 10 | /* Support arithmetic decoding */ 11 | #define D_ARITH_CODING_SUPPORTED 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_DLFCN_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_INTTYPES_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | /* #undef HAVE_JNI_H */ 21 | 22 | /* Define to 1 if you have the `memcpy' function. */ 23 | #define HAVE_MEMCPY 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_MEMORY_H 1 27 | 28 | /* Define to 1 if you have the `memset' function. */ 29 | #define HAVE_MEMSET 1 30 | 31 | /* Define if your compiler supports prototypes */ 32 | #define HAVE_PROTOTYPES 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDDEF_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_STDINT_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_STDLIB_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_STRINGS_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_STRING_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_STAT_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_SYS_TYPES_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_UNISTD_H 1 57 | 58 | /* Define to 1 if the system has the type `unsigned char'. */ 59 | #define HAVE_UNSIGNED_CHAR 1 60 | 61 | /* Define to 1 if the system has the type `unsigned short'. */ 62 | #define HAVE_UNSIGNED_SHORT 1 63 | 64 | /* Compiler does not support pointers to undefined structures. */ 65 | /* #undef INCOMPLETE_TYPES_BROKEN */ 66 | 67 | /* libjpeg API version */ 68 | #define JPEG_LIB_VERSION 62 69 | 70 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 71 | */ 72 | #define LT_OBJDIR ".libs/" 73 | 74 | /* Define if you have BSD-like bzero and bcopy */ 75 | /* #undef NEED_BSD_STRINGS */ 76 | 77 | /* Define if you need short function names */ 78 | /* #undef NEED_SHORT_EXTERNAL_NAMES */ 79 | //#define NEED_SHORT_EXTERNAL_NAMES 80 | 81 | /* Define if you have sys/types.h */ 82 | #define NEED_SYS_TYPES_H 1 83 | 84 | /* Name of package */ 85 | #define PACKAGE "libjpeg-turbo" 86 | 87 | /* Define to the address where bug reports for this package should be sent. */ 88 | #define PACKAGE_BUGREPORT "" 89 | 90 | /* Define to the full name of this package. */ 91 | #define PACKAGE_NAME "libjpeg-turbo" 92 | 93 | /* Define to the full name and version of this package. */ 94 | #define PACKAGE_STRING "libjpeg-turbo 1.1.90" 95 | 96 | /* Define to the one symbol short name of this package. */ 97 | #define PACKAGE_TARNAME "libjpeg-turbo" 98 | 99 | /* Define to the home page for this package. */ 100 | #define PACKAGE_URL "" 101 | 102 | /* Define to the version of this package. */ 103 | #define PACKAGE_VERSION "1.1.90" 104 | 105 | /* Define if shift is unsigned */ 106 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */ 107 | 108 | /* Define to 1 if you have the ANSI C header files. */ 109 | #define STDC_HEADERS 1 110 | 111 | /* Version number of package */ 112 | #define VERSION "1.1.90" 113 | 114 | /* Use accelerated SIMD routines. */ 115 | #define WITH_SIMD 1 116 | 117 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */ 118 | #ifndef __CHAR_UNSIGNED__ 119 | /* # undef __CHAR_UNSIGNED__ */ 120 | #endif 121 | 122 | /* Define to empty if `const' does not conform to ANSI C. */ 123 | /* #undef const */ 124 | 125 | /* Define to `__inline__' or `__inline' if that's what the C compiler 126 | calls it, or to nothing if 'inline' is not supported under any name. */ 127 | #ifndef __cplusplus 128 | /* #undef inline */ 129 | #endif 130 | 131 | /* Define to `unsigned int' if does not define. */ 132 | /* #undef size_t */ 133 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/android/jconfig.h: -------------------------------------------------------------------------------- 1 | /* jconfig.h. Generated from jconfig.h.in by configure. */ 2 | /* Version ID for the JPEG library. 3 | * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". 4 | */ 5 | #define JPEG_LIB_VERSION 62 6 | 7 | /* Support arithmetic encoding */ 8 | #define C_ARITH_CODING_SUPPORTED 1 9 | 10 | /* Support arithmetic decoding */ 11 | #define D_ARITH_CODING_SUPPORTED 1 12 | 13 | /* Define if your compiler supports prototypes */ 14 | #define HAVE_PROTOTYPES 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STDDEF_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STDLIB_H 1 21 | 22 | /* Define to 1 if the system has the type `unsigned char'. */ 23 | #define HAVE_UNSIGNED_CHAR 1 24 | 25 | /* Define to 1 if the system has the type `unsigned short'. */ 26 | #define HAVE_UNSIGNED_SHORT 1 27 | 28 | /* Define if you want use complete types */ 29 | /* #undef INCOMPLETE_TYPES_BROKEN */ 30 | 31 | /* Define if you have BSD-like bzero and bcopy */ 32 | /* #undef NEED_BSD_STRINGS */ 33 | 34 | /* Define if you need short function names */ 35 | /* #undef NEED_SHORT_EXTERNAL_NAMES */ 36 | 37 | /* Define if you have sys/types.h */ 38 | #define NEED_SYS_TYPES_H 1 39 | 40 | /* Define if shift is unsigned */ 41 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */ 42 | 43 | /* Use accelerated SIMD routines. */ 44 | #define WITH_SIMD 1 45 | 46 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */ 47 | #ifndef __CHAR_UNSIGNED__ 48 | /* # undef __CHAR_UNSIGNED__ */ 49 | #endif 50 | 51 | /* Define to empty if `const' does not conform to ANSI C. */ 52 | /* #undef const */ 53 | 54 | /* Define to `__inline__' or `__inline' if that's what the C compiler 55 | calls it, or to nothing if 'inline' is not supported under any name. */ 56 | #ifndef __cplusplus 57 | /* #undef inline */ 58 | #endif 59 | 60 | /* Define to `unsigned int' if does not define. */ 61 | /* #undef size_t */ 62 | 63 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/cderror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cderror.h 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * Modified 2009 by Guido Vollbeding. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file defines the error and message codes for the cjpeg/djpeg 10 | * applications. These strings are not needed as part of the JPEG library 11 | * proper. 12 | * Edit this file to add new codes, or to translate the message strings to 13 | * some other language. 14 | */ 15 | 16 | /* 17 | * To define the enum list of message codes, include this file without 18 | * defining macro JMESSAGE. To create a message string table, include it 19 | * again with a suitable JMESSAGE definition (see jerror.c for an example). 20 | */ 21 | #ifndef JMESSAGE 22 | #ifndef CDERROR_H 23 | #define CDERROR_H 24 | /* First time through, define the enum list */ 25 | #define JMAKE_ENUM_LIST 26 | #else 27 | /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ 28 | #define JMESSAGE(code,string) 29 | #endif /* CDERROR_H */ 30 | #endif /* JMESSAGE */ 31 | 32 | #ifdef JMAKE_ENUM_LIST 33 | 34 | typedef enum { 35 | 36 | #define JMESSAGE(code,string) code , 37 | 38 | #endif /* JMAKE_ENUM_LIST */ 39 | 40 | JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */ 41 | 42 | #ifdef BMP_SUPPORTED 43 | JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format") 44 | JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported") 45 | JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length") 46 | JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1") 47 | JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB") 48 | JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported") 49 | JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image") 50 | JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM") 51 | JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image") 52 | JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image") 53 | JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image") 54 | JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image") 55 | #endif /* BMP_SUPPORTED */ 56 | 57 | #ifdef GIF_SUPPORTED 58 | JMESSAGE(JERR_GIF_BUG, "GIF output got confused") 59 | JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d") 60 | JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB") 61 | JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file") 62 | JMESSAGE(JERR_GIF_NOT, "Not a GIF file") 63 | JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image") 64 | JMESSAGE(JTRC_GIF_BADVERSION, 65 | "Warning: unexpected GIF version number '%c%c%c'") 66 | JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x") 67 | JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input") 68 | JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file") 69 | JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring") 70 | JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image") 71 | JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits") 72 | #endif /* GIF_SUPPORTED */ 73 | 74 | #ifdef PPM_SUPPORTED 75 | JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB") 76 | JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file") 77 | JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file") 78 | JMESSAGE(JTRC_PGM, "%ux%u PGM image") 79 | JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image") 80 | JMESSAGE(JTRC_PPM, "%ux%u PPM image") 81 | JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image") 82 | #endif /* PPM_SUPPORTED */ 83 | 84 | #ifdef RLE_SUPPORTED 85 | JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library") 86 | JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB") 87 | JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE") 88 | JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file") 89 | JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header") 90 | JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header") 91 | JMESSAGE(JERR_RLE_NOT, "Not an RLE file") 92 | JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE") 93 | JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup") 94 | JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file") 95 | JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d") 96 | JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file") 97 | JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d") 98 | JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d") 99 | #endif /* RLE_SUPPORTED */ 100 | 101 | #ifdef TARGA_SUPPORTED 102 | JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format") 103 | JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file") 104 | JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB") 105 | JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image") 106 | JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image") 107 | JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image") 108 | #else 109 | JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled") 110 | #endif /* TARGA_SUPPORTED */ 111 | 112 | JMESSAGE(JERR_BAD_CMAP_FILE, 113 | "Color map file is invalid or of unsupported format") 114 | JMESSAGE(JERR_TOO_MANY_COLORS, 115 | "Output file format cannot handle %d colormap entries") 116 | JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed") 117 | #ifdef TARGA_SUPPORTED 118 | JMESSAGE(JERR_UNKNOWN_FORMAT, 119 | "Unrecognized input file format --- perhaps you need -targa") 120 | #else 121 | JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format") 122 | #endif 123 | JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format") 124 | 125 | #ifdef JMAKE_ENUM_LIST 126 | 127 | JMSG_LASTADDONCODE 128 | } ADDON_MESSAGE_CODE; 129 | 130 | #undef JMAKE_ENUM_LIST 131 | #endif /* JMAKE_ENUM_LIST */ 132 | 133 | /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ 134 | #undef JMESSAGE 135 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/cdjpeg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cdjpeg.h 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains common declarations for the sample applications 9 | * cjpeg and djpeg. It is NOT used by the core JPEG library. 10 | */ 11 | 12 | #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */ 13 | #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */ 14 | #include "jinclude.h" 15 | #include "jpeglib.h" 16 | #include "jerror.h" /* get library error codes too */ 17 | #include "cderror.h" /* get application-specific error codes */ 18 | #include 19 | #include 20 | 21 | /* 22 | * Object interface for cjpeg's source file decoding modules 23 | */ 24 | 25 | typedef struct cjpeg_source_struct * cjpeg_source_ptr; 26 | 27 | struct cjpeg_source_struct { 28 | JMETHOD(void, start_input, (j_compress_ptr cinfo, 29 | cjpeg_source_ptr sinfo)); 30 | JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, 31 | cjpeg_source_ptr sinfo)); 32 | JMETHOD(void, finish_input, (j_compress_ptr cinfo, 33 | cjpeg_source_ptr sinfo)); 34 | 35 | FILE *input_file; 36 | 37 | JSAMPARRAY buffer; 38 | JDIMENSION buffer_height; 39 | }; 40 | 41 | 42 | /* 43 | * Object interface for djpeg's output file encoding modules 44 | */ 45 | 46 | typedef struct djpeg_dest_struct * djpeg_dest_ptr; 47 | 48 | struct djpeg_dest_struct { 49 | /* start_output is called after jpeg_start_decompress finishes. 50 | * The color map will be ready at this time, if one is needed. 51 | */ 52 | JMETHOD(void, start_output, (j_decompress_ptr cinfo, 53 | djpeg_dest_ptr dinfo)); 54 | /* Emit the specified number of pixel rows from the buffer. */ 55 | JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo, 56 | djpeg_dest_ptr dinfo, 57 | JDIMENSION rows_supplied)); 58 | /* Finish up at the end of the image. */ 59 | JMETHOD(void, finish_output, (j_decompress_ptr cinfo, 60 | djpeg_dest_ptr dinfo)); 61 | 62 | /* Target file spec; filled in by djpeg.c after object is created. */ 63 | FILE * output_file; 64 | 65 | /* Output pixel-row buffer. Created by module init or start_output. 66 | * Width is cinfo->output_width * cinfo->output_components; 67 | * height is buffer_height. 68 | */ 69 | JSAMPARRAY buffer; 70 | JDIMENSION buffer_height; 71 | }; 72 | 73 | 74 | /* 75 | * cjpeg/djpeg may need to perform extra passes to convert to or from 76 | * the source/destination file format. The JPEG library does not know 77 | * about these passes, but we'd like them to be counted by the progress 78 | * monitor. We use an expanded progress monitor object to hold the 79 | * additional pass count. 80 | */ 81 | 82 | struct cdjpeg_progress_mgr { 83 | struct jpeg_progress_mgr pub; /* fields known to JPEG library */ 84 | int completed_extra_passes; /* extra passes completed */ 85 | int total_extra_passes; /* total extra */ 86 | /* last printed percentage stored here to avoid multiple printouts */ 87 | int percent_done; 88 | }; 89 | 90 | typedef struct cdjpeg_progress_mgr * cd_progress_ptr; 91 | 92 | 93 | /* Short forms of external names for systems with brain-damaged linkers. */ 94 | 95 | #ifdef NEED_SHORT_EXTERNAL_NAMES 96 | #define jinit_read_bmp jIRdBMP 97 | #define jinit_write_bmp jIWrBMP 98 | #define jinit_read_gif jIRdGIF 99 | #define jinit_write_gif jIWrGIF 100 | #define jinit_read_ppm jIRdPPM 101 | #define jinit_write_ppm jIWrPPM 102 | #define jinit_read_rle jIRdRLE 103 | #define jinit_write_rle jIWrRLE 104 | #define jinit_read_targa jIRdTarga 105 | #define jinit_write_targa jIWrTarga 106 | #define read_quant_tables RdQTables 107 | #define read_scan_script RdScnScript 108 | #define set_quality_ratings SetQRates 109 | #define set_quant_slots SetQSlots 110 | #define set_sample_factors SetSFacts 111 | #define read_color_map RdCMap 112 | #define enable_signal_catcher EnSigCatcher 113 | #define start_progress_monitor StProgMon 114 | #define end_progress_monitor EnProgMon 115 | #define read_stdin RdStdin 116 | #define write_stdout WrStdout 117 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 118 | 119 | /* Module selection routines for I/O modules. */ 120 | 121 | EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo)); 122 | EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo, 123 | boolean is_os2)); 124 | EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo)); 125 | EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo)); 126 | EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo)); 127 | EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo)); 128 | EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo)); 129 | EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo)); 130 | EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo)); 131 | EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo)); 132 | 133 | /* cjpeg support routines (in rdswitch.c) */ 134 | 135 | EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename, 136 | boolean force_baseline)); 137 | EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename)); 138 | EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg, 139 | boolean force_baseline)); 140 | EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg)); 141 | EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg)); 142 | 143 | /* djpeg support routines (in rdcolmap.c) */ 144 | 145 | EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile)); 146 | 147 | /* common support routines (in cdjpeg.c) */ 148 | 149 | EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo)); 150 | EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo, 151 | cd_progress_ptr progress)); 152 | EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo)); 153 | EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars)); 154 | EXTERN(FILE *) read_stdin JPP((void)); 155 | EXTERN(FILE *) write_stdout JPP((void)); 156 | 157 | /* miscellaneous useful macros */ 158 | 159 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ 160 | #define READ_BINARY "r" 161 | #define WRITE_BINARY "w" 162 | #else 163 | #ifdef VMS /* VMS is very nonstandard */ 164 | #define READ_BINARY "rb", "ctx=stm" 165 | #define WRITE_BINARY "wb", "ctx=stm" 166 | #else /* standard ANSI-compliant case */ 167 | #define READ_BINARY "rb" 168 | #define WRITE_BINARY "wb" 169 | #endif 170 | #endif 171 | 172 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ 173 | #define EXIT_FAILURE 1 174 | #endif 175 | #ifndef EXIT_SUCCESS 176 | #ifdef VMS 177 | #define EXIT_SUCCESS 1 /* VMS is very nonstandard */ 178 | #else 179 | #define EXIT_SUCCESS 0 180 | #endif 181 | #endif 182 | #ifndef EXIT_WARNING 183 | #ifdef VMS 184 | #define EXIT_WARNING 1 /* VMS is very nonstandard */ 185 | #else 186 | #define EXIT_WARNING 2 187 | #endif 188 | #endif 189 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/jconfig.h: -------------------------------------------------------------------------------- 1 | /* jconfig.h. Generated from jconfig.h.in by configure. */ 2 | /* Version ID for the JPEG library. 3 | * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". 4 | */ 5 | #define JPEG_LIB_VERSION 62 6 | 7 | /* Support arithmetic encoding */ 8 | #define C_ARITH_CODING_SUPPORTED 1 9 | 10 | /* Support arithmetic decoding */ 11 | #define D_ARITH_CODING_SUPPORTED 1 12 | 13 | /* Define if your compiler supports prototypes */ 14 | #define HAVE_PROTOTYPES 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STDDEF_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STDLIB_H 1 21 | 22 | /* Define to 1 if the system has the type `unsigned char'. */ 23 | #define HAVE_UNSIGNED_CHAR 1 24 | 25 | /* Define to 1 if the system has the type `unsigned short'. */ 26 | #define HAVE_UNSIGNED_SHORT 1 27 | 28 | /* Define if you want use complete types */ 29 | /* #undef INCOMPLETE_TYPES_BROKEN */ 30 | 31 | /* Define if you have BSD-like bzero and bcopy */ 32 | /* #undef NEED_BSD_STRINGS */ 33 | 34 | /* Define if you need short function names */ 35 | /* #undef NEED_SHORT_EXTERNAL_NAMES */ 36 | 37 | /* Define if you have sys/types.h */ 38 | #define NEED_SYS_TYPES_H 1 39 | 40 | /* Define if shift is unsigned */ 41 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */ 42 | 43 | /* Use accelerated SIMD routines. */ 44 | #define WITH_SIMD 1 45 | 46 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */ 47 | #ifndef __CHAR_UNSIGNED__ 48 | /* # undef __CHAR_UNSIGNED__ */ 49 | #endif 50 | 51 | /* Define to empty if `const' does not conform to ANSI C. */ 52 | /* #undef const */ 53 | 54 | /* Define to `__inline__' or `__inline' if that's what the C compiler 55 | calls it, or to nothing if 'inline' is not supported under any name. */ 56 | #ifndef __cplusplus 57 | /* #undef inline */ 58 | #endif 59 | 60 | #define INLINE inline 61 | 62 | /* Define to `unsigned int' if does not define. */ 63 | /* #undef size_t */ 64 | 65 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/jerror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jerror.h 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * Modified 1997-2009 by Guido Vollbeding. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file defines the error and message codes for the JPEG library. 10 | * Edit this file to add new codes, or to translate the message strings to 11 | * some other language. 12 | * A set of error-reporting macros are defined too. Some applications using 13 | * the JPEG library may wish to include this file to get the error codes 14 | * and/or the macros. 15 | */ 16 | 17 | /* 18 | * To define the enum list of message codes, include this file without 19 | * defining macro JMESSAGE. To create a message string table, include it 20 | * again with a suitable JMESSAGE definition (see jerror.c for an example). 21 | */ 22 | #ifndef JMESSAGE 23 | #ifndef JERROR_H 24 | /* First time through, define the enum list */ 25 | #define JMAKE_ENUM_LIST 26 | #else 27 | /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ 28 | #define JMESSAGE(code,string) 29 | #endif /* JERROR_H */ 30 | #endif /* JMESSAGE */ 31 | 32 | #ifdef JMAKE_ENUM_LIST 33 | 34 | typedef enum { 35 | 36 | #define JMESSAGE(code,string) code , 37 | 38 | #endif /* JMAKE_ENUM_LIST */ 39 | 40 | JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */ 41 | 42 | /* For maintenance convenience, list is alphabetical by message code name */ 43 | #if JPEG_LIB_VERSION < 70 44 | JMESSAGE(JERR_ARITH_NOTIMPL, 45 | "Sorry, arithmetic coding is not implemented") 46 | #endif 47 | JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") 48 | JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") 49 | JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode") 50 | JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") 51 | #if JPEG_LIB_VERSION >= 70 52 | JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request") 53 | #endif 54 | JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range") 55 | JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") 56 | #if JPEG_LIB_VERSION >= 70 57 | JMESSAGE(JERR_BAD_DROP_SAMPLING, 58 | "Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c") 59 | #endif 60 | JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") 61 | JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") 62 | JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") 63 | JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") 64 | JMESSAGE(JERR_BAD_LIB_VERSION, 65 | "Wrong JPEG library version: library is %d, caller expects %d") 66 | JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") 67 | JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") 68 | JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") 69 | JMESSAGE(JERR_BAD_PROGRESSION, 70 | "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") 71 | JMESSAGE(JERR_BAD_PROG_SCRIPT, 72 | "Invalid progressive parameters at scan script entry %d") 73 | JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") 74 | JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") 75 | JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") 76 | JMESSAGE(JERR_BAD_STRUCT_SIZE, 77 | "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") 78 | JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") 79 | JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") 80 | JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") 81 | JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet") 82 | JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d") 83 | JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request") 84 | JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d") 85 | JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x") 86 | JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d") 87 | JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d") 88 | JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)") 89 | JMESSAGE(JERR_EMS_READ, "Read from EMS failed") 90 | JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed") 91 | JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan") 92 | JMESSAGE(JERR_FILE_READ, "Input file read error") 93 | JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") 94 | JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") 95 | JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow") 96 | JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") 97 | JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") 98 | JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") 99 | JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") 100 | JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, 101 | "Cannot transcode due to multiple use of quantization table %d") 102 | JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") 103 | JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") 104 | JMESSAGE(JERR_NOTIMPL, "Not implemented yet") 105 | JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") 106 | #if JPEG_LIB_VERSION >= 70 107 | JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined") 108 | #endif 109 | JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") 110 | JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined") 111 | JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image") 112 | JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined") 113 | JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") 114 | JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") 115 | JMESSAGE(JERR_QUANT_COMPONENTS, 116 | "Cannot quantize more than %d color components") 117 | JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") 118 | JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") 119 | JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") 120 | JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") 121 | JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") 122 | JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") 123 | JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF") 124 | JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") 125 | JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") 126 | JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") 127 | JMESSAGE(JERR_TFILE_WRITE, 128 | "Write failed on temporary file --- out of disk space?") 129 | JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") 130 | JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") 131 | JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") 132 | JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") 133 | JMESSAGE(JERR_XMS_READ, "Read from XMS failed") 134 | JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") 135 | JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) 136 | JMESSAGE(JMSG_VERSION, JVERSION) 137 | JMESSAGE(JTRC_16BIT_TABLES, 138 | "Caution: quantization tables are too coarse for baseline JPEG") 139 | JMESSAGE(JTRC_ADOBE, 140 | "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") 141 | JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") 142 | JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") 143 | JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") 144 | JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x") 145 | JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d") 146 | JMESSAGE(JTRC_DRI, "Define Restart Interval %u") 147 | JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u") 148 | JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u") 149 | JMESSAGE(JTRC_EOI, "End Of Image") 150 | JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") 151 | JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") 152 | JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, 153 | "Warning: thumbnail image size does not match data length %u") 154 | JMESSAGE(JTRC_JFIF_EXTENSION, 155 | "JFIF extension marker: type 0x%02x, length %u") 156 | JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") 157 | JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") 158 | JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") 159 | JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u") 160 | JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors") 161 | JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors") 162 | JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization") 163 | JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") 164 | JMESSAGE(JTRC_RST, "RST%d") 165 | JMESSAGE(JTRC_SMOOTH_NOTIMPL, 166 | "Smoothing not supported with nonstandard sampling ratios") 167 | JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") 168 | JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") 169 | JMESSAGE(JTRC_SOI, "Start of Image") 170 | JMESSAGE(JTRC_SOS, "Start Of Scan: %d components") 171 | JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d") 172 | JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d") 173 | JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") 174 | JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") 175 | JMESSAGE(JTRC_THUMB_JPEG, 176 | "JFIF extension marker: JPEG-compressed thumbnail image, length %u") 177 | JMESSAGE(JTRC_THUMB_PALETTE, 178 | "JFIF extension marker: palette thumbnail image, length %u") 179 | JMESSAGE(JTRC_THUMB_RGB, 180 | "JFIF extension marker: RGB thumbnail image, length %u") 181 | JMESSAGE(JTRC_UNKNOWN_IDS, 182 | "Unrecognized component IDs %d %d %d, assuming YCbCr") 183 | JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") 184 | JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") 185 | JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") 186 | #if JPEG_LIB_VERSION >= 70 187 | JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") 188 | #endif 189 | JMESSAGE(JWRN_BOGUS_PROGRESSION, 190 | "Inconsistent progression sequence for component %d coefficient %d") 191 | JMESSAGE(JWRN_EXTRANEOUS_DATA, 192 | "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") 193 | JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") 194 | JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") 195 | JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") 196 | JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") 197 | JMESSAGE(JWRN_MUST_RESYNC, 198 | "Corrupt JPEG data: found marker 0x%02x instead of RST%d") 199 | JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") 200 | JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") 201 | #if JPEG_LIB_VERSION < 70 202 | JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request") 203 | #if defined(C_ARITH_CODING_SUPPORTED) || defined(D_ARITH_CODING_SUPPORTED) 204 | JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined") 205 | JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") 206 | #endif 207 | #endif 208 | 209 | #ifdef JMAKE_ENUM_LIST 210 | 211 | JMSG_LASTMSGCODE 212 | } J_MESSAGE_CODE; 213 | 214 | #undef JMAKE_ENUM_LIST 215 | #endif /* JMAKE_ENUM_LIST */ 216 | 217 | /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ 218 | #undef JMESSAGE 219 | 220 | 221 | #ifndef JERROR_H 222 | #define JERROR_H 223 | 224 | /* Macros to simplify using the error and trace message stuff */ 225 | /* The first parameter is either type of cinfo pointer */ 226 | 227 | /* Fatal errors (print message and exit) */ 228 | #define ERREXIT(cinfo,code) \ 229 | ((cinfo)->err->msg_code = (code), \ 230 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 231 | #define ERREXIT1(cinfo,code,p1) \ 232 | ((cinfo)->err->msg_code = (code), \ 233 | (cinfo)->err->msg_parm.i[0] = (p1), \ 234 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 235 | #define ERREXIT2(cinfo,code,p1,p2) \ 236 | ((cinfo)->err->msg_code = (code), \ 237 | (cinfo)->err->msg_parm.i[0] = (p1), \ 238 | (cinfo)->err->msg_parm.i[1] = (p2), \ 239 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 240 | #define ERREXIT3(cinfo,code,p1,p2,p3) \ 241 | ((cinfo)->err->msg_code = (code), \ 242 | (cinfo)->err->msg_parm.i[0] = (p1), \ 243 | (cinfo)->err->msg_parm.i[1] = (p2), \ 244 | (cinfo)->err->msg_parm.i[2] = (p3), \ 245 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 246 | #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ 247 | ((cinfo)->err->msg_code = (code), \ 248 | (cinfo)->err->msg_parm.i[0] = (p1), \ 249 | (cinfo)->err->msg_parm.i[1] = (p2), \ 250 | (cinfo)->err->msg_parm.i[2] = (p3), \ 251 | (cinfo)->err->msg_parm.i[3] = (p4), \ 252 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 253 | #define ERREXITS(cinfo,code,str) \ 254 | ((cinfo)->err->msg_code = (code), \ 255 | strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ 256 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 257 | 258 | #define MAKESTMT(stuff) do { stuff } while (0) 259 | 260 | /* Nonfatal errors (we can keep going, but the data is probably corrupt) */ 261 | #define WARNMS(cinfo,code) \ 262 | ((cinfo)->err->msg_code = (code), \ 263 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) 264 | #define WARNMS1(cinfo,code,p1) \ 265 | ((cinfo)->err->msg_code = (code), \ 266 | (cinfo)->err->msg_parm.i[0] = (p1), \ 267 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) 268 | #define WARNMS2(cinfo,code,p1,p2) \ 269 | ((cinfo)->err->msg_code = (code), \ 270 | (cinfo)->err->msg_parm.i[0] = (p1), \ 271 | (cinfo)->err->msg_parm.i[1] = (p2), \ 272 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) 273 | 274 | /* Informational/debugging messages */ 275 | #define TRACEMS(cinfo,lvl,code) \ 276 | ((cinfo)->err->msg_code = (code), \ 277 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 278 | #define TRACEMS1(cinfo,lvl,code,p1) \ 279 | ((cinfo)->err->msg_code = (code), \ 280 | (cinfo)->err->msg_parm.i[0] = (p1), \ 281 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 282 | #define TRACEMS2(cinfo,lvl,code,p1,p2) \ 283 | ((cinfo)->err->msg_code = (code), \ 284 | (cinfo)->err->msg_parm.i[0] = (p1), \ 285 | (cinfo)->err->msg_parm.i[1] = (p2), \ 286 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 287 | #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ 288 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 289 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ 290 | (cinfo)->err->msg_code = (code); \ 291 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 292 | #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ 293 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 294 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ 295 | (cinfo)->err->msg_code = (code); \ 296 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 297 | #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ 298 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 299 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ 300 | _mp[4] = (p5); \ 301 | (cinfo)->err->msg_code = (code); \ 302 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 303 | #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ 304 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 305 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ 306 | _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ 307 | (cinfo)->err->msg_code = (code); \ 308 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 309 | #define TRACEMSS(cinfo,lvl,code,str) \ 310 | ((cinfo)->err->msg_code = (code), \ 311 | strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ 312 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 313 | 314 | #endif /* JERROR_H */ 315 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/jinclude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jinclude.h 3 | * 4 | * Copyright (C) 1991-1994, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file exists to provide a single place to fix any problems with 9 | * including the wrong system include files. (Common problems are taken 10 | * care of by the standard jconfig symbols, but on really weird systems 11 | * you may have to edit this file.) 12 | * 13 | * NOTE: this file is NOT intended to be included by applications using the 14 | * JPEG library. Most applications need only include jpeglib.h. 15 | */ 16 | 17 | 18 | /* Include auto-config file to find out which system include files we need. */ 19 | 20 | #include "jconfig.h" /* auto configuration options */ 21 | #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ 22 | 23 | /* 24 | * We need the NULL macro and size_t typedef. 25 | * On an ANSI-conforming system it is sufficient to include . 26 | * Otherwise, we get them from or ; we may have to 27 | * pull in as well. 28 | * Note that the core JPEG library does not require ; 29 | * only the default error handler and data source/destination modules do. 30 | * But we must pull it in because of the references to FILE in jpeglib.h. 31 | * You can remove those references if you want to compile without . 32 | */ 33 | 34 | #ifdef HAVE_STDDEF_H 35 | #include 36 | #endif 37 | 38 | #ifdef HAVE_STDLIB_H 39 | #include 40 | #endif 41 | 42 | #ifdef NEED_SYS_TYPES_H 43 | #include 44 | #endif 45 | 46 | #include 47 | 48 | /* 49 | * We need memory copying and zeroing functions, plus strncpy(). 50 | * ANSI and System V implementations declare these in . 51 | * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). 52 | * Some systems may declare memset and memcpy in . 53 | * 54 | * NOTE: we assume the size parameters to these functions are of type size_t. 55 | * Change the casts in these macros if not! 56 | */ 57 | 58 | #ifdef NEED_BSD_STRINGS 59 | 60 | #include 61 | #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) 62 | #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) 63 | 64 | #else /* not BSD, assume ANSI/SysV string lib */ 65 | 66 | #include 67 | #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) 68 | #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) 69 | 70 | #endif 71 | 72 | /* 73 | * In ANSI C, and indeed any rational implementation, size_t is also the 74 | * type returned by sizeof(). However, it seems there are some irrational 75 | * implementations out there, in which sizeof() returns an int even though 76 | * size_t is defined as long or unsigned long. To ensure consistent results 77 | * we always use this SIZEOF() macro in place of using sizeof() directly. 78 | */ 79 | 80 | #define SIZEOF(object) ((size_t) sizeof(object)) 81 | 82 | /* 83 | * The modules that use fread() and fwrite() always invoke them through 84 | * these macros. On some systems you may need to twiddle the argument casts. 85 | * CAUTION: argument order is different from underlying functions! 86 | */ 87 | 88 | #define JFREAD(file,buf,sizeofbuf) \ 89 | ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 90 | #define JFWRITE(file,buf,sizeofbuf) \ 91 | ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 92 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/jmorecfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jmorecfg.h 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * Copyright (C) 2009, 2011, D. R. Commander. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file contains additional configuration options that customize the 10 | * JPEG software for special applications or support machine-dependent 11 | * optimizations. Most users will not need to touch this file. 12 | */ 13 | 14 | /* 15 | * When we're building for android, turn on ANDROID_RGB by default. 16 | * This is needed for components like skia which make use of the 17 | * new encodings defined behind ANDROID_RBG. It's not a reasonable 18 | * config to have ANDROID_RBG off. 19 | */ 20 | #ifdef ANDROID 21 | #ifndef ANDROID_RGB 22 | #define ANDROID_RGB 23 | #endif 24 | #endif 25 | 26 | /* 27 | * Define BITS_IN_JSAMPLE as either 28 | * 8 for 8-bit sample values (the usual setting) 29 | * 12 for 12-bit sample values 30 | * Only 8 and 12 are legal data precisions for lossy JPEG according to the 31 | * JPEG standard, and the IJG code does not support anything else! 32 | * We do not support run-time selection of data precision, sorry. 33 | */ 34 | 35 | #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ 36 | 37 | 38 | /* 39 | * Maximum number of components (color channels) allowed in JPEG image. 40 | * To meet the letter of the JPEG spec, set this to 255. However, darn 41 | * few applications need more than 4 channels (maybe 5 for CMYK + alpha 42 | * mask). We recommend 10 as a reasonable compromise; use 4 if you are 43 | * really short on memory. (Each allowed component costs a hundred or so 44 | * bytes of storage, whether actually used in an image or not.) 45 | */ 46 | 47 | #define MAX_COMPONENTS 10 /* maximum number of image components */ 48 | 49 | 50 | /* 51 | * Basic data types. 52 | * You may need to change these if you have a machine with unusual data 53 | * type sizes; for example, "char" not 8 bits, "short" not 16 bits, 54 | * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits, 55 | * but it had better be at least 16. 56 | */ 57 | 58 | /* Representation of a single sample (pixel element value). 59 | * We frequently allocate large arrays of these, so it's important to keep 60 | * them small. But if you have memory to burn and access to char or short 61 | * arrays is very slow on your hardware, you might want to change these. 62 | */ 63 | 64 | #if BITS_IN_JSAMPLE == 8 65 | /* JSAMPLE should be the smallest type that will hold the values 0..255. 66 | * You can use a signed char by having GETJSAMPLE mask it with 0xFF. 67 | */ 68 | 69 | #ifdef HAVE_UNSIGNED_CHAR 70 | 71 | typedef unsigned char JSAMPLE; 72 | #define GETJSAMPLE(value) ((int) (value)) 73 | 74 | #else /* not HAVE_UNSIGNED_CHAR */ 75 | 76 | typedef char JSAMPLE; 77 | #ifdef __CHAR_UNSIGNED__ 78 | #define GETJSAMPLE(value) ((int) (value)) 79 | #else 80 | #define GETJSAMPLE(value) ((int) (value) & 0xFF) 81 | #endif /* __CHAR_UNSIGNED__ */ 82 | 83 | #endif /* HAVE_UNSIGNED_CHAR */ 84 | 85 | #define MAXJSAMPLE 255 86 | #define CENTERJSAMPLE 128 87 | 88 | #endif /* BITS_IN_JSAMPLE == 8 */ 89 | 90 | 91 | #if BITS_IN_JSAMPLE == 12 92 | /* JSAMPLE should be the smallest type that will hold the values 0..4095. 93 | * On nearly all machines "short" will do nicely. 94 | */ 95 | 96 | typedef short JSAMPLE; 97 | #define GETJSAMPLE(value) ((int) (value)) 98 | 99 | #define MAXJSAMPLE 4095 100 | #define CENTERJSAMPLE 2048 101 | 102 | #endif /* BITS_IN_JSAMPLE == 12 */ 103 | 104 | 105 | /* Representation of a DCT frequency coefficient. 106 | * This should be a signed value of at least 16 bits; "short" is usually OK. 107 | * Again, we allocate large arrays of these, but you can change to int 108 | * if you have memory to burn and "short" is really slow. 109 | */ 110 | 111 | typedef short JCOEF; 112 | 113 | 114 | /* Compressed datastreams are represented as arrays of JOCTET. 115 | * These must be EXACTLY 8 bits wide, at least once they are written to 116 | * external storage. Note that when using the stdio data source/destination 117 | * managers, this is also the data type passed to fread/fwrite. 118 | */ 119 | 120 | #ifdef HAVE_UNSIGNED_CHAR 121 | 122 | typedef unsigned char JOCTET; 123 | #define GETJOCTET(value) (value) 124 | 125 | #else /* not HAVE_UNSIGNED_CHAR */ 126 | 127 | typedef char JOCTET; 128 | #ifdef __CHAR_UNSIGNED__ 129 | #define GETJOCTET(value) (value) 130 | #else 131 | #define GETJOCTET(value) ((value) & 0xFF) 132 | #endif /* __CHAR_UNSIGNED__ */ 133 | 134 | #endif /* HAVE_UNSIGNED_CHAR */ 135 | 136 | 137 | /* These typedefs are used for various table entries and so forth. 138 | * They must be at least as wide as specified; but making them too big 139 | * won't cost a huge amount of memory, so we don't provide special 140 | * extraction code like we did for JSAMPLE. (In other words, these 141 | * typedefs live at a different point on the speed/space tradeoff curve.) 142 | */ 143 | 144 | /* UINT8 must hold at least the values 0..255. */ 145 | 146 | #ifdef HAVE_UNSIGNED_CHAR 147 | typedef unsigned char UINT8; 148 | #else /* not HAVE_UNSIGNED_CHAR */ 149 | #ifdef __CHAR_UNSIGNED__ 150 | typedef char UINT8; 151 | #else /* not __CHAR_UNSIGNED__ */ 152 | typedef short UINT8; 153 | #endif /* __CHAR_UNSIGNED__ */ 154 | #endif /* HAVE_UNSIGNED_CHAR */ 155 | 156 | /* UINT16 must hold at least the values 0..65535. */ 157 | 158 | #ifdef HAVE_UNSIGNED_SHORT 159 | typedef unsigned short UINT16; 160 | #else /* not HAVE_UNSIGNED_SHORT */ 161 | typedef unsigned int UINT16; 162 | #endif /* HAVE_UNSIGNED_SHORT */ 163 | 164 | /* INT16 must hold at least the values -32768..32767. */ 165 | 166 | #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ 167 | typedef short INT16; 168 | #endif 169 | 170 | /* INT32 must hold at least signed 32-bit values. */ 171 | 172 | #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ 173 | typedef long INT32; 174 | #endif 175 | 176 | /* Datatype used for image dimensions. The JPEG standard only supports 177 | * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore 178 | * "unsigned int" is sufficient on all machines. However, if you need to 179 | * handle larger images and you don't mind deviating from the spec, you 180 | * can change this datatype. 181 | */ 182 | 183 | typedef unsigned int JDIMENSION; 184 | 185 | #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */ 186 | 187 | 188 | /* These macros are used in all function definitions and extern declarations. 189 | * You could modify them if you need to change function linkage conventions; 190 | * in particular, you'll need to do that to make the library a Windows DLL. 191 | * Another application is to make all functions global for use with debuggers 192 | * or code profilers that require it. 193 | */ 194 | 195 | /* a function called through method pointers: */ 196 | #define METHODDEF(type) static type 197 | /* a function used only in its module: */ 198 | #define LOCAL(type) static type 199 | /* a function referenced thru EXTERNs: */ 200 | #define GLOBAL(type) type 201 | /* a reference to a GLOBAL function: */ 202 | #define EXTERN(type) extern type 203 | 204 | 205 | /* This macro is used to declare a "method", that is, a function pointer. 206 | * We want to supply prototype parameters if the compiler can cope. 207 | * Note that the arglist parameter must be parenthesized! 208 | * Again, you can customize this if you need special linkage keywords. 209 | */ 210 | 211 | #ifdef HAVE_PROTOTYPES 212 | #define JMETHOD(type,methodname,arglist) type (*methodname) arglist 213 | #else 214 | #define JMETHOD(type,methodname,arglist) type (*methodname) () 215 | #endif 216 | 217 | 218 | /* Here is the pseudo-keyword for declaring pointers that must be "far" 219 | * on 80x86 machines. Most of the specialized coding for 80x86 is handled 220 | * by just saying "FAR *" where such a pointer is needed. In a few places 221 | * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol. 222 | */ 223 | 224 | #ifdef NEED_FAR_POINTERS 225 | #define FAR far 226 | #else 227 | #define FAR 228 | #endif 229 | 230 | 231 | /* 232 | * On a few systems, type boolean and/or its values FALSE, TRUE may appear 233 | * in standard header files. Or you may have conflicts with application- 234 | * specific header files that you want to include together with these files. 235 | * Defining HAVE_BOOLEAN before including jpeglib.h should make it work. 236 | */ 237 | 238 | #ifndef HAVE_BOOLEAN 239 | typedef int boolean; 240 | #endif 241 | #ifndef FALSE /* in case these macros already exist */ 242 | #define FALSE 0 /* values of boolean */ 243 | #endif 244 | #ifndef TRUE 245 | #define TRUE 1 246 | #endif 247 | 248 | 249 | /* 250 | * The remaining options affect code selection within the JPEG library, 251 | * but they don't need to be visible to most applications using the library. 252 | * To minimize application namespace pollution, the symbols won't be 253 | * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined. 254 | */ 255 | 256 | #ifdef JPEG_INTERNALS 257 | #define JPEG_INTERNAL_OPTIONS 258 | #endif 259 | 260 | #ifdef JPEG_INTERNAL_OPTIONS 261 | 262 | 263 | /* 264 | * These defines indicate whether to include various optional functions. 265 | * Undefining some of these symbols will produce a smaller but less capable 266 | * library. Note that you can leave certain source files out of the 267 | * compilation/linking process if you've #undef'd the corresponding symbols. 268 | * (You may HAVE to do that if your compiler doesn't like null source files.) 269 | */ 270 | 271 | /* Capability options common to encoder and decoder: */ 272 | 273 | #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ 274 | #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ 275 | #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ 276 | 277 | /* Encoder capability options: */ 278 | 279 | #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ 280 | #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ 281 | #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ 282 | /* Note: if you selected 12-bit data precision, it is dangerous to turn off 283 | * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit 284 | * precision, so jchuff.c normally uses entropy optimization to compute 285 | * usable tables for higher precision. If you don't want to do optimization, 286 | * you'll have to supply different default Huffman tables. 287 | * The exact same statements apply for progressive JPEG: the default tables 288 | * don't work for progressive mode. (This may get fixed, however.) 289 | */ 290 | #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */ 291 | 292 | /* Decoder capability options: */ 293 | 294 | #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ 295 | #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ 296 | #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ 297 | #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ 298 | #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ 299 | #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ 300 | #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ 301 | #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ 302 | #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ 303 | 304 | /* more capability options later, no doubt */ 305 | 306 | 307 | /* 308 | * Ordering of RGB data in scanlines passed to or from the application. 309 | * If your application wants to deal with data in the order B,G,R, just 310 | * change these macros. You can also deal with formats such as R,G,B,X 311 | * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing 312 | * the offsets will also change the order in which colormap data is organized. 313 | * RESTRICTIONS: 314 | * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. 315 | * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not 316 | * useful if you are using JPEG color spaces other than YCbCr or grayscale. 317 | * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE 318 | * is not 3 (they don't understand about dummy color components!). So you 319 | * can't use color quantization if you change that value. 320 | */ 321 | 322 | #define RGB_RED 0 /* Offset of Red in an RGB scanline element */ 323 | #define RGB_GREEN 1 /* Offset of Green */ 324 | #define RGB_BLUE 2 /* Offset of Blue */ 325 | #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ 326 | 327 | #ifdef ANDROID_RGB 328 | #define RGB_ALPHA 3 /* Offset of Alpha */ 329 | #endif 330 | 331 | #define JPEG_NUMCS 16 332 | 333 | #define EXT_RGB_RED 0 334 | #define EXT_RGB_GREEN 1 335 | #define EXT_RGB_BLUE 2 336 | #define EXT_RGB_PIXELSIZE 3 337 | 338 | #define EXT_RGBX_RED 0 339 | #define EXT_RGBX_GREEN 1 340 | #define EXT_RGBX_BLUE 2 341 | #define EXT_RGBX_PIXELSIZE 4 342 | 343 | #define EXT_BGR_RED 2 344 | #define EXT_BGR_GREEN 1 345 | #define EXT_BGR_BLUE 0 346 | #define EXT_BGR_PIXELSIZE 3 347 | 348 | #define EXT_BGRX_RED 2 349 | #define EXT_BGRX_GREEN 1 350 | #define EXT_BGRX_BLUE 0 351 | #define EXT_BGRX_PIXELSIZE 4 352 | 353 | #define EXT_XBGR_RED 3 354 | #define EXT_XBGR_GREEN 2 355 | #define EXT_XBGR_BLUE 1 356 | #define EXT_XBGR_PIXELSIZE 4 357 | 358 | #define EXT_XRGB_RED 1 359 | #define EXT_XRGB_GREEN 2 360 | #define EXT_XRGB_BLUE 3 361 | #define EXT_XRGB_PIXELSIZE 4 362 | 363 | #ifdef ANDROID_RGB 364 | #define RGB_ALPHA 3 /* Offset of Alpha */ 365 | #endif 366 | 367 | static const int rgb_red[JPEG_NUMCS] = { 368 | -1, -1, RGB_RED, -1, -1, -1, EXT_RGB_RED, EXT_RGBX_RED, 369 | EXT_BGR_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED, 370 | EXT_RGBX_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED 371 | }; 372 | 373 | static const int rgb_green[JPEG_NUMCS] = { 374 | -1, -1, RGB_GREEN, -1, -1, -1, EXT_RGB_GREEN, EXT_RGBX_GREEN, 375 | EXT_BGR_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN, 376 | EXT_RGBX_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN 377 | }; 378 | 379 | static const int rgb_blue[JPEG_NUMCS] = { 380 | -1, -1, RGB_BLUE, -1, -1, -1, EXT_RGB_BLUE, EXT_RGBX_BLUE, 381 | EXT_BGR_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE, 382 | EXT_RGBX_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE 383 | }; 384 | 385 | static const int rgb_pixelsize[JPEG_NUMCS] = { 386 | -1, -1, RGB_PIXELSIZE, -1, -1, -1, EXT_RGB_PIXELSIZE, EXT_RGBX_PIXELSIZE, 387 | EXT_BGR_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE, 388 | EXT_RGBX_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE 389 | }; 390 | 391 | 392 | /* 393 | * Define ANDROID_RGB to enable specific optimizations for Android 394 | * JCS_RGBA_8888 support 395 | * JCS_RGB_565 support 396 | * 397 | */ 398 | 399 | #ifdef ANDROID_RGB 400 | #define PACK_SHORT_565(r,g,b) ((((r)<<8)&0xf800)|(((g)<<3)&0x7E0)|((b)>>3)) 401 | #define PACK_TWO_PIXELS(l,r) ((r<<16) | l) 402 | #define PACK_NEED_ALIGNMENT(ptr) (((int)(ptr))&3) 403 | #define WRITE_TWO_PIXELS(addr, pixels) do { \ 404 | ((INT16*)(addr))[0] = (pixels); \ 405 | ((INT16*)(addr))[1] = (pixels)>>16; \ 406 | } while(0) 407 | #define WRITE_TWO_ALIGNED_PIXELS(addr, pixels) ((*(INT32*)(addr)) = pixels) 408 | #define DITHER_565_R(r, dither) ((r) + ((dither)&0xFF)) 409 | #define DITHER_565_G(g, dither) ((g) + (((dither)&0xFF)>>1)) 410 | #define DITHER_565_B(b, dither) ((b) + ((dither)&0xFF)) 411 | #endif 412 | 413 | 414 | /* Definitions for speed-related optimizations. */ 415 | 416 | /* On some machines (notably 68000 series) "int" is 32 bits, but multiplying 417 | * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER 418 | * as short on such a machine. MULTIPLIER must be at least 16 bits wide. 419 | */ 420 | 421 | #ifndef MULTIPLIER 422 | #ifndef WITH_SIMD 423 | #define MULTIPLIER int /* type for fastest integer multiply */ 424 | #else 425 | #define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */ 426 | #endif 427 | #endif 428 | 429 | 430 | /* FAST_FLOAT should be either float or double, whichever is done faster 431 | * by your compiler. (Note that this type is only used in the floating point 432 | * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) 433 | * Typically, float is faster in ANSI C compilers, while double is faster in 434 | * pre-ANSI compilers (because they insist on converting to double anyway). 435 | * The code below therefore chooses float if we have ANSI-style prototypes. 436 | */ 437 | 438 | #ifndef FAST_FLOAT 439 | #ifdef HAVE_PROTOTYPES 440 | #define FAST_FLOAT float 441 | #else 442 | #define FAST_FLOAT double 443 | #endif 444 | #endif 445 | 446 | #endif /* JPEG_INTERNAL_OPTIONS */ 447 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/jpeglib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jpeglib.h 3 | * 4 | * Copyright (C) 1991-1998, Thomas G. Lane. 5 | * Modified 2002-2009 by Guido Vollbeding. 6 | * Copyright (C) 2009-2011, D. R. Commander. 7 | * This file is part of the Independent JPEG Group's software. 8 | * For conditions of distribution and use, see the accompanying README file. 9 | * 10 | * This file defines the application interface for the JPEG library. 11 | * Most applications using the library need only include this file, 12 | * and perhaps jerror.h if they want to know the exact error codes. 13 | */ 14 | 15 | #ifndef JPEGLIB_H 16 | #define JPEGLIB_H 17 | 18 | /* 19 | * First we include the configuration files that record how this 20 | * installation of the JPEG library is set up. jconfig.h can be 21 | * generated automatically for many systems. jmorecfg.h contains 22 | * manual configuration options that most people need not worry about. 23 | */ 24 | 25 | #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ 26 | #include "android/jconfig.h" /* widely used configuration options */ 27 | #endif 28 | #include "jmorecfg.h" /* seldom changed options */ 29 | #include 30 | #include 31 | #include 32 | #ifndef ANDROID 33 | #ifdef __cplusplus 34 | #ifndef DONT_USE_EXTERN_C 35 | extern "C" { 36 | #endif 37 | #endif 38 | #endif 39 | 40 | 41 | /* Various constants determining the sizes of things. 42 | * All of these are specified by the JPEG standard, so don't change them 43 | * if you want to be compatible. 44 | */ 45 | 46 | #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ 47 | #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ 48 | #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */ 49 | #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */ 50 | #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */ 51 | #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */ 52 | #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */ 53 | /* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard; 54 | * the PostScript DCT filter can emit files with many more than 10 blocks/MCU. 55 | * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU 56 | * to handle it. We even let you do this from the jconfig.h file. However, 57 | * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe 58 | * sometimes emits noncompliant files doesn't mean you should too. 59 | */ 60 | #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */ 61 | #ifndef D_MAX_BLOCKS_IN_MCU 62 | #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */ 63 | #endif 64 | 65 | 66 | /* Data structures for images (arrays of samples and of DCT coefficients). 67 | * On 80x86 machines, the image arrays are too big for near pointers, 68 | * but the pointer arrays can fit in near memory. 69 | */ 70 | 71 | typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */ 72 | typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ 73 | typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ 74 | 75 | typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ 76 | typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */ 77 | typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */ 78 | typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */ 79 | 80 | typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */ 81 | 82 | 83 | /* Types for JPEG compression parameters and working tables. */ 84 | 85 | 86 | /* DCT coefficient quantization tables. */ 87 | 88 | typedef struct { 89 | /* This array gives the coefficient quantizers in natural array order 90 | * (not the zigzag order in which they are stored in a JPEG DQT marker). 91 | * CAUTION: IJG versions prior to v6a kept this array in zigzag order. 92 | */ 93 | UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */ 94 | /* This field is used only during compression. It's initialized FALSE when 95 | * the table is created, and set TRUE when it's been output to the file. 96 | * You could suppress output of a table by setting this to TRUE. 97 | * (See jpeg_suppress_tables for an example.) 98 | */ 99 | boolean sent_table; /* TRUE when table has been output */ 100 | } JQUANT_TBL; 101 | 102 | 103 | /* Huffman coding tables. */ 104 | 105 | typedef struct { 106 | /* These two fields directly represent the contents of a JPEG DHT marker */ 107 | UINT8 bits[17]; /* bits[k] = # of symbols with codes of */ 108 | /* length k bits; bits[0] is unused */ 109 | UINT8 huffval[256]; /* The symbols, in order of incr code length */ 110 | /* This field is used only during compression. It's initialized FALSE when 111 | * the table is created, and set TRUE when it's been output to the file. 112 | * You could suppress output of a table by setting this to TRUE. 113 | * (See jpeg_suppress_tables for an example.) 114 | */ 115 | boolean sent_table; /* TRUE when table has been output */ 116 | } JHUFF_TBL; 117 | 118 | 119 | /* Basic info about one component (color channel). */ 120 | 121 | typedef struct { 122 | /* These values are fixed over the whole image. */ 123 | /* For compression, they must be supplied by parameter setup; */ 124 | /* for decompression, they are read from the SOF marker. */ 125 | int component_id; /* identifier for this component (0..255) */ 126 | int component_index; /* its index in SOF or cinfo->comp_info[] */ 127 | int h_samp_factor; /* horizontal sampling factor (1..4) */ 128 | int v_samp_factor; /* vertical sampling factor (1..4) */ 129 | int quant_tbl_no; /* quantization table selector (0..3) */ 130 | /* These values may vary between scans. */ 131 | /* For compression, they must be supplied by parameter setup; */ 132 | /* for decompression, they are read from the SOS marker. */ 133 | /* The decompressor output side may not use these variables. */ 134 | int dc_tbl_no; /* DC entropy table selector (0..3) */ 135 | int ac_tbl_no; /* AC entropy table selector (0..3) */ 136 | 137 | /* Remaining fields should be treated as private by applications. */ 138 | 139 | /* These values are computed during compression or decompression startup: */ 140 | /* Component's size in DCT blocks. 141 | * Any dummy blocks added to complete an MCU are not counted; therefore 142 | * these values do not depend on whether a scan is interleaved or not. 143 | */ 144 | JDIMENSION width_in_blocks; 145 | JDIMENSION height_in_blocks; 146 | /* Size of a DCT block in samples. Always DCTSIZE for compression. 147 | * For decompression this is the size of the output from one DCT block, 148 | * reflecting any scaling we choose to apply during the IDCT step. 149 | * Values of 1,2,4,8 are likely to be supported. Note that different 150 | * components may receive different IDCT scalings. 151 | */ 152 | #if JPEG_LIB_VERSION >= 70 153 | int DCT_h_scaled_size; 154 | int DCT_v_scaled_size; 155 | #else 156 | int DCT_scaled_size; 157 | #endif 158 | /* The downsampled dimensions are the component's actual, unpadded number 159 | * of samples at the main buffer (preprocessing/compression interface), thus 160 | * downsampled_width = ceil(image_width * Hi/Hmax) 161 | * and similarly for height. For decompression, IDCT scaling is included, so 162 | * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE) 163 | */ 164 | JDIMENSION downsampled_width; /* actual width in samples */ 165 | JDIMENSION downsampled_height; /* actual height in samples */ 166 | /* This flag is used only for decompression. In cases where some of the 167 | * components will be ignored (eg grayscale output from YCbCr image), 168 | * we can skip most computations for the unused components. 169 | */ 170 | boolean component_needed; /* do we need the value of this component? */ 171 | 172 | /* These values are computed before starting a scan of the component. */ 173 | /* The decompressor output side may not use these variables. */ 174 | int MCU_width; /* number of blocks per MCU, horizontally */ 175 | int MCU_height; /* number of blocks per MCU, vertically */ 176 | int MCU_blocks; /* MCU_width * MCU_height */ 177 | int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */ 178 | int last_col_width; /* # of non-dummy blocks across in last MCU */ 179 | int last_row_height; /* # of non-dummy blocks down in last MCU */ 180 | 181 | /* Saved quantization table for component; NULL if none yet saved. 182 | * See jdinput.c comments about the need for this information. 183 | * This field is currently used only for decompression. 184 | */ 185 | JQUANT_TBL * quant_table; 186 | 187 | /* Private per-component storage for DCT or IDCT subsystem. */ 188 | void * dct_table; 189 | } jpeg_component_info; 190 | 191 | 192 | /* The script for encoding a multiple-scan file is an array of these: */ 193 | 194 | typedef struct { 195 | int comps_in_scan; /* number of components encoded in this scan */ 196 | int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */ 197 | int Ss, Se; /* progressive JPEG spectral selection parms */ 198 | int Ah, Al; /* progressive JPEG successive approx. parms */ 199 | } jpeg_scan_info; 200 | 201 | /* The decompressor can save APPn and COM markers in a list of these: */ 202 | 203 | typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr; 204 | 205 | struct jpeg_marker_struct { 206 | jpeg_saved_marker_ptr next; /* next in list, or NULL */ 207 | UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */ 208 | unsigned int original_length; /* # bytes of data in the file */ 209 | unsigned int data_length; /* # bytes of data saved at data[] */ 210 | JOCTET FAR * data; /* the data contained in the marker */ 211 | /* the marker length word is not counted in data_length or original_length */ 212 | }; 213 | 214 | /* Known color spaces. */ 215 | 216 | #define JCS_EXTENSIONS 1 217 | #define JCS_ALPHA_EXTENSIONS 1 218 | 219 | typedef enum { 220 | JCS_UNKNOWN, /* error/unspecified */ 221 | JCS_GRAYSCALE, /* monochrome */ 222 | JCS_RGB, /* red/green/blue as specified by the RGB_RED, RGB_GREEN, 223 | RGB_BLUE, and RGB_PIXELSIZE macros */ 224 | JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ 225 | JCS_CMYK, /* C/M/Y/K */ 226 | JCS_YCCK, /* Y/Cb/Cr/K */ 227 | JCS_EXT_RGB, /* red/green/blue */ 228 | JCS_EXT_RGBX, /* red/green/blue/x */ 229 | JCS_EXT_BGR, /* blue/green/red */ 230 | JCS_EXT_BGRX, /* blue/green/red/x */ 231 | JCS_EXT_XBGR, /* x/blue/green/red */ 232 | JCS_EXT_XRGB, /* x/red/green/blue */ 233 | /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, 234 | JCS_EXT_XBGR, or JCS_EXT_XRGB during decompression, the X byte is 235 | undefined, and in order to ensure the best performance, 236 | libjpeg-turbo can set that byte to whatever value it wishes. Use 237 | the following colorspace constants to ensure that the X byte is set 238 | to 0xFF, so that it can be interpreted as an opaque alpha 239 | channel. */ 240 | JCS_EXT_RGBA, /* red/green/blue/alpha */ 241 | JCS_EXT_BGRA, /* blue/green/red/alpha */ 242 | JCS_EXT_ABGR, /* alpha/blue/green/red */ 243 | JCS_EXT_ARGB, /* alpha/red/green/blue */ 244 | #ifdef ANDROID_RGB 245 | JCS_RGBA_8888, /* red/green/blue/alpha */ 246 | JCS_RGB_565 /* red/green/blue in 565 format */ 247 | #endif 248 | } J_COLOR_SPACE; 249 | 250 | /* DCT/IDCT algorithm options. */ 251 | 252 | typedef enum { 253 | JDCT_ISLOW, /* slow but accurate integer algorithm */ 254 | JDCT_IFAST, /* faster, less accurate integer method */ 255 | JDCT_FLOAT /* floating-point: accurate, fast on fast HW */ 256 | } J_DCT_METHOD; 257 | 258 | #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */ 259 | #define JDCT_DEFAULT JDCT_ISLOW 260 | #endif 261 | #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */ 262 | #define JDCT_FASTEST JDCT_IFAST 263 | #endif 264 | 265 | /* Dithering options for decompression. */ 266 | 267 | typedef enum { 268 | JDITHER_NONE, /* no dithering */ 269 | JDITHER_ORDERED, /* simple ordered dither */ 270 | JDITHER_FS /* Floyd-Steinberg error diffusion dither */ 271 | } J_DITHER_MODE; 272 | 273 | 274 | /* Common fields between JPEG compression and decompression master structs. */ 275 | 276 | #define jpeg_common_fields \ 277 | struct jpeg_error_mgr * err; /* Error handler module */\ 278 | struct jpeg_memory_mgr * mem; /* Memory manager module */\ 279 | struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\ 280 | void * client_data; /* Available for use by application */\ 281 | boolean is_decompressor; /* So common code can tell which is which */\ 282 | int global_state /* For checking call sequence validity */ 283 | 284 | /* Routines that are to be used by both halves of the library are declared 285 | * to receive a pointer to this structure. There are no actual instances of 286 | * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct. 287 | */ 288 | struct jpeg_common_struct { 289 | jpeg_common_fields; /* Fields common to both master struct types */ 290 | /* Additional fields follow in an actual jpeg_compress_struct or 291 | * jpeg_decompress_struct. All three structs must agree on these 292 | * initial fields! (This would be a lot cleaner in C++.) 293 | */ 294 | }; 295 | 296 | typedef struct jpeg_common_struct * j_common_ptr; 297 | typedef struct jpeg_compress_struct * j_compress_ptr; 298 | typedef struct jpeg_decompress_struct * j_decompress_ptr; 299 | 300 | 301 | /* Master record for a compression instance */ 302 | 303 | struct jpeg_compress_struct { 304 | jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */ 305 | 306 | /* Destination for compressed data */ 307 | struct jpeg_destination_mgr * dest; 308 | 309 | /* Description of source image --- these fields must be filled in by 310 | * outer application before starting compression. in_color_space must 311 | * be correct before you can even call jpeg_set_defaults(). 312 | */ 313 | 314 | JDIMENSION image_width; /* input image width */ 315 | JDIMENSION image_height; /* input image height */ 316 | int input_components; /* # of color components in input image */ 317 | J_COLOR_SPACE in_color_space; /* colorspace of input image */ 318 | 319 | double input_gamma; /* image gamma of input image */ 320 | 321 | /* Compression parameters --- these fields must be set before calling 322 | * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to 323 | * initialize everything to reasonable defaults, then changing anything 324 | * the application specifically wants to change. That way you won't get 325 | * burnt when new parameters are added. Also note that there are several 326 | * helper routines to simplify changing parameters. 327 | */ 328 | 329 | #if JPEG_LIB_VERSION >= 70 330 | unsigned int scale_num, scale_denom; /* fraction by which to scale image */ 331 | 332 | JDIMENSION jpeg_width; /* scaled JPEG image width */ 333 | JDIMENSION jpeg_height; /* scaled JPEG image height */ 334 | /* Dimensions of actual JPEG image that will be written to file, 335 | * derived from input dimensions by scaling factors above. 336 | * These fields are computed by jpeg_start_compress(). 337 | * You can also use jpeg_calc_jpeg_dimensions() to determine these values 338 | * in advance of calling jpeg_start_compress(). 339 | */ 340 | #endif 341 | 342 | int data_precision; /* bits of precision in image data */ 343 | 344 | int num_components; /* # of color components in JPEG image */ 345 | J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ 346 | 347 | jpeg_component_info * comp_info; 348 | /* comp_info[i] describes component that appears i'th in SOF */ 349 | 350 | JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; 351 | #if JPEG_LIB_VERSION >= 70 352 | int q_scale_factor[NUM_QUANT_TBLS]; 353 | #endif 354 | /* ptrs to coefficient quantization tables, or NULL if not defined, 355 | * and corresponding scale factors (percentage, initialized 100). 356 | */ 357 | 358 | JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; 359 | JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; 360 | /* ptrs to Huffman coding tables, or NULL if not defined */ 361 | 362 | UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ 363 | UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ 364 | UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ 365 | 366 | int num_scans; /* # of entries in scan_info array */ 367 | const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */ 368 | /* The default value of scan_info is NULL, which causes a single-scan 369 | * sequential JPEG file to be emitted. To create a multi-scan file, 370 | * set num_scans and scan_info to point to an array of scan definitions. 371 | */ 372 | 373 | boolean raw_data_in; /* TRUE=caller supplies downsampled data */ 374 | boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ 375 | boolean optimize_coding; /* TRUE=optimize entropy encoding parms */ 376 | boolean CCIR601_sampling; /* TRUE=first samples are cosited */ 377 | #if JPEG_LIB_VERSION >= 70 378 | boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */ 379 | #endif 380 | int smoothing_factor; /* 1..100, or 0 for no input smoothing */ 381 | J_DCT_METHOD dct_method; /* DCT algorithm selector */ 382 | 383 | /* The restart interval can be specified in absolute MCUs by setting 384 | * restart_interval, or in MCU rows by setting restart_in_rows 385 | * (in which case the correct restart_interval will be figured 386 | * for each scan). 387 | */ 388 | unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */ 389 | int restart_in_rows; /* if > 0, MCU rows per restart interval */ 390 | 391 | /* Parameters controlling emission of special markers. */ 392 | 393 | boolean write_JFIF_header; /* should a JFIF marker be written? */ 394 | UINT8 JFIF_major_version; /* What to write for the JFIF version number */ 395 | UINT8 JFIF_minor_version; 396 | /* These three values are not used by the JPEG code, merely copied */ 397 | /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */ 398 | /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */ 399 | /* ratio is defined by X_density/Y_density even when density_unit=0. */ 400 | UINT8 density_unit; /* JFIF code for pixel size units */ 401 | UINT16 X_density; /* Horizontal pixel density */ 402 | UINT16 Y_density; /* Vertical pixel density */ 403 | boolean write_Adobe_marker; /* should an Adobe marker be written? */ 404 | 405 | /* State variable: index of next scanline to be written to 406 | * jpeg_write_scanlines(). Application may use this to control its 407 | * processing loop, e.g., "while (next_scanline < image_height)". 408 | */ 409 | 410 | JDIMENSION next_scanline; /* 0 .. image_height-1 */ 411 | 412 | /* Remaining fields are known throughout compressor, but generally 413 | * should not be touched by a surrounding application. 414 | */ 415 | 416 | /* 417 | * These fields are computed during compression startup 418 | */ 419 | boolean progressive_mode; /* TRUE if scan script uses progressive mode */ 420 | int max_h_samp_factor; /* largest h_samp_factor */ 421 | int max_v_samp_factor; /* largest v_samp_factor */ 422 | 423 | #if JPEG_LIB_VERSION >= 70 424 | int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ 425 | int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ 426 | #endif 427 | 428 | JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ 429 | /* The coefficient controller receives data in units of MCU rows as defined 430 | * for fully interleaved scans (whether the JPEG file is interleaved or not). 431 | * There are v_samp_factor * DCTSIZE sample rows of each component in an 432 | * "iMCU" (interleaved MCU) row. 433 | */ 434 | 435 | /* 436 | * These fields are valid during any one scan. 437 | * They describe the components and MCUs actually appearing in the scan. 438 | */ 439 | int comps_in_scan; /* # of JPEG components in this scan */ 440 | jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; 441 | /* *cur_comp_info[i] describes component that appears i'th in SOS */ 442 | 443 | JDIMENSION MCUs_per_row; /* # of MCUs across the image */ 444 | JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ 445 | 446 | int blocks_in_MCU; /* # of DCT blocks per MCU */ 447 | int MCU_membership[C_MAX_BLOCKS_IN_MCU]; 448 | /* MCU_membership[i] is index in cur_comp_info of component owning */ 449 | /* i'th block in an MCU */ 450 | 451 | int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ 452 | 453 | #if JPEG_LIB_VERSION >= 80 454 | int block_size; /* the basic DCT block size: 1..16 */ 455 | const int * natural_order; /* natural-order position array */ 456 | int lim_Se; /* min( Se, DCTSIZE2-1 ) */ 457 | #endif 458 | 459 | /* 460 | * Links to compression subobjects (methods and private variables of modules) 461 | */ 462 | struct jpeg_comp_master * master; 463 | struct jpeg_c_main_controller * main; 464 | struct jpeg_c_prep_controller * prep; 465 | struct jpeg_c_coef_controller * coef; 466 | struct jpeg_marker_writer * marker; 467 | struct jpeg_color_converter * cconvert; 468 | struct jpeg_downsampler * downsample; 469 | struct jpeg_forward_dct * fdct; 470 | struct jpeg_entropy_encoder * entropy; 471 | jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */ 472 | int script_space_size; 473 | }; 474 | 475 | 476 | /* Master record for a decompression instance */ 477 | 478 | struct jpeg_decompress_struct { 479 | jpeg_common_fields; /* Fields shared with jpeg_compress_struct */ 480 | 481 | /* Source of compressed data */ 482 | struct jpeg_source_mgr * src; 483 | 484 | /* Basic description of image --- filled in by jpeg_read_header(). */ 485 | /* Application may inspect these values to decide how to process image. */ 486 | 487 | JDIMENSION original_image_width; /* nominal image width (from SOF marker) */ 488 | JDIMENSION image_width; /* nominal image width (from SOF marker) */ 489 | JDIMENSION image_height; /* nominal image height */ 490 | int num_components; /* # of color components in JPEG image */ 491 | J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ 492 | 493 | /* Decompression processing parameters --- these fields must be set before 494 | * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes 495 | * them to default values. 496 | */ 497 | 498 | J_COLOR_SPACE out_color_space; /* colorspace for output */ 499 | 500 | unsigned int scale_num, scale_denom; /* fraction by which to scale image */ 501 | 502 | double output_gamma; /* image gamma wanted in output */ 503 | 504 | boolean buffered_image; /* TRUE=multiple output passes */ 505 | boolean raw_data_out; /* TRUE=downsampled data wanted */ 506 | 507 | J_DCT_METHOD dct_method; /* IDCT algorithm selector */ 508 | boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */ 509 | boolean do_block_smoothing; /* TRUE=apply interblock smoothing */ 510 | 511 | boolean quantize_colors; /* TRUE=colormapped output wanted */ 512 | /* the following are ignored if not quantize_colors: */ 513 | J_DITHER_MODE dither_mode; /* type of color dithering to use */ 514 | boolean two_pass_quantize; /* TRUE=use two-pass color quantization */ 515 | int desired_number_of_colors; /* max # colors to use in created colormap */ 516 | /* these are significant only in buffered-image mode: */ 517 | boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */ 518 | boolean enable_external_quant;/* enable future use of external colormap */ 519 | boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */ 520 | 521 | /* Description of actual output image that will be returned to application. 522 | * These fields are computed by jpeg_start_decompress(). 523 | * You can also use jpeg_calc_output_dimensions() to determine these values 524 | * in advance of calling jpeg_start_decompress(). 525 | */ 526 | 527 | JDIMENSION output_width; /* scaled image width */ 528 | JDIMENSION output_height; /* scaled image height */ 529 | int out_color_components; /* # of color components in out_color_space */ 530 | int output_components; /* # of color components returned */ 531 | /* output_components is 1 (a colormap index) when quantizing colors; 532 | * otherwise it equals out_color_components. 533 | */ 534 | int rec_outbuf_height; /* min recommended height of scanline buffer */ 535 | /* If the buffer passed to jpeg_read_scanlines() is less than this many rows 536 | * high, space and time will be wasted due to unnecessary data copying. 537 | * Usually rec_outbuf_height will be 1 or 2, at most 4. 538 | */ 539 | 540 | /* When quantizing colors, the output colormap is described by these fields. 541 | * The application can supply a colormap by setting colormap non-NULL before 542 | * calling jpeg_start_decompress; otherwise a colormap is created during 543 | * jpeg_start_decompress or jpeg_start_output. 544 | * The map has out_color_components rows and actual_number_of_colors columns. 545 | */ 546 | int actual_number_of_colors; /* number of entries in use */ 547 | JSAMPARRAY colormap; /* The color map as a 2-D pixel array */ 548 | 549 | /* State variables: these variables indicate the progress of decompression. 550 | * The application may examine these but must not modify them. 551 | */ 552 | 553 | /* Row index of next scanline to be read from jpeg_read_scanlines(). 554 | * Application may use this to control its processing loop, e.g., 555 | * "while (output_scanline < output_height)". 556 | */ 557 | JDIMENSION output_scanline; /* 0 .. output_height-1 */ 558 | 559 | /* Current input scan number and number of iMCU rows completed in scan. 560 | * These indicate the progress of the decompressor input side. 561 | */ 562 | int input_scan_number; /* Number of SOS markers seen so far */ 563 | JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */ 564 | 565 | /* The "output scan number" is the notional scan being displayed by the 566 | * output side. The decompressor will not allow output scan/row number 567 | * to get ahead of input scan/row, but it can fall arbitrarily far behind. 568 | */ 569 | int output_scan_number; /* Nominal scan number being displayed */ 570 | JDIMENSION output_iMCU_row; /* Number of iMCU rows read */ 571 | 572 | /* Current progression status. coef_bits[c][i] indicates the precision 573 | * with which component c's DCT coefficient i (in zigzag order) is known. 574 | * It is -1 when no data has yet been received, otherwise it is the point 575 | * transform (shift) value for the most recent scan of the coefficient 576 | * (thus, 0 at completion of the progression). 577 | * This pointer is NULL when reading a non-progressive file. 578 | */ 579 | int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */ 580 | 581 | /* Internal JPEG parameters --- the application usually need not look at 582 | * these fields. Note that the decompressor output side may not use 583 | * any parameters that can change between scans. 584 | */ 585 | 586 | /* Quantization and Huffman tables are carried forward across input 587 | * datastreams when processing abbreviated JPEG datastreams. 588 | */ 589 | 590 | JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; 591 | /* ptrs to coefficient quantization tables, or NULL if not defined */ 592 | 593 | JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; 594 | JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; 595 | /* ptrs to Huffman coding tables, or NULL if not defined */ 596 | 597 | /* These parameters are never carried across datastreams, since they 598 | * are given in SOF/SOS markers or defined to be reset by SOI. 599 | */ 600 | 601 | int data_precision; /* bits of precision in image data */ 602 | 603 | jpeg_component_info * comp_info; 604 | /* comp_info[i] describes component that appears i'th in SOF */ 605 | 606 | #if JPEG_LIB_VERSION >= 80 607 | boolean is_baseline; /* TRUE if Baseline SOF0 encountered */ 608 | #endif 609 | #ifdef ANDROID 610 | boolean tile_decode; /* TRUE if using tile based decoding */ 611 | #endif 612 | boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */ 613 | boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ 614 | 615 | UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ 616 | UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ 617 | UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ 618 | 619 | unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */ 620 | 621 | /* These fields record data obtained from optional markers recognized by 622 | * the JPEG library. 623 | */ 624 | boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */ 625 | /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */ 626 | UINT8 JFIF_major_version; /* JFIF version number */ 627 | UINT8 JFIF_minor_version; 628 | UINT8 density_unit; /* JFIF code for pixel size units */ 629 | UINT16 X_density; /* Horizontal pixel density */ 630 | UINT16 Y_density; /* Vertical pixel density */ 631 | boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */ 632 | UINT8 Adobe_transform; /* Color transform code from Adobe marker */ 633 | 634 | boolean CCIR601_sampling; /* TRUE=first samples are cosited */ 635 | 636 | /* Aside from the specific data retained from APPn markers known to the 637 | * library, the uninterpreted contents of any or all APPn and COM markers 638 | * can be saved in a list for examination by the application. 639 | */ 640 | jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */ 641 | 642 | /* Remaining fields are known throughout decompressor, but generally 643 | * should not be touched by a surrounding application. 644 | */ 645 | 646 | /* 647 | * These fields are computed during decompression startup 648 | */ 649 | int max_h_samp_factor; /* largest h_samp_factor */ 650 | int max_v_samp_factor; /* largest v_samp_factor */ 651 | 652 | #if JPEG_LIB_VERSION >= 70 653 | int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ 654 | int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ 655 | #else 656 | int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */ 657 | #endif 658 | 659 | JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */ 660 | /* The coefficient controller's input and output progress is measured in 661 | * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows 662 | * in fully interleaved JPEG scans, but are used whether the scan is 663 | * interleaved or not. We define an iMCU row as v_samp_factor DCT block 664 | * rows of each component. Therefore, the IDCT output contains 665 | * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row. 666 | */ 667 | 668 | JSAMPLE * sample_range_limit; /* table for fast range-limiting */ 669 | 670 | /* 671 | * These fields are valid during any one scan. 672 | * They describe the components and MCUs actually appearing in the scan. 673 | * Note that the decompressor output side must not use these fields. 674 | */ 675 | int comps_in_scan; /* # of JPEG components in this scan */ 676 | jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; 677 | /* *cur_comp_info[i] describes component that appears i'th in SOS */ 678 | 679 | JDIMENSION MCUs_per_row; /* # of MCUs across the image */ 680 | JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ 681 | 682 | int blocks_in_MCU; /* # of DCT blocks per MCU */ 683 | int MCU_membership[D_MAX_BLOCKS_IN_MCU]; 684 | /* MCU_membership[i] is index in cur_comp_info of component owning */ 685 | /* i'th block in an MCU */ 686 | 687 | int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ 688 | 689 | #if JPEG_LIB_VERSION >= 80 690 | /* These fields are derived from Se of first SOS marker. 691 | */ 692 | int block_size; /* the basic DCT block size: 1..16 */ 693 | const int * natural_order; /* natural-order position array for entropy decode */ 694 | int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */ 695 | #endif 696 | 697 | /* This field is shared between entropy decoder and marker parser. 698 | * It is either zero or the code of a JPEG marker that has been 699 | * read from the data source, but has not yet been processed. 700 | */ 701 | int unread_marker; 702 | 703 | /* 704 | * Links to decompression subobjects (methods, private variables of modules) 705 | */ 706 | struct jpeg_decomp_master * master; 707 | struct jpeg_d_main_controller * main; 708 | struct jpeg_d_coef_controller * coef; 709 | struct jpeg_d_post_controller * post; 710 | struct jpeg_input_controller * inputctl; 711 | struct jpeg_marker_reader * marker; 712 | struct jpeg_entropy_decoder * entropy; 713 | struct jpeg_inverse_dct * idct; 714 | struct jpeg_upsampler * upsample; 715 | struct jpeg_color_deconverter * cconvert; 716 | struct jpeg_color_quantizer * cquantize; 717 | }; 718 | 719 | 720 | typedef struct { 721 | 722 | // |--- byte_offset ---|- bit_left -| 723 | // \------ 27 -------/ \---- 5 ----/ 724 | unsigned int bitstream_offset; 725 | short prev_dc[3]; 726 | 727 | // remaining EOBs in EOBRUN 728 | unsigned short EOBRUN; 729 | 730 | // save the decoder current bit buffer, entropy->bitstate.get_buffer. 731 | INT32 get_buffer; 732 | 733 | // save the restart info. 734 | unsigned short restarts_to_go; 735 | unsigned char next_restart_num; 736 | } huffman_offset_data; 737 | 738 | typedef struct { 739 | 740 | // The header starting position of this scan 741 | unsigned int bitstream_offset; 742 | 743 | // Number of components in this scan 744 | int comps_in_scan; 745 | 746 | // Number of MCUs in each row 747 | int MCUs_per_row; 748 | int MCU_rows_per_iMCU_row; 749 | 750 | // The last MCU position and its dc value in this scan 751 | huffman_offset_data prev_MCU_offset; 752 | 753 | huffman_offset_data **offset; 754 | } huffman_scan_header; 755 | 756 | #define DEFAULT_MCU_SAMPLE_SIZE 16 757 | 758 | typedef struct { 759 | 760 | // The number of MCUs that we sample each time as an index point 761 | int MCU_sample_size; 762 | 763 | // Number of scan in this image 764 | int scan_count; 765 | 766 | // Number of iMCUs rows in this image 767 | int total_iMCU_rows; 768 | 769 | // Memory used by scan struct 770 | size_t mem_used; 771 | huffman_scan_header *scan; 772 | } huffman_index; 773 | 774 | 775 | /* "Object" declarations for JPEG modules that may be supplied or called 776 | * directly by the surrounding application. 777 | * As with all objects in the JPEG library, these structs only define the 778 | * publicly visible methods and state variables of a module. Additional 779 | * private fields may exist after the public ones. 780 | */ 781 | 782 | 783 | /* Error handler object */ 784 | 785 | struct jpeg_error_mgr { 786 | /* Error exit handler: does not return to caller */ 787 | JMETHOD(void, error_exit, (j_common_ptr cinfo)); 788 | /* Conditionally emit a trace or warning message */ 789 | JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); 790 | /* Routine that actually outputs a trace or error message */ 791 | JMETHOD(void, output_message, (j_common_ptr cinfo)); 792 | /* Format a message string for the most recent JPEG error or message */ 793 | JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer)); 794 | #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */ 795 | /* Reset error state variables at start of a new image */ 796 | JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); 797 | 798 | /* The message ID code and any parameters are saved here. 799 | * A message can have one string parameter or up to 8 int parameters. 800 | */ 801 | int msg_code; 802 | #define JMSG_STR_PARM_MAX 80 803 | union { 804 | int i[8]; 805 | char s[JMSG_STR_PARM_MAX]; 806 | } msg_parm; 807 | 808 | /* Standard state variables for error facility */ 809 | 810 | int trace_level; /* max msg_level that will be displayed */ 811 | 812 | /* For recoverable corrupt-data errors, we emit a warning message, 813 | * but keep going unless emit_message chooses to abort. emit_message 814 | * should count warnings in num_warnings. The surrounding application 815 | * can check for bad data by seeing if num_warnings is nonzero at the 816 | * end of processing. 817 | */ 818 | long num_warnings; /* number of corrupt-data warnings */ 819 | 820 | /* These fields point to the table(s) of error message strings. 821 | * An application can change the table pointer to switch to a different 822 | * message list (typically, to change the language in which errors are 823 | * reported). Some applications may wish to add additional error codes 824 | * that will be handled by the JPEG library error mechanism; the second 825 | * table pointer is used for this purpose. 826 | * 827 | * First table includes all errors generated by JPEG library itself. 828 | * Error code 0 is reserved for a "no such error string" message. 829 | */ 830 | const char * const * jpeg_message_table; /* Library errors */ 831 | int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */ 832 | /* Second table can be added by application (see cjpeg/djpeg for example). 833 | * It contains strings numbered first_addon_message..last_addon_message. 834 | */ 835 | const char * const * addon_message_table; /* Non-library errors */ 836 | int first_addon_message; /* code for first string in addon table */ 837 | int last_addon_message; /* code for last string in addon table */ 838 | }; 839 | 840 | 841 | /* Progress monitor object */ 842 | 843 | struct jpeg_progress_mgr { 844 | JMETHOD(void, progress_monitor, (j_common_ptr cinfo)); 845 | 846 | long pass_counter; /* work units completed in this pass */ 847 | long pass_limit; /* total number of work units in this pass */ 848 | int completed_passes; /* passes completed so far */ 849 | int total_passes; /* total number of passes expected */ 850 | }; 851 | 852 | 853 | /* Data destination object for compression */ 854 | 855 | struct jpeg_destination_mgr { 856 | JOCTET * next_output_byte; /* => next byte to write in buffer */ 857 | size_t free_in_buffer; /* # of byte spaces remaining in buffer */ 858 | 859 | JMETHOD(void, init_destination, (j_compress_ptr cinfo)); 860 | JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo)); 861 | JMETHOD(void, term_destination, (j_compress_ptr cinfo)); 862 | }; 863 | 864 | 865 | /* Data source object for decompression */ 866 | 867 | struct jpeg_source_mgr { 868 | const JOCTET * next_input_byte; /* => next byte to read from buffer */ 869 | size_t bytes_in_buffer; /* # of bytes remaining in buffer */ 870 | #ifdef ANDROID 871 | const JOCTET * start_input_byte; /* => first byte to read from input */ 872 | size_t current_offset; /* current readed input offset */ 873 | #endif 874 | 875 | JMETHOD(void, init_source, (j_decompress_ptr cinfo)); 876 | JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo)); 877 | JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes)); 878 | JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired)); 879 | JMETHOD(void, term_source, (j_decompress_ptr cinfo)); 880 | #ifdef ANDROID 881 | JMETHOD(boolean, seek_input_data, (j_decompress_ptr cinfo, long byte_offset)); 882 | #endif 883 | }; 884 | 885 | 886 | /* Memory manager object. 887 | * Allocates "small" objects (a few K total), "large" objects (tens of K), 888 | * and "really big" objects (virtual arrays with backing store if needed). 889 | * The memory manager does not allow individual objects to be freed; rather, 890 | * each created object is assigned to a pool, and whole pools can be freed 891 | * at once. This is faster and more convenient than remembering exactly what 892 | * to free, especially where malloc()/free() are not too speedy. 893 | * NB: alloc routines never return NULL. They exit to error_exit if not 894 | * successful. 895 | */ 896 | 897 | #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */ 898 | #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */ 899 | #define JPOOL_NUMPOOLS 2 900 | 901 | typedef struct jvirt_sarray_control * jvirt_sarray_ptr; 902 | typedef struct jvirt_barray_control * jvirt_barray_ptr; 903 | 904 | 905 | struct jpeg_memory_mgr { 906 | /* Method pointers */ 907 | JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, 908 | size_t sizeofobject)); 909 | JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, 910 | size_t sizeofobject)); 911 | JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, 912 | JDIMENSION samplesperrow, 913 | JDIMENSION numrows)); 914 | JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, 915 | JDIMENSION blocksperrow, 916 | JDIMENSION numrows)); 917 | JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo, 918 | int pool_id, 919 | boolean pre_zero, 920 | JDIMENSION samplesperrow, 921 | JDIMENSION numrows, 922 | JDIMENSION maxaccess)); 923 | JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, 924 | int pool_id, 925 | boolean pre_zero, 926 | JDIMENSION blocksperrow, 927 | JDIMENSION numrows, 928 | JDIMENSION maxaccess)); 929 | JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo)); 930 | JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, 931 | jvirt_sarray_ptr ptr, 932 | JDIMENSION start_row, 933 | JDIMENSION num_rows, 934 | boolean writable)); 935 | JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, 936 | jvirt_barray_ptr ptr, 937 | JDIMENSION start_row, 938 | JDIMENSION num_rows, 939 | boolean writable)); 940 | JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id)); 941 | JMETHOD(void, self_destruct, (j_common_ptr cinfo)); 942 | 943 | /* Limit on memory allocation for this JPEG object. (Note that this is 944 | * merely advisory, not a guaranteed maximum; it only affects the space 945 | * used for virtual-array buffers.) May be changed by outer application 946 | * after creating the JPEG object. 947 | */ 948 | long max_memory_to_use; 949 | 950 | /* Maximum allocation request accepted by alloc_large. */ 951 | long max_alloc_chunk; 952 | }; 953 | 954 | 955 | /* Routine signature for application-supplied marker processing methods. 956 | * Need not pass marker code since it is stored in cinfo->unread_marker. 957 | */ 958 | typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo)); 959 | 960 | 961 | /* Declarations for routines called by application. 962 | * The JPP macro hides prototype parameters from compilers that can't cope. 963 | * Note JPP requires double parentheses. 964 | */ 965 | 966 | #ifdef HAVE_PROTOTYPES 967 | #define JPP(arglist) arglist 968 | #else 969 | #define JPP(arglist) () 970 | #endif 971 | 972 | 973 | /* Short forms of external names for systems with brain-damaged linkers. 974 | * We shorten external names to be unique in the first six letters, which 975 | * is good enough for all known systems. 976 | * (If your compiler itself needs names to be unique in less than 15 977 | * characters, you are out of luck. Get a better compiler.) 978 | */ 979 | 980 | #ifdef NEED_SHORT_EXTERNAL_NAMES 981 | #define jpeg_std_error jStdError 982 | #define jpeg_CreateCompress jCreaCompress 983 | #define jpeg_CreateDecompress jCreaDecompress 984 | #define jpeg_destroy_compress jDestCompress 985 | #define jpeg_destroy_decompress jDestDecompress 986 | #define jpeg_stdio_dest jStdDest 987 | #define jpeg_stdio_src jStdSrc 988 | #if JPEG_LIB_VERSION >= 80 989 | #define jpeg_mem_dest jMemDest 990 | #define jpeg_mem_src jMemSrc 991 | #endif 992 | #define jpeg_set_defaults jSetDefaults 993 | #define jpeg_set_colorspace jSetColorspace 994 | #define jpeg_default_colorspace jDefColorspace 995 | #define jpeg_set_quality jSetQuality 996 | #define jpeg_set_linear_quality jSetLQuality 997 | #if JPEG_LIB_VERSION >= 70 998 | #define jpeg_default_qtables jDefQTables 999 | #endif 1000 | #define jpeg_add_quant_table jAddQuantTable 1001 | #define jpeg_quality_scaling jQualityScaling 1002 | #define jpeg_simple_progression jSimProgress 1003 | #define jpeg_suppress_tables jSuppressTables 1004 | #define jpeg_alloc_quant_table jAlcQTable 1005 | #define jpeg_alloc_huff_table jAlcHTable 1006 | #define jpeg_start_compress jStrtCompress 1007 | #define jpeg_write_scanlines jWrtScanlines 1008 | #define jpeg_finish_compress jFinCompress 1009 | #if JPEG_LIB_VERSION >= 70 1010 | #define jpeg_calc_jpeg_dimensions jCjpegDimensions 1011 | #endif 1012 | #define jpeg_write_raw_data jWrtRawData 1013 | #define jpeg_write_marker jWrtMarker 1014 | #define jpeg_write_m_header jWrtMHeader 1015 | #define jpeg_write_m_byte jWrtMByte 1016 | #define jpeg_write_tables jWrtTables 1017 | #define jpeg_read_header jReadHeader 1018 | #define jpeg_start_decompress jStrtDecompress 1019 | #define jpeg_read_scanlines jReadScanlines 1020 | #define jpeg_finish_decompress jFinDecompress 1021 | #define jpeg_read_raw_data jReadRawData 1022 | #define jpeg_has_multiple_scans jHasMultScn 1023 | #define jpeg_start_output jStrtOutput 1024 | #define jpeg_finish_output jFinOutput 1025 | #define jpeg_input_complete jInComplete 1026 | #define jpeg_new_colormap jNewCMap 1027 | #define jpeg_consume_input jConsumeInput 1028 | #if JPEG_LIB_VERSION >= 80 1029 | #define jpeg_core_output_dimensions jCoreDimensions 1030 | #endif 1031 | #define jpeg_calc_output_dimensions jCalcDimensions 1032 | #define jpeg_save_markers jSaveMarkers 1033 | #define jpeg_set_marker_processor jSetMarker 1034 | #define jpeg_read_coefficients jReadCoefs 1035 | #define jpeg_write_coefficients jWrtCoefs 1036 | #define jpeg_copy_critical_parameters jCopyCrit 1037 | #define jpeg_abort_compress jAbrtCompress 1038 | #define jpeg_abort_decompress jAbrtDecompress 1039 | #define jpeg_abort jAbort 1040 | #define jpeg_destroy jDestroy 1041 | #define jpeg_resync_to_restart jResyncRestart 1042 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 1043 | 1044 | 1045 | /* Default error-management setup */ 1046 | EXTERN(struct jpeg_error_mgr *) jpeg_std_error 1047 | JPP((struct jpeg_error_mgr * err)); 1048 | 1049 | /* Initialization of JPEG compression objects. 1050 | * jpeg_create_compress() and jpeg_create_decompress() are the exported 1051 | * names that applications should call. These expand to calls on 1052 | * jpeg_CreateCompress and jpeg_CreateDecompress with additional information 1053 | * passed for version mismatch checking. 1054 | * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. 1055 | */ 1056 | #define jpeg_create_compress(cinfo) \ 1057 | jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \ 1058 | (size_t) sizeof(struct jpeg_compress_struct)) 1059 | #define jpeg_create_decompress(cinfo) \ 1060 | jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ 1061 | (size_t) sizeof(struct jpeg_decompress_struct)) 1062 | EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo, 1063 | int version, size_t structsize)); 1064 | EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo, 1065 | int version, size_t structsize)); 1066 | /* Destruction of JPEG compression objects */ 1067 | EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); 1068 | EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); 1069 | 1070 | /* Standard data source and destination managers: stdio streams. */ 1071 | /* Caller is responsible for opening the file before and closing after. */ 1072 | EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); 1073 | EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); 1074 | 1075 | #if JPEG_LIB_VERSION >= 80 1076 | /* Data source and destination managers: memory buffers. */ 1077 | EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo, 1078 | unsigned char ** outbuffer, 1079 | unsigned long * outsize)); 1080 | EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo, 1081 | unsigned char * inbuffer, 1082 | unsigned long insize)); 1083 | #endif 1084 | 1085 | /* Default parameter setup for compression */ 1086 | EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); 1087 | /* Compression parameter setup aids */ 1088 | EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, 1089 | J_COLOR_SPACE colorspace)); 1090 | EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); 1091 | EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, 1092 | boolean force_baseline)); 1093 | EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, 1094 | int scale_factor, 1095 | boolean force_baseline)); 1096 | #if JPEG_LIB_VERSION >= 70 1097 | EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo, 1098 | boolean force_baseline)); 1099 | #endif 1100 | EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, 1101 | const unsigned int *basic_table, 1102 | int scale_factor, 1103 | boolean force_baseline)); 1104 | EXTERN(int) jpeg_quality_scaling JPP((int quality)); 1105 | EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); 1106 | EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, 1107 | boolean suppress)); 1108 | EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo)); 1109 | EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo)); 1110 | 1111 | /* Main entry points for compression */ 1112 | EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, 1113 | boolean write_all_tables)); 1114 | EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, 1115 | JSAMPARRAY scanlines, 1116 | JDIMENSION num_lines)); 1117 | EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); 1118 | 1119 | #if JPEG_LIB_VERSION >= 70 1120 | /* Precalculate JPEG dimensions for current compression parameters. */ 1121 | EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo)); 1122 | #endif 1123 | 1124 | /* Replaces jpeg_write_scanlines when writing raw downsampled data. */ 1125 | EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, 1126 | JSAMPIMAGE data, 1127 | JDIMENSION num_lines)); 1128 | 1129 | /* Write a special marker. See libjpeg.txt concerning safe usage. */ 1130 | EXTERN(void) jpeg_write_marker 1131 | JPP((j_compress_ptr cinfo, int marker, 1132 | const JOCTET * dataptr, unsigned int datalen)); 1133 | /* Same, but piecemeal. */ 1134 | EXTERN(void) jpeg_write_m_header 1135 | JPP((j_compress_ptr cinfo, int marker, unsigned int datalen)); 1136 | EXTERN(void) jpeg_write_m_byte 1137 | JPP((j_compress_ptr cinfo, int val)); 1138 | 1139 | /* Alternate compression function: just write an abbreviated table file */ 1140 | EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo)); 1141 | 1142 | /* Decompression startup: read start of JPEG datastream to see what's there */ 1143 | EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo, 1144 | boolean require_image)); 1145 | /* Return value is one of: */ 1146 | #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ 1147 | #define JPEG_HEADER_OK 1 /* Found valid image datastream */ 1148 | #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */ 1149 | /* If you pass require_image = TRUE (normal case), you need not check for 1150 | * a TABLES_ONLY return code; an abbreviated file will cause an error exit. 1151 | * JPEG_SUSPENDED is only possible if you use a data source module that can 1152 | * give a suspension return (the stdio source module doesn't). 1153 | */ 1154 | 1155 | /* Main entry points for decompression */ 1156 | EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo)); 1157 | 1158 | #ifdef ANDROID 1159 | EXTERN(boolean) jpeg_start_tile_decompress JPP((j_decompress_ptr cinfo)); 1160 | #endif 1161 | 1162 | EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo, 1163 | JSAMPARRAY scanlines, 1164 | JDIMENSION max_lines)); 1165 | EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo)); 1166 | 1167 | /* Replaces jpeg_read_scanlines when reading raw downsampled data. */ 1168 | EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, 1169 | JSAMPIMAGE data, 1170 | JDIMENSION max_lines)); 1171 | 1172 | #ifdef ANDROID 1173 | EXTERN(JDIMENSION) jpeg_read_scanlines_from JPP((j_decompress_ptr cinfo, 1174 | JSAMPARRAY scanlines, 1175 | int line_offset, 1176 | JDIMENSION max_lines)); 1177 | EXTERN(JDIMENSION) jpeg_read_tile_scanline JPP((j_decompress_ptr cinfo, 1178 | huffman_index *index, 1179 | JSAMPARRAY scanlines)); 1180 | EXTERN(void) jpeg_init_read_tile_scanline JPP((j_decompress_ptr cinfo, 1181 | huffman_index *index, 1182 | int *start_x, int *start_y, 1183 | int *width, int *height)); 1184 | #endif 1185 | 1186 | /* Additional entry points for buffered-image mode. */ 1187 | EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo)); 1188 | EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo, 1189 | int scan_number)); 1190 | EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo)); 1191 | EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo)); 1192 | EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo)); 1193 | EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo)); 1194 | /* Return value is one of: */ 1195 | /* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ 1196 | #define JPEG_REACHED_SOS 1 /* Reached start of new scan */ 1197 | #define JPEG_REACHED_EOI 2 /* Reached end of image */ 1198 | #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */ 1199 | #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */ 1200 | 1201 | /* Precalculate output dimensions for current decompression parameters. */ 1202 | #if JPEG_LIB_VERSION >= 80 1203 | EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo)); 1204 | #endif 1205 | EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); 1206 | 1207 | /* Control saving of COM and APPn markers into marker_list. */ 1208 | EXTERN(void) jpeg_save_markers 1209 | JPP((j_decompress_ptr cinfo, int marker_code, 1210 | unsigned int length_limit)); 1211 | 1212 | /* Install a special processing method for COM or APPn markers. */ 1213 | EXTERN(void) jpeg_set_marker_processor 1214 | JPP((j_decompress_ptr cinfo, int marker_code, 1215 | jpeg_marker_parser_method routine)); 1216 | 1217 | /* Read or write raw DCT coefficients --- useful for lossless transcoding. */ 1218 | EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo)); 1219 | EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo, 1220 | jvirt_barray_ptr * coef_arrays)); 1221 | EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo, 1222 | j_compress_ptr dstinfo)); 1223 | 1224 | /* If you choose to abort compression or decompression before completing 1225 | * jpeg_finish_(de)compress, then you need to clean up to release memory, 1226 | * temporary files, etc. You can just call jpeg_destroy_(de)compress 1227 | * if you're done with the JPEG object, but if you want to clean it up and 1228 | * reuse it, call this: 1229 | */ 1230 | EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo)); 1231 | EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo)); 1232 | 1233 | /* Generic versions of jpeg_abort and jpeg_destroy that work on either 1234 | * flavor of JPEG object. These may be more convenient in some places. 1235 | */ 1236 | EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo)); 1237 | EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo)); 1238 | 1239 | /* Default restart-marker-resync procedure for use by data source modules */ 1240 | EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo, 1241 | int desired)); 1242 | 1243 | #ifdef ANDROID 1244 | EXTERN(boolean) jpeg_build_huffman_index 1245 | JPP((j_decompress_ptr cinfo, huffman_index *index)); 1246 | EXTERN(void) jpeg_configure_huffman_decoder(j_decompress_ptr cinfo, 1247 | huffman_offset_data offset); 1248 | EXTERN(void) jpeg_get_huffman_decoder_configuration(j_decompress_ptr cinfo, 1249 | huffman_offset_data *offset); 1250 | EXTERN(void) jpeg_create_huffman_index(j_decompress_ptr cinfo, 1251 | huffman_index *index); 1252 | EXTERN(void) jpeg_configure_huffman_index_scan(j_decompress_ptr cinfo, 1253 | huffman_index *index, int scan_no, int offset); 1254 | EXTERN(void) jpeg_destroy_huffman_index(huffman_index *index); 1255 | #endif 1256 | 1257 | /* These marker codes are exported since applications and data source modules 1258 | * are likely to want to use them. 1259 | */ 1260 | 1261 | #define JPEG_RST0 0xD0 /* RST0 marker code */ 1262 | #define JPEG_EOI 0xD9 /* EOI marker code */ 1263 | #define JPEG_APP0 0xE0 /* APP0 marker code */ 1264 | #define JPEG_COM 0xFE /* COM marker code */ 1265 | 1266 | 1267 | /* If we have a brain-damaged compiler that emits warnings (or worse, errors) 1268 | * for structure definitions that are never filled in, keep it quiet by 1269 | * supplying dummy definitions for the various substructures. 1270 | */ 1271 | 1272 | #ifdef INCOMPLETE_TYPES_BROKEN 1273 | #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */ 1274 | struct jvirt_sarray_control { long dummy; }; 1275 | struct jvirt_barray_control { long dummy; }; 1276 | struct jpeg_comp_master { long dummy; }; 1277 | struct jpeg_c_main_controller { long dummy; }; 1278 | struct jpeg_c_prep_controller { long dummy; }; 1279 | struct jpeg_c_coef_controller { long dummy; }; 1280 | struct jpeg_marker_writer { long dummy; }; 1281 | struct jpeg_color_converter { long dummy; }; 1282 | struct jpeg_downsampler { long dummy; }; 1283 | struct jpeg_forward_dct { long dummy; }; 1284 | struct jpeg_entropy_encoder { long dummy; }; 1285 | struct jpeg_decomp_master { long dummy; }; 1286 | struct jpeg_d_main_controller { long dummy; }; 1287 | struct jpeg_d_coef_controller { long dummy; }; 1288 | struct jpeg_d_post_controller { long dummy; }; 1289 | struct jpeg_input_controller { long dummy; }; 1290 | struct jpeg_marker_reader { long dummy; }; 1291 | struct jpeg_entropy_decoder { long dummy; }; 1292 | struct jpeg_inverse_dct { long dummy; }; 1293 | struct jpeg_upsampler { long dummy; }; 1294 | struct jpeg_color_deconverter { long dummy; }; 1295 | struct jpeg_color_quantizer { long dummy; }; 1296 | #endif /* JPEG_INTERNALS */ 1297 | #endif /* INCOMPLETE_TYPES_BROKEN */ 1298 | 1299 | 1300 | /* 1301 | * The JPEG library modules define JPEG_INTERNALS before including this file. 1302 | * The internal structure declarations are read only when that is true. 1303 | * Applications using the library should not include jpegint.h, but may wish 1304 | * to include jerror.h. 1305 | */ 1306 | 1307 | #ifdef JPEG_INTERNALS 1308 | #include "jpegint.h" /* fetch private declarations */ 1309 | #include "jerror.h" /* fetch error codes too */ 1310 | #endif 1311 | 1312 | #ifndef ANDROID 1313 | #ifdef __cplusplus 1314 | #ifndef DONT_USE_EXTERN_C 1315 | } 1316 | #endif 1317 | #endif 1318 | #endif 1319 | 1320 | #endif /* JPEGLIB_H */ 1321 | -------------------------------------------------------------------------------- /app/src/main/cpp/jpeg/jversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jversion.h 3 | * 4 | * Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding. 5 | * Copyright (C) 2010, D. R. Commander. 6 | * This file is part of the Independent JPEG Group's software. 7 | * For conditions of distribution and use, see the accompanying README file. 8 | * 9 | * This file contains software version identification. 10 | */ 11 | 12 | 13 | #if JPEG_LIB_VERSION >= 80 14 | 15 | #define JVERSION "8b 16-May-2010" 16 | 17 | #define JCOPYRIGHT "Copyright (C) 2010, Thomas G. Lane, Guido Vollbeding" 18 | 19 | #elif JPEG_LIB_VERSION >= 70 20 | 21 | #define JVERSION "7 27-Jun-2009" 22 | 23 | #define JCOPYRIGHT "Copyright (C) 2009, Thomas G. Lane, Guido Vollbeding" 24 | 25 | #else 26 | 27 | #define JVERSION "6b 27-Mar-1998" 28 | 29 | #define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane" 30 | 31 | #endif 32 | 33 | #define LJTCOPYRIGHT "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ 34 | "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \ 35 | "Copyright (C) 2009-2011 D. R. Commander\n" \ 36 | "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)" 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/effective/bitmap/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.effective.bitmap; 2 | 3 | import android.Manifest; 4 | import android.annotation.TargetApi; 5 | import android.app.Activity; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.pm.PackageManager; 9 | import android.graphics.Bitmap; 10 | import android.net.Uri; 11 | import android.os.Build; 12 | import android.provider.DocumentsContract; 13 | import android.provider.MediaStore; 14 | import android.support.annotation.NonNull; 15 | import android.support.v4.app.ActivityCompat; 16 | import android.support.v4.content.ContextCompat; 17 | import android.support.v7.app.AppCompatActivity; 18 | import android.os.Bundle; 19 | import android.view.View; 20 | import android.widget.TextView; 21 | import android.widget.Toast; 22 | 23 | import com.effective.bitmap.utils.EffectiveBitmapUtils; 24 | import com.effective.bitmap.utils.UriToPathUtils; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | 29 | public class MainActivity extends AppCompatActivity { 30 | 31 | public static final int REQUEST_CODE_IMAGE = 0; 32 | public static final int REQUEST_CODE_KITKAT_IMAGE = 1; 33 | public static final int REQUEST_CODE_PERMISSION = 2; 34 | 35 | TextView tv_path; 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_main); 41 | tv_path = findViewById(R.id.tv_path); 42 | } 43 | 44 | public void selectPhoto(View v) { 45 | 46 | int result = ContextCompat.checkSelfPermission(MainActivity.this, 47 | Manifest.permission.READ_EXTERNAL_STORAGE); 48 | if (result != PackageManager.PERMISSION_GRANTED) { 49 | ActivityCompat.requestPermissions(MainActivity.this, 50 | new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE_PERMISSION); 51 | } else { 52 | pickPhoto(); 53 | } 54 | 55 | } 56 | 57 | private void pickPhoto() { 58 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 59 | startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"), 60 | REQUEST_CODE_IMAGE); 61 | } else { 62 | Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 63 | intent.addCategory(Intent.CATEGORY_OPENABLE); 64 | intent.setType("image/*"); 65 | startActivityForResult(intent, REQUEST_CODE_KITKAT_IMAGE); 66 | } 67 | } 68 | 69 | @Override 70 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 71 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 72 | if (requestCode == REQUEST_CODE_PERMISSION) { 73 | if (grantResults.length > 0) { 74 | pickPhoto(); 75 | } 76 | } 77 | } 78 | 79 | @Override 80 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 81 | super.onActivityResult(requestCode, resultCode, data); 82 | if (resultCode == Activity.RESULT_OK) { 83 | switch (requestCode) { 84 | case REQUEST_CODE_IMAGE: 85 | if (data != null) { 86 | Uri uri = data.getData(); 87 | compressImage(uri); 88 | } 89 | break; 90 | case REQUEST_CODE_KITKAT_IMAGE: 91 | if (data != null) { 92 | Uri uri = ensureUriPermission(this, data); 93 | compressImage(uri); 94 | } 95 | break; 96 | } 97 | } 98 | } 99 | 100 | @SuppressWarnings("ResourceType") 101 | @TargetApi(Build.VERSION_CODES.KITKAT) 102 | public static Uri ensureUriPermission(Context context, Intent intent) { 103 | Uri uri = intent.getData(); 104 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 105 | final int takeFlags = intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION; 106 | context.getContentResolver().takePersistableUriPermission(uri, takeFlags); 107 | } 108 | return uri; 109 | } 110 | 111 | public void compressImage(final Uri uri) { 112 | Toast.makeText(MainActivity.this, "start compress...", Toast.LENGTH_LONG).show(); 113 | new Thread(new Runnable() { 114 | @Override 115 | public void run() { 116 | try { 117 | Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); 118 | 119 | File fromQualityFile = new File(getExternalCacheDir(), "FromQuality.jpg"); 120 | EffectiveBitmapUtils.compressByQuality(bitmap, fromQualityFile); 121 | 122 | File fromSizeFile = new File(getExternalCacheDir(), "FromSize.jpg"); 123 | EffectiveBitmapUtils.compressBySize(bitmap, fromSizeFile); 124 | 125 | File fromSample = new File(getExternalCacheDir(), "FromSample.jpg"); 126 | File f = new File(getPathByUri(getApplicationContext(), uri)); 127 | EffectiveBitmapUtils.compressBySample(f.getAbsolutePath(), fromSample); 128 | 129 | File fromJniFile = new File(getExternalCacheDir(), "FromJNI.jpg"); 130 | EffectiveBitmapUtils.compressByJNI(bitmap, fromJniFile.getAbsolutePath(), true); 131 | 132 | runOnUiThread(new Runnable() { 133 | @Override 134 | public void run() { 135 | tv_path.setText(getExternalCacheDir().getAbsolutePath()); 136 | } 137 | }); 138 | } catch (IOException e) { 139 | e.printStackTrace(); 140 | } 141 | } 142 | }).start(); 143 | } 144 | 145 | private String getPathByUri(Context context, Uri uri) { 146 | String path; 147 | if (DocumentsContract.isDocumentUri(context, uri)) { 148 | path = UriToPathUtils.getPath(context, uri); 149 | } else { 150 | path = UriToPathUtils.getEncodedPath(context, uri); 151 | } 152 | return path; 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /app/src/main/java/com/effective/bitmap/utils/EffectiveBitmapUtils.java: -------------------------------------------------------------------------------- 1 | package com.effective.bitmap.utils; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.File; 10 | import java.io.FileOutputStream; 11 | 12 | /** 13 | * Created by Ricky on 2018/4/12. 14 | */ 15 | 16 | public class EffectiveBitmapUtils { 17 | 18 | static { 19 | System.loadLibrary("jpegbither"); 20 | System.loadLibrary("effective-bitmap"); 21 | } 22 | 23 | public static native String compressBitmap(Bitmap bit, int w, int h, int quality, byte[] fileNameBytes, 24 | boolean optimize); 25 | 26 | private static int DEFAULT_QUALITY = 30; 27 | 28 | public static void compressByJNI(Bitmap bit, String fileName, boolean optimize) { 29 | saveBitmap(bit, DEFAULT_QUALITY, fileName, optimize); 30 | } 31 | 32 | private static void saveBitmap(Bitmap bit, int quality, String fileName, boolean optimize) { 33 | compressBitmap(bit, bit.getWidth(), bit.getHeight(), quality, fileName.getBytes(), optimize); 34 | } 35 | 36 | public static void compressByQuality(Bitmap bmp, File file) { 37 | int options = DEFAULT_QUALITY; 38 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 39 | bmp.compress(Bitmap.CompressFormat.JPEG, options, baos); 40 | try { 41 | FileOutputStream fos = new FileOutputStream(file); 42 | fos.write(baos.toByteArray()); 43 | fos.flush(); 44 | fos.close(); 45 | } catch (Exception e) { 46 | e.printStackTrace(); 47 | } 48 | } 49 | 50 | public static void compressBySize(Bitmap bmp, File file) { 51 | int ratio = 8; 52 | Bitmap result = Bitmap.createBitmap(bmp.getWidth() / ratio, bmp.getHeight() / ratio, Bitmap.Config.ARGB_8888); 53 | Canvas canvas = new Canvas(result); 54 | Rect rect = new Rect(0, 0, bmp.getWidth() / ratio, bmp.getHeight() / ratio); 55 | canvas.drawBitmap(bmp, null, rect, null); 56 | 57 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 58 | result.compress(Bitmap.CompressFormat.JPEG, 100, baos); 59 | try { 60 | FileOutputStream fos = new FileOutputStream(file); 61 | fos.write(baos.toByteArray()); 62 | fos.flush(); 63 | fos.close(); 64 | } catch (Exception e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | public static void compressBySample(String filePath, File file) { 70 | int inSampleSize = 8; 71 | BitmapFactory.Options options = new BitmapFactory.Options(); 72 | options.inJustDecodeBounds = false; 73 | options.inSampleSize = inSampleSize; 74 | Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); 75 | 76 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 77 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 78 | try { 79 | if (file.exists()) { 80 | file.delete(); 81 | } else { 82 | file.createNewFile(); 83 | } 84 | FileOutputStream fos = new FileOutputStream(file); 85 | fos.write(baos.toByteArray()); 86 | fos.flush(); 87 | fos.close(); 88 | } catch (Exception e) { 89 | e.printStackTrace(); 90 | } 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /app/src/main/java/com/effective/bitmap/utils/UriToPathUtils.java: -------------------------------------------------------------------------------- 1 | package com.effective.bitmap.utils; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.ContentUris; 5 | import android.content.Context; 6 | import android.database.Cursor; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.os.Environment; 10 | import android.provider.DocumentsContract; 11 | import android.provider.MediaStore; 12 | 13 | public class UriToPathUtils { 14 | 15 | @TargetApi(19) 16 | public static String getPath(final Context context, final Uri uri) { 17 | 18 | final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 19 | 20 | // DocumentProvider 21 | if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { 22 | // ExternalStorageProvider 23 | if (isExternalStorageDocument(uri)) { 24 | final String docId = DocumentsContract.getDocumentId(uri); 25 | final String[] split = docId.split(":"); 26 | final String type = split[0]; 27 | 28 | if ("primary".equalsIgnoreCase(type)) { 29 | return Environment.getExternalStorageDirectory() + "/" + split[1]; 30 | } 31 | 32 | // TODO handle non-primary volumes 33 | } 34 | // DownloadsProvider 35 | else if (isDownloadsDocument(uri)) { 36 | 37 | final String id = DocumentsContract.getDocumentId(uri); 38 | final Uri contentUri = ContentUris.withAppendedId( 39 | Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); 40 | 41 | return getDataColumn(context, contentUri, null, null); 42 | } 43 | // MediaProvider 44 | else if (isMediaDocument(uri)) { 45 | final String docId = DocumentsContract.getDocumentId(uri); 46 | final String[] split = docId.split(":"); 47 | final String type = split[0]; 48 | 49 | Uri contentUri = null; 50 | if ("image".equals(type)) { 51 | contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 52 | } else if ("video".equals(type)) { 53 | contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 54 | } else if ("audio".equals(type)) { 55 | contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 56 | } 57 | 58 | final String selection = "_id=?"; 59 | final String[] selectionArgs = new String[]{ 60 | split[1] 61 | }; 62 | 63 | return getDataColumn(context, contentUri, selection, selectionArgs); 64 | } 65 | } 66 | // MediaStore (and general) 67 | else if ("content".equalsIgnoreCase(uri.getScheme())) { 68 | 69 | // Return the remote address 70 | if (isGooglePhotosUri(uri)) 71 | return uri.getLastPathSegment(); 72 | 73 | return getDataColumn(context, uri, null, null); 74 | } 75 | // File 76 | else if ("file".equalsIgnoreCase(uri.getScheme())) { 77 | return uri.getPath(); 78 | } 79 | 80 | return null; 81 | } 82 | 83 | /** 84 | * Get the value of the data column for this Uri. This is useful for 85 | * MediaStore Uris, and other file-based ContentProviders. 86 | * 87 | * @param context The context. 88 | * @param uri The Uri to query. 89 | * @param selection (Optional) Filter used in the query. 90 | * @param selectionArgs (Optional) Selection arguments used in the query. 91 | * @return The value of the _data column, which is typically a file path. 92 | */ 93 | public static String getDataColumn(Context context, Uri uri, String selection, 94 | String[] selectionArgs) { 95 | 96 | Cursor cursor = null; 97 | final String column = "_data"; 98 | final String[] projection = { 99 | column 100 | }; 101 | 102 | try { 103 | cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, 104 | null); 105 | if (cursor != null && cursor.moveToFirst()) { 106 | final int index = cursor.getColumnIndexOrThrow(column); 107 | return cursor.getString(index); 108 | } 109 | } finally { 110 | if (cursor != null) 111 | cursor.close(); 112 | } 113 | return null; 114 | } 115 | 116 | 117 | /** 118 | * @param uri The Uri to check. 119 | * @return Whether the Uri authority is ExternalStorageProvider. 120 | */ 121 | public static boolean isExternalStorageDocument(Uri uri) { 122 | return "com.android.externalstorage.documents".equals(uri.getAuthority()); 123 | } 124 | 125 | /** 126 | * @param uri The Uri to check. 127 | * @return Whether the Uri authority is DownloadsProvider. 128 | */ 129 | public static boolean isDownloadsDocument(Uri uri) { 130 | return "com.android.providers.downloads.documents".equals(uri.getAuthority()); 131 | } 132 | 133 | /** 134 | * @param uri The Uri to check. 135 | * @return Whether the Uri authority is MediaProvider. 136 | */ 137 | public static boolean isMediaDocument(Uri uri) { 138 | return "com.android.providers.media.documents".equals(uri.getAuthority()); 139 | } 140 | 141 | /** 142 | * @param uri The Uri to check. 143 | * @return Whether the Uri authority is Google Photos. 144 | */ 145 | public static boolean isGooglePhotosUri(Uri uri) { 146 | return "com.google.android.apps.photos.content".equals(uri.getAuthority()); 147 | } 148 | 149 | /** 150 | * 获得本地图片的本地地址 151 | * 152 | * @param context 153 | * @return 154 | */ 155 | public static String getEncodedPath(Context context, Uri selectedImage) { 156 | // Uri selectedImage = data.getData(); 157 | // Log.e(TAG, selectedImage.toString()); 158 | if (selectedImage != null) { 159 | String uriStr = selectedImage.toString(); 160 | String path = uriStr.substring(10, uriStr.length()); 161 | if (path.startsWith("com.sec.android.gallery3d")) { 162 | return null; 163 | } 164 | } 165 | String[] filePathColumn = {MediaStore.Images.Media.DATA}; 166 | Cursor cursor = context.getContentResolver().query(selectedImage, filePathColumn, null, null, null); 167 | cursor.moveToFirst(); 168 | int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 169 | String picturePath = cursor.getString(columnIndex); 170 | cursor.close(); 171 | return picturePath; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |