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

GifDrawable#getFrame() detect if any pixel is transparency may slow down the decode procedure for those large resolution frame #22

Closed vince-styling closed 1 year ago

vince-styling commented 1 year ago

should we default the ARGB_8888 to wield space for time? especially I give up your BitmapCache, instead used only one bitmap instance through the whole decode procedure, I will explain in another issue

redwarp commented 1 year ago

I think you are right, seems like a useless optimization in this day and age

redwarp commented 1 year ago

Reopening it, I have not yet updated to only use 8888

redwarp commented 1 year ago

I decided to keep the transparency check, but to cache it, so it's only calculated the first time each frame is decoded.

redwarp commented 1 year ago

Actually, changed my mind 😂 , I'll simplify to ARGB_8888, this way I can also use a direct copyPixelsFromBuffer method, slightly more optimized.

vince-styling commented 1 year ago

pay a test about time consuming of copyPixelsFromBuffer and setPixels, on android-11 there is no obvious difference, but setPixels faster over 4 times on android-13(0.515ms vs 2.102ms)

redwarp commented 1 year ago

That seems counter intuitive, I'll have to bench that too 🤔

vince-styling commented 1 year ago

perhaps I was wrong, because I haven't much devices, my test may less accurate, don't bench before you confirm it

redwarp commented 1 year ago

I added a bench to compare both, and copyPixels is always faster. It makes only a really little difference though, as the biggest part of creating a frame is decoding, not copying the result in a bitmap.