Comments (6)
As I known, Glide library won' t cache gif frames result to memory. I think it is a balance of cpu and memory usage. It's hard to decide how many frames of one gif image should be cached. Some gif/webp might contains 100+ frames and many frame bitmaps in gif/webp image are similar with only minor difference. When an app need to display much animated image (gif/webp), caching the frame will cause the bitmap OOM easily. More complicated memory management are required and avoid flush static image caches meanwhile. So the gif/webp frames are always decoded and rendered in a realtime without cache.
You can test more gif/webp images in a screen to get more reliable performance data not just one specifical image.
from glidewebpdecoder.
It was just a guess, that others cache the frames.
I don't know about the library I've mentioned, but I think that ImageDecoder does something special. I can see in the code of AnimatedImageDrawable
:
@Override
public void draw(@NonNull Canvas canvas) {
if (mState.mNativePtr == 0) {
throw new IllegalStateException("called draw on empty AnimatedImageDrawable");
}
if (mStarting) {
mStarting = false;
postOnAnimationStart();
}
long nextUpdate = nDraw(mState.mNativePtr, canvas.getNativeCanvasWrapper());
// a value <= 0 indicates that the drawable is stopped or that renderThread
// will manage the animation
if (nextUpdate > 0) {
if (mRunnable == null) {
mRunnable = this::invalidateSelf;
}
scheduleSelf(mRunnable, nextUpdate + SystemClock.uptimeMillis());
} else if (nextUpdate == FINISHED) {
// This means the animation was drawn in software mode and ended.
postOnAnimationEnd();
}
}
It's written that renderThread
will handle the animation, and indeed, after some frames, it doesn't call the runnable anymore, which means I can't use a similar solution to what I've written here: #22 .
If you know how to overcome this , please let me know. Here's a sample project:
ImageDecoderTest.zip
About caching, I know it can lead to OOM, but if it's dynamic up to some amount of memory to use, just like other images, it shouldn't reach OOM.
BTW, starting from Android O, it's a bit harder to reach OOM, as bitmaps seem to be stored on the normal memory of the device, and not the heap.
The solution of frame-by-frame animation might help with customized caching mechanism outside of the library, but I don't see if it's possible with ImageDecoder API.
from glidewebpdecoder.
AnimatedImageDrawable
render code is in native and I have not investigated it. The memory cache mechaim for frame should be implemented by Glide library. If you have good idea or PR, you can submit feedback to Glide . Once Glide library support it, this library will follow the changes soon.
from glidewebpdecoder.
Since I don't have time to investigate how Glide works behind the scenes (let alone its caching mechanism), I only thought that since the caching doesn't exist in this case, and I have a solution for going frame-by-frame (you helped me a bit, here: #22 ) , I could cache some of the bitmaps by myself, outside of the Glide library. Not sure if it's possible. Just an idea.
Do you know perhaps how does the other library do it (from here: https://github.com/huzongyao/AndLibNsgif ) ? Sadly it's not available for animated WEBP, but on animated GIF it uses a bit less CPU than here (though uses a bit more RAM).
from glidewebpdecoder.
I do not known AndLibNsgif library as you mentioned. Glide library not support frame-by-frame cache and there is no easy way to extend the Glide interface or function.
from glidewebpdecoder.
Too bad. Thank you for your help and kindness !
from glidewebpdecoder.
Related Issues (20)
- 希望公开OnEveryFrameListener接口及其set方法 HOT 1
- 加载webp动图,结果图片缩小了 HOT 1
- 使用协程好像会出现多线程问题 HOT 1
- 首帧预览 功能 HOT 2
- 在 onResourceReady call WebpDrawable#stop() 沒有辦法停下動畫 HOT 1
- 版本对应问题 HOT 1
- please release 2.3.4.15.1 HOT 1
- 有没有非androidX的版本引用 HOT 1
- 加载webp动图时,偶现会出现这种现象 HOT 3
- Question: is it possible to decode the frames of GIF/WEBP and get callbacks for playing them in specific threads? HOT 2
- Update glide version to 4.16.0 HOT 1
- Critical WebP bug: many apps, not just browsers, under threat HOT 6
- 升级libwebp到1.3.2 HOT 2
- so 出现报毒 HOT 1
- Drawable 转 WebpDrawable 失败,无法设置 动画次数 HOT 1
- so包体积太大了 HOT 1
- 加载webp动图的时候放大控件会导致动图闪烁,好像2层一样 HOT 1
- is this library supposed to help with preventing images rendering black background? HOT 2
- 列表同时加载多个webp动图卡顿
- how can i get all bitmap frame from animate webp HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glidewebpdecoder.