├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── libs │ ├── armeabi-v7a │ │ └── libjpeg.a │ ├── armeabi │ │ └── libjpeg.a │ └── jpeg │ │ ├── android │ │ ├── config.h │ │ └── jconfig.h │ │ ├── cderror.h │ │ ├── cdjpeg.h │ │ ├── jconfig.h │ │ ├── jerror.h │ │ ├── jinclude.h │ │ ├── jmorecfg.h │ │ ├── jpeglib.h │ │ └── jversion.h ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── handsome │ │ └── bitmapcompress │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── cpp │ │ └── native-lib.cpp │ ├── java │ │ └── com │ │ │ └── handsome │ │ │ └── bitmapcompress │ │ │ ├── CompressUtils.java │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.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 │ └── handsome │ └── bitmapcompress │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 39 | 40 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 88 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 115 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndroidHensen/BitmapCompress/3aa08853e6d04b0d38466746d57ceea5242789bc/README.md -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | include_directories(./libs/jpeg) 4 | link_directories(./libs/${ANDROID_ABI}) 5 | 6 | find_library(log-lib 7 | log) 8 | find_library(android-lib 9 | android) 10 | find_library(bitmap-lib 11 | jnigraphics) 12 | 13 | 14 | add_library( # Sets the name of the library. 15 | native-lib 16 | 17 | # Sets the library as a shared library. 18 | SHARED 19 | 20 | # Provides a relative path to your source file(s). 21 | src/main/cpp/native-lib.cpp ) 22 | 23 | target_link_libraries( native-lib 24 | ${log-lib} 25 | ${android-lib} 26 | ${bitmap-lib} 27 | jpeg ) -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | defaultConfig { 7 | applicationId "com.handsome.bitmapcompress" 8 | minSdkVersion 16 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | externalNativeBuild { 14 | cmake { 15 | cppFlags "-std=c++11 -frtti -fexceptions" 16 | abiFilters "armeabi", "armeabi-v7a" 17 | } 18 | } 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | sourceSets.main { 27 | jniLibs.srcDirs = ['libs'] 28 | jni.srcDirs = [] 29 | } 30 | externalNativeBuild { 31 | cmake { 32 | path "CMakeLists.txt" 33 | } 34 | } 35 | } 36 | 37 | dependencies { 38 | compile fileTree(dir: 'libs', include: ['*.jar']) 39 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 40 | exclude group: 'com.android.support', module: 'support-annotations' 41 | }) 42 | compile 'com.android.support:appcompat-v7:25.3.1' 43 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 44 | testCompile 'junit:junit:4.12' 45 | } 46 | -------------------------------------------------------------------------------- /app/libs/armeabi-v7a/libjpeg.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndroidHensen/BitmapCompress/3aa08853e6d04b0d38466746d57ceea5242789bc/app/libs/armeabi-v7a/libjpeg.a -------------------------------------------------------------------------------- /app/libs/armeabi/libjpeg.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndroidHensen/BitmapCompress/3aa08853e6d04b0d38466746d57ceea5242789bc/app/libs/armeabi/libjpeg.a -------------------------------------------------------------------------------- /app/libs/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 | 80 | /* Define if you have sys/types.h */ 81 | #define NEED_SYS_TYPES_H 1 82 | 83 | /* Name of package */ 84 | #define PACKAGE "libjpeg-turbo" 85 | 86 | /* Define to the address where bug reports for this package should be sent. */ 87 | #define PACKAGE_BUGREPORT "" 88 | 89 | /* Define to the full name of this package. */ 90 | #define PACKAGE_NAME "libjpeg-turbo" 91 | 92 | /* Define to the full name and version of this package. */ 93 | #define PACKAGE_STRING "libjpeg-turbo 1.1.90" 94 | 95 | /* Define to the one symbol short name of this package. */ 96 | #define PACKAGE_TARNAME "libjpeg-turbo" 97 | 98 | /* Define to the home page for this package. */ 99 | #define PACKAGE_URL "" 100 | 101 | /* Define to the version of this package. */ 102 | #define PACKAGE_VERSION "1.1.90" 103 | 104 | /* Define if shift is unsigned */ 105 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */ 106 | 107 | /* Define to 1 if you have the ANSI C header files. */ 108 | #define STDC_HEADERS 1 109 | 110 | /* Version number of package */ 111 | #define VERSION "1.1.90" 112 | 113 | /* Use accelerated SIMD routines. */ 114 | #define WITH_SIMD 1 115 | 116 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */ 117 | #ifndef __CHAR_UNSIGNED__ 118 | /* # undef __CHAR_UNSIGNED__ */ 119 | #endif 120 | 121 | /* Define to empty if `const' does not conform to ANSI C. */ 122 | /* #undef const */ 123 | 124 | /* Define to `__inline__' or `__inline' if that's what the C compiler 125 | calls it, or to nothing if 'inline' is not supported under any name. */ 126 | #ifndef __cplusplus 127 | /* #undef inline */ 128 | #endif 129 | 130 | /* Define to `unsigned int' if does not define. */ 131 | /* #undef size_t */ 132 | -------------------------------------------------------------------------------- /app/libs/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/libs/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/libs/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/libs/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/libs/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/libs/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/libs/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/libs/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/libs/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/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Eclipse\android-studio-sdk\android-sdk-windows/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/handsome/bitmapcompress/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.handsome.bitmapcompress; 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 | * Instrumentation 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.handsome.bitmapcompress", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/cpp/native-lib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern "C" { 8 | #include "jpeglib.h" 9 | #include "cdjpeg.h" 10 | } 11 | 12 | #define LOG_TAG "jni" 13 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) 14 | 15 | typedef uint8_t BYTE; 16 | 17 | typedef struct my_error_mgr *my_error_ptr; 18 | struct my_error_mgr { 19 | struct jpeg_error_mgr pub; 20 | jmp_buf setjmp_buffer; 21 | }; 22 | 23 | METHODDEF(void) 24 | my_error_exit(j_common_ptr cinfo) { 25 | my_error_ptr myerr = (my_error_ptr) cinfo->err; 26 | (*cinfo->err->output_message)(cinfo); 27 | LOGE("jpeg_message_table[%d]:%s", myerr->pub.msg_code, 28 | myerr->pub.jpeg_message_table[myerr->pub.msg_code]); 29 | longjmp(myerr->setjmp_buffer, 1); 30 | } 31 | 32 | /** 33 | * 采用Libjpeg压缩 34 | * @param data 35 | * @param w 36 | * @param h 37 | * @param quality 38 | * @param outfilename 39 | * @param optimize 40 | * @return 41 | */ 42 | int generateJPEG(BYTE *data, int w, int h, int quality, 43 | const char *outfilename, jboolean optimize) { 44 | 45 | //jpeg的结构体,保存的比如宽、高、位深、图片格式等信息 46 | struct jpeg_compress_struct jcs; 47 | //当读完整个文件的时候就会回调my_error_exit 48 | struct my_error_mgr jem; 49 | jcs.err = jpeg_std_error(&jem.pub); 50 | jem.pub.error_exit = my_error_exit; 51 | if (setjmp(jem.setjmp_buffer)) { 52 | return 0; 53 | } 54 | //初始化jsc结构体 55 | jpeg_create_compress(&jcs); 56 | //打开输出文件 57 | FILE* f = fopen(outfilename, "wb"); 58 | if (f == NULL) { 59 | return 0; 60 | } 61 | //设置结构体的文件路径 62 | jpeg_stdio_dest(&jcs, f); 63 | jcs.image_width = w;//设置宽高 64 | jcs.image_height = h; 65 | //设置哈夫曼编码,TRUE=arithmetic coding, FALSE=Huffman 66 | if (optimize) { 67 | jcs.arith_code = false; 68 | } else { 69 | jcs.arith_code = true; 70 | } 71 | //颜色通道数量 72 | int nComponent = 3; 73 | jcs.input_components = nComponent; 74 | //设置结构体的颜色空间为RGB 75 | jcs.in_color_space = JCS_RGB; 76 | //全部设置默认参数 77 | jpeg_set_defaults(&jcs); 78 | //是否采用哈弗曼表数据计算 品质相差5-10倍 79 | jcs.optimize_coding = optimize; 80 | //设置质量 81 | jpeg_set_quality(&jcs, quality, true); 82 | //开始压缩,(是否写入全部像素) 83 | jpeg_start_compress(&jcs, TRUE); 84 | 85 | JSAMPROW row_pointer[1]; 86 | int row_stride; 87 | //一行的RGB数量 88 | row_stride = jcs.image_width * nComponent; 89 | //一行一行遍历 90 | while (jcs.next_scanline < jcs.image_height) { 91 | //得到一行的首地址 92 | row_pointer[0] = &data[jcs.next_scanline * row_stride]; 93 | //此方法会将jcs.next_scanline加1 94 | jpeg_write_scanlines(&jcs, row_pointer, 1);//row_pointer就是一行的首地址,1:写入的行数 95 | } 96 | jpeg_finish_compress(&jcs); 97 | jpeg_destroy_compress(&jcs); 98 | fclose(f); 99 | return 1; 100 | } 101 | 102 | /** 103 | * byte数组转C的字符串 104 | */ 105 | char *jstrinTostring(JNIEnv *env, jbyteArray barr) { 106 | char *rtn = NULL; 107 | jsize alen = env->GetArrayLength(barr); 108 | jbyte *ba = env->GetByteArrayElements(barr, 0); 109 | if (alen > 0) { 110 | rtn = (char *) malloc(alen + 1); 111 | memcpy(rtn, ba, alen); 112 | rtn[alen] = 0; 113 | } 114 | env->ReleaseByteArrayElements(barr, ba, 0); 115 | return rtn; 116 | } 117 | 118 | extern "C" 119 | JNIEXPORT jint JNICALL 120 | Java_com_handsome_bitmapcompress_CompressUtils_compressBitmap(JNIEnv *env, jclass type, 121 | jobject bitmap, 122 | jint quality, 123 | jbyteArray fileNameBytes_, 124 | jboolean optimize) { 125 | //获取Bitmap信息 126 | AndroidBitmapInfo android_bitmap_info; 127 | AndroidBitmap_getInfo(env, bitmap, &android_bitmap_info); 128 | //获取bitmap的 宽,高,format 129 | int w = android_bitmap_info.width; 130 | int h = android_bitmap_info.height; 131 | int format = android_bitmap_info.format; 132 | 133 | if (format != ANDROID_BITMAP_FORMAT_RGBA_8888) { 134 | return -1; 135 | } 136 | 137 | //存储ARGB所有像素点 138 | BYTE *pixelsColor; 139 | //1、读取Bitmap所有像素信息 140 | AndroidBitmap_lockPixels(env, bitmap, (void **) &pixelsColor); 141 | //2、解析每个像素,去除A通量,取出RGB通量 142 | int i = 0, j = 0; 143 | BYTE a, r, g, b; 144 | //存储RGB所有像素点 145 | BYTE *data; 146 | data = (BYTE *) malloc(w * h * 3); 147 | //存储RGB首地址 148 | BYTE *tempData = data; 149 | 150 | int color; 151 | for (i = 0; i < h; ++i) { 152 | for (j = 0; j < w; ++j) { 153 | //将8位通道转成32位通道 154 | color = *((int *) pixelsColor); 155 | //取值 156 | a = ((color & 0xFF000000) >> 24); 157 | r = ((color & 0x00FF0000) >> 16); 158 | g = ((color & 0x0000FF00) >> 8); 159 | b = ((color & 0x000000FF)); 160 | //赋值 161 | *data = b; 162 | *(data + 1) = g; 163 | *(data + 2) = r; 164 | //指针往后移 165 | data += 3; 166 | pixelsColor += 4; 167 | } 168 | } 169 | 170 | //3、读取像素点完毕 171 | AndroidBitmap_unlockPixels(env, bitmap); 172 | char *fileName = jstrinTostring(env, fileNameBytes_); 173 | //4、采用Libjpeg进行压缩 174 | int resultCode = generateJPEG(tempData, w, h, quality, fileName, optimize); 175 | if (resultCode == 0) { 176 | return 0; 177 | } 178 | return 1; 179 | } 180 | -------------------------------------------------------------------------------- /app/src/main/java/com/handsome/bitmapcompress/CompressUtils.java: -------------------------------------------------------------------------------- 1 | package com.handsome.bitmapcompress; 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 | * =====作者===== 14 | * 许英俊 15 | * =====时间===== 16 | * 2017/12/23. 17 | */ 18 | 19 | public class CompressUtils { 20 | 21 | static { 22 | System.loadLibrary("native-lib"); 23 | } 24 | 25 | /** 26 | * LibJpeg压缩 27 | * 28 | * @param bitmap 29 | * @param quality 30 | * @param fileNameBytes 31 | * @param optimize 32 | * @return 33 | */ 34 | public static native int compressBitmap(Bitmap bitmap, int quality, byte[] fileNameBytes, 35 | boolean optimize); 36 | 37 | 38 | /** 39 | * 质量压缩 40 | * 41 | * @param bitmap 42 | * @param quality 43 | * @param file 44 | */ 45 | public static void compressQuality(Bitmap bitmap, int quality, File file) { 46 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 47 | bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos); 48 | try { 49 | FileOutputStream fos = new FileOutputStream(file); 50 | fos.write(baos.toByteArray()); 51 | fos.flush(); 52 | fos.close(); 53 | } catch (Exception e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | 58 | /** 59 | * 尺寸压缩 60 | * 61 | * @param bitmap 62 | * @param file 63 | */ 64 | public static void compressSize(Bitmap bitmap, File file) { 65 | int ratio = 8;//尺寸压缩比例 66 | Bitmap result = Bitmap.createBitmap(bitmap.getWidth() / ratio, bitmap.getHeight() / ratio, Bitmap.Config.ARGB_8888); 67 | Canvas canvas = new Canvas(result); 68 | Rect rect = new Rect(0, 0, bitmap.getWidth() / ratio, bitmap.getHeight() / ratio); 69 | canvas.drawBitmap(bitmap, null, rect, null); 70 | 71 | compressQuality(result, 100, file); 72 | } 73 | 74 | /** 75 | * 采样率压缩 76 | * 77 | * @param filePath 78 | * @param file 79 | */ 80 | public static void compressSample(String filePath, File file) { 81 | int inSampleSize = 8;//采样率设置 82 | BitmapFactory.Options options = new BitmapFactory.Options(); 83 | options.inJustDecodeBounds = false; 84 | options.inSampleSize = inSampleSize; 85 | Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); 86 | 87 | compressQuality(bitmap, 100, file); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/handsome/bitmapcompress/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.handsome.bitmapcompress; 2 | 3 | import android.Manifest; 4 | import android.annotation.TargetApi; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.pm.PackageManager; 8 | import android.graphics.Bitmap; 9 | import android.net.Uri; 10 | import android.os.Build; 11 | import android.provider.MediaStore; 12 | import android.support.v4.app.ActivityCompat; 13 | import android.support.v4.content.ContextCompat; 14 | import android.support.v7.app.AppCompatActivity; 15 | import android.os.Bundle; 16 | import android.view.View; 17 | import android.widget.Toast; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | 22 | public class MainActivity extends AppCompatActivity { 23 | 24 | private static final int REQUEST_PICK_IMAGE = 0x0011; 25 | private static final int REQUEST_KITKAT_PICK_IMAGE = 0x0012; 26 | private static final int REQUEST_PERMISSION_CODE = 0x0013; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | } 33 | 34 | /** 35 | * 点击事件 36 | * 37 | * @param v 38 | */ 39 | public void pickFromGallery(View v) { 40 | checkPermission(); 41 | } 42 | 43 | /** 44 | * 申请权限 45 | */ 46 | public void checkPermission() { 47 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) 48 | != PackageManager.PERMISSION_GRANTED) { 49 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 50 | REQUEST_PERMISSION_CODE); 51 | } else { 52 | selectFile(); 53 | } 54 | } 55 | 56 | /** 57 | * 选择文件 58 | */ 59 | public void selectFile() { 60 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 61 | startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"), REQUEST_PICK_IMAGE); 62 | } else { 63 | Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 64 | intent.addCategory(Intent.CATEGORY_OPENABLE); 65 | intent.setType("image/*"); 66 | startActivityForResult(intent, REQUEST_KITKAT_PICK_IMAGE); 67 | } 68 | } 69 | 70 | /** 71 | * 返回结果 72 | * 73 | * @param requestCode 74 | * @param resultCode 75 | * @param data 76 | */ 77 | @Override 78 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 79 | super.onActivityResult(requestCode, resultCode, data); 80 | if (resultCode == RESULT_OK) { 81 | switch (requestCode) { 82 | case REQUEST_PICK_IMAGE: 83 | if (data != null) { 84 | Uri uri = data.getData(); 85 | compressImage(uri); 86 | } 87 | break; 88 | case REQUEST_KITKAT_PICK_IMAGE: 89 | if (data != null) { 90 | Uri uri = ensureUriPermission(this, data); 91 | compressImage(uri); 92 | } 93 | break; 94 | } 95 | } 96 | } 97 | 98 | /** 99 | * 分配临时权限,仅适配机型作用 100 | * 101 | * @param context 102 | * @param intent 103 | * @return 104 | */ 105 | @SuppressWarnings("ResourceType") 106 | @TargetApi(Build.VERSION_CODES.KITKAT) 107 | public static Uri ensureUriPermission(Context context, Intent intent) { 108 | Uri uri = intent.getData(); 109 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 110 | final int takeFlags = intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION; 111 | context.getContentResolver().takePersistableUriPermission(uri, takeFlags); 112 | } 113 | return uri; 114 | } 115 | 116 | /** 117 | * 压缩图片 118 | * 注意:记得手动开启权限 119 | * 120 | * @param uri 121 | */ 122 | public void compressImage(Uri uri) { 123 | try { 124 | File saveFile = new File(getExternalCacheDir(), "NDK压缩.jpg"); 125 | Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); 126 | int code = CompressUtils.compressBitmap(bitmap, 20, saveFile.getAbsolutePath().getBytes(), true); 127 | 128 | File saveFile1 = new File(getExternalCacheDir(), "质量压缩.jpg"); 129 | CompressUtils.compressQuality(bitmap, 20, saveFile1); 130 | 131 | File saveFile2 = new File(getExternalCacheDir(), "尺寸压缩.jpg"); 132 | CompressUtils.compressSize(bitmap, saveFile2); 133 | 134 | //采样率比较特殊,需要传递文件的目录,这里采用直接指定目录的文件 135 | File saveFile3 = new File(getExternalCacheDir(), "采样率压缩.jpg"); 136 | File LocalFile = new File("/storage/emulated/0/DCIM/Camera/IMG_20171216_171956.jpg"); 137 | if (LocalFile.exists()) { 138 | CompressUtils.compressSample(LocalFile.getAbsolutePath(), saveFile3); 139 | } 140 | 141 | } catch (IOException e) { 142 | e.printStackTrace(); 143 | } 144 | } 145 | 146 | /** 147 | * 权限回调 148 | * 149 | * @param requestCode 150 | * @param permissions 151 | * @param grantResults 152 | */ 153 | @Override 154 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 155 | if (requestCode == REQUEST_PERMISSION_CODE) { 156 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 157 | selectFile(); 158 | } else { 159 | Toast.makeText(MainActivity.this, "Permission Denied", Toast.LENGTH_SHORT).show(); 160 | } 161 | return; 162 | } 163 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |