├── webp-backport
├── src
│ ├── main
│ │ ├── .gitignore
│ │ ├── res
│ │ │ └── .gitignore
│ │ ├── jni
│ │ │ ├── webp
│ │ │ │ ├── autogen.sh
│ │ │ │ ├── Makefile.am
│ │ │ │ ├── swig
│ │ │ │ │ ├── libwebp.jar
│ │ │ │ │ ├── setup.py
│ │ │ │ │ ├── libwebp.go
│ │ │ │ │ ├── libwebp_gc.c
│ │ │ │ │ └── README
│ │ │ │ ├── examples
│ │ │ │ │ ├── test.webp
│ │ │ │ │ ├── test_ref.ppm
│ │ │ │ │ ├── jpegdec.h
│ │ │ │ │ ├── wicdec.h
│ │ │ │ │ ├── pngdec.h
│ │ │ │ │ ├── tiffdec.h
│ │ │ │ │ ├── webpdec.h
│ │ │ │ │ ├── metadata.h
│ │ │ │ │ ├── metadata.c
│ │ │ │ │ ├── Android.mk
│ │ │ │ │ ├── stopwatch.h
│ │ │ │ │ ├── anim_util.h
│ │ │ │ │ ├── Makefile.am
│ │ │ │ │ ├── webpdec.c
│ │ │ │ │ ├── example_util.h
│ │ │ │ │ └── gifdec.h
│ │ │ │ ├── man
│ │ │ │ │ ├── Makefile.am
│ │ │ │ │ └── vwebp.1
│ │ │ │ ├── src
│ │ │ │ │ ├── libwebp.pc.in
│ │ │ │ │ ├── mux
│ │ │ │ │ │ ├── libwebpmux.pc.in
│ │ │ │ │ │ └── Makefile.am
│ │ │ │ │ ├── demux
│ │ │ │ │ │ ├── libwebpdemux.pc.in
│ │ │ │ │ │ └── Makefile.am
│ │ │ │ │ ├── extras
│ │ │ │ │ │ ├── libwebpextras.pc.in
│ │ │ │ │ │ ├── Makefile.am
│ │ │ │ │ │ └── extras.c
│ │ │ │ │ ├── libwebpdecoder.pc.in
│ │ │ │ │ ├── dsp
│ │ │ │ │ │ ├── enc_avx2.c
│ │ │ │ │ │ ├── dec_sse41.c
│ │ │ │ │ │ ├── lossless_enc_sse41.c
│ │ │ │ │ │ ├── argb.c
│ │ │ │ │ │ ├── argb_sse2.c
│ │ │ │ │ │ ├── neon.h
│ │ │ │ │ │ ├── alpha_processing_sse41.c
│ │ │ │ │ │ ├── Makefile.am
│ │ │ │ │ │ ├── cost_sse2.c
│ │ │ │ │ │ └── cost_mips_dsp_r2.c
│ │ │ │ │ ├── dec
│ │ │ │ │ │ ├── Makefile.am
│ │ │ │ │ │ ├── alphai.h
│ │ │ │ │ │ ├── common.h
│ │ │ │ │ │ ├── quant.c
│ │ │ │ │ │ └── vp8li.h
│ │ │ │ │ ├── utils
│ │ │ │ │ │ ├── filters.h
│ │ │ │ │ │ ├── Makefile.am
│ │ │ │ │ │ ├── quant_levels.h
│ │ │ │ │ │ ├── quant_levels_dec.h
│ │ │ │ │ │ ├── color_cache.c
│ │ │ │ │ │ ├── random.c
│ │ │ │ │ │ ├── random.h
│ │ │ │ │ │ ├── huffman_encode.h
│ │ │ │ │ │ ├── filters.c
│ │ │ │ │ │ ├── color_cache.h
│ │ │ │ │ │ ├── endian_inl.h
│ │ │ │ │ │ ├── huffman.h
│ │ │ │ │ │ ├── thread.h
│ │ │ │ │ │ ├── rescaler.h
│ │ │ │ │ │ └── quant_levels.c
│ │ │ │ │ ├── enc
│ │ │ │ │ │ ├── delta_palettization.h
│ │ │ │ │ │ ├── Makefile.am
│ │ │ │ │ │ ├── cost.h
│ │ │ │ │ │ └── vp8li.h
│ │ │ │ │ ├── Makefile.am
│ │ │ │ │ └── webp
│ │ │ │ │ │ ├── types.h
│ │ │ │ │ │ ├── extras.h
│ │ │ │ │ │ ├── mux_types.h
│ │ │ │ │ │ └── format_constants.h
│ │ │ │ ├── doc
│ │ │ │ │ ├── TODO
│ │ │ │ │ ├── README
│ │ │ │ │ └── template.html
│ │ │ │ ├── PATENTS
│ │ │ │ ├── AUTHORS
│ │ │ │ ├── COPYING
│ │ │ │ └── iosbuild.sh
│ │ │ ├── Android.mk
│ │ │ ├── webpbackport
│ │ │ │ ├── Android.mk
│ │ │ │ └── webpbackport.c
│ │ │ └── Application.mk
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── de
│ │ │ └── marcreichelt
│ │ │ └── webp_backport
│ │ │ └── FileSignatureChecker.java
│ └── androidTest
│ │ ├── res
│ │ └── raw
│ │ │ ├── test_empty.webp
│ │ │ ├── test_line_png.png
│ │ │ ├── test_round_png.png
│ │ │ ├── test_line_webp.webp
│ │ │ ├── test_round_webp.webp
│ │ │ ├── test_pixel_red_png.png
│ │ │ ├── test_maximum_16383px.webp
│ │ │ ├── test_pixel_red_webp.webp
│ │ │ ├── test_round_small_png.png
│ │ │ ├── test_round_small_webp.webp
│ │ │ ├── test_lights_1280x853_png.png
│ │ │ ├── test_lights_1280x853_webp.webp
│ │ │ ├── test_pixel_transparent_png.png
│ │ │ ├── test_pixel_transparent_webp.webp
│ │ │ ├── test_pixel_semi_transparent_png.png
│ │ │ ├── test_pixel_semi_transparent_webp.webp
│ │ │ ├── test_red_pixel_with_transparent_border_png.png
│ │ │ ├── test_red_pixel_with_transparent_border_webp.webp
│ │ │ ├── test_red_pixel_with_transparent_border_lossy_png.png
│ │ │ └── test_red_pixel_with_transparent_border_lossy_webp.webp
│ │ └── java
│ │ └── de
│ │ └── marcreichelt
│ │ └── webp_backport
│ │ └── FileSignatureCheckerTest.java
└── proguard-rules.pro
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── testapp
├── src
│ └── main
│ │ ├── res
│ │ ├── raw
│ │ │ ├── round.webp
│ │ │ ├── round_decoded.png
│ │ │ ├── test_lights_150x100.webp
│ │ │ ├── test_lights_256x171.webp
│ │ │ └── test_lights_1280x853.webp
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── layout
│ │ │ ├── glide_demo_item.xml
│ │ │ ├── glide_demo.xml
│ │ │ ├── main.xml
│ │ │ └── simple_decode_demo.xml
│ │ ├── menu
│ │ │ └── menu_main.xml
│ │ └── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── java
│ │ └── de
│ │ │ └── marcreichelt
│ │ │ └── webp_backport
│ │ │ └── testapp
│ │ │ ├── MarginDecoration.java
│ │ │ ├── Main.java
│ │ │ ├── SimpleDecodeDemo.java
│ │ │ ├── GlideDemo.java
│ │ │ └── GlideWebPBackportDecoder.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── .gitmodules
├── .gitignore
├── gradle.properties
├── README.md
└── gradlew.bat
/webp-backport/src/main/.gitignore:
--------------------------------------------------------------------------------
1 | /libs
--------------------------------------------------------------------------------
/webp-backport/src/main/res/.gitignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_empty.webp:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':testapp', ':webp-backport'
2 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/autogen.sh:
--------------------------------------------------------------------------------
1 | #! /bin/sh -e
2 | exec autoreconf -fi
3 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/Makefile.am:
--------------------------------------------------------------------------------
1 | ACLOCAL_AMFLAGS = -I m4
2 | SUBDIRS = src examples man
3 | EXTRA_DIST = COPYING autogen.sh
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/testapp/src/main/res/raw/round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/raw/round.webp
--------------------------------------------------------------------------------
/testapp/src/main/res/raw/round_decoded.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/raw/round_decoded.png
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | #[submodule "webp-backport/src/main/jni/webp"]
2 | # path = webp-backport/src/main/jni/webp
3 | # url = https://chromium.googlesource.com/webm/libwebp
4 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/Android.mk:
--------------------------------------------------------------------------------
1 | # Small trick to disallow samples building
2 | BUILD_EXECUTABLE := $(CLEAR_VARS)
3 |
4 | include $(call all-subdir-makefiles)
5 |
--------------------------------------------------------------------------------
/testapp/src/main/res/raw/test_lights_150x100.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/raw/test_lights_150x100.webp
--------------------------------------------------------------------------------
/testapp/src/main/res/raw/test_lights_256x171.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/raw/test_lights_256x171.webp
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/swig/libwebp.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/main/jni/webp/swig/libwebp.jar
--------------------------------------------------------------------------------
/testapp/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/testapp/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/testapp/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/testapp/src/main/res/raw/test_lights_1280x853.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/raw/test_lights_1280x853.webp
--------------------------------------------------------------------------------
/testapp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/test.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/main/jni/webp/examples/test.webp
--------------------------------------------------------------------------------
/testapp/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/testapp/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/test_ref.ppm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/main/jni/webp/examples/test_ref.ppm
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_line_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_line_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_round_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_round_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_line_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_line_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_round_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_round_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_pixel_red_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_pixel_red_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_maximum_16383px.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_maximum_16383px.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_pixel_red_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_pixel_red_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_round_small_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_round_small_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_round_small_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_round_small_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_lights_1280x853_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_lights_1280x853_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_lights_1280x853_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_lights_1280x853_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_pixel_transparent_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_pixel_transparent_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_pixel_transparent_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_pixel_transparent_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_pixel_semi_transparent_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_pixel_semi_transparent_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_pixel_semi_transparent_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_pixel_semi_transparent_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_webp.webp
--------------------------------------------------------------------------------
/testapp/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 8dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_lossy_png.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_lossy_png.png
--------------------------------------------------------------------------------
/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_lossy_webp.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mreichelt/webp-android-backport-library/HEAD/webp-backport/src/androidTest/res/raw/test_red_pixel_with_transparent_border_lossy_webp.webp
--------------------------------------------------------------------------------
/webp-backport/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/man/Makefile.am:
--------------------------------------------------------------------------------
1 | man_MANS = cwebp.1 dwebp.1
2 | if WANT_MUX
3 | man_MANS += webpmux.1
4 | endif
5 | if BUILD_GIF2WEBP
6 | man_MANS += gif2webp.1
7 | endif
8 | if BUILD_VWEBP
9 | man_MANS += vwebp.1
10 | endif
11 | EXTRA_DIST = $(man_MANS)
12 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 08 23:35:00 CET 2014
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-2.6-all.zip
7 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/libwebp.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libwebp
7 | Description: Library for the WebP graphics format
8 | Version: @PACKAGE_VERSION@
9 | Cflags: -I${includedir}
10 | Libs: -L${libdir} -lwebp
11 | Libs.private: -lm @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
12 |
--------------------------------------------------------------------------------
/testapp/src/main/res/layout/glide_demo_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/mux/libwebpmux.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libwebpmux
7 | Description: Library for manipulating the WebP graphics format container
8 | Version: @PACKAGE_VERSION@
9 | Requires: libwebp >= 0.2.0
10 | Cflags: -I${includedir}
11 | Libs: -L${libdir} -lwebpmux
12 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/demux/libwebpdemux.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libwebpdemux
7 | Description: Library for parsing the WebP graphics format container
8 | Version: @PACKAGE_VERSION@
9 | Requires: libwebp >= 0.2.0
10 | Cflags: -I${includedir}
11 | Libs: -L${libdir} -lwebpdemux
12 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/extras/libwebpextras.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libwebpextras
7 | Description: Additional utility functions useful in processing WebP files
8 | Version: @PACKAGE_VERSION@
9 | Requires: libwebp >= 0.5.0
10 | Cflags: -I${includedir}
11 | Libs: -L${libdir} -lwebpextras
12 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/libwebpdecoder.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libwebpdecoder
7 | Description: Library for the WebP graphics format (decode only)
8 | Version: @PACKAGE_VERSION@
9 | Cflags: -I${includedir}
10 | Libs: -L${libdir} -lwebpdecoder
11 | Libs.private: -lm @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
12 |
--------------------------------------------------------------------------------
/testapp/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/testapp/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webpbackport/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | LOCAL_MODULE := webpbackport
6 |
7 | LOCAL_SRC_FILES := \
8 | webpbackport.c
9 |
10 | LOCAL_C_INCLUDES := \
11 | $(LOCAL_PATH) \
12 | $(LOCAL_PATH)/../webp/src
13 |
14 | LOCAL_STATIC_LIBRARIES := webp
15 |
16 | LOCAL_LDLIBS := -lm -llog -ljnigraphics
17 |
18 | include $(BUILD_SHARED_LIBRARY)
19 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/Application.mk:
--------------------------------------------------------------------------------
1 | # Only these platforms are needed. The new 64 bit ABIs run on newer Android versions anyway.
2 | APP_ABI := armeabi armeabi-v7a x86
3 | APP_CPPFLAGS := -fno-rtti -fno-exceptions
4 | APP_PLATFORM := android-8
5 |
6 | ifndef WEBP_BACKPORT_DEBUG_NATIVE
7 | # Force release compilation in release optimizations, even if application is debuggable by manifest
8 | APP_OPTIM := release
9 | endif
10 |
--------------------------------------------------------------------------------
/testapp/src/main/res/layout/glide_demo.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/testapp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | webp-android-backport-library
5 | WebP test image:
6 | Settings
7 | WebP image loaded in %s ms\nLibrary used: %s
8 | Image
9 |
10 |
11 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/extras/Makefile.am:
--------------------------------------------------------------------------------
1 | lib_LTLIBRARIES = libwebpextras.la
2 |
3 | libwebpextras_la_SOURCES =
4 | libwebpextras_la_SOURCES += extras.c
5 |
6 | libwebpextrasinclude_HEADERS =
7 | libwebpextrasinclude_HEADERS += ../webp/extras.h
8 | libwebpextrasinclude_HEADERS += ../webp/types.h
9 |
10 | libwebpextras_la_LIBADD = ../libwebp.la
11 | libwebpextras_la_LDFLAGS = -no-undefined -version-info 0:0:0
12 | libwebpextrasincludedir = $(includedir)/webp
13 | pkgconfig_DATA = libwebpextras.pc
14 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/demux/Makefile.am:
--------------------------------------------------------------------------------
1 | lib_LTLIBRARIES = libwebpdemux.la
2 |
3 | libwebpdemux_la_SOURCES =
4 | libwebpdemux_la_SOURCES += anim_decode.c demux.c
5 |
6 | libwebpdemuxinclude_HEADERS =
7 | libwebpdemuxinclude_HEADERS += ../webp/demux.h
8 | libwebpdemuxinclude_HEADERS += ../webp/mux_types.h
9 | libwebpdemuxinclude_HEADERS += ../webp/types.h
10 |
11 | libwebpdemux_la_LIBADD = ../libwebp.la
12 | libwebpdemux_la_LDFLAGS = -no-undefined -version-info 2:0:0
13 | libwebpdemuxincludedir = $(includedir)/webp
14 | pkgconfig_DATA = libwebpdemux.pc
15 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/doc/TODO:
--------------------------------------------------------------------------------
1 | , 20111004
2 |
3 | * Determine that normative RFC 2119 terms (MUST, SHOULD, MAY, etc.) are
4 | truly intended in all cases where capitalized.
5 |
6 | * Several passages could be made clearer.
7 |
8 | * Overall edit for scope. Portions are phrased as an introduction to
9 | the 0.1.3 RIFF container additions, rather than a holistic guide to
10 | WebP.
11 |
12 | * To wit, suggest s/[spec|specification]/guide/g . "Spec" can imply a
13 | standards track; in any case it's too formal for a work in progress.
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | .gradle
3 | local.properties
4 | obj
5 |
6 | # Intellij IDEA (see https://gist.github.com/iainconnor/8605514)
7 | .idea/libraries
8 | .idea/workspace.xml
9 | .idea/tasks.xml
10 | .idea/.name
11 | .idea/compiler.xml
12 | .idea/copyright/profiles_settings.xml
13 | .idea/encodings.xml
14 | .idea/misc.xml
15 | .idea/modules.xml
16 | .idea/scopes/scope_settings.xml
17 | .idea/vcs.xml
18 | .idea/runConfigurations.xml
19 | .idea/gradle.xml
20 | .idea/dictionaries
21 | *.iml
22 |
23 | # other stuff
24 | .DS_Store
25 | .DS_Store?
26 | ._*
27 | .Spotlight-V100
28 | .Trashes
29 | ehthumbs.db
30 | Thumbs.db
31 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/mux/Makefile.am:
--------------------------------------------------------------------------------
1 | lib_LTLIBRARIES = libwebpmux.la
2 |
3 | libwebpmux_la_SOURCES =
4 | libwebpmux_la_SOURCES += anim_encode.c
5 | libwebpmux_la_SOURCES += muxedit.c
6 | libwebpmux_la_SOURCES += muxi.h
7 | libwebpmux_la_SOURCES += muxinternal.c
8 | libwebpmux_la_SOURCES += muxread.c
9 |
10 | libwebpmuxinclude_HEADERS =
11 | libwebpmuxinclude_HEADERS += ../webp/mux.h
12 | libwebpmuxinclude_HEADERS += ../webp/mux_types.h
13 | libwebpmuxinclude_HEADERS += ../webp/types.h
14 |
15 | libwebpmux_la_LIBADD = ../libwebp.la
16 | libwebpmux_la_LDFLAGS = -no-undefined -version-info 2:0:0
17 | libwebpmuxincludedir = $(includedir)/webp
18 | pkgconfig_DATA = libwebpmux.pc
19 |
--------------------------------------------------------------------------------
/testapp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/marc/bin/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/webp-backport/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/marc/bin/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/testapp/src/main/java/de/marcreichelt/webp_backport/testapp/MarginDecoration.java:
--------------------------------------------------------------------------------
1 | package de.marcreichelt.webp_backport.testapp;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 |
8 | public class MarginDecoration extends RecyclerView.ItemDecoration {
9 |
10 | private int margin;
11 |
12 | public MarginDecoration(Context context) {
13 | margin = context.getResources().getDimensionPixelSize(R.dimen.item_margin);
14 | }
15 |
16 | @Override
17 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
18 | outRect.set(margin, margin, margin, margin);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/testapp/src/main/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
14 |
15 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/enc_avx2.c:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // AVX2 version of speed-critical encoding functions.
11 |
12 | #include "./dsp.h"
13 |
14 | #if defined(WEBP_USE_AVX2)
15 |
16 | #endif // WEBP_USE_AVX2
17 |
18 | //------------------------------------------------------------------------------
19 | // Entry point
20 |
21 | WEBP_DSP_INIT_STUB(VP8EncDspInitAVX2)
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/testapp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '23.0.2'
6 |
7 | defaultConfig {
8 | applicationId "de.marcreichelt.webp_backport.testapp"
9 | minSdkVersion 8
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:appcompat-v7:23.1.1'
25 | compile 'com.android.support:recyclerview-v7:23.1.1'
26 | compile 'com.github.bumptech.glide:glide:3.6.1'
27 | compile 'org.apache.commons:commons-io:1.3.2'
28 | compile project(':webp-backport')
29 | }
30 |
--------------------------------------------------------------------------------
/testapp/src/main/res/layout/simple_decode_demo.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/testapp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dec/Makefile.am:
--------------------------------------------------------------------------------
1 | noinst_LTLIBRARIES = libwebpdecode.la
2 |
3 | libwebpdecode_la_SOURCES =
4 | libwebpdecode_la_SOURCES += alpha.c
5 | libwebpdecode_la_SOURCES += alphai.h
6 | libwebpdecode_la_SOURCES += buffer.c
7 | libwebpdecode_la_SOURCES += common.h
8 | libwebpdecode_la_SOURCES += decode_vp8.h
9 | libwebpdecode_la_SOURCES += frame.c
10 | libwebpdecode_la_SOURCES += idec.c
11 | libwebpdecode_la_SOURCES += io.c
12 | libwebpdecode_la_SOURCES += quant.c
13 | libwebpdecode_la_SOURCES += tree.c
14 | libwebpdecode_la_SOURCES += vp8.c
15 | libwebpdecode_la_SOURCES += vp8i.h
16 | libwebpdecode_la_SOURCES += vp8l.c
17 | libwebpdecode_la_SOURCES += vp8li.h
18 | libwebpdecode_la_SOURCES += webp.c
19 | libwebpdecode_la_SOURCES += webpi.h
20 |
21 | libwebpdecodeinclude_HEADERS =
22 | libwebpdecodeinclude_HEADERS += ../webp/decode.h
23 | libwebpdecodeinclude_HEADERS += ../webp/types.h
24 | noinst_HEADERS =
25 | noinst_HEADERS += ../webp/format_constants.h
26 |
27 | libwebpdecode_la_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
28 | libwebpdecodeincludedir = $(includedir)/webp
29 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/filters.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Spatial prediction using various filters
11 | //
12 | // Author: Urvang (urvang@google.com)
13 |
14 | #ifndef WEBP_UTILS_FILTERS_H_
15 | #define WEBP_UTILS_FILTERS_H_
16 |
17 | #include "../webp/types.h"
18 | #include "../dsp/dsp.h"
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | // Fast estimate of a potentially good filter.
25 | WEBP_FILTER_TYPE WebPEstimateBestFilter(const uint8_t* data,
26 | int width, int height, int stride);
27 |
28 | #ifdef __cplusplus
29 | } // extern "C"
30 | #endif
31 |
32 | #endif /* WEBP_UTILS_FILTERS_H_ */
33 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/enc/delta_palettization.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Author: Mislav Bradac (mislavm@google.com)
11 | //
12 |
13 | #ifndef WEBP_ENC_DELTA_PALETTIZATION_H_
14 | #define WEBP_ENC_DELTA_PALETTIZATION_H_
15 |
16 | #include "../webp/encode.h"
17 | #include "../enc/vp8li.h"
18 |
19 | // Replaces enc->argb_[] input by a palettizable approximation of it,
20 | // and generates optimal enc->palette_[].
21 | // This function can revert enc->use_palette_ / enc->use_predict_ flag
22 | // if delta-palettization is not producing expected saving.
23 | WebPEncodingError WebPSearchOptimalDeltaPalette(VP8LEncoder* const enc);
24 |
25 | #endif // WEBP_ENC_DELTA_PALETTIZATION_H_
26 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/doc/README:
--------------------------------------------------------------------------------
1 |
2 | Generate libwebp Container Spec Docs from Text Source
3 | =====================================================
4 |
5 | HTML generation requires kramdown [1], easily installed as a
6 | rubygem [2]. Rubygems installation should satisfy dependencies
7 | automatically.
8 |
9 | [1]: http://kramdown.rubyforge.org/
10 | [2]: http://rubygems.org/
11 |
12 | HTML generation can then be done from the project root:
13 |
14 | $ kramdown doc/webp-container-spec.txt --template doc/template.html > \
15 | doc/output/webp-container-spec.html
16 |
17 | kramdown can optionally syntax highlight code blocks, using CodeRay [3],
18 | a dependency of kramdown that rubygems will install automatically. The
19 | following will apply inline CSS styling; an external stylesheet is not
20 | needed.
21 |
22 | $ kramdown doc/webp-lossless-bitstream-spec.txt --template \
23 | doc/template.html --coderay-css style --coderay-line-numbers ' ' \
24 | --coderay-default-lang c > \
25 | doc/output/webp-lossless-bitstream-spec.html
26 |
27 | Optimally, use kramdown 0.13.7 or newer if syntax highlighting desired.
28 |
29 | [3]: http://coderay.rubychan.de/
30 |
--------------------------------------------------------------------------------
/testapp/src/main/java/de/marcreichelt/webp_backport/testapp/Main.java:
--------------------------------------------------------------------------------
1 | package de.marcreichelt.webp_backport.testapp;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class Main extends AppCompatActivity implements View.OnClickListener {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.main);
14 |
15 | findViewById(R.id.simple_decode).setOnClickListener(this);
16 | findViewById(R.id.glide).setOnClickListener(this);
17 | }
18 |
19 | @Override
20 | public void onClick(View v) {
21 | Class> clazz;
22 | switch (v.getId()) {
23 | case R.id.simple_decode:
24 | clazz = SimpleDecodeDemo.class;
25 | break;
26 |
27 | case R.id.glide:
28 | clazz = GlideDemo.class;
29 | break;
30 |
31 | default:
32 | return;
33 | }
34 |
35 | startActivity(new Intent(this, clazz));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | webp-android-backport-library
2 | =============================
3 |
4 | Backport of WebP library for Android devices < 4.3
5 |
6 | A small project I have been working on in private - making the [official WebP library](https://chromium.googlesource.com/webm/libwebp/) easily accessible for Android developers that have to support older devices.
7 | Basic usage:
8 | ```java
9 | byte[] encodedWebPData = loadYourWebPDataFromSomewhere();
10 | Bitmap bitmap = WebPBackport.decode(encodedWebPData);
11 | ```
12 | See [MainActivity](https://github.com/mreichelt/webp-android-backport-library/blob/master/testapp/src/main/java/de/marcreichelt/webp_backport/testapp/MainActivity.java#L74) as another example.
13 | The library automatically uses the faster native bitmap decoding feature of the system if it is available, so you don't have to care about it.
14 |
15 | Let me know if this library is useful for you!
16 | If enough people like it I will add it to a Maven repository so you can add it to your Android project with one line in your build.gradle. :-)
17 |
18 |
19 | License: Same as libwebp - see [PATENTS](https://github.com/mreichelt/webp-android-backport-library/blob/master/webp_backport/jni/PATENTS) file.
20 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/jpegdec.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // JPEG decode.
11 |
12 | #ifndef WEBP_EXAMPLES_JPEGDEC_H_
13 | #define WEBP_EXAMPLES_JPEGDEC_H_
14 |
15 | #include
16 | #include "webp/types.h"
17 |
18 | #ifdef __cplusplus
19 | extern "C" {
20 | #endif
21 |
22 | struct Metadata;
23 | struct WebPPicture;
24 |
25 | // Reads a JPEG from 'data', returning the decoded output in 'pic'.
26 | // The output is RGB or YUV depending on pic->use_argb value.
27 | // Returns true on success.
28 | int ReadJPEG(const uint8_t* const data, size_t data_size,
29 | struct WebPPicture* const pic, struct Metadata* const metadata);
30 |
31 | #ifdef __cplusplus
32 | } // extern "C"
33 | #endif
34 |
35 | #endif // WEBP_EXAMPLES_JPEGDEC_H_
36 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/wicdec.h:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Windows Imaging Component (WIC) decode.
11 |
12 | #ifndef WEBP_EXAMPLES_WICDEC_H_
13 | #define WEBP_EXAMPLES_WICDEC_H_
14 |
15 | #ifdef __cplusplus
16 | extern "C" {
17 | #endif
18 |
19 | struct Metadata;
20 | struct WebPPicture;
21 |
22 | // Reads an image from 'filename', returning the decoded output in 'pic'.
23 | // If 'keep_alpha' is true and the image has an alpha channel, the output is
24 | // RGBA otherwise it will be RGB. pic->use_argb is always forced to true.
25 | // Returns true on success.
26 | int ReadPictureWithWIC(const char* const filename,
27 | struct WebPPicture* const pic, int keep_alpha,
28 | struct Metadata* const metadata);
29 |
30 | #ifdef __cplusplus
31 | } // extern "C"
32 | #endif
33 |
34 | #endif // WEBP_EXAMPLES_WICDEC_H_
35 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/Makefile.am:
--------------------------------------------------------------------------------
1 | noinst_LTLIBRARIES = libwebputils.la
2 |
3 | if BUILD_LIBWEBPDECODER
4 | noinst_LTLIBRARIES += libwebputilsdecode.la
5 | endif
6 |
7 | common_HEADERS = ../webp/types.h
8 | commondir = $(includedir)/webp
9 |
10 | COMMON_SOURCES =
11 | COMMON_SOURCES += bit_reader.c
12 | COMMON_SOURCES += bit_reader.h
13 | COMMON_SOURCES += bit_reader_inl.h
14 | COMMON_SOURCES += color_cache.c
15 | COMMON_SOURCES += color_cache.h
16 | COMMON_SOURCES += endian_inl.h
17 | COMMON_SOURCES += filters.c
18 | COMMON_SOURCES += filters.h
19 | COMMON_SOURCES += huffman.c
20 | COMMON_SOURCES += huffman.h
21 | COMMON_SOURCES += quant_levels_dec.c
22 | COMMON_SOURCES += quant_levels_dec.h
23 | COMMON_SOURCES += rescaler.c
24 | COMMON_SOURCES += rescaler.h
25 | COMMON_SOURCES += random.c
26 | COMMON_SOURCES += random.h
27 | COMMON_SOURCES += thread.c
28 | COMMON_SOURCES += thread.h
29 | COMMON_SOURCES += utils.c
30 | COMMON_SOURCES += utils.h
31 |
32 | ENC_SOURCES =
33 | ENC_SOURCES += bit_writer.c
34 | ENC_SOURCES += bit_writer.h
35 | ENC_SOURCES += huffman_encode.c
36 | ENC_SOURCES += huffman_encode.h
37 | ENC_SOURCES += quant_levels.c
38 | ENC_SOURCES += quant_levels.h
39 |
40 | libwebputils_la_SOURCES = $(COMMON_SOURCES) $(ENC_SOURCES)
41 |
42 | if BUILD_LIBWEBPDECODER
43 | libwebputilsdecode_la_SOURCES = $(COMMON_SOURCES)
44 | endif
45 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/quant_levels.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Alpha plane quantization utility
11 | //
12 | // Author: Vikas Arora (vikasa@google.com)
13 |
14 | #ifndef WEBP_UTILS_QUANT_LEVELS_H_
15 | #define WEBP_UTILS_QUANT_LEVELS_H_
16 |
17 | #include
18 |
19 | #include "../webp/types.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | // Replace the input 'data' of size 'width'x'height' with 'num-levels'
26 | // quantized values. If not NULL, 'sse' will contain the sum of squared error.
27 | // Valid range for 'num_levels' is [2, 256].
28 | // Returns false in case of error (data is NULL, or parameters are invalid).
29 | int QuantizeLevels(uint8_t* const data, int width, int height, int num_levels,
30 | uint64_t* const sse);
31 |
32 | #ifdef __cplusplus
33 | } // extern "C"
34 | #endif
35 |
36 | #endif /* WEBP_UTILS_QUANT_LEVELS_H_ */
37 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/pngdec.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // PNG decode.
11 |
12 | #ifndef WEBP_EXAMPLES_PNGDEC_H_
13 | #define WEBP_EXAMPLES_PNGDEC_H_
14 |
15 | #include "webp/types.h"
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | struct Metadata;
22 | struct WebPPicture;
23 |
24 | // Reads a PNG from 'data', returning the decoded output in 'pic'.
25 | // Output is RGBA or YUVA, depending on pic->use_argb value.
26 | // If 'keep_alpha' is true and the PNG has an alpha channel, the output is RGBA
27 | // or YUVA. Otherwise, alpha channel is dropped and output is RGB or YUV.
28 | // Returns true on success.
29 | int ReadPNG(const uint8_t* const data, size_t data_size,
30 | struct WebPPicture* const pic,
31 | int keep_alpha, struct Metadata* const metadata);
32 |
33 | #ifdef __cplusplus
34 | } // extern "C"
35 | #endif
36 |
37 | #endif // WEBP_EXAMPLES_PNGDEC_H_
38 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/quant_levels_dec.h:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Alpha plane de-quantization utility
11 | //
12 | // Author: Vikas Arora (vikasa@google.com)
13 |
14 | #ifndef WEBP_UTILS_QUANT_LEVELS_DEC_H_
15 | #define WEBP_UTILS_QUANT_LEVELS_DEC_H_
16 |
17 | #include "../webp/types.h"
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | // Apply post-processing to input 'data' of size 'width'x'height' assuming that
24 | // the source was quantized to a reduced number of levels.
25 | // Strength is in [0..100] and controls the amount of dithering applied.
26 | // Returns false in case of error (data is NULL, invalid parameters,
27 | // malloc failure, ...).
28 | int WebPDequantizeLevels(uint8_t* const data, int width, int height,
29 | int strength);
30 |
31 | #ifdef __cplusplus
32 | } // extern "C"
33 | #endif
34 |
35 | #endif /* WEBP_UTILS_QUANT_LEVELS_DEC_H_ */
36 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/tiffdec.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // TIFF decode.
11 |
12 | #ifndef WEBP_EXAMPLES_TIFFDEC_H_
13 | #define WEBP_EXAMPLES_TIFFDEC_H_
14 |
15 | #include "webp/types.h"
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | struct Metadata;
22 | struct WebPPicture;
23 |
24 | // Reads a TIFF from 'data', returning the decoded output in 'pic'.
25 | // Output is RGBA or YUVA, depending on pic->use_argb value.
26 | // If 'keep_alpha' is true and the TIFF has an alpha channel, the output is RGBA
27 | // or YUVA. Otherwise, alpha channel is dropped and output is RGB or YUV.
28 | // Returns true on success.
29 | int ReadTIFF(const uint8_t* const data, size_t data_size,
30 | struct WebPPicture* const pic, int keep_alpha,
31 | struct Metadata* const metadata);
32 |
33 | #ifdef __cplusplus
34 | } // extern "C"
35 | #endif
36 |
37 | #endif // WEBP_EXAMPLES_TIFFDEC_H_
38 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/swig/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | """distutils script for libwebp python module."""
4 |
5 | from distutils.core import setup
6 | from distutils.extension import Extension
7 | import os
8 | import shutil
9 | import tempfile
10 |
11 | tmpdir = tempfile.mkdtemp()
12 | package = "com.google.webp"
13 | package_path = os.path.join(tmpdir, *package.split("."))
14 | os.makedirs(package_path)
15 |
16 | # Create __init_.py files along the package path.
17 | initpy_path = tmpdir
18 | for d in package.split("."):
19 | initpy_path = os.path.join(initpy_path, d)
20 | open(os.path.join(initpy_path, "__init__.py"), "w").close()
21 |
22 | shutil.copy2("libwebp.py", package_path)
23 | setup(name="libwebp",
24 | version="0.0",
25 | description="libwebp python wrapper",
26 | long_description="Provides access to 'simple' libwebp decode interface",
27 | license="BSD",
28 | url="http://developers.google.com/speed/webp",
29 | ext_package=package,
30 | ext_modules=[Extension("_libwebp",
31 | ["libwebp_python_wrap.c"],
32 | libraries=["webp"],
33 | ),
34 | ],
35 | package_dir={"": tmpdir},
36 | packages=["com", "com.google", "com.google.webp"],
37 | py_modules=[package + ".libwebp"],
38 | )
39 |
40 | shutil.rmtree(tmpdir)
41 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/webpdec.h:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // WebP decode.
11 |
12 | #ifndef WEBP_EXAMPLES_WEBPDEC_H_
13 | #define WEBP_EXAMPLES_WEBPDEC_H_
14 |
15 | #include "webp/types.h"
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | struct Metadata;
22 | struct WebPPicture;
23 |
24 | // Reads a WebP from 'in_file', returning the decoded output in 'pic'.
25 | // Output is RGBA or YUVA, depending on pic->use_argb value.
26 | // If 'keep_alpha' is true and the WebP has an alpha channel, the output is RGBA
27 | // or YUVA. Otherwise, alpha channel is dropped and output is RGB or YUV.
28 | // Returns true on success.
29 | int ReadWebP(const uint8_t* const data, size_t data_size,
30 | struct WebPPicture* const pic,
31 | int keep_alpha, struct Metadata* const metadata);
32 |
33 | #ifdef __cplusplus
34 | } // extern "C"
35 | #endif
36 |
37 | #endif // WEBP_EXAMPLES_WEBPDEC_H_
38 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/swig/libwebp.go:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.10
4 | *
5 | * This file is not intended to be easily readable and contains a number of
6 | * coding conventions designed to improve portability and efficiency. Do not make
7 | * changes to this file unless you know what you are doing--modify the SWIG
8 | * interface file instead.
9 | * ----------------------------------------------------------------------------- */
10 |
11 | package libwebp
12 |
13 | import _ "runtime/cgo"
14 | import "unsafe"
15 |
16 | type _ unsafe.Pointer
17 |
18 | type _swig_fnptr *byte
19 | type _swig_memberptr *byte
20 |
21 | //extern libwebpSwigCgocall
22 | func SwigCgocall()
23 |
24 | //extern libwebpSwigCgocallDone
25 | func SwigCgocallDone()
26 |
27 | //extern libwebpSwigCgocallBack
28 | func SwigCgocallBack()
29 |
30 | //extern libwebpSwigCgocallBackDone
31 | func SwigCgocallBackDone()
32 |
33 | func WebPGetDecoderVersion() int
34 | func Wrapped_WebPGetInfo(string, []int, []int) int
35 |
36 | // WebPGetInfo has 2 output parameters, provide a version in the more natural
37 | // go idiom:
38 | func WebPGetInfo(webp []byte) (ok bool, width int, height int) {
39 | w := []int{0}
40 | h := []int{0}
41 | ok = Wrapped_WebPGetInfo(string(webp), w, h) != 0
42 | width = w[0]
43 | height = h[0]
44 | return
45 | }
46 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/dec_sse41.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // SSE4 version of some decoding functions.
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #include "./dsp.h"
15 |
16 | #if defined(WEBP_USE_SSE41)
17 |
18 | #include
19 | #include "../dec/vp8i.h"
20 |
21 | static void HE16(uint8_t* dst) { // horizontal
22 | int j;
23 | const __m128i kShuffle3 = _mm_set1_epi8(3);
24 | for (j = 16; j > 0; --j) {
25 | const __m128i in = _mm_cvtsi32_si128(WebPMemToUint32(dst - 4));
26 | const __m128i values = _mm_shuffle_epi8(in, kShuffle3);
27 | _mm_storeu_si128((__m128i*)dst, values);
28 | dst += BPS;
29 | }
30 | }
31 |
32 | //------------------------------------------------------------------------------
33 | // Entry point
34 |
35 | extern void VP8DspInitSSE41(void);
36 |
37 | WEBP_TSAN_IGNORE_FUNCTION void VP8DspInitSSE41(void) {
38 | VP8PredLuma16[3] = HE16;
39 | }
40 |
41 | #else // !WEBP_USE_SSE41
42 |
43 | WEBP_DSP_INIT_STUB(VP8DspInitSSE41)
44 |
45 | #endif // WEBP_USE_SSE41
46 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 | ------------------------------------
3 |
4 | "These implementations" means the copyrightable works that implement the WebM
5 | codecs distributed by Google as part of the WebM Project.
6 |
7 | Google hereby grants to you a perpetual, worldwide, non-exclusive, no-charge,
8 | royalty-free, irrevocable (except as stated in this section) patent license to
9 | make, have made, use, offer to sell, sell, import, transfer, and otherwise
10 | run, modify and propagate the contents of these implementations of WebM, where
11 | such license applies only to those patent claims, both currently owned by
12 | Google and acquired in the future, licensable by Google that are necessarily
13 | infringed by these implementations of WebM. This grant does not include claims
14 | that would be infringed only as a consequence of further modification of these
15 | implementations. If you or your agent or exclusive licensee institute or order
16 | or agree to the institution of patent litigation or any other patent
17 | enforcement activity against any entity (including a cross-claim or
18 | counterclaim in a lawsuit) alleging that any of these implementations of WebM
19 | or any code incorporated within any of these implementations of WebM
20 | constitute direct or contributory patent infringement, or inducement of
21 | patent infringement, then any patent rights granted to you under this License
22 | for these implementations of WebM shall terminate as of the date such
23 | litigation is filed.
24 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/metadata.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Metadata types and functions.
11 | //
12 |
13 | #ifndef WEBP_EXAMPLES_METADATA_H_
14 | #define WEBP_EXAMPLES_METADATA_H_
15 |
16 | #include "webp/types.h"
17 |
18 | #ifdef __cplusplus
19 | extern "C" {
20 | #endif
21 |
22 | typedef struct MetadataPayload {
23 | uint8_t* bytes;
24 | size_t size;
25 | } MetadataPayload;
26 |
27 | typedef struct Metadata {
28 | MetadataPayload exif;
29 | MetadataPayload iccp;
30 | MetadataPayload xmp;
31 | } Metadata;
32 |
33 | #define METADATA_OFFSET(x) offsetof(Metadata, x)
34 |
35 | void MetadataInit(Metadata* const metadata);
36 | void MetadataPayloadDelete(MetadataPayload* const payload);
37 | void MetadataFree(Metadata* const metadata);
38 |
39 | // Stores 'metadata' to 'payload->bytes', returns false on allocation error.
40 | int MetadataCopy(const char* metadata, size_t metadata_len,
41 | MetadataPayload* const payload);
42 |
43 | #ifdef __cplusplus
44 | } // extern "C"
45 | #endif
46 |
47 | #endif // WEBP_EXAMPLES_METADATA_H_
48 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/AUTHORS:
--------------------------------------------------------------------------------
1 | Contributors:
2 | - Charles Munger (clm at google dot com)
3 | - Christian Duvivier (cduvivier at google dot com)
4 | - Djordje Pesut (djordje dot pesut at imgtec dot com)
5 | - James Zern (jzern at google dot com)
6 | - Jan Engelhardt (jengelh at medozas dot de)
7 | - Johann (johann dot koenig at duck dot com)
8 | - Jovan Zelincevic (jovan dot zelincevic at imgtec dot com)
9 | - Jyrki Alakuijala (jyrki at google dot com)
10 | - Lode Vandevenne (lode at google dot com)
11 | - Lou Quillio (louquillio at google dot com)
12 | - Mans Rullgard (mans at mansr dot com)
13 | - Martin Olsson (mnemo at minimum dot se)
14 | - Mikołaj Zalewski (mikolajz at google dot com)
15 | - Mislav Bradac (mislavm at google dot com)
16 | - Noel Chromium (noel at chromium dot org)
17 | - Pascal Massimino (pascal dot massimino at gmail dot com)
18 | - Paweł Hajdan, Jr (phajdan dot jr at chromium dot org)
19 | - Pierre Joye (pierre dot php at gmail dot com)
20 | - Sam Clegg (sbc at chromium dot org)
21 | - Scott Hancher (seh at google dot com)
22 | - Scott LaVarnway (slavarnway at google dot com)
23 | - Scott Talbot (s at chikachow dot org)
24 | - Slobodan Prijic (slobodan dot prijic at imgtec dot com)
25 | - Somnath Banerjee (somnath dot banerjee at gmail dot com)
26 | - Sriraman Tallam (tmsriram at google dot com)
27 | - Tamar Levy (tamar dot levy at intel dot com)
28 | - Timothy Gu (timothygu99 at gmail dot com)
29 | - Urvang Joshi (urvang at google dot com)
30 | - Vikas Arora (vikasa at google dot com)
31 | - Vincent Rabaud (vrabaud at google dot com)
32 | - Yang Zhang (yang dot zhang at arm dot com)
33 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/COPYING:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010, Google Inc. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in
12 | the documentation and/or other materials provided with the
13 | distribution.
14 |
15 | * Neither the name of Google nor the names of its contributors may
16 | be used to endorse or promote products derived from this software
17 | without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
31 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/swig/libwebp_gc.c:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.10
4 | *
5 | * This file is not intended to be easily readable and contains a number of
6 | * coding conventions designed to improve portability and efficiency. Do not make
7 | * changes to this file unless you know what you are doing--modify the SWIG
8 | * interface file instead.
9 | * ----------------------------------------------------------------------------- */
10 |
11 | /* This file should be compiled with 6c/8c. */
12 | #pragma dynimport _ _ "libwebp_go.so"
13 |
14 | #include "runtime.h"
15 | #include "cgocall.h"
16 |
17 | #ifdef _64BIT
18 | #define SWIG_PARM_SIZE 8
19 | #else
20 | #define SWIG_PARM_SIZE 4
21 | #endif
22 |
23 | #pragma dynimport _wrap_WebPGetDecoderVersion _wrap_WebPGetDecoderVersion ""
24 | extern void (*_wrap_WebPGetDecoderVersion)(void*);
25 | static void (*x_wrap_WebPGetDecoderVersion)(void*) = _wrap_WebPGetDecoderVersion;
26 |
27 | void
28 | ·WebPGetDecoderVersion(struct {
29 | uint8 x[SWIG_PARM_SIZE];
30 | } p)
31 |
32 | {
33 | runtime·cgocall(x_wrap_WebPGetDecoderVersion, &p);
34 | }
35 |
36 |
37 |
38 | #pragma dynimport _wrap_wrapped_WebPGetInfo _wrap_wrapped_WebPGetInfo ""
39 | extern void (*_wrap_wrapped_WebPGetInfo)(void*);
40 | static void (*x_wrap_wrapped_WebPGetInfo)(void*) = _wrap_wrapped_WebPGetInfo;
41 |
42 | void
43 | ·Wrapped_WebPGetInfo(struct {
44 | uint8 x[(2 * SWIG_PARM_SIZE) + (3 * SWIG_PARM_SIZE) + (3 * SWIG_PARM_SIZE) + SWIG_PARM_SIZE];
45 | } p)
46 |
47 | {
48 | runtime·cgocall(x_wrap_wrapped_WebPGetInfo, &p);
49 | }
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/enc/Makefile.am:
--------------------------------------------------------------------------------
1 | noinst_LTLIBRARIES = libwebpencode.la
2 |
3 | libwebpencode_la_SOURCES =
4 | libwebpencode_la_SOURCES += alpha.c
5 | libwebpencode_la_SOURCES += analysis.c
6 | libwebpencode_la_SOURCES += backward_references.c
7 | libwebpencode_la_SOURCES += backward_references.h
8 | libwebpencode_la_SOURCES += config.c
9 | libwebpencode_la_SOURCES += cost.c
10 | libwebpencode_la_SOURCES += cost.h
11 | libwebpencode_la_SOURCES += delta_palettization.c
12 | libwebpencode_la_SOURCES += delta_palettization.h
13 | libwebpencode_la_SOURCES += filter.c
14 | libwebpencode_la_SOURCES += frame.c
15 | libwebpencode_la_SOURCES += histogram.c
16 | libwebpencode_la_SOURCES += histogram.h
17 | libwebpencode_la_SOURCES += iterator.c
18 | libwebpencode_la_SOURCES += near_lossless.c
19 | libwebpencode_la_SOURCES += picture.c
20 | libwebpencode_la_SOURCES += picture_csp.c
21 | libwebpencode_la_SOURCES += picture_psnr.c
22 | libwebpencode_la_SOURCES += picture_rescale.c
23 | libwebpencode_la_SOURCES += picture_tools.c
24 | libwebpencode_la_SOURCES += quant.c
25 | libwebpencode_la_SOURCES += syntax.c
26 | libwebpencode_la_SOURCES += token.c
27 | libwebpencode_la_SOURCES += tree.c
28 | libwebpencode_la_SOURCES += vp8enci.h
29 | libwebpencode_la_SOURCES += vp8l.c
30 | libwebpencode_la_SOURCES += vp8li.h
31 | libwebpencode_la_SOURCES += webpenc.c
32 |
33 | libwebpencodeinclude_HEADERS =
34 | libwebpencodeinclude_HEADERS += ../webp/encode.h
35 | libwebpencodeinclude_HEADERS += ../webp/types.h
36 | noinst_HEADERS =
37 | noinst_HEADERS += ../webp/format_constants.h
38 |
39 | libwebpencode_la_LDFLAGS = -lm
40 | libwebpencode_la_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
41 | libwebpencodeincludedir = $(includedir)/webp
42 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/metadata.c:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Metadata types and functions.
11 | //
12 |
13 | #include "./metadata.h"
14 |
15 | #include
16 | #include
17 |
18 | #include "webp/types.h"
19 |
20 | void MetadataInit(Metadata* const metadata) {
21 | if (metadata == NULL) return;
22 | memset(metadata, 0, sizeof(*metadata));
23 | }
24 |
25 | void MetadataPayloadDelete(MetadataPayload* const payload) {
26 | if (payload == NULL) return;
27 | free(payload->bytes);
28 | payload->bytes = NULL;
29 | payload->size = 0;
30 | }
31 |
32 | void MetadataFree(Metadata* const metadata) {
33 | if (metadata == NULL) return;
34 | MetadataPayloadDelete(&metadata->exif);
35 | MetadataPayloadDelete(&metadata->iccp);
36 | MetadataPayloadDelete(&metadata->xmp);
37 | }
38 |
39 | int MetadataCopy(const char* metadata, size_t metadata_len,
40 | MetadataPayload* const payload) {
41 | if (metadata == NULL || metadata_len == 0 || payload == NULL) return 0;
42 | payload->bytes = (uint8_t*)malloc(metadata_len);
43 | if (payload->bytes == NULL) return 0;
44 | payload->size = metadata_len;
45 | memcpy(payload->bytes, metadata, metadata_len);
46 | return 1;
47 | }
48 |
49 | // -----------------------------------------------------------------------------
50 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/swig/README:
--------------------------------------------------------------------------------
1 | Building:
2 | =========
3 |
4 | JNI SWIG bindings:
5 | ------------------
6 | $ gcc -shared -fPIC -fno-strict-aliasing -O2 \
7 | -I/path/to/your/jdk/includes \
8 | libwebp_java_wrap.c \
9 | -lwebp \
10 | -o libwebp_jni.so
11 |
12 | -------------------------------------- BEGIN PSEUDO EXAMPLE
13 | import com.google.webp.libwebp;
14 |
15 | import java.lang.reflect.Method;
16 |
17 | public class libwebp_jni_example {
18 | static {
19 | System.loadLibrary("webp_jni");
20 | }
21 |
22 | /**
23 | * usage: java -cp libwebp.jar:. libwebp_jni_example
24 | */
25 | public static void main(String argv[]) {
26 | final int version = libwebp.WebPGetDecoderVersion();
27 | System.out.println("libwebp version: " + Integer.toHexString(version));
28 |
29 | System.out.println("libwebp methods:");
30 | final Method[] libwebpMethods = libwebp.class.getDeclaredMethods();
31 | for (int i = 0; i < libwebpMethods.length; i++) {
32 | System.out.println(libwebpMethods[i]);
33 | }
34 | }
35 | }
36 | -------------------------------------- END PSEUDO EXAMPLE
37 |
38 | $ javac -cp libwebp.jar libwebp_jni_example.java
39 | $ java -Djava.library.path=. -cp libwebp.jar:. libwebp_jni_example
40 |
41 | Python SWIG bindings:
42 | ---------------------
43 | $ python setup.py build_ext
44 | $ python setup.py install --prefix=pylocal
45 |
46 | -------------------------------------- BEGIN PSEUDO EXAMPLE
47 | import glob
48 | import sys
49 | sys.path.append(glob.glob('pylocal/lib/python*/site-packages')[0])
50 |
51 | from com.google.webp import libwebp
52 | print "libwebp decoder version: %x" % libwebp.WebPGetDecoderVersion()
53 |
54 | print "libwebp attributes:"
55 | for attr in dir(libwebp): print attr
56 | -------------------------------------- END PSEUDO EXAMPLE
57 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/color_cache.c:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Color Cache for WebP Lossless
11 | //
12 | // Author: Jyrki Alakuijala (jyrki@google.com)
13 |
14 | #include
15 | #include
16 | #include
17 | #include "./color_cache.h"
18 | #include "../utils/utils.h"
19 |
20 | //------------------------------------------------------------------------------
21 | // VP8LColorCache.
22 |
23 | int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
24 | const int hash_size = 1 << hash_bits;
25 | assert(cc != NULL);
26 | assert(hash_bits > 0);
27 | cc->colors_ = (uint32_t*)WebPSafeCalloc((uint64_t)hash_size,
28 | sizeof(*cc->colors_));
29 | if (cc->colors_ == NULL) return 0;
30 | cc->hash_shift_ = 32 - hash_bits;
31 | cc->hash_bits_ = hash_bits;
32 | return 1;
33 | }
34 |
35 | void VP8LColorCacheClear(VP8LColorCache* const cc) {
36 | if (cc != NULL) {
37 | WebPSafeFree(cc->colors_);
38 | cc->colors_ = NULL;
39 | }
40 | }
41 |
42 | void VP8LColorCacheCopy(const VP8LColorCache* const src,
43 | VP8LColorCache* const dst) {
44 | assert(src != NULL);
45 | assert(dst != NULL);
46 | assert(src->hash_bits_ == dst->hash_bits_);
47 | memcpy(dst->colors_, src->colors_,
48 | ((size_t)1u << dst->hash_bits_) * sizeof(*dst->colors_));
49 | }
50 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | ################################################################################
4 | # libexample_util
5 |
6 | include $(CLEAR_VARS)
7 |
8 | LOCAL_SRC_FILES := \
9 | example_util.c \
10 |
11 | LOCAL_CFLAGS := $(WEBP_CFLAGS)
12 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
13 |
14 | LOCAL_MODULE := example_util
15 |
16 | include $(BUILD_STATIC_LIBRARY)
17 |
18 | ################################################################################
19 | # cwebp
20 |
21 | include $(CLEAR_VARS)
22 |
23 | # Note: to enable jpeg/png encoding the sources from AOSP can be used with
24 | # minor modification to their Android.mk files.
25 | LOCAL_SRC_FILES := \
26 | cwebp.c \
27 | jpegdec.c \
28 | metadata.c \
29 | pngdec.c \
30 | tiffdec.c \
31 | webpdec.c \
32 |
33 | LOCAL_CFLAGS := $(WEBP_CFLAGS)
34 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
35 | LOCAL_STATIC_LIBRARIES := example_util webp
36 |
37 | LOCAL_MODULE := cwebp
38 |
39 | include $(BUILD_EXECUTABLE)
40 |
41 | ################################################################################
42 | # dwebp
43 |
44 | include $(CLEAR_VARS)
45 |
46 | LOCAL_SRC_FILES := \
47 | dwebp.c \
48 |
49 | LOCAL_CFLAGS := $(WEBP_CFLAGS)
50 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
51 | LOCAL_STATIC_LIBRARIES := example_util webp
52 |
53 | LOCAL_MODULE := dwebp
54 |
55 | include $(BUILD_EXECUTABLE)
56 |
57 | ################################################################################
58 | # webpmux
59 |
60 | include $(CLEAR_VARS)
61 |
62 | LOCAL_SRC_FILES := \
63 | webpmux.c \
64 |
65 | LOCAL_CFLAGS := $(WEBP_CFLAGS)
66 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
67 | LOCAL_STATIC_LIBRARIES := example_util webpmux webp
68 |
69 | LOCAL_MODULE := webpmux_example
70 |
71 | include $(BUILD_EXECUTABLE)
72 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dec/alphai.h:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Alpha decoder: internal header.
11 | //
12 | // Author: Urvang (urvang@google.com)
13 |
14 | #ifndef WEBP_DEC_ALPHAI_H_
15 | #define WEBP_DEC_ALPHAI_H_
16 |
17 | #include "./webpi.h"
18 | #include "../utils/filters.h"
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | struct VP8LDecoder; // Defined in dec/vp8li.h.
25 |
26 | typedef struct ALPHDecoder ALPHDecoder;
27 | struct ALPHDecoder {
28 | int width_;
29 | int height_;
30 | int method_;
31 | WEBP_FILTER_TYPE filter_;
32 | int pre_processing_;
33 | struct VP8LDecoder* vp8l_dec_;
34 | VP8Io io_;
35 | int use_8b_decode; // Although alpha channel requires only 1 byte per
36 | // pixel, sometimes VP8LDecoder may need to allocate
37 | // 4 bytes per pixel internally during decode.
38 | };
39 |
40 | //------------------------------------------------------------------------------
41 | // internal functions. Not public.
42 |
43 | // Allocates a new alpha decoder instance.
44 | ALPHDecoder* ALPHNew(void);
45 |
46 | // Clears and deallocates an alpha decoder instance.
47 | void ALPHDelete(ALPHDecoder* const dec);
48 |
49 | //------------------------------------------------------------------------------
50 |
51 | #ifdef __cplusplus
52 | } // extern "C"
53 | #endif
54 |
55 | #endif /* WEBP_DEC_ALPHAI_H_ */
56 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/Makefile.am:
--------------------------------------------------------------------------------
1 | # The mux, demux and extras libraries depend on libwebp, thus the '.' to force
2 | # the build order so it's available to them.
3 | SUBDIRS = dec enc dsp utils .
4 | if WANT_MUX
5 | SUBDIRS += mux
6 | endif
7 | if WANT_DEMUX
8 | SUBDIRS += demux
9 | endif
10 | if WANT_EXTRAS
11 | SUBDIRS += extras
12 | endif
13 |
14 | lib_LTLIBRARIES = libwebp.la
15 |
16 | if BUILD_LIBWEBPDECODER
17 | lib_LTLIBRARIES += libwebpdecoder.la
18 | endif
19 |
20 | common_HEADERS =
21 | common_HEADERS += webp/decode.h
22 | common_HEADERS += webp/types.h
23 | commondir = $(includedir)/webp
24 |
25 | libwebp_la_SOURCES =
26 | libwebpinclude_HEADERS =
27 | libwebpinclude_HEADERS += webp/encode.h
28 | noinst_HEADERS =
29 | noinst_HEADERS += webp/format_constants.h
30 |
31 | libwebp_la_LIBADD =
32 | libwebp_la_LIBADD += dec/libwebpdecode.la
33 | libwebp_la_LIBADD += dsp/libwebpdsp.la
34 | libwebp_la_LIBADD += enc/libwebpencode.la
35 | libwebp_la_LIBADD += utils/libwebputils.la
36 |
37 | # Use '-no-undefined' to declare that libwebp does not depend on any libraries
38 | # other than the ones listed on the command line, i.e., after linking, it will
39 | # not have unresolved symbols. Some platforms (Windows among them) require all
40 | # symbols in shared libraries to be resolved at library creation.
41 | libwebp_la_LDFLAGS = -no-undefined -version-info 6:0:0
42 | libwebpincludedir = $(includedir)/webp
43 | pkgconfig_DATA = libwebp.pc
44 |
45 | if BUILD_LIBWEBPDECODER
46 | libwebpdecoder_la_SOURCES =
47 |
48 | libwebpdecoder_la_LIBADD =
49 | libwebpdecoder_la_LIBADD += dec/libwebpdecode.la
50 | libwebpdecoder_la_LIBADD += dsp/libwebpdspdecode.la
51 | libwebpdecoder_la_LIBADD += utils/libwebputilsdecode.la
52 |
53 | libwebpdecoder_la_LDFLAGS = -no-undefined -version-info 2:0:0
54 | pkgconfig_DATA += libwebpdecoder.pc
55 | endif
56 |
57 | ${pkgconfig_DATA}: ${top_builddir}/config.status
58 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dec/common.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Definitions and macros common to encoding and decoding
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_DEC_COMMON_H_
15 | #define WEBP_DEC_COMMON_H_
16 |
17 | // intra prediction modes
18 | enum { B_DC_PRED = 0, // 4x4 modes
19 | B_TM_PRED = 1,
20 | B_VE_PRED = 2,
21 | B_HE_PRED = 3,
22 | B_RD_PRED = 4,
23 | B_VR_PRED = 5,
24 | B_LD_PRED = 6,
25 | B_VL_PRED = 7,
26 | B_HD_PRED = 8,
27 | B_HU_PRED = 9,
28 | NUM_BMODES = B_HU_PRED + 1 - B_DC_PRED, // = 10
29 |
30 | // Luma16 or UV modes
31 | DC_PRED = B_DC_PRED, V_PRED = B_VE_PRED,
32 | H_PRED = B_HE_PRED, TM_PRED = B_TM_PRED,
33 | B_PRED = NUM_BMODES, // refined I4x4 mode
34 | NUM_PRED_MODES = 4,
35 |
36 | // special modes
37 | B_DC_PRED_NOTOP = 4,
38 | B_DC_PRED_NOLEFT = 5,
39 | B_DC_PRED_NOTOPLEFT = 6,
40 | NUM_B_DC_MODES = 7 };
41 |
42 | enum { MB_FEATURE_TREE_PROBS = 3,
43 | NUM_MB_SEGMENTS = 4,
44 | NUM_REF_LF_DELTAS = 4,
45 | NUM_MODE_LF_DELTAS = 4, // I4x4, ZERO, *, SPLIT
46 | MAX_NUM_PARTITIONS = 8,
47 | // Probabilities
48 | NUM_TYPES = 4, // 0: i16-AC, 1: i16-DC, 2:chroma-AC, 3:i4-AC
49 | NUM_BANDS = 8,
50 | NUM_CTX = 3,
51 | NUM_PROBAS = 11
52 | };
53 |
54 | #endif // WEBP_DEC_COMMON_H_
55 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/webp/types.h:
--------------------------------------------------------------------------------
1 | // Copyright 2010 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Common types
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_WEBP_TYPES_H_
15 | #define WEBP_WEBP_TYPES_H_
16 |
17 | #include // for size_t
18 |
19 | #ifndef _MSC_VER
20 | #include
21 | #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
22 | (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
23 | #define WEBP_INLINE inline
24 | #else
25 | #define WEBP_INLINE
26 | #endif
27 | #else
28 | typedef signed char int8_t;
29 | typedef unsigned char uint8_t;
30 | typedef signed short int16_t;
31 | typedef unsigned short uint16_t;
32 | typedef signed int int32_t;
33 | typedef unsigned int uint32_t;
34 | typedef unsigned long long int uint64_t;
35 | typedef long long int int64_t;
36 | #define WEBP_INLINE __forceinline
37 | #endif /* _MSC_VER */
38 |
39 | #ifndef WEBP_EXTERN
40 | // This explicitly marks library functions and allows for changing the
41 | // signature for e.g., Windows DLL builds.
42 | # if defined(__GNUC__) && __GNUC__ >= 4
43 | # define WEBP_EXTERN(type) extern __attribute__ ((visibility ("default"))) type
44 | # else
45 | # define WEBP_EXTERN(type) extern type
46 | # endif /* __GNUC__ >= 4 */
47 | #endif /* WEBP_EXTERN */
48 |
49 | // Macro to check ABI compatibility (same major revision number)
50 | #define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8))
51 |
52 | #endif /* WEBP_WEBP_TYPES_H_ */
53 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/lossless_enc_sse41.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // SSE4.1 variant of methods for lossless encoder
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #include "./dsp.h"
15 |
16 | #if defined(WEBP_USE_SSE41)
17 | #include
18 | #include
19 | #include "./lossless.h"
20 |
21 | //------------------------------------------------------------------------------
22 | // Subtract-Green Transform
23 |
24 | static void SubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixels) {
25 | int i;
26 | const __m128i kCstShuffle = _mm_set_epi8(-1, 13, -1, 13, -1, 9, -1, 9,
27 | -1, 5, -1, 5, -1, 1, -1, 1);
28 | for (i = 0; i + 4 <= num_pixels; i += 4) {
29 | const __m128i in = _mm_loadu_si128((__m128i*)&argb_data[i]);
30 | const __m128i in_0g0g = _mm_shuffle_epi8(in, kCstShuffle);
31 | const __m128i out = _mm_sub_epi8(in, in_0g0g);
32 | _mm_storeu_si128((__m128i*)&argb_data[i], out);
33 | }
34 | // fallthrough and finish off with plain-C
35 | VP8LSubtractGreenFromBlueAndRed_C(argb_data + i, num_pixels - i);
36 | }
37 |
38 | //------------------------------------------------------------------------------
39 | // Entry point
40 |
41 | extern void VP8LEncDspInitSSE41(void);
42 |
43 | WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitSSE41(void) {
44 | VP8LSubtractGreenFromBlueAndRed = SubtractGreenFromBlueAndRed;
45 | }
46 |
47 | #else // !WEBP_USE_SSE41
48 |
49 | WEBP_DSP_INIT_STUB(VP8LEncDspInitSSE41)
50 |
51 | #endif // WEBP_USE_SSE41
52 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/random.c:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Pseudo-random utilities
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #include
15 | #include "./random.h"
16 |
17 | //------------------------------------------------------------------------------
18 |
19 | // 31b-range values
20 | static const uint32_t kRandomTable[VP8_RANDOM_TABLE_SIZE] = {
21 | 0x0de15230, 0x03b31886, 0x775faccb, 0x1c88626a, 0x68385c55, 0x14b3b828,
22 | 0x4a85fef8, 0x49ddb84b, 0x64fcf397, 0x5c550289, 0x4a290000, 0x0d7ec1da,
23 | 0x5940b7ab, 0x5492577d, 0x4e19ca72, 0x38d38c69, 0x0c01ee65, 0x32a1755f,
24 | 0x5437f652, 0x5abb2c32, 0x0faa57b1, 0x73f533e7, 0x685feeda, 0x7563cce2,
25 | 0x6e990e83, 0x4730a7ed, 0x4fc0d9c6, 0x496b153c, 0x4f1403fa, 0x541afb0c,
26 | 0x73990b32, 0x26d7cb1c, 0x6fcc3706, 0x2cbb77d8, 0x75762f2a, 0x6425ccdd,
27 | 0x24b35461, 0x0a7d8715, 0x220414a8, 0x141ebf67, 0x56b41583, 0x73e502e3,
28 | 0x44cab16f, 0x28264d42, 0x73baaefb, 0x0a50ebed, 0x1d6ab6fb, 0x0d3ad40b,
29 | 0x35db3b68, 0x2b081e83, 0x77ce6b95, 0x5181e5f0, 0x78853bbc, 0x009f9494,
30 | 0x27e5ed3c
31 | };
32 |
33 | void VP8InitRandom(VP8Random* const rg, float dithering) {
34 | memcpy(rg->tab_, kRandomTable, sizeof(rg->tab_));
35 | rg->index1_ = 0;
36 | rg->index2_ = 31;
37 | rg->amp_ = (dithering < 0.0) ? 0
38 | : (dithering > 1.0) ? (1 << VP8_RANDOM_DITHER_FIX)
39 | : (uint32_t)((1 << VP8_RANDOM_DITHER_FIX) * dithering);
40 | }
41 |
42 | //------------------------------------------------------------------------------
43 |
44 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/webp/extras.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 |
11 | #ifndef WEBP_WEBP_EXTRAS_H_
12 | #define WEBP_WEBP_EXTRAS_H_
13 |
14 | #include "./types.h"
15 |
16 | #ifdef __cplusplus
17 | extern "C" {
18 | #endif
19 |
20 | #include "./encode.h"
21 |
22 | #define WEBP_EXTRAS_ABI_VERSION 0x0000 // MAJOR(8b) + MINOR(8b)
23 |
24 | //------------------------------------------------------------------------------
25 |
26 | // Returns the version number of the extras library, packed in hexadecimal using
27 | // 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507.
28 | WEBP_EXTERN(int) WebPGetExtrasVersion(void);
29 |
30 | //------------------------------------------------------------------------------
31 | // Ad-hoc colorspace importers.
32 |
33 | // Import luma sample (gray scale image) into 'picture'. The 'picture'
34 | // width and height must be set prior to calling this function.
35 | WEBP_EXTERN(int) WebPImportGray(const uint8_t* gray, WebPPicture* picture);
36 |
37 | // Import rgb sample in RGB565 packed format into 'picture'. The 'picture'
38 | // width and height must be set prior to calling this function.
39 | WEBP_EXTERN(int) WebPImportRGB565(const uint8_t* rgb565, WebPPicture* pic);
40 |
41 | // Import rgb sample in RGB4444 packed format into 'picture'. The 'picture'
42 | // width and height must be set prior to calling this function.
43 | WEBP_EXTERN(int) WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic);
44 |
45 | //------------------------------------------------------------------------------
46 |
47 | #ifdef __cplusplus
48 | } // extern "C"
49 | #endif
50 |
51 | #endif /* WEBP_WEBP_EXTRAS_H_ */
52 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/stopwatch.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Helper functions to measure elapsed time.
11 | //
12 | // Author: Mikolaj Zalewski (mikolajz@google.com)
13 |
14 | #ifndef WEBP_EXAMPLES_STOPWATCH_H_
15 | #define WEBP_EXAMPLES_STOPWATCH_H_
16 |
17 | #include "webp/types.h"
18 |
19 | #if defined _WIN32 && !defined __GNUC__
20 | #include
21 |
22 | typedef LARGE_INTEGER Stopwatch;
23 |
24 | static WEBP_INLINE void StopwatchReset(Stopwatch* watch) {
25 | QueryPerformanceCounter(watch);
26 | }
27 |
28 | static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) {
29 | const LARGE_INTEGER old_value = *watch;
30 | LARGE_INTEGER freq;
31 | if (!QueryPerformanceCounter(watch))
32 | return 0.0;
33 | if (!QueryPerformanceFrequency(&freq))
34 | return 0.0;
35 | if (freq.QuadPart == 0)
36 | return 0.0;
37 | return (watch->QuadPart - old_value.QuadPart) / (double)freq.QuadPart;
38 | }
39 |
40 |
41 | #else /* !_WIN32 */
42 | #include // memcpy
43 | #include
44 |
45 | typedef struct timeval Stopwatch;
46 |
47 | static WEBP_INLINE void StopwatchReset(Stopwatch* watch) {
48 | gettimeofday(watch, NULL);
49 | }
50 |
51 | static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) {
52 | struct timeval old_value;
53 | double delta_sec, delta_usec;
54 | memcpy(&old_value, watch, sizeof(old_value));
55 | gettimeofday(watch, NULL);
56 | delta_sec = (double)watch->tv_sec - old_value.tv_sec;
57 | delta_usec = (double)watch->tv_usec - old_value.tv_usec;
58 | return delta_sec + delta_usec / 1000000.0;
59 | }
60 |
61 | #endif /* _WIN32 */
62 |
63 | #endif /* WEBP_EXAMPLES_STOPWATCH_H_ */
64 |
--------------------------------------------------------------------------------
/testapp/src/main/java/de/marcreichelt/webp_backport/testapp/SimpleDecodeDemo.java:
--------------------------------------------------------------------------------
1 | package de.marcreichelt.webp_backport.testapp;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.AsyncTask;
5 | import android.os.Bundle;
6 | import android.os.SystemClock;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import org.apache.commons.io.IOUtils;
12 |
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 |
16 | import de.marcreichelt.webp_backport.WebPBackport;
17 |
18 |
19 | public class SimpleDecodeDemo extends AppCompatActivity {
20 |
21 | TextView status;
22 | ImageView image;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.simple_decode_demo);
28 |
29 | status = (TextView) findViewById(R.id.status);
30 | image = (ImageView) findViewById(R.id.image);
31 | }
32 |
33 | @Override
34 | protected void onStart() {
35 | super.onStart();
36 | new LoadWebPTask().execute(R.raw.test_lights_1280x853);
37 | }
38 |
39 | class LoadWebPTask extends AsyncTask {
40 |
41 | @Override
42 | protected Bitmap doInBackground(Integer... params) {
43 | try {
44 | publishProgress(getString(R.string.loading_image));
45 | long start = SystemClock.elapsedRealtime();
46 | InputStream in = getResources().openRawResource(params[0]);
47 | byte[] encoded = IOUtils.toByteArray(in);
48 | long time = SystemClock.elapsedRealtime() - start;
49 | publishProgress(getString(R.string.status, time, WebPBackport.isLibraryUsed()));
50 | return WebPBackport.decode(encoded);
51 | } catch (IOException e) {
52 | throw new RuntimeException(e);
53 | }
54 | }
55 |
56 | @Override
57 | protected void onPostExecute(Bitmap bitmap) {
58 | image.setImageBitmap(bitmap);
59 | }
60 |
61 | @Override
62 | protected void onProgressUpdate(String... values) {
63 | status.setText(values[0]);
64 | }
65 |
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/enc/cost.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Cost tables for level and modes.
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_ENC_COST_H_
15 | #define WEBP_ENC_COST_H_
16 |
17 | #include
18 | #include
19 | #include "./vp8enci.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | // On-the-fly info about the current set of residuals. Handy to avoid
26 | // passing zillions of params.
27 | typedef struct VP8Residual VP8Residual;
28 | struct VP8Residual {
29 | int first;
30 | int last;
31 | const int16_t* coeffs;
32 |
33 | int coeff_type;
34 | ProbaArray* prob;
35 | StatsArray* stats;
36 | CostArrayPtr costs;
37 | };
38 |
39 | void VP8InitResidual(int first, int coeff_type,
40 | VP8Encoder* const enc, VP8Residual* const res);
41 |
42 | int VP8RecordCoeffs(int ctx, const VP8Residual* const res);
43 |
44 | // Cost of coding one event with probability 'proba'.
45 | static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
46 | return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
47 | }
48 |
49 | // Level cost calculations
50 | extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2];
51 | void VP8CalculateLevelCosts(VP8EncProba* const proba);
52 | static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
53 | return VP8LevelFixedCosts[level]
54 | + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
55 | }
56 |
57 | // Mode costs
58 | extern const uint16_t VP8FixedCostsUV[4];
59 | extern const uint16_t VP8FixedCostsI16[4];
60 | extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
61 |
62 | //------------------------------------------------------------------------------
63 |
64 | #ifdef __cplusplus
65 | } // extern "C"
66 | #endif
67 |
68 | #endif /* WEBP_ENC_COST_H_ */
69 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/doc/template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | WebP Container Specification
6 |
7 |
90 |
91 |
92 | <%= @body %>
93 |
94 |
95 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/anim_util.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Utilities for animated images
11 |
12 | #ifndef WEBP_EXAMPLES_ANIM_UTIL_H_
13 | #define WEBP_EXAMPLES_ANIM_UTIL_H_
14 |
15 | #ifdef HAVE_CONFIG_H
16 | #include "webp/config.h"
17 | #endif
18 |
19 | #include "webp/types.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | typedef struct {
26 | uint8_t* rgba; // Decoded and reconstructed full frame.
27 | int duration; // Frame duration in milliseconds.
28 | int is_key_frame; // True if this frame is a key-frame.
29 | } DecodedFrame;
30 |
31 | typedef struct {
32 | uint32_t canvas_width;
33 | uint32_t canvas_height;
34 | uint32_t bgcolor;
35 | uint32_t loop_count;
36 | DecodedFrame* frames;
37 | uint32_t num_frames;
38 | void* raw_mem;
39 | } AnimatedImage;
40 |
41 | // Deallocate everything in 'image' (but not the object itself).
42 | void ClearAnimatedImage(AnimatedImage* const image);
43 |
44 | // Read animated image file into 'AnimatedImage' struct.
45 | // If 'dump_frames' is true, dump frames to 'dump_folder'.
46 | // Previous content of 'image' is obliterated.
47 | // Upon successful return, content of 'image' must be deleted by
48 | // calling 'ClearAnimatedImage'.
49 | int ReadAnimatedImage(const char filename[], AnimatedImage* const image,
50 | int dump_frames, const char dump_folder[]);
51 |
52 | // Given two RGBA buffers, calculate max pixel difference and PSNR.
53 | // If 'premultiply' is true, R/G/B values will be pre-multiplied by the
54 | // transparency before comparison.
55 | void GetDiffAndPSNR(const uint8_t rgba1[], const uint8_t rgba2[],
56 | uint32_t width, uint32_t height, int premultiply,
57 | int* const max_diff, double* const psnr);
58 |
59 | #ifdef __cplusplus
60 | } // extern "C"
61 | #endif
62 |
63 | #endif // WEBP_EXAMPLES_ANIM_UTIL_H_
64 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/random.h:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Pseudo-random utilities
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_UTILS_RANDOM_H_
15 | #define WEBP_UTILS_RANDOM_H_
16 |
17 | #include
18 | #include "../webp/types.h"
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | #define VP8_RANDOM_DITHER_FIX 8 // fixed-point precision for dithering
25 | #define VP8_RANDOM_TABLE_SIZE 55
26 |
27 | typedef struct {
28 | int index1_, index2_;
29 | uint32_t tab_[VP8_RANDOM_TABLE_SIZE];
30 | int amp_;
31 | } VP8Random;
32 |
33 | // Initializes random generator with an amplitude 'dithering' in range [0..1].
34 | void VP8InitRandom(VP8Random* const rg, float dithering);
35 |
36 | // Returns a centered pseudo-random number with 'num_bits' amplitude.
37 | // (uses D.Knuth's Difference-based random generator).
38 | // 'amp' is in VP8_RANDOM_DITHER_FIX fixed-point precision.
39 | static WEBP_INLINE int VP8RandomBits2(VP8Random* const rg, int num_bits,
40 | int amp) {
41 | int diff;
42 | assert(num_bits + VP8_RANDOM_DITHER_FIX <= 31);
43 | diff = rg->tab_[rg->index1_] - rg->tab_[rg->index2_];
44 | if (diff < 0) diff += (1u << 31);
45 | rg->tab_[rg->index1_] = diff;
46 | if (++rg->index1_ == VP8_RANDOM_TABLE_SIZE) rg->index1_ = 0;
47 | if (++rg->index2_ == VP8_RANDOM_TABLE_SIZE) rg->index2_ = 0;
48 | // sign-extend, 0-center
49 | diff = (int)((uint32_t)diff << 1) >> (32 - num_bits);
50 | diff = (diff * amp) >> VP8_RANDOM_DITHER_FIX; // restrict range
51 | diff += 1 << (num_bits - 1); // shift back to 0.5-center
52 | return diff;
53 | }
54 |
55 | static WEBP_INLINE int VP8RandomBits(VP8Random* const rg, int num_bits) {
56 | return VP8RandomBits2(rg, num_bits, rg->amp_);
57 | }
58 |
59 | #ifdef __cplusplus
60 | } // extern "C"
61 | #endif
62 |
63 | #endif /* WEBP_UTILS_RANDOM_H_ */
64 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/huffman_encode.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Author: Jyrki Alakuijala (jyrki@google.com)
11 | //
12 | // Entropy encoding (Huffman) for webp lossless
13 |
14 | #ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_
15 | #define WEBP_UTILS_HUFFMAN_ENCODE_H_
16 |
17 | #include "../webp/types.h"
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | // Struct for holding the tree header in coded form.
24 | typedef struct {
25 | uint8_t code; // value (0..15) or escape code (16,17,18)
26 | uint8_t extra_bits; // extra bits for escape codes
27 | } HuffmanTreeToken;
28 |
29 | // Struct to represent the tree codes (depth and bits array).
30 | typedef struct {
31 | int num_symbols; // Number of symbols.
32 | uint8_t* code_lengths; // Code lengths of the symbols.
33 | uint16_t* codes; // Symbol Codes.
34 | } HuffmanTreeCode;
35 |
36 | // Struct to represent the Huffman tree.
37 | typedef struct {
38 | uint32_t total_count_; // Symbol frequency.
39 | int value_; // Symbol value.
40 | int pool_index_left_; // Index for the left sub-tree.
41 | int pool_index_right_; // Index for the right sub-tree.
42 | } HuffmanTree;
43 |
44 | // Turn the Huffman tree into a token sequence.
45 | // Returns the number of tokens used.
46 | int VP8LCreateCompressedHuffmanTree(const HuffmanTreeCode* const tree,
47 | HuffmanTreeToken* tokens, int max_tokens);
48 |
49 | // Create an optimized tree, and tokenize it.
50 | // 'buf_rle' and 'huff_tree' are pre-allocated and the 'tree' is the constructed
51 | // huffman code tree.
52 | void VP8LCreateHuffmanTree(uint32_t* const histogram, int tree_depth_limit,
53 | uint8_t* const buf_rle, HuffmanTree* const huff_tree,
54 | HuffmanTreeCode* const tree);
55 |
56 | #ifdef __cplusplus
57 | }
58 | #endif
59 |
60 | #endif // WEBP_UTILS_HUFFMAN_ENCODE_H_
61 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/Makefile.am:
--------------------------------------------------------------------------------
1 | AM_CPPFLAGS += -I$(top_builddir)/src -I$(top_srcdir)/src
2 |
3 | bin_PROGRAMS = dwebp cwebp
4 | if BUILD_VWEBP
5 | bin_PROGRAMS += vwebp
6 | endif
7 | if WANT_MUX
8 | bin_PROGRAMS += webpmux
9 | endif
10 |
11 | if BUILD_GIF2WEBP
12 | bin_PROGRAMS += gif2webp
13 | endif
14 |
15 | noinst_LTLIBRARIES = libexampleutil.la
16 |
17 | libexampleutil_la_SOURCES = example_util.c example_util.h stopwatch.h
18 |
19 | if BUILD_ANIMDIFF
20 | noinst_PROGRAMS = anim_diff
21 | endif
22 |
23 | anim_diff_SOURCES = anim_diff.c anim_util.c anim_util.h
24 | anim_diff_CPPFLAGS = $(AM_CPPFLAGS) $(GIF_INCLUDES)
25 | anim_diff_LDADD = ../src/demux/libwebpdemux.la
26 | anim_diff_LDADD += libexampleutil.la
27 | anim_diff_LDADD += $(GIF_LIBS) -lm
28 |
29 | dwebp_SOURCES = dwebp.c stopwatch.h
30 | dwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
31 | dwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES)
32 | dwebp_LDADD = libexampleutil.la $(PNG_LIBS) $(JPEG_LIBS)
33 |
34 | cwebp_SOURCES = cwebp.c metadata.c metadata.h stopwatch.h
35 | cwebp_SOURCES += jpegdec.c jpegdec.h
36 | cwebp_SOURCES += pngdec.c pngdec.h
37 | cwebp_SOURCES += tiffdec.c tiffdec.h
38 | cwebp_SOURCES += webpdec.c webpdec.h
39 | cwebp_SOURCES += wicdec.c wicdec.h
40 | cwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
41 | cwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES)
42 | cwebp_LDADD = libexampleutil.la ../src/libwebp.la
43 | cwebp_LDADD += $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS)
44 |
45 | gif2webp_SOURCES = gif2webp.c gifdec.c gifdec.h
46 | gif2webp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) $(GIF_INCLUDES)
47 | gif2webp_LDADD = libexampleutil.la ../src/mux/libwebpmux.la ../src/libwebp.la
48 | gif2webp_LDADD += $(GIF_LIBS)
49 |
50 | webpmux_SOURCES = webpmux.c
51 | webpmux_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
52 | webpmux_LDADD = libexampleutil.la ../src/mux/libwebpmux.la ../src/libwebp.la
53 |
54 | vwebp_SOURCES = vwebp.c
55 | vwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) $(GL_INCLUDES)
56 | vwebp_LDADD = libexampleutil.la ../src/demux/libwebpdemux.la $(GL_LIBS)
57 |
58 | if BUILD_LIBWEBPDECODER
59 | anim_diff_LDADD += ../src/libwebpdecoder.la
60 | dwebp_LDADD += ../src/libwebpdecoder.la
61 | vwebp_LDADD += ../src/libwebpdecoder.la
62 | else
63 | anim_diff_LDADD += ../src/libwebp.la
64 | dwebp_LDADD += ../src/libwebp.la
65 | vwebp_LDADD += ../src/libwebp.la
66 | endif
67 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/argb.c:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // ARGB making functions.
11 | //
12 | // Author: Djordje Pesut (djordje.pesut@imgtec.com)
13 |
14 | #include "./dsp.h"
15 |
16 | static WEBP_INLINE uint32_t MakeARGB32(int a, int r, int g, int b) {
17 | return (((uint32_t)a << 24) | (r << 16) | (g << 8) | b);
18 | }
19 |
20 | static void PackARGB(const uint8_t* a, const uint8_t* r, const uint8_t* g,
21 | const uint8_t* b, int len, uint32_t* out) {
22 | int i;
23 | for (i = 0; i < len; ++i) {
24 | out[i] = MakeARGB32(a[4 * i], r[4 * i], g[4 * i], b[4 * i]);
25 | }
26 | }
27 |
28 | static void PackRGB(const uint8_t* r, const uint8_t* g, const uint8_t* b,
29 | int len, int step, uint32_t* out) {
30 | int i, offset = 0;
31 | for (i = 0; i < len; ++i) {
32 | out[i] = MakeARGB32(0xff, r[offset], g[offset], b[offset]);
33 | offset += step;
34 | }
35 | }
36 |
37 | void (*VP8PackARGB)(const uint8_t*, const uint8_t*, const uint8_t*,
38 | const uint8_t*, int, uint32_t*);
39 | void (*VP8PackRGB)(const uint8_t*, const uint8_t*, const uint8_t*,
40 | int, int, uint32_t*);
41 |
42 | extern void VP8EncDspARGBInitMIPSdspR2(void);
43 | extern void VP8EncDspARGBInitSSE2(void);
44 |
45 | static volatile VP8CPUInfo argb_last_cpuinfo_used =
46 | (VP8CPUInfo)&argb_last_cpuinfo_used;
47 |
48 | WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) {
49 | if (argb_last_cpuinfo_used == VP8GetCPUInfo) return;
50 |
51 | VP8PackARGB = PackARGB;
52 | VP8PackRGB = PackRGB;
53 |
54 | // If defined, use CPUInfo() to overwrite some pointers with faster versions.
55 | if (VP8GetCPUInfo != NULL) {
56 | #if defined(WEBP_USE_SSE2)
57 | if (VP8GetCPUInfo(kSSE2)) {
58 | VP8EncDspARGBInitSSE2();
59 | }
60 | #endif
61 | #if defined(WEBP_USE_MIPS_DSP_R2)
62 | if (VP8GetCPUInfo(kMIPSdspR2)) {
63 | VP8EncDspARGBInitMIPSdspR2();
64 | }
65 | #endif
66 | }
67 | argb_last_cpuinfo_used = VP8GetCPUInfo;
68 | }
69 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/argb_sse2.c:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // ARGB making functions (SSE2 version).
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #include "./dsp.h"
15 |
16 | #if defined(WEBP_USE_SSE2)
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | static WEBP_INLINE uint32_t MakeARGB32(int a, int r, int g, int b) {
23 | return (((uint32_t)a << 24) | (r << 16) | (g << 8) | b);
24 | }
25 |
26 | static void PackARGB(const uint8_t* a, const uint8_t* r, const uint8_t* g,
27 | const uint8_t* b, int len, uint32_t* out) {
28 | if (g == r + 1) { // RGBA input order. Need to swap R and B.
29 | int i = 0;
30 | const int len_max = len & ~3; // max length processed in main loop
31 | const __m128i red_blue_mask = _mm_set1_epi32(0x00ff00ffu);
32 | assert(b == r + 2);
33 | assert(a == r + 3);
34 | for (; i < len_max; i += 4) {
35 | const __m128i A = _mm_loadu_si128((const __m128i*)(r + 4 * i));
36 | const __m128i B = _mm_and_si128(A, red_blue_mask); // R 0 B 0
37 | const __m128i C = _mm_andnot_si128(red_blue_mask, A); // 0 G 0 A
38 | const __m128i D = _mm_shufflelo_epi16(B, _MM_SHUFFLE(2, 3, 0, 1));
39 | const __m128i E = _mm_shufflehi_epi16(D, _MM_SHUFFLE(2, 3, 0, 1));
40 | const __m128i F = _mm_or_si128(E, C);
41 | _mm_storeu_si128((__m128i*)(out + i), F);
42 | }
43 | for (; i < len; ++i) {
44 | out[i] = MakeARGB32(a[4 * i], r[4 * i], g[4 * i], b[4 * i]);
45 | }
46 | } else {
47 | assert(g == b + 1);
48 | assert(r == b + 2);
49 | assert(a == b + 3);
50 | memcpy(out, b, len * 4);
51 | }
52 | }
53 |
54 | //------------------------------------------------------------------------------
55 | // Entry point
56 |
57 | extern void VP8EncDspARGBInitSSE2(void);
58 |
59 | WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInitSSE2(void) {
60 | VP8PackARGB = PackARGB;
61 | }
62 |
63 | #else // !WEBP_USE_SSE2
64 |
65 | WEBP_DSP_INIT_STUB(VP8EncDspARGBInitSSE2)
66 |
67 | #endif // WEBP_USE_SSE2
68 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/webpdec.c:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // WebP decode.
11 |
12 | #include "./webpdec.h"
13 |
14 | #include
15 | #include
16 |
17 | #include "webp/decode.h"
18 | #include "webp/encode.h"
19 | #include "./example_util.h"
20 | #include "./metadata.h"
21 |
22 | int ReadWebP(const uint8_t* const data, size_t data_size,
23 | WebPPicture* const pic,
24 | int keep_alpha, Metadata* const metadata) {
25 | int ok = 0;
26 | VP8StatusCode status = VP8_STATUS_OK;
27 | WebPDecoderConfig config;
28 | WebPDecBuffer* const output_buffer = &config.output;
29 | WebPBitstreamFeatures* const bitstream = &config.input;
30 |
31 | // TODO(jzern): add Exif/XMP/ICC extraction.
32 | if (metadata != NULL) {
33 | fprintf(stderr, "Warning: metadata extraction from WebP is unsupported.\n");
34 | }
35 |
36 | if (!WebPInitDecoderConfig(&config)) {
37 | fprintf(stderr, "Library version mismatch!\n");
38 | return 0;
39 | }
40 |
41 | status = WebPGetFeatures(data, data_size, bitstream);
42 | if (status != VP8_STATUS_OK) {
43 | ExUtilPrintWebPError("input data", status);
44 | return 0;
45 | }
46 | {
47 | const int has_alpha = keep_alpha && bitstream->has_alpha;
48 | // TODO(skal): use MODE_YUV(A), depending on the expected
49 | // input pic->use_argb. This would save some conversion steps.
50 | output_buffer->colorspace = has_alpha ? MODE_RGBA : MODE_RGB;
51 |
52 | status = ExUtilDecodeWebP(data, data_size, 0, &config);
53 | if (status == VP8_STATUS_OK) {
54 | const uint8_t* const rgba = output_buffer->u.RGBA.rgba;
55 | const int stride = output_buffer->u.RGBA.stride;
56 | pic->width = output_buffer->width;
57 | pic->height = output_buffer->height;
58 | ok = has_alpha ? WebPPictureImportRGBA(pic, rgba, stride)
59 | : WebPPictureImportRGB(pic, rgba, stride);
60 | }
61 | }
62 |
63 | if (status != VP8_STATUS_OK) {
64 | ExUtilPrintWebPError("input data", status);
65 | }
66 |
67 | WebPFreeDecBuffer(output_buffer);
68 | return ok;
69 | }
70 |
71 | // -----------------------------------------------------------------------------
72 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/man/vwebp.1:
--------------------------------------------------------------------------------
1 | .\" Hey, EMACS: -*- nroff -*-
2 | .TH VWEBP 1 "December 11, 2015"
3 | .SH NAME
4 | vwebp \- decompress a WebP file and display it in a window
5 | .SH SYNOPSIS
6 | .B vwebp
7 | .RI [ options ] " input_file.webp
8 | .br
9 | .SH DESCRIPTION
10 | This manual page documents the
11 | .B vwebp
12 | command.
13 | .PP
14 | \fBvwebp\fP decompresses a WebP file and displays it in a window using OpenGL.
15 | .SH OPTIONS
16 | .TP
17 | .B \-h
18 | Print usage summary.
19 | .TP
20 | .B \-version
21 | Print version number and exit.
22 | .TP
23 | .B \-noicc
24 | Don't use the ICC profile if present.
25 | .TP
26 | .B \-nofancy
27 | Don't use the fancy YUV420 upscaler.
28 | .TP
29 | .B \-nofilter
30 | Disable in-loop filtering.
31 | .TP
32 | .BI \-dither " strength
33 | Specify a dithering \fBstrength\fP between 0 and 100. Dithering is a
34 | post-processing effect applied to chroma components in lossy compression.
35 | It helps by smoothing gradients and avoiding banding artifacts. Default: 50.
36 | .TP
37 | .BI \-noalphadither
38 | By default, quantized transparency planes are dithered during decompression,
39 | to smooth the gradients. This flag will prevent this dithering.
40 | .TP
41 | .B \-mt
42 | Use multi-threading for decoding, if possible.
43 | .TP
44 | .B \-info
45 | Display image information on top of the decoded image.
46 | .TP
47 | .BI \-\- " string
48 | Explicitly specify the input file. This option is useful if the input
49 | file starts with an '\-' for instance. This option must appear \fBlast\fP.
50 | Any other options afterward will be ignored. If the input file is "\-",
51 | the data will be read from \fIstdin\fP instead of a file.
52 | .TP
53 |
54 | .SH KEYBOARD SHORTCUTS
55 | .TP
56 | .B 'c'
57 | Toggle use of color profile.
58 | .TP
59 | .B 'i'
60 | Overlay file information.
61 | .TP
62 | .B 'q' / 'Q' / ESC
63 | Quit.
64 |
65 | .SH BUGS
66 | Please report all bugs to our issue tracker:
67 | https://bugs.chromium.org/p/webp
68 | .br
69 | Patches welcome! See this page to get started:
70 | http://www.webmproject.org/code/contribute/submitting-patches/
71 |
72 | .SH EXAMPLES
73 | vwebp picture.webp
74 | .br
75 | vwebp picture.webp -mt -dither 0
76 | .br
77 | vwebp \-\- \-\-\-picture.webp
78 |
79 | .SH AUTHORS
80 | \fBvwebp\fP is a part of libwebp and was written by the WebP team.
81 | .br
82 | The latest source tree is available at
83 | https://chromium.googlesource.com/webm/libwebp
84 | .PP
85 | This manual page was written for the Debian project (and may be used by others).
86 |
87 | .SH SEE ALSO
88 | .BR dwebp (1)
89 | .br
90 | Please refer to http://developers.google.com/speed/webp/ for additional
91 | information.
92 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/webp-backport/src/main/java/de/marcreichelt/webp_backport/FileSignatureChecker.java:
--------------------------------------------------------------------------------
1 | package de.marcreichelt.webp_backport;
2 |
3 | public class FileSignatureChecker {
4 |
5 | /**
6 | * Check if a given byte array has the necessary WebP signature in the beginning of its content.
7 | * The signature is 'RIFFxxxxWEBP' where 'xxxx' is the file size.
8 | *
9 | * @param image the byte array to check
10 | * @return true if the byte array has the WebP signature else false
11 | */
12 | public static boolean checkForWebP(byte[] image) {
13 | return checkForRIFF(image) // starts with 'RIFF'
14 | && containsAt(image, new byte[]{87, 69, 66, 80}, 8); // index 8 to 11 must be 'WEBP'
15 | }
16 |
17 | /**
18 | * Check if a given byte array has a signature that starts with 'RIFF'
19 | *
20 | * @param data the byte array to check
21 | * @return true if the byte array starts with RIFF else false
22 | */
23 | public static boolean checkForRIFF(byte[] data) {
24 | return startsWith(data, new byte[]{82, 73, 70, 70}); // starts with 'RIFF'
25 | }
26 |
27 |
28 | /**
29 | * Check if a byte array starts with the same bytes as another byte array
30 | * that is however smaller than the first one.
31 | *
32 | * @param haystack e.g. {-1, -40, -1, -32, ........}
33 | * @param needle e.g. {-1, -40, -1, -32}
34 | * @return true if {@code haystack} starts with the same bytes as {@code needle}
35 | */
36 | public static boolean startsWith(byte[] haystack, byte[] needle) {
37 | return containsAt(haystack, needle, 0);
38 | }
39 |
40 |
41 | /**
42 | * Check if a byte array contains another byte array that is equal or smaller in size
43 | *
44 | * @param haystack e.g. {..., -1, -40, -1, -32, ...}
45 | * @param needle e.g. {-1, -40, -1, -32}
46 | * @param offset the index where {@code needle} should be starting in {@code haystack}
47 | * @return true if {@code needle} is contained in {@code haystack} starting at index {@code offset}
48 | */
49 | public static boolean containsAt(byte[] haystack, byte[] needle, int offset) {
50 | if (needle.length < 1) {
51 | return true; // everything starts with empty
52 | }
53 | boolean haystackEmpty = haystack.length == 0;
54 | boolean offsetOutOfRange = (offset < 0 || offset >= haystack.length);
55 | boolean needleDoesNotFit = (haystack.length < needle.length + offset);
56 | if (haystackEmpty || offsetOutOfRange || needleDoesNotFit) {
57 | return false;
58 | }
59 |
60 | for (int i = 0; i < needle.length; i++) {
61 | if (needle[i] != haystack[offset + i]) {
62 | return false;
63 | }
64 | }
65 | return true;
66 | }
67 |
68 |
69 | }
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/filters.c:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // filter estimation
11 | //
12 | // Author: Urvang (urvang@google.com)
13 |
14 | #include "./filters.h"
15 | #include
16 | #include
17 |
18 | // -----------------------------------------------------------------------------
19 | // Quick estimate of a potentially interesting filter mode to try.
20 |
21 | #define SMAX 16
22 | #define SDIFF(a, b) (abs((a) - (b)) >> 4) // Scoring diff, in [0..SMAX)
23 |
24 | static WEBP_INLINE int GradientPredictor(uint8_t a, uint8_t b, uint8_t c) {
25 | const int g = a + b - c;
26 | return ((g & ~0xff) == 0) ? g : (g < 0) ? 0 : 255; // clip to 8bit
27 | }
28 |
29 | WEBP_FILTER_TYPE WebPEstimateBestFilter(const uint8_t* data,
30 | int width, int height, int stride) {
31 | int i, j;
32 | int bins[WEBP_FILTER_LAST][SMAX];
33 | memset(bins, 0, sizeof(bins));
34 |
35 | // We only sample every other pixels. That's enough.
36 | for (j = 2; j < height - 1; j += 2) {
37 | const uint8_t* const p = data + j * stride;
38 | int mean = p[0];
39 | for (i = 2; i < width - 1; i += 2) {
40 | const int diff0 = SDIFF(p[i], mean);
41 | const int diff1 = SDIFF(p[i], p[i - 1]);
42 | const int diff2 = SDIFF(p[i], p[i - width]);
43 | const int grad_pred =
44 | GradientPredictor(p[i - 1], p[i - width], p[i - width - 1]);
45 | const int diff3 = SDIFF(p[i], grad_pred);
46 | bins[WEBP_FILTER_NONE][diff0] = 1;
47 | bins[WEBP_FILTER_HORIZONTAL][diff1] = 1;
48 | bins[WEBP_FILTER_VERTICAL][diff2] = 1;
49 | bins[WEBP_FILTER_GRADIENT][diff3] = 1;
50 | mean = (3 * mean + p[i] + 2) >> 2;
51 | }
52 | }
53 | {
54 | int filter;
55 | WEBP_FILTER_TYPE best_filter = WEBP_FILTER_NONE;
56 | int best_score = 0x7fffffff;
57 | for (filter = WEBP_FILTER_NONE; filter < WEBP_FILTER_LAST; ++filter) {
58 | int score = 0;
59 | for (i = 0; i < SMAX; ++i) {
60 | if (bins[filter][i] > 0) {
61 | score += i;
62 | }
63 | }
64 | if (score < best_score) {
65 | best_score = score;
66 | best_filter = (WEBP_FILTER_TYPE)filter;
67 | }
68 | }
69 | return best_filter;
70 | }
71 | }
72 |
73 | #undef SMAX
74 | #undef SDIFF
75 |
76 | //------------------------------------------------------------------------------
77 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/color_cache.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Color Cache for WebP Lossless
11 | //
12 | // Authors: Jyrki Alakuijala (jyrki@google.com)
13 | // Urvang Joshi (urvang@google.com)
14 |
15 | #ifndef WEBP_UTILS_COLOR_CACHE_H_
16 | #define WEBP_UTILS_COLOR_CACHE_H_
17 |
18 | #include "../webp/types.h"
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | // Main color cache struct.
25 | typedef struct {
26 | uint32_t *colors_; // color entries
27 | int hash_shift_; // Hash shift: 32 - hash_bits_.
28 | int hash_bits_;
29 | } VP8LColorCache;
30 |
31 | static const uint32_t kHashMul = 0x1e35a7bd;
32 |
33 | static WEBP_INLINE uint32_t VP8LColorCacheLookup(
34 | const VP8LColorCache* const cc, uint32_t key) {
35 | assert((key >> cc->hash_bits_) == 0u);
36 | return cc->colors_[key];
37 | }
38 |
39 | static WEBP_INLINE void VP8LColorCacheSet(const VP8LColorCache* const cc,
40 | uint32_t key, uint32_t argb) {
41 | assert((key >> cc->hash_bits_) == 0u);
42 | cc->colors_[key] = argb;
43 | }
44 |
45 | static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc,
46 | uint32_t argb) {
47 | const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
48 | cc->colors_[key] = argb;
49 | }
50 |
51 | static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc,
52 | uint32_t argb) {
53 | return (kHashMul * argb) >> cc->hash_shift_;
54 | }
55 |
56 | static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
57 | uint32_t argb) {
58 | const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
59 | return (cc->colors_[key] == argb);
60 | }
61 |
62 | //------------------------------------------------------------------------------
63 |
64 | // Initializes the color cache with 'hash_bits' bits for the keys.
65 | // Returns false in case of memory error.
66 | int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits);
67 |
68 | void VP8LColorCacheCopy(const VP8LColorCache* const src,
69 | VP8LColorCache* const dst);
70 |
71 | // Delete the memory associated to color cache.
72 | void VP8LColorCacheClear(VP8LColorCache* const color_cache);
73 |
74 | //------------------------------------------------------------------------------
75 |
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 |
80 | #endif // WEBP_UTILS_COLOR_CACHE_H_
81 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/enc/vp8li.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Lossless encoder: internal header.
11 | //
12 | // Author: Vikas Arora (vikaas.arora@gmail.com)
13 |
14 | #ifndef WEBP_ENC_VP8LI_H_
15 | #define WEBP_ENC_VP8LI_H_
16 |
17 | #include "./backward_references.h"
18 | #include "./histogram.h"
19 | #include "../utils/bit_writer.h"
20 | #include "../webp/encode.h"
21 | #include "../webp/format_constants.h"
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | typedef struct {
28 | const WebPConfig* config_; // user configuration and parameters
29 | const WebPPicture* pic_; // input picture.
30 |
31 | uint32_t* argb_; // Transformed argb image data.
32 | uint32_t* argb_scratch_; // Scratch memory for argb rows
33 | // (used for prediction).
34 | uint32_t* transform_data_; // Scratch memory for transform data.
35 | int current_width_; // Corresponds to packed image width.
36 |
37 | // Encoding parameters derived from quality parameter.
38 | int histo_bits_;
39 | int transform_bits_;
40 | int cache_bits_; // If equal to 0, don't use color cache.
41 |
42 | // Encoding parameters derived from image characteristics.
43 | int use_cross_color_;
44 | int use_subtract_green_;
45 | int use_predict_;
46 | int use_palette_;
47 | int palette_size_;
48 | uint32_t palette_[MAX_PALETTE_SIZE];
49 |
50 | // Some 'scratch' (potentially large) objects.
51 | struct VP8LBackwardRefs refs_[2]; // Backward Refs array corresponding to
52 | // LZ77 & RLE coding.
53 | VP8LHashChain hash_chain_; // HashChain data for constructing
54 | // backward references.
55 | } VP8LEncoder;
56 |
57 | //------------------------------------------------------------------------------
58 | // internal functions. Not public.
59 |
60 | // Encodes the picture.
61 | // Returns 0 if config or picture is NULL or picture doesn't have valid argb
62 | // input.
63 | int VP8LEncodeImage(const WebPConfig* const config,
64 | const WebPPicture* const picture);
65 |
66 | // Encodes the main image stream using the supplied bit writer.
67 | WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
68 | const WebPPicture* const picture,
69 | VP8LBitWriter* const bw);
70 |
71 | //------------------------------------------------------------------------------
72 |
73 | #ifdef __cplusplus
74 | } // extern "C"
75 | #endif
76 |
77 | #endif /* WEBP_ENC_VP8LI_H_ */
78 |
--------------------------------------------------------------------------------
/testapp/src/main/java/de/marcreichelt/webp_backport/testapp/GlideDemo.java:
--------------------------------------------------------------------------------
1 | package de.marcreichelt.webp_backport.testapp;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.GridLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 |
13 | import com.bumptech.glide.Glide;
14 | import com.bumptech.glide.load.DecodeFormat;
15 |
16 | import org.apache.commons.io.IOUtils;
17 |
18 | import java.io.IOException;
19 | import java.io.InputStream;
20 |
21 | import de.marcreichelt.webp_backport.WebPBackport;
22 |
23 | public class GlideDemo extends AppCompatActivity {
24 |
25 | static {
26 | WebPBackport.forceLoadLibrary();
27 | }
28 |
29 | RecyclerView recyclerView;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.glide_demo);
35 |
36 | recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
37 | recyclerView.addItemDecoration(new MarginDecoration(this));
38 | recyclerView.setHasFixedSize(true);
39 | recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
40 | recyclerView.setAdapter(new GlideDemoAdapter(10000));
41 | }
42 |
43 | private class GlideDemoAdapter extends RecyclerView.Adapter {
44 |
45 | private final int n;
46 | private final byte[] imageData;
47 |
48 | public GlideDemoAdapter(int n) {
49 | this.n = n;
50 | InputStream in = getResources().openRawResource(R.raw.round);
51 | try {
52 | imageData = IOUtils.toByteArray(in);
53 | } catch (IOException e) {
54 | throw new RuntimeException(e);
55 | }
56 | }
57 |
58 | @Override
59 | public GlideDemoViewHolder onCreateViewHolder(ViewGroup parent, int position) {
60 | LayoutInflater inflater = LayoutInflater.from(parent.getContext());
61 | return new GlideDemoViewHolder(inflater.inflate(R.layout.glide_demo_item, parent, false));
62 | }
63 |
64 | @Override
65 | public void onBindViewHolder(GlideDemoViewHolder viewHolder, int position) {
66 | Context context = getApplicationContext();
67 | Glide.with(context)
68 | .load(imageData)
69 | .placeholder(R.drawable.ic_launcher)
70 | .decoder(new GlideWebPBackportDecoder(context, DecodeFormat.PREFER_ARGB_8888))
71 | .into(viewHolder.image);
72 | }
73 |
74 | @Override
75 | public int getItemCount() {
76 | return n;
77 | }
78 |
79 | }
80 |
81 | private static class GlideDemoViewHolder extends RecyclerView.ViewHolder {
82 |
83 | public ImageView image;
84 |
85 | public GlideDemoViewHolder(View itemView) {
86 | super(itemView);
87 | image = (ImageView) itemView.findViewById(R.id.image);
88 | }
89 |
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/neon.h:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // NEON common code.
11 |
12 | #ifndef WEBP_DSP_NEON_H_
13 | #define WEBP_DSP_NEON_H_
14 |
15 | #include
16 |
17 | #include "./dsp.h"
18 |
19 | // Right now, some intrinsics functions seem slower, so we disable them
20 | // everywhere except aarch64 where the inline assembly is incompatible.
21 | #if defined(__aarch64__)
22 | #define WEBP_USE_INTRINSICS // use intrinsics when possible
23 | #endif
24 |
25 | #define INIT_VECTOR2(v, a, b) do { \
26 | v.val[0] = a; \
27 | v.val[1] = b; \
28 | } while (0)
29 |
30 | #define INIT_VECTOR3(v, a, b, c) do { \
31 | v.val[0] = a; \
32 | v.val[1] = b; \
33 | v.val[2] = c; \
34 | } while (0)
35 |
36 | #define INIT_VECTOR4(v, a, b, c, d) do { \
37 | v.val[0] = a; \
38 | v.val[1] = b; \
39 | v.val[2] = c; \
40 | v.val[3] = d; \
41 | } while (0)
42 |
43 | // if using intrinsics, this flag avoids some functions that make gcc-4.6.3
44 | // crash ("internal compiler error: in immed_double_const, at emit-rtl.").
45 | // (probably similar to gcc.gnu.org/bugzilla/show_bug.cgi?id=48183)
46 | #if !(LOCAL_GCC_PREREQ(4,8) || defined(__aarch64__))
47 | #define WORK_AROUND_GCC
48 | #endif
49 |
50 | static WEBP_INLINE int32x4x4_t Transpose4x4(const int32x4x4_t rows) {
51 | uint64x2x2_t row01, row23;
52 |
53 | row01.val[0] = vreinterpretq_u64_s32(rows.val[0]);
54 | row01.val[1] = vreinterpretq_u64_s32(rows.val[1]);
55 | row23.val[0] = vreinterpretq_u64_s32(rows.val[2]);
56 | row23.val[1] = vreinterpretq_u64_s32(rows.val[3]);
57 | // Transpose 64-bit values (there's no vswp equivalent)
58 | {
59 | const uint64x1_t row0h = vget_high_u64(row01.val[0]);
60 | const uint64x1_t row2l = vget_low_u64(row23.val[0]);
61 | const uint64x1_t row1h = vget_high_u64(row01.val[1]);
62 | const uint64x1_t row3l = vget_low_u64(row23.val[1]);
63 | row01.val[0] = vcombine_u64(vget_low_u64(row01.val[0]), row2l);
64 | row23.val[0] = vcombine_u64(row0h, vget_high_u64(row23.val[0]));
65 | row01.val[1] = vcombine_u64(vget_low_u64(row01.val[1]), row3l);
66 | row23.val[1] = vcombine_u64(row1h, vget_high_u64(row23.val[1]));
67 | }
68 | {
69 | const int32x4x2_t out01 = vtrnq_s32(vreinterpretq_s32_u64(row01.val[0]),
70 | vreinterpretq_s32_u64(row01.val[1]));
71 | const int32x4x2_t out23 = vtrnq_s32(vreinterpretq_s32_u64(row23.val[0]),
72 | vreinterpretq_s32_u64(row23.val[1]));
73 | int32x4x4_t out;
74 | out.val[0] = out01.val[0];
75 | out.val[1] = out01.val[1];
76 | out.val[2] = out23.val[0];
77 | out.val[3] = out23.val[1];
78 | return out;
79 | }
80 | }
81 |
82 | #endif // WEBP_DSP_NEON_H_
83 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/webp/mux_types.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Data-types common to the mux and demux libraries.
11 | //
12 | // Author: Urvang (urvang@google.com)
13 |
14 | #ifndef WEBP_WEBP_MUX_TYPES_H_
15 | #define WEBP_WEBP_MUX_TYPES_H_
16 |
17 | #include // free()
18 | #include // memset()
19 | #include "./types.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | // Note: forward declaring enumerations is not allowed in (strict) C and C++,
26 | // the types are left here for reference.
27 | // typedef enum WebPFeatureFlags WebPFeatureFlags;
28 | // typedef enum WebPMuxAnimDispose WebPMuxAnimDispose;
29 | // typedef enum WebPMuxAnimBlend WebPMuxAnimBlend;
30 | typedef struct WebPData WebPData;
31 |
32 | // VP8X Feature Flags.
33 | typedef enum WebPFeatureFlags {
34 | FRAGMENTS_FLAG = 0x00000001,
35 | ANIMATION_FLAG = 0x00000002,
36 | XMP_FLAG = 0x00000004,
37 | EXIF_FLAG = 0x00000008,
38 | ALPHA_FLAG = 0x00000010,
39 | ICCP_FLAG = 0x00000020
40 | } WebPFeatureFlags;
41 |
42 | // Dispose method (animation only). Indicates how the area used by the current
43 | // frame is to be treated before rendering the next frame on the canvas.
44 | typedef enum WebPMuxAnimDispose {
45 | WEBP_MUX_DISPOSE_NONE, // Do not dispose.
46 | WEBP_MUX_DISPOSE_BACKGROUND // Dispose to background color.
47 | } WebPMuxAnimDispose;
48 |
49 | // Blend operation (animation only). Indicates how transparent pixels of the
50 | // current frame are blended with those of the previous canvas.
51 | typedef enum WebPMuxAnimBlend {
52 | WEBP_MUX_BLEND, // Blend.
53 | WEBP_MUX_NO_BLEND // Do not blend.
54 | } WebPMuxAnimBlend;
55 |
56 | // Data type used to describe 'raw' data, e.g., chunk data
57 | // (ICC profile, metadata) and WebP compressed image data.
58 | struct WebPData {
59 | const uint8_t* bytes;
60 | size_t size;
61 | };
62 |
63 | // Initializes the contents of the 'webp_data' object with default values.
64 | static WEBP_INLINE void WebPDataInit(WebPData* webp_data) {
65 | if (webp_data != NULL) {
66 | memset(webp_data, 0, sizeof(*webp_data));
67 | }
68 | }
69 |
70 | // Clears the contents of the 'webp_data' object by calling free(). Does not
71 | // deallocate the object itself.
72 | static WEBP_INLINE void WebPDataClear(WebPData* webp_data) {
73 | if (webp_data != NULL) {
74 | free((void*)webp_data->bytes);
75 | WebPDataInit(webp_data);
76 | }
77 | }
78 |
79 | // Allocates necessary storage for 'dst' and copies the contents of 'src'.
80 | // Returns true on success.
81 | static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) {
82 | if (src == NULL || dst == NULL) return 0;
83 | WebPDataInit(dst);
84 | if (src->bytes != NULL && src->size != 0) {
85 | dst->bytes = (uint8_t*)malloc(src->size);
86 | if (dst->bytes == NULL) return 0;
87 | memcpy((void*)dst->bytes, src->bytes, src->size);
88 | dst->size = src->size;
89 | }
90 | return 1;
91 | }
92 |
93 | #ifdef __cplusplus
94 | } // extern "C"
95 | #endif
96 |
97 | #endif /* WEBP_WEBP_MUX_TYPES_H_ */
98 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/endian_inl.h:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Endian related functions.
11 |
12 | #ifndef WEBP_UTILS_ENDIAN_INL_H_
13 | #define WEBP_UTILS_ENDIAN_INL_H_
14 |
15 | #ifdef HAVE_CONFIG_H
16 | #include "../webp/config.h"
17 | #endif
18 |
19 | #include "../dsp/dsp.h"
20 | #include "../webp/types.h"
21 |
22 | // some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__)
23 | #if !defined(WORDS_BIGENDIAN) && \
24 | (defined(__BIG_ENDIAN__) || defined(_M_PPC) || \
25 | (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)))
26 | #define WORDS_BIGENDIAN
27 | #endif
28 |
29 | #if defined(WORDS_BIGENDIAN)
30 | #define HToLE32 BSwap32
31 | #define HToLE16 BSwap16
32 | #else
33 | #define HToLE32(x) (x)
34 | #define HToLE16(x) (x)
35 | #endif
36 |
37 | #if !defined(HAVE_CONFIG_H)
38 | #if LOCAL_GCC_PREREQ(4,8) || __has_builtin(__builtin_bswap16)
39 | #define HAVE_BUILTIN_BSWAP16
40 | #endif
41 | #if LOCAL_GCC_PREREQ(4,3) || __has_builtin(__builtin_bswap32)
42 | #define HAVE_BUILTIN_BSWAP32
43 | #endif
44 | #if LOCAL_GCC_PREREQ(4,3) || __has_builtin(__builtin_bswap64)
45 | #define HAVE_BUILTIN_BSWAP64
46 | #endif
47 | #endif // !HAVE_CONFIG_H
48 |
49 | static WEBP_INLINE uint16_t BSwap16(uint16_t x) {
50 | #if defined(HAVE_BUILTIN_BSWAP16)
51 | return __builtin_bswap16(x);
52 | #elif defined(_MSC_VER)
53 | return _byteswap_ushort(x);
54 | #else
55 | // gcc will recognize a 'rorw $8, ...' here:
56 | return (x >> 8) | ((x & 0xff) << 8);
57 | #endif // HAVE_BUILTIN_BSWAP16
58 | }
59 |
60 | static WEBP_INLINE uint32_t BSwap32(uint32_t x) {
61 | #if defined(WEBP_USE_MIPS32_R2)
62 | uint32_t ret;
63 | __asm__ volatile (
64 | "wsbh %[ret], %[x] \n\t"
65 | "rotr %[ret], %[ret], 16 \n\t"
66 | : [ret]"=r"(ret)
67 | : [x]"r"(x)
68 | );
69 | return ret;
70 | #elif defined(HAVE_BUILTIN_BSWAP32)
71 | return __builtin_bswap32(x);
72 | #elif defined(__i386__) || defined(__x86_64__)
73 | uint32_t swapped_bytes;
74 | __asm__ volatile("bswap %0" : "=r"(swapped_bytes) : "0"(x));
75 | return swapped_bytes;
76 | #elif defined(_MSC_VER)
77 | return (uint32_t)_byteswap_ulong(x);
78 | #else
79 | return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24);
80 | #endif // HAVE_BUILTIN_BSWAP32
81 | }
82 |
83 | static WEBP_INLINE uint64_t BSwap64(uint64_t x) {
84 | #if defined(HAVE_BUILTIN_BSWAP64)
85 | return __builtin_bswap64(x);
86 | #elif defined(__x86_64__)
87 | uint64_t swapped_bytes;
88 | __asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x));
89 | return swapped_bytes;
90 | #elif defined(_MSC_VER)
91 | return (uint64_t)_byteswap_uint64(x);
92 | #else // generic code for swapping 64-bit values (suggested by bdb@)
93 | x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32);
94 | x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16);
95 | x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8);
96 | return x;
97 | #endif // HAVE_BUILTIN_BSWAP64
98 | }
99 |
100 | #endif // WEBP_UTILS_ENDIAN_INL_H_
101 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webpbackport/webpbackport.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | #define LOG_TAG "libwebpbackport"
13 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
14 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
15 |
16 | JNIEXPORT jboolean JNICALL Java_de_marcreichelt_webp_1backport_WebPBackport_getInfo(
17 | JNIEnv * env,
18 | jobject obj,
19 | jbyteArray encoded,
20 | jintArray width,
21 | jintArray height
22 | ) {
23 | jbyte* encoded_array;
24 | jsize encoded_length;
25 | int ret, tmpWidth, tmpHeight;
26 | jint elements[] = {0};
27 |
28 | encoded_array = (*env)->GetByteArrayElements(env, encoded, NULL);
29 | encoded_length = (*env)->GetArrayLength(env, encoded);
30 |
31 | ret = WebPGetInfo(encoded_array, encoded_length, &tmpWidth, &tmpHeight);
32 |
33 | (*env)->ReleaseByteArrayElements(env, encoded, encoded_array, JNI_ABORT);
34 |
35 | elements[0] = tmpWidth;
36 | (*env)->SetIntArrayRegion(env, width, 0, 1, elements);
37 | elements[0] = tmpHeight;
38 | (*env)->SetIntArrayRegion(env, height, 0, 1, elements);
39 |
40 | return ret ? JNI_TRUE : JNI_FALSE;
41 | }
42 |
43 | jboolean decodeRGBAIntoInternal(JNIEnv * env, AndroidBitmapInfo info, jbyteArray encoded, jobject bitmap) {
44 | size_t output_buffer_size;
45 | uint8_t* result;
46 | void *pixels;
47 | int ret;
48 | jbyte* encoded_array;
49 | jsize encoded_length;
50 | int width = 0;
51 | int height = 0;
52 |
53 | output_buffer_size = info.height * info.stride;
54 | encoded_array = (*env)->GetByteArrayElements(env, encoded, NULL);
55 | encoded_length = (*env)->GetArrayLength(env, encoded);
56 | ret = WebPGetInfo(encoded_array, encoded_length, &width, &height);
57 |
58 | if (!ret) {
59 | LOGE("unable to get webp info");
60 | return JNI_FALSE;
61 | }
62 | if (info.width != width || info.height != height) {
63 | LOGE("webp size %dx%d does not match bitmap size %dx%d", width, height, info.width, info.height);
64 | return JNI_FALSE;
65 | }
66 |
67 | if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
68 | LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
69 | return JNI_FALSE;
70 | }
71 |
72 | result = WebPDecodergbAInto(encoded_array, encoded_length, (uint8_t*) pixels, output_buffer_size, info.stride);
73 |
74 | AndroidBitmap_unlockPixels(env, bitmap);
75 |
76 | (*env)->ReleaseByteArrayElements(env, encoded, encoded_array, JNI_ABORT);
77 |
78 | return result ? JNI_TRUE : JNI_FALSE;
79 | }
80 |
81 |
82 |
83 | JNIEXPORT jboolean JNICALL Java_de_marcreichelt_webp_1backport_WebPBackport_decodeRGBAInto(
84 | JNIEnv * env,
85 | jobject obj,
86 | jobject bitmap,
87 | jbyteArray encoded
88 | ) {
89 | AndroidBitmapInfo info;
90 | int ret;
91 |
92 | if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
93 | LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
94 | return JNI_FALSE;
95 | }
96 |
97 | if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
98 | LOGE("Bitmap format is not RGBA_8888 !");
99 | return JNI_FALSE;
100 | }
101 |
102 | return decodeRGBAIntoInternal(env, info, encoded, bitmap);
103 | }
104 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/huffman.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Utilities for building and looking up Huffman trees.
11 | //
12 | // Author: Urvang Joshi (urvang@google.com)
13 |
14 | #ifndef WEBP_UTILS_HUFFMAN_H_
15 | #define WEBP_UTILS_HUFFMAN_H_
16 |
17 | #include
18 | #include "../webp/format_constants.h"
19 | #include "../webp/types.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #define HUFFMAN_TABLE_BITS 8
26 | #define HUFFMAN_TABLE_MASK ((1 << HUFFMAN_TABLE_BITS) - 1)
27 |
28 | #define LENGTHS_TABLE_BITS 7
29 | #define LENGTHS_TABLE_MASK ((1 << LENGTHS_TABLE_BITS) - 1)
30 |
31 |
32 | // Huffman lookup table entry
33 | typedef struct {
34 | uint8_t bits; // number of bits used for this symbol
35 | uint16_t value; // symbol value or table offset
36 | } HuffmanCode;
37 |
38 | // long version for holding 32b values
39 | typedef struct {
40 | int bits; // number of bits used for this symbol,
41 | // or an impossible value if not a literal code.
42 | uint32_t value; // 32b packed ARGB value if literal,
43 | // or non-literal symbol otherwise
44 | } HuffmanCode32;
45 |
46 | #define HUFFMAN_PACKED_BITS 6
47 | #define HUFFMAN_PACKED_TABLE_SIZE (1u << HUFFMAN_PACKED_BITS)
48 |
49 | // Huffman table group.
50 | // Includes special handling for the following cases:
51 | // - is_trivial_literal: one common literal base for RED/BLUE/ALPHA (not GREEN)
52 | // - is_trivial_code: only 1 code (no bit is read from bitstream)
53 | // - use_packed_table: few enough literal symbols, so all the bit codes
54 | // can fit into a small look-up table packed_table[]
55 | // The common literal base, if applicable, is stored in 'literal_arb'.
56 | typedef struct HTreeGroup HTreeGroup;
57 | struct HTreeGroup {
58 | HuffmanCode* htrees[HUFFMAN_CODES_PER_META_CODE];
59 | int is_trivial_literal; // True, if huffman trees for Red, Blue & Alpha
60 | // Symbols are trivial (have a single code).
61 | uint32_t literal_arb; // If is_trivial_literal is true, this is the
62 | // ARGB value of the pixel, with Green channel
63 | // being set to zero.
64 | int is_trivial_code; // true if is_trivial_literal with only one code
65 | int use_packed_table; // use packed table below for short literal code
66 | // table mapping input bits to a packed values, or escape case to literal code
67 | HuffmanCode32 packed_table[HUFFMAN_PACKED_TABLE_SIZE];
68 | };
69 |
70 | // Creates the instance of HTreeGroup with specified number of tree-groups.
71 | HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups);
72 |
73 | // Releases the memory allocated for HTreeGroup.
74 | void VP8LHtreeGroupsFree(HTreeGroup* const htree_groups);
75 |
76 | // Builds Huffman lookup table assuming code lengths are in symbol order.
77 | // The 'code_lengths' is pre-allocated temporary memory buffer used for creating
78 | // the huffman table.
79 | // Returns built table size or 0 in case of error (invalid tree or
80 | // memory error).
81 | int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
82 | const int code_lengths[], int code_lengths_size);
83 |
84 | #ifdef __cplusplus
85 | } // extern "C"
86 | #endif
87 |
88 | #endif // WEBP_UTILS_HUFFMAN_H_
89 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/extras/extras.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Additional WebP utilities.
11 | //
12 |
13 | #include "../webp/extras.h"
14 |
15 | #include
16 |
17 | #define XTRA_MAJ_VERSION 0
18 | #define XTRA_MIN_VERSION 0
19 | #define XTRA_REV_VERSION 0
20 |
21 | //------------------------------------------------------------------------------
22 |
23 | int WebPGetExtrasVersion(void) {
24 | return (XTRA_MAJ_VERSION << 16) | (XTRA_MIN_VERSION << 8) | XTRA_REV_VERSION;
25 | }
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | int WebPImportGray(const uint8_t* gray_data, WebPPicture* pic) {
30 | int y, width, uv_width;
31 | if (pic == NULL || gray_data == NULL) return 0;
32 | pic->colorspace = WEBP_YUV420;
33 | if (!WebPPictureAlloc(pic)) return 0;
34 | width = pic->width;
35 | uv_width = (width + 1) >> 1;
36 | for (y = 0; y < pic->height; ++y) {
37 | memcpy(pic->y + y * pic->y_stride, gray_data, width);
38 | gray_data += width; // <- we could use some 'data_stride' here if needed
39 | if ((y & 1) == 0) {
40 | memset(pic->u + (y >> 1) * pic->uv_stride, 128, uv_width);
41 | memset(pic->v + (y >> 1) * pic->uv_stride, 128, uv_width);
42 | }
43 | }
44 | return 1;
45 | }
46 |
47 | int WebPImportRGB565(const uint8_t* rgb565, WebPPicture* pic) {
48 | int x, y;
49 | if (pic == NULL || rgb565 == NULL) return 0;
50 | pic->colorspace = WEBP_YUV420;
51 | pic->use_argb = 1;
52 | if (!WebPPictureAlloc(pic)) return 0;
53 | for (y = 0; y < pic->height; ++y) {
54 | const int width = pic->width;
55 | uint32_t* dst = pic->argb + y * pic->argb_stride;
56 | for (x = 0; x < width; ++x) {
57 | #ifdef WEBP_SWAP_16BIT_CSP
58 | const uint32_t rg = rgb565[2 * x + 1];
59 | const uint32_t gb = rgb565[2 * x + 0];
60 | #else
61 | const uint32_t rg = rgb565[2 * x + 0];
62 | const uint32_t gb = rgb565[2 * x + 1];
63 | #endif
64 | uint32_t r = rg & 0xf8;
65 | uint32_t g = ((rg << 5) | (gb >> 3)) & 0xfc;
66 | uint32_t b = (gb << 5);
67 | // dithering
68 | r = r | (r >> 5);
69 | g = g | (g >> 6);
70 | b = b | (b >> 5);
71 | dst[x] = (r << 16) | (g << 8) | b;
72 | }
73 | rgb565 += 2 * width;
74 | }
75 | return 1;
76 | }
77 |
78 | int WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic) {
79 | int x, y;
80 | if (pic == NULL || rgb4444 == NULL) return 0;
81 | pic->colorspace = WEBP_YUV420;
82 | pic->use_argb = 1;
83 | if (!WebPPictureAlloc(pic)) return 0;
84 | for (y = 0; y < pic->height; ++y) {
85 | const int width = pic->width;
86 | uint32_t* dst = pic->argb + y * pic->argb_stride;
87 | for (x = 0; x < width; ++x) {
88 | #ifdef WEBP_SWAP_16BIT_CSP
89 | const uint32_t rg = rgb4444[2 * x + 1];
90 | const uint32_t ba = rgb4444[2 * x + 0];
91 | #else
92 | const uint32_t rg = rgb4444[2 * x + 0];
93 | const uint32_t ba = rgb4444[2 * x + 1];
94 | #endif
95 | uint32_t r = rg & 0xf0;
96 | uint32_t g = (rg << 4);
97 | uint32_t b = (ba & 0xf0);
98 | uint32_t a = (ba << 4);
99 | // dithering
100 | r = r | (r >> 4);
101 | g = g | (g >> 4);
102 | b = b | (b >> 4);
103 | a = a | (a >> 4);
104 | dst[x] = (a << 24) | (r << 16) | (g << 8) | b;
105 | }
106 | rgb4444 += 2 * width;
107 | }
108 | return 1;
109 | }
110 |
111 | //------------------------------------------------------------------------------
112 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/example_util.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Utility functions used by the example programs.
11 | //
12 |
13 | #ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
14 | #define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
15 |
16 | #include
17 | #include "webp/decode.h"
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | //------------------------------------------------------------------------------
24 | // String parsing
25 |
26 | // Parses 'v' using strto(ul|l|d)(). If error is non-NULL, '*error' is set to
27 | // true on failure while on success it is left unmodified to allow chaining of
28 | // calls. An error is only printed on the first occurrence.
29 | uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
30 | int ExUtilGetInt(const char* const v, int base, int* const error);
31 | float ExUtilGetFloat(const char* const v, int* const error);
32 |
33 | //------------------------------------------------------------------------------
34 | // File I/O
35 |
36 | // Reopen file in binary (O_BINARY) mode.
37 | // Returns 'file' on success, NULL otherwise.
38 | FILE* ExUtilSetBinaryMode(FILE* file);
39 |
40 | // Allocates storage for entire file 'file_name' and returns contents and size
41 | // in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
42 | // be deleted using free().
43 | // If 'file_name' is NULL or equal to "-", input is read from stdin by calling
44 | // the function ExUtilReadFromStdin().
45 | int ExUtilReadFile(const char* const file_name,
46 | const uint8_t** data, size_t* data_size);
47 |
48 | // Same as ExUtilReadFile(), but reads until EOF from stdin instead.
49 | int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
50 |
51 | // Write a data segment into a file named 'file_name'. Returns true if ok.
52 | // If 'file_name' is NULL or equal to "-", output is written to stdout.
53 | int ExUtilWriteFile(const char* const file_name,
54 | const uint8_t* data, size_t data_size);
55 |
56 | //------------------------------------------------------------------------------
57 | // WebP decoding
58 |
59 | // Prints an informative error message regarding decode failure of 'in_file'.
60 | // 'status' is treated as a VP8StatusCode and if valid will be printed as a
61 | // text string.
62 | void ExUtilPrintWebPError(const char* const in_file, int status);
63 |
64 | // Reads a WebP from 'in_file', returning the contents and size in 'data' and
65 | // 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
66 | // Returns true on success.
67 | int ExUtilLoadWebP(const char* const in_file,
68 | const uint8_t** data, size_t* data_size,
69 | WebPBitstreamFeatures* bitstream);
70 |
71 | // Decodes the WebP contained in 'data'.
72 | // 'config' is a structure previously initialized by WebPInitDecoderConfig().
73 | // 'config->output' should have the desired colorspace selected. 'verbose' will
74 | // cause decode timing to be reported.
75 | // Returns the decoder status. On success 'config->output' will contain the
76 | // decoded picture.
77 | VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
78 | int verbose, WebPDecoderConfig* const config);
79 |
80 | // Same as ExUtilDecodeWebP(), but using the incremental decoder.
81 | VP8StatusCode ExUtilDecodeWebPIncremental(
82 | const uint8_t* const data, size_t data_size,
83 | int verbose, WebPDecoderConfig* const config);
84 |
85 | #ifdef __cplusplus
86 | } // extern "C"
87 | #endif
88 |
89 | #endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_
90 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/alpha_processing_sse41.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Utilities for processing transparent channel, SSE4.1 variant.
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #include "./dsp.h"
15 |
16 | #if defined(WEBP_USE_SSE41)
17 |
18 | #include
19 |
20 | //------------------------------------------------------------------------------
21 |
22 | static int ExtractAlpha(const uint8_t* argb, int argb_stride,
23 | int width, int height,
24 | uint8_t* alpha, int alpha_stride) {
25 | // alpha_and stores an 'and' operation of all the alpha[] values. The final
26 | // value is not 0xff if any of the alpha[] is not equal to 0xff.
27 | uint32_t alpha_and = 0xff;
28 | int i, j;
29 | const __m128i all_0xff = _mm_set1_epi32(~0u);
30 | __m128i all_alphas = all_0xff;
31 |
32 | // We must be able to access 3 extra bytes after the last written byte
33 | // 'src[4 * width - 4]', because we don't know if alpha is the first or the
34 | // last byte of the quadruplet.
35 | const int limit = (width - 1) & ~15;
36 | const __m128i kCstAlpha0 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1,
37 | -1, -1, -1, -1, 12, 8, 4, 0);
38 | const __m128i kCstAlpha1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1,
39 | 12, 8, 4, 0, -1, -1, -1, -1);
40 | const __m128i kCstAlpha2 = _mm_set_epi8(-1, -1, -1, -1, 12, 8, 4, 0,
41 | -1, -1, -1, -1, -1, -1, -1, -1);
42 | const __m128i kCstAlpha3 = _mm_set_epi8(12, 8, 4, 0, -1, -1, -1, -1,
43 | -1, -1, -1, -1, -1, -1, -1, -1);
44 | for (j = 0; j < height; ++j) {
45 | const __m128i* src = (const __m128i*)argb;
46 | for (i = 0; i < limit; i += 16) {
47 | // load 64 argb bytes
48 | const __m128i a0 = _mm_loadu_si128(src + 0);
49 | const __m128i a1 = _mm_loadu_si128(src + 1);
50 | const __m128i a2 = _mm_loadu_si128(src + 2);
51 | const __m128i a3 = _mm_loadu_si128(src + 3);
52 | const __m128i b0 = _mm_shuffle_epi8(a0, kCstAlpha0);
53 | const __m128i b1 = _mm_shuffle_epi8(a1, kCstAlpha1);
54 | const __m128i b2 = _mm_shuffle_epi8(a2, kCstAlpha2);
55 | const __m128i b3 = _mm_shuffle_epi8(a3, kCstAlpha3);
56 | const __m128i c0 = _mm_or_si128(b0, b1);
57 | const __m128i c1 = _mm_or_si128(b2, b3);
58 | const __m128i d0 = _mm_or_si128(c0, c1);
59 | // store
60 | _mm_storeu_si128((__m128i*)&alpha[i], d0);
61 | // accumulate sixteen alpha 'and' in parallel
62 | all_alphas = _mm_and_si128(all_alphas, d0);
63 | src += 4;
64 | }
65 | for (; i < width; ++i) {
66 | const uint32_t alpha_value = argb[4 * i];
67 | alpha[i] = alpha_value;
68 | alpha_and &= alpha_value;
69 | }
70 | argb += argb_stride;
71 | alpha += alpha_stride;
72 | }
73 | // Combine the sixteen alpha 'and' into an 8-bit mask.
74 | alpha_and |= 0xff00u; // pretend the upper bits [8..15] were tested ok.
75 | alpha_and &= _mm_movemask_epi8(_mm_cmpeq_epi8(all_alphas, all_0xff));
76 | return (alpha_and == 0xffffu);
77 | }
78 |
79 | //------------------------------------------------------------------------------
80 | // Entry point
81 |
82 | extern void WebPInitAlphaProcessingSSE41(void);
83 |
84 | WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingSSE41(void) {
85 | WebPExtractAlpha = ExtractAlpha;
86 | }
87 |
88 | #else // !WEBP_USE_SSE41
89 |
90 | WEBP_DSP_INIT_STUB(WebPInitAlphaProcessingSSE41)
91 |
92 | #endif // WEBP_USE_SSE41
93 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/thread.h:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Multi-threaded worker
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_UTILS_THREAD_H_
15 | #define WEBP_UTILS_THREAD_H_
16 |
17 | #ifdef HAVE_CONFIG_H
18 | #include "../webp/config.h"
19 | #endif
20 |
21 | #include "../webp/types.h"
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif
26 |
27 | // State of the worker thread object
28 | typedef enum {
29 | NOT_OK = 0, // object is unusable
30 | OK, // ready to work
31 | WORK // busy finishing the current task
32 | } WebPWorkerStatus;
33 |
34 | // Function to be called by the worker thread. Takes two opaque pointers as
35 | // arguments (data1 and data2), and should return false in case of error.
36 | typedef int (*WebPWorkerHook)(void*, void*);
37 |
38 | // Platform-dependent implementation details for the worker.
39 | typedef struct WebPWorkerImpl WebPWorkerImpl;
40 |
41 | // Synchronization object used to launch job in the worker thread
42 | typedef struct {
43 | WebPWorkerImpl* impl_;
44 | WebPWorkerStatus status_;
45 | WebPWorkerHook hook; // hook to call
46 | void* data1; // first argument passed to 'hook'
47 | void* data2; // second argument passed to 'hook'
48 | int had_error; // return value of the last call to 'hook'
49 | } WebPWorker;
50 |
51 | // The interface for all thread-worker related functions. All these functions
52 | // must be implemented.
53 | typedef struct {
54 | // Must be called first, before any other method.
55 | void (*Init)(WebPWorker* const worker);
56 | // Must be called to initialize the object and spawn the thread. Re-entrant.
57 | // Will potentially launch the thread. Returns false in case of error.
58 | int (*Reset)(WebPWorker* const worker);
59 | // Makes sure the previous work is finished. Returns true if worker->had_error
60 | // was not set and no error condition was triggered by the working thread.
61 | int (*Sync)(WebPWorker* const worker);
62 | // Triggers the thread to call hook() with data1 and data2 arguments. These
63 | // hook/data1/data2 values can be changed at any time before calling this
64 | // function, but not be changed afterward until the next call to Sync().
65 | void (*Launch)(WebPWorker* const worker);
66 | // This function is similar to Launch() except that it calls the
67 | // hook directly instead of using a thread. Convenient to bypass the thread
68 | // mechanism while still using the WebPWorker structs. Sync() must
69 | // still be called afterward (for error reporting).
70 | void (*Execute)(WebPWorker* const worker);
71 | // Kill the thread and terminate the object. To use the object again, one
72 | // must call Reset() again.
73 | void (*End)(WebPWorker* const worker);
74 | } WebPWorkerInterface;
75 |
76 | // Install a new set of threading functions, overriding the defaults. This
77 | // should be done before any workers are started, i.e., before any encoding or
78 | // decoding takes place. The contents of the interface struct are copied, it
79 | // is safe to free the corresponding memory after this call. This function is
80 | // not thread-safe. Return false in case of invalid pointer or methods.
81 | WEBP_EXTERN(int) WebPSetWorkerInterface(
82 | const WebPWorkerInterface* const winterface);
83 |
84 | // Retrieve the currently set thread worker interface.
85 | WEBP_EXTERN(const WebPWorkerInterface*) WebPGetWorkerInterface(void);
86 |
87 | //------------------------------------------------------------------------------
88 |
89 | #ifdef __cplusplus
90 | } // extern "C"
91 | #endif
92 |
93 | #endif /* WEBP_UTILS_THREAD_H_ */
94 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/iosbuild.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # This script generates 'WebP.framework'. An iOS app can decode WebP images
4 | # by including 'WebP.framework'.
5 | #
6 | # Run ./iosbuild.sh to generate 'WebP.framework' under the current directory
7 | # (previous build will be erased if it exists).
8 | #
9 | # This script is inspired by the build script written by Carson McDonald.
10 | # (http://www.ioncannon.net/programming/1483/using-webp-to-reduce-native-ios-app-size/).
11 |
12 | set -e
13 |
14 | # Extract the latest SDK version from the final field of the form: iphoneosX.Y
15 | readonly SDK=$(xcodebuild -showsdks \
16 | | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
17 | )
18 | # Extract Xcode version.
19 | readonly XCODE=$(xcodebuild -version | grep Xcode | cut -d " " -f2)
20 | if [[ -z "${XCODE}" ]]; then
21 | echo "Xcode not available"
22 | exit 1
23 | fi
24 |
25 | readonly OLDPATH=${PATH}
26 |
27 | # Add iPhoneOS-V6 to the list of platforms below if you need armv6 support.
28 | # Note that iPhoneOS-V6 support is not available with the iOS6 SDK.
29 | PLATFORMS="iPhoneSimulator iPhoneSimulator64"
30 | PLATFORMS+=" iPhoneOS-V7 iPhoneOS-V7s iPhoneOS-V7-arm64"
31 | readonly PLATFORMS
32 | readonly SRCDIR=$(dirname $0)
33 | readonly TOPDIR=$(pwd)
34 | readonly BUILDDIR="${TOPDIR}/iosbuild"
35 | readonly TARGETDIR="${TOPDIR}/WebP.framework"
36 | readonly DEVELOPER=$(xcode-select --print-path)
37 | readonly PLATFORMSROOT="${DEVELOPER}/Platforms"
38 | readonly LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo)
39 | LIBLIST=''
40 |
41 | if [[ -z "${SDK}" ]]; then
42 | echo "iOS SDK not available"
43 | exit 1
44 | elif [[ ${SDK%%.*} -gt 8 ]]; then
45 | EXTRA_CFLAGS="-fembed-bitcode"
46 | elif [[ ${SDK} < 6.0 ]]; then
47 | echo "You need iOS SDK version 6.0 or above"
48 | exit 1
49 | else
50 | echo "iOS SDK Version ${SDK}"
51 | fi
52 |
53 | rm -rf ${BUILDDIR}
54 | rm -rf ${TARGETDIR}
55 | mkdir -p ${BUILDDIR}
56 | mkdir -p ${TARGETDIR}/Headers/
57 |
58 | if [[ ! -e ${SRCDIR}/configure ]]; then
59 | if ! (cd ${SRCDIR} && sh autogen.sh); then
60 | cat < {
29 |
30 | private static final String ID = "de.marcreichelt.webp_backport.GlideWebPBackportDecoder";
31 | private static final String TAG = GlideWebPBackportDecoder.class.getSimpleName();
32 |
33 | private final Downsampler downsampler;
34 |
35 | private BitmapPool bitmapPool;
36 |
37 | private DecodeFormat decodeFormat;
38 |
39 | private String id;
40 |
41 | @SuppressWarnings("unused")
42 | public GlideWebPBackportDecoder(Context context) {
43 | this(Glide.get(context).getBitmapPool());
44 | }
45 |
46 | public GlideWebPBackportDecoder(BitmapPool bitmapPool) {
47 | this(bitmapPool, DecodeFormat.DEFAULT);
48 | }
49 |
50 | public GlideWebPBackportDecoder(Context context, DecodeFormat decodeFormat) {
51 | this(Glide.get(context).getBitmapPool(), decodeFormat);
52 | }
53 |
54 | public GlideWebPBackportDecoder(BitmapPool bitmapPool, DecodeFormat decodeFormat) {
55 | this(Downsampler.AT_LEAST, bitmapPool, decodeFormat);
56 | }
57 |
58 | public GlideWebPBackportDecoder(Downsampler downsampler, BitmapPool bitmapPool, DecodeFormat decodeFormat) {
59 | this.downsampler = downsampler;
60 | this.bitmapPool = bitmapPool;
61 | this.decodeFormat = decodeFormat;
62 | }
63 |
64 | @Override
65 | public Resource decode(ImageVideoWrapper source, int width, int height) {
66 | final InputStream stream = getMarkSupportingStream(source.getStream());
67 | Bitmap bitmap = WebPBackport.decode(inputStreamToBytes(stream));
68 | BitmapResource bitmapResource = BitmapResource.obtain(bitmap, bitmapPool);
69 | return new GifBitmapWrapperResource(new GifBitmapWrapper(bitmapResource, null));
70 | }
71 |
72 | private InputStream getMarkSupportingStream(InputStream stream) {
73 | if (stream.markSupported()) {
74 | return stream;
75 | } else {
76 | return new BufferedInputStream(stream);
77 | }
78 | }
79 |
80 | @Override
81 | public String getId() {
82 | if (id == null) {
83 | id = ID + downsampler.getId() + decodeFormat.name();
84 | }
85 | return id;
86 | }
87 |
88 | private byte[] inputStreamToBytes(InputStream is) {
89 | final int bufferSize = 16 * 1024;
90 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(bufferSize);
91 | try {
92 | int nRead;
93 | byte[] data = new byte[bufferSize];
94 | while ((nRead = is.read(data)) != -1) {
95 | buffer.write(data, 0, nRead);
96 | }
97 | buffer.flush();
98 | } catch (IOException e) {
99 | Log.w(TAG, "Error reading data from stream", e);
100 | return null;
101 | }
102 | return buffer.toByteArray();
103 | }
104 |
105 | }
106 |
107 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/webp/format_constants.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Internal header for constants related to WebP file format.
11 | //
12 | // Author: Urvang (urvang@google.com)
13 |
14 | #ifndef WEBP_WEBP_FORMAT_CONSTANTS_H_
15 | #define WEBP_WEBP_FORMAT_CONSTANTS_H_
16 |
17 | // Create fourcc of the chunk from the chunk tag characters.
18 | #define MKFOURCC(a, b, c, d) ((a) | (b) << 8 | (c) << 16 | (uint32_t)(d) << 24)
19 |
20 | // VP8 related constants.
21 | #define VP8_SIGNATURE 0x9d012a // Signature in VP8 data.
22 | #define VP8_MAX_PARTITION0_SIZE (1 << 19) // max size of mode partition
23 | #define VP8_MAX_PARTITION_SIZE (1 << 24) // max size for token partition
24 | #define VP8_FRAME_HEADER_SIZE 10 // Size of the frame header within VP8 data.
25 |
26 | // VP8L related constants.
27 | #define VP8L_SIGNATURE_SIZE 1 // VP8L signature size.
28 | #define VP8L_MAGIC_BYTE 0x2f // VP8L signature byte.
29 | #define VP8L_IMAGE_SIZE_BITS 14 // Number of bits used to store
30 | // width and height.
31 | #define VP8L_VERSION_BITS 3 // 3 bits reserved for version.
32 | #define VP8L_VERSION 0 // version 0
33 | #define VP8L_FRAME_HEADER_SIZE 5 // Size of the VP8L frame header.
34 |
35 | #define MAX_PALETTE_SIZE 256
36 | #define MAX_CACHE_BITS 11
37 | #define HUFFMAN_CODES_PER_META_CODE 5
38 | #define ARGB_BLACK 0xff000000
39 |
40 | #define DEFAULT_CODE_LENGTH 8
41 | #define MAX_ALLOWED_CODE_LENGTH 15
42 |
43 | #define NUM_LITERAL_CODES 256
44 | #define NUM_LENGTH_CODES 24
45 | #define NUM_DISTANCE_CODES 40
46 | #define CODE_LENGTH_CODES 19
47 |
48 | #define MIN_HUFFMAN_BITS 2 // min number of Huffman bits
49 | #define MAX_HUFFMAN_BITS 9 // max number of Huffman bits
50 |
51 | #define TRANSFORM_PRESENT 1 // The bit to be written when next data
52 | // to be read is a transform.
53 | #define NUM_TRANSFORMS 4 // Maximum number of allowed transform
54 | // in a bitstream.
55 | typedef enum {
56 | PREDICTOR_TRANSFORM = 0,
57 | CROSS_COLOR_TRANSFORM = 1,
58 | SUBTRACT_GREEN = 2,
59 | COLOR_INDEXING_TRANSFORM = 3
60 | } VP8LImageTransformType;
61 |
62 | // Alpha related constants.
63 | #define ALPHA_HEADER_LEN 1
64 | #define ALPHA_NO_COMPRESSION 0
65 | #define ALPHA_LOSSLESS_COMPRESSION 1
66 | #define ALPHA_PREPROCESSED_LEVELS 1
67 |
68 | // Mux related constants.
69 | #define TAG_SIZE 4 // Size of a chunk tag (e.g. "VP8L").
70 | #define CHUNK_SIZE_BYTES 4 // Size needed to store chunk's size.
71 | #define CHUNK_HEADER_SIZE 8 // Size of a chunk header.
72 | #define RIFF_HEADER_SIZE 12 // Size of the RIFF header ("RIFFnnnnWEBP").
73 | #define ANMF_CHUNK_SIZE 16 // Size of an ANMF chunk.
74 | #define ANIM_CHUNK_SIZE 6 // Size of an ANIM chunk.
75 | #define FRGM_CHUNK_SIZE 6 // Size of a FRGM chunk.
76 | #define VP8X_CHUNK_SIZE 10 // Size of a VP8X chunk.
77 |
78 | #define MAX_CANVAS_SIZE (1 << 24) // 24-bit max for VP8X width/height.
79 | #define MAX_IMAGE_AREA (1ULL << 32) // 32-bit max for width x height.
80 | #define MAX_LOOP_COUNT (1 << 16) // maximum value for loop-count
81 | #define MAX_DURATION (1 << 24) // maximum duration
82 | #define MAX_POSITION_OFFSET (1 << 24) // maximum frame/fragment x/y offset
83 |
84 | // Maximum chunk payload is such that adding the header and padding won't
85 | // overflow a uint32_t.
86 | #define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1)
87 |
88 | #endif /* WEBP_WEBP_FORMAT_CONSTANTS_H_ */
89 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dec/quant.c:
--------------------------------------------------------------------------------
1 | // Copyright 2010 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Quantizer initialization
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #include "./vp8i.h"
15 |
16 | static WEBP_INLINE int clip(int v, int M) {
17 | return v < 0 ? 0 : v > M ? M : v;
18 | }
19 |
20 | // Paragraph 14.1
21 | static const uint8_t kDcTable[128] = {
22 | 4, 5, 6, 7, 8, 9, 10, 10,
23 | 11, 12, 13, 14, 15, 16, 17, 17,
24 | 18, 19, 20, 20, 21, 21, 22, 22,
25 | 23, 23, 24, 25, 25, 26, 27, 28,
26 | 29, 30, 31, 32, 33, 34, 35, 36,
27 | 37, 37, 38, 39, 40, 41, 42, 43,
28 | 44, 45, 46, 46, 47, 48, 49, 50,
29 | 51, 52, 53, 54, 55, 56, 57, 58,
30 | 59, 60, 61, 62, 63, 64, 65, 66,
31 | 67, 68, 69, 70, 71, 72, 73, 74,
32 | 75, 76, 76, 77, 78, 79, 80, 81,
33 | 82, 83, 84, 85, 86, 87, 88, 89,
34 | 91, 93, 95, 96, 98, 100, 101, 102,
35 | 104, 106, 108, 110, 112, 114, 116, 118,
36 | 122, 124, 126, 128, 130, 132, 134, 136,
37 | 138, 140, 143, 145, 148, 151, 154, 157
38 | };
39 |
40 | static const uint16_t kAcTable[128] = {
41 | 4, 5, 6, 7, 8, 9, 10, 11,
42 | 12, 13, 14, 15, 16, 17, 18, 19,
43 | 20, 21, 22, 23, 24, 25, 26, 27,
44 | 28, 29, 30, 31, 32, 33, 34, 35,
45 | 36, 37, 38, 39, 40, 41, 42, 43,
46 | 44, 45, 46, 47, 48, 49, 50, 51,
47 | 52, 53, 54, 55, 56, 57, 58, 60,
48 | 62, 64, 66, 68, 70, 72, 74, 76,
49 | 78, 80, 82, 84, 86, 88, 90, 92,
50 | 94, 96, 98, 100, 102, 104, 106, 108,
51 | 110, 112, 114, 116, 119, 122, 125, 128,
52 | 131, 134, 137, 140, 143, 146, 149, 152,
53 | 155, 158, 161, 164, 167, 170, 173, 177,
54 | 181, 185, 189, 193, 197, 201, 205, 209,
55 | 213, 217, 221, 225, 229, 234, 239, 245,
56 | 249, 254, 259, 264, 269, 274, 279, 284
57 | };
58 |
59 | //------------------------------------------------------------------------------
60 | // Paragraph 9.6
61 |
62 | void VP8ParseQuant(VP8Decoder* const dec) {
63 | VP8BitReader* const br = &dec->br_;
64 | const int base_q0 = VP8GetValue(br, 7);
65 | const int dqy1_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;
66 | const int dqy2_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;
67 | const int dqy2_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;
68 | const int dquv_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;
69 | const int dquv_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0;
70 |
71 | const VP8SegmentHeader* const hdr = &dec->segment_hdr_;
72 | int i;
73 |
74 | for (i = 0; i < NUM_MB_SEGMENTS; ++i) {
75 | int q;
76 | if (hdr->use_segment_) {
77 | q = hdr->quantizer_[i];
78 | if (!hdr->absolute_delta_) {
79 | q += base_q0;
80 | }
81 | } else {
82 | if (i > 0) {
83 | dec->dqm_[i] = dec->dqm_[0];
84 | continue;
85 | } else {
86 | q = base_q0;
87 | }
88 | }
89 | {
90 | VP8QuantMatrix* const m = &dec->dqm_[i];
91 | m->y1_mat_[0] = kDcTable[clip(q + dqy1_dc, 127)];
92 | m->y1_mat_[1] = kAcTable[clip(q + 0, 127)];
93 |
94 | m->y2_mat_[0] = kDcTable[clip(q + dqy2_dc, 127)] * 2;
95 | // For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
96 | // The smallest precision for that is '(x*6349) >> 12' but 16 is a good
97 | // word size.
98 | m->y2_mat_[1] = (kAcTable[clip(q + dqy2_ac, 127)] * 101581) >> 16;
99 | if (m->y2_mat_[1] < 8) m->y2_mat_[1] = 8;
100 |
101 | m->uv_mat_[0] = kDcTable[clip(q + dquv_dc, 117)];
102 | m->uv_mat_[1] = kAcTable[clip(q + dquv_ac, 127)];
103 |
104 | m->uv_quant_ = q + dquv_ac; // for dithering strength evaluation
105 | }
106 | }
107 | }
108 |
109 | //------------------------------------------------------------------------------
110 |
111 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/rescaler.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Rescaling functions
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #ifndef WEBP_UTILS_RESCALER_H_
15 | #define WEBP_UTILS_RESCALER_H_
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | #include "../webp/types.h"
22 |
23 | #define WEBP_RESCALER_RFIX 32 // fixed-point precision for multiplies
24 | #define WEBP_RESCALER_ONE (1ull << WEBP_RESCALER_RFIX)
25 | #define WEBP_RESCALER_FRAC(x, y) \
26 | ((uint32_t)(((uint64_t)(x) << WEBP_RESCALER_RFIX) / (y)))
27 |
28 | // Structure used for on-the-fly rescaling
29 | typedef uint32_t rescaler_t; // type for side-buffer
30 | typedef struct WebPRescaler WebPRescaler;
31 | struct WebPRescaler {
32 | int x_expand; // true if we're expanding in the x direction
33 | int y_expand; // true if we're expanding in the y direction
34 | int num_channels; // bytes to jump between pixels
35 | uint32_t fx_scale; // fixed-point scaling factors
36 | uint32_t fy_scale; // ''
37 | uint32_t fxy_scale; // ''
38 | int y_accum; // vertical accumulator
39 | int y_add, y_sub; // vertical increments
40 | int x_add, x_sub; // horizontal increments
41 | int src_width, src_height; // source dimensions
42 | int dst_width, dst_height; // destination dimensions
43 | int src_y, dst_y; // row counters for input and output
44 | uint8_t* dst;
45 | int dst_stride;
46 | rescaler_t* irow, *frow; // work buffer
47 | };
48 |
49 | // Initialize a rescaler given scratch area 'work' and dimensions of src & dst.
50 | void WebPRescalerInit(WebPRescaler* const rescaler,
51 | int src_width, int src_height,
52 | uint8_t* const dst,
53 | int dst_width, int dst_height, int dst_stride,
54 | int num_channels,
55 | rescaler_t* const work);
56 |
57 | // If either 'scaled_width' or 'scaled_height' (but not both) is 0 the value
58 | // will be calculated preserving the aspect ratio, otherwise the values are
59 | // left unmodified. Returns true on success, false if either value is 0 after
60 | // performing the scaling calculation.
61 | int WebPRescalerGetScaledDimensions(int src_width, int src_height,
62 | int* const scaled_width,
63 | int* const scaled_height);
64 |
65 | // Returns the number of input lines needed next to produce one output line,
66 | // considering that the maximum available input lines are 'max_num_lines'.
67 | int WebPRescaleNeededLines(const WebPRescaler* const rescaler,
68 | int max_num_lines);
69 |
70 | // Import multiple rows over all channels, until at least one row is ready to
71 | // be exported. Returns the actual number of lines that were imported.
72 | int WebPRescalerImport(WebPRescaler* const rescaler, int num_rows,
73 | const uint8_t* src, int src_stride);
74 |
75 | // Export as many rows as possible. Return the numbers of rows written.
76 | int WebPRescalerExport(WebPRescaler* const rescaler);
77 |
78 | // Return true if input is finished
79 | static WEBP_INLINE
80 | int WebPRescalerInputDone(const WebPRescaler* const rescaler) {
81 | return (rescaler->src_y >= rescaler->src_height);
82 | }
83 | // Return true if output is finished
84 | static WEBP_INLINE
85 | int WebPRescalerOutputDone(const WebPRescaler* const rescaler) {
86 | return (rescaler->dst_y >= rescaler->dst_height);
87 | }
88 |
89 | // Return true if there are pending output rows ready.
90 | static WEBP_INLINE
91 | int WebPRescalerHasPendingOutput(const WebPRescaler* const rescaler) {
92 | return !WebPRescalerOutputDone(rescaler) && (rescaler->y_accum <= 0);
93 | }
94 |
95 | //------------------------------------------------------------------------------
96 |
97 | #ifdef __cplusplus
98 | } // extern "C"
99 | #endif
100 |
101 | #endif /* WEBP_UTILS_RESCALER_H_ */
102 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/examples/gifdec.h:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // GIF decode.
11 |
12 | #ifndef WEBP_EXAMPLES_GIFDEC_H_
13 | #define WEBP_EXAMPLES_GIFDEC_H_
14 |
15 | #include
16 | #include "webp/types.h"
17 |
18 | #ifdef HAVE_CONFIG_H
19 | #include "webp/config.h"
20 | #endif
21 |
22 | #ifdef WEBP_HAVE_GIF
23 | #include
24 | #endif
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | // GIFLIB_MAJOR is only defined in libgif >= 4.2.0.
31 | #if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR)
32 | # define LOCAL_GIF_VERSION ((GIFLIB_MAJOR << 8) | GIFLIB_MINOR)
33 | # define LOCAL_GIF_PREREQ(maj, min) \
34 | (LOCAL_GIF_VERSION >= (((maj) << 8) | (min)))
35 | #else
36 | # define LOCAL_GIF_VERSION 0
37 | # define LOCAL_GIF_PREREQ(maj, min) 0
38 | #endif
39 |
40 | #define GIF_INDEX_INVALID (-1)
41 |
42 | typedef enum GIFDisposeMethod {
43 | GIF_DISPOSE_NONE,
44 | GIF_DISPOSE_BACKGROUND,
45 | GIF_DISPOSE_RESTORE_PREVIOUS
46 | } GIFDisposeMethod;
47 |
48 | typedef struct {
49 | int x_offset, y_offset, width, height;
50 | } GIFFrameRect;
51 |
52 | struct WebPData;
53 | struct WebPPicture;
54 |
55 | #ifndef WEBP_HAVE_GIF
56 | struct ColorMapObject;
57 | struct GifFileType;
58 | typedef unsigned char GifByteType;
59 | #endif
60 |
61 | // Given the index of background color and transparent color, returns the
62 | // corresponding background color (in BGRA format) in 'bgcolor'.
63 | void GIFGetBackgroundColor(const struct ColorMapObject* const color_map,
64 | int bgcolor_index, int transparent_index,
65 | uint32_t* const bgcolor);
66 |
67 | // Parses the given graphics extension data to get frame duration (in 1ms
68 | // units), dispose method and transparent color index.
69 | // Returns true on success.
70 | int GIFReadGraphicsExtension(const GifByteType* const buf, int* const duration,
71 | GIFDisposeMethod* const dispose,
72 | int* const transparent_index);
73 |
74 | // Reads the next GIF frame from 'gif' into 'picture'. Also, returns the GIF
75 | // frame dimensions and offsets in 'rect'.
76 | // Returns true on success.
77 | int GIFReadFrame(struct GifFileType* const gif, int transparent_index,
78 | GIFFrameRect* const gif_rect,
79 | struct WebPPicture* const picture);
80 |
81 | // Parses loop count from the given Netscape extension data.
82 | int GIFReadLoopCount(struct GifFileType* const gif, GifByteType** const buf,
83 | int* const loop_count);
84 |
85 | // Parses the given ICC or XMP extension data and stores it into 'metadata'.
86 | // Returns true on success.
87 | int GIFReadMetadata(struct GifFileType* const gif, GifByteType** const buf,
88 | struct WebPData* const metadata);
89 |
90 | // Dispose the pixels within 'rect' of 'curr_canvas' based on 'dispose' method
91 | // and 'prev_canvas'.
92 | void GIFDisposeFrame(GIFDisposeMethod dispose, const GIFFrameRect* const rect,
93 | const struct WebPPicture* const prev_canvas,
94 | struct WebPPicture* const curr_canvas);
95 |
96 | // Given 'src' picture and its frame rectangle 'rect', blend it into 'dst'.
97 | void GIFBlendFrames(const struct WebPPicture* const src,
98 | const GIFFrameRect* const rect,
99 | struct WebPPicture* const dst);
100 |
101 | // Prints an error string based on 'gif_error'.
102 | void GIFDisplayError(const struct GifFileType* const gif, int gif_error);
103 |
104 | // In the given 'pic', clear the pixels in 'rect' to transparent color.
105 | void GIFClearPic(struct WebPPicture* const pic, const GIFFrameRect* const rect);
106 |
107 | // Copy pixels from 'src' to 'dst' honoring strides. 'src' and 'dst' are assumed
108 | // to be already allocated.
109 | void GIFCopyPixels(const struct WebPPicture* const src,
110 | struct WebPPicture* const dst);
111 |
112 | #ifdef __cplusplus
113 | } // extern "C"
114 | #endif
115 |
116 | #endif // WEBP_EXAMPLES_GIFDEC_H_
117 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/Makefile.am:
--------------------------------------------------------------------------------
1 | noinst_LTLIBRARIES = libwebpdsp.la libwebpdsp_avx2.la
2 | noinst_LTLIBRARIES += libwebpdsp_sse2.la libwebpdspdecode_sse2.la
3 | noinst_LTLIBRARIES += libwebpdsp_sse41.la libwebpdspdecode_sse41.la
4 |
5 | if BUILD_LIBWEBPDECODER
6 | noinst_LTLIBRARIES += libwebpdspdecode.la
7 | endif
8 |
9 | common_HEADERS = ../webp/types.h
10 | commondir = $(includedir)/webp
11 |
12 | COMMON_SOURCES =
13 | COMMON_SOURCES += alpha_processing.c
14 | COMMON_SOURCES += alpha_processing_mips_dsp_r2.c
15 | COMMON_SOURCES += cpu.c
16 | COMMON_SOURCES += dec.c
17 | COMMON_SOURCES += dec_clip_tables.c
18 | COMMON_SOURCES += dec_mips32.c
19 | COMMON_SOURCES += dec_mips_dsp_r2.c
20 | COMMON_SOURCES += dec_neon.c
21 | COMMON_SOURCES += dsp.h
22 | COMMON_SOURCES += filters.c
23 | COMMON_SOURCES += filters_mips_dsp_r2.c
24 | COMMON_SOURCES += lossless.c
25 | COMMON_SOURCES += lossless.h
26 | COMMON_SOURCES += lossless_mips_dsp_r2.c
27 | COMMON_SOURCES += lossless_neon.c
28 | COMMON_SOURCES += mips_macro.h
29 | COMMON_SOURCES += neon.h
30 | COMMON_SOURCES += rescaler.c
31 | COMMON_SOURCES += rescaler_mips32.c
32 | COMMON_SOURCES += rescaler_mips_dsp_r2.c
33 | COMMON_SOURCES += rescaler_neon.c
34 | COMMON_SOURCES += upsampling.c
35 | COMMON_SOURCES += upsampling_mips_dsp_r2.c
36 | COMMON_SOURCES += upsampling_neon.c
37 | COMMON_SOURCES += yuv.c
38 | COMMON_SOURCES += yuv.h
39 | COMMON_SOURCES += yuv_mips32.c
40 | COMMON_SOURCES += yuv_mips_dsp_r2.c
41 |
42 | ENC_SOURCES =
43 | ENC_SOURCES += argb.c
44 | ENC_SOURCES += argb_mips_dsp_r2.c
45 | ENC_SOURCES += cost.c
46 | ENC_SOURCES += cost_mips32.c
47 | ENC_SOURCES += cost_mips_dsp_r2.c
48 | ENC_SOURCES += enc.c
49 | ENC_SOURCES += enc_mips32.c
50 | ENC_SOURCES += enc_mips_dsp_r2.c
51 | ENC_SOURCES += enc_neon.c
52 | ENC_SOURCES += lossless_enc.c
53 | ENC_SOURCES += lossless_enc_mips32.c
54 | ENC_SOURCES += lossless_enc_mips_dsp_r2.c
55 | ENC_SOURCES += lossless_enc_neon.c
56 |
57 | libwebpdsp_avx2_la_SOURCES =
58 | libwebpdsp_avx2_la_SOURCES += enc_avx2.c
59 | libwebpdsp_avx2_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
60 | libwebpdsp_avx2_la_CFLAGS = $(AM_CFLAGS) $(AVX2_FLAGS)
61 |
62 | libwebpdspdecode_sse41_la_SOURCES =
63 | libwebpdspdecode_sse41_la_SOURCES += alpha_processing_sse41.c
64 | libwebpdspdecode_sse41_la_SOURCES += dec_sse41.c
65 | libwebpdspdecode_sse41_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
66 | libwebpdspdecode_sse41_la_CFLAGS = $(AM_CFLAGS) $(SSE41_FLAGS)
67 |
68 | libwebpdspdecode_sse2_la_SOURCES =
69 | libwebpdspdecode_sse2_la_SOURCES += alpha_processing_sse2.c
70 | libwebpdspdecode_sse2_la_SOURCES += dec_sse2.c
71 | libwebpdspdecode_sse2_la_SOURCES += filters_sse2.c
72 | libwebpdspdecode_sse2_la_SOURCES += lossless_sse2.c
73 | libwebpdspdecode_sse2_la_SOURCES += rescaler_sse2.c
74 | libwebpdspdecode_sse2_la_SOURCES += upsampling_sse2.c
75 | libwebpdspdecode_sse2_la_SOURCES += yuv_sse2.c
76 | libwebpdspdecode_sse2_la_CPPFLAGS = $(libwebpdsp_sse2_la_CPPFLAGS)
77 | libwebpdspdecode_sse2_la_CFLAGS = $(libwebpdsp_sse2_la_CFLAGS)
78 |
79 | libwebpdsp_sse2_la_SOURCES =
80 | libwebpdsp_sse2_la_SOURCES += argb_sse2.c
81 | libwebpdsp_sse2_la_SOURCES += cost_sse2.c
82 | libwebpdsp_sse2_la_SOURCES += enc_sse2.c
83 | libwebpdsp_sse2_la_SOURCES += lossless_enc_sse2.c
84 | libwebpdsp_sse2_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
85 | libwebpdsp_sse2_la_CFLAGS = $(AM_CFLAGS) $(SSE2_FLAGS)
86 | libwebpdsp_sse2_la_LIBADD = libwebpdspdecode_sse2.la
87 |
88 | libwebpdsp_sse41_la_SOURCES =
89 | libwebpdsp_sse41_la_SOURCES += enc_sse41.c
90 | libwebpdsp_sse41_la_SOURCES += lossless_enc_sse41.c
91 | libwebpdsp_sse41_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
92 | libwebpdsp_sse41_la_CFLAGS = $(AM_CFLAGS) $(SSE41_FLAGS)
93 | libwebpdsp_sse41_la_LIBADD = libwebpdspdecode_sse41.la
94 |
95 | libwebpdsp_la_SOURCES = $(COMMON_SOURCES) $(ENC_SOURCES)
96 |
97 | noinst_HEADERS =
98 | noinst_HEADERS += ../dec/decode_vp8.h
99 | noinst_HEADERS += ../webp/decode.h
100 |
101 | libwebpdsp_la_CPPFLAGS =
102 | libwebpdsp_la_CPPFLAGS += $(AM_CPPFLAGS)
103 | libwebpdsp_la_CPPFLAGS += $(USE_EXPERIMENTAL_CODE) $(USE_SWAP_16BIT_CSP)
104 | libwebpdsp_la_LDFLAGS = -lm
105 | libwebpdsp_la_LIBADD =
106 | libwebpdsp_la_LIBADD += libwebpdsp_avx2.la libwebpdsp_sse2.la
107 | libwebpdsp_la_LIBADD += libwebpdsp_sse41.la
108 |
109 | if BUILD_LIBWEBPDECODER
110 | libwebpdspdecode_la_SOURCES = $(COMMON_SOURCES)
111 |
112 | libwebpdspdecode_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
113 | libwebpdspdecode_la_LDFLAGS = $(libwebpdsp_la_LDFLAGS)
114 | libwebpdspdecode_la_LIBADD =
115 | libwebpdspdecode_la_LIBADD += libwebpdspdecode_sse2.la
116 | libwebpdspdecode_la_LIBADD += libwebpdspdecode_sse41.la
117 | endif
118 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/utils/quant_levels.c:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Quantize levels for specified number of quantization-levels ([2, 256]).
11 | // Min and max values are preserved (usual 0 and 255 for alpha plane).
12 | //
13 | // Author: Skal (pascal.massimino@gmail.com)
14 |
15 | #include
16 |
17 | #include "./quant_levels.h"
18 |
19 | #define NUM_SYMBOLS 256
20 |
21 | #define MAX_ITER 6 // Maximum number of convergence steps.
22 | #define ERROR_THRESHOLD 1e-4 // MSE stopping criterion.
23 |
24 | // -----------------------------------------------------------------------------
25 | // Quantize levels.
26 |
27 | int QuantizeLevels(uint8_t* const data, int width, int height,
28 | int num_levels, uint64_t* const sse) {
29 | int freq[NUM_SYMBOLS] = { 0 };
30 | int q_level[NUM_SYMBOLS] = { 0 };
31 | double inv_q_level[NUM_SYMBOLS] = { 0 };
32 | int min_s = 255, max_s = 0;
33 | const size_t data_size = height * width;
34 | int i, num_levels_in, iter;
35 | double last_err = 1.e38, err = 0.;
36 | const double err_threshold = ERROR_THRESHOLD * data_size;
37 |
38 | if (data == NULL) {
39 | return 0;
40 | }
41 |
42 | if (width <= 0 || height <= 0) {
43 | return 0;
44 | }
45 |
46 | if (num_levels < 2 || num_levels > 256) {
47 | return 0;
48 | }
49 |
50 | {
51 | size_t n;
52 | num_levels_in = 0;
53 | for (n = 0; n < data_size; ++n) {
54 | num_levels_in += (freq[data[n]] == 0);
55 | if (min_s > data[n]) min_s = data[n];
56 | if (max_s < data[n]) max_s = data[n];
57 | ++freq[data[n]];
58 | }
59 | }
60 |
61 | if (num_levels_in <= num_levels) goto End; // nothing to do!
62 |
63 | // Start with uniformly spread centroids.
64 | for (i = 0; i < num_levels; ++i) {
65 | inv_q_level[i] = min_s + (double)(max_s - min_s) * i / (num_levels - 1);
66 | }
67 |
68 | // Fixed values. Won't be changed.
69 | q_level[min_s] = 0;
70 | q_level[max_s] = num_levels - 1;
71 | assert(inv_q_level[0] == min_s);
72 | assert(inv_q_level[num_levels - 1] == max_s);
73 |
74 | // k-Means iterations.
75 | for (iter = 0; iter < MAX_ITER; ++iter) {
76 | double q_sum[NUM_SYMBOLS] = { 0 };
77 | double q_count[NUM_SYMBOLS] = { 0 };
78 | int s, slot = 0;
79 |
80 | // Assign classes to representatives.
81 | for (s = min_s; s <= max_s; ++s) {
82 | // Keep track of the nearest neighbour 'slot'
83 | while (slot < num_levels - 1 &&
84 | 2 * s > inv_q_level[slot] + inv_q_level[slot + 1]) {
85 | ++slot;
86 | }
87 | if (freq[s] > 0) {
88 | q_sum[slot] += s * freq[s];
89 | q_count[slot] += freq[s];
90 | }
91 | q_level[s] = slot;
92 | }
93 |
94 | // Assign new representatives to classes.
95 | if (num_levels > 2) {
96 | for (slot = 1; slot < num_levels - 1; ++slot) {
97 | const double count = q_count[slot];
98 | if (count > 0.) {
99 | inv_q_level[slot] = q_sum[slot] / count;
100 | }
101 | }
102 | }
103 |
104 | // Compute convergence error.
105 | err = 0.;
106 | for (s = min_s; s <= max_s; ++s) {
107 | const double error = s - inv_q_level[q_level[s]];
108 | err += freq[s] * error * error;
109 | }
110 |
111 | // Check for convergence: we stop as soon as the error is no
112 | // longer improving.
113 | if (last_err - err < err_threshold) break;
114 | last_err = err;
115 | }
116 |
117 | // Remap the alpha plane to quantized values.
118 | {
119 | // double->int rounding operation can be costly, so we do it
120 | // once for all before remapping. We also perform the data[] -> slot
121 | // mapping, while at it (avoid one indirection in the final loop).
122 | uint8_t map[NUM_SYMBOLS];
123 | int s;
124 | size_t n;
125 | for (s = min_s; s <= max_s; ++s) {
126 | const int slot = q_level[s];
127 | map[s] = (uint8_t)(inv_q_level[slot] + .5);
128 | }
129 | // Final pass.
130 | for (n = 0; n < data_size; ++n) {
131 | data[n] = map[data[n]];
132 | }
133 | }
134 | End:
135 | // Store sum of squared error if needed.
136 | if (sse != NULL) *sse = (uint64_t)err;
137 |
138 | return 1;
139 | }
140 |
141 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/cost_sse2.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // SSE2 version of cost functions
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 |
14 | #include "./dsp.h"
15 |
16 | #if defined(WEBP_USE_SSE2)
17 | #include
18 |
19 | #include "../enc/cost.h"
20 | #include "../enc/vp8enci.h"
21 | #include "../utils/utils.h"
22 |
23 | //------------------------------------------------------------------------------
24 |
25 | static void SetResidualCoeffsSSE2(const int16_t* const coeffs,
26 | VP8Residual* const res) {
27 | const __m128i c0 = _mm_loadu_si128((const __m128i*)(coeffs + 0));
28 | const __m128i c1 = _mm_loadu_si128((const __m128i*)(coeffs + 8));
29 | // Use SSE2 to compare 16 values with a single instruction.
30 | const __m128i zero = _mm_setzero_si128();
31 | const __m128i m0 = _mm_packs_epi16(c0, c1);
32 | const __m128i m1 = _mm_cmpeq_epi8(m0, zero);
33 | // Get the comparison results as a bitmask into 16bits. Negate the mask to get
34 | // the position of entries that are not equal to zero. We don't need to mask
35 | // out least significant bits according to res->first, since coeffs[0] is 0
36 | // if res->first > 0.
37 | const uint32_t mask = 0x0000ffffu ^ (uint32_t)_mm_movemask_epi8(m1);
38 | // The position of the most significant non-zero bit indicates the position of
39 | // the last non-zero value.
40 | assert(res->first == 0 || coeffs[0] == 0);
41 | res->last = mask ? BitsLog2Floor(mask) : -1;
42 | res->coeffs = coeffs;
43 | }
44 |
45 | static int GetResidualCostSSE2(int ctx0, const VP8Residual* const res) {
46 | uint8_t levels[16], ctxs[16];
47 | uint16_t abs_levels[16];
48 | int n = res->first;
49 | // should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
50 | const int p0 = res->prob[n][ctx0][0];
51 | CostArrayPtr const costs = res->costs;
52 | const uint16_t* t = costs[n][ctx0];
53 | // bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 0
54 | // (as required by the syntax). For ctx0 == 0, we need to add it here or it'll
55 | // be missing during the loop.
56 | int cost = (ctx0 == 0) ? VP8BitCost(1, p0) : 0;
57 |
58 | if (res->last < 0) {
59 | return VP8BitCost(0, p0);
60 | }
61 |
62 | { // precompute clamped levels and contexts, packed to 8b.
63 | const __m128i zero = _mm_setzero_si128();
64 | const __m128i kCst2 = _mm_set1_epi8(2);
65 | const __m128i kCst67 = _mm_set1_epi8(MAX_VARIABLE_LEVEL);
66 | const __m128i c0 = _mm_loadu_si128((const __m128i*)&res->coeffs[0]);
67 | const __m128i c1 = _mm_loadu_si128((const __m128i*)&res->coeffs[8]);
68 | const __m128i D0 = _mm_sub_epi16(zero, c0);
69 | const __m128i D1 = _mm_sub_epi16(zero, c1);
70 | const __m128i E0 = _mm_max_epi16(c0, D0); // abs(v), 16b
71 | const __m128i E1 = _mm_max_epi16(c1, D1);
72 | const __m128i F = _mm_packs_epi16(E0, E1);
73 | const __m128i G = _mm_min_epu8(F, kCst2); // context = 0,1,2
74 | const __m128i H = _mm_min_epu8(F, kCst67); // clamp_level in [0..67]
75 |
76 | _mm_storeu_si128((__m128i*)&ctxs[0], G);
77 | _mm_storeu_si128((__m128i*)&levels[0], H);
78 |
79 | _mm_storeu_si128((__m128i*)&abs_levels[0], E0);
80 | _mm_storeu_si128((__m128i*)&abs_levels[8], E1);
81 | }
82 | for (; n < res->last; ++n) {
83 | const int ctx = ctxs[n];
84 | const int level = levels[n];
85 | const int flevel = abs_levels[n]; // full level
86 | cost += VP8LevelFixedCosts[flevel] + t[level]; // simplified VP8LevelCost()
87 | t = costs[n + 1][ctx];
88 | }
89 | // Last coefficient is always non-zero
90 | {
91 | const int level = levels[n];
92 | const int flevel = abs_levels[n];
93 | assert(flevel != 0);
94 | cost += VP8LevelFixedCosts[flevel] + t[level];
95 | if (n < 15) {
96 | const int b = VP8EncBands[n + 1];
97 | const int ctx = ctxs[n];
98 | const int last_p0 = res->prob[b][ctx][0];
99 | cost += VP8BitCost(0, last_p0);
100 | }
101 | }
102 | return cost;
103 | }
104 |
105 | //------------------------------------------------------------------------------
106 | // Entry point
107 |
108 | extern void VP8EncDspCostInitSSE2(void);
109 |
110 | WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspCostInitSSE2(void) {
111 | VP8SetResidualCoeffs = SetResidualCoeffsSSE2;
112 | VP8GetResidualCost = GetResidualCostSSE2;
113 | }
114 |
115 | #else // !WEBP_USE_SSE2
116 |
117 | WEBP_DSP_INIT_STUB(VP8EncDspCostInitSSE2)
118 |
119 | #endif // WEBP_USE_SSE2
120 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dsp/cost_mips_dsp_r2.c:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Author: Djordje Pesut (djordje.pesut@imgtec.com)
11 |
12 | #include "./dsp.h"
13 |
14 | #if defined(WEBP_USE_MIPS_DSP_R2)
15 |
16 | #include "../enc/cost.h"
17 |
18 | static int GetResidualCost(int ctx0, const VP8Residual* const res) {
19 | int temp0, temp1;
20 | int v_reg, ctx_reg;
21 | int n = res->first;
22 | // should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
23 | int p0 = res->prob[n][ctx0][0];
24 | CostArrayPtr const costs = res->costs;
25 | const uint16_t* t = costs[n][ctx0];
26 | // bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 0
27 | // (as required by the syntax). For ctx0 == 0, we need to add it here or it'll
28 | // be missing during the loop.
29 | int cost = (ctx0 == 0) ? VP8BitCost(1, p0) : 0;
30 | const int16_t* res_coeffs = res->coeffs;
31 | const int res_last = res->last;
32 | const int const_max_level = MAX_VARIABLE_LEVEL;
33 | const int const_2 = 2;
34 | const uint16_t** p_costs = &costs[n][0];
35 | const size_t inc_p_costs = NUM_CTX * sizeof(*p_costs);
36 |
37 | if (res->last < 0) {
38 | return VP8BitCost(0, p0);
39 | }
40 |
41 | __asm__ volatile (
42 | ".set push \n\t"
43 | ".set noreorder \n\t"
44 | "subu %[temp1], %[res_last], %[n] \n\t"
45 | "blez %[temp1], 2f \n\t"
46 | " nop \n\t"
47 | "1: \n\t"
48 | "sll %[temp0], %[n], 1 \n\t"
49 | "lhx %[v_reg], %[temp0](%[res_coeffs]) \n\t"
50 | "addiu %[n], %[n], 1 \n\t"
51 | "absq_s.w %[v_reg], %[v_reg] \n\t"
52 | "sltiu %[temp0], %[v_reg], 2 \n\t"
53 | "move %[ctx_reg], %[v_reg] \n\t"
54 | "movz %[ctx_reg], %[const_2], %[temp0] \n\t"
55 | "sll %[temp1], %[v_reg], 1 \n\t"
56 | "lhx %[temp1], %[temp1](%[VP8LevelFixedCosts]) \n\t"
57 | "slt %[temp0], %[v_reg], %[const_max_level] \n\t"
58 | "movz %[v_reg], %[const_max_level], %[temp0] \n\t"
59 | "addu %[cost], %[cost], %[temp1] \n\t"
60 | "sll %[v_reg], %[v_reg], 1 \n\t"
61 | "sll %[ctx_reg], %[ctx_reg], 2 \n\t"
62 | "lhx %[temp0], %[v_reg](%[t]) \n\t"
63 | "addu %[p_costs], %[p_costs], %[inc_p_costs] \n\t"
64 | "addu %[t], %[p_costs], %[ctx_reg] \n\t"
65 | "addu %[cost], %[cost], %[temp0] \n\t"
66 | "bne %[n], %[res_last], 1b \n\t"
67 | " lw %[t], 0(%[t]) \n\t"
68 | "2: \n\t"
69 | ".set pop \n\t"
70 | : [cost]"+&r"(cost), [t]"+&r"(t), [n]"+&r"(n), [v_reg]"=&r"(v_reg),
71 | [ctx_reg]"=&r"(ctx_reg), [p_costs]"+&r"(p_costs), [temp0]"=&r"(temp0),
72 | [temp1]"=&r"(temp1)
73 | : [const_2]"r"(const_2), [const_max_level]"r"(const_max_level),
74 | [VP8LevelFixedCosts]"r"(VP8LevelFixedCosts), [res_last]"r"(res_last),
75 | [res_coeffs]"r"(res_coeffs), [inc_p_costs]"r"(inc_p_costs)
76 | : "memory"
77 | );
78 |
79 | // Last coefficient is always non-zero
80 | {
81 | const int v = abs(res->coeffs[n]);
82 | assert(v != 0);
83 | cost += VP8LevelCost(t, v);
84 | if (n < 15) {
85 | const int b = VP8EncBands[n + 1];
86 | const int ctx = (v == 1) ? 1 : 2;
87 | const int last_p0 = res->prob[b][ctx][0];
88 | cost += VP8BitCost(0, last_p0);
89 | }
90 | }
91 | return cost;
92 | }
93 |
94 | //------------------------------------------------------------------------------
95 | // Entry point
96 |
97 | extern void VP8EncDspCostInitMIPSdspR2(void);
98 |
99 | WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspCostInitMIPSdspR2(void) {
100 | VP8GetResidualCost = GetResidualCost;
101 | }
102 |
103 | #else // !WEBP_USE_MIPS_DSP_R2
104 |
105 | WEBP_DSP_INIT_STUB(VP8EncDspCostInitMIPSdspR2)
106 |
107 | #endif // WEBP_USE_MIPS_DSP_R2
108 |
--------------------------------------------------------------------------------
/webp-backport/src/main/jni/webp/src/dec/vp8li.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All Rights Reserved.
2 | //
3 | // Use of this source code is governed by a BSD-style license
4 | // that can be found in the COPYING file in the root of the source
5 | // tree. An additional intellectual property rights grant can be found
6 | // in the file PATENTS. All contributing project authors may
7 | // be found in the AUTHORS file in the root of the source tree.
8 | // -----------------------------------------------------------------------------
9 | //
10 | // Lossless decoder: internal header.
11 | //
12 | // Author: Skal (pascal.massimino@gmail.com)
13 | // Vikas Arora(vikaas.arora@gmail.com)
14 |
15 | #ifndef WEBP_DEC_VP8LI_H_
16 | #define WEBP_DEC_VP8LI_H_
17 |
18 | #include // for memcpy()
19 | #include "./webpi.h"
20 | #include "../utils/bit_reader.h"
21 | #include "../utils/color_cache.h"
22 | #include "../utils/huffman.h"
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | typedef enum {
29 | READ_DATA = 0,
30 | READ_HDR = 1,
31 | READ_DIM = 2
32 | } VP8LDecodeState;
33 |
34 | typedef struct VP8LTransform VP8LTransform;
35 | struct VP8LTransform {
36 | VP8LImageTransformType type_; // transform type.
37 | int bits_; // subsampling bits defining transform window.
38 | int xsize_; // transform window X index.
39 | int ysize_; // transform window Y index.
40 | uint32_t *data_; // transform data.
41 | };
42 |
43 | typedef struct {
44 | int color_cache_size_;
45 | VP8LColorCache color_cache_;
46 | VP8LColorCache saved_color_cache_; // for incremental
47 |
48 | int huffman_mask_;
49 | int huffman_subsample_bits_;
50 | int huffman_xsize_;
51 | uint32_t *huffman_image_;
52 | int num_htree_groups_;
53 | HTreeGroup *htree_groups_;
54 | HuffmanCode *huffman_tables_;
55 | } VP8LMetadata;
56 |
57 | typedef struct VP8LDecoder VP8LDecoder;
58 | struct VP8LDecoder {
59 | VP8StatusCode status_;
60 | VP8LDecodeState state_;
61 | VP8Io *io_;
62 |
63 | const WebPDecBuffer *output_; // shortcut to io->opaque->output
64 |
65 | uint32_t *pixels_; // Internal data: either uint8_t* for alpha
66 | // or uint32_t* for BGRA.
67 | uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage.
68 |
69 | VP8LBitReader br_;
70 | int incremental_; // if true, incremental decoding is expected
71 | VP8LBitReader saved_br_; // note: could be local variables too
72 | int saved_last_pixel_;
73 |
74 | int width_;
75 | int height_;
76 | int last_row_; // last input row decoded so far.
77 | int last_pixel_; // last pixel decoded so far. However, it may
78 | // not be transformed, scaled and
79 | // color-converted yet.
80 | int last_out_row_; // last row output so far.
81 |
82 | VP8LMetadata hdr_;
83 |
84 | int next_transform_;
85 | VP8LTransform transforms_[NUM_TRANSFORMS];
86 | // or'd bitset storing the transforms types.
87 | uint32_t transforms_seen_;
88 |
89 | uint8_t *rescaler_memory; // Working memory for rescaling work.
90 | WebPRescaler *rescaler; // Common rescaler for all channels.
91 | };
92 |
93 | //------------------------------------------------------------------------------
94 | // internal functions. Not public.
95 |
96 | struct ALPHDecoder; // Defined in dec/alphai.h.
97 |
98 | // in vp8l.c
99 |
100 | // Decodes image header for alpha data stored using lossless compression.
101 | // Returns false in case of error.
102 | int VP8LDecodeAlphaHeader(struct ALPHDecoder* const alph_dec,
103 | const uint8_t* const data, size_t data_size,
104 | uint8_t* const output);
105 |
106 | // Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are
107 | // already decoded in previous call(s), it will resume decoding from where it
108 | // was paused.
109 | // Returns false in case of bitstream error.
110 | int VP8LDecodeAlphaImageStream(struct ALPHDecoder* const alph_dec,
111 | int last_row);
112 |
113 | // Allocates and initialize a new lossless decoder instance.
114 | VP8LDecoder* VP8LNew(void);
115 |
116 | // Decodes the image header. Returns false in case of error.
117 | int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);
118 |
119 | // Decodes an image. It's required to decode the lossless header before calling
120 | // this function. Returns false in case of error, with updated dec->status_.
121 | int VP8LDecodeImage(VP8LDecoder* const dec);
122 |
123 | // Resets the decoder in its initial state, reclaiming memory.
124 | // Preserves the dec->status_ value.
125 | void VP8LClear(VP8LDecoder* const dec);
126 |
127 | // Clears and deallocate a lossless decoder instance.
128 | void VP8LDelete(VP8LDecoder* const dec);
129 |
130 | //------------------------------------------------------------------------------
131 |
132 | #ifdef __cplusplus
133 | } // extern "C"
134 | #endif
135 |
136 | #endif /* WEBP_DEC_VP8LI_H_ */
137 |
--------------------------------------------------------------------------------