An implementation of a gif decoder written 100% in Kotlin, plus an associated Drawable for Android

Overview

Gif Decoder

An implementation of a gif decoder written 100% in kotlin

This project contains several parts.

decoder

Maven Central

A simple jvm library written 100% in kotlin that handles the parsing of the gif format, headers, lzw decoder and so on.

decoder is available on mavenCentral()

implementation "app.redwarp.gif:decoder:x.y.z"

See decoder.

android-drawable

Maven Central

An implementation of an Android Drawable, using the decoder, as a simple way to display a gif in an Android app.

android-drawable is available on mavenCentral()

implementation "app.redwarp.gif:android-drawable:x.y.z"

See android-drawable.

License

The decoder and android-drawable library are both under an Apache 2.0 License.

You might notice a few classes in the project copyrighted to Google: they are the OG decoder copied from the bumptech/glide library, and are included in the project to do benchmarking and compare performance between the java implementation and the kotlin one.

They are not actually included in the two deliverables, decoder and android-drawable.

The bitmap.h in the giflzwdecoder folder is copyrighted to the Android Open Source Project, but is also not included in the deliverables: it's part of a currently failed attempt at making a native implementation of the decoder.

Android ndk + rust is not trivial, and that attempt is currently on hold.

Even though my first attempt at it kind of worked, it was naive and did come with a set of issues so I dropped it. I might get back to it in the future.

