redwarp / gifdecoder

An implementation of a gif decoder written 100% in Kotlin, plus an associated Drawable for Android
Apache License 2.0
47 stars 6 forks source link

Adds function to create a Gif from another Gif #14

Closed PauGuillamon closed 3 years ago

PauGuillamon commented 3 years ago

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.

redwarp commented 3 years ago

Actually, that's a great question. Maybe we should make the shared input stream thread safe? As is, if two GIFs using the same descriptor would read data, I wonder what would happen. I'll take a look tomorrow.

PauGuillamon commented 3 years ago

For my use case I always call my Gif objects on the main thread, so that shouldn´t be a problem for me. I guess in a multi-threaded environment we could have a problem here, but same would apply for GifDrawable, right?

If you like this PR we could merge it and afterwards look into making it thread safe.

redwarp commented 3 years ago

If you want I can release a point release tonight?

PauGuillamon commented 3 years ago

That will be awesome, thank you!

redwarp commented 3 years ago

@PauGuillamon 0.7.3 released! Should be deployed in 10 minutes or so.