├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── cpp
│ │ │ ├── libs
│ │ │ │ └── armeabi-v7a
│ │ │ │ │ ├── libjpeg.a
│ │ │ │ │ └── libturbojpeg.a
│ │ │ ├── include
│ │ │ │ ├── jconfig.h
│ │ │ │ ├── jerror.h
│ │ │ │ ├── jmorecfg.h
│ │ │ │ └── jpeglib.h
│ │ │ └── jpeg-yk.cpp
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── yk
│ │ │ │ └── libjpeg_sample
│ │ │ │ ├── libjpeg
│ │ │ │ └── JpegUtils.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── yk
│ │ │ └── libjpeg_sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── yk
│ │ └── libjpeg_sample
│ │ └── ExampleInstrumentedTest.java
├── CMakeLists.txt
├── proguard-rules.pro
└── build.gradle
├── jpeg_app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── ykun
│ │ │ └── libjpeg_sample
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── yk
│ │ │ └── libjpeg_sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── yk
│ │ └── libjpeg_sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── libjpeg_module
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── yk
│ │ │ └── libjpeg_sample
│ │ │ └── libjpeg
│ │ │ └── JpegUtils.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── yk
│ │ │ └── libjpeg_sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── yk
│ │ └── libjpeg_sample
│ │ └── ExampleInstrumentedTest.java
├── libs
│ └── armeabi-v7a
│ │ └── libjpeg-yk.so
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── encodings.xml
├── misc.xml
├── runConfigurations.xml
└── modules.xml
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── jpeg_build.sh
├── gradlew
├── LICENSE
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/jpeg_app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/libjpeg_module/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':libjpeg_module', ':jpeg_app'
2 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | JPEG_APP
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | libjpeg_sample
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/libjpeg_module/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | libjpeg_app
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/cpp/libs/armeabi-v7a/libjpeg.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/cpp/libs/armeabi-v7a/libjpeg.a
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/libjpeg_module/libs/armeabi-v7a/libjpeg-yk.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/libjpeg_module/libs/armeabi-v7a/libjpeg-yk.so
--------------------------------------------------------------------------------
/app/src/main/cpp/libs/armeabi-v7a/libturbojpeg.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/cpp/libs/armeabi-v7a/libturbojpeg.a
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/libjpeg_module/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/LIBJPEG_SAMPLE/HEAD/jpeg_app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun May 19 16:42:00 GMT+08:00 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/yk/libjpeg_sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/jpeg_app/src/test/java/com/yk/libjpeg_sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yk/libjpeg_sample/libjpeg/JpegUtils.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample.libjpeg;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | public class JpegUtils {
6 | static {
7 | System.loadLibrary("jpeg-yk");
8 | }
9 |
10 | /**
11 | * A native method that is implemented by the 'native-lib' native library,
12 | * which is packaged with this application.
13 | */
14 | public native static void native_Compress(Bitmap bitmap, int q, String path);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/libjpeg_module/src/test/java/com/yk/libjpeg_sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/libjpeg_module/src/main/java/com/yk/libjpeg_sample/libjpeg/JpegUtils.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample.libjpeg;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | public class JpegUtils {
6 | static {
7 | System.loadLibrary("jpeg-yk");
8 | }
9 |
10 | /**
11 | * A native method that is implemented by the 'native-lib' native library,
12 | * which is packaged with this application.
13 | */
14 | public native static void native_Compress(Bitmap bitmap, int q, String path);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.4.1)
3 |
4 | add_library(
5 | jpeg-yk
6 | SHARED
7 | src/main/cpp/jpeg-yk.cpp)
8 |
9 | add_library(libjpeg STATIC IMPORTED)
10 |
11 | set_target_properties(libjpeg PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/cpp/libs/armeabi-v7a/libturbojpeg.a)
12 | #set_target_properties(libjpeg PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/cpp/libs/armeabi/libturbojpeg.a)
13 |
14 | #引入头文件 import
15 | include_directories(src/main/cpp/include)
16 |
17 | target_link_libraries(
18 | jpeg-yk
19 | libjpeg
20 | #jnigraphics是安卓NDK目录中直接有的
21 | jnigraphics
22 | log)
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2049m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/jpeg_app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/libjpeg_module/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/yk/libjpeg_sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.yk.libjpeg_sample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/libjpeg_module/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 | defaultConfig {
8 | minSdkVersion 18
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | ndk {
16 | abiFilters "armeabi-v7a"
17 | }
18 |
19 | }
20 |
21 | sourceSets {
22 | main {
23 | jniLibs.srcDirs = ['libs']
24 | }
25 | }
26 |
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 |
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/jpeg_app/src/androidTest/java/com/yk/libjpeg_sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.yk.libjpeg_sample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/libjpeg_module/src/androidTest/java/com/yk/libjpeg_sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.yk.libjpeg_app.test", 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 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/jpeg_app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.ykun.libjpeg_sample"
7 | minSdkVersion 18
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 |
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 | implementation 'com.android.support:appcompat-v7:28.0.0'
26 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
27 | testImplementation 'junit:junit:4.12'
28 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
29 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
30 |
31 | // implementation project(':libjpeg_module')
32 | implementation 'com.github.yangkun19921001:LIBJPEG_SAMPLE:v1.0.1'
33 | }
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
26 |
27 |
32 |
33 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
26 |
27 |
32 |
33 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.yk.libjpeg_sample"
7 | minSdkVersion 18
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | externalNativeBuild {
13 | cmake {
14 | cppFlags ""
15 | abiFilters 'armeabi-v7a'
16 | //指定android的编译器
17 | arguments '-DANDROID_TOOLCHAIN=clang'
18 | }
19 | }
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | externalNativeBuild {
28 | cmake {
29 | path "CMakeLists.txt"
30 | }
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation fileTree(dir: 'libs', include: ['*.jar'])
36 | implementation 'com.android.support:appcompat-v7:28.0.0'
37 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
38 | testImplementation 'junit:junit:4.12'
39 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
40 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
41 | }
42 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/java/com/ykun/libjpeg_sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ykun.libjpeg_sample;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Bundle;
6 | import android.os.Environment;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.Toast;
11 |
12 | import com.yk.libjpeg_sample.libjpeg.JpegUtils;
13 |
14 | import java.io.File;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 | Bitmap inputBitmap = null;
18 | private ImageView mNextImg;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | }
25 |
26 |
27 | public void click(View view) {
28 | File input = new File(Environment.getExternalStorageDirectory(), "/girl.jpg");
29 | ImageView preImg = findViewById(R.id.pre);
30 | mNextImg = findViewById(R.id.next);
31 | inputBitmap = BitmapFactory.decodeFile(input.getAbsolutePath());
32 | preImg.setImageBitmap(inputBitmap);
33 | JpegUtils.native_Compress(inputBitmap, 10, Environment.getExternalStorageDirectory() + "/girl4.jpg");
34 | Toast.makeText(this, "执行完成", Toast.LENGTH_SHORT).show();
35 | String filePath = Environment.getExternalStorageDirectory() + "/girl4.jpg";
36 | mNextImg.setImageBitmap(BitmapFactory.decodeFile(filePath));
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yk/libjpeg_sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yk.libjpeg_sample;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Bundle;
6 | import android.os.Environment;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.Toast;
11 |
12 | import com.yk.libjpeg_sample.libjpeg.JpegUtils;
13 |
14 | import java.io.File;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 |
18 | // Used to load the 'native-lib' library on application startup.
19 |
20 | Bitmap inputBitmap = null;
21 | private ImageView mNextImg;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | // Example of a call to a native method
29 | }
30 |
31 |
32 |
33 | public void click(View view) {
34 | File input = new File(Environment.getExternalStorageDirectory(), "/girl.jpg");
35 | ImageView preImg = findViewById(R.id.pre);
36 | mNextImg = findViewById(R.id.next);
37 | inputBitmap = BitmapFactory.decodeFile(input.getAbsolutePath());
38 | preImg.setImageBitmap(inputBitmap);
39 | JpegUtils .native_Compress(inputBitmap, 10, Environment.getExternalStorageDirectory() + "/girl4.jpg");
40 | Toast.makeText(this, "执行完成", Toast.LENGTH_SHORT).show();
41 | String filePath = Environment.getExternalStorageDirectory() + "/girl4.jpg";
42 | mNextImg.setImageBitmap(BitmapFactory.decodeFile(filePath));
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/cpp/include/jconfig.h:
--------------------------------------------------------------------------------
1 | /* Version ID for the JPEG library.
2 | * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
3 | */
4 | #define JPEG_LIB_VERSION 80
5 |
6 | /* libjpeg-turbo version */
7 | #define LIBJPEG_TURBO_VERSION 2.0.2
8 |
9 | /* libjpeg-turbo version in integer form */
10 | #define LIBJPEG_TURBO_VERSION_NUMBER 2000002
11 |
12 | /* Support arithmetic encoding */
13 | #define C_ARITH_CODING_SUPPORTED 1
14 |
15 | /* Support arithmetic decoding */
16 | #define D_ARITH_CODING_SUPPORTED 1
17 |
18 | /* Support in-memory source/destination managers */
19 | /* #undef MEM_SRCDST_SUPPORTED */
20 |
21 | /* Use accelerated SIMD routines. */
22 | #define WITH_SIMD 1
23 |
24 | /*
25 | * Define BITS_IN_JSAMPLE as either
26 | * 8 for 8-bit sample values (the usual setting)
27 | * 12 for 12-bit sample values
28 | * Only 8 and 12 are legal data precisions for lossy JPEG according to the
29 | * JPEG standard, and the IJG code does not support anything else!
30 | * We do not support run-time selection of data precision, sorry.
31 | */
32 |
33 | #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
34 |
35 | /* Define to 1 if you have the header file. */
36 | #define HAVE_LOCALE_H 1
37 |
38 | /* Define to 1 if you have the header file. */
39 | #define HAVE_STDDEF_H 1
40 |
41 | /* Define to 1 if you have the header file. */
42 | #define HAVE_STDLIB_H 1
43 |
44 | /* Define if you need to include to get size_t. */
45 | #define NEED_SYS_TYPES_H 1
46 |
47 | /* Define if you have BSD-like bzero and bcopy in rather than
48 | memset/memcpy in . */
49 | /* #undef NEED_BSD_STRINGS */
50 |
51 | /* Define to 1 if the system has the type `unsigned char'. */
52 | #define HAVE_UNSIGNED_CHAR 1
53 |
54 | /* Define to 1 if the system has the type `unsigned short'. */
55 | #define HAVE_UNSIGNED_SHORT 1
56 |
57 | /* Compiler does not support pointers to undefined structures. */
58 | /* #undef INCOMPLETE_TYPES_BROKEN */
59 |
60 | /* Define if your (broken) compiler shifts signed values as if they were
61 | unsigned. */
62 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */
63 |
64 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */
65 | #ifndef __CHAR_UNSIGNED__
66 | /* #undef __CHAR_UNSIGNED__ */
67 | #endif
68 |
69 | /* Define to empty if `const' does not conform to ANSI C. */
70 | /* #undef const */
71 |
72 | /* Define to `unsigned int' if does not define. */
73 | /* #undef size_t */
74 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/cpp/jpeg-yk.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "../include/jpeglib.h"
4 | #include
5 | #include
6 |
7 |
8 | void write_JPEG_file(uint8_t *data, int w, int h, jint q, const char *path) {
9 | // 3.1、创建jpeg压缩对象
10 | jpeg_compress_struct jcs;
11 | //错误回调
12 | jpeg_error_mgr error;
13 | jcs.err = jpeg_std_error(&error);
14 | //创建压缩对象
15 | jpeg_create_compress(&jcs);
16 | // 3.2、指定存储文件 write binary
17 | FILE *f = fopen(path, "wb");
18 | jpeg_stdio_dest(&jcs, f);
19 | // 3.3、设置压缩参数
20 | jcs.image_width = w;
21 | jcs.image_height = h;
22 | //bgr
23 | jcs.input_components = 3;
24 | jcs.in_color_space = JCS_RGB;
25 | jpeg_set_defaults(&jcs);
26 | //开启哈夫曼功能
27 | jcs.optimize_coding = true;
28 | jpeg_set_quality(&jcs, q, 1);
29 | // 3.4、开始压缩
30 | jpeg_start_compress(&jcs, 1);
31 | // 3.5、循环写入每一行数据
32 | int row_stride = w * 3;//一行的字节数
33 | JSAMPROW row[1];
34 | while (jcs.next_scanline < jcs.image_height) {
35 | //取一行数据
36 | uint8_t *pixels = data + jcs.next_scanline * row_stride;
37 | row[0] = pixels;
38 | jpeg_write_scanlines(&jcs, row, 1);
39 | }
40 | // 3.6、压缩完成
41 | jpeg_finish_compress(&jcs);
42 | // 3.7、释放jpeg对象
43 | fclose(f);
44 | jpeg_destroy_compress(&jcs);
45 | }
46 |
47 |
48 | extern "C"
49 | JNIEXPORT void JNICALL
50 | Java_com_yk_libjpeg_1sample_libjpeg_JpegUtils_native_1Compress__Landroid_graphics_Bitmap_2ILjava_lang_String_2(
51 | JNIEnv *env, jclass type, jobject bitmap, jint q, jstring path_) {
52 | const char *path = env->GetStringUTFChars(path_, 0);
53 | //从bitmap获取argb数据
54 | AndroidBitmapInfo info;//info=new 对象();
55 | //获取里面的信息
56 | AndroidBitmap_getInfo(env, bitmap, &info);// void method(list)
57 | //得到图片中的像素信息
58 | uint8_t *pixels;//uint8_t char java byte *pixels可以当byte[]
59 | AndroidBitmap_lockPixels(env, bitmap, (void **) &pixels);
60 | //jpeg argb中去掉他的a ===>rgb
61 | int w = info.width;
62 | int h = info.height;
63 | int color;
64 | //开一块内存用来存入rgb信息
65 | uint8_t *data = (uint8_t *) malloc(w * h * 3);//data中可以存放图片的所有内容
66 | uint8_t *temp = data;
67 | uint8_t r, g, b;//byte
68 | //循环取图片的每一个像素
69 | for (int i = 0; i < h; i++) {
70 | for (int j = 0; j < w; j++) {
71 | color = *(int *) pixels;//0-3字节 color4 个字节 一个点
72 | //取出rgb
73 | r = (color >> 16) & 0xFF;// #00rrggbb 16 0000rr 8 00rrgg
74 | g = (color >> 8) & 0xFF;
75 | b = color & 0xFF;
76 | //存放,以前的主流格式jpeg bgr
77 | *data = b;
78 | *(data + 1) = g;
79 | *(data + 2) = r;
80 | data += 3;
81 | //指针跳过4个字节
82 | pixels += 4;
83 | }
84 | }
85 | //把得到的新的图片的信息存入一个新文件 中
86 | write_JPEG_file(temp, w, h, q, path);
87 |
88 | //释放内存
89 | free(temp);
90 | AndroidBitmap_unlockPixels(env, bitmap);
91 | env->ReleaseStringUTFChars(path_, path);
92 | }
--------------------------------------------------------------------------------
/jpeg_build.sh:
--------------------------------------------------------------------------------
1 | # lib-name
2 | MY_LIBS_NAME=libjpeg-turbo_2.0.2
3 | # 源码目录
4 | MY_SOURCE_DIR=/home/yangkun/libjpeg-turbo-2.0.2
5 | MY_BUILD_DIR=yangkun
6 |
7 | # android-cmake
8 | CMAKE_PATH=/opt/cmake-3.14.4/bin
9 |
10 | export PATH=${CMAKE_PATH}/bin:$PATH
11 |
12 | NDK_PATH=/home/yangkun//android-ndk-r17c
13 | BUILD_PLATFORM=linux-x86_64
14 | TOOLCHAIN_VERSION=4.9
15 | ANDROID_VERSION=24
16 |
17 | ANDROID_ARMV5_CFLAGS="-march=armv5te"
18 | ANDROID_ARMV7_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon" # -mfpu=vfpv3-d16 -fexceptions -frtti
19 | ANDROID_ARMV8_CFLAGS="-march=armv8-a" # -mfloat-abi=softfp -mfpu=neon -fexceptions -frtti
20 | ANDROID_X86_CFLAGS="-march=i386 -mtune=intel -mssse3 -mfpmath=sse -m32"
21 | ANDROID_X86_64_CFLAGS="-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel"
22 |
23 | # params($1:arch,$2:arch_abi,$3:host,$4:compiler,$5:cflags,$6:processor)
24 | build_bin() {
25 |
26 | echo "-------------------star build $2-------------------------"
27 |
28 | ARCH=$1 # arm arm64 x86 x86_64
29 | ANDROID_ARCH_ABI=$2 # armeabi armeabi-v7a x86 mips
30 | # 最终编译的安装目录
31 | PREFIX=$(pwd)/dist/${MY_LIBS_NAME}/${ANDROID_ARCH_ABI}/
32 | HOST=$3
33 | COMPILER=$4
34 | PROCESSOR=$6
35 | SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-${ARCH}
36 | CFALGS="$5"
37 | TOOLCHAIN=${NDK_PATH}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
38 |
39 | # build 中间件
40 | BUILD_DIR=./${MY_BUILD_DIR}/${ANDROID_ARCH_ABI}
41 |
42 | export CFLAGS="$5 -Os -D__ANDROID_API__=${ANDROID_VERSION} --sysroot=${SYSROOT} \
43 | -isystem ${NDK_PATH}/sysroot/usr/include \
44 | -isystem ${NDK_PATH}/sysroot/usr/include/${HOST} "
45 | export LDFLAGS=-pie
46 |
47 | echo "path==>$PATH"
48 | echo "build_dir==>$BUILD_DIR"
49 | echo "ARCH==>$ARCH"
50 | echo "ANDROID_ARCH_ABI==>$ANDROID_ARCH_ABI"
51 | echo "HOST==>$HOST"
52 | echo "CFALGS==>$CFALGS"
53 | echo "COMPILER==>$COMPILER-gcc"
54 | echo "PROCESSOR==>$PROCESSOR"
55 |
56 | mkdir -p ${BUILD_DIR} #创建当前arch_abi的编译目录,比如:binary/armeabi-v7a
57 | cd ${BUILD_DIR} #此处 进了当前arch_abi的2级编译目录
58 |
59 | #运行时创建临时编译链文件toolchain.cmake
60 | cat >toolchain.cmake << EOF
61 | set(CMAKE_SYSTEM_NAME Linux)
62 | set(CMAKE_SYSTEM_PROCESSOR $6)
63 | set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${COMPILER}-gcc)
64 | set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/${COMPILER})
65 | EOF
66 |
67 | cmake -G"Unix Makefiles" \
68 | -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
69 | -DCMAKE_POSITION_INDEPENDENT_CODE=1 \
70 | -DCMAKE_INSTALL_PREFIX=${PREFIX} \
71 | -DWITH_JPEG8=1 \
72 | ${MY_SOURCE_DIR}
73 |
74 | make clean
75 | make
76 | make install
77 |
78 | #从当前arch_abi编译目录跳出,对应上面的cd ${BUILD_DIR},以便function多次执行
79 | cd ../../
80 |
81 | echo "-------------------$2 build end-------------------------"
82 | }
83 |
84 | # build armeabi
85 | build_bin arm armeabi arm-linux-androideabi arm-linux-androideabi "$ANDROID_ARMV5_CFLAGS" arm
86 |
87 | #build armeabi-v7a
88 | build_bin arm armeabi-v7a arm-linux-androideabi arm-linux-androideabi "$ANDROID_ARMV7_CFLAGS" arm
89 |
90 | #build arm64-v8a
91 | build_bin arm64 arm64-v8a aarch64-linux-android aarch64-linux-android "$ANDROID_ARMV8_CFLAGS" aarch64
92 |
93 | #build x86
94 | build_bin x86 x86 x86 i686-linux-android "$ANDROID_X86_CFLAGS" i386
95 |
96 | #build x86_64
97 | build_bin x86_64 x86_64 x86_64 x86_64-linux-android "$ANDROID_X86_64_CFLAGS" x86_64
98 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/jpeg_app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## [或者更多信息请移步我的博客](https://juejin.im/post/5ce15d0ce51d45106e5e6dac)
2 | ## 使用方式
3 |
4 | 1. 在 project/build.gradle 上添加以下代码
5 |
6 | ```java
7 | allprojects {
8 | repositories {
9 | ...
10 | maven { url 'https://jitpack.io' }
11 | }
12 | }
13 | ```
14 |
15 |
16 |
17 | 2. 在 app/build.gradle 添加依赖
18 |
19 | ```java
20 | dependencies {
21 | implementation 'com.github.yangkun19921001:LIBJPEG_SAMPLE:v1.0.1'
22 | }
23 | ```
24 |
25 |
26 |
27 | 3. 压缩使用
28 |
29 | ```java
30 | //bitmap : 需要压缩的 bitmap
31 | //q : 压缩质量 建议 30 - 50
32 | //outputFilePath: 压缩之后存储的图片地址
33 | JpegUtils.native_Compress(Bitmap bitmap,int q,String outputFilePath);
34 | ```
35 |
36 |
37 |
38 | ## JEPG 是什么?
39 |
40 | 相信有一部分使用 iPhone 手机用微信发送图片的时候,明明图片大小只有 1M ,但清晰度比 Android 手机 5 M 图片大小的还要清晰,那么这是为什么呢 ?。
41 |
42 | 当时谷歌开发 Android 的时候,考虑了大部分手机的配置并没有那么高,所以对图片处理使用的是 Skia。当然这个库的底层还是用的 jpeg 图片压缩处理。但是为了能够适配低端的手机(这里的低端是指以前的硬件配置不高的手机,CPU 和内存在手机上都非常吃紧,性能差),由于哈夫曼算法比较吃 CPU 并且编解码慢,被迫用了其他的算法。所以 Skia 在进行图片处理在低版本中并没有开启哈弗曼算法。
43 |
44 | 那么,JEPG 到底是什么?JEPG (全称是 Joint Photographic Experts Group) 是一种常见的一种图像格式,为什么我在这里会提到 JEPG 呢?是因为开源了一个 C/C++ 库底层是基于哈夫曼算法对图片的压缩 (libjpeg),下面我们就来着重了解下 libjpeg 这个库
45 |
46 | ### libjpeg 简介
47 |
48 | libjpeg-turbo 是一个 JPEG 图像编解码器,它使用 SIMD 指令(MMX,SSE2,AVX2,NEON,AltiVec)来加速 x86,x86-64,ARM 和 PowerPC 系统上的基线 JPEG 压缩和解压缩,以及渐进式JPEG 压缩 x86 和 x86-64 系统。在这样的系统上,libjpeg-turbo 的速度通常是 libjpeg 的 2 - 6 倍,其他条件相同。在其他类型的系统上,凭借其高度优化的霍夫曼编码例程,libjpeg-turbo 仍然可以大大超过 libjpeg。在许多情况下,libjpeg-turbo 的性能可与专有的高速 JPEG 编解码器相媲美。 libjpeg-turbo 实现了传统的 libjpeg API 以及功能较弱但更直接的 TurboJPEG API 。 libjpeg-turbo 还具有色彩空间扩展,允许它从/解压缩到32位和大端像素缓冲区(RGBX,XBGR等),以及功能齐全的 Java 接口。 libjpeg-turbo 最初基于 libjpeg / SIMD,这是由 Miyasaka Masaru 开发的 libjpeg v6b 的 MMX 加速衍生物。 TigerVNC 和 VirtualGL 项目在 2009 年对编解码器进行了大量增强,并且在2010年初,libjpeg-turbo 分拆成一个独立项目,目标是为更广泛的用户提供高速 JPEG压缩/解压缩技术。开发人员。
49 |
50 | 现在我们大概了解到了 libjpeg 是一个对图像编解码库,现在我们需要准备环境去编译 libjpeg。
51 |
52 | ## 编译准备工作
53 |
54 | **系统:** [Ubuntu 18.04]() [也可以使用我下载好的 提取码:biyt](https://pan.baidu.com/s/1PkcNn2Oh_fp698zdCuuyow)
55 |
56 | **libjpeg:** [libjepg 2.0.2](https://github.com/libjpeg-turbo/libjpeg-turbo/archive/2.0.2.tar.gz)
57 |
58 | **cmake**: [cmake-3.14.4-Linux-x86_64.tar.gz](https://github.com/Kitware/CMake/releases/download/v3.14.4/cmake-3.14.4.tar.gz)
59 |
60 | **ndk:** [android-ndk-r17c](https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip)
61 |
62 | **开始发车准备编译**
63 |
64 | 1. ubuntu 中下载 [libjpeg]()
65 |
66 | 1. wget https://github.com/libjpeg-turbo/libjpeg-turbo/archive/2.0.2.tar.gz
67 |
68 | 2. 解压 tar xvf 2.0.2.tar.gz
69 |
70 | 3. [编译参考])()
71 |
72 |
73 |
74 | 2. ubuntu 中安装 cmake
75 |
76 | 1. 删除原来的 apt-get autoremove cmake
77 |
78 | 2. wget https://github.com/Kitware/CMake/releases/download/v3.14.4/cmake-3.14.4.tar.gz
79 |
80 | 3. 解压 tar zxvf cmake-3.14.3.tar.gz
81 |
82 | 4. 创建软连接
83 |
84 | 1. mv cmake-3.14.3-Linux-x86_64 /opt/cmake-3.14.3
85 | 2. ln -sf /opt/cmake-3.14.3/bin/* /usr/bin/
86 |
87 | 输入 cmake -- version 如果有这样的显示代表安装成功
88 |
89 | 
90 |
91 |
92 |
93 | 3. 进入到 libjpeg 目录,生成 shell 脚本
94 |
95 | 1. vim build.sh 新建一个文件
96 |
97 | ```java
98 | # lib-name
99 | MY_LIBS_NAME=libjpeg-turbo_2.0.2
100 | # 源码目录
101 | MY_SOURCE_DIR=/home/yangkun/libjpeg-turbo-2.0.2
102 | MY_BUILD_DIR=yangkun
103 |
104 | # android-cmake
105 | CMAKE_PATH=/opt/cmake-3.14.4/bin
106 |
107 | export PATH=${CMAKE_PATH}/bin:$PATH
108 |
109 | NDK_PATH=/home/yangkun//android-ndk-r17c
110 | BUILD_PLATFORM=linux-x86_64
111 | TOOLCHAIN_VERSION=4.9
112 | ANDROID_VERSION=24
113 |
114 | ANDROID_ARMV5_CFLAGS="-march=armv5te"
115 | ANDROID_ARMV7_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon" # -mfpu=vfpv3-d16 -fexceptions -frtti
116 | ANDROID_ARMV8_CFLAGS="-march=armv8-a" # -mfloat-abi=softfp -mfpu=neon -fexceptions -frtti
117 | ANDROID_X86_CFLAGS="-march=i386 -mtune=intel -mssse3 -mfpmath=sse -m32"
118 | ANDROID_X86_64_CFLAGS="-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel"
119 |
120 | # params($1:arch,$2:arch_abi,$3:host,$4:compiler,$5:cflags,$6:processor)
121 | build_bin() {
122 |
123 | echo "-------------------star build $2-------------------------"
124 |
125 | ARCH=$1 # arm arm64 x86 x86_64
126 | ANDROID_ARCH_ABI=$2 # armeabi armeabi-v7a x86 mips
127 | # 最终编译的安装目录
128 | PREFIX=$(pwd)/dist/${MY_LIBS_NAME}/${ANDROID_ARCH_ABI}/
129 | HOST=$3
130 | COMPILER=$4
131 | PROCESSOR=$6
132 | SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-${ARCH}
133 | CFALGS="$5"
134 | TOOLCHAIN=${NDK_PATH}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
135 |
136 | # build 中间件
137 | BUILD_DIR=./${MY_BUILD_DIR}/${ANDROID_ARCH_ABI}
138 |
139 | export CFLAGS="$5 -Os -D__ANDROID_API__=${ANDROID_VERSION} --sysroot=${SYSROOT} \
140 | -isystem ${NDK_PATH}/sysroot/usr/include \
141 | -isystem ${NDK_PATH}/sysroot/usr/include/${HOST} "
142 | export LDFLAGS=-pie
143 |
144 | echo "path==>$PATH"
145 | echo "build_dir==>$BUILD_DIR"
146 | echo "ARCH==>$ARCH"
147 | echo "ANDROID_ARCH_ABI==>$ANDROID_ARCH_ABI"
148 | echo "HOST==>$HOST"
149 | echo "CFALGS==>$CFALGS"
150 | echo "COMPILER==>$COMPILER-gcc"
151 | echo "PROCESSOR==>$PROCESSOR"
152 |
153 | mkdir -p ${BUILD_DIR} #创建当前arch_abi的编译目录,比如:binary/armeabi-v7a
154 | cd ${BUILD_DIR} #此处 进了当前arch_abi的2级编译目录
155 |
156 | #运行时创建临时编译链文件toolchain.cmake
157 | cat >toolchain.cmake << EOF
158 | set(CMAKE_SYSTEM_NAME Linux)
159 | set(CMAKE_SYSTEM_PROCESSOR $6)
160 | set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${COMPILER}-gcc)
161 | set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/${COMPILER})
162 | EOF
163 |
164 | cmake -G"Unix Makefiles" \
165 | -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
166 | -DCMAKE_POSITION_INDEPENDENT_CODE=1 \
167 | -DCMAKE_INSTALL_PREFIX=${PREFIX} \
168 | -DWITH_JPEG8=1 \
169 | ${MY_SOURCE_DIR}
170 |
171 | make clean
172 | make
173 | make install
174 |
175 | #从当前arch_abi编译目录跳出,对应上面的cd ${BUILD_DIR},以便function多次执行
176 | cd ../../
177 |
178 | echo "-------------------$2 build end-------------------------"
179 | }
180 |
181 | # build armeabi
182 | build_bin arm armeabi arm-linux-androideabi arm-linux-androideabi "$ANDROID_ARMV5_CFLAGS" arm
183 |
184 | #build armeabi-v7a
185 | build_bin arm armeabi-v7a arm-linux-androideabi arm-linux-androideabi "$ANDROID_ARMV7_CFLAGS" arm
186 |
187 | #build arm64-v8a
188 | build_bin arm64 arm64-v8a aarch64-linux-android aarch64-linux-android "$ANDROID_ARMV8_CFLAGS" aarch64
189 |
190 | #build x86
191 | build_bin x86 x86 x86 i686-linux-android "$ANDROID_X86_CFLAGS" i386
192 |
193 | #build x86_64
194 | build_bin x86_64 x86_64 x86_64 x86_64-linux-android "$ANDROID_X86_64_CFLAGS" x86_64
195 | ```
196 |
197 | 2. 如果编译遇见 权限问题
198 |
199 | 
200 |
201 | 给它一个 可执行文件的权限 chmod +x build.sh
202 |
203 | 3. 继续执行
204 |
205 | 
206 |
207 | 4. 编译完成
208 |
209 | 
210 |
211 | 这里我们发现 已经有我们需要的 静态库 .a 和 动态库 .so
212 |
213 | 5. 在 AndroidStudio 中创建一个简单的项目 用于测试是否压缩成功
214 |
215 | 1. 结构目录
216 |
217 | 
218 |
219 | 标红的都是重要的文件,include 头文件和 libs/armeabi-v7a 是我们刚刚编译出来的文件
220 |
221 | 下面我们就来运行一下看看压缩效果
222 |
223 | 2. 压缩主要代码
224 |
225 | **jni 代码**
226 |
227 | ```c++
228 | #include
229 | #include
230 | #include "../include/jpeglib.h"
231 | #include
232 | #include
233 |
234 |
235 | void write_JPEG_file(uint8_t *data, int w, int h, jint q, const char *path) {
236 | // 3.1、创建jpeg压缩对象
237 | jpeg_compress_struct jcs;
238 | //错误回调
239 | jpeg_error_mgr error;
240 | jcs.err = jpeg_std_error(&error);
241 | //创建压缩对象
242 | jpeg_create_compress(&jcs);
243 | // 3.2、指定存储文件 write binary
244 | FILE *f = fopen(path, "wb");
245 | jpeg_stdio_dest(&jcs, f);
246 | // 3.3、设置压缩参数
247 | jcs.image_width = w;
248 | jcs.image_height = h;
249 | //bgr
250 | jcs.input_components = 3;
251 | jcs.in_color_space = JCS_RGB;
252 | jpeg_set_defaults(&jcs);
253 | //开启哈夫曼功能
254 | jcs.optimize_coding = true;
255 | jpeg_set_quality(&jcs, q, 1);
256 | // 3.4、开始压缩
257 | jpeg_start_compress(&jcs, 1);
258 | // 3.5、循环写入每一行数据
259 | int row_stride = w * 3;//一行的字节数
260 | JSAMPROW row[1];
261 | while (jcs.next_scanline < jcs.image_height) {
262 | //取一行数据
263 | uint8_t *pixels = data + jcs.next_scanline * row_stride;
264 | row[0] = pixels;
265 | jpeg_write_scanlines(&jcs, row, 1);
266 | }
267 | // 3.6、压缩完成
268 | jpeg_finish_compress(&jcs);
269 | // 3.7、释放jpeg对象
270 | fclose(f);
271 | jpeg_destroy_compress(&jcs);
272 | }
273 |
274 |
275 | extern "C"
276 | JNIEXPORT void JNICALL
277 | Java_com_yk_libjpeg_1sample_libjpeg_JpegUtils_native_1Compress__Landroid_graphics_Bitmap_2ILjava_lang_String_2(
278 | JNIEnv *env, jclass type, jobject bitmap, jint q, jstring path_) {
279 | const char *path = env->GetStringUTFChars(path_, 0);
280 | //从bitmap获取argb数据
281 | AndroidBitmapInfo info;//info=new 对象();
282 | //获取里面的信息
283 | AndroidBitmap_getInfo(env, bitmap, &info);// void method(list)
284 | //得到图片中的像素信息
285 | uint8_t *pixels;//uint8_t char java byte *pixels可以当byte[]
286 | AndroidBitmap_lockPixels(env, bitmap, (void **) &pixels);
287 | //jpeg argb中去掉他的a ===>rgb
288 | int w = info.width;
289 | int h = info.height;
290 | int color;
291 | //开一块内存用来存入rgb信息
292 | uint8_t *data = (uint8_t *) malloc(w * h * 3);//data中可以存放图片的所有内容
293 | uint8_t *temp = data;
294 | uint8_t r, g, b;//byte
295 | //循环取图片的每一个像素
296 | for (int i = 0; i < h; i++) {
297 | for (int j = 0; j < w; j++) {
298 | color = *(int *) pixels;//0-3字节 color4 个字节 一个点
299 | //取出rgb
300 | r = (color >> 16) & 0xFF;// #00rrggbb 16 0000rr 8 00rrgg
301 | g = (color >> 8) & 0xFF;
302 | b = color & 0xFF;
303 | //存放,以前的主流格式jpeg bgr
304 | *data = b;
305 | *(data + 1) = g;
306 | *(data + 2) = r;
307 | data += 3;
308 | //指针跳过4个字节
309 | pixels += 4;
310 | }
311 | }
312 | //把得到的新的图片的信息存入一个新文件 中
313 | write_JPEG_file(temp, w, h, q, path);
314 |
315 | //释放内存
316 | free(temp);
317 | AndroidBitmap_unlockPixels(env, bitmap);
318 | env->ReleaseStringUTFChars(path_, path);
319 | }
320 | ```
321 |
322 | **调用代码**
323 |
324 | ```java
325 | public class JpegUtils {
326 | static {
327 | System.loadLibrary("jpeg-yk");
328 | }
329 |
330 | /**
331 | * A native method that is implemented by the 'native-lib' native library,
332 | * which is packaged with this application.
333 | */
334 | public native static void native_Compress(Bitmap bitmap, int q, String path);
335 |
336 | }
337 | ```
338 |
339 | ## 效果
340 |
341 | 1. 开始压缩
342 |
343 | ```java
344 | public void click(View view) {
345 | File input = new File(Environment.getExternalStorageDirectory(), "/girl.jpg");
346 | ImageView preImg = findViewById(R.id.pre);
347 | mNextImg = findViewById(R.id.next);
348 | inputBitmap = BitmapFactory.decodeFile(input.getAbsolutePath());
349 | preImg.setImageBitmap(inputBitmap);
350 | JpegUtils .native_Compress(inputBitmap, 10, Environment.getExternalStorageDirectory() + "/girl4.jpg");
351 | Toast.makeText(this, "执行完成", Toast.LENGTH_SHORT).show();
352 | String filePath = Environment.getExternalStorageDirectory() + "/girl4.jpg";
353 | mNextImg.setImageBitmap(BitmapFactory.decodeFile(filePath));
354 | }
355 | ```
356 |
357 | 2. 动画效果
358 |
359 | 
360 |
361 | **压缩效果:** 压缩质量在 10 的时候用压缩出来的质量也还是挺好了,只有周围有点点模糊,但是建议压缩质量在 30 -50 之间。
362 |
363 | **压缩率:** 大约压缩后的图片大小是原图的缩小 6 倍的样子。
364 |
365 |
366 |
367 | ## 资料
368 |
369 | ### [更多代码信息请移步 GitHub]()
370 |
371 | ### [提供 libjpeg 编译脚本]()
372 |
373 | ### [libjpeg 编译的源码和动态/静态库 在 dist 目录 提取码:b0cs](https://pan.baidu.com/s/1WshwS4GjYl3bbzXD4RX_pg )
374 |
375 | ## 计划(也有可能由于工作任务,滞后)
376 |
377 |
378 | **图片优化计划出三篇文章**
379 | 1. libjpeg 编译及使用
380 | 2. 长图巨图优化
381 | 3. bitmap 内存管理 三级缓存
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
--------------------------------------------------------------------------------
/app/src/main/cpp/include/jerror.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jerror.h
3 | *
4 | * This file was part of the Independent JPEG Group's software:
5 | * Copyright (C) 1994-1997, Thomas G. Lane.
6 | * Modified 1997-2009 by Guido Vollbeding.
7 | * libjpeg-turbo Modifications:
8 | * Copyright (C) 2014, 2017, D. R. Commander.
9 | * For conditions of distribution and use, see the accompanying README.ijg
10 | * file.
11 | *
12 | * This file defines the error and message codes for the JPEG library.
13 | * Edit this file to add new codes, or to translate the message strings to
14 | * some other language.
15 | * A set of error-reporting macros are defined too. Some applications using
16 | * the JPEG library may wish to include this file to get the error codes
17 | * and/or the macros.
18 | */
19 |
20 | /*
21 | * To define the enum list of message codes, include this file without
22 | * defining macro JMESSAGE. To create a message string table, include it
23 | * again with a suitable JMESSAGE definition (see jerror.c for an example).
24 | */
25 | #ifndef JMESSAGE
26 | #ifndef JERROR_H
27 | /* First time through, define the enum list */
28 | #define JMAKE_ENUM_LIST
29 | #else
30 | /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
31 | #define JMESSAGE(code, string)
32 | #endif /* JERROR_H */
33 | #endif /* JMESSAGE */
34 |
35 | #ifdef JMAKE_ENUM_LIST
36 |
37 | typedef enum {
38 |
39 | #define JMESSAGE(code, string) code,
40 |
41 | #endif /* JMAKE_ENUM_LIST */
42 |
43 | JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
44 |
45 | /* For maintenance convenience, list is alphabetical by message code name */
46 | #if JPEG_LIB_VERSION < 70
47 | JMESSAGE(JERR_ARITH_NOTIMPL, "Sorry, arithmetic coding is not implemented")
48 | #endif
49 | JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
50 | JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
51 | JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
52 | JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
53 | #if JPEG_LIB_VERSION >= 70
54 | JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
55 | #endif
56 | JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
57 | JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
58 | #if JPEG_LIB_VERSION >= 70
59 | JMESSAGE(JERR_BAD_DROP_SAMPLING,
60 | "Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
61 | #endif
62 | JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
63 | JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
64 | JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
65 | JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
66 | JMESSAGE(JERR_BAD_LIB_VERSION,
67 | "Wrong JPEG library version: library is %d, caller expects %d")
68 | JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
69 | JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
70 | JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
71 | JMESSAGE(JERR_BAD_PROGRESSION,
72 | "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
73 | JMESSAGE(JERR_BAD_PROG_SCRIPT,
74 | "Invalid progressive parameters at scan script entry %d")
75 | JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
76 | JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
77 | JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
78 | JMESSAGE(JERR_BAD_STRUCT_SIZE,
79 | "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
80 | JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
81 | JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
82 | JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
83 | JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
84 | JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
85 | JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
86 | JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
87 | JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
88 | JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
89 | JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
90 | JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
91 | JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
92 | JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
93 | JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
94 | JMESSAGE(JERR_FILE_READ, "Input file read error")
95 | JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
96 | JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
97 | JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
98 | JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
99 | JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
100 | JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
101 | JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
102 | JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
103 | "Cannot transcode due to multiple use of quantization table %d")
104 | JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
105 | JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
106 | JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
107 | JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
108 | #if JPEG_LIB_VERSION >= 70
109 | JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
110 | #endif
111 | JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
112 | JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
113 | JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
114 | JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
115 | JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
116 | JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
117 | JMESSAGE(JERR_QUANT_COMPONENTS,
118 | "Cannot quantize more than %d color components")
119 | JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
120 | JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
121 | JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
122 | JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
123 | JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
124 | JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
125 | JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
126 | JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
127 | JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
128 | JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
129 | JMESSAGE(JERR_TFILE_WRITE,
130 | "Write failed on temporary file --- out of disk space?")
131 | JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
132 | JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
133 | JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
134 | JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
135 | JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
136 | JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
137 | JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT_SHORT)
138 | JMESSAGE(JMSG_VERSION, JVERSION)
139 | JMESSAGE(JTRC_16BIT_TABLES,
140 | "Caution: quantization tables are too coarse for baseline JPEG")
141 | JMESSAGE(JTRC_ADOBE,
142 | "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
143 | JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
144 | JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
145 | JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
146 | JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
147 | JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
148 | JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
149 | JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
150 | JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
151 | JMESSAGE(JTRC_EOI, "End Of Image")
152 | JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
153 | JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
154 | JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
155 | "Warning: thumbnail image size does not match data length %u")
156 | JMESSAGE(JTRC_JFIF_EXTENSION, "JFIF extension marker: type 0x%02x, length %u")
157 | JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
158 | JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
159 | JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
160 | JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
161 | JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
162 | JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
163 | JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
164 | JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
165 | JMESSAGE(JTRC_RST, "RST%d")
166 | JMESSAGE(JTRC_SMOOTH_NOTIMPL,
167 | "Smoothing not supported with nonstandard sampling ratios")
168 | JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
169 | JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
170 | JMESSAGE(JTRC_SOI, "Start of Image")
171 | JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
172 | JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
173 | JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
174 | JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
175 | JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
176 | JMESSAGE(JTRC_THUMB_JPEG,
177 | "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
178 | JMESSAGE(JTRC_THUMB_PALETTE,
179 | "JFIF extension marker: palette thumbnail image, length %u")
180 | JMESSAGE(JTRC_THUMB_RGB,
181 | "JFIF extension marker: RGB thumbnail image, length %u")
182 | JMESSAGE(JTRC_UNKNOWN_IDS,
183 | "Unrecognized component IDs %d %d %d, assuming YCbCr")
184 | JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
185 | JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
186 | JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
187 | #if JPEG_LIB_VERSION >= 70
188 | JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
189 | #endif
190 | JMESSAGE(JWRN_BOGUS_PROGRESSION,
191 | "Inconsistent progression sequence for component %d coefficient %d")
192 | JMESSAGE(JWRN_EXTRANEOUS_DATA,
193 | "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
194 | JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
195 | JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
196 | JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
197 | JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
198 | JMESSAGE(JWRN_MUST_RESYNC,
199 | "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
200 | JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
201 | JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
202 | #if JPEG_LIB_VERSION < 70
203 | JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
204 | #if defined(C_ARITH_CODING_SUPPORTED) || defined(D_ARITH_CODING_SUPPORTED)
205 | JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
206 | JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
207 | #endif
208 | #endif
209 | JMESSAGE(JWRN_BOGUS_ICC, "Corrupt JPEG data: bad ICC marker")
210 |
211 | #ifdef JMAKE_ENUM_LIST
212 |
213 | JMSG_LASTMSGCODE
214 | } J_MESSAGE_CODE;
215 |
216 | #undef JMAKE_ENUM_LIST
217 | #endif /* JMAKE_ENUM_LIST */
218 |
219 | /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
220 | #undef JMESSAGE
221 |
222 |
223 | #ifndef JERROR_H
224 | #define JERROR_H
225 |
226 | /* Macros to simplify using the error and trace message stuff */
227 | /* The first parameter is either type of cinfo pointer */
228 |
229 | /* Fatal errors (print message and exit) */
230 | #define ERREXIT(cinfo, code) \
231 | ((cinfo)->err->msg_code = (code), \
232 | (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
233 | #define ERREXIT1(cinfo, code, p1) \
234 | ((cinfo)->err->msg_code = (code), \
235 | (cinfo)->err->msg_parm.i[0] = (p1), \
236 | (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
237 | #define ERREXIT2(cinfo, code, p1, p2) \
238 | ((cinfo)->err->msg_code = (code), \
239 | (cinfo)->err->msg_parm.i[0] = (p1), \
240 | (cinfo)->err->msg_parm.i[1] = (p2), \
241 | (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
242 | #define ERREXIT3(cinfo, code, p1, p2, p3) \
243 | ((cinfo)->err->msg_code = (code), \
244 | (cinfo)->err->msg_parm.i[0] = (p1), \
245 | (cinfo)->err->msg_parm.i[1] = (p2), \
246 | (cinfo)->err->msg_parm.i[2] = (p3), \
247 | (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
248 | #define ERREXIT4(cinfo, code, p1, p2, p3, p4) \
249 | ((cinfo)->err->msg_code = (code), \
250 | (cinfo)->err->msg_parm.i[0] = (p1), \
251 | (cinfo)->err->msg_parm.i[1] = (p2), \
252 | (cinfo)->err->msg_parm.i[2] = (p3), \
253 | (cinfo)->err->msg_parm.i[3] = (p4), \
254 | (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
255 | #define ERREXITS(cinfo, code, str) \
256 | ((cinfo)->err->msg_code = (code), \
257 | strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
258 | (*(cinfo)->err->error_exit) ((j_common_ptr)(cinfo)))
259 |
260 | #define MAKESTMT(stuff) do { stuff } while (0)
261 |
262 | /* Nonfatal errors (we can keep going, but the data is probably corrupt) */
263 | #define WARNMS(cinfo, code) \
264 | ((cinfo)->err->msg_code = (code), \
265 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), -1))
266 | #define WARNMS1(cinfo, code, p1) \
267 | ((cinfo)->err->msg_code = (code), \
268 | (cinfo)->err->msg_parm.i[0] = (p1), \
269 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), -1))
270 | #define WARNMS2(cinfo, code, p1, p2) \
271 | ((cinfo)->err->msg_code = (code), \
272 | (cinfo)->err->msg_parm.i[0] = (p1), \
273 | (cinfo)->err->msg_parm.i[1] = (p2), \
274 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), -1))
275 |
276 | /* Informational/debugging messages */
277 | #define TRACEMS(cinfo, lvl, code) \
278 | ((cinfo)->err->msg_code = (code), \
279 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
280 | #define TRACEMS1(cinfo, lvl, code, p1) \
281 | ((cinfo)->err->msg_code = (code), \
282 | (cinfo)->err->msg_parm.i[0] = (p1), \
283 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
284 | #define TRACEMS2(cinfo, lvl, code, p1, p2) \
285 | ((cinfo)->err->msg_code = (code), \
286 | (cinfo)->err->msg_parm.i[0] = (p1), \
287 | (cinfo)->err->msg_parm.i[1] = (p2), \
288 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
289 | #define TRACEMS3(cinfo, lvl, code, p1, p2, p3) \
290 | MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
291 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
292 | (cinfo)->err->msg_code = (code); \
293 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
294 | #define TRACEMS4(cinfo, lvl, code, p1, p2, p3, p4) \
295 | MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
296 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
297 | (cinfo)->err->msg_code = (code); \
298 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
299 | #define TRACEMS5(cinfo, lvl, code, p1, p2, p3, p4, p5) \
300 | MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
301 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
302 | _mp[4] = (p5); \
303 | (cinfo)->err->msg_code = (code); \
304 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
305 | #define TRACEMS8(cinfo, lvl, code, p1, p2, p3, p4, p5, p6, p7, p8) \
306 | MAKESTMT(int *_mp = (cinfo)->err->msg_parm.i; \
307 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
308 | _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
309 | (cinfo)->err->msg_code = (code); \
310 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)); )
311 | #define TRACEMSS(cinfo, lvl, code, str) \
312 | ((cinfo)->err->msg_code = (code), \
313 | strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
314 | (*(cinfo)->err->emit_message) ((j_common_ptr)(cinfo), (lvl)))
315 |
316 | #endif /* JERROR_H */
317 |
--------------------------------------------------------------------------------
/app/src/main/cpp/include/jmorecfg.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jmorecfg.h
3 | *
4 | * This file was part of the Independent JPEG Group's software:
5 | * Copyright (C) 1991-1997, Thomas G. Lane.
6 | * Modified 1997-2009 by Guido Vollbeding.
7 | * libjpeg-turbo Modifications:
8 | * Copyright (C) 2009, 2011, 2014-2015, 2018, D. R. Commander.
9 | * For conditions of distribution and use, see the accompanying README.ijg
10 | * file.
11 | *
12 | * This file contains additional configuration options that customize the
13 | * JPEG software for special applications or support machine-dependent
14 | * optimizations. Most users will not need to touch this file.
15 | */
16 |
17 |
18 | /*
19 | * Maximum number of components (color channels) allowed in JPEG image.
20 | * To meet the letter of Rec. ITU-T T.81 | ISO/IEC 10918-1, set this to 255.
21 | * However, darn few applications need more than 4 channels (maybe 5 for CMYK +
22 | * alpha mask). We recommend 10 as a reasonable compromise; use 4 if you are
23 | * really short on memory. (Each allowed component costs a hundred or so
24 | * bytes of storage, whether actually used in an image or not.)
25 | */
26 |
27 | #define MAX_COMPONENTS 10 /* maximum number of image components */
28 |
29 |
30 | /*
31 | * Basic data types.
32 | * You may need to change these if you have a machine with unusual data
33 | * type sizes; for example, "char" not 8 bits, "short" not 16 bits,
34 | * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits,
35 | * but it had better be at least 16.
36 | */
37 |
38 | /* Representation of a single sample (pixel element value).
39 | * We frequently allocate large arrays of these, so it's important to keep
40 | * them small. But if you have memory to burn and access to char or short
41 | * arrays is very slow on your hardware, you might want to change these.
42 | */
43 |
44 | #if BITS_IN_JSAMPLE == 8
45 | /* JSAMPLE should be the smallest type that will hold the values 0..255.
46 | * You can use a signed char by having GETJSAMPLE mask it with 0xFF.
47 | */
48 |
49 | #ifdef HAVE_UNSIGNED_CHAR
50 |
51 | typedef unsigned char JSAMPLE;
52 | #define GETJSAMPLE(value) ((int)(value))
53 |
54 | #else /* not HAVE_UNSIGNED_CHAR */
55 |
56 | typedef char JSAMPLE;
57 | #ifdef __CHAR_UNSIGNED__
58 | #define GETJSAMPLE(value) ((int)(value))
59 | #else
60 | #define GETJSAMPLE(value) ((int)(value) & 0xFF)
61 | #endif /* __CHAR_UNSIGNED__ */
62 |
63 | #endif /* HAVE_UNSIGNED_CHAR */
64 |
65 | #define MAXJSAMPLE 255
66 | #define CENTERJSAMPLE 128
67 |
68 | #endif /* BITS_IN_JSAMPLE == 8 */
69 |
70 |
71 | #if BITS_IN_JSAMPLE == 12
72 | /* JSAMPLE should be the smallest type that will hold the values 0..4095.
73 | * On nearly all machines "short" will do nicely.
74 | */
75 |
76 | typedef short JSAMPLE;
77 | #define GETJSAMPLE(value) ((int)(value))
78 |
79 | #define MAXJSAMPLE 4095
80 | #define CENTERJSAMPLE 2048
81 |
82 | #endif /* BITS_IN_JSAMPLE == 12 */
83 |
84 |
85 | /* Representation of a DCT frequency coefficient.
86 | * This should be a signed value of at least 16 bits; "short" is usually OK.
87 | * Again, we allocate large arrays of these, but you can change to int
88 | * if you have memory to burn and "short" is really slow.
89 | */
90 |
91 | typedef short JCOEF;
92 |
93 |
94 | /* Compressed datastreams are represented as arrays of JOCTET.
95 | * These must be EXACTLY 8 bits wide, at least once they are written to
96 | * external storage. Note that when using the stdio data source/destination
97 | * managers, this is also the data type passed to fread/fwrite.
98 | */
99 |
100 | #ifdef HAVE_UNSIGNED_CHAR
101 |
102 | typedef unsigned char JOCTET;
103 | #define GETJOCTET(value) (value)
104 |
105 | #else /* not HAVE_UNSIGNED_CHAR */
106 |
107 | typedef char JOCTET;
108 | #ifdef __CHAR_UNSIGNED__
109 | #define GETJOCTET(value) (value)
110 | #else
111 | #define GETJOCTET(value) ((value) & 0xFF)
112 | #endif /* __CHAR_UNSIGNED__ */
113 |
114 | #endif /* HAVE_UNSIGNED_CHAR */
115 |
116 |
117 | /* These typedefs are used for various table entries and so forth.
118 | * They must be at least as wide as specified; but making them too big
119 | * won't cost a huge amount of memory, so we don't provide special
120 | * extraction code like we did for JSAMPLE. (In other words, these
121 | * typedefs live at a different point on the speed/space tradeoff curve.)
122 | */
123 |
124 | /* UINT8 must hold at least the values 0..255. */
125 |
126 | #ifdef HAVE_UNSIGNED_CHAR
127 | typedef unsigned char UINT8;
128 | #else /* not HAVE_UNSIGNED_CHAR */
129 | #ifdef __CHAR_UNSIGNED__
130 | typedef char UINT8;
131 | #else /* not __CHAR_UNSIGNED__ */
132 | typedef short UINT8;
133 | #endif /* __CHAR_UNSIGNED__ */
134 | #endif /* HAVE_UNSIGNED_CHAR */
135 |
136 | /* UINT16 must hold at least the values 0..65535. */
137 |
138 | #ifdef HAVE_UNSIGNED_SHORT
139 | typedef unsigned short UINT16;
140 | #else /* not HAVE_UNSIGNED_SHORT */
141 | typedef unsigned int UINT16;
142 | #endif /* HAVE_UNSIGNED_SHORT */
143 |
144 | /* INT16 must hold at least the values -32768..32767. */
145 |
146 | #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
147 | typedef short INT16;
148 | #endif
149 |
150 | /* INT32 must hold at least signed 32-bit values.
151 | *
152 | * NOTE: The INT32 typedef dates back to libjpeg v5 (1994.) Integers were
153 | * sometimes 16-bit back then (MS-DOS), which is why INT32 is typedef'd to
154 | * long. It also wasn't common (or at least as common) in 1994 for INT32 to be
155 | * defined by platform headers. Since then, however, INT32 is defined in
156 | * several other common places:
157 | *
158 | * Xmd.h (X11 header) typedefs INT32 to int on 64-bit platforms and long on
159 | * 32-bit platforms (i.e always a 32-bit signed type.)
160 | *
161 | * basetsd.h (Win32 header) typedefs INT32 to int (always a 32-bit signed type
162 | * on modern platforms.)
163 | *
164 | * qglobal.h (Qt header) typedefs INT32 to int (always a 32-bit signed type on
165 | * modern platforms.)
166 | *
167 | * This is a recipe for conflict, since "long" and "int" aren't always
168 | * compatible types. Since the definition of INT32 has technically been part
169 | * of the libjpeg API for more than 20 years, we can't remove it, but we do not
170 | * use it internally any longer. We instead define a separate type (JLONG)
171 | * for internal use, which ensures that internal behavior will always be the
172 | * same regardless of any external headers that may be included.
173 | */
174 |
175 | #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
176 | #ifndef _BASETSD_H_ /* Microsoft defines it in basetsd.h */
177 | #ifndef _BASETSD_H /* MinGW is slightly different */
178 | #ifndef QGLOBAL_H /* Qt defines it in qglobal.h */
179 | typedef long INT32;
180 | #endif
181 | #endif
182 | #endif
183 | #endif
184 |
185 | /* Datatype used for image dimensions. The JPEG standard only supports
186 | * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore
187 | * "unsigned int" is sufficient on all machines. However, if you need to
188 | * handle larger images and you don't mind deviating from the spec, you
189 | * can change this datatype. (Note that changing this datatype will
190 | * potentially require modifying the SIMD code. The x86-64 SIMD extensions,
191 | * in particular, assume a 32-bit JDIMENSION.)
192 | */
193 |
194 | typedef unsigned int JDIMENSION;
195 |
196 | #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
197 |
198 |
199 | /* These macros are used in all function definitions and extern declarations.
200 | * You could modify them if you need to change function linkage conventions;
201 | * in particular, you'll need to do that to make the library a Windows DLL.
202 | * Another application is to make all functions global for use with debuggers
203 | * or code profilers that require it.
204 | */
205 |
206 | /* a function called through method pointers: */
207 | #define METHODDEF(type) static type
208 | /* a function used only in its module: */
209 | #define LOCAL(type) static type
210 | /* a function referenced thru EXTERNs: */
211 | #define GLOBAL(type) type
212 | /* a reference to a GLOBAL function: */
213 | #define EXTERN(type) extern type
214 |
215 |
216 | /* Originally, this macro was used as a way of defining function prototypes
217 | * for both modern compilers as well as older compilers that did not support
218 | * prototype parameters. libjpeg-turbo has never supported these older,
219 | * non-ANSI compilers, but the macro is still included because there is some
220 | * software out there that uses it.
221 | */
222 |
223 | #define JMETHOD(type, methodname, arglist) type (*methodname) arglist
224 |
225 |
226 | /* libjpeg-turbo no longer supports platforms that have far symbols (MS-DOS),
227 | * but again, some software relies on this macro.
228 | */
229 |
230 | #undef FAR
231 | #define FAR
232 |
233 |
234 | /*
235 | * On a few systems, type boolean and/or its values FALSE, TRUE may appear
236 | * in standard header files. Or you may have conflicts with application-
237 | * specific header files that you want to include together with these files.
238 | * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
239 | */
240 |
241 | #ifndef HAVE_BOOLEAN
242 | typedef int boolean;
243 | #endif
244 | #ifndef FALSE /* in case these macros already exist */
245 | #define FALSE 0 /* values of boolean */
246 | #endif
247 | #ifndef TRUE
248 | #define TRUE 1
249 | #endif
250 |
251 |
252 | /*
253 | * The remaining options affect code selection within the JPEG library,
254 | * but they don't need to be visible to most applications using the library.
255 | * To minimize application namespace pollution, the symbols won't be
256 | * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.
257 | */
258 |
259 | #ifdef JPEG_INTERNALS
260 | #define JPEG_INTERNAL_OPTIONS
261 | #endif
262 |
263 | #ifdef JPEG_INTERNAL_OPTIONS
264 |
265 |
266 | /*
267 | * These defines indicate whether to include various optional functions.
268 | * Undefining some of these symbols will produce a smaller but less capable
269 | * library. Note that you can leave certain source files out of the
270 | * compilation/linking process if you've #undef'd the corresponding symbols.
271 | * (You may HAVE to do that if your compiler doesn't like null source files.)
272 | */
273 |
274 | /* Capability options common to encoder and decoder: */
275 |
276 | #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
277 | #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
278 | #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
279 |
280 | /* Encoder capability options: */
281 |
282 | #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
283 | #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
284 | #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
285 | /* Note: if you selected 12-bit data precision, it is dangerous to turn off
286 | * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
287 | * precision, so jchuff.c normally uses entropy optimization to compute
288 | * usable tables for higher precision. If you don't want to do optimization,
289 | * you'll have to supply different default Huffman tables.
290 | * The exact same statements apply for progressive JPEG: the default tables
291 | * don't work for progressive mode. (This may get fixed, however.)
292 | */
293 | #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
294 |
295 | /* Decoder capability options: */
296 |
297 | #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
298 | #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
299 | #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
300 | #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
301 | #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
302 | #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
303 | #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
304 | #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
305 | #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
306 |
307 | /* more capability options later, no doubt */
308 |
309 |
310 | /*
311 | * The RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros are a vestigial
312 | * feature of libjpeg. The idea was that, if an application developer needed
313 | * to compress from/decompress to a BGR/BGRX/RGBX/XBGR/XRGB buffer, they could
314 | * change these macros, rebuild libjpeg, and link their application statically
315 | * with it. In reality, few people ever did this, because there were some
316 | * severe restrictions involved (cjpeg and djpeg no longer worked properly,
317 | * compressing/decompressing RGB JPEGs no longer worked properly, and the color
318 | * quantizer wouldn't work with pixel sizes other than 3.) Furthermore, since
319 | * all of the O/S-supplied versions of libjpeg were built with the default
320 | * values of RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE, many applications
321 | * have come to regard these values as immutable.
322 | *
323 | * The libjpeg-turbo colorspace extensions provide a much cleaner way of
324 | * compressing from/decompressing to buffers with arbitrary component orders
325 | * and pixel sizes. Thus, we do not support changing the values of RGB_RED,
326 | * RGB_GREEN, RGB_BLUE, or RGB_PIXELSIZE. In addition to the restrictions
327 | * listed above, changing these values will also break the SIMD extensions and
328 | * the regression tests.
329 | */
330 |
331 | #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
332 | #define RGB_GREEN 1 /* Offset of Green */
333 | #define RGB_BLUE 2 /* Offset of Blue */
334 | #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
335 |
336 | #define JPEG_NUMCS 17
337 |
338 | #define EXT_RGB_RED 0
339 | #define EXT_RGB_GREEN 1
340 | #define EXT_RGB_BLUE 2
341 | #define EXT_RGB_PIXELSIZE 3
342 |
343 | #define EXT_RGBX_RED 0
344 | #define EXT_RGBX_GREEN 1
345 | #define EXT_RGBX_BLUE 2
346 | #define EXT_RGBX_PIXELSIZE 4
347 |
348 | #define EXT_BGR_RED 2
349 | #define EXT_BGR_GREEN 1
350 | #define EXT_BGR_BLUE 0
351 | #define EXT_BGR_PIXELSIZE 3
352 |
353 | #define EXT_BGRX_RED 2
354 | #define EXT_BGRX_GREEN 1
355 | #define EXT_BGRX_BLUE 0
356 | #define EXT_BGRX_PIXELSIZE 4
357 |
358 | #define EXT_XBGR_RED 3
359 | #define EXT_XBGR_GREEN 2
360 | #define EXT_XBGR_BLUE 1
361 | #define EXT_XBGR_PIXELSIZE 4
362 |
363 | #define EXT_XRGB_RED 1
364 | #define EXT_XRGB_GREEN 2
365 | #define EXT_XRGB_BLUE 3
366 | #define EXT_XRGB_PIXELSIZE 4
367 |
368 | static const int rgb_red[JPEG_NUMCS] = {
369 | -1, -1, RGB_RED, -1, -1, -1, EXT_RGB_RED, EXT_RGBX_RED,
370 | EXT_BGR_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED,
371 | EXT_RGBX_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED,
372 | -1
373 | };
374 |
375 | static const int rgb_green[JPEG_NUMCS] = {
376 | -1, -1, RGB_GREEN, -1, -1, -1, EXT_RGB_GREEN, EXT_RGBX_GREEN,
377 | EXT_BGR_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN,
378 | EXT_RGBX_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN,
379 | -1
380 | };
381 |
382 | static const int rgb_blue[JPEG_NUMCS] = {
383 | -1, -1, RGB_BLUE, -1, -1, -1, EXT_RGB_BLUE, EXT_RGBX_BLUE,
384 | EXT_BGR_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE,
385 | EXT_RGBX_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE,
386 | -1
387 | };
388 |
389 | static const int rgb_pixelsize[JPEG_NUMCS] = {
390 | -1, -1, RGB_PIXELSIZE, -1, -1, -1, EXT_RGB_PIXELSIZE, EXT_RGBX_PIXELSIZE,
391 | EXT_BGR_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE,
392 | EXT_RGBX_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE,
393 | -1
394 | };
395 |
396 | /* Definitions for speed-related optimizations. */
397 |
398 | /* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
399 | * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER
400 | * as short on such a machine. MULTIPLIER must be at least 16 bits wide.
401 | */
402 |
403 | #ifndef MULTIPLIER
404 | #ifndef WITH_SIMD
405 | #define MULTIPLIER int /* type for fastest integer multiply */
406 | #else
407 | #define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */
408 | #endif
409 | #endif
410 |
411 |
412 | /* FAST_FLOAT should be either float or double, whichever is done faster
413 | * by your compiler. (Note that this type is only used in the floating point
414 | * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
415 | */
416 |
417 | #ifndef FAST_FLOAT
418 | #define FAST_FLOAT float
419 | #endif
420 |
421 | #endif /* JPEG_INTERNAL_OPTIONS */
422 |
--------------------------------------------------------------------------------
/app/src/main/cpp/include/jpeglib.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jpeglib.h
3 | *
4 | * This file was part of the Independent JPEG Group's software:
5 | * Copyright (C) 1991-1998, Thomas G. Lane.
6 | * Modified 2002-2009 by Guido Vollbeding.
7 | * libjpeg-turbo Modifications:
8 | * Copyright (C) 2009-2011, 2013-2014, 2016-2017, D. R. Commander.
9 | * Copyright (C) 2015, Google, Inc.
10 | * For conditions of distribution and use, see the accompanying README.ijg
11 | * file.
12 | *
13 | * This file defines the application interface for the JPEG library.
14 | * Most applications using the library need only include this file,
15 | * and perhaps jerror.h if they want to know the exact error codes.
16 | */
17 |
18 | #ifndef JPEGLIB_H
19 | #define JPEGLIB_H
20 |
21 | /*
22 | * First we include the configuration files that record how this
23 | * installation of the JPEG library is set up. jconfig.h can be
24 | * generated automatically for many systems. jmorecfg.h contains
25 | * manual configuration options that most people need not worry about.
26 | */
27 |
28 | #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
29 | #include "jconfig.h" /* widely used configuration options */
30 | #endif
31 | #include "jmorecfg.h" /* seldom changed options */
32 |
33 |
34 | #ifdef __cplusplus
35 | #ifndef DONT_USE_EXTERN_C
36 | extern "C" {
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 | */
68 |
69 | typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples. */
70 | typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
71 | typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
72 |
73 | typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
74 | typedef JBLOCK *JBLOCKROW; /* pointer to one row of coefficient blocks */
75 | typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
76 | typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
77 |
78 | typedef JCOEF *JCOEFPTR; /* useful in a couple of places */
79 |
80 |
81 | /* Types for JPEG compression parameters and working tables. */
82 |
83 |
84 | /* DCT coefficient quantization tables. */
85 |
86 | typedef struct {
87 | /* This array gives the coefficient quantizers in natural array order
88 | * (not the zigzag order in which they are stored in a JPEG DQT marker).
89 | * CAUTION: IJG versions prior to v6a kept this array in zigzag order.
90 | */
91 | UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
92 | /* This field is used only during compression. It's initialized FALSE when
93 | * the table is created, and set TRUE when it's been output to the file.
94 | * You could suppress output of a table by setting this to TRUE.
95 | * (See jpeg_suppress_tables for an example.)
96 | */
97 | boolean sent_table; /* TRUE when table has been output */
98 | } JQUANT_TBL;
99 |
100 |
101 | /* Huffman coding tables. */
102 |
103 | typedef struct {
104 | /* These two fields directly represent the contents of a JPEG DHT marker */
105 | UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
106 | /* length k bits; bits[0] is unused */
107 | UINT8 huffval[256]; /* The symbols, in order of incr code length */
108 | /* This field is used only during compression. It's initialized FALSE when
109 | * the table is created, and set TRUE when it's been output to the file.
110 | * You could suppress output of a table by setting this to TRUE.
111 | * (See jpeg_suppress_tables for an example.)
112 | */
113 | boolean sent_table; /* TRUE when table has been output */
114 | } JHUFF_TBL;
115 |
116 |
117 | /* Basic info about one component (color channel). */
118 |
119 | typedef struct {
120 | /* These values are fixed over the whole image. */
121 | /* For compression, they must be supplied by parameter setup; */
122 | /* for decompression, they are read from the SOF marker. */
123 | int component_id; /* identifier for this component (0..255) */
124 | int component_index; /* its index in SOF or cinfo->comp_info[] */
125 | int h_samp_factor; /* horizontal sampling factor (1..4) */
126 | int v_samp_factor; /* vertical sampling factor (1..4) */
127 | int quant_tbl_no; /* quantization table selector (0..3) */
128 | /* These values may vary between scans. */
129 | /* For compression, they must be supplied by parameter setup; */
130 | /* for decompression, they are read from the SOS marker. */
131 | /* The decompressor output side may not use these variables. */
132 | int dc_tbl_no; /* DC entropy table selector (0..3) */
133 | int ac_tbl_no; /* AC entropy table selector (0..3) */
134 |
135 | /* Remaining fields should be treated as private by applications. */
136 |
137 | /* These values are computed during compression or decompression startup: */
138 | /* Component's size in DCT blocks.
139 | * Any dummy blocks added to complete an MCU are not counted; therefore
140 | * these values do not depend on whether a scan is interleaved or not.
141 | */
142 | JDIMENSION width_in_blocks;
143 | JDIMENSION height_in_blocks;
144 | /* Size of a DCT block in samples. Always DCTSIZE for compression.
145 | * For decompression this is the size of the output from one DCT block,
146 | * reflecting any scaling we choose to apply during the IDCT step.
147 | * Values from 1 to 16 are supported.
148 | * Note that different components may receive different IDCT scalings.
149 | */
150 | #if JPEG_LIB_VERSION >= 70
151 | int DCT_h_scaled_size;
152 | int DCT_v_scaled_size;
153 | #else
154 | int DCT_scaled_size;
155 | #endif
156 | /* The downsampled dimensions are the component's actual, unpadded number
157 | * of samples at the main buffer (preprocessing/compression interface), thus
158 | * downsampled_width = ceil(image_width * Hi/Hmax)
159 | * and similarly for height. For decompression, IDCT scaling is included, so
160 | * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE)
161 | */
162 | JDIMENSION downsampled_width; /* actual width in samples */
163 | JDIMENSION downsampled_height; /* actual height in samples */
164 | /* This flag is used only for decompression. In cases where some of the
165 | * components will be ignored (eg grayscale output from YCbCr image),
166 | * we can skip most computations for the unused components.
167 | */
168 | boolean component_needed; /* do we need the value of this component? */
169 |
170 | /* These values are computed before starting a scan of the component. */
171 | /* The decompressor output side may not use these variables. */
172 | int MCU_width; /* number of blocks per MCU, horizontally */
173 | int MCU_height; /* number of blocks per MCU, vertically */
174 | int MCU_blocks; /* MCU_width * MCU_height */
175 | int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */
176 | int last_col_width; /* # of non-dummy blocks across in last MCU */
177 | int last_row_height; /* # of non-dummy blocks down in last MCU */
178 |
179 | /* Saved quantization table for component; NULL if none yet saved.
180 | * See jdinput.c comments about the need for this information.
181 | * This field is currently used only for decompression.
182 | */
183 | JQUANT_TBL *quant_table;
184 |
185 | /* Private per-component storage for DCT or IDCT subsystem. */
186 | void *dct_table;
187 | } jpeg_component_info;
188 |
189 |
190 | /* The script for encoding a multiple-scan file is an array of these: */
191 |
192 | typedef struct {
193 | int comps_in_scan; /* number of components encoded in this scan */
194 | int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
195 | int Ss, Se; /* progressive JPEG spectral selection parms */
196 | int Ah, Al; /* progressive JPEG successive approx. parms */
197 | } jpeg_scan_info;
198 |
199 | /* The decompressor can save APPn and COM markers in a list of these: */
200 |
201 | typedef struct jpeg_marker_struct *jpeg_saved_marker_ptr;
202 |
203 | struct jpeg_marker_struct {
204 | jpeg_saved_marker_ptr next; /* next in list, or NULL */
205 | UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
206 | unsigned int original_length; /* # bytes of data in the file */
207 | unsigned int data_length; /* # bytes of data saved at data[] */
208 | JOCTET *data; /* the data contained in the marker */
209 | /* the marker length word is not counted in data_length or original_length */
210 | };
211 |
212 | /* Known color spaces. */
213 |
214 | #define JCS_EXTENSIONS 1
215 | #define JCS_ALPHA_EXTENSIONS 1
216 |
217 | typedef enum {
218 | JCS_UNKNOWN, /* error/unspecified */
219 | JCS_GRAYSCALE, /* monochrome */
220 | JCS_RGB, /* red/green/blue as specified by the RGB_RED,
221 | RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros */
222 | JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
223 | JCS_CMYK, /* C/M/Y/K */
224 | JCS_YCCK, /* Y/Cb/Cr/K */
225 | JCS_EXT_RGB, /* red/green/blue */
226 | JCS_EXT_RGBX, /* red/green/blue/x */
227 | JCS_EXT_BGR, /* blue/green/red */
228 | JCS_EXT_BGRX, /* blue/green/red/x */
229 | JCS_EXT_XBGR, /* x/blue/green/red */
230 | JCS_EXT_XRGB, /* x/red/green/blue */
231 | /* When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, JCS_EXT_XBGR,
232 | or JCS_EXT_XRGB during decompression, the X byte is undefined, and in
233 | order to ensure the best performance, libjpeg-turbo can set that byte to
234 | whatever value it wishes. Use the following colorspace constants to
235 | ensure that the X byte is set to 0xFF, so that it can be interpreted as an
236 | opaque alpha channel. */
237 | JCS_EXT_RGBA, /* red/green/blue/alpha */
238 | JCS_EXT_BGRA, /* blue/green/red/alpha */
239 | JCS_EXT_ABGR, /* alpha/blue/green/red */
240 | JCS_EXT_ARGB, /* alpha/red/green/blue */
241 | JCS_RGB565 /* 5-bit red/6-bit green/5-bit blue */
242 | } J_COLOR_SPACE;
243 |
244 | /* DCT/IDCT algorithm options. */
245 |
246 | typedef enum {
247 | JDCT_ISLOW, /* slow but accurate integer algorithm */
248 | JDCT_IFAST, /* faster, less accurate integer method */
249 | JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
250 | } J_DCT_METHOD;
251 |
252 | #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
253 | #define JDCT_DEFAULT JDCT_ISLOW
254 | #endif
255 | #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
256 | #define JDCT_FASTEST JDCT_IFAST
257 | #endif
258 |
259 | /* Dithering options for decompression. */
260 |
261 | typedef enum {
262 | JDITHER_NONE, /* no dithering */
263 | JDITHER_ORDERED, /* simple ordered dither */
264 | JDITHER_FS /* Floyd-Steinberg error diffusion dither */
265 | } J_DITHER_MODE;
266 |
267 |
268 | /* Common fields between JPEG compression and decompression master structs. */
269 |
270 | #define jpeg_common_fields \
271 | struct jpeg_error_mgr *err; /* Error handler module */ \
272 | struct jpeg_memory_mgr *mem; /* Memory manager module */ \
273 | struct jpeg_progress_mgr *progress; /* Progress monitor, or NULL if none */ \
274 | void *client_data; /* Available for use by application */ \
275 | boolean is_decompressor; /* So common code can tell which is which */ \
276 | int global_state /* For checking call sequence validity */
277 |
278 | /* Routines that are to be used by both halves of the library are declared
279 | * to receive a pointer to this structure. There are no actual instances of
280 | * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
281 | */
282 | struct jpeg_common_struct {
283 | jpeg_common_fields; /* Fields common to both master struct types */
284 | /* Additional fields follow in an actual jpeg_compress_struct or
285 | * jpeg_decompress_struct. All three structs must agree on these
286 | * initial fields! (This would be a lot cleaner in C++.)
287 | */
288 | };
289 |
290 | typedef struct jpeg_common_struct *j_common_ptr;
291 | typedef struct jpeg_compress_struct *j_compress_ptr;
292 | typedef struct jpeg_decompress_struct *j_decompress_ptr;
293 |
294 |
295 | /* Master record for a compression instance */
296 |
297 | struct jpeg_compress_struct {
298 | jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
299 |
300 | /* Destination for compressed data */
301 | struct jpeg_destination_mgr *dest;
302 |
303 | /* Description of source image --- these fields must be filled in by
304 | * outer application before starting compression. in_color_space must
305 | * be correct before you can even call jpeg_set_defaults().
306 | */
307 |
308 | JDIMENSION image_width; /* input image width */
309 | JDIMENSION image_height; /* input image height */
310 | int input_components; /* # of color components in input image */
311 | J_COLOR_SPACE in_color_space; /* colorspace of input image */
312 |
313 | double input_gamma; /* image gamma of input image */
314 |
315 | /* Compression parameters --- these fields must be set before calling
316 | * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to
317 | * initialize everything to reasonable defaults, then changing anything
318 | * the application specifically wants to change. That way you won't get
319 | * burnt when new parameters are added. Also note that there are several
320 | * helper routines to simplify changing parameters.
321 | */
322 |
323 | #if JPEG_LIB_VERSION >= 70
324 | unsigned int scale_num, scale_denom; /* fraction by which to scale image */
325 |
326 | JDIMENSION jpeg_width; /* scaled JPEG image width */
327 | JDIMENSION jpeg_height; /* scaled JPEG image height */
328 | /* Dimensions of actual JPEG image that will be written to file,
329 | * derived from input dimensions by scaling factors above.
330 | * These fields are computed by jpeg_start_compress().
331 | * You can also use jpeg_calc_jpeg_dimensions() to determine these values
332 | * in advance of calling jpeg_start_compress().
333 | */
334 | #endif
335 |
336 | int data_precision; /* bits of precision in image data */
337 |
338 | int num_components; /* # of color components in JPEG image */
339 | J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
340 |
341 | jpeg_component_info *comp_info;
342 | /* comp_info[i] describes component that appears i'th in SOF */
343 |
344 | JQUANT_TBL *quant_tbl_ptrs[NUM_QUANT_TBLS];
345 | #if JPEG_LIB_VERSION >= 70
346 | int q_scale_factor[NUM_QUANT_TBLS];
347 | #endif
348 | /* ptrs to coefficient quantization tables, or NULL if not defined,
349 | * and corresponding scale factors (percentage, initialized 100).
350 | */
351 |
352 | JHUFF_TBL *dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
353 | JHUFF_TBL *ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
354 | /* ptrs to Huffman coding tables, or NULL if not defined */
355 |
356 | UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
357 | UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
358 | UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
359 |
360 | int num_scans; /* # of entries in scan_info array */
361 | const jpeg_scan_info *scan_info; /* script for multi-scan file, or NULL */
362 | /* The default value of scan_info is NULL, which causes a single-scan
363 | * sequential JPEG file to be emitted. To create a multi-scan file,
364 | * set num_scans and scan_info to point to an array of scan definitions.
365 | */
366 |
367 | boolean raw_data_in; /* TRUE=caller supplies downsampled data */
368 | boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
369 | boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
370 | boolean CCIR601_sampling; /* TRUE=first samples are cosited */
371 | #if JPEG_LIB_VERSION >= 70
372 | boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */
373 | #endif
374 | int smoothing_factor; /* 1..100, or 0 for no input smoothing */
375 | J_DCT_METHOD dct_method; /* DCT algorithm selector */
376 |
377 | /* The restart interval can be specified in absolute MCUs by setting
378 | * restart_interval, or in MCU rows by setting restart_in_rows
379 | * (in which case the correct restart_interval will be figured
380 | * for each scan).
381 | */
382 | unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
383 | int restart_in_rows; /* if > 0, MCU rows per restart interval */
384 |
385 | /* Parameters controlling emission of special markers. */
386 |
387 | boolean write_JFIF_header; /* should a JFIF marker be written? */
388 | UINT8 JFIF_major_version; /* What to write for the JFIF version number */
389 | UINT8 JFIF_minor_version;
390 | /* These three values are not used by the JPEG code, merely copied */
391 | /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */
392 | /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */
393 | /* ratio is defined by X_density/Y_density even when density_unit=0. */
394 | UINT8 density_unit; /* JFIF code for pixel size units */
395 | UINT16 X_density; /* Horizontal pixel density */
396 | UINT16 Y_density; /* Vertical pixel density */
397 | boolean write_Adobe_marker; /* should an Adobe marker be written? */
398 |
399 | /* State variable: index of next scanline to be written to
400 | * jpeg_write_scanlines(). Application may use this to control its
401 | * processing loop, e.g., "while (next_scanline < image_height)".
402 | */
403 |
404 | JDIMENSION next_scanline; /* 0 .. image_height-1 */
405 |
406 | /* Remaining fields are known throughout compressor, but generally
407 | * should not be touched by a surrounding application.
408 | */
409 |
410 | /*
411 | * These fields are computed during compression startup
412 | */
413 | boolean progressive_mode; /* TRUE if scan script uses progressive mode */
414 | int max_h_samp_factor; /* largest h_samp_factor */
415 | int max_v_samp_factor; /* largest v_samp_factor */
416 |
417 | #if JPEG_LIB_VERSION >= 70
418 | int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */
419 | int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */
420 | #endif
421 |
422 | JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
423 | /* The coefficient controller receives data in units of MCU rows as defined
424 | * for fully interleaved scans (whether the JPEG file is interleaved or not).
425 | * There are v_samp_factor * DCTSIZE sample rows of each component in an
426 | * "iMCU" (interleaved MCU) row.
427 | */
428 |
429 | /*
430 | * These fields are valid during any one scan.
431 | * They describe the components and MCUs actually appearing in the scan.
432 | */
433 | int comps_in_scan; /* # of JPEG components in this scan */
434 | jpeg_component_info *cur_comp_info[MAX_COMPS_IN_SCAN];
435 | /* *cur_comp_info[i] describes component that appears i'th in SOS */
436 |
437 | JDIMENSION MCUs_per_row; /* # of MCUs across the image */
438 | JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
439 |
440 | int blocks_in_MCU; /* # of DCT blocks per MCU */
441 | int MCU_membership[C_MAX_BLOCKS_IN_MCU];
442 | /* MCU_membership[i] is index in cur_comp_info of component owning */
443 | /* i'th block in an MCU */
444 |
445 | int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
446 |
447 | #if JPEG_LIB_VERSION >= 80
448 | int block_size; /* the basic DCT block size: 1..16 */
449 | const int *natural_order; /* natural-order position array */
450 | int lim_Se; /* min( Se, DCTSIZE2-1 ) */
451 | #endif
452 |
453 | /*
454 | * Links to compression subobjects (methods and private variables of modules)
455 | */
456 | struct jpeg_comp_master *master;
457 | struct jpeg_c_main_controller *main;
458 | struct jpeg_c_prep_controller *prep;
459 | struct jpeg_c_coef_controller *coef;
460 | struct jpeg_marker_writer *marker;
461 | struct jpeg_color_converter *cconvert;
462 | struct jpeg_downsampler *downsample;
463 | struct jpeg_forward_dct *fdct;
464 | struct jpeg_entropy_encoder *entropy;
465 | jpeg_scan_info *script_space; /* workspace for jpeg_simple_progression */
466 | int script_space_size;
467 | };
468 |
469 |
470 | /* Master record for a decompression instance */
471 |
472 | struct jpeg_decompress_struct {
473 | jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
474 |
475 | /* Source of compressed data */
476 | struct jpeg_source_mgr *src;
477 |
478 | /* Basic description of image --- filled in by jpeg_read_header(). */
479 | /* Application may inspect these values to decide how to process image. */
480 |
481 | JDIMENSION image_width; /* nominal image width (from SOF marker) */
482 | JDIMENSION image_height; /* nominal image height */
483 | int num_components; /* # of color components in JPEG image */
484 | J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
485 |
486 | /* Decompression processing parameters --- these fields must be set before
487 | * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes
488 | * them to default values.
489 | */
490 |
491 | J_COLOR_SPACE out_color_space; /* colorspace for output */
492 |
493 | unsigned int scale_num, scale_denom; /* fraction by which to scale image */
494 |
495 | double output_gamma; /* image gamma wanted in output */
496 |
497 | boolean buffered_image; /* TRUE=multiple output passes */
498 | boolean raw_data_out; /* TRUE=downsampled data wanted */
499 |
500 | J_DCT_METHOD dct_method; /* IDCT algorithm selector */
501 | boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
502 | boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
503 |
504 | boolean quantize_colors; /* TRUE=colormapped output wanted */
505 | /* the following are ignored if not quantize_colors: */
506 | J_DITHER_MODE dither_mode; /* type of color dithering to use */
507 | boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
508 | int desired_number_of_colors; /* max # colors to use in created colormap */
509 | /* these are significant only in buffered-image mode: */
510 | boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
511 | boolean enable_external_quant;/* enable future use of external colormap */
512 | boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
513 |
514 | /* Description of actual output image that will be returned to application.
515 | * These fields are computed by jpeg_start_decompress().
516 | * You can also use jpeg_calc_output_dimensions() to determine these values
517 | * in advance of calling jpeg_start_decompress().
518 | */
519 |
520 | JDIMENSION output_width; /* scaled image width */
521 | JDIMENSION output_height; /* scaled image height */
522 | int out_color_components; /* # of color components in out_color_space */
523 | int output_components; /* # of color components returned */
524 | /* output_components is 1 (a colormap index) when quantizing colors;
525 | * otherwise it equals out_color_components.
526 | */
527 | int rec_outbuf_height; /* min recommended height of scanline buffer */
528 | /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
529 | * high, space and time will be wasted due to unnecessary data copying.
530 | * Usually rec_outbuf_height will be 1 or 2, at most 4.
531 | */
532 |
533 | /* When quantizing colors, the output colormap is described by these fields.
534 | * The application can supply a colormap by setting colormap non-NULL before
535 | * calling jpeg_start_decompress; otherwise a colormap is created during
536 | * jpeg_start_decompress or jpeg_start_output.
537 | * The map has out_color_components rows and actual_number_of_colors columns.
538 | */
539 | int actual_number_of_colors; /* number of entries in use */
540 | JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
541 |
542 | /* State variables: these variables indicate the progress of decompression.
543 | * The application may examine these but must not modify them.
544 | */
545 |
546 | /* Row index of next scanline to be read from jpeg_read_scanlines().
547 | * Application may use this to control its processing loop, e.g.,
548 | * "while (output_scanline < output_height)".
549 | */
550 | JDIMENSION output_scanline; /* 0 .. output_height-1 */
551 |
552 | /* Current input scan number and number of iMCU rows completed in scan.
553 | * These indicate the progress of the decompressor input side.
554 | */
555 | int input_scan_number; /* Number of SOS markers seen so far */
556 | JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
557 |
558 | /* The "output scan number" is the notional scan being displayed by the
559 | * output side. The decompressor will not allow output scan/row number
560 | * to get ahead of input scan/row, but it can fall arbitrarily far behind.
561 | */
562 | int output_scan_number; /* Nominal scan number being displayed */
563 | JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
564 |
565 | /* Current progression status. coef_bits[c][i] indicates the precision
566 | * with which component c's DCT coefficient i (in zigzag order) is known.
567 | * It is -1 when no data has yet been received, otherwise it is the point
568 | * transform (shift) value for the most recent scan of the coefficient
569 | * (thus, 0 at completion of the progression).
570 | * This pointer is NULL when reading a non-progressive file.
571 | */
572 | int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
573 |
574 | /* Internal JPEG parameters --- the application usually need not look at
575 | * these fields. Note that the decompressor output side may not use
576 | * any parameters that can change between scans.
577 | */
578 |
579 | /* Quantization and Huffman tables are carried forward across input
580 | * datastreams when processing abbreviated JPEG datastreams.
581 | */
582 |
583 | JQUANT_TBL *quant_tbl_ptrs[NUM_QUANT_TBLS];
584 | /* ptrs to coefficient quantization tables, or NULL if not defined */
585 |
586 | JHUFF_TBL *dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
587 | JHUFF_TBL *ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
588 | /* ptrs to Huffman coding tables, or NULL if not defined */
589 |
590 | /* These parameters are never carried across datastreams, since they
591 | * are given in SOF/SOS markers or defined to be reset by SOI.
592 | */
593 |
594 | int data_precision; /* bits of precision in image data */
595 |
596 | jpeg_component_info *comp_info;
597 | /* comp_info[i] describes component that appears i'th in SOF */
598 |
599 | #if JPEG_LIB_VERSION >= 80
600 | boolean is_baseline; /* TRUE if Baseline SOF0 encountered */
601 | #endif
602 | boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
603 | boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
604 |
605 | UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
606 | UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
607 | UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
608 |
609 | unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
610 |
611 | /* These fields record data obtained from optional markers recognized by
612 | * the JPEG library.
613 | */
614 | boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
615 | /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */
616 | UINT8 JFIF_major_version; /* JFIF version number */
617 | UINT8 JFIF_minor_version;
618 | UINT8 density_unit; /* JFIF code for pixel size units */
619 | UINT16 X_density; /* Horizontal pixel density */
620 | UINT16 Y_density; /* Vertical pixel density */
621 | boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
622 | UINT8 Adobe_transform; /* Color transform code from Adobe marker */
623 |
624 | boolean CCIR601_sampling; /* TRUE=first samples are cosited */
625 |
626 | /* Aside from the specific data retained from APPn markers known to the
627 | * library, the uninterpreted contents of any or all APPn and COM markers
628 | * can be saved in a list for examination by the application.
629 | */
630 | jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
631 |
632 | /* Remaining fields are known throughout decompressor, but generally
633 | * should not be touched by a surrounding application.
634 | */
635 |
636 | /*
637 | * These fields are computed during decompression startup
638 | */
639 | int max_h_samp_factor; /* largest h_samp_factor */
640 | int max_v_samp_factor; /* largest v_samp_factor */
641 |
642 | #if JPEG_LIB_VERSION >= 70
643 | int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */
644 | int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */
645 | #else
646 | int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
647 | #endif
648 |
649 | JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
650 | /* The coefficient controller's input and output progress is measured in
651 | * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows
652 | * in fully interleaved JPEG scans, but are used whether the scan is
653 | * interleaved or not. We define an iMCU row as v_samp_factor DCT block
654 | * rows of each component. Therefore, the IDCT output contains
655 | * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row.
656 | */
657 |
658 | JSAMPLE *sample_range_limit; /* table for fast range-limiting */
659 |
660 | /*
661 | * These fields are valid during any one scan.
662 | * They describe the components and MCUs actually appearing in the scan.
663 | * Note that the decompressor output side must not use these fields.
664 | */
665 | int comps_in_scan; /* # of JPEG components in this scan */
666 | jpeg_component_info *cur_comp_info[MAX_COMPS_IN_SCAN];
667 | /* *cur_comp_info[i] describes component that appears i'th in SOS */
668 |
669 | JDIMENSION MCUs_per_row; /* # of MCUs across the image */
670 | JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
671 |
672 | int blocks_in_MCU; /* # of DCT blocks per MCU */
673 | int MCU_membership[D_MAX_BLOCKS_IN_MCU];
674 | /* MCU_membership[i] is index in cur_comp_info of component owning */
675 | /* i'th block in an MCU */
676 |
677 | int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
678 |
679 | #if JPEG_LIB_VERSION >= 80
680 | /* These fields are derived from Se of first SOS marker.
681 | */
682 | int block_size; /* the basic DCT block size: 1..16 */
683 | const int *natural_order; /* natural-order position array for entropy decode */
684 | int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */
685 | #endif
686 |
687 | /* This field is shared between entropy decoder and marker parser.
688 | * It is either zero or the code of a JPEG marker that has been
689 | * read from the data source, but has not yet been processed.
690 | */
691 | int unread_marker;
692 |
693 | /*
694 | * Links to decompression subobjects (methods, private variables of modules)
695 | */
696 | struct jpeg_decomp_master *master;
697 | struct jpeg_d_main_controller *main;
698 | struct jpeg_d_coef_controller *coef;
699 | struct jpeg_d_post_controller *post;
700 | struct jpeg_input_controller *inputctl;
701 | struct jpeg_marker_reader *marker;
702 | struct jpeg_entropy_decoder *entropy;
703 | struct jpeg_inverse_dct *idct;
704 | struct jpeg_upsampler *upsample;
705 | struct jpeg_color_deconverter *cconvert;
706 | struct jpeg_color_quantizer *cquantize;
707 | };
708 |
709 |
710 | /* "Object" declarations for JPEG modules that may be supplied or called
711 | * directly by the surrounding application.
712 | * As with all objects in the JPEG library, these structs only define the
713 | * publicly visible methods and state variables of a module. Additional
714 | * private fields may exist after the public ones.
715 | */
716 |
717 |
718 | /* Error handler object */
719 |
720 | struct jpeg_error_mgr {
721 | /* Error exit handler: does not return to caller */
722 | void (*error_exit) (j_common_ptr cinfo);
723 | /* Conditionally emit a trace or warning message */
724 | void (*emit_message) (j_common_ptr cinfo, int msg_level);
725 | /* Routine that actually outputs a trace or error message */
726 | void (*output_message) (j_common_ptr cinfo);
727 | /* Format a message string for the most recent JPEG error or message */
728 | void (*format_message) (j_common_ptr cinfo, char *buffer);
729 | #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
730 | /* Reset error state variables at start of a new image */
731 | void (*reset_error_mgr) (j_common_ptr cinfo);
732 |
733 | /* The message ID code and any parameters are saved here.
734 | * A message can have one string parameter or up to 8 int parameters.
735 | */
736 | int msg_code;
737 | #define JMSG_STR_PARM_MAX 80
738 | union {
739 | int i[8];
740 | char s[JMSG_STR_PARM_MAX];
741 | } msg_parm;
742 |
743 | /* Standard state variables for error facility */
744 |
745 | int trace_level; /* max msg_level that will be displayed */
746 |
747 | /* For recoverable corrupt-data errors, we emit a warning message,
748 | * but keep going unless emit_message chooses to abort. emit_message
749 | * should count warnings in num_warnings. The surrounding application
750 | * can check for bad data by seeing if num_warnings is nonzero at the
751 | * end of processing.
752 | */
753 | long num_warnings; /* number of corrupt-data warnings */
754 |
755 | /* These fields point to the table(s) of error message strings.
756 | * An application can change the table pointer to switch to a different
757 | * message list (typically, to change the language in which errors are
758 | * reported). Some applications may wish to add additional error codes
759 | * that will be handled by the JPEG library error mechanism; the second
760 | * table pointer is used for this purpose.
761 | *
762 | * First table includes all errors generated by JPEG library itself.
763 | * Error code 0 is reserved for a "no such error string" message.
764 | */
765 | const char * const *jpeg_message_table; /* Library errors */
766 | int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
767 | /* Second table can be added by application (see cjpeg/djpeg for example).
768 | * It contains strings numbered first_addon_message..last_addon_message.
769 | */
770 | const char * const *addon_message_table; /* Non-library errors */
771 | int first_addon_message; /* code for first string in addon table */
772 | int last_addon_message; /* code for last string in addon table */
773 | };
774 |
775 |
776 | /* Progress monitor object */
777 |
778 | struct jpeg_progress_mgr {
779 | void (*progress_monitor) (j_common_ptr cinfo);
780 |
781 | long pass_counter; /* work units completed in this pass */
782 | long pass_limit; /* total number of work units in this pass */
783 | int completed_passes; /* passes completed so far */
784 | int total_passes; /* total number of passes expected */
785 | };
786 |
787 |
788 | /* Data destination object for compression */
789 |
790 | struct jpeg_destination_mgr {
791 | JOCTET *next_output_byte; /* => next byte to write in buffer */
792 | size_t free_in_buffer; /* # of byte spaces remaining in buffer */
793 |
794 | void (*init_destination) (j_compress_ptr cinfo);
795 | boolean (*empty_output_buffer) (j_compress_ptr cinfo);
796 | void (*term_destination) (j_compress_ptr cinfo);
797 | };
798 |
799 |
800 | /* Data source object for decompression */
801 |
802 | struct jpeg_source_mgr {
803 | const JOCTET *next_input_byte; /* => next byte to read from buffer */
804 | size_t bytes_in_buffer; /* # of bytes remaining in buffer */
805 |
806 | void (*init_source) (j_decompress_ptr cinfo);
807 | boolean (*fill_input_buffer) (j_decompress_ptr cinfo);
808 | void (*skip_input_data) (j_decompress_ptr cinfo, long num_bytes);
809 | boolean (*resync_to_restart) (j_decompress_ptr cinfo, int desired);
810 | void (*term_source) (j_decompress_ptr cinfo);
811 | };
812 |
813 |
814 | /* Memory manager object.
815 | * Allocates "small" objects (a few K total), "large" objects (tens of K),
816 | * and "really big" objects (virtual arrays with backing store if needed).
817 | * The memory manager does not allow individual objects to be freed; rather,
818 | * each created object is assigned to a pool, and whole pools can be freed
819 | * at once. This is faster and more convenient than remembering exactly what
820 | * to free, especially where malloc()/free() are not too speedy.
821 | * NB: alloc routines never return NULL. They exit to error_exit if not
822 | * successful.
823 | */
824 |
825 | #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
826 | #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
827 | #define JPOOL_NUMPOOLS 2
828 |
829 | typedef struct jvirt_sarray_control *jvirt_sarray_ptr;
830 | typedef struct jvirt_barray_control *jvirt_barray_ptr;
831 |
832 |
833 | struct jpeg_memory_mgr {
834 | /* Method pointers */
835 | void *(*alloc_small) (j_common_ptr cinfo, int pool_id, size_t sizeofobject);
836 | void *(*alloc_large) (j_common_ptr cinfo, int pool_id,
837 | size_t sizeofobject);
838 | JSAMPARRAY (*alloc_sarray) (j_common_ptr cinfo, int pool_id,
839 | JDIMENSION samplesperrow, JDIMENSION numrows);
840 | JBLOCKARRAY (*alloc_barray) (j_common_ptr cinfo, int pool_id,
841 | JDIMENSION blocksperrow, JDIMENSION numrows);
842 | jvirt_sarray_ptr (*request_virt_sarray) (j_common_ptr cinfo, int pool_id,
843 | boolean pre_zero,
844 | JDIMENSION samplesperrow,
845 | JDIMENSION numrows,
846 | JDIMENSION maxaccess);
847 | jvirt_barray_ptr (*request_virt_barray) (j_common_ptr cinfo, int pool_id,
848 | boolean pre_zero,
849 | JDIMENSION blocksperrow,
850 | JDIMENSION numrows,
851 | JDIMENSION maxaccess);
852 | void (*realize_virt_arrays) (j_common_ptr cinfo);
853 | JSAMPARRAY (*access_virt_sarray) (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
854 | JDIMENSION start_row, JDIMENSION num_rows,
855 | boolean writable);
856 | JBLOCKARRAY (*access_virt_barray) (j_common_ptr cinfo, jvirt_barray_ptr ptr,
857 | JDIMENSION start_row, JDIMENSION num_rows,
858 | boolean writable);
859 | void (*free_pool) (j_common_ptr cinfo, int pool_id);
860 | void (*self_destruct) (j_common_ptr cinfo);
861 |
862 | /* Limit on memory allocation for this JPEG object. (Note that this is
863 | * merely advisory, not a guaranteed maximum; it only affects the space
864 | * used for virtual-array buffers.) May be changed by outer application
865 | * after creating the JPEG object.
866 | */
867 | long max_memory_to_use;
868 |
869 | /* Maximum allocation request accepted by alloc_large. */
870 | long max_alloc_chunk;
871 | };
872 |
873 |
874 | /* Routine signature for application-supplied marker processing methods.
875 | * Need not pass marker code since it is stored in cinfo->unread_marker.
876 | */
877 | typedef boolean (*jpeg_marker_parser_method) (j_decompress_ptr cinfo);
878 |
879 |
880 | /* Originally, this macro was used as a way of defining function prototypes
881 | * for both modern compilers as well as older compilers that did not support
882 | * prototype parameters. libjpeg-turbo has never supported these older,
883 | * non-ANSI compilers, but the macro is still included because there is some
884 | * software out there that uses it.
885 | */
886 |
887 | #define JPP(arglist) arglist
888 |
889 |
890 | /* Default error-management setup */
891 | EXTERN(struct jpeg_error_mgr *) jpeg_std_error(struct jpeg_error_mgr *err);
892 |
893 | /* Initialization of JPEG compression objects.
894 | * jpeg_create_compress() and jpeg_create_decompress() are the exported
895 | * names that applications should call. These expand to calls on
896 | * jpeg_CreateCompress and jpeg_CreateDecompress with additional information
897 | * passed for version mismatch checking.
898 | * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx.
899 | */
900 | #define jpeg_create_compress(cinfo) \
901 | jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
902 | (size_t)sizeof(struct jpeg_compress_struct))
903 | #define jpeg_create_decompress(cinfo) \
904 | jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
905 | (size_t)sizeof(struct jpeg_decompress_struct))
906 | EXTERN(void) jpeg_CreateCompress(j_compress_ptr cinfo, int version,
907 | size_t structsize);
908 | EXTERN(void) jpeg_CreateDecompress(j_decompress_ptr cinfo, int version,
909 | size_t structsize);
910 | /* Destruction of JPEG compression objects */
911 | EXTERN(void) jpeg_destroy_compress(j_compress_ptr cinfo);
912 | EXTERN(void) jpeg_destroy_decompress(j_decompress_ptr cinfo);
913 |
914 | /* Standard data source and destination managers: stdio streams. */
915 | /* Caller is responsible for opening the file before and closing after. */
916 | EXTERN(void) jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile);
917 | EXTERN(void) jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile);
918 |
919 | #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
920 | /* Data source and destination managers: memory buffers. */
921 | EXTERN(void) jpeg_mem_dest(j_compress_ptr cinfo, unsigned char **outbuffer,
922 | unsigned long *outsize);
923 | EXTERN(void) jpeg_mem_src(j_decompress_ptr cinfo,
924 | const unsigned char *inbuffer, unsigned long insize);
925 | #endif
926 |
927 | /* Default parameter setup for compression */
928 | EXTERN(void) jpeg_set_defaults(j_compress_ptr cinfo);
929 | /* Compression parameter setup aids */
930 | EXTERN(void) jpeg_set_colorspace(j_compress_ptr cinfo,
931 | J_COLOR_SPACE colorspace);
932 | EXTERN(void) jpeg_default_colorspace(j_compress_ptr cinfo);
933 | EXTERN(void) jpeg_set_quality(j_compress_ptr cinfo, int quality,
934 | boolean force_baseline);
935 | EXTERN(void) jpeg_set_linear_quality(j_compress_ptr cinfo, int scale_factor,
936 | boolean force_baseline);
937 | #if JPEG_LIB_VERSION >= 70
938 | EXTERN(void) jpeg_default_qtables(j_compress_ptr cinfo,
939 | boolean force_baseline);
940 | #endif
941 | EXTERN(void) jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl,
942 | const unsigned int *basic_table,
943 | int scale_factor, boolean force_baseline);
944 | EXTERN(int) jpeg_quality_scaling(int quality);
945 | EXTERN(void) jpeg_simple_progression(j_compress_ptr cinfo);
946 | EXTERN(void) jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress);
947 | EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table(j_common_ptr cinfo);
948 | EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table(j_common_ptr cinfo);
949 |
950 | /* Main entry points for compression */
951 | EXTERN(void) jpeg_start_compress(j_compress_ptr cinfo,
952 | boolean write_all_tables);
953 | EXTERN(JDIMENSION) jpeg_write_scanlines(j_compress_ptr cinfo,
954 | JSAMPARRAY scanlines,
955 | JDIMENSION num_lines);
956 | EXTERN(void) jpeg_finish_compress(j_compress_ptr cinfo);
957 |
958 | #if JPEG_LIB_VERSION >= 70
959 | /* Precalculate JPEG dimensions for current compression parameters. */
960 | EXTERN(void) jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo);
961 | #endif
962 |
963 | /* Replaces jpeg_write_scanlines when writing raw downsampled data. */
964 | EXTERN(JDIMENSION) jpeg_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
965 | JDIMENSION num_lines);
966 |
967 | /* Write a special marker. See libjpeg.txt concerning safe usage. */
968 | EXTERN(void) jpeg_write_marker(j_compress_ptr cinfo, int marker,
969 | const JOCTET *dataptr, unsigned int datalen);
970 | /* Same, but piecemeal. */
971 | EXTERN(void) jpeg_write_m_header(j_compress_ptr cinfo, int marker,
972 | unsigned int datalen);
973 | EXTERN(void) jpeg_write_m_byte(j_compress_ptr cinfo, int val);
974 |
975 | /* Alternate compression function: just write an abbreviated table file */
976 | EXTERN(void) jpeg_write_tables(j_compress_ptr cinfo);
977 |
978 | /* Write ICC profile. See libjpeg.txt for usage information. */
979 | EXTERN(void) jpeg_write_icc_profile(j_compress_ptr cinfo,
980 | const JOCTET *icc_data_ptr,
981 | unsigned int icc_data_len);
982 |
983 |
984 | /* Decompression startup: read start of JPEG datastream to see what's there */
985 | EXTERN(int) jpeg_read_header(j_decompress_ptr cinfo, boolean require_image);
986 | /* Return value is one of: */
987 | #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
988 | #define JPEG_HEADER_OK 1 /* Found valid image datastream */
989 | #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
990 | /* If you pass require_image = TRUE (normal case), you need not check for
991 | * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
992 | * JPEG_SUSPENDED is only possible if you use a data source module that can
993 | * give a suspension return (the stdio source module doesn't).
994 | */
995 |
996 | /* Main entry points for decompression */
997 | EXTERN(boolean) jpeg_start_decompress(j_decompress_ptr cinfo);
998 | EXTERN(JDIMENSION) jpeg_read_scanlines(j_decompress_ptr cinfo,
999 | JSAMPARRAY scanlines,
1000 | JDIMENSION max_lines);
1001 | EXTERN(JDIMENSION) jpeg_skip_scanlines(j_decompress_ptr cinfo,
1002 | JDIMENSION num_lines);
1003 | EXTERN(void) jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
1004 | JDIMENSION *width);
1005 | EXTERN(boolean) jpeg_finish_decompress(j_decompress_ptr cinfo);
1006 |
1007 | /* Replaces jpeg_read_scanlines when reading raw downsampled data. */
1008 | EXTERN(JDIMENSION) jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data,
1009 | JDIMENSION max_lines);
1010 |
1011 | /* Additional entry points for buffered-image mode. */
1012 | EXTERN(boolean) jpeg_has_multiple_scans(j_decompress_ptr cinfo);
1013 | EXTERN(boolean) jpeg_start_output(j_decompress_ptr cinfo, int scan_number);
1014 | EXTERN(boolean) jpeg_finish_output(j_decompress_ptr cinfo);
1015 | EXTERN(boolean) jpeg_input_complete(j_decompress_ptr cinfo);
1016 | EXTERN(void) jpeg_new_colormap(j_decompress_ptr cinfo);
1017 | EXTERN(int) jpeg_consume_input(j_decompress_ptr cinfo);
1018 | /* Return value is one of: */
1019 | /* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */
1020 | #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
1021 | #define JPEG_REACHED_EOI 2 /* Reached end of image */
1022 | #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
1023 | #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
1024 |
1025 | /* Precalculate output dimensions for current decompression parameters. */
1026 | #if JPEG_LIB_VERSION >= 80
1027 | EXTERN(void) jpeg_core_output_dimensions(j_decompress_ptr cinfo);
1028 | #endif
1029 | EXTERN(void) jpeg_calc_output_dimensions(j_decompress_ptr cinfo);
1030 |
1031 | /* Control saving of COM and APPn markers into marker_list. */
1032 | EXTERN(void) jpeg_save_markers(j_decompress_ptr cinfo, int marker_code,
1033 | unsigned int length_limit);
1034 |
1035 | /* Install a special processing method for COM or APPn markers. */
1036 | EXTERN(void) jpeg_set_marker_processor(j_decompress_ptr cinfo,
1037 | int marker_code,
1038 | jpeg_marker_parser_method routine);
1039 |
1040 | /* Read or write raw DCT coefficients --- useful for lossless transcoding. */
1041 | EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients(j_decompress_ptr cinfo);
1042 | EXTERN(void) jpeg_write_coefficients(j_compress_ptr cinfo,
1043 | jvirt_barray_ptr *coef_arrays);
1044 | EXTERN(void) jpeg_copy_critical_parameters(j_decompress_ptr srcinfo,
1045 | j_compress_ptr dstinfo);
1046 |
1047 | /* If you choose to abort compression or decompression before completing
1048 | * jpeg_finish_(de)compress, then you need to clean up to release memory,
1049 | * temporary files, etc. You can just call jpeg_destroy_(de)compress
1050 | * if you're done with the JPEG object, but if you want to clean it up and
1051 | * reuse it, call this:
1052 | */
1053 | EXTERN(void) jpeg_abort_compress(j_compress_ptr cinfo);
1054 | EXTERN(void) jpeg_abort_decompress(j_decompress_ptr cinfo);
1055 |
1056 | /* Generic versions of jpeg_abort and jpeg_destroy that work on either
1057 | * flavor of JPEG object. These may be more convenient in some places.
1058 | */
1059 | EXTERN(void) jpeg_abort(j_common_ptr cinfo);
1060 | EXTERN(void) jpeg_destroy(j_common_ptr cinfo);
1061 |
1062 | /* Default restart-marker-resync procedure for use by data source modules */
1063 | EXTERN(boolean) jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired);
1064 |
1065 | /* Read ICC profile. See libjpeg.txt for usage information. */
1066 | EXTERN(boolean) jpeg_read_icc_profile(j_decompress_ptr cinfo,
1067 | JOCTET **icc_data_ptr,
1068 | unsigned int *icc_data_len);
1069 |
1070 |
1071 | /* These marker codes are exported since applications and data source modules
1072 | * are likely to want to use them.
1073 | */
1074 |
1075 | #define JPEG_RST0 0xD0 /* RST0 marker code */
1076 | #define JPEG_EOI 0xD9 /* EOI marker code */
1077 | #define JPEG_APP0 0xE0 /* APP0 marker code */
1078 | #define JPEG_COM 0xFE /* COM marker code */
1079 |
1080 |
1081 | /* If we have a brain-damaged compiler that emits warnings (or worse, errors)
1082 | * for structure definitions that are never filled in, keep it quiet by
1083 | * supplying dummy definitions for the various substructures.
1084 | */
1085 |
1086 | #ifdef INCOMPLETE_TYPES_BROKEN
1087 | #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
1088 | struct jvirt_sarray_control { long dummy; };
1089 | struct jvirt_barray_control { long dummy; };
1090 | struct jpeg_comp_master { long dummy; };
1091 | struct jpeg_c_main_controller { long dummy; };
1092 | struct jpeg_c_prep_controller { long dummy; };
1093 | struct jpeg_c_coef_controller { long dummy; };
1094 | struct jpeg_marker_writer { long dummy; };
1095 | struct jpeg_color_converter { long dummy; };
1096 | struct jpeg_downsampler { long dummy; };
1097 | struct jpeg_forward_dct { long dummy; };
1098 | struct jpeg_entropy_encoder { long dummy; };
1099 | struct jpeg_decomp_master { long dummy; };
1100 | struct jpeg_d_main_controller { long dummy; };
1101 | struct jpeg_d_coef_controller { long dummy; };
1102 | struct jpeg_d_post_controller { long dummy; };
1103 | struct jpeg_input_controller { long dummy; };
1104 | struct jpeg_marker_reader { long dummy; };
1105 | struct jpeg_entropy_decoder { long dummy; };
1106 | struct jpeg_inverse_dct { long dummy; };
1107 | struct jpeg_upsampler { long dummy; };
1108 | struct jpeg_color_deconverter { long dummy; };
1109 | struct jpeg_color_quantizer { long dummy; };
1110 | #endif /* JPEG_INTERNALS */
1111 | #endif /* INCOMPLETE_TYPES_BROKEN */
1112 |
1113 |
1114 | /*
1115 | * The JPEG library modules define JPEG_INTERNALS before including this file.
1116 | * The internal structure declarations are read only when that is true.
1117 | * Applications using the library should not include jpegint.h, but may wish
1118 | * to include jerror.h.
1119 | */
1120 |
1121 | #ifdef JPEG_INTERNALS
1122 | #include "jpegint.h" /* fetch private declarations */
1123 | #include "jerror.h" /* fetch error codes too */
1124 | #endif
1125 |
1126 | #ifdef __cplusplus
1127 | #ifndef DONT_USE_EXTERN_C
1128 | }
1129 | #endif
1130 | #endif
1131 |
1132 | #endif /* JPEGLIB_H */
1133 |
--------------------------------------------------------------------------------