├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── checkstyle.xml ├── checkstyle_suppressions.xml ├── framesequence ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ ├── android │ │ └── support │ │ │ └── rastermill │ │ │ ├── FrameSequence.java │ │ │ └── FrameSequenceDrawable.java │ └── com │ │ └── bumptech │ │ └── glide │ │ └── integration │ │ └── framesequence │ │ ├── ByteBufferFsDecoder.java │ │ ├── FrameSequenceResource.java │ │ ├── FsDrawableDecoder.java │ │ ├── FsDrawableResource.java │ │ ├── FsDrawableTranscoder.java │ │ ├── FsGlideLibraryModule.java │ │ ├── FsGlideModule.java │ │ ├── LazyFsDrawableResource.java │ │ ├── StreamFsDecoder.java │ │ └── WebpHeaderParser.java │ ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── BitmapDecoderJNI.cpp │ ├── Color.h │ ├── FrameSequence.cpp │ ├── FrameSequence.h │ ├── FrameSequenceJNI.cpp │ ├── FrameSequenceJNI.h │ ├── FrameSequence_gif.cpp │ ├── FrameSequence_gif.h │ ├── FrameSequence_webp.cpp │ ├── FrameSequence_webp.h │ ├── JNIHelpers.cpp │ ├── JNIHelpers.h │ ├── Registry.cpp │ ├── Registry.h │ ├── Stream.cpp │ ├── Stream.h │ ├── giflib │ │ ├── Android.mk │ │ └── src │ │ │ ├── Makefile.am │ │ │ ├── Makefile.in │ │ │ ├── Makefile.unx │ │ │ ├── config.h │ │ │ ├── dgif_lib.c │ │ │ ├── egif_lib.c │ │ │ ├── gif_err.c │ │ │ ├── gif_font.c │ │ │ ├── gif_hash.c │ │ │ ├── gif_hash.h │ │ │ ├── gif_lib.h │ │ │ ├── gif_lib_private.h │ │ │ ├── gifalloc.c │ │ │ ├── openbsd-reallocarray.c │ │ │ └── quantize.c │ └── utils │ │ ├── log.h │ │ └── math.h │ └── res │ └── values │ └── strings.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── release-bintray.gradle ├── scripts ├── android-tasks.gradle ├── bintray.gradle ├── publish.gradle ├── travis-sonatype-publish.sh ├── update_javadocs.sh └── upload.gradle ├── settings.gradle ├── webp_decoder ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── bumptech │ │ └── glide │ │ └── integration │ │ └── webp │ │ ├── WebpBitmapFactory.java │ │ ├── WebpFrame.java │ │ ├── WebpFrameInfo.java │ │ ├── WebpGlideLibraryModule.java │ │ ├── WebpGlideModule.java │ │ ├── WebpHeaderParser.java │ │ ├── WebpImage.java │ │ └── decoder │ │ ├── AnimatedWebpBitmapDecoder.java │ │ ├── ByteBufferAnimatedBitmapDecoder.java │ │ ├── ByteBufferBitmapWebpDecoder.java │ │ ├── ByteBufferWebpDecoder.java │ │ ├── StreamAnimatedBitmapDecoder.java │ │ ├── StreamBitmapWebpDecoder.java │ │ ├── StreamWebpDecoder.java │ │ ├── Utils.java │ │ ├── WebpDecoder.java │ │ ├── WebpDownsampler.java │ │ ├── WebpDrawable.java │ │ ├── WebpDrawableEncoder.java │ │ ├── WebpDrawableResource.java │ │ ├── WebpDrawableTransformation.java │ │ ├── WebpFrameCacheStrategy.java │ │ └── WebpFrameLoader.java │ ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── jni_common.cpp │ ├── jni_common.h │ ├── libwebp │ │ ├── Android.mk │ │ └── src │ │ │ ├── Makefile.am │ │ │ ├── dec │ │ │ ├── Makefile.am │ │ │ ├── alpha_dec.c │ │ │ ├── alphai_dec.h │ │ │ ├── buffer_dec.c │ │ │ ├── common_dec.h │ │ │ ├── frame_dec.c │ │ │ ├── idec_dec.c │ │ │ ├── io_dec.c │ │ │ ├── quant_dec.c │ │ │ ├── tree_dec.c │ │ │ ├── vp8_dec.c │ │ │ ├── vp8_dec.h │ │ │ ├── vp8i_dec.h │ │ │ ├── vp8l_dec.c │ │ │ ├── vp8li_dec.h │ │ │ ├── webp_dec.c │ │ │ └── webpi_dec.h │ │ │ ├── demux │ │ │ ├── Makefile.am │ │ │ ├── anim_decode.c │ │ │ ├── demux.c │ │ │ ├── libwebpdemux.pc.in │ │ │ └── libwebpdemux.rc │ │ │ ├── dsp │ │ │ ├── Makefile.am │ │ │ ├── alpha_processing.c │ │ │ ├── alpha_processing_mips_dsp_r2.c │ │ │ ├── alpha_processing_neon.c │ │ │ ├── alpha_processing_sse2.c │ │ │ ├── alpha_processing_sse41.c │ │ │ ├── common_sse2.h │ │ │ ├── common_sse41.h │ │ │ ├── cost.c │ │ │ ├── cost_mips32.c │ │ │ ├── cost_mips_dsp_r2.c │ │ │ ├── cost_neon.c │ │ │ ├── cost_sse2.c │ │ │ ├── cpu.c │ │ │ ├── cpu.h │ │ │ ├── dec.c │ │ │ ├── dec_clip_tables.c │ │ │ ├── dec_mips32.c │ │ │ ├── dec_mips_dsp_r2.c │ │ │ ├── dec_msa.c │ │ │ ├── dec_neon.c │ │ │ ├── dec_sse2.c │ │ │ ├── dec_sse41.c │ │ │ ├── dsp.h │ │ │ ├── enc.c │ │ │ ├── enc_mips32.c │ │ │ ├── enc_mips_dsp_r2.c │ │ │ ├── enc_msa.c │ │ │ ├── enc_neon.c │ │ │ ├── enc_sse2.c │ │ │ ├── enc_sse41.c │ │ │ ├── filters.c │ │ │ ├── filters_mips_dsp_r2.c │ │ │ ├── filters_msa.c │ │ │ ├── filters_neon.c │ │ │ ├── filters_sse2.c │ │ │ ├── lossless.c │ │ │ ├── lossless.h │ │ │ ├── lossless_common.h │ │ │ ├── lossless_enc.c │ │ │ ├── lossless_enc_mips32.c │ │ │ ├── lossless_enc_mips_dsp_r2.c │ │ │ ├── lossless_enc_msa.c │ │ │ ├── lossless_enc_neon.c │ │ │ ├── lossless_enc_sse2.c │ │ │ ├── lossless_enc_sse41.c │ │ │ ├── lossless_mips_dsp_r2.c │ │ │ ├── lossless_msa.c │ │ │ ├── lossless_neon.c │ │ │ ├── lossless_sse2.c │ │ │ ├── lossless_sse41.c │ │ │ ├── mips_macro.h │ │ │ ├── msa_macro.h │ │ │ ├── neon.h │ │ │ ├── quant.h │ │ │ ├── rescaler.c │ │ │ ├── rescaler_mips32.c │ │ │ ├── rescaler_mips_dsp_r2.c │ │ │ ├── rescaler_msa.c │ │ │ ├── rescaler_neon.c │ │ │ ├── rescaler_sse2.c │ │ │ ├── ssim.c │ │ │ ├── ssim_sse2.c │ │ │ ├── upsampling.c │ │ │ ├── upsampling_mips_dsp_r2.c │ │ │ ├── upsampling_msa.c │ │ │ ├── upsampling_neon.c │ │ │ ├── upsampling_sse2.c │ │ │ ├── upsampling_sse41.c │ │ │ ├── yuv.c │ │ │ ├── yuv.h │ │ │ ├── yuv_mips32.c │ │ │ ├── yuv_mips_dsp_r2.c │ │ │ ├── yuv_neon.c │ │ │ ├── yuv_sse2.c │ │ │ └── yuv_sse41.c │ │ │ ├── enc │ │ │ ├── Makefile.am │ │ │ ├── alpha_enc.c │ │ │ ├── analysis_enc.c │ │ │ ├── backward_references_cost_enc.c │ │ │ ├── backward_references_enc.c │ │ │ ├── backward_references_enc.h │ │ │ ├── config_enc.c │ │ │ ├── cost_enc.c │ │ │ ├── cost_enc.h │ │ │ ├── filter_enc.c │ │ │ ├── frame_enc.c │ │ │ ├── histogram_enc.c │ │ │ ├── histogram_enc.h │ │ │ ├── iterator_enc.c │ │ │ ├── near_lossless_enc.c │ │ │ ├── picture_csp_enc.c │ │ │ ├── picture_enc.c │ │ │ ├── picture_psnr_enc.c │ │ │ ├── picture_rescale_enc.c │ │ │ ├── picture_tools_enc.c │ │ │ ├── predictor_enc.c │ │ │ ├── quant_enc.c │ │ │ ├── syntax_enc.c │ │ │ ├── token_enc.c │ │ │ ├── tree_enc.c │ │ │ ├── vp8i_enc.h │ │ │ ├── vp8l_enc.c │ │ │ ├── vp8li_enc.h │ │ │ └── webp_enc.c │ │ │ ├── libwebp.pc.in │ │ │ ├── libwebp.rc │ │ │ ├── libwebpdecoder.pc.in │ │ │ ├── libwebpdecoder.rc │ │ │ ├── mux │ │ │ ├── Makefile.am │ │ │ ├── anim_encode.c │ │ │ ├── animi.h │ │ │ ├── libwebpmux.pc.in │ │ │ ├── libwebpmux.rc │ │ │ ├── muxedit.c │ │ │ ├── muxi.h │ │ │ ├── muxinternal.c │ │ │ └── muxread.c │ │ │ ├── utils │ │ │ ├── Makefile.am │ │ │ ├── bit_reader_inl_utils.h │ │ │ ├── bit_reader_utils.c │ │ │ ├── bit_reader_utils.h │ │ │ ├── bit_writer_utils.c │ │ │ ├── bit_writer_utils.h │ │ │ ├── color_cache_utils.c │ │ │ ├── color_cache_utils.h │ │ │ ├── endian_inl_utils.h │ │ │ ├── filters_utils.c │ │ │ ├── filters_utils.h │ │ │ ├── huffman_encode_utils.c │ │ │ ├── huffman_encode_utils.h │ │ │ ├── huffman_utils.c │ │ │ ├── huffman_utils.h │ │ │ ├── quant_levels_dec_utils.c │ │ │ ├── quant_levels_dec_utils.h │ │ │ ├── quant_levels_utils.c │ │ │ ├── quant_levels_utils.h │ │ │ ├── random_utils.c │ │ │ ├── random_utils.h │ │ │ ├── rescaler_utils.c │ │ │ ├── rescaler_utils.h │ │ │ ├── thread_utils.c │ │ │ ├── thread_utils.h │ │ │ ├── utils.c │ │ │ └── utils.h │ │ │ └── webp │ │ │ ├── decode.h │ │ │ ├── demux.h │ │ │ ├── encode.h │ │ │ ├── format_constants.h │ │ │ ├── mux.h │ │ │ ├── mux_types.h │ │ │ └── types.h │ ├── webp.cpp │ └── webp.h │ └── res │ └── values │ └── strings.xml └── webpsample ├── build.gradle ├── lint.xml ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── bumptech │ └── glide │ └── samples │ └── webp │ ├── AspectRatioImageView.java │ ├── ImageAdapter.java │ ├── MainActivity.java │ ├── WebpApplication.java │ ├── WebpModule.java │ └── WebpTextView.java └── res ├── drawable-xhdpi ├── broken.webp ├── head.webp ├── small_frame.webp └── test.webp ├── drawable ├── dot_dot_dot.xml ├── image_error.xml └── image_loading.xml ├── layout ├── activity_main.xml └── webp_image_item.xml ├── menu └── menu_main.xml ├── mipmap-hdpi └── ic_launcher.png ├── mipmap-mdpi └── ic_launcher.png ├── mipmap-xhdpi └── ic_launcher.png ├── mipmap-xxhdpi └── ic_launcher.png ├── mipmap-xxxhdpi └── ic_launcher.png ├── raw ├── android_toy_h.svg ├── circle_alpha_webp_ll.webp ├── static_poster.webp ├── wandoujia_webp_a.webp ├── yellow_rose_webp_a.webp └── yellow_rose_webp_ll.webp ├── values-w820dp └── dimens.xml └── values ├── arrays.xml ├── dimens.xml └── strings.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Android 2 | local.properties 3 | *.keystore 4 | *.DS_Store 5 | proguard-project.txt 6 | 7 | # Gradle 8 | **/.gradle 9 | **/.settings 10 | **/build 11 | 12 | # gh-pages 13 | doc/** 14 | _site/* 15 | _pages/* 16 | docs/**/* 17 | 18 | # Vim 19 | *.swp 20 | *.swo 21 | 22 | # Intellij 23 | *.ipr 24 | *.iml 25 | *.iws 26 | **/.idea 27 | **/.idea/.name 28 | **/.idea/compiler.xml 29 | **/.idea/copyright/profiles_settings.xml 30 | **/.idea/encodings.xml 31 | **/.idea/misc.xml 32 | **/.idea/modules.xml 33 | **/.idea/scopes/scope_settings.xml 34 | **/.idea/vcs.xml 35 | **/.idea/libraries 36 | **/.idea/workspace.xml 37 | **/.idea/tasks.xml 38 | **/.idea/gradle.xml 39 | **/.idea/dictionaries 40 | **/.idea/dataSources.ids 41 | **/.idea/datasources.xml 42 | **/.idea/uiDesigner.xml 43 | **/.idea/runConfigurations.xml 44 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath "com.android.tools.build:gradle:${ANDROID_GRADLE_VERSION}" 10 | //classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1' 11 | } 12 | } 13 | 14 | // See http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html. 15 | if (JavaVersion.current().isJava8Compatible()) { 16 | allprojects { 17 | tasks.withType(Javadoc) { 18 | options.addStringOption('Xdoclint:none', '-quiet') 19 | } 20 | } 21 | } 22 | 23 | subprojects { 24 | tasks.withType(JavaCompile) { 25 | sourceCompatibility = 1.7 26 | targetCompatibility = 1.7 27 | } 28 | } 29 | 30 | subprojects { project -> 31 | repositories { 32 | google() 33 | mavenCentral() 34 | //jcenter() 35 | } 36 | 37 | apply plugin: 'checkstyle' 38 | 39 | checkstyle { 40 | toolVersion = '6.12.1' 41 | } 42 | 43 | checkstyle { 44 | configFile = rootProject.file('checkstyle.xml') 45 | configProperties.checkStyleConfigDir = rootProject.rootDir 46 | } 47 | 48 | task checkstyle(type: Checkstyle) { 49 | source 'src' 50 | include '**/*.java' 51 | exclude '**/gen/**' 52 | 53 | // empty classpath 54 | classpath = files() 55 | } 56 | 57 | // afterEvaluate { 58 | // if (project.tasks.findByName('check')) { 59 | // check.dependsOn('checkstyle') 60 | // } 61 | // } 62 | 63 | gradle.projectsEvaluated { 64 | tasks.withType(JavaCompile) { 65 | options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation' 66 | } 67 | } 68 | } 69 | 70 | //task wrapper(type: Wrapper) { 71 | // gradleVersion = '5.4' 72 | // distributionType = Wrapper.DistributionType.ALL 73 | //} 74 | 75 | ext { 76 | GLIDE_MAJOR_VERSION = GLIDE_VERSION.split("\\.")[0] as String 77 | VERSION_NAME = "${DECODER_VERSION}.${GLIDE_VERSION}" 78 | } -------------------------------------------------------------------------------- /checkstyle_suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /framesequence/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | .externalNativeBuild 3 | /src/main/jni/libwebp -------------------------------------------------------------------------------- /framesequence/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | dependencies { 4 | compileOnly "androidx.annotation:annotation:${ANDROIDX_VERSION}" 5 | implementation("com.github.bumptech.glide:glide:${GLIDE_VERSION}"){ 6 | exclude group:"com.android.support" 7 | } 8 | annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}" 9 | compileOnly "androidx.fragment:fragment:${ANDROIDX_VERSION}" 10 | } 11 | 12 | android { 13 | ndkVersion "${NDK_VERSION}" 14 | compileSdkVersion COMPILE_SDK_VERSION as int 15 | buildToolsVersion BUILD_TOOLS_VERSION as String 16 | 17 | defaultConfig { 18 | minSdkVersion MIN_SDK_VERSION as int 19 | targetSdkVersion TARGET_SDK_VERSION as int 20 | 21 | ndk { 22 | abiFilter "armeabi-v7a" 23 | abiFilter "armeabi" 24 | abiFilter "arm64-v8a" 25 | abiFilter "x86" 26 | abiFilter "x86_64" 27 | } 28 | } 29 | 30 | externalNativeBuild { 31 | ndkBuild { 32 | path "src/main/jni/Android.mk" 33 | } 34 | } 35 | 36 | sourceSets { 37 | main { 38 | jni.srcDirs = [] 39 | } 40 | } 41 | compileOptions { 42 | sourceCompatibility JavaVersion.VERSION_1_7 43 | targetCompatibility JavaVersion.VERSION_1_7 44 | } 45 | } 46 | 47 | task copyLibwebp(type: Copy) { 48 | def sourceDir = new File(project(':webp_decoder').projectDir, "src/main/jni/libwebp") 49 | def targetDir = new File(projectDir, "src/main/jni/libwebp") 50 | targetDir.deleteDir() 51 | 52 | from sourceDir 53 | into targetDir 54 | include("**/**.c") 55 | include("**/**.h") 56 | include("**.mk") 57 | include("**/**.rc") 58 | include("**/**.in") 59 | } 60 | 61 | afterEvaluate { 62 | project.tasks.findAll { 63 | it.name.startsWith("externalNativeBuild") 64 | } .each { 65 | it.dependsOn copyLibwebp 66 | } 67 | copyLibwebp.execute() 68 | } 69 | 70 | apply from: "${rootProject.projectDir}/release-bintray.gradle" 71 | -------------------------------------------------------------------------------- /framesequence/gradle.properties: -------------------------------------------------------------------------------- 1 | # FrameSequenceDrawable not support scale and down sampling, so it will not be used temporary. 2 | # 3 | # 4 | POM_NAME=Glide WebpDecoder Integration 5 | POM_ARTIFACT_ID=framesequence 6 | POM_PACKAGING=aar 7 | POM_DESCRIPTION=An integration library to decode and show animated webp for Glide 8 | 9 | JAR_PREFIX=glide- 10 | JAR_POSTFIX=-integration 11 | -------------------------------------------------------------------------------- /framesequence/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 C:\Android\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /framesequence/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/ByteBufferFsDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | 4 | import android.support.rastermill.FrameSequence; 5 | 6 | import androidx.annotation.Nullable; 7 | 8 | import com.bumptech.glide.load.ImageHeaderParser; 9 | import com.bumptech.glide.load.ImageHeaderParserUtils; 10 | import com.bumptech.glide.load.Option; 11 | import com.bumptech.glide.load.Options; 12 | import com.bumptech.glide.load.ResourceDecoder; 13 | import com.bumptech.glide.load.engine.Resource; 14 | 15 | import java.io.IOException; 16 | import java.nio.ByteBuffer; 17 | import java.util.List; 18 | 19 | /** 20 | * @author liuchun 21 | */ 22 | public class ByteBufferFsDecoder implements ResourceDecoder { 23 | 24 | public static final Option DISABLE_ANIMATION = Option.memory( 25 | "com.bumptech.glide.integration.framesequence.ByteBufferFsDecoder.DisableAnimation", false); 26 | 27 | public static final Option DISABLE_WEBP = Option.memory( 28 | "com.bumptech.glide.integration.framesequence.ByteBufferFsDecoder.DisableWebp", false); 29 | 30 | private final List parsers; 31 | 32 | public ByteBufferFsDecoder(List parsers) { 33 | this.parsers = parsers; 34 | } 35 | 36 | @Override 37 | public boolean handles(ByteBuffer source, Options options) throws IOException { 38 | if (options.get(DISABLE_ANIMATION)) { 39 | return false; 40 | } 41 | 42 | source.mark(); 43 | ImageHeaderParser.ImageType imageType = ImageHeaderParserUtils.getType(parsers, source); 44 | source.reset(); // reset the Buffer for twice read 45 | if (imageType == ImageHeaderParser.ImageType.GIF) { 46 | // GIF 47 | return true; 48 | } 49 | 50 | if (options.get(DISABLE_WEBP) || !isWebp(imageType)) { 51 | // Non Webp 52 | return false; 53 | } 54 | 55 | WebpHeaderParser.WebpImageType webpImageType = WebpHeaderParser.getType(source); 56 | return WebpHeaderParser.isAnimatedWebpType(webpImageType); 57 | } 58 | 59 | @Nullable 60 | @Override 61 | public Resource decode(ByteBuffer source, int width, int height, Options options) throws IOException { 62 | 63 | int length = source.remaining(); 64 | byte[] data = new byte[length]; 65 | source.get(data, 0, length); 66 | 67 | FrameSequence fs = FrameSequence.decodeByteArray(data); 68 | if (fs == null) { 69 | return null; 70 | } 71 | // int sampleSize = getSampleSize(fs.getWidth(), fs.getHeight(), width, height); 72 | // fs.setSampleSize(sampleSize); 73 | return new FrameSequenceResource(fs); 74 | } 75 | 76 | 77 | public static boolean isWebp(ImageHeaderParser.ImageType imageType) { 78 | return imageType == ImageHeaderParser.ImageType.WEBP 79 | || imageType == ImageHeaderParser.ImageType.WEBP_A 80 | || imageType == ImageHeaderParser.ImageType.ANIMATED_WEBP; 81 | } 82 | 83 | static int getSampleSize(int srcWidth, int srcHeight, int targetWidth, int targetHeight) { 84 | int exactSampleSize = Math.min(srcHeight / targetHeight, 85 | srcWidth / targetWidth); 86 | int powerOfTwoSampleSize = exactSampleSize == 0 ? 0 : Integer.highestOneBit(exactSampleSize); 87 | // Although functionally equivalent to 0 for BitmapFactory, 1 is a safer default for our code 88 | // than 0. 89 | return Math.max(1, powerOfTwoSampleSize); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/FrameSequenceResource.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | import android.support.rastermill.FrameSequence; 4 | 5 | import com.bumptech.glide.load.engine.Resource; 6 | 7 | /** 8 | * @author liuchun 9 | */ 10 | public class FrameSequenceResource implements Resource { 11 | private final FrameSequence frameSequence; 12 | 13 | 14 | public FrameSequenceResource(FrameSequence fs) { 15 | frameSequence = fs; 16 | } 17 | 18 | @Override 19 | public Class getResourceClass() { 20 | return FrameSequence.class; 21 | } 22 | 23 | @Override 24 | public FrameSequence get() { 25 | return frameSequence; 26 | } 27 | 28 | @Override 29 | public int getSize() { 30 | return frameSequence.getWidth() * frameSequence.getHeight() * 4; 31 | } 32 | 33 | @Override 34 | public void recycle() { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/FsDrawableDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | import android.graphics.Bitmap; 4 | import android.support.rastermill.FrameSequence; 5 | import android.support.rastermill.FrameSequenceDrawable; 6 | 7 | import androidx.annotation.Nullable; 8 | 9 | import com.bumptech.glide.load.Options; 10 | import com.bumptech.glide.load.ResourceDecoder; 11 | import com.bumptech.glide.load.engine.Resource; 12 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 13 | 14 | import java.io.IOException; 15 | 16 | /** 17 | * author: liuchun 18 | * date: 2018/1/6 19 | */ 20 | public class FsDrawableDecoder implements ResourceDecoder{ 21 | 22 | private final ResourceDecoder decoder; 23 | private final FrameSequenceDrawable.BitmapProvider bitmapProvider; 24 | 25 | public FsDrawableDecoder(final BitmapPool bitmapPool, ResourceDecoder decoder) { 26 | this.decoder = decoder; 27 | this.bitmapProvider = new FrameSequenceDrawable.BitmapProvider() { 28 | @Override 29 | public Bitmap acquireBitmap(int minWidth, int minHeight) { 30 | return bitmapPool.get(minWidth, minHeight, Bitmap.Config.ARGB_8888); 31 | } 32 | 33 | @Override 34 | public void releaseBitmap(Bitmap bitmap) { 35 | bitmapPool.put(bitmap); 36 | } 37 | }; 38 | } 39 | 40 | @Override 41 | public boolean handles(DataType dataType, Options options) throws IOException { 42 | return decoder.handles(dataType, options); 43 | } 44 | 45 | @Nullable 46 | @Override 47 | public Resource decode(DataType dataType, int width, int height, Options options) throws IOException { 48 | 49 | Resource fsResource = decoder.decode(dataType, width, height, options); 50 | if (fsResource == null) { 51 | return null; 52 | } 53 | 54 | // TODO modify the source code to support downsampling 55 | FrameSequenceDrawable fsDrawable = new FrameSequenceDrawable(fsResource.get(), bitmapProvider); 56 | return new FsDrawableResource(fsDrawable); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/FsDrawableResource.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | import android.support.rastermill.FrameSequenceDrawable; 4 | 5 | import com.bumptech.glide.load.resource.drawable.DrawableResource; 6 | 7 | /** 8 | * author: liuchun 9 | * date: 2018/1/6 10 | */ 11 | public class FsDrawableResource extends DrawableResource { 12 | 13 | public FsDrawableResource(FrameSequenceDrawable drawable) { 14 | super(drawable); 15 | } 16 | 17 | @Override 18 | public Class getResourceClass() { 19 | return FrameSequenceDrawable.class; 20 | } 21 | 22 | 23 | @Override 24 | public int getSize() { 25 | return drawable.getSize(); 26 | } 27 | 28 | @Override 29 | public void recycle() { 30 | drawable.stop(); 31 | drawable.destroy(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/FsDrawableTranscoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | import android.graphics.Bitmap; 4 | import android.support.rastermill.FrameSequence; 5 | import android.support.rastermill.FrameSequenceDrawable; 6 | 7 | import com.bumptech.glide.load.Options; 8 | import com.bumptech.glide.load.engine.Resource; 9 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 10 | import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; 11 | 12 | /** 13 | * author: liuchun 14 | * date: 2018/1/6 15 | */ 16 | public class FsDrawableTranscoder implements ResourceTranscoder { 17 | 18 | private final FrameSequenceDrawable.BitmapProvider bitmapProvider; 19 | 20 | public FsDrawableTranscoder(final BitmapPool bitmapPool) { 21 | bitmapProvider = new FrameSequenceDrawable.BitmapProvider() { 22 | @Override 23 | public Bitmap acquireBitmap(int minWidth, int minHeight) { 24 | return bitmapPool.get(minWidth, minHeight, Bitmap.Config.ARGB_8888); 25 | } 26 | 27 | @Override 28 | public void releaseBitmap(Bitmap bitmap) { 29 | bitmapPool.put(bitmap); 30 | } 31 | }; 32 | } 33 | 34 | 35 | @Override 36 | public Resource transcode(Resource resource, Options options) { 37 | 38 | FrameSequenceDrawable fsDrawable = new FrameSequenceDrawable(resource.get(), bitmapProvider); 39 | return new FsDrawableResource(fsDrawable); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/FsGlideLibraryModule.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | import android.content.Context; 4 | import android.support.rastermill.FrameSequence; 5 | import android.support.rastermill.FrameSequenceDrawable; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.bumptech.glide.Registry; 9 | import com.bumptech.glide.annotation.GlideModule; 10 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 11 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 12 | import com.bumptech.glide.module.LibraryGlideModule; 13 | 14 | import java.io.InputStream; 15 | import java.nio.ByteBuffer; 16 | 17 | /** 18 | * 19 | * @author liuchun 20 | */ 21 | @GlideModule 22 | public class FsGlideLibraryModule extends LibraryGlideModule { 23 | @Override 24 | public void registerComponents(Context context, Glide glide, Registry registry) { 25 | 26 | final BitmapPool bitmapPool = glide.getBitmapPool(); 27 | final ArrayPool arrayPool = glide.getArrayPool(); 28 | final ByteBufferFsDecoder bufferFsDecoder = new ByteBufferFsDecoder(registry.getImageHeaderParsers()); 29 | final StreamFsDecoder streamFsDecoder = new StreamFsDecoder(registry.getImageHeaderParsers(), arrayPool); 30 | registry /* FrameSequences */ 31 | .prepend(ByteBuffer.class, FrameSequence.class, bufferFsDecoder) 32 | .prepend(InputStream.class, FrameSequence.class, streamFsDecoder) 33 | /* FrameSequencesDrawables */ 34 | .prepend(ByteBuffer.class, FrameSequenceDrawable.class, 35 | new FsDrawableDecoder<>(bitmapPool, bufferFsDecoder)) 36 | .prepend(InputStream.class, FrameSequenceDrawable.class, 37 | new FsDrawableDecoder<>(bitmapPool, streamFsDecoder)) 38 | /* Transcodes */ 39 | .register(FrameSequence.class, FrameSequenceDrawable.class, 40 | new FsDrawableTranscoder(bitmapPool)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/FsGlideModule.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | import android.content.Context; 4 | import android.support.rastermill.FrameSequence; 5 | import android.support.rastermill.FrameSequenceDrawable; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.bumptech.glide.GlideBuilder; 9 | import com.bumptech.glide.Registry; 10 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 11 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 12 | 13 | import java.io.InputStream; 14 | import java.nio.ByteBuffer; 15 | 16 | /** 17 | * author: liuchun 18 | * date: 2018/1/22 19 | */ 20 | @Deprecated 21 | public class FsGlideModule implements com.bumptech.glide.module.GlideModule{ 22 | @Override 23 | public void applyOptions(Context context, GlideBuilder builder) { 24 | 25 | } 26 | 27 | @Override 28 | public void registerComponents(Context context, Glide glide, Registry registry) { 29 | 30 | final BitmapPool bitmapPool = glide.getBitmapPool(); 31 | final ArrayPool arrayPool = glide.getArrayPool(); 32 | final ByteBufferFsDecoder bufferFsDecoder = new ByteBufferFsDecoder(registry.getImageHeaderParsers()); 33 | final StreamFsDecoder streamFsDecoder = new StreamFsDecoder(registry.getImageHeaderParsers(), arrayPool); 34 | registry /* FrameSequences */ 35 | .prepend(ByteBuffer.class, FrameSequence.class, bufferFsDecoder) 36 | .prepend(InputStream.class, FrameSequence.class, streamFsDecoder) 37 | /* FrameSequencesDrawables */ 38 | .prepend(ByteBuffer.class, FrameSequenceDrawable.class, 39 | new FsDrawableDecoder<>(bitmapPool, bufferFsDecoder)) 40 | .prepend(InputStream.class, FrameSequenceDrawable.class, 41 | new FsDrawableDecoder<>(bitmapPool, streamFsDecoder)) 42 | /* Transcodes */ 43 | .register(FrameSequence.class, FrameSequenceDrawable.class, 44 | new FsDrawableTranscoder(bitmapPool)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/LazyFsDrawableResource.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | import android.graphics.Bitmap; 4 | import android.support.rastermill.FrameSequence; 5 | import android.support.rastermill.FrameSequenceDrawable; 6 | 7 | import com.bumptech.glide.load.engine.Resource; 8 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 9 | 10 | /** 11 | * Lazily allocates a {@link android.support.rastermill.FrameSequenceDrawable} from a given 12 | * {@link android.support.rastermill.FrameSequence} on the first call to {@link #get()}. 13 | * 14 | * author: liuchun 15 | * date: 2018/1/6 16 | */ 17 | public class LazyFsDrawableResource implements Resource{ 18 | 19 | private final FrameSequence frameSequence; 20 | private final FrameSequenceDrawable.BitmapProvider bitmapProvider; 21 | 22 | public LazyFsDrawableResource(FrameSequence frameSequence, final BitmapPool bitmapPool) { 23 | this.frameSequence = frameSequence; 24 | this.bitmapProvider = new FrameSequenceDrawable.BitmapProvider() { 25 | @Override 26 | public Bitmap acquireBitmap(int minWidth, int minHeight) { 27 | return bitmapPool.get(minWidth, minHeight, Bitmap.Config.ARGB_8888); 28 | } 29 | 30 | @Override 31 | public void releaseBitmap(Bitmap bitmap) { 32 | bitmapPool.put(bitmap); 33 | } 34 | }; 35 | } 36 | 37 | @Override 38 | public Class getResourceClass() { 39 | return FrameSequenceDrawable.class; 40 | } 41 | 42 | @Override 43 | public FrameSequenceDrawable get() { 44 | return new FrameSequenceDrawable(frameSequence, bitmapProvider); 45 | } 46 | 47 | @Override 48 | public int getSize() { 49 | return frameSequence.getWidth() * frameSequence.getHeight() * 4; 50 | } 51 | 52 | @Override 53 | public void recycle() { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /framesequence/src/main/java/com/bumptech/glide/integration/framesequence/StreamFsDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.framesequence; 2 | 3 | 4 | 5 | import android.support.rastermill.FrameSequence; 6 | 7 | import androidx.annotation.Nullable; 8 | 9 | import com.bumptech.glide.load.ImageHeaderParser; 10 | import com.bumptech.glide.load.ImageHeaderParserUtils; 11 | import com.bumptech.glide.load.Option; 12 | import com.bumptech.glide.load.Options; 13 | import com.bumptech.glide.load.ResourceDecoder; 14 | import com.bumptech.glide.load.engine.Resource; 15 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 16 | 17 | import java.io.IOException; 18 | import java.io.InputStream; 19 | import java.util.List; 20 | 21 | /** 22 | * 23 | * @author liuchun 24 | */ 25 | public class StreamFsDecoder implements ResourceDecoder { 26 | 27 | public static final Option DISABLE_ANIMATION = Option.memory( 28 | "com.bumptech.glide.integration.framesequence.StreamFsDecoder.DisableAnimation", false); 29 | 30 | public static final Option DISABLE_WEBP = Option.memory( 31 | "com.bumptech.glide.integration.framesequence.StreamFsDecoder.DisableWebp", false); 32 | 33 | private final List parsers; 34 | private final ArrayPool byteArrayPool; 35 | 36 | public StreamFsDecoder(List parsers, ArrayPool byteArrayPool) { 37 | this.parsers = parsers; 38 | this.byteArrayPool = byteArrayPool; 39 | } 40 | 41 | @Override 42 | public boolean handles(InputStream source, Options options) throws IOException { 43 | if (options.get(DISABLE_ANIMATION)) { 44 | return false; 45 | } 46 | 47 | ImageHeaderParser.ImageType imageType = ImageHeaderParserUtils.getType(parsers, source, byteArrayPool); 48 | if (imageType == ImageHeaderParser.ImageType.GIF) { 49 | // GIF 50 | return true; 51 | } 52 | 53 | if (options.get(DISABLE_WEBP) || !ByteBufferFsDecoder.isWebp(imageType)) { 54 | // Non Webp 55 | return false; 56 | } 57 | 58 | WebpHeaderParser.WebpImageType webpImageType = WebpHeaderParser.getType(source, byteArrayPool); 59 | return WebpHeaderParser.isAnimatedWebpType(webpImageType); 60 | } 61 | 62 | @Nullable 63 | @Override 64 | public Resource decode(InputStream source, int width, int height, Options options) throws IOException { 65 | 66 | FrameSequence fs = FrameSequence.decodeStream(source); 67 | if (fs == null) { 68 | return null; 69 | } 70 | // int sampleSize = ByteBufferFsDecoder.getSampleSize(fs.getWidth(), fs.getHeight(), width, height); 71 | // fs.setSampleSize(sampleSize); 72 | return new FrameSequenceResource(fs); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | LOCAL_MODULE := framesequence 6 | LOCAL_SRC_FILES := \ 7 | BitmapDecoderJNI.cpp \ 8 | FrameSequence.cpp \ 9 | FrameSequenceJNI.cpp \ 10 | FrameSequence_gif.cpp \ 11 | JNIHelpers.cpp \ 12 | Registry.cpp \ 13 | Stream.cpp \ 14 | 15 | CXX11_FLAGS := -std=c++11 16 | LOCAL_CFLAGS += $(CXX11_FLAGS) 17 | #LOCAL_CFLAGS += -DLOG_TAG=\"libglide-webp\" 18 | LOCAL_CFLAGS += -fvisibility=hidden 19 | LOCAL_CFLAGS += $(GLIDE_CPP_CFLAGS) 20 | 21 | LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS) 22 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 23 | LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/libwebp/src 24 | LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/giflib/src 25 | 26 | LOCAL_LDLIBS := -latomic -llog -ljnigraphics 27 | LOCAL_LDFLAGS += $(GLIDE_CPP_LDFLAGS) 28 | 29 | LOCAL_SHARED_LIBRARIES += gif 30 | 31 | ifeq ($(FRAMESEQUENCE_INCLUDE_WEBP),true) 32 | LOCAL_SRC_FILES += FrameSequence_webp.cpp 33 | LOCAL_SHARED_LIBRARIES += webp 34 | endif 35 | 36 | include $(BUILD_SHARED_LIBRARY) 37 | 38 | $(call import-module,giflib) 39 | 40 | ifeq ($(FRAMESEQUENCE_INCLUDE_WEBP),true) 41 | $(call import-module,libwebp) 42 | endif 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_BUILD_SCRIPT := Android.mk 2 | 3 | APP_ABI := armeabi-v7a armeabi arm64-v8a x86 x86_64 4 | 5 | APP_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST))) 6 | NDK_MODULE_PATH := $(APP_MK_DIR) 7 | 8 | APP_OPTIM := release 9 | 10 | APP_STL := c++_static 11 | 12 | # Make sure every shared lib includes a .note.gnu.build-id header 13 | #APP_LDFLAGS := -Wl,--build-id 14 | 15 | #NDK_TOOLCHAIN_VERSION := clang 16 | 17 | # We link our libs with static stl implementation. Because of that we need to 18 | # hide all stl related symbols to make them unaccessible from the outside. 19 | # We also need to make sure that our library does not use any stl functions 20 | # coming from other stl implementations as well 21 | 22 | # This hides all symbols exported from libc++_static 23 | GLIDE_CPP_CFLAGS := -Wall -Wno-unused-parameter -Wno-unused-variable -Wno-overloaded-virtual 24 | GLIDE_CPP_LDFLAGS := -Wl,--gc-sections,--exclude-libs,libc++_static.a 25 | 26 | FRAMESEQUENCE_INCLUDE_WEBP := true -------------------------------------------------------------------------------- /framesequence/src/main/jni/BitmapDecoderJNI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "FancyDecoding" 18 | 19 | #include 20 | #include 21 | #include 22 | #include "FrameSequenceJNI.h" 23 | #include "JNIHelpers.h" 24 | #include "Stream.h" 25 | #include "utils/log.h" 26 | 27 | void throwException(JNIEnv* env, const char* error) { 28 | jclass clazz = env->FindClass("java/lang/RuntimeException"); 29 | env->ThrowNew(clazz, error); 30 | } 31 | 32 | jint JNI_OnLoad(JavaVM* vm, void* reserved) { 33 | JNIEnv* env; 34 | if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { 35 | return -1; 36 | } 37 | if (FrameSequence_OnLoad(env)) { 38 | ALOGE("Failed to load FrameSequence"); 39 | return -1; 40 | } 41 | if (JavaStream_OnLoad(env)) { 42 | ALOGE("Failed to load JavaStream"); 43 | return -1; 44 | } 45 | 46 | return JNI_VERSION_1_6; 47 | } 48 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/Color.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_COLOR_H 18 | #define RASTERMILL_COLOR_H 19 | 20 | #include 21 | 22 | typedef uint32_t Color8888; 23 | 24 | static const Color8888 COLOR_8888_ALPHA_MASK = 0xff000000; // TODO: handle endianness 25 | static const Color8888 TRANSPARENT = 0x0; 26 | 27 | // TODO: handle endianness 28 | #define ARGB_TO_COLOR8888(a, r, g, b) \ 29 | ((a) << 24 | (b) << 16 | (g) << 8 | (r)) 30 | 31 | #endif // RASTERMILL_COLOR_H 32 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/FrameSequence.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "FrameSequence.h" 18 | 19 | #include "Registry.h" 20 | 21 | FrameSequence* FrameSequence::create(Stream* stream) { 22 | const RegistryEntry* entry = Registry::Find(stream); 23 | 24 | if (!entry) return NULL; 25 | 26 | FrameSequence* frameSequence = entry->createFrameSequence(stream); 27 | if (!frameSequence->getFrameCount() || 28 | !frameSequence->getWidth() || !frameSequence->getHeight()) { 29 | // invalid contents, abort 30 | delete frameSequence; 31 | return NULL; 32 | } 33 | 34 | return frameSequence; 35 | } 36 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/FrameSequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_FRAME_SEQUENCE_H 18 | #define RASTERMILL_FRAME_SEQUENCE_H 19 | 20 | #include "Stream.h" 21 | #include "Color.h" 22 | 23 | class FrameSequenceState { 24 | public: 25 | /** 26 | * Produces a frame of animation in the output buffer, drawing (at minimum) the delta since 27 | * previousFrameNr (the current contents of the buffer), or from scratch if previousFrameNr is 28 | * negative 29 | * 30 | * Returns frame's delay time in milliseconds. 31 | */ 32 | virtual long drawFrame(int frameNr, 33 | Color8888* outputPtr, int outputPixelStride, int previousFrameNr) = 0; 34 | virtual ~FrameSequenceState() {} 35 | }; 36 | 37 | class FrameSequence { 38 | public: 39 | /** 40 | * Creates a FrameSequence using data from the data stream 41 | * 42 | * Type determined by header information in the stream 43 | */ 44 | static FrameSequence* create(Stream* stream); 45 | 46 | virtual ~FrameSequence() {} 47 | virtual int getWidth() const = 0; 48 | virtual int getHeight() const = 0; 49 | virtual bool isOpaque() const = 0; 50 | virtual int getFrameCount() const = 0; 51 | virtual int getDefaultLoopCount() const = 0; 52 | virtual jobject getRawByteBuffer() const = 0; 53 | 54 | virtual FrameSequenceState* createState() const = 0; 55 | }; 56 | 57 | #endif //RASTERMILL_FRAME_SEQUENCE_H 58 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/FrameSequenceJNI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_FRAMESEQUENCE_JNI 18 | #define RASTERMILL_FRAMESEQUENCE_JNI 19 | 20 | #include 21 | 22 | jint FrameSequence_OnLoad(JNIEnv* env); 23 | 24 | #endif // RASTERMILL_FRAMESEQUENCE_JNI 25 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/FrameSequence_gif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_FRAMESQUENCE_GIF_H 18 | #define RASTERMILL_FRAMESQUENCE_GIF_H 19 | 20 | #include "config.h" 21 | #include "gif_lib.h" 22 | 23 | #include "Stream.h" 24 | #include "Color.h" 25 | #include "FrameSequence.h" 26 | 27 | class FrameSequence_gif : public FrameSequence { 28 | public: 29 | FrameSequence_gif(Stream* stream); 30 | virtual ~FrameSequence_gif(); 31 | 32 | virtual int getWidth() const { 33 | return mGif ? mGif->SWidth : 0; 34 | } 35 | 36 | virtual int getHeight() const { 37 | return mGif ? mGif->SHeight : 0; 38 | } 39 | 40 | virtual bool isOpaque() const { 41 | return (mBgColor & COLOR_8888_ALPHA_MASK) == COLOR_8888_ALPHA_MASK; 42 | } 43 | 44 | virtual int getFrameCount() const { 45 | return mGif ? mGif->ImageCount : 0; 46 | } 47 | 48 | virtual int getDefaultLoopCount() const { 49 | return mLoopCount; 50 | } 51 | 52 | virtual jobject getRawByteBuffer() const { 53 | return NULL; 54 | } 55 | 56 | virtual FrameSequenceState* createState() const; 57 | 58 | GifFileType* getGif() const { return mGif; } 59 | Color8888 getBackgroundColor() const { return mBgColor; } 60 | bool getPreservedFrame(int frameIndex) const { return mPreservedFrames[frameIndex]; } 61 | int getRestoringFrame(int frameIndex) const { return mRestoringFrames[frameIndex]; } 62 | 63 | private: 64 | GifFileType* mGif; 65 | int mLoopCount; 66 | Color8888 mBgColor; 67 | 68 | // array of bool per frame - if true, frame data is used by a later DISPOSE_PREVIOUS frame 69 | bool* mPreservedFrames; 70 | 71 | // array of ints per frame - if >= 0, points to the index of the preserve that frame needs 72 | int* mRestoringFrames; 73 | }; 74 | 75 | class FrameSequenceState_gif : public FrameSequenceState { 76 | public: 77 | FrameSequenceState_gif(const FrameSequence_gif& frameSequence); 78 | virtual ~FrameSequenceState_gif(); 79 | 80 | // returns frame's delay time in ms 81 | virtual long drawFrame(int frameNr, 82 | Color8888* outputPtr, int outputPixelStride, int previousFrameNr); 83 | 84 | private: 85 | void savePreserveBuffer(Color8888* outputPtr, int outputPixelStride, int frameNr); 86 | void restorePreserveBuffer(Color8888* outputPtr, int outputPixelStride); 87 | 88 | const FrameSequence_gif& mFrameSequence; 89 | Color8888* mPreserveBuffer; 90 | int mPreserveBufferFrame; 91 | }; 92 | 93 | #endif //RASTERMILL_FRAMESQUENCE_GIF_H 94 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/FrameSequence_webp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_FRAMESQUENCE_WEBP_H 18 | #define RASTERMILL_FRAMESQUENCE_WEBP_H 19 | 20 | #include "config.h" 21 | #include "webp/decode.h" 22 | #include "webp/demux.h" 23 | 24 | #include "Stream.h" 25 | #include "Color.h" 26 | #include "FrameSequence.h" 27 | 28 | // Parser for a possibly-animated WebP bitstream. 29 | class FrameSequence_webp : public FrameSequence { 30 | public: 31 | FrameSequence_webp(Stream* stream); 32 | virtual ~FrameSequence_webp(); 33 | 34 | virtual int getWidth() const { 35 | if (!mDemux) { 36 | return 0; 37 | } 38 | return WebPDemuxGetI(mDemux, WEBP_FF_CANVAS_WIDTH); 39 | } 40 | 41 | virtual int getHeight() const { 42 | if (!mDemux) { 43 | return 0; 44 | } 45 | return WebPDemuxGetI(mDemux, WEBP_FF_CANVAS_HEIGHT); 46 | } 47 | 48 | virtual bool isOpaque() const { 49 | return !(mFormatFlags & ALPHA_FLAG); 50 | } 51 | 52 | virtual int getFrameCount() const { 53 | if (!mDemux) { 54 | return 0; 55 | } 56 | return WebPDemuxGetI(mDemux, WEBP_FF_FRAME_COUNT); 57 | } 58 | 59 | virtual int getDefaultLoopCount() const { 60 | return mLoopCount; 61 | } 62 | 63 | virtual jobject getRawByteBuffer() const { 64 | return mRawByteBuffer; 65 | } 66 | 67 | virtual FrameSequenceState* createState() const; 68 | 69 | WebPDemuxer* getDemuxer() const { return mDemux; } 70 | 71 | bool isKeyFrame(size_t frameNr) const { return mIsKeyFrame[frameNr]; } 72 | 73 | private: 74 | void constructDependencyChain(); 75 | 76 | WebPData mData; 77 | WebPDemuxer* mDemux; 78 | int mLoopCount; 79 | uint32_t mFormatFlags; 80 | // mIsKeyFrame[i] is true if ith canvas can be constructed without decoding any prior frames. 81 | bool* mIsKeyFrame; 82 | jobject mRawByteBuffer = nullptr; 83 | }; 84 | 85 | // Produces frames of a possibly-animated WebP file for display. 86 | class FrameSequenceState_webp : public FrameSequenceState { 87 | public: 88 | FrameSequenceState_webp(const FrameSequence_webp& frameSequence); 89 | virtual ~FrameSequenceState_webp(); 90 | 91 | // Returns frame's delay time in milliseconds. 92 | virtual long drawFrame(int frameNr, 93 | Color8888* outputPtr, int outputPixelStride, int previousFrameNr); 94 | 95 | private: 96 | void initializeFrame(const WebPIterator& currIter, Color8888* currBuffer, int currStride, 97 | const WebPIterator& prevIter, const Color8888* prevBuffer, int prevStride); 98 | bool decodeFrame(const WebPIterator& iter, Color8888* currBuffer, int currStride, 99 | const WebPIterator& prevIter, const Color8888* prevBuffer, int prevStride); 100 | 101 | const FrameSequence_webp& mFrameSequence; 102 | WebPDecoderConfig mDecoderConfig; 103 | Color8888* mPreservedBuffer; 104 | }; 105 | 106 | #endif //RASTERMILL_FRAMESQUENCE_WEBP_H 107 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/JNIHelpers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "JNIHelpers.h" 18 | #include "utils/log.h" 19 | 20 | void jniThrowException(JNIEnv* env, const char* className, const char* msg) { 21 | jclass clazz = env->FindClass(className); 22 | if (!clazz) { 23 | ALOGE("Unable to find exception class %s", className); 24 | /* ClassNotFoundException now pending */ 25 | return; 26 | } 27 | 28 | if (env->ThrowNew(clazz, msg) != JNI_OK) { 29 | ALOGE("Failed throwing '%s' '%s'", className, msg); 30 | /* an exception, most likely OOM, will now be pending */ 31 | } 32 | env->DeleteLocalRef(clazz); 33 | } 34 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/JNIHelpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_JNIHELPERS_H 18 | #define RASTERMILL_JNIHELPERS_H 19 | 20 | #include 21 | 22 | #define METHOD_COUNT(methodArray) (sizeof(methodArray) / sizeof((methodArray)[0])) 23 | 24 | #define ILLEGAL_STATE_EXEPTION "java/lang/IllegalStateException" 25 | 26 | void jniThrowException(JNIEnv* env, const char* className, const char* msg); 27 | 28 | 29 | #endif //RASTERMILL_JNIHELPERS_H 30 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/Registry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "Registry.h" 18 | 19 | #include "Stream.h" 20 | 21 | static Registry* gHead = 0; 22 | static int gHeaderBytesRequired = 0; 23 | 24 | Registry::Registry(const RegistryEntry& entry) { 25 | mImpl = entry; 26 | 27 | mNext = gHead; 28 | gHead = this; 29 | 30 | if (gHeaderBytesRequired < entry.requiredHeaderBytes) { 31 | gHeaderBytesRequired = entry.requiredHeaderBytes; 32 | } 33 | } 34 | 35 | const RegistryEntry* Registry::Find(Stream* stream) { 36 | Registry* registry = gHead; 37 | 38 | if (stream->getRawBuffer() != NULL) { 39 | while (registry) { 40 | if (registry->mImpl.acceptsBuffer()) { 41 | return &(registry->mImpl); 42 | } 43 | registry = registry->mNext; 44 | } 45 | } else { 46 | int headerSize = gHeaderBytesRequired; 47 | char header[headerSize]; 48 | headerSize = stream->peek(header, headerSize); 49 | while (registry) { 50 | if (headerSize >= registry->mImpl.requiredHeaderBytes 51 | && registry->mImpl.checkHeader(header, headerSize)) { 52 | return &(registry->mImpl); 53 | } 54 | registry = registry->mNext; 55 | } 56 | } 57 | return 0; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/Registry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_REGISTRY_H 18 | #define RASTERMILL_REGISTRY_H 19 | 20 | #include "jni.h" 21 | #include 22 | 23 | class FrameSequence; 24 | class Decoder; 25 | class Stream; 26 | 27 | struct RegistryEntry { 28 | int requiredHeaderBytes; 29 | bool (*checkHeader)(void* header, int header_size); 30 | FrameSequence* (*createFrameSequence)(Stream* stream); 31 | Decoder* (*createDecoder)(Stream* stream); 32 | bool (*acceptsBuffer)(); 33 | }; 34 | 35 | /** 36 | * Template class for registering subclasses that can produce instances of themselves given a 37 | * DataStream pointer. 38 | * 39 | * The super class / root constructable type only needs to define a single static construction 40 | * meathod that creates an instance by iterating through all factory methods. 41 | */ 42 | class Registry { 43 | public: 44 | Registry(const RegistryEntry& entry); 45 | 46 | static const RegistryEntry* Find(Stream* stream); 47 | 48 | private: 49 | RegistryEntry mImpl; 50 | Registry* mNext; 51 | }; 52 | 53 | #endif // RASTERMILL_REGISTRY_H 54 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef RASTERMILL_STREAM_H 18 | #define RASTERMILL_STREAM_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class Stream { 25 | public: 26 | Stream(); 27 | virtual ~Stream(); 28 | 29 | size_t peek(void* buffer, size_t size); 30 | size_t read(void* buffer, size_t size); 31 | virtual uint8_t* getRawBufferAddr(); 32 | virtual jobject getRawBuffer(); 33 | virtual int getRawBufferSize(); 34 | 35 | protected: 36 | virtual size_t doRead(void* buffer, size_t size) = 0; 37 | 38 | private: 39 | char* mPeekBuffer; 40 | size_t mPeekSize; 41 | size_t mPeekOffset; 42 | }; 43 | 44 | class MemoryStream : public Stream { 45 | public: 46 | MemoryStream(void* buffer, size_t size, jobject buf) : 47 | mBuffer((uint8_t*)buffer), 48 | mRemaining(size), 49 | mRawBuffer(buf) {} 50 | virtual uint8_t* getRawBufferAddr(); 51 | virtual jobject getRawBuffer(); 52 | virtual int getRawBufferSize(); 53 | 54 | protected: 55 | virtual size_t doRead(void* buffer, size_t size); 56 | 57 | private: 58 | uint8_t* mBuffer; 59 | size_t mRemaining; 60 | jobject mRawBuffer; 61 | }; 62 | 63 | class FileStream : public Stream { 64 | public: 65 | FileStream(FILE* fd) : mFd(fd) {} 66 | 67 | protected: 68 | virtual size_t doRead(void* buffer, size_t size); 69 | 70 | private: 71 | FILE* mFd; 72 | }; 73 | 74 | class JavaInputStream : public Stream { 75 | public: 76 | JavaInputStream(JNIEnv* env, jobject inputStream, jbyteArray byteArray) : 77 | mEnv(env), 78 | mInputStream(inputStream), 79 | mByteArray(byteArray), 80 | mByteArrayLength(env->GetArrayLength(byteArray)) {} 81 | 82 | protected: 83 | virtual size_t doRead(void* buffer, size_t size); 84 | 85 | private: 86 | JNIEnv* mEnv; 87 | const jobject mInputStream; 88 | const jbyteArray mByteArray; 89 | const size_t mByteArrayLength; 90 | }; 91 | 92 | jint JavaStream_OnLoad(JNIEnv* env); 93 | 94 | #endif //RASTERMILL_STREAM_H 95 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/Android.mk: -------------------------------------------------------------------------------- 1 | # libgif version 5.1.4, https://github.com/aosp-mirror/platform_external_giflib 2 | LOCAL_PATH := $(call my-dir) 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_SRC_FILES := \ 6 | src/dgif_lib.c \ 7 | src/gifalloc.c \ 8 | src/openbsd-reallocarray.c 9 | 10 | UNUSED_SRCS := \ 11 | src/egif_lib.c \ 12 | src/gif_font.c \ 13 | src/gif_hash.c \ 14 | src/quantize.c 15 | 16 | GIF_CFLAGS := -Wall -DANDROID -DHAVE_MALLOC_H -DHAVE_PTHREAD 17 | 18 | LOCAL_CFLAGS := $(GIF_CFLAGS) 19 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/src 20 | 21 | LOCAL_MODULE := gif 22 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/src 23 | 24 | include $(BUILD_STATIC_LIBRARY) 25 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce a Makefile.in for giflib. 2 | 3 | EXTRA_DIST = Makefile.unx 4 | 5 | lib_LTLIBRARIES = libgif.la 6 | 7 | include_HEADERS = gif_lib.h 8 | 9 | libgif_la_SOURCES = dgif_lib.c \ 10 | egif_lib.c \ 11 | gif_font.c \ 12 | gif_hash.c \ 13 | gif_hash.h \ 14 | gifalloc.c \ 15 | openbsd-reallocarray.c \ 16 | gif_err.c \ 17 | gif_lib_private.h \ 18 | quantize.c 19 | 20 | libgif_la_LDFLAGS = -no-undefined -version-info @SHLIBVERSION@ 21 | libgif_CFLAGS = $(X_CFLAGS) $(AM_CFLAGS) 22 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/src/Makefile.unx: -------------------------------------------------------------------------------- 1 | # (Note: this is not presently used, there's an autoconf build.) 2 | # 3 | # This is the make file for the lib subdirectory of the GIF library 4 | # You'll need GNU gcc or some other ANSI-complient compiler. 5 | # 6 | LIBVERSION = 3.0 7 | 8 | SHLIB = libgif.so.$(LIBVERSION) 9 | 10 | # Where all the include files are: 11 | INCS = -I. 12 | 13 | LIBDIR = /usr/lib 14 | 15 | CC = gcc 16 | #CFLAGS = -fno-builtin -O -c -W -Wreturn-type -Wcomment 17 | CFLAGS = -fno-builtin -g -c -W -Wreturn-type -Wcomment 18 | 19 | OBJS = egif_lib.o dgif_lib.o gifalloc.o gif_font.o gif_hash.o \ 20 | gif_err.o quantize.o qprintf.o getarg.o 21 | 22 | .c.o: 23 | $(CC) $(INCS) $(CFLAGS) $< 24 | 25 | all: static shared 26 | 27 | static: libgif.a 28 | shared: $(SHLIB) 29 | 30 | libgif.a: $(OBJS) 31 | rm -f libgif.a 32 | ar rcv libgif.a $(OBJS) 33 | -ranlib libgif.a 34 | 35 | $(SHLIB): $(OBJS) 36 | rm -f libgif.so.$(LIBVERSION) 37 | gcc -shared -o $(SHLIB) $(OBJS) 38 | 39 | egif_lib.o: gif_lib.h gif_hash.h 40 | dgif_lib.o: gif_lib.h gif_hash.h 41 | gif_hash.o: gif_lib.h gif_hash.h 42 | gif_err.o: gif_lib.h 43 | gifalloc.o: gif_lib.h 44 | gif_font.o: gif_lib.h 45 | quantize.o: gif_lib.h 46 | qprintf.o: gif_lib.h 47 | getarg.o: getarg.h 48 | 49 | install-lib: libgif.a 50 | cp libgif.a libgif.so.$(LIBVERSION) $(LIBDIR) 51 | 52 | uninstall-lib: shared static 53 | rm -f $(LIBDIR)/libgif.a $(LIBDIR)/$(SHLIB) 54 | clean: 55 | rm -f *.[oa] *~ libgif.so.$(LIBVERSION) 56 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/src/config.h: -------------------------------------------------------------------------------- 1 | 2 | // giflib config.h 3 | 4 | #ifndef GIF_CONFIG_H_DEFINED 5 | #define GIF_CONFIG_H_DEFINED 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | typedef uint32_t UINT32; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/src/gif_err.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | 3 | gif_err.c - handle error reporting for the GIF library. 4 | 5 | ****************************************************************************/ 6 | 7 | #include 8 | 9 | #include "gif_lib.h" 10 | #include "gif_lib_private.h" 11 | 12 | /***************************************************************************** 13 | Return a string description of the last GIF error 14 | *****************************************************************************/ 15 | const char * 16 | GifErrorString(int ErrorCode) 17 | { 18 | const char *Err; 19 | 20 | switch (ErrorCode) { 21 | case E_GIF_ERR_OPEN_FAILED: 22 | Err = "Failed to open given file"; 23 | break; 24 | case E_GIF_ERR_WRITE_FAILED: 25 | Err = "Failed to write to given file"; 26 | break; 27 | case E_GIF_ERR_HAS_SCRN_DSCR: 28 | Err = "Screen descriptor has already been set"; 29 | break; 30 | case E_GIF_ERR_HAS_IMAG_DSCR: 31 | Err = "Image descriptor is still active"; 32 | break; 33 | case E_GIF_ERR_NO_COLOR_MAP: 34 | Err = "Neither global nor local color map"; 35 | break; 36 | case E_GIF_ERR_DATA_TOO_BIG: 37 | Err = "Number of pixels bigger than width * height"; 38 | break; 39 | case E_GIF_ERR_NOT_ENOUGH_MEM: 40 | Err = "Failed to allocate required memory"; 41 | break; 42 | case E_GIF_ERR_DISK_IS_FULL: 43 | Err = "Write failed (disk full?)"; 44 | break; 45 | case E_GIF_ERR_CLOSE_FAILED: 46 | Err = "Failed to close given file"; 47 | break; 48 | case E_GIF_ERR_NOT_WRITEABLE: 49 | Err = "Given file was not opened for write"; 50 | break; 51 | case D_GIF_ERR_OPEN_FAILED: 52 | Err = "Failed to open given file"; 53 | break; 54 | case D_GIF_ERR_READ_FAILED: 55 | Err = "Failed to read from given file"; 56 | break; 57 | case D_GIF_ERR_NOT_GIF_FILE: 58 | Err = "Data is not in GIF format"; 59 | break; 60 | case D_GIF_ERR_NO_SCRN_DSCR: 61 | Err = "No screen descriptor detected"; 62 | break; 63 | case D_GIF_ERR_NO_IMAG_DSCR: 64 | Err = "No Image Descriptor detected"; 65 | break; 66 | case D_GIF_ERR_NO_COLOR_MAP: 67 | Err = "Neither global nor local color map"; 68 | break; 69 | case D_GIF_ERR_WRONG_RECORD: 70 | Err = "Wrong record type detected"; 71 | break; 72 | case D_GIF_ERR_DATA_TOO_BIG: 73 | Err = "Number of pixels bigger than width * height"; 74 | break; 75 | case D_GIF_ERR_NOT_ENOUGH_MEM: 76 | Err = "Failed to allocate required memory"; 77 | break; 78 | case D_GIF_ERR_CLOSE_FAILED: 79 | Err = "Failed to close given file"; 80 | break; 81 | case D_GIF_ERR_NOT_READABLE: 82 | Err = "Given file was not opened for read"; 83 | break; 84 | case D_GIF_ERR_IMAGE_DEFECT: 85 | Err = "Image is defective, decoding aborted"; 86 | break; 87 | case D_GIF_ERR_EOF_TOO_SOON: 88 | Err = "Image EOF detected before image complete"; 89 | break; 90 | default: 91 | Err = NULL; 92 | break; 93 | } 94 | return Err; 95 | } 96 | 97 | /* end */ 98 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/src/gif_hash.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | gif_hash.h - magfic constants and declarations for GIF LZW 4 | 5 | ******************************************************************************/ 6 | 7 | #ifndef _GIF_HASH_H_ 8 | #define _GIF_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | #define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */ 14 | #define HT_KEY_MASK 0x1FFF /* 13bits keys */ 15 | #define HT_KEY_NUM_BITS 13 /* 13bits keys */ 16 | #define HT_MAX_KEY 8191 /* 13bits - 1, maximal code possible */ 17 | #define HT_MAX_CODE 4095 /* Biggest code possible in 12 bits. */ 18 | 19 | /* The 32 bits of the long are divided into two parts for the key & code: */ 20 | /* 1. The code is 12 bits as our compression algorithm is limited to 12bits */ 21 | /* 2. The key is 12 bits Prefix code + 8 bit new char or 20 bits. */ 22 | /* The key is the upper 20 bits. The code is the lower 12. */ 23 | #define HT_GET_KEY(l) (l >> 12) 24 | #define HT_GET_CODE(l) (l & 0x0FFF) 25 | #define HT_PUT_KEY(l) (l << 12) 26 | #define HT_PUT_CODE(l) (l & 0x0FFF) 27 | 28 | typedef struct GifHashTableType { 29 | uint32_t HTable[HT_SIZE]; 30 | } GifHashTableType; 31 | 32 | GifHashTableType *_InitHashTable(void); 33 | void _ClearHashTable(GifHashTableType *HashTable); 34 | void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code); 35 | int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key); 36 | 37 | #endif /* _GIF_HASH_H_ */ 38 | 39 | /* end */ 40 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/src/gif_lib_private.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | 3 | gif_lib_private.h - internal giflib routines and structures 4 | 5 | ****************************************************************************/ 6 | 7 | #ifndef _GIF_LIB_PRIVATE_H 8 | #define _GIF_LIB_PRIVATE_H 9 | 10 | #include "gif_lib.h" 11 | #include "gif_hash.h" 12 | 13 | #define EXTENSION_INTRODUCER 0x21 14 | #define DESCRIPTOR_INTRODUCER 0x2c 15 | #define TERMINATOR_INTRODUCER 0x3b 16 | 17 | #define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */ 18 | #define LZ_BITS 12 19 | 20 | #define FLUSH_OUTPUT 4096 /* Impossible code, to signal flush. */ 21 | #define FIRST_CODE 4097 /* Impossible code, to signal first. */ 22 | #define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */ 23 | 24 | #define FILE_STATE_WRITE 0x01 25 | #define FILE_STATE_SCREEN 0x02 26 | #define FILE_STATE_IMAGE 0x04 27 | #define FILE_STATE_READ 0x08 28 | 29 | #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ) 30 | #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE) 31 | 32 | typedef struct GifFilePrivateType { 33 | GifWord FileState, FileHandle, /* Where all this data goes to! */ 34 | BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */ 35 | ClearCode, /* The CLEAR LZ code. */ 36 | EOFCode, /* The EOF LZ code. */ 37 | RunningCode, /* The next code algorithm can generate. */ 38 | RunningBits, /* The number of bits required to represent RunningCode. */ 39 | MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits. */ 40 | LastCode, /* The code before the current code. */ 41 | CrntCode, /* Current algorithm code. */ 42 | StackPtr, /* For character stack (see below). */ 43 | CrntShiftState; /* Number of bits in CrntShiftDWord. */ 44 | unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */ 45 | unsigned long PixelCount; /* Number of pixels in image. */ 46 | FILE *File; /* File as stream. */ 47 | InputFunc Read; /* function to read gif input (TVT) */ 48 | OutputFunc Write; /* function to write gif output (MRB) */ 49 | GifByteType Buf[256]; /* Compressed input is buffered here. */ 50 | GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */ 51 | GifByteType Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */ 52 | GifPrefixType Prefix[LZ_MAX_CODE + 1]; 53 | GifHashTableType *HashTable; 54 | bool gif89; 55 | } GifFilePrivateType; 56 | 57 | #endif /* _GIF_LIB_PRIVATE_H */ 58 | 59 | /* end */ 60 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/giflib/src/openbsd-reallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */ 2 | /* 3 | * Copyright (c) 2008 Otto Moerbeek 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | /* 25 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 26 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 27 | */ 28 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) 29 | 30 | void * 31 | reallocarray(void *optr, size_t nmemb, size_t size) 32 | { 33 | if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 34 | nmemb > 0 && SIZE_MAX / nmemb < size) { 35 | errno = ENOMEM; 36 | return NULL; 37 | } 38 | return realloc(optr, size * nmemb); 39 | } 40 | -------------------------------------------------------------------------------- /framesequence/src/main/jni/utils/math.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef MATH_H_ 18 | #define MATH_H_ 19 | 20 | #define max(a,b) \ 21 | ({ __typeof__ (a) _a = (a); \ 22 | __typeof__ (b) _b = (b); \ 23 | _a > _b ? _a : _b; }) 24 | 25 | #define min(a,b) \ 26 | ({ __typeof__ (a) _a = (a); \ 27 | __typeof__ (b) _b = (b); \ 28 | _a < _b ? _a : _b; }) 29 | 30 | #endif /* MATH_H_ */ 31 | -------------------------------------------------------------------------------- /framesequence/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | webp_decoder 3 | 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.daemon=true 2 | org.gradle.configureondemand=false 3 | org.gradle.jvmargs=-Xmx2048M 4 | 5 | DECODER_VERSION=2.7 6 | GROUP=com.github.zjupure 7 | 8 | POM_DESCRIPTION=A Glide webp decoder intergration library for decoding and displaying webp images. 9 | POM_URL=https://github.com/zjupure/GlideWebpDecoder 10 | POM_SCM_URL=https://github.com/zjupure/GlideWebpDecoder 11 | POM_SCM_CONNECTION=scm:git@github.com:zjupure/GlideWebpDecoder.git 12 | POM_SCM_DEV_CONNECTION=scm:git@github.com:zjupure/GlideWebpDecoder.git 13 | POM_DEVELOPER_ID=zjupure 14 | POM_DEVELOPER_NAME=zjupure 15 | POM_DEVELOPER_EMAIL=zjupure@gmail.com 16 | 17 | ANDROID_SUPPORT_VERSION=28.0.0 18 | ANDROIDX_VERSION=1.0.0 19 | GLIDE_VERSION=4.16.0 20 | ANDROID_GRADLE_VERSION=3.5.2 21 | NDK_VERSION=21.1.6352462 22 | 23 | FRESCO_VERSION=2.0.0 24 | 25 | android.useAndroidX=true 26 | android.enableJetifier=true 27 | 28 | COMPILE_SDK_VERSION=29 29 | BUILD_TOOLS_VERSION=29.0.3 30 | TARGET_SDK_VERSION=29 31 | MIN_SDK_VERSION=14 32 | 33 | bintrayUsername= 34 | bintrayApiKey= 35 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Aug 19 14:01:59 CST 2018 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-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /release-bintray.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | // Set up everything required for releasing on Bintray 4 | ext { 5 | bintrayRepo = 'maven-home' 6 | //bintrayUserOrg = 'individual' 7 | bintrayName = "${GROUP}:${POM_ARTIFACT_ID}" 8 | bintrayDescription = POM_DESCRIPTION 9 | projectUrl = 'https://github.com/zjupure/GlideWebpDecoder' 10 | issuesUrl = 'https://github.com/zjupure/GlideWebpDecoder' 11 | scmUrl = 'https://github.com/zjupure/GlideWebpDecoder' 12 | scmConnection = 'scm:git:https://github.com/zjupure/GlideWebpDecoder.git' 13 | scmDeveloperConnection = 'scm:git:git@github.com:zjupure/GlideWebpDecoder.git' 14 | 15 | publishedGroupId = GROUP 16 | libraryName = 'glide-webpdecoder' 17 | artifact = 'webpdecoder' 18 | 19 | projectLicenses = { 20 | license { 21 | name 'BSD License' 22 | url 'https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/add-license-1/LICENSE' 23 | distribution 'repo' 24 | } 25 | } 26 | } 27 | 28 | // Android tasks 29 | apply from: rootProject.file('scripts/android-tasks.gradle') 30 | 31 | // Upload to Bintray 32 | //apply from: rootProject.file('scripts/bintray.gradle') 33 | 34 | // Upload to Maven 35 | apply from: rootProject.file('scripts/upload.gradle') 36 | 37 | // Upload to Maven-Central 38 | apply from: rootProject.file('scripts/publish.gradle') 39 | 40 | 41 | afterEvaluate { 42 | Task mavenUpload = project.tasks.getByName("uploadArchives") 43 | Task build = project.tasks.getByName("build") 44 | Task assemble = project.tasks.getByName("assemble") 45 | project.tasks.findAll { 46 | it.name.startsWith("publish") 47 | }.each { 48 | it.dependsOn(build) 49 | it.dependsOn(assemble) 50 | } 51 | 52 | mavenUpload.dependsOn(build) 53 | mavenUpload.dependsOn(assemble) 54 | } -------------------------------------------------------------------------------- /scripts/android-tasks.gradle: -------------------------------------------------------------------------------- 1 | // Android tasks for Javadoc and sources.jar generation 2 | 3 | afterEvaluate { project -> 4 | task androidJavadoc(type: Javadoc) { 5 | source = android.sourceSets.main.java.srcDirs 6 | exclude '**/pom.xml' 7 | exclude '**/proguard_annotations.pro' 8 | classpath += files(android.bootClasspath) 9 | } 10 | 11 | task androidJavadocsJar(type: Jar) { 12 | classifier = 'javadoc' 13 | from androidJavadoc.destinationDir 14 | } 15 | 16 | task androidSourcesJar(type: Jar) { 17 | classifier = 'sources' 18 | from android.sourceSets.main.java.srcDirs 19 | } 20 | 21 | android.libraryVariants.all { variant -> 22 | def name = variant.name.capitalize() 23 | task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) { 24 | from variant.javaCompile.destinationDir 25 | } 26 | } 27 | 28 | artifacts.add('archives', androidJavadocsJar) 29 | artifacts.add('archives', androidSourcesJar) 30 | } 31 | -------------------------------------------------------------------------------- /scripts/bintray.gradle: -------------------------------------------------------------------------------- 1 | // Upload to Bintray 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | def getBintrayUsername() { 5 | return hasProperty('bintrayUsername') ? property('bintrayUsername') : System.getenv('BINTRAY_USERNAME') 6 | } 7 | 8 | def getBintrayApiKey() { 9 | return hasProperty('bintrayApiKey') ? property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') 10 | } 11 | 12 | def getBintrayGpgPassword() { 13 | return hasProperty('bintrayGpgPassword') ? property('bintrayGpgPassword') : System.getenv('BINTRAY_GPG_PASSWORD') 14 | } 15 | 16 | def getMavenCentralUsername() { 17 | return hasProperty('mavenCentralUsername') ? property('mavenCentralUsername') : System.getenv('MAVEN_CENTRAL_USERNAME') 18 | } 19 | 20 | def getMavenCentralPassword() { 21 | return hasProperty('mavenCentralPassword') ? property('mavenCentralPassword') : System.getenv('MAVEN_CENTRAL_PASSWORD') 22 | } 23 | 24 | def shouldSyncWithMavenCentral() { 25 | return hasProperty('syncWithMavenCentral') ? property('syncWithMavenCentral').toBoolean() : false 26 | } 27 | 28 | def dryRunOnly() { 29 | return hasProperty('dryRun') ? property('dryRun').toBoolean() : false 30 | } 31 | 32 | bintray { 33 | user = getBintrayUsername() 34 | key = getBintrayApiKey() 35 | configurations = ['archives'] 36 | pkg { 37 | repo = bintrayRepo 38 | //userOrg = bintrayUserOrg 39 | name = bintrayName 40 | desc = bintrayDescription 41 | websiteUrl = projectUrl 42 | issueTrackerUrl = issuesUrl 43 | vcsUrl = scmUrl 44 | licenses = ['Apache-2.0'] 45 | //licenses = projectLicenses 46 | dryRun = dryRunOnly() 47 | override = true 48 | publish = true 49 | publicDownloadNumbers = true 50 | // version { 51 | // desc = bintrayDescription 52 | // gpg { 53 | // sign = true 54 | // passphrase = getBintrayGpgPassword() 55 | // } 56 | // mavenCentralSync { 57 | // sync = shouldSyncWithMavenCentral() 58 | // user = getMavenCentralUsername() 59 | // password = getMavenCentralPassword() 60 | // close = '1' // If set to 0, you have to manually click release 61 | // } 62 | // } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /scripts/travis-sonatype-publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Publishes the latest snapshot to Sonatype. Works only for SNAPSHOT versions. 3 | # Based closely on material from 4 | # http://benlimmer.com/2014/01/04/automatically-publish-to-sonatype-with-gradle-and-travis-ci. 5 | 6 | if [ "$SONATYPE_PUBLISH" == "true" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "$SONATYPE_PUBLISH_BRANCH" ]; then 7 | echo -e "Starting publish to Sonatype...\n" 8 | 9 | ./gradlew uploadArchives -PNEXUS_USERNAME="${NEXUS_USERNAME}" -PNEXUS_PASSWORD="${NEXUS_PASSWORD}" 10 | RETVAL=$? 11 | 12 | if [ $RETVAL -eq 0 ]; then 13 | echo 'Completed publish!' 14 | else 15 | echo 'Publish failed.' 16 | return 1 17 | fi 18 | else 19 | echo 'Skipping Sonatype push' 20 | fi 21 | -------------------------------------------------------------------------------- /scripts/update_javadocs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -o pipefail 4 | 5 | TEMP_DIR="/tmp/tmp_glide_javadoc" 6 | JAVADOC_GH_PAGES_DIR="javadocs" 7 | 8 | if [[ -z "$1" ]]; 9 | then 10 | echo "You must supply a target version" 11 | echo "Usage ./scripts/update_javadocs.sh <400>" 12 | exit 1 13 | fi 14 | 15 | if [[ $(git status -uno --porcelain) ]]; 16 | then 17 | echo "One or more changes, commit or revert first." 18 | git status -uno --porcelain 19 | exit 1 20 | fi 21 | 22 | if [ -e "$JAVADOC_GH_PAGES_DIR" ]; 23 | then 24 | echo "javadocs directory exists locally, remove first." 25 | exit 1 26 | fi 27 | 28 | if [[ $(git rev-list master...origin/master --count) -ne 0 ]]; 29 | then 30 | echo "Origin and master are not up to date" 31 | git rev-list master...origin/master --pretty 32 | exit 1 33 | fi 34 | if [[ $(git rev-list gh-pages...origin/gh-pages --count) -ne 0 ]]; 35 | then 36 | echo "Origin and gh-pages are not up to date" 37 | git rev-list gh-pages...origin/gh-pages --pretty 38 | exit 1 39 | fi 40 | 41 | git checkout master 42 | GIT_COMMIT_SHA="$(git rev-parse HEAD)" 43 | ./gradlew clean releaseJavadocJar javadoc 44 | rm -rf $TEMP_DIR 45 | cp -r glide/build/docs/javadoc $TEMP_DIR 46 | git checkout gh-pages 47 | rm -rf "${JAVADOC_GH_PAGES_DIR}/${1}" 48 | cp -r $TEMP_DIR $JAVADOC_GH_PAGES_DIR/$1 49 | rm -rf $TEMP_DIR 50 | git add "${JAVADOC_GH_PAGES_DIR}/$1" 51 | git commit -m "Update javadocs for version $1" -m "Generated from commit on master branch: ${GIT_COMMIT_SHA}" 52 | echo "Copied javadoc into ${JAVADOC_GH_PAGES_DIR}/${1} and committed" 53 | git log -1 --pretty=%B 54 | echo "Ready to push" 55 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':webpsample' 2 | include ':webp_decoder' 3 | //include ':framesequence' 4 | -------------------------------------------------------------------------------- /webp_decoder/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | .externalNativeBuild 3 | .cxx -------------------------------------------------------------------------------- /webp_decoder/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | dependencies { 4 | compileOnly "androidx.annotation:annotation:${ANDROIDX_VERSION}" 5 | implementation("com.github.bumptech.glide:glide:${GLIDE_VERSION}"){ 6 | exclude group:"com.android.support" 7 | } 8 | annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}" 9 | compileOnly "androidx.fragment:fragment:${ANDROIDX_VERSION}" 10 | compileOnly "androidx.vectordrawable:vectordrawable-animated:${ANDROIDX_VERSION}" 11 | } 12 | 13 | android { 14 | ndkVersion "${NDK_VERSION}" 15 | compileSdkVersion COMPILE_SDK_VERSION as int 16 | buildToolsVersion BUILD_TOOLS_VERSION as String 17 | 18 | defaultConfig { 19 | minSdkVersion MIN_SDK_VERSION as int 20 | targetSdkVersion TARGET_SDK_VERSION as int 21 | consumerProguardFiles "proguard-rules.pro" 22 | 23 | ndk { 24 | //abiFilter "armeabi" 25 | abiFilter "armeabi-v7a" 26 | abiFilter "arm64-v8a" 27 | abiFilter "x86" 28 | abiFilter "x86_64" 29 | } 30 | } 31 | 32 | externalNativeBuild { 33 | ndkBuild { 34 | path "src/main/jni/Android.mk" 35 | } 36 | } 37 | 38 | sourceSets { 39 | main { 40 | jni.srcDirs = [] 41 | } 42 | } 43 | compileOptions { 44 | sourceCompatibility JavaVersion.VERSION_1_7 45 | targetCompatibility JavaVersion.VERSION_1_7 46 | } 47 | 48 | lintOptions { 49 | abortOnError false 50 | } 51 | } 52 | 53 | apply from: "${rootProject.projectDir}/release-bintray.gradle" 54 | -------------------------------------------------------------------------------- /webp_decoder/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=Glide WebpDecoder Integration 2 | POM_ARTIFACT_ID=webpdecoder 3 | POM_PACKAGING=aar 4 | POM_DESCRIPTION=An integration library to decode and show animated webp for Glide 5 | 6 | JAR_PREFIX=glide- 7 | JAR_POSTFIX=-integration 8 | -------------------------------------------------------------------------------- /webp_decoder/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 C:\Android\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | 27 | -keep public class com.bumptech.glide.integration.webp.WebpImage { *; } 28 | -keep public class com.bumptech.glide.integration.webp.WebpFrame { *; } 29 | -keep public class com.bumptech.glide.integration.webp.WebpBitmapFactory { *; } 30 | -------------------------------------------------------------------------------- /webp_decoder/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/WebpFrame.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import androidx.annotation.Keep; 6 | 7 | /** 8 | * Inner model class housing metadata for each animated webp frame. 9 | * 10 | * @see Container Specification 11 | * 12 | * @author liuchun 13 | */ 14 | @Keep 15 | public class WebpFrame { 16 | 17 | // See comment in fixFrameDuration below. 18 | static final int MIN_FRAME_DURATION_MS = 11; 19 | static final int FRAME_DURATION_MS_FOR_MIN = 100; 20 | 21 | // Access from Native 22 | @Keep 23 | private long mNativePtr; 24 | /** 25 | * XOffset, YOffset, Frame Width, Frame Height 26 | */ 27 | int ix, iy, iw, ih; 28 | /** 29 | * Delay, in milliseconds, to next frame. 30 | */ 31 | int delay; 32 | /** 33 | * Indicates how transparent pixels of the current frame are to be 34 | * blended with corresponding pixels of the previous canvas 35 | */ 36 | boolean blendPreviousFrame; 37 | /** 38 | * Indicates how the current frame is to be treated after it has been 39 | * displayed (before rendering the next frame) on the canvas: 40 | */ 41 | boolean disposeBackgroundColor; 42 | 43 | // Called from JNI 44 | WebpFrame(long nativePtr, int xOffset, int yOffset, int width, int height, 45 | int delay, boolean blendPreviousFrame, boolean disposeBackgroundColor) { 46 | 47 | this.mNativePtr = nativePtr; 48 | this.ix = xOffset; 49 | this.iy = yOffset; 50 | this.iw = width; 51 | this.ih = height; 52 | this.delay = delay; 53 | this.blendPreviousFrame = blendPreviousFrame; 54 | this.disposeBackgroundColor = disposeBackgroundColor; 55 | fixFrameDuration(); 56 | } 57 | 58 | /** 59 | * Adjust the frame duration to respect logic for minimum frame duration times 60 | */ 61 | private void fixFrameDuration() { 62 | // We follow Chrome's behavior which comes from Firefox. 63 | // Comment from Chrome's ImageSource.cpp follows: 64 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify 65 | // a duration of <= 10 ms. See and 66 | // for more information. 67 | if (delay < MIN_FRAME_DURATION_MS) { 68 | delay = FRAME_DURATION_MS_FOR_MIN; 69 | } 70 | } 71 | 72 | @Override 73 | protected void finalize() throws Throwable { 74 | nativeFinalize(); 75 | } 76 | 77 | public void dispose() { 78 | nativeDispose(); 79 | } 80 | 81 | public void renderFrame(int width, int height, Bitmap bitmap) { 82 | nativeRenderFrame(width, height, bitmap); 83 | } 84 | 85 | public int getWidth() { 86 | return iw; 87 | } 88 | 89 | public int getHeight() { 90 | return ih; 91 | } 92 | 93 | public int getDurationMs() { 94 | return delay; 95 | } 96 | 97 | public int getXOffest() { 98 | return ix; 99 | } 100 | 101 | public int getYOffest() { 102 | return iy; 103 | } 104 | 105 | public boolean shouldDisposeToBackgroundColor() { 106 | return disposeBackgroundColor; 107 | } 108 | 109 | public boolean isBlendWithPreviousFrame() { 110 | return blendPreviousFrame; 111 | } 112 | 113 | private native void nativeRenderFrame(int width, int height, Bitmap bitmap); 114 | private native void nativeDispose(); 115 | private native void nativeFinalize(); 116 | } 117 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/WebpFrameInfo.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp; 2 | 3 | 4 | 5 | public class WebpFrameInfo { 6 | public final int frameNumber; 7 | public final int xOffset; 8 | public final int yOffset; 9 | public final int width; 10 | public final int height; 11 | public final int duration; 12 | public final boolean blendPreviousFrame; 13 | public final boolean disposeBackgroundColor; 14 | 15 | WebpFrameInfo(int frameNumber, WebpFrame webpFrame) { 16 | this.frameNumber = frameNumber; 17 | this.xOffset = webpFrame.getXOffest(); 18 | this.yOffset = webpFrame.getYOffest(); 19 | this.width = webpFrame.getWidth(); 20 | this.height = webpFrame.getHeight(); 21 | this.duration = webpFrame.getDurationMs(); 22 | this.blendPreviousFrame = webpFrame.isBlendWithPreviousFrame(); 23 | this.disposeBackgroundColor = webpFrame.shouldDisposeToBackgroundColor(); 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "frameNumber=" + frameNumber + ", xOffset=" + xOffset + ", yOffset=" + yOffset 29 | + ", width=" + width + ", height=" + height + ", duration=" + duration + 30 | ", blendPreviousFrame=" + blendPreviousFrame + ", disposeBackgroundColor=" + disposeBackgroundColor; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/WebpGlideLibraryModule.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Bitmap; 6 | import android.graphics.drawable.BitmapDrawable; 7 | 8 | import com.bumptech.glide.Glide; 9 | import com.bumptech.glide.Registry; 10 | import com.bumptech.glide.annotation.GlideModule; 11 | import com.bumptech.glide.integration.webp.decoder.AnimatedWebpBitmapDecoder; 12 | import com.bumptech.glide.integration.webp.decoder.ByteBufferAnimatedBitmapDecoder; 13 | import com.bumptech.glide.integration.webp.decoder.ByteBufferBitmapWebpDecoder; 14 | import com.bumptech.glide.integration.webp.decoder.StreamAnimatedBitmapDecoder; 15 | import com.bumptech.glide.integration.webp.decoder.StreamBitmapWebpDecoder; 16 | import com.bumptech.glide.integration.webp.decoder.WebpDownsampler; 17 | import com.bumptech.glide.integration.webp.decoder.WebpDrawableEncoder; 18 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 19 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 20 | import com.bumptech.glide.load.resource.bitmap.BitmapDrawableDecoder; 21 | import com.bumptech.glide.module.LibraryGlideModule; 22 | import com.bumptech.glide.integration.webp.decoder.ByteBufferWebpDecoder; 23 | import com.bumptech.glide.integration.webp.decoder.StreamWebpDecoder; 24 | import com.bumptech.glide.integration.webp.decoder.WebpDrawable; 25 | 26 | import java.io.InputStream; 27 | import java.nio.ByteBuffer; 28 | 29 | 30 | @GlideModule 31 | public class WebpGlideLibraryModule extends LibraryGlideModule { 32 | 33 | @Override 34 | public void registerComponents(Context context, Glide glide, Registry registry) { 35 | 36 | // We should put our decoder before the build-in decoders, 37 | // because the Downsampler will consume arbitrary data and make the inputstream corrupt 38 | // on some devices 39 | final Resources resources = context.getResources(); 40 | final BitmapPool bitmapPool = glide.getBitmapPool(); 41 | final ArrayPool arrayPool = glide.getArrayPool(); 42 | /* static webp decoders */ 43 | WebpDownsampler webpDownsampler = new WebpDownsampler(registry.getImageHeaderParsers(), 44 | resources.getDisplayMetrics(), bitmapPool, arrayPool); 45 | AnimatedWebpBitmapDecoder bitmapDecoder = new AnimatedWebpBitmapDecoder(arrayPool, bitmapPool); 46 | ByteBufferBitmapWebpDecoder byteBufferBitmapDecoder = new ByteBufferBitmapWebpDecoder(webpDownsampler); 47 | StreamBitmapWebpDecoder streamBitmapDecoder = new StreamBitmapWebpDecoder(webpDownsampler, arrayPool); 48 | /* animate webp decoders */ 49 | ByteBufferWebpDecoder byteBufferWebpDecoder = 50 | new ByteBufferWebpDecoder(context, arrayPool, bitmapPool); 51 | registry 52 | /* Bitmaps for static webp images */ 53 | .prepend(Registry.BUCKET_BITMAP, ByteBuffer.class, Bitmap.class, byteBufferBitmapDecoder) 54 | .prepend(Registry.BUCKET_BITMAP, InputStream.class, Bitmap.class, streamBitmapDecoder) 55 | /* BitmapDrawables for static webp images */ 56 | .prepend( 57 | Registry.BUCKET_BITMAP_DRAWABLE, 58 | ByteBuffer.class, 59 | BitmapDrawable.class, 60 | new BitmapDrawableDecoder<>(resources, byteBufferBitmapDecoder)) 61 | .prepend( 62 | Registry.BUCKET_BITMAP_DRAWABLE, 63 | InputStream.class, 64 | BitmapDrawable.class, 65 | new BitmapDrawableDecoder<>(resources, streamBitmapDecoder)) 66 | /* Bitmaps for animated webp images*/ 67 | .prepend(Registry.BUCKET_BITMAP, ByteBuffer.class, Bitmap.class, new ByteBufferAnimatedBitmapDecoder(bitmapDecoder)) 68 | .prepend(Registry.BUCKET_BITMAP, InputStream.class, Bitmap.class, new StreamAnimatedBitmapDecoder(bitmapDecoder)) 69 | /* Animated webp images */ 70 | .prepend(ByteBuffer.class, WebpDrawable.class, byteBufferWebpDecoder) 71 | .prepend(InputStream.class, WebpDrawable.class, new StreamWebpDecoder(byteBufferWebpDecoder, arrayPool)) 72 | .prepend(WebpDrawable.class, new WebpDrawableEncoder()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/WebpImage.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp; 2 | 3 | 4 | 5 | import androidx.annotation.Keep; 6 | 7 | import com.bumptech.glide.util.Preconditions; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import static com.bumptech.glide.integration.webp.WebpFrame.FRAME_DURATION_MS_FOR_MIN; 12 | import static com.bumptech.glide.integration.webp.WebpFrame.MIN_FRAME_DURATION_MS; 13 | 14 | /** 15 | * A WebpImage container whose encoded data held by native ptr 16 | * 17 | * @author liuchun 18 | */ 19 | @Keep 20 | public class WebpImage { 21 | // Access by native 22 | @Keep 23 | private long mNativePtr; 24 | 25 | private int mWidth; 26 | private int mHeigth; 27 | 28 | private int mFrameCount; 29 | private int mDurationMs; 30 | private int[] mFrameDurations; 31 | private int mLoopCount; 32 | 33 | private int mBackgroundColor; 34 | 35 | static { 36 | System.loadLibrary("glide-webp"); 37 | } 38 | 39 | public static WebpImage create(byte[] source) { 40 | Preconditions.checkNotNull(source); 41 | 42 | ByteBuffer byteBuffer = ByteBuffer.allocateDirect(source.length); 43 | byteBuffer.put(source); 44 | byteBuffer.rewind(); 45 | 46 | return nativeCreateFromDirectByteBuffer(byteBuffer); 47 | } 48 | 49 | /** 50 | * Private constructor that must received an already allocated native bitmap 51 | * int (pointer). 52 | */ 53 | // called from JNI 54 | @Keep 55 | WebpImage(long nativePtr, int width, int height, int frameCount, 56 | int durationMs, int[] frameDurations, int loopCount, 57 | int backgroundColor) { 58 | 59 | if (nativePtr == 0) { 60 | throw new RuntimeException("internal error: native WebpImage is 0"); 61 | } 62 | 63 | mWidth = width; 64 | mHeigth = height; 65 | 66 | mFrameCount = frameCount; 67 | mDurationMs = durationMs; 68 | mFrameDurations = frameDurations; 69 | mLoopCount = loopCount; 70 | fixFrameDurations(mFrameDurations); 71 | 72 | mBackgroundColor = backgroundColor; 73 | 74 | mNativePtr = nativePtr; 75 | } 76 | 77 | /** 78 | * Adjust the frame duration to respect logic for minimum frame duration times 79 | */ 80 | private void fixFrameDurations(int[] frameDurationMs) { 81 | for (int i = 0; i < frameDurationMs.length; i++) { 82 | if (frameDurationMs[i] < MIN_FRAME_DURATION_MS) { 83 | frameDurationMs[i] = FRAME_DURATION_MS_FOR_MIN; 84 | } 85 | } 86 | } 87 | 88 | @Override 89 | protected void finalize() throws Throwable { 90 | nativeFinalize(); 91 | } 92 | 93 | public void dispose(){ 94 | nativeDispose(); 95 | } 96 | 97 | public int getWidth() { 98 | return mWidth; 99 | } 100 | 101 | public int getHeight() { 102 | return mHeigth; 103 | } 104 | 105 | public int getFrameCount() { 106 | return mFrameCount; 107 | } 108 | 109 | public int getDuration() { 110 | return mDurationMs; 111 | } 112 | 113 | public int[] getFrameDurations() { 114 | return mFrameDurations; 115 | } 116 | 117 | public int getLoopCount() { 118 | return mLoopCount; 119 | } 120 | 121 | public int getBackgroundColor() { 122 | return mBackgroundColor; 123 | } 124 | 125 | public WebpFrame getFrame(int frameNubmer) { 126 | return nativeGetFrame(frameNubmer); 127 | } 128 | 129 | public WebpFrameInfo getFrameInfo(int frameNumber) { 130 | 131 | WebpFrame frame = getFrame(frameNumber); 132 | try { 133 | return new WebpFrameInfo(frameNumber, frame); 134 | } finally { 135 | frame.dispose(); 136 | } 137 | } 138 | 139 | public int getSizeInBytes() { 140 | return nativeGetSizeInBytes(); 141 | } 142 | 143 | private static native WebpImage nativeCreateFromDirectByteBuffer(ByteBuffer buffer); 144 | private native WebpFrame nativeGetFrame(int frameNumber); 145 | private native int nativeGetSizeInBytes(); 146 | private native void nativeDispose(); 147 | private native void nativeFinalize(); 148 | } 149 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/AnimatedWebpBitmapDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import androidx.annotation.NonNull; 6 | 7 | import com.bumptech.glide.integration.webp.WebpHeaderParser; 8 | import com.bumptech.glide.integration.webp.WebpImage; 9 | import com.bumptech.glide.load.Option; 10 | import com.bumptech.glide.load.Options; 11 | import com.bumptech.glide.load.engine.Resource; 12 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 13 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 14 | import com.bumptech.glide.load.resource.bitmap.BitmapResource; 15 | import com.bumptech.glide.load.resource.gif.GifBitmapProvider; 16 | 17 | import java.io.IOException; 18 | import java.io.InputStream; 19 | import java.nio.ByteBuffer; 20 | 21 | /** 22 | * Decode the animated webp image and obtain the first frame bitmap 23 | * 24 | * @author liuchun 25 | */ 26 | public class AnimatedWebpBitmapDecoder { 27 | public static final Option DISABLE_BITMAP = Option.memory( 28 | "com.bumptech.glide.integration.webp.decoder.AnimatedWebpBitmapDecoder.DisableBitmap", false); 29 | 30 | private final ArrayPool mArrayPool; 31 | private final BitmapPool mBitmapPool; 32 | private final GifBitmapProvider mProvider; 33 | 34 | public AnimatedWebpBitmapDecoder(ArrayPool byteArrayPool, BitmapPool bitmapPool) { 35 | mArrayPool = byteArrayPool; 36 | mBitmapPool = bitmapPool; 37 | mProvider = new GifBitmapProvider(bitmapPool, byteArrayPool); 38 | } 39 | 40 | public boolean handles(InputStream source, @NonNull Options options) throws IOException { 41 | if (options.get(DISABLE_BITMAP)) { 42 | return false; 43 | } 44 | WebpHeaderParser.WebpImageType webpType = WebpHeaderParser.getType(source, mArrayPool); 45 | return WebpHeaderParser.isAnimatedWebpType(webpType); 46 | } 47 | 48 | public boolean handles(ByteBuffer source, @NonNull Options options) throws IOException { 49 | if (options.get(DISABLE_BITMAP)) { 50 | return false; 51 | } 52 | WebpHeaderParser.WebpImageType webpType = WebpHeaderParser.getType(source); 53 | return WebpHeaderParser.isAnimatedWebpType(webpType); 54 | } 55 | 56 | public Resource decode(InputStream source, int width, int height, 57 | Options options) throws IOException { 58 | byte[] data = Utils.inputStreamToBytes(source); 59 | if (data == null) { 60 | return null; 61 | } 62 | ByteBuffer byteBuffer = ByteBuffer.wrap(data); 63 | return decode(byteBuffer, width, height, options); 64 | } 65 | 66 | public Resource decode(ByteBuffer source, int width, int height, 67 | Options options) throws IOException { 68 | int length = source.remaining(); 69 | byte[] data = new byte[length]; 70 | source.get(data, 0, length); 71 | 72 | WebpImage webp = WebpImage.create(data); 73 | 74 | int sampleSize = Utils.getSampleSize(webp.getWidth(), webp.getHeight(), width, height); 75 | WebpDecoder webpDecoder = new WebpDecoder(mProvider, webp, source, sampleSize); 76 | try { 77 | webpDecoder.advance(); 78 | Bitmap firstFrame = webpDecoder.getNextFrame(); 79 | return BitmapResource.obtain(firstFrame, mBitmapPool); 80 | } finally { 81 | // release the resources 82 | webpDecoder.clear(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/ByteBufferAnimatedBitmapDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.annotation.Nullable; 7 | 8 | import com.bumptech.glide.load.Options; 9 | import com.bumptech.glide.load.ResourceDecoder; 10 | import com.bumptech.glide.load.engine.Resource; 11 | 12 | import java.io.IOException; 13 | import java.nio.ByteBuffer; 14 | 15 | /** 16 | * Decodes webp {@link android.graphics.Bitmap Bitmaps} from {@link java.nio.ByteBuffer ByteBuffers}. 17 | * For Animated Webp Images 18 | * 19 | * @author liuchun 20 | */ 21 | public class ByteBufferAnimatedBitmapDecoder implements ResourceDecoder { 22 | private final AnimatedWebpBitmapDecoder bitmapDecoder; 23 | 24 | public ByteBufferAnimatedBitmapDecoder(AnimatedWebpBitmapDecoder bitmapDecoder) { 25 | this.bitmapDecoder = bitmapDecoder; 26 | } 27 | 28 | @Override 29 | public boolean handles(@NonNull ByteBuffer source, @NonNull Options options) throws IOException { 30 | return bitmapDecoder.handles(source, options); 31 | } 32 | 33 | @Nullable 34 | @Override 35 | public Resource decode(@NonNull ByteBuffer source, int width, int height, @NonNull Options options) throws IOException { 36 | return bitmapDecoder.decode(source, width, height, options); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/ByteBufferBitmapWebpDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import androidx.annotation.NonNull; 6 | 7 | import com.bumptech.glide.load.Options; 8 | import com.bumptech.glide.load.ResourceDecoder; 9 | import com.bumptech.glide.load.engine.Resource; 10 | import com.bumptech.glide.util.ByteBufferUtil; 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.nio.ByteBuffer; 15 | 16 | /** 17 | * Decodes webp {@link android.graphics.Bitmap Bitmaps} from {@link java.nio.ByteBuffer ByteBuffers}. 18 | * For static lossless and transparent webp 19 | * 20 | * @author liuchun 21 | */ 22 | public class ByteBufferBitmapWebpDecoder implements ResourceDecoder { 23 | private final WebpDownsampler downsampler; 24 | 25 | public ByteBufferBitmapWebpDecoder(WebpDownsampler downsampler) { 26 | this.downsampler = downsampler; 27 | } 28 | 29 | @Override 30 | public boolean handles(@NonNull ByteBuffer source, @NonNull Options options) throws IOException { 31 | return downsampler.handles(source, options); 32 | } 33 | 34 | @Override 35 | public Resource decode(@NonNull ByteBuffer source, int width, int height, @NonNull Options options) throws IOException { 36 | InputStream is = ByteBufferUtil.toStream(source); 37 | return downsampler.decode(is, width, height, options); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/ByteBufferWebpDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | 6 | import androidx.annotation.NonNull; 7 | import androidx.annotation.Nullable; 8 | 9 | import com.bumptech.glide.Glide; 10 | import com.bumptech.glide.load.Option; 11 | import com.bumptech.glide.load.Options; 12 | import com.bumptech.glide.load.ResourceDecoder; 13 | import com.bumptech.glide.load.Transformation; 14 | import com.bumptech.glide.load.engine.Resource; 15 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 16 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 17 | import com.bumptech.glide.load.resource.UnitTransformation; 18 | import com.bumptech.glide.load.resource.gif.GifBitmapProvider; 19 | import com.bumptech.glide.integration.webp.WebpHeaderParser; 20 | import com.bumptech.glide.integration.webp.WebpImage; 21 | 22 | import java.io.IOException; 23 | import java.nio.ByteBuffer; 24 | 25 | /** 26 | * An {@link com.bumptech.glide.load.ResourceDecoder} that decodes {@link 27 | * com.bumptech.glide.integration.webp.decoder.WebpDrawable} from {@link java.nio.ByteBuffer} data 28 | * 29 | * @author liuchun 30 | */ 31 | public class ByteBufferWebpDecoder implements ResourceDecoder { 32 | public static final Option DISABLE_ANIMATION = Option.memory( 33 | "com.bumptech.glide.integration.webp.decoder.ByteBufferWebpDecoder.DisableAnimation", false); 34 | 35 | private final Context mContext; 36 | private final BitmapPool mBitmapPool; 37 | private final GifBitmapProvider mProvider; 38 | 39 | public ByteBufferWebpDecoder(Context context) { 40 | this(context, Glide.get(context).getArrayPool(), 41 | Glide.get(context).getBitmapPool()); 42 | } 43 | 44 | public ByteBufferWebpDecoder(Context context, ArrayPool byteArrayPool, BitmapPool bitmapPool) { 45 | this.mContext = context.getApplicationContext(); 46 | this.mBitmapPool = bitmapPool; 47 | this.mProvider = new GifBitmapProvider(bitmapPool, byteArrayPool); 48 | } 49 | 50 | @Override 51 | public boolean handles(@NonNull ByteBuffer source, @NonNull Options options) throws IOException { 52 | if (options.get(DISABLE_ANIMATION)) { 53 | return false; 54 | } 55 | 56 | WebpHeaderParser.WebpImageType webpType = WebpHeaderParser.getType(source); 57 | return WebpHeaderParser.isAnimatedWebpType(webpType); 58 | } 59 | 60 | @Nullable 61 | @Override 62 | public Resource decode(@NonNull ByteBuffer source, int width, int height, @NonNull Options options) throws IOException { 63 | 64 | int length = source.remaining(); 65 | byte[] data = new byte[length]; 66 | source.get(data, 0, length); 67 | 68 | WebpImage webp = WebpImage.create(data); 69 | 70 | int sampleSize = Utils.getSampleSize(webp.getWidth(), webp.getHeight(), width, height); 71 | WebpFrameCacheStrategy cacheStrategy = options.get(WebpFrameLoader.FRAME_CACHE_STRATEGY); 72 | WebpDecoder webpDecoder = new WebpDecoder(mProvider, webp, source, sampleSize, cacheStrategy); 73 | webpDecoder.advance(); 74 | Bitmap firstFrame = webpDecoder.getNextFrame(); 75 | if (firstFrame == null) { 76 | return null; 77 | } 78 | 79 | Transformation unitTransformation = UnitTransformation.get(); 80 | 81 | return new WebpDrawableResource(new WebpDrawable(mContext, webpDecoder, mBitmapPool, unitTransformation, width, height, 82 | firstFrame)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/StreamAnimatedBitmapDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.annotation.Nullable; 7 | 8 | import com.bumptech.glide.load.Options; 9 | import com.bumptech.glide.load.ResourceDecoder; 10 | import com.bumptech.glide.load.engine.Resource; 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | 15 | /** 16 | * Decodes Webp {@link android.graphics.Bitmap Bitmaps} from {@link java.io.InputStream InputStreams}. 17 | * For Animated Webp Images 18 | * 19 | * @author liuchun 20 | */ 21 | public class StreamAnimatedBitmapDecoder implements ResourceDecoder { 22 | private final AnimatedWebpBitmapDecoder bitmapDecoder; 23 | 24 | public StreamAnimatedBitmapDecoder(AnimatedWebpBitmapDecoder bitmapDecoder) { 25 | this.bitmapDecoder = bitmapDecoder; 26 | } 27 | 28 | @Override 29 | public boolean handles(@NonNull InputStream source, @NonNull Options options) throws IOException { 30 | return bitmapDecoder.handles(source, options); 31 | } 32 | 33 | @Nullable 34 | @Override 35 | public Resource decode(@NonNull InputStream source, int width, int height, @NonNull Options options) throws IOException { 36 | return bitmapDecoder.decode(source, width, height, options); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/StreamBitmapWebpDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import androidx.annotation.NonNull; 6 | 7 | import com.bumptech.glide.load.Options; 8 | import com.bumptech.glide.load.ResourceDecoder; 9 | import com.bumptech.glide.load.engine.Resource; 10 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | 15 | /** 16 | * Decodes Webp {@link android.graphics.Bitmap Bitmaps} from {@link java.io.InputStream InputStreams}. 17 | * For static lossless and transparent webp 18 | * 19 | * @author liuchun 20 | */ 21 | public class StreamBitmapWebpDecoder implements ResourceDecoder { 22 | private final WebpDownsampler downsampler; 23 | private final ArrayPool byteArrayPool; 24 | 25 | public StreamBitmapWebpDecoder(WebpDownsampler downsampler, ArrayPool byteArrayPool) { 26 | this.downsampler = downsampler; 27 | this.byteArrayPool = byteArrayPool; 28 | } 29 | 30 | @Override 31 | public boolean handles(@NonNull InputStream source, @NonNull Options options) throws IOException { 32 | return downsampler.handles(source, options); 33 | } 34 | 35 | @Override 36 | public Resource decode(@NonNull InputStream source, int width, int height, @NonNull Options options) throws IOException { 37 | return downsampler.decode(source, width, height, options); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/StreamWebpDecoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | 4 | import androidx.annotation.NonNull; 5 | import androidx.annotation.Nullable; 6 | 7 | import com.bumptech.glide.load.Option; 8 | import com.bumptech.glide.load.Options; 9 | import com.bumptech.glide.load.ResourceDecoder; 10 | import com.bumptech.glide.load.engine.Resource; 11 | import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; 12 | import com.bumptech.glide.integration.webp.WebpHeaderParser; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.nio.ByteBuffer; 17 | 18 | 19 | /** 20 | * An {@link com.bumptech.glide.load.ResourceDecoder} that decodes {@link 21 | * com.bumptech.glide.integration.webp.decoder.WebpDrawable} from {@link java.io.InputStream} data 22 | * 23 | * @author liuchun 24 | */ 25 | public class StreamWebpDecoder implements ResourceDecoder { 26 | public static final Option DISABLE_ANIMATION = Option.memory( 27 | "com.bumptech.glide.integration.webp.decoder.StreamWebpDecoder.DisableAnimation", false); 28 | 29 | private final ResourceDecoder byteBufferDecoder; 30 | private final ArrayPool byteArrayPool; 31 | 32 | public StreamWebpDecoder(ResourceDecoder byteBufferDecoder, ArrayPool byteArrayPool) { 33 | this.byteBufferDecoder = byteBufferDecoder; 34 | this.byteArrayPool = byteArrayPool; 35 | } 36 | 37 | 38 | @Override 39 | public boolean handles(@NonNull InputStream inputStream, @NonNull Options options) throws IOException { 40 | if (options.get(DISABLE_ANIMATION)) { 41 | return false; 42 | } 43 | 44 | WebpHeaderParser.WebpImageType webpType = WebpHeaderParser.getType(inputStream, byteArrayPool); 45 | return WebpHeaderParser.isAnimatedWebpType(webpType); 46 | } 47 | 48 | @Nullable 49 | @Override 50 | public Resource decode(@NonNull InputStream inputStream, int width, int height, @NonNull Options options) throws IOException { 51 | 52 | byte[] data = Utils.inputStreamToBytes(inputStream); 53 | if (data == null) { 54 | return null; 55 | } 56 | ByteBuffer byteBuffer = ByteBuffer.wrap(data); 57 | 58 | return byteBufferDecoder.decode(byteBuffer, width, height, options); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/Utils.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.ByteArrayOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | 9 | /** 10 | * @author liuchun 11 | */ 12 | class Utils { 13 | private static final String TAG = "Utils"; 14 | 15 | static int getSampleSize(int srcWidth, int srcHeight, int targetWidth, int targetHeight) { 16 | int exactSampleSize = Math.min(srcHeight / targetHeight, 17 | srcWidth / targetWidth); 18 | int powerOfTwoSampleSize = exactSampleSize == 0 ? 0 : Integer.highestOneBit(exactSampleSize); 19 | // Although functionally equivalent to 0 for BitmapFactory, 1 is a safer default for our code 20 | // than 0. 21 | int sampleSize = Math.max(1, powerOfTwoSampleSize); 22 | if (Log.isLoggable(TAG, Log.VERBOSE) && sampleSize > 1) { 23 | Log.v(TAG, "Downsampling WEBP" 24 | + ", sampleSize: " + sampleSize 25 | + ", target dimens: [" + targetWidth + "x" + targetHeight + "]" 26 | + ", actual dimens: [" + srcWidth + "x" + srcHeight + "]"); 27 | } 28 | return sampleSize; 29 | } 30 | 31 | static byte[] inputStreamToBytes(InputStream is) { 32 | final int bufferSize = 16384; 33 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(bufferSize); 34 | try { 35 | int nRead; 36 | byte[] data = new byte[bufferSize]; 37 | while ((nRead = is.read(data)) != -1) { 38 | buffer.write(data, 0, nRead); 39 | } 40 | buffer.flush(); 41 | } catch (IOException e) { 42 | if (Log.isLoggable(TAG, Log.WARN)) { 43 | Log.w(TAG, "Error reading data from stream", e); 44 | } 45 | return null; 46 | } 47 | return buffer.toByteArray(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/WebpDrawableEncoder.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.util.Log; 4 | 5 | import com.bumptech.glide.load.EncodeStrategy; 6 | import com.bumptech.glide.load.Options; 7 | import com.bumptech.glide.load.ResourceEncoder; 8 | import com.bumptech.glide.load.engine.Resource; 9 | import com.bumptech.glide.util.ByteBufferUtil; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | 14 | /** 15 | * Writes the original bytes of a {@link com.bumptech.glide.integration.webp.decoder.WebpDrawable} to an 16 | * {@link java.io.OutputStream}. 17 | * 18 | * @author liuchun 19 | */ 20 | public class WebpDrawableEncoder implements ResourceEncoder { 21 | private static final String TAG = "WebpEncoder"; 22 | 23 | @Override 24 | public EncodeStrategy getEncodeStrategy(Options options) { 25 | return EncodeStrategy.SOURCE; 26 | } 27 | 28 | @Override 29 | public boolean encode(Resource data, File file, Options options) { 30 | WebpDrawable drawable = data.get(); 31 | boolean success = false; 32 | try { 33 | ByteBufferUtil.toFile(drawable.getBuffer(), file); 34 | success = true; 35 | } catch (IOException e) { 36 | if (Log.isLoggable(TAG, Log.WARN)) { 37 | Log.w(TAG, "Failed to encode WebP drawable data", e); 38 | } 39 | } 40 | return success; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/WebpDrawableResource.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import com.bumptech.glide.load.engine.Initializable; 4 | import com.bumptech.glide.load.resource.drawable.DrawableResource; 5 | 6 | /** 7 | * @author liuchun 8 | */ 9 | public class WebpDrawableResource extends DrawableResource implements Initializable { 10 | 11 | public WebpDrawableResource(WebpDrawable drawable) { 12 | super(drawable); 13 | } 14 | 15 | public Class getResourceClass() { 16 | return WebpDrawable.class; 17 | } 18 | 19 | public int getSize() { 20 | return drawable.getSize(); 21 | } 22 | 23 | public void recycle() { 24 | drawable.stop(); 25 | drawable.recycle(); 26 | } 27 | 28 | public void initialize() { 29 | drawable.getFirstFrame().prepareToDraw(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/WebpDrawableTransformation.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.load.Transformation; 8 | import com.bumptech.glide.load.engine.Resource; 9 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 10 | import com.bumptech.glide.load.resource.bitmap.BitmapResource; 11 | import com.bumptech.glide.util.Preconditions; 12 | 13 | import java.security.MessageDigest; 14 | 15 | /** 16 | * An {@link com.bumptech.glide.load.Transformation} that wraps a transformation for a 17 | * {@link Bitmap} and can apply it to every frame of any 18 | * {@link com.bumptech.glide.integration.webp.decoder.WebpDrawable}. 19 | * 20 | * @author liuchun 21 | */ 22 | public class WebpDrawableTransformation implements Transformation { 23 | private final Transformation wrapped; 24 | 25 | public WebpDrawableTransformation(Transformation wrapped) { 26 | this.wrapped = Preconditions.checkNotNull(wrapped); 27 | } 28 | 29 | @Override 30 | public Resource transform(Context context, Resource resource, int outWidth, int outHeight) { 31 | WebpDrawable drawable = resource.get(); 32 | 33 | // The drawable needs to be initialized with the correct width and height in order for a view 34 | // displaying it to end up with the right dimensions. Since our transformations may arbitrarily 35 | // modify the dimensions of our GIF, here we create a stand in for a frame and pass it to the 36 | // transformation to see what the final transformed dimensions will be so that our drawable can 37 | // report the correct intrinsic width and height. 38 | BitmapPool bitmapPool = Glide.get(context).getBitmapPool(); 39 | Bitmap firstFrame = drawable.getFirstFrame(); 40 | Resource bitmapResource = new BitmapResource(firstFrame, bitmapPool); 41 | Resource transformed = wrapped.transform(context, bitmapResource, outWidth, outHeight); 42 | if (!bitmapResource.equals(transformed)) { 43 | bitmapResource.recycle(); 44 | } 45 | Bitmap transformedFrame = transformed.get(); 46 | 47 | drawable.setFrameTransformation(wrapped, transformedFrame); 48 | return resource; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (o instanceof WebpDrawableTransformation) { 54 | WebpDrawableTransformation other = (WebpDrawableTransformation) o; 55 | return wrapped.equals(other.wrapped); 56 | } 57 | return false; 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return wrapped.hashCode(); 63 | } 64 | 65 | @Override 66 | public void updateDiskCacheKey(MessageDigest messageDigest) { 67 | wrapped.updateDiskCacheKey(messageDigest); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /webp_decoder/src/main/java/com/bumptech/glide/integration/webp/decoder/WebpFrameCacheStrategy.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.integration.webp.decoder; 2 | 3 | /** 4 | * author: liuchun 5 | * date: 2019-05-15 6 | */ 7 | public final class WebpFrameCacheStrategy { 8 | 9 | public static final WebpFrameCacheStrategy NONE = new Builder().noCache().build(); 10 | 11 | public static final WebpFrameCacheStrategy AUTO = new Builder().cacheAuto().build(); 12 | 13 | public static final WebpFrameCacheStrategy ALL = new Builder().cacheAll().build(); 14 | 15 | public enum CacheControl { 16 | CACHE_NONE, 17 | CACHE_LIMITED, 18 | CACHE_AUTO, 19 | CACHE_ALL, 20 | } 21 | 22 | private CacheControl mCacheStrategy; 23 | private int mCacheSize; 24 | 25 | private WebpFrameCacheStrategy(Builder builder) { 26 | this.mCacheStrategy = builder.cacheControl; 27 | this.mCacheSize = builder.cacheSize; 28 | } 29 | 30 | public CacheControl getCacheControl() { 31 | return this.mCacheStrategy; 32 | } 33 | 34 | public boolean noCache() { 35 | return mCacheStrategy == CacheControl.CACHE_NONE; 36 | } 37 | 38 | public boolean cacheAuto() { 39 | return mCacheStrategy == CacheControl.CACHE_AUTO; 40 | } 41 | 42 | public boolean cacheAll() { 43 | return mCacheStrategy == CacheControl.CACHE_ALL; 44 | } 45 | 46 | public int getCacheSize() { 47 | return this.mCacheSize; 48 | } 49 | 50 | public final static class Builder { 51 | private CacheControl cacheControl; 52 | private int cacheSize; 53 | 54 | public Builder noCache() { 55 | this.cacheControl = CacheControl.CACHE_NONE; 56 | return this; 57 | } 58 | 59 | public Builder cacheAll() { 60 | this.cacheControl = CacheControl.CACHE_ALL; 61 | return this; 62 | } 63 | 64 | public Builder cacheAuto() { 65 | this.cacheControl = CacheControl.CACHE_AUTO; 66 | return this; 67 | } 68 | 69 | public Builder cacheLimited() { 70 | this.cacheControl = CacheControl.CACHE_LIMITED; 71 | return this; 72 | } 73 | 74 | public Builder cacheControl(CacheControl control) { 75 | this.cacheControl = control; 76 | return this; 77 | } 78 | 79 | public Builder cacheSize(int cacheSize) { 80 | this.cacheSize = cacheSize; 81 | if (cacheSize == 0) { 82 | this.cacheControl = CacheControl.CACHE_NONE; 83 | } else if (cacheSize == Integer.MAX_VALUE) { 84 | this.cacheControl = CacheControl.CACHE_ALL; 85 | } else { 86 | this.cacheControl = CacheControl.CACHE_LIMITED; 87 | } 88 | return this; 89 | } 90 | 91 | public WebpFrameCacheStrategy build() { 92 | return new WebpFrameCacheStrategy(this); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | LOCAL_MODULE := glide-webp 6 | LOCAL_SRC_FILES := \ 7 | jni_common.cpp \ 8 | webp.cpp \ 9 | 10 | CXX11_FLAGS := -std=c++11 11 | LOCAL_CFLAGS += $(CXX11_FLAGS) 12 | #LOCAL_CFLAGS += -DLOG_TAG=\"libglide-webp\" 13 | LOCAL_CFLAGS += -fvisibility=hidden 14 | #LOCAL_CFLAGS += $(FRESCO_CPP_CFLAGS) 15 | LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS) 16 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 17 | LOCAL_LDLIBS := -latomic -llog -ljnigraphics 18 | LOCAL_LDFLAGS += $(GLIDE_CPP_LDFLAGS) 19 | 20 | ifeq ($(TARGET_ARCH_ABI),arm64-v8a) 21 | LOCAL_LDFLAGS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384 22 | else ifeq ($(TARGET_ARCH_ABI), x86_64) 23 | LOCAL_LDFLAGS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384 24 | endif 25 | 26 | LOCAL_STATIC_LIBRARIES += c++_static 27 | LOCAL_SHARED_LIBRARIES += webp 28 | 29 | include $(BUILD_SHARED_LIBRARY) 30 | $(call import-module,libwebp) -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_BUILD_SCRIPT := Android.mk 2 | 3 | APP_ABI := armeabi-v7a armeabi arm64-v8a x86 x86_64 4 | 5 | APP_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST))) 6 | NDK_MODULE_PATH := $(APP_MK_DIR) 7 | 8 | APP_OPTIM := release 9 | 10 | APP_STL := c++_static 11 | 12 | # Make sure every shared lib includes a .note.gnu.build-id header 13 | #APP_LDFLAGS := -Wl,--build-id 14 | 15 | #NDK_TOOLCHAIN_VERSION := clang 16 | 17 | # We link our libs with static stl implementation. Because of that we need to 18 | # hide all stl related symbols to make them unaccessible from the outside. 19 | # We also need to make sure that our library does not use any stl functions 20 | # coming from other stl implementations as well 21 | 22 | # This hides all symbols exported from libc++_static 23 | GLIDE_CPP_LDFLAGS := -Wl,--gc-sections,--exclude-libs,libc++_static.a -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/Makefile.am: -------------------------------------------------------------------------------- 1 | # The mux and demux 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 BUILD_MUX 5 | SUBDIRS += mux 6 | endif 7 | if BUILD_DEMUX 8 | SUBDIRS += demux 9 | endif 10 | 11 | lib_LTLIBRARIES = libwebp.la 12 | 13 | if BUILD_LIBWEBPDECODER 14 | lib_LTLIBRARIES += libwebpdecoder.la 15 | endif 16 | 17 | common_HEADERS = 18 | common_HEADERS += webp/decode.h 19 | common_HEADERS += webp/types.h 20 | commondir = $(includedir)/webp 21 | 22 | libwebp_la_SOURCES = 23 | libwebpinclude_HEADERS = 24 | libwebpinclude_HEADERS += webp/encode.h 25 | 26 | noinst_HEADERS = 27 | noinst_HEADERS += webp/format_constants.h 28 | 29 | libwebp_la_LIBADD = 30 | libwebp_la_LIBADD += dec/libwebpdecode.la 31 | libwebp_la_LIBADD += dsp/libwebpdsp.la 32 | libwebp_la_LIBADD += enc/libwebpencode.la 33 | libwebp_la_LIBADD += utils/libwebputils.la 34 | 35 | # Use '-no-undefined' to declare that libwebp does not depend on any libraries 36 | # other than the ones listed on the command line, i.e., after linking, it will 37 | # not have unresolved symbols. Some platforms (Windows among them) require all 38 | # symbols in shared libraries to be resolved at library creation. 39 | libwebp_la_LDFLAGS = -no-undefined -version-info 8:8:1 40 | libwebpincludedir = $(includedir)/webp 41 | pkgconfig_DATA = libwebp.pc 42 | 43 | if BUILD_LIBWEBPDECODER 44 | libwebpdecoder_la_SOURCES = 45 | 46 | libwebpdecoder_la_LIBADD = 47 | libwebpdecoder_la_LIBADD += dec/libwebpdecode.la 48 | libwebpdecoder_la_LIBADD += dsp/libwebpdspdecode.la 49 | libwebpdecoder_la_LIBADD += utils/libwebputilsdecode.la 50 | 51 | libwebpdecoder_la_LDFLAGS = -no-undefined -version-info 4:8:1 52 | pkgconfig_DATA += libwebpdecoder.pc 53 | endif 54 | 55 | ${pkgconfig_DATA}: ${top_builddir}/config.status 56 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/dec/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS += -I$(top_builddir) -I$(top_srcdir) 2 | noinst_LTLIBRARIES = libwebpdecode.la 3 | 4 | libwebpdecode_la_SOURCES = 5 | libwebpdecode_la_SOURCES += alpha_dec.c 6 | libwebpdecode_la_SOURCES += alphai_dec.h 7 | libwebpdecode_la_SOURCES += buffer_dec.c 8 | libwebpdecode_la_SOURCES += common_dec.h 9 | libwebpdecode_la_SOURCES += vp8_dec.h 10 | libwebpdecode_la_SOURCES += frame_dec.c 11 | libwebpdecode_la_SOURCES += idec_dec.c 12 | libwebpdecode_la_SOURCES += io_dec.c 13 | libwebpdecode_la_SOURCES += quant_dec.c 14 | libwebpdecode_la_SOURCES += tree_dec.c 15 | libwebpdecode_la_SOURCES += vp8_dec.c 16 | libwebpdecode_la_SOURCES += vp8i_dec.h 17 | libwebpdecode_la_SOURCES += vp8l_dec.c 18 | libwebpdecode_la_SOURCES += vp8li_dec.h 19 | libwebpdecode_la_SOURCES += webp_dec.c 20 | libwebpdecode_la_SOURCES += webpi_dec.h 21 | 22 | libwebpdecodeinclude_HEADERS = 23 | libwebpdecodeinclude_HEADERS += ../webp/decode.h 24 | libwebpdecodeinclude_HEADERS += ../webp/types.h 25 | noinst_HEADERS = 26 | noinst_HEADERS += ../webp/format_constants.h 27 | 28 | libwebpdecode_la_CPPFLAGS = $(AM_CPPFLAGS) 29 | libwebpdecodeincludedir = $(includedir)/webp 30 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/dec/alphai_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 decoder: internal header. 11 | // 12 | // Author: Urvang (urvang@google.com) 13 | 14 | #ifndef WEBP_DEC_ALPHAI_DEC_H_ 15 | #define WEBP_DEC_ALPHAI_DEC_H_ 16 | 17 | #include "src/dec/webpi_dec.h" 18 | #include "src/utils/filters_utils.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 | uint8_t* output_; 39 | const uint8_t* prev_line_; // last output row (or NULL) 40 | }; 41 | 42 | //------------------------------------------------------------------------------ 43 | // internal functions. Not public. 44 | 45 | // Deallocate memory associated to dec->alpha_plane_ decoding 46 | void WebPDeallocateAlphaMemory(VP8Decoder* const dec); 47 | 48 | //------------------------------------------------------------------------------ 49 | 50 | #ifdef __cplusplus 51 | } // extern "C" 52 | #endif 53 | 54 | #endif // WEBP_DEC_ALPHAI_DEC_H_ 55 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/dec/common_dec.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_DEC_H_ 15 | #define WEBP_DEC_COMMON_DEC_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_DEC_H_ 55 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/demux/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS += -I$(top_builddir) -I$(top_srcdir) 2 | lib_LTLIBRARIES = libwebpdemux.la 3 | 4 | libwebpdemux_la_SOURCES = 5 | libwebpdemux_la_SOURCES += anim_decode.c demux.c 6 | 7 | libwebpdemuxinclude_HEADERS = 8 | libwebpdemuxinclude_HEADERS += ../webp/decode.h 9 | libwebpdemuxinclude_HEADERS += ../webp/demux.h 10 | libwebpdemuxinclude_HEADERS += ../webp/mux_types.h 11 | libwebpdemuxinclude_HEADERS += ../webp/types.h 12 | noinst_HEADERS = 13 | noinst_HEADERS += ../webp/format_constants.h 14 | 15 | libwebpdemux_la_LIBADD = ../libwebp.la 16 | libwebpdemux_la_LDFLAGS = -no-undefined -version-info 2:14:0 17 | libwebpdemuxincludedir = $(includedir)/webp 18 | pkgconfig_DATA = libwebpdemux.pc 19 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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.private: libwebp >= 0.2.0 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -l@webp_libname_prefix@webpdemux 12 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/demux/libwebpdemux.rc: -------------------------------------------------------------------------------- 1 | #define APSTUDIO_READONLY_SYMBOLS 2 | #include "winres.h" 3 | #undef APSTUDIO_READONLY_SYMBOLS 4 | 5 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 6 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 7 | 8 | VS_VERSION_INFO VERSIONINFO 9 | FILEVERSION 1,0,3,2 10 | PRODUCTVERSION 1,0,3,2 11 | FILEFLAGSMASK 0x3fL 12 | #ifdef _DEBUG 13 | FILEFLAGS 0x1L 14 | #else 15 | FILEFLAGS 0x0L 16 | #endif 17 | FILEOS 0x40004L 18 | FILETYPE 0x2L 19 | FILESUBTYPE 0x0L 20 | BEGIN 21 | BLOCK "StringFileInfo" 22 | BEGIN 23 | BLOCK "040904b0" 24 | BEGIN 25 | VALUE "CompanyName", "Google, Inc." 26 | VALUE "FileDescription", "libwebpdemux DLL" 27 | VALUE "FileVersion", "1.3.2" 28 | VALUE "InternalName", "libwebpdemux.dll" 29 | VALUE "LegalCopyright", "Copyright (C) 2023" 30 | VALUE "OriginalFilename", "libwebpdemux.dll" 31 | VALUE "ProductName", "WebP Image Demuxer" 32 | VALUE "ProductVersion", "1.3.2" 33 | END 34 | END 35 | BLOCK "VarFileInfo" 36 | BEGIN 37 | VALUE "Translation", 0x409, 1200 38 | END 39 | END 40 | 41 | #endif // English (United States) resources 42 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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 "src/dsp/dsp.h" 15 | 16 | #if defined(WEBP_USE_SSE41) 17 | 18 | #include 19 | 20 | //------------------------------------------------------------------------------ 21 | 22 | static int ExtractAlpha_SSE41(const uint8_t* WEBP_RESTRICT argb, 23 | int argb_stride, int width, int height, 24 | uint8_t* WEBP_RESTRICT 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(~0); 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_SSE41; 86 | } 87 | 88 | #else // !WEBP_USE_SSE41 89 | 90 | WEBP_DSP_INIT_STUB(WebPInitAlphaProcessingSSE41) 91 | 92 | #endif // WEBP_USE_SSE41 93 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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 "src/dsp/dsp.h" 15 | 16 | #if defined(WEBP_USE_SSE41) 17 | 18 | #include 19 | #include "src/dec/vp8i_dec.h" 20 | #include "src/utils/utils.h" 21 | 22 | static void HE16_SSE41(uint8_t* dst) { // horizontal 23 | int j; 24 | const __m128i kShuffle3 = _mm_set1_epi8(3); 25 | for (j = 16; j > 0; --j) { 26 | const __m128i in = _mm_cvtsi32_si128(WebPMemToInt32(dst - 4)); 27 | const __m128i values = _mm_shuffle_epi8(in, kShuffle3); 28 | _mm_storeu_si128((__m128i*)dst, values); 29 | dst += BPS; 30 | } 31 | } 32 | 33 | //------------------------------------------------------------------------------ 34 | // Entry point 35 | 36 | extern void VP8DspInitSSE41(void); 37 | 38 | WEBP_TSAN_IGNORE_FUNCTION void VP8DspInitSSE41(void) { 39 | VP8PredLuma16[3] = HE16_SSE41; 40 | } 41 | 42 | #else // !WEBP_USE_SSE41 43 | 44 | WEBP_DSP_INIT_STUB(VP8DspInitSSE41) 45 | 46 | #endif // WEBP_USE_SSE41 47 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/dsp/quant.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 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 | #ifndef WEBP_DSP_QUANT_H_ 11 | #define WEBP_DSP_QUANT_H_ 12 | 13 | #include 14 | 15 | #include "src/dsp/dsp.h" 16 | #include "src/webp/types.h" 17 | 18 | #if defined(WEBP_USE_NEON) && !defined(WEBP_ANDROID_NEON) && \ 19 | !defined(WEBP_HAVE_NEON_RTCD) 20 | #include 21 | 22 | #define IsFlat IsFlat_NEON 23 | 24 | static uint32_t horizontal_add_uint32x4(const uint32x4_t a) { 25 | #if WEBP_AARCH64 26 | return vaddvq_u32(a); 27 | #else 28 | const uint64x2_t b = vpaddlq_u32(a); 29 | const uint32x2_t c = vadd_u32(vreinterpret_u32_u64(vget_low_u64(b)), 30 | vreinterpret_u32_u64(vget_high_u64(b))); 31 | return vget_lane_u32(c, 0); 32 | #endif 33 | } 34 | 35 | static WEBP_INLINE int IsFlat(const int16_t* levels, int num_blocks, 36 | int thresh) { 37 | const int16x8_t tst_ones = vdupq_n_s16(-1); 38 | uint32x4_t sum = vdupq_n_u32(0); 39 | 40 | for (int i = 0; i < num_blocks; ++i) { 41 | // Set DC to zero. 42 | const int16x8_t a_0 = vsetq_lane_s16(0, vld1q_s16(levels), 0); 43 | const int16x8_t a_1 = vld1q_s16(levels + 8); 44 | 45 | const uint16x8_t b_0 = vshrq_n_u16(vtstq_s16(a_0, tst_ones), 15); 46 | const uint16x8_t b_1 = vshrq_n_u16(vtstq_s16(a_1, tst_ones), 15); 47 | 48 | sum = vpadalq_u16(sum, b_0); 49 | sum = vpadalq_u16(sum, b_1); 50 | 51 | levels += 16; 52 | } 53 | return thresh >= (int)horizontal_add_uint32x4(sum); 54 | } 55 | 56 | #else 57 | 58 | #define IsFlat IsFlat_C 59 | 60 | static WEBP_INLINE int IsFlat(const int16_t* levels, int num_blocks, 61 | int thresh) { 62 | int score = 0; 63 | while (num_blocks-- > 0) { // TODO(skal): refine positional scoring? 64 | int i; 65 | for (i = 1; i < 16; ++i) { // omit DC, we're only interested in AC 66 | score += (levels[i] != 0); 67 | if (score > thresh) return 0; 68 | } 69 | levels += 16; 70 | } 71 | return 1; 72 | } 73 | 74 | #endif // defined(WEBP_USE_NEON) && !defined(WEBP_ANDROID_NEON) && 75 | // !defined(WEBP_HAVE_NEON_RTCD) 76 | 77 | static WEBP_INLINE int IsFlatSource16(const uint8_t* src) { 78 | const uint32_t v = src[0] * 0x01010101u; 79 | int i; 80 | for (i = 0; i < 16; ++i) { 81 | if (memcmp(src + 0, &v, 4) || memcmp(src + 4, &v, 4) || 82 | memcmp(src + 8, &v, 4) || memcmp(src + 12, &v, 4)) { 83 | return 0; 84 | } 85 | src += BPS; 86 | } 87 | return 1; 88 | } 89 | 90 | #endif // WEBP_DSP_QUANT_H_ 91 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/enc/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS += -I$(top_builddir) -I$(top_srcdir) 2 | noinst_LTLIBRARIES = libwebpencode.la 3 | 4 | libwebpencode_la_SOURCES = 5 | libwebpencode_la_SOURCES += alpha_enc.c 6 | libwebpencode_la_SOURCES += analysis_enc.c 7 | libwebpencode_la_SOURCES += backward_references_cost_enc.c 8 | libwebpencode_la_SOURCES += backward_references_enc.c 9 | libwebpencode_la_SOURCES += backward_references_enc.h 10 | libwebpencode_la_SOURCES += config_enc.c 11 | libwebpencode_la_SOURCES += cost_enc.c 12 | libwebpencode_la_SOURCES += cost_enc.h 13 | libwebpencode_la_SOURCES += filter_enc.c 14 | libwebpencode_la_SOURCES += frame_enc.c 15 | libwebpencode_la_SOURCES += histogram_enc.c 16 | libwebpencode_la_SOURCES += histogram_enc.h 17 | libwebpencode_la_SOURCES += iterator_enc.c 18 | libwebpencode_la_SOURCES += near_lossless_enc.c 19 | libwebpencode_la_SOURCES += picture_enc.c 20 | libwebpencode_la_SOURCES += picture_csp_enc.c 21 | libwebpencode_la_SOURCES += picture_psnr_enc.c 22 | libwebpencode_la_SOURCES += picture_rescale_enc.c 23 | libwebpencode_la_SOURCES += picture_tools_enc.c 24 | libwebpencode_la_SOURCES += predictor_enc.c 25 | libwebpencode_la_SOURCES += quant_enc.c 26 | libwebpencode_la_SOURCES += syntax_enc.c 27 | libwebpencode_la_SOURCES += token_enc.c 28 | libwebpencode_la_SOURCES += tree_enc.c 29 | libwebpencode_la_SOURCES += vp8i_enc.h 30 | libwebpencode_la_SOURCES += vp8l_enc.c 31 | libwebpencode_la_SOURCES += vp8li_enc.h 32 | libwebpencode_la_SOURCES += webp_enc.c 33 | 34 | libwebpencodeinclude_HEADERS = 35 | libwebpencodeinclude_HEADERS += ../webp/encode.h 36 | libwebpencodeinclude_HEADERS += ../webp/types.h 37 | noinst_HEADERS = 38 | noinst_HEADERS += ../webp/format_constants.h 39 | 40 | libwebpencode_la_LIBADD = ../../sharpyuv/libsharpyuv.la 41 | libwebpencode_la_LDFLAGS = -lm 42 | libwebpencode_la_CPPFLAGS = $(AM_CPPFLAGS) 43 | libwebpencodeincludedir = $(includedir)/webp 44 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/enc/cost_enc.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_ENC_H_ 15 | #define WEBP_ENC_COST_ENC_H_ 16 | 17 | #include 18 | #include 19 | #include "src/enc/vp8i_enc.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 | // Record proba context used. 45 | static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) { 46 | proba_t p = *stats; 47 | // An overflow is inbound. Note we handle this at 0xfffe0000u instead of 48 | // 0xffff0000u to make sure p + 1u does not overflow. 49 | if (p >= 0xfffe0000u) { 50 | p = ((p + 1u) >> 1) & 0x7fff7fffu; // -> divide the stats by 2. 51 | } 52 | // record bit count (lower 16 bits) and increment total count (upper 16 bits). 53 | p += 0x00010000u + bit; 54 | *stats = p; 55 | return bit; 56 | } 57 | 58 | // Cost of coding one event with probability 'proba'. 59 | static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) { 60 | return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba]; 61 | } 62 | 63 | // Level cost calculations 64 | extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2]; 65 | void VP8CalculateLevelCosts(VP8EncProba* const proba); 66 | static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) { 67 | return VP8LevelFixedCosts[level] 68 | + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level]; 69 | } 70 | 71 | // Mode costs 72 | extern const uint16_t VP8FixedCostsUV[4]; 73 | extern const uint16_t VP8FixedCostsI16[4]; 74 | extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES]; 75 | 76 | //------------------------------------------------------------------------------ 77 | 78 | #ifdef __cplusplus 79 | } // extern "C" 80 | #endif 81 | 82 | #endif // WEBP_ENC_COST_ENC_H_ 83 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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 | Requires.private: libsharpyuv 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -l@webp_libname_prefix@webp 12 | Libs.private: -lm @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ 13 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/libwebp.rc: -------------------------------------------------------------------------------- 1 | #define APSTUDIO_READONLY_SYMBOLS 2 | #include "winres.h" 3 | #undef APSTUDIO_READONLY_SYMBOLS 4 | 5 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 6 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 7 | 8 | VS_VERSION_INFO VERSIONINFO 9 | FILEVERSION 1,0,3,2 10 | PRODUCTVERSION 1,0,3,2 11 | FILEFLAGSMASK 0x3fL 12 | #ifdef _DEBUG 13 | FILEFLAGS 0x1L 14 | #else 15 | FILEFLAGS 0x0L 16 | #endif 17 | FILEOS 0x40004L 18 | FILETYPE 0x2L 19 | FILESUBTYPE 0x0L 20 | BEGIN 21 | BLOCK "StringFileInfo" 22 | BEGIN 23 | BLOCK "040904b0" 24 | BEGIN 25 | VALUE "CompanyName", "Google, Inc." 26 | VALUE "FileDescription", "libwebp DLL" 27 | VALUE "FileVersion", "1.3.2" 28 | VALUE "InternalName", "libwebp.dll" 29 | VALUE "LegalCopyright", "Copyright (C) 2023" 30 | VALUE "OriginalFilename", "libwebp.dll" 31 | VALUE "ProductName", "WebP Image Codec" 32 | VALUE "ProductVersion", "1.3.2" 33 | END 34 | END 35 | BLOCK "VarFileInfo" 36 | BEGIN 37 | VALUE "Translation", 0x409, 1200 38 | END 39 | END 40 | 41 | #endif // English (United States) resources 42 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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} -l@webp_libname_prefix@webpdecoder 11 | Libs.private: -lm @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ 12 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/libwebpdecoder.rc: -------------------------------------------------------------------------------- 1 | #define APSTUDIO_READONLY_SYMBOLS 2 | #include "winres.h" 3 | #undef APSTUDIO_READONLY_SYMBOLS 4 | 5 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 6 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 7 | 8 | VS_VERSION_INFO VERSIONINFO 9 | FILEVERSION 1,0,3,2 10 | PRODUCTVERSION 1,0,3,2 11 | FILEFLAGSMASK 0x3fL 12 | #ifdef _DEBUG 13 | FILEFLAGS 0x1L 14 | #else 15 | FILEFLAGS 0x0L 16 | #endif 17 | FILEOS 0x40004L 18 | FILETYPE 0x2L 19 | FILESUBTYPE 0x0L 20 | BEGIN 21 | BLOCK "StringFileInfo" 22 | BEGIN 23 | BLOCK "040904b0" 24 | BEGIN 25 | VALUE "CompanyName", "Google, Inc." 26 | VALUE "FileDescription", "libwebpdecoder DLL" 27 | VALUE "FileVersion", "1.3.2" 28 | VALUE "InternalName", "libwebpdecoder.dll" 29 | VALUE "LegalCopyright", "Copyright (C) 2023" 30 | VALUE "OriginalFilename", "libwebpdecoder.dll" 31 | VALUE "ProductName", "WebP Image Decoder" 32 | VALUE "ProductVersion", "1.3.2" 33 | END 34 | END 35 | BLOCK "VarFileInfo" 36 | BEGIN 37 | VALUE "Translation", 0x409, 1200 38 | END 39 | END 40 | 41 | #endif // English (United States) resources 42 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/mux/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS += -I$(top_builddir) -I$(top_srcdir) 2 | lib_LTLIBRARIES = libwebpmux.la 3 | 4 | libwebpmux_la_SOURCES = 5 | libwebpmux_la_SOURCES += anim_encode.c 6 | libwebpmux_la_SOURCES += animi.h 7 | libwebpmux_la_SOURCES += muxedit.c 8 | libwebpmux_la_SOURCES += muxi.h 9 | libwebpmux_la_SOURCES += muxinternal.c 10 | libwebpmux_la_SOURCES += muxread.c 11 | 12 | libwebpmuxinclude_HEADERS = 13 | libwebpmuxinclude_HEADERS += ../webp/mux.h 14 | libwebpmuxinclude_HEADERS += ../webp/mux_types.h 15 | libwebpmuxinclude_HEADERS += ../webp/types.h 16 | noinst_HEADERS = 17 | noinst_HEADERS += ../webp/format_constants.h 18 | 19 | libwebpmux_la_LIBADD = ../libwebp.la 20 | libwebpmux_la_LDFLAGS = -no-undefined -version-info 3:13:0 -lm 21 | libwebpmuxincludedir = $(includedir)/webp 22 | pkgconfig_DATA = libwebpmux.pc 23 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/mux/animi.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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 animation related functions. 11 | // 12 | // Author: Hui Su (huisu@google.com) 13 | 14 | #ifndef WEBP_MUX_ANIMI_H_ 15 | #define WEBP_MUX_ANIMI_H_ 16 | 17 | #include "src/webp/mux.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | // Picks the optimal rectangle between two pictures, starting with initial 24 | // values of offsets and dimensions that are passed in. The initial 25 | // values will be clipped, if necessary, to make sure the rectangle is 26 | // within the canvas. "use_argb" must be true for both pictures. 27 | // Parameters: 28 | // prev_canvas, curr_canvas - (in) two input pictures to compare. 29 | // is_lossless, quality - (in) encoding settings. 30 | // x_offset, y_offset, width, height - (in/out) rectangle between the two 31 | // input pictures. 32 | // Returns true on success. 33 | int WebPAnimEncoderRefineRect( 34 | const struct WebPPicture* const prev_canvas, 35 | const struct WebPPicture* const curr_canvas, 36 | int is_lossless, float quality, int* const x_offset, int* const y_offset, 37 | int* const width, int* const height); 38 | 39 | #ifdef __cplusplus 40 | } // extern "C" 41 | #endif 42 | 43 | #endif // WEBP_MUX_ANIMI_H_ 44 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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.private: libwebp >= 0.2.0 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -l@webp_libname_prefix@webpmux 12 | Libs.private: -lm 13 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/mux/libwebpmux.rc: -------------------------------------------------------------------------------- 1 | #define APSTUDIO_READONLY_SYMBOLS 2 | #include "winres.h" 3 | #undef APSTUDIO_READONLY_SYMBOLS 4 | 5 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 6 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 7 | 8 | VS_VERSION_INFO VERSIONINFO 9 | FILEVERSION 1,0,3,2 10 | PRODUCTVERSION 1,0,3,2 11 | FILEFLAGSMASK 0x3fL 12 | #ifdef _DEBUG 13 | FILEFLAGS 0x1L 14 | #else 15 | FILEFLAGS 0x0L 16 | #endif 17 | FILEOS 0x40004L 18 | FILETYPE 0x2L 19 | FILESUBTYPE 0x0L 20 | BEGIN 21 | BLOCK "StringFileInfo" 22 | BEGIN 23 | BLOCK "040904b0" 24 | BEGIN 25 | VALUE "CompanyName", "Google, Inc." 26 | VALUE "FileDescription", "libwebpmux DLL" 27 | VALUE "FileVersion", "1.3.2" 28 | VALUE "InternalName", "libwebpmux.dll" 29 | VALUE "LegalCopyright", "Copyright (C) 2023" 30 | VALUE "OriginalFilename", "libwebpmux.dll" 31 | VALUE "ProductName", "WebP Image Muxer" 32 | VALUE "ProductVersion", "1.3.2" 33 | END 34 | END 35 | BLOCK "VarFileInfo" 36 | BEGIN 37 | VALUE "Translation", 0x409, 1200 38 | END 39 | END 40 | 41 | #endif // English (United States) resources 42 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS += -I$(top_builddir) -I$(top_srcdir) 2 | noinst_LTLIBRARIES = libwebputils.la 3 | 4 | if BUILD_LIBWEBPDECODER 5 | noinst_LTLIBRARIES += libwebputilsdecode.la 6 | endif 7 | 8 | common_HEADERS = ../webp/types.h 9 | commondir = $(includedir)/webp 10 | 11 | noinst_HEADERS = 12 | noinst_HEADERS += ../dsp/cpu.h 13 | noinst_HEADERS += ../dsp/dsp.h 14 | noinst_HEADERS += ../webp/decode.h 15 | noinst_HEADERS += ../webp/encode.h 16 | noinst_HEADERS += ../webp/format_constants.h 17 | 18 | COMMON_SOURCES = 19 | COMMON_SOURCES += bit_reader_utils.c 20 | COMMON_SOURCES += bit_reader_utils.h 21 | COMMON_SOURCES += bit_reader_inl_utils.h 22 | COMMON_SOURCES += color_cache_utils.c 23 | COMMON_SOURCES += color_cache_utils.h 24 | COMMON_SOURCES += endian_inl_utils.h 25 | COMMON_SOURCES += filters_utils.c 26 | COMMON_SOURCES += filters_utils.h 27 | COMMON_SOURCES += huffman_utils.c 28 | COMMON_SOURCES += huffman_utils.h 29 | COMMON_SOURCES += quant_levels_dec_utils.c 30 | COMMON_SOURCES += quant_levels_dec_utils.h 31 | COMMON_SOURCES += rescaler_utils.c 32 | COMMON_SOURCES += rescaler_utils.h 33 | COMMON_SOURCES += random_utils.c 34 | COMMON_SOURCES += random_utils.h 35 | COMMON_SOURCES += thread_utils.c 36 | COMMON_SOURCES += thread_utils.h 37 | COMMON_SOURCES += utils.c 38 | COMMON_SOURCES += utils.h 39 | 40 | ENC_SOURCES = 41 | ENC_SOURCES += bit_writer_utils.c 42 | ENC_SOURCES += bit_writer_utils.h 43 | ENC_SOURCES += huffman_encode_utils.c 44 | ENC_SOURCES += huffman_encode_utils.h 45 | ENC_SOURCES += quant_levels_utils.c 46 | ENC_SOURCES += quant_levels_utils.h 47 | 48 | libwebputils_la_SOURCES = $(COMMON_SOURCES) $(ENC_SOURCES) 49 | 50 | if BUILD_LIBWEBPDECODER 51 | libwebputilsdecode_la_SOURCES = $(COMMON_SOURCES) 52 | endif 53 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/color_cache_utils.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 "src/utils/color_cache_utils.h" 18 | #include "src/utils/utils.h" 19 | 20 | //------------------------------------------------------------------------------ 21 | // VP8LColorCache. 22 | 23 | int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits) { 24 | const int hash_size = 1 << hash_bits; 25 | assert(color_cache != NULL); 26 | assert(hash_bits > 0); 27 | color_cache->colors_ = (uint32_t*)WebPSafeCalloc( 28 | (uint64_t)hash_size, sizeof(*color_cache->colors_)); 29 | if (color_cache->colors_ == NULL) return 0; 30 | color_cache->hash_shift_ = 32 - hash_bits; 31 | color_cache->hash_bits_ = hash_bits; 32 | return 1; 33 | } 34 | 35 | void VP8LColorCacheClear(VP8LColorCache* const color_cache) { 36 | if (color_cache != NULL) { 37 | WebPSafeFree(color_cache->colors_); 38 | color_cache->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_decoder/src/main/jni/libwebp/src/utils/color_cache_utils.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_UTILS_H_ 16 | #define WEBP_UTILS_COLOR_CACHE_UTILS_H_ 17 | 18 | #include 19 | 20 | #include "src/dsp/dsp.h" 21 | #include "src/webp/types.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | // Main color cache struct. 28 | typedef struct { 29 | uint32_t* colors_; // color entries 30 | int hash_shift_; // Hash shift: 32 - hash_bits_. 31 | int hash_bits_; 32 | } VP8LColorCache; 33 | 34 | static const uint32_t kHashMul = 0x1e35a7bdu; 35 | 36 | static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW WEBP_INLINE 37 | int VP8LHashPix(uint32_t argb, int shift) { 38 | return (int)((argb * kHashMul) >> shift); 39 | } 40 | 41 | static WEBP_INLINE uint32_t VP8LColorCacheLookup( 42 | const VP8LColorCache* const cc, uint32_t key) { 43 | assert((key >> cc->hash_bits_) == 0u); 44 | return cc->colors_[key]; 45 | } 46 | 47 | static WEBP_INLINE void VP8LColorCacheSet(const VP8LColorCache* const cc, 48 | uint32_t key, uint32_t argb) { 49 | assert((key >> cc->hash_bits_) == 0u); 50 | cc->colors_[key] = argb; 51 | } 52 | 53 | static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc, 54 | uint32_t argb) { 55 | const int key = VP8LHashPix(argb, cc->hash_shift_); 56 | cc->colors_[key] = argb; 57 | } 58 | 59 | static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc, 60 | uint32_t argb) { 61 | return VP8LHashPix(argb, cc->hash_shift_); 62 | } 63 | 64 | // Return the key if cc contains argb, and -1 otherwise. 65 | static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc, 66 | uint32_t argb) { 67 | const int key = VP8LHashPix(argb, cc->hash_shift_); 68 | return (cc->colors_[key] == argb) ? key : -1; 69 | } 70 | 71 | //------------------------------------------------------------------------------ 72 | 73 | // Initializes the color cache with 'hash_bits' bits for the keys. 74 | // Returns false in case of memory error. 75 | int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits); 76 | 77 | void VP8LColorCacheCopy(const VP8LColorCache* const src, 78 | VP8LColorCache* const dst); 79 | 80 | // Delete the memory associated to color cache. 81 | void VP8LColorCacheClear(VP8LColorCache* const color_cache); 82 | 83 | //------------------------------------------------------------------------------ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif // WEBP_UTILS_COLOR_CACHE_UTILS_H_ 90 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/endian_inl_utils.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_UTILS_H_ 13 | #define WEBP_UTILS_ENDIAN_INL_UTILS_H_ 14 | 15 | #ifdef HAVE_CONFIG_H 16 | #include "src/webp/config.h" 17 | #endif 18 | 19 | #include "src/dsp/dsp.h" 20 | #include "src/webp/types.h" 21 | 22 | #if defined(WORDS_BIGENDIAN) 23 | #define HToLE32 BSwap32 24 | #define HToLE16 BSwap16 25 | #else 26 | #define HToLE32(x) (x) 27 | #define HToLE16(x) (x) 28 | #endif 29 | 30 | #if !defined(HAVE_CONFIG_H) 31 | #if LOCAL_GCC_PREREQ(4,8) || __has_builtin(__builtin_bswap16) 32 | #define HAVE_BUILTIN_BSWAP16 33 | #endif 34 | #if LOCAL_GCC_PREREQ(4,3) || __has_builtin(__builtin_bswap32) 35 | #define HAVE_BUILTIN_BSWAP32 36 | #endif 37 | #if LOCAL_GCC_PREREQ(4,3) || __has_builtin(__builtin_bswap64) 38 | #define HAVE_BUILTIN_BSWAP64 39 | #endif 40 | #endif // !HAVE_CONFIG_H 41 | 42 | static WEBP_INLINE uint16_t BSwap16(uint16_t x) { 43 | #if defined(HAVE_BUILTIN_BSWAP16) 44 | return __builtin_bswap16(x); 45 | #elif defined(_MSC_VER) 46 | return _byteswap_ushort(x); 47 | #else 48 | // gcc will recognize a 'rorw $8, ...' here: 49 | return (x >> 8) | ((x & 0xff) << 8); 50 | #endif // HAVE_BUILTIN_BSWAP16 51 | } 52 | 53 | static WEBP_INLINE uint32_t BSwap32(uint32_t x) { 54 | #if defined(WEBP_USE_MIPS32_R2) 55 | uint32_t ret; 56 | __asm__ volatile ( 57 | "wsbh %[ret], %[x] \n\t" 58 | "rotr %[ret], %[ret], 16 \n\t" 59 | : [ret]"=r"(ret) 60 | : [x]"r"(x) 61 | ); 62 | return ret; 63 | #elif defined(HAVE_BUILTIN_BSWAP32) 64 | return __builtin_bswap32(x); 65 | #elif defined(__i386__) || defined(__x86_64__) 66 | uint32_t swapped_bytes; 67 | __asm__ volatile("bswap %0" : "=r"(swapped_bytes) : "0"(x)); 68 | return swapped_bytes; 69 | #elif defined(_MSC_VER) 70 | return (uint32_t)_byteswap_ulong(x); 71 | #else 72 | return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24); 73 | #endif // HAVE_BUILTIN_BSWAP32 74 | } 75 | 76 | static WEBP_INLINE uint64_t BSwap64(uint64_t x) { 77 | #if defined(HAVE_BUILTIN_BSWAP64) 78 | return __builtin_bswap64(x); 79 | #elif defined(__x86_64__) 80 | uint64_t swapped_bytes; 81 | __asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x)); 82 | return swapped_bytes; 83 | #elif defined(_MSC_VER) 84 | return (uint64_t)_byteswap_uint64(x); 85 | #else // generic code for swapping 64-bit values (suggested by bdb@) 86 | x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32); 87 | x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16); 88 | x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8); 89 | return x; 90 | #endif // HAVE_BUILTIN_BSWAP64 91 | } 92 | 93 | #endif // WEBP_UTILS_ENDIAN_INL_UTILS_H_ 94 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/filters_utils.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 "src/utils/filters_utils.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_decoder/src/main/jni/libwebp/src/utils/filters_utils.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_UTILS_H_ 15 | #define WEBP_UTILS_FILTERS_UTILS_H_ 16 | 17 | #include "src/webp/types.h" 18 | #include "src/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_UTILS_H_ 33 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/huffman_encode_utils.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_UTILS_H_ 15 | #define WEBP_UTILS_HUFFMAN_ENCODE_UTILS_H_ 16 | 17 | #include "src/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 huff_code); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif // WEBP_UTILS_HUFFMAN_ENCODE_UTILS_H_ 61 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/quant_levels_dec_utils.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_UTILS_H_ 15 | #define WEBP_UTILS_QUANT_LEVELS_DEC_UTILS_H_ 16 | 17 | #include "src/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. 'stride' is in bytes. 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, int stride, 29 | int strength); 30 | 31 | #ifdef __cplusplus 32 | } // extern "C" 33 | #endif 34 | 35 | #endif // WEBP_UTILS_QUANT_LEVELS_DEC_UTILS_H_ 36 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/quant_levels_utils.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_UTILS_H_ 15 | #define WEBP_UTILS_QUANT_LEVELS_UTILS_H_ 16 | 17 | #include 18 | 19 | #include "src/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_UTILS_H_ 37 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/random_utils.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 "src/utils/random_utils.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_decoder/src/main/jni/libwebp/src/utils/random_utils.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_UTILS_H_ 15 | #define WEBP_UTILS_RANDOM_UTILS_H_ 16 | 17 | #include 18 | #include "src/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_UTILS_H_ 64 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/src/utils/thread_utils.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_UTILS_H_ 15 | #define WEBP_UTILS_THREAD_UTILS_H_ 16 | 17 | #ifdef HAVE_CONFIG_H 18 | #include "src/webp/config.h" 19 | #endif 20 | 21 | #include "src/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 | // Synchronization object used to launch job in the worker thread 39 | typedef struct { 40 | void* impl_; // platform-dependent implementation worker details 41 | WebPWorkerStatus status_; 42 | WebPWorkerHook hook; // hook to call 43 | void* data1; // first argument passed to 'hook' 44 | void* data2; // second argument passed to 'hook' 45 | int had_error; // return value of the last call to 'hook' 46 | } WebPWorker; 47 | 48 | // The interface for all thread-worker related functions. All these functions 49 | // must be implemented. 50 | typedef struct { 51 | // Must be called first, before any other method. 52 | void (*Init)(WebPWorker* const worker); 53 | // Must be called to initialize the object and spawn the thread. Re-entrant. 54 | // Will potentially launch the thread. Returns false in case of error. 55 | int (*Reset)(WebPWorker* const worker); 56 | // Makes sure the previous work is finished. Returns true if worker->had_error 57 | // was not set and no error condition was triggered by the working thread. 58 | int (*Sync)(WebPWorker* const worker); 59 | // Triggers the thread to call hook() with data1 and data2 arguments. These 60 | // hook/data1/data2 values can be changed at any time before calling this 61 | // function, but not be changed afterward until the next call to Sync(). 62 | void (*Launch)(WebPWorker* const worker); 63 | // This function is similar to Launch() except that it calls the 64 | // hook directly instead of using a thread. Convenient to bypass the thread 65 | // mechanism while still using the WebPWorker structs. Sync() must 66 | // still be called afterward (for error reporting). 67 | void (*Execute)(WebPWorker* const worker); 68 | // Kill the thread and terminate the object. To use the object again, one 69 | // must call Reset() again. 70 | void (*End)(WebPWorker* const worker); 71 | } WebPWorkerInterface; 72 | 73 | // Install a new set of threading functions, overriding the defaults. This 74 | // should be done before any workers are started, i.e., before any encoding or 75 | // decoding takes place. The contents of the interface struct are copied, it 76 | // is safe to free the corresponding memory after this call. This function is 77 | // not thread-safe. Return false in case of invalid pointer or methods. 78 | WEBP_EXTERN int WebPSetWorkerInterface( 79 | const WebPWorkerInterface* const winterface); 80 | 81 | // Retrieve the currently set thread worker interface. 82 | WEBP_EXTERN const WebPWorkerInterface* WebPGetWorkerInterface(void); 83 | 84 | //------------------------------------------------------------------------------ 85 | 86 | #ifdef __cplusplus 87 | } // extern "C" 88 | #endif 89 | 90 | #endif // WEBP_UTILS_THREAD_UTILS_H_ 91 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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_TRANSFORM = 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 VP8X_CHUNK_SIZE 10 // Size of a VP8X chunk. 76 | 77 | #define MAX_CANVAS_SIZE (1 << 24) // 24-bit max for VP8X width/height. 78 | #define MAX_IMAGE_AREA (1ULL << 32) // 32-bit max for width x height. 79 | #define MAX_LOOP_COUNT (1 << 16) // maximum value for loop-count 80 | #define MAX_DURATION (1 << 24) // maximum duration 81 | #define MAX_POSITION_OFFSET (1 << 24) // maximum frame x/y offset 82 | 83 | // Maximum chunk payload is such that adding the header and padding won't 84 | // overflow a uint32_t. 85 | #define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1) 86 | 87 | #endif // WEBP_WEBP_FORMAT_CONSTANTS_H_ 88 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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 // memset() 18 | #include "./types.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | // Note: forward declaring enumerations is not allowed in (strict) C and C++, 25 | // the types are left here for reference. 26 | // typedef enum WebPFeatureFlags WebPFeatureFlags; 27 | // typedef enum WebPMuxAnimDispose WebPMuxAnimDispose; 28 | // typedef enum WebPMuxAnimBlend WebPMuxAnimBlend; 29 | typedef struct WebPData WebPData; 30 | 31 | // VP8X Feature Flags. 32 | typedef enum WebPFeatureFlags { 33 | ANIMATION_FLAG = 0x00000002, 34 | XMP_FLAG = 0x00000004, 35 | EXIF_FLAG = 0x00000008, 36 | ALPHA_FLAG = 0x00000010, 37 | ICCP_FLAG = 0x00000020, 38 | 39 | ALL_VALID_FLAGS = 0x0000003e 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 | // 'bytes' memory must be allocated using WebPMalloc() and such. 59 | struct WebPData { 60 | const uint8_t* bytes; 61 | size_t size; 62 | }; 63 | 64 | // Initializes the contents of the 'webp_data' object with default values. 65 | static WEBP_INLINE void WebPDataInit(WebPData* webp_data) { 66 | if (webp_data != NULL) { 67 | memset(webp_data, 0, sizeof(*webp_data)); 68 | } 69 | } 70 | 71 | // Clears the contents of the 'webp_data' object by calling WebPFree(). 72 | // Does not deallocate the object itself. 73 | static WEBP_INLINE void WebPDataClear(WebPData* webp_data) { 74 | if (webp_data != NULL) { 75 | WebPFree((void*)webp_data->bytes); 76 | WebPDataInit(webp_data); 77 | } 78 | } 79 | 80 | // Allocates necessary storage for 'dst' and copies the contents of 'src'. 81 | // Returns true on success. 82 | static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) { 83 | if (src == NULL || dst == NULL) return 0; 84 | WebPDataInit(dst); 85 | if (src->bytes != NULL && src->size != 0) { 86 | dst->bytes = (uint8_t*)WebPMalloc(src->size); 87 | if (dst->bytes == NULL) return 0; 88 | memcpy((void*)dst->bytes, src->bytes, src->size); 89 | dst->size = src->size; 90 | } 91 | return 1; 92 | } 93 | 94 | #ifdef __cplusplus 95 | } // extern "C" 96 | #endif 97 | 98 | #endif // WEBP_WEBP_MUX_TYPES_H_ 99 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/libwebp/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 + memory wrappers 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 extern __attribute__ ((visibility ("default"))) 44 | # else 45 | # if defined(_MSC_VER) && defined(WEBP_DLL) 46 | # define WEBP_EXTERN __declspec(dllexport) 47 | # else 48 | # define WEBP_EXTERN extern 49 | # endif 50 | # endif /* __GNUC__ >= 4 */ 51 | #endif /* WEBP_EXTERN */ 52 | 53 | // Macro to check ABI compatibility (same major revision number) 54 | #define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8)) 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | // Allocates 'size' bytes of memory. Returns NULL upon error. Memory 61 | // must be deallocated by calling WebPFree(). This function is made available 62 | // by the core 'libwebp' library. 63 | WEBP_EXTERN void* WebPMalloc(size_t size); 64 | 65 | // Releases memory returned by the WebPDecode*() functions (from decode.h). 66 | WEBP_EXTERN void WebPFree(void* ptr); 67 | 68 | #ifdef __cplusplus 69 | } // extern "C" 70 | #endif 71 | 72 | #endif // WEBP_WEBP_TYPES_H_ 73 | -------------------------------------------------------------------------------- /webp_decoder/src/main/jni/webp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by liuchun on 2017/10/16. 3 | // 4 | 5 | #ifndef GLIDE_PARENT_WEBP_H 6 | #define GLIDE_PARENT_WEBP_H 7 | 8 | int initWebPImage(JNIEnv* pEnv); 9 | 10 | int initWebpBitmapFactory(JNIEnv* env); 11 | 12 | #endif //GLIDE_PARENT_WEBP_H 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /webp_decoder/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | webp_decoder 3 | 4 | -------------------------------------------------------------------------------- /webpsample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | dependencies { 4 | 5 | implementation("com.github.bumptech.glide:glide:${GLIDE_VERSION}"){ 6 | exclude group:"com.android.support" 7 | } 8 | annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE_VERSION}" 9 | // okhttp network 10 | implementation "com.github.bumptech.glide:okhttp3-integration:${GLIDE_VERSION}" 11 | 12 | implementation project(':webp_decoder') 13 | //implementation "com.github.zjupure:webpdecoder:${DECODER_VERSION}.${GLIDE_VERSION}" 14 | 15 | //implementation project(':framesequence') 16 | 17 | implementation "androidx.fragment:fragment:${ANDROIDX_VERSION}" 18 | implementation "androidx.vectordrawable:vectordrawable-animated:${ANDROIDX_VERSION}" 19 | implementation "androidx.recyclerview:recyclerview:${ANDROIDX_VERSION}" 20 | 21 | implementation "com.facebook.fresco:fresco:${FRESCO_VERSION}" 22 | // Support animated GIF. It is needed. 23 | implementation "com.facebook.fresco:animated-gif:${FRESCO_VERSION}" 24 | // Support WebP (both static + animated images). It is also needed. 25 | implementation "com.facebook.fresco:animated-webp:${FRESCO_VERSION}" 26 | implementation "com.facebook.fresco:webpsupport:${FRESCO_VERSION}" 27 | } 28 | 29 | android { 30 | compileSdkVersion COMPILE_SDK_VERSION as int 31 | buildToolsVersion BUILD_TOOLS_VERSION as String 32 | 33 | defaultConfig { 34 | applicationId 'com.bumptech.glide.samples.webp' 35 | minSdkVersion MIN_SDK_VERSION as int 36 | targetSdkVersion TARGET_SDK_VERSION as int 37 | 38 | versionCode 1 39 | versionName '1.0' 40 | } 41 | 42 | compileOptions { 43 | sourceCompatibility JavaVersion.VERSION_1_7 44 | targetCompatibility JavaVersion.VERSION_1_7 45 | } 46 | } 47 | 48 | task run(type: Exec, dependsOn: 'installDebug') { 49 | description 'Installs the APK and runs the main activity: "gradlew :samples:???:run"' 50 | commandLine "${android.sdkDirectory}/platform-tools/adb", 'shell', 'am', 'start', '-n', 'com.bumptech.glide.samples.webp/.MainActivity' 51 | } 52 | -------------------------------------------------------------------------------- /webpsample/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /webpsample/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/judds/dev/adt-bundle-mac-x86_64-20131030/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 | -------------------------------------------------------------------------------- /webpsample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /webpsample/src/main/java/com/bumptech/glide/samples/webp/AspectRatioImageView.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.samples.webp; 2 | 3 | import android.content.Context; 4 | import android.os.Build; 5 | import android.util.AttributeSet; 6 | import android.widget.ImageView; 7 | 8 | import androidx.annotation.Nullable; 9 | import androidx.annotation.RequiresApi; 10 | 11 | public class AspectRatioImageView extends ImageView { 12 | 13 | private float mAspectRatio = 1.0f; 14 | 15 | public AspectRatioImageView(Context context) { 16 | super(context); 17 | } 18 | 19 | public AspectRatioImageView(Context context, @Nullable AttributeSet attrs) { 20 | super(context, attrs); 21 | } 22 | 23 | public AspectRatioImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 24 | super(context, attrs, defStyleAttr); 25 | } 26 | 27 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 28 | public AspectRatioImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 29 | super(context, attrs, defStyleAttr, defStyleRes); 30 | } 31 | 32 | public float getAspectRatio() { 33 | return mAspectRatio; 34 | } 35 | 36 | public void setAspectRatio(float aspectRatio) { 37 | this.mAspectRatio = aspectRatio; 38 | requestLayout(); 39 | } 40 | 41 | @Override 42 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 43 | int width = MeasureSpec.getSize(widthMeasureSpec); 44 | int height = (int) (width / mAspectRatio); 45 | super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 46 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /webpsample/src/main/java/com/bumptech/glide/samples/webp/WebpApplication.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.samples.webp; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.drawee.backends.pipeline.Fresco; 6 | 7 | /** 8 | * author: liuchun 9 | * date: 2019-08-20 10 | */ 11 | public class WebpApplication extends Application { 12 | 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | Fresco.initialize(this); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /webpsample/src/main/java/com/bumptech/glide/samples/webp/WebpModule.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.samples.webp; 2 | 3 | import android.content.Context; 4 | 5 | import com.bumptech.glide.Glide; 6 | import com.bumptech.glide.Registry; 7 | import com.bumptech.glide.annotation.GlideModule; 8 | import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader; 9 | import com.bumptech.glide.load.model.GlideUrl; 10 | import com.bumptech.glide.module.AppGlideModule; 11 | 12 | import java.io.InputStream; 13 | 14 | import okhttp3.OkHttpClient; 15 | 16 | /** 17 | * Created by liuchun on 2017/10/17. 18 | */ 19 | @GlideModule 20 | public class WebpModule extends AppGlideModule { 21 | 22 | @Override 23 | public void registerComponents(Context context, Glide glide, Registry registry) { 24 | //OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); 25 | //registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient)); 26 | } 27 | 28 | @Override 29 | public boolean isManifestParsingEnabled() { 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /webpsample/src/main/java/com/bumptech/glide/samples/webp/WebpTextView.java: -------------------------------------------------------------------------------- 1 | package com.bumptech.glide.samples.webp; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Animatable; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Build; 7 | import android.text.Spanned; 8 | import android.text.style.ImageSpan; 9 | import android.util.AttributeSet; 10 | import android.widget.TextView; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.annotation.Nullable; 14 | import androidx.annotation.RequiresApi; 15 | 16 | import java.lang.ref.WeakReference; 17 | import java.util.HashMap; 18 | 19 | /** 20 | * A TextView support displaying WebpDrawable in ImageSpan 21 | */ 22 | public class WebpTextView extends TextView { 23 | // save ImageSpan Drawable with callbacks 24 | private HashMap> mCallBacks; 25 | 26 | public WebpTextView(Context context) { 27 | super(context); 28 | } 29 | 30 | public WebpTextView(Context context, @Nullable AttributeSet attrs) { 31 | super(context, attrs); 32 | } 33 | 34 | public WebpTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 35 | super(context, attrs, defStyleAttr); 36 | } 37 | 38 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 39 | public WebpTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 40 | super(context, attrs, defStyleAttr, defStyleRes); 41 | } 42 | 43 | @Override 44 | public void setText(CharSequence text, BufferType type) { 45 | super.setText(text, type); 46 | 47 | CharSequence nText = getText(); 48 | if (nText instanceof Spanned) { 49 | if (mCallBacks == null) { 50 | mCallBacks = new HashMap<>(); 51 | } else { 52 | mCallBacks.clear(); 53 | } 54 | 55 | final ImageSpan[] spans = ((Spanned) nText).getSpans(0, nText.length(), ImageSpan.class); 56 | for (ImageSpan span : spans) { 57 | Drawable drawable = span.getDrawable(); 58 | if (drawable == null) { 59 | continue; 60 | } 61 | 62 | if (drawable instanceof Animatable) { 63 | ((Animatable) drawable).start(); 64 | } 65 | 66 | Drawable.Callback callback = drawable.getCallback(); 67 | mCallBacks.put(drawable, new WeakReference(callback)); 68 | drawable.setCallback(this); 69 | } 70 | } 71 | } 72 | 73 | private Drawable.Callback getCallBack(@NonNull Drawable drawable) { 74 | WeakReference callback = mCallBacks.get(drawable); 75 | return callback != null ? callback.get() : null; 76 | } 77 | 78 | @Override 79 | public void invalidateDrawable(@NonNull Drawable drawable) { 80 | 81 | if (mCallBacks.containsKey(drawable)) { 82 | postInvalidate(); 83 | } else { 84 | super.invalidateDrawable(drawable); 85 | } 86 | 87 | Drawable.Callback callback = getCallBack(drawable); 88 | if (callback != null) { 89 | callback.invalidateDrawable(drawable); 90 | } 91 | } 92 | 93 | @Override 94 | public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) { 95 | super.scheduleDrawable(who, what, when); 96 | 97 | Drawable.Callback callback = getCallBack(who); 98 | if (callback != null) { 99 | callback.scheduleDrawable(who, what, when); 100 | } 101 | } 102 | 103 | @Override 104 | public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) { 105 | super.unscheduleDrawable(who, what); 106 | 107 | Drawable.Callback callback = getCallBack(who); 108 | if (callback != null) { 109 | callback.unscheduleDrawable(who, what); 110 | } 111 | } 112 | 113 | @Override 114 | protected boolean verifyDrawable(@NonNull Drawable who) { 115 | return super.verifyDrawable(who) || mCallBacks.containsKey(who); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /webpsample/src/main/res/drawable-xhdpi/broken.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/drawable-xhdpi/broken.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/drawable-xhdpi/head.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/drawable-xhdpi/head.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/drawable-xhdpi/small_frame.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/drawable-xhdpi/small_frame.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/drawable-xhdpi/test.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/drawable-xhdpi/test.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/drawable/dot_dot_dot.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 11 | 12 | 13 | 14 | 17 | 18 | 21 | 22 | 23 | 24 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /webpsample/src/main/res/drawable/image_error.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /webpsample/src/main/res/drawable/image_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /webpsample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 14 | 15 | 21 | 22 | 29 | 30 | 35 | 36 | 37 | 41 | 42 | 48 | 49 | -------------------------------------------------------------------------------- /webpsample/src/main/res/layout/webp_image_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 25 | -------------------------------------------------------------------------------- /webpsample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 11 | 12 | 16 | 17 | 22 | 23 | 27 | 28 | 31 | 32 | -------------------------------------------------------------------------------- /webpsample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /webpsample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /webpsample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /webpsample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /webpsample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /webpsample/src/main/res/raw/circle_alpha_webp_ll.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/raw/circle_alpha_webp_ll.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/raw/static_poster.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/raw/static_poster.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/raw/wandoujia_webp_a.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/raw/wandoujia_webp_a.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/raw/yellow_rose_webp_a.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/raw/yellow_rose_webp_a.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/raw/yellow_rose_webp_ll.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zjupure/GlideWebpDecoder/56d3f2523d546bd069600b8ee2435a0e0e2c3c07/webpsample/src/main/res/raw/yellow_rose_webp_ll.webp -------------------------------------------------------------------------------- /webpsample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /webpsample/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | No Transformation 5 | CenterCrop 6 | CircleCrop 7 | RoundedCorners 8 | CenterInside 9 | FitCenter 10 | 11 | -------------------------------------------------------------------------------- /webpsample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /webpsample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | WebpSample 4 | An Android robot playing with a blue linen should appear below after a \"dot dot dot\" loading image on both the left and the right side. The left is loaded from a raw resource and the right is from the internet. Click here to clear all caches. 5 | Click to cycle scale type (current: %1$s) 6 | An android playing with blue linen 7 | 8 | --------------------------------------------------------------------------------