Comments
  • Advancing multiple frames results in artifacts

    Advancing multiple frames results in artifacts

    When advancing multiple frames without calling getCurrentFrame(), the pixels contain artifacts. I have changed the sample app to call advance() twice before getting the frame, I got this: gifdecoder_artifacts_1 gifdecoder_artifacts_2

    The use case for this would be integrating Gif into a rendering engine where advancing frames is calculated on each frame update. If the frame rate of the engine is slower than the gif's, then advance() needs to be called multiple times in a frame resulting in this issue. Temporary workaround would be to explicitly call getCurrentFrame() after each advance() call, but I'm sure we can improve this :)

    I am not sure if calling getCurrentFrame() internally when advance() is called would be the best solution, but it would fix the problem. I am not into the details of decoding, but it sounds like we need to decode frame by frame?

    opened by PauGuillamon 12
  • Disposal not correct sometimes?

    Disposal not correct sometimes?

    HI there, found another little bug :)

    I was testing with lots of different gifs and downloaded some from Giphy, I found some stickers are not rendered correctly. For example this one (and others): https://media0.giphy.com/media/kayGhRlOKbJHCqnj9m/giphy.gif ends up in including the first frame when rendering the second:

    image

    I debugged a bit, this gif has 2 frames with different disposal method, the first frame being RESTORE_TO_BACKGROUND and the second DO_NOT_DISPOSE. Not sure whether that's common or not, but other tools render it correctly.

    I have created a branch on my fork so you can quickly test it https://github.com/PauGuillamon/gifdecoder/commits/PGJ/car_gunna_incorrect_disposal I'm not sure what would be the best fix here, since I don't know the specs of GIF.

    Let me know if I can help in any way. Thank you!

    opened by PauGuillamon 6
  • Adds function to create a Gif from another Gif

    Adds function to create a Gif from another Gif

    Adding a function to be able to clone a Gif. As I'm using Gif directly instead of GifDrawable, I was missing the possibility of being able to clone Gifs. With this I don't need to keep opening a file and creating new Gifs with a manually handled InputStream.

    I was not sure if sharing the same InputStream between Gifs was safe or not, but I saw GifDrawable basically doing the same through GifDrawableState(). So I hope I didn't miss anything šŸ˜„

    I tried keeping the same convention with a Git.from() function, but I am happy to change it in another way if you prefer.

    opened by PauGuillamon 5
  • License

    License

    Hi,

    As I'm trying to use this library in a commercial project, can you please clarify a few things regarding licenses?

    Are these benchmark files actually included in the library?

    benchmark/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.kt: * Copyright 2014 Google, Inc. All rights reserved.
    benchmark/src/main/java/com/bumptech/glide/gifdecoder/GifFrame.kt: * Copyright 2014 Google, Inc. All rights reserved.
    benchmark/src/main/java/com/bumptech/glide/gifdecoder/GifHeader.kt: * Copyright 2014 Google, Inc. All rights reserved.
    benchmark/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.kt: * Copyright 2014 Google, Inc. All rights reserved.
    benchmark/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java: * Copyright (c) 2013 Xcellent Creations, Inc.
    benchmark/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java: * Copyright 2014 Google, Inc. All rights reserved.
    

    Is this bitmap.h file from AOSP actually used in the library?

    giflzwdecoder/ndkheaders/bitmap.h: * Copyright (C) 2009 The Android Open Source Project
    

    Any other thing I should take into account regarding the license?

    Could also be helpful to clarify this in the README.md file ;)

    Thank you so much!

    opened by PauGuillamon 3
  • Do not depend on `cargoBuild`

    Do not depend on `cargoBuild`

    Given android-drawable-native being currently broken, calling gradle assemble on the project fails as the cargoBuild task is missing. I'm removing this dependency.

    opened by cortinico 3
  • Add license scan report and status

    Add license scan report and status

    Your FOSSA integration was successful! Attached in this PR is a badge and license report to track scan status in your README.

    Below are docs for integrating FOSSA license checks into your CI:

    opened by fossabot 1
  • Remove explicit dependency on Kotlin stdlib

    Remove explicit dependency on Kotlin stdlib

    Explicit dependencies on kotlin-stdlib artifact are unnecessary (unless you want to specifically target a variant of the standard library).

    The dependency is added automatically as you add the kotlin("jvm") plugin. Ref: https://kotlinlang.org/docs/gradle.html#dependency-on-the-standard-library

    opened by cortinico 1
  • IndexOutOfBoundsException in the decoder

    IndexOutOfBoundsException in the decoder

    The decoder sometimes throws exception on multipl IndexOutOfBoundsExceptions:

    java.lang.ArrayIndexOutOfBoundsException: 
      at net.redwarp.gif.decoder.lzw.LzwDecoder.decode (LzwDecoder.java:100)
      at net.redwarp.gif.decoder.Gif.getFrame (Gif.java:98)
      at net.redwarp.gif.decoder.Gif.getCurrentFrame (Gif.java:24)
    
    java.lang.IndexOutOfBoundsException: 
      at java.util.ArrayList.get (ArrayList.java:437)
      at net.redwarp.gif.decoder.Gif.getFrame (Gif.java:17)
      at net.redwarp.gif.decoder.Gif.getCurrentFrame (Gif.java:24)
    
    java.lang.ArrayIndexOutOfBoundsException: 
      at net.redwarp.gif.decoder.Gif.fillPixelsInterlaced (Gif.java:79)
      at net.redwarp.gif.decoder.Gif.fillPixels (Gif.java:6)
      at net.redwarp.gif.decoder.Gif.getFrame (Gif.java:114)
      at net.redwarp.gif.decoder.Gif.getCurrentFrame (Gif.java:24)
    
    java.lang.ArrayIndexOutOfBoundsException: 
      at net.redwarp.gif.decoder.Gif.fillPixelsSimple (Gif.java:75)
      at net.redwarp.gif.decoder.Gif.fillPixels (Gif.java:10)
      at net.redwarp.gif.decoder.Gif.getFrame (Gif.java:114)
      at net.redwarp.gif.decoder.Gif.getCurrentFrame (Gif.java:24)
    
    bug 
    opened by redwarp 1
  • Replace Result with kotlin.Result

    Replace Result with kotlin.Result

    Replace self made Result class with the official kotlin.Result, now out of unstable. Also consolidate the API to use Result everywhere, instead of relying on returning null in case of error.

    opened by redwarp 0
  • Advance will now  calculate the current frame

    Advance will now calculate the current frame

    Implements #15 : The calculation of the frame will now occur when calling the advance() method, and getCurrentFrame will simply copy the pixel buffer. getFrame(index) will now internally call advance to make sure that each frame is processed in sequence.

    So, the new flow would be: getFrame (once, twice, as many as wanted), then advance, then getframe, then advance.

    opened by redwarp 0
  • Random access file: handle file deleted case

    Random access file: handle file deleted case

    With 0.4.0 comes reading the gif from a random access file. Cool. But what happens if the file gets deleted? It crashes.

    It might be cool to create or reuse an exception for:

    • failing to parse a file that doesn't exists
    • a file that got properly parsed gets deleted before we ask to get a frame.
    opened by redwarp 0
Releases(v1.4.4)
Owner
BenoƮt Vermont
BenoƮt Vermont
Use a jar executable to create a Drawable class to display a SVG on Android.

SVG2Drawable Use a jar executable to create a Drawable class to display a SVG on Android. This is a standalone library, not a Runtime Android library.

Stan Kocken 202 Nov 28, 2022
Transforms a Vector Drawable or a SVG path to a Compose ImageVector

Svg2Compose Transforms a Vector Drawable or a SVG path to a Compose ImageVector. Download Download the latest version (Windows) here: Releases. How to

Denis Mondon 18 Dec 22, 2022
A simple implementation of rectangle detector on Android using OpenCV.

A simple implementation of rectangle detector on Android using OpenCV.

SmartBank, Inc. 4 Oct 7, 2022
An open-source implementation of the Pixel Active Edge gesture

Active Edge Service This is an open-source implementation of the Pixel Active Edge gesture, written from scratch for portability and customizability.

hlcynprjct! 0 Nov 20, 2021
Software blur implementation for Blur, blur, and one more time blur article

Software Blur Software blur implementation for Blur, blur, and one more time blu

Algo Club 0 Jan 20, 2022
Image cropping library written with Jetpack Compose with other Composables such as ImageWithConstraints scales Bitmap

Image cropping library written with Jetpack Compose with other Composables such as ImageWithConstraints scales Bitmap it displays and returns position and bounds of Bitmap and ImageWithThumbnail to display thumbnail of the image on selected corner.

Smart Tool Factory 9 Jul 27, 2022
Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.

Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.

Nosakhare Belvi 115 Dec 20, 2022
Generate Mermaid graphs from docker-compose files (in kotlin).

docker-compose-viz with Mermaid Generate Mermaid graphs from docker-compose files (in kotlin). Inspired from https://github.com/pmsipilot/docker-compo

Lucy Linder 12 Nov 22, 2022
Phimp.me Android Phimp.me is an Android image editor app

Phimp.me Android Phimp.me is an Android image editor app that aims to replace proprietary photographing and image apps on smart phones. It offers feat

FOSSASIA 2.6k Jan 6, 2023
Opencv Android SDK application for Deep Neural Networks to run on Android.

This application allows you to deploy deep nets in Android environment using OpenCV Android SDK. With OpenCV, images are taken from the camera on your phone, and then these images are passed through the neural network and visualized on the front side. In this application, we will search for faces in the images taken and draw the found faces on the screen.

Ahmet Furkan DEMIR 10 Nov 1, 2022
Android filters based on OpenGL (idea from GPUImage for iOS)

GPUImage for Android Idea from: iOS GPUImage framework Goal is to have something as similar to GPUImage as possible. Vertex and fragment shaders are e

CATS Open Source Softwares 8.6k Dec 28, 2022
Android library project for cropping images

I guess people are just cropping out all the sadness An Android library project that provides a simple image cropping Activity, based on code from AOS

Jamie McDonald 4.5k Jan 7, 2023
Custom view for circular images in Android while maintaining the best draw performance

CircularImageView Custom view for circular images in Android while maintaining the best draw performance Usage To make a circular ImageView, add this

Pkmmte Xeleon 1.2k Dec 28, 2022
some android image filters

android-image-filter some android image filters in some filter, I use NDK to implement to make it more efficient Setup Install Android NDK and properl

RagnarokStack 643 Dec 27, 2022
An android image compression library.

Compressor Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller

Zetra 6.7k Dec 31, 2022
Custom shaped android imageview components

Shape Image View Provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitma

Siyamed SINIR 2.6k Jan 3, 2023
Android widget for cropping and rotating an image.

Cropper The Cropper is an image cropping tool. It provides a way to set an image in XML and programmatically, and displays a resizable crop window on

Edmodo 2.9k Nov 14, 2022
A simple image cropping library for Android.

SimpleCropView The SimpleCropView is an image cropping library for Android. It simplifies your code for cropping image and provides an easily customiz

Issei Aoki 2.5k Dec 28, 2022
Customizable Android full screen image viewer for Fresco library supporting "pinch to zoom" and "swipe to dismiss" gestures. Made by Stfalcon

This project is no longer supported. If you're able to switch from Fresco to any other library that works with the Android's ImageView, please migrate

Stfalcon LLC 1.8k Dec 19, 2022