Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to be able to get size in bytes from GifDrawables #29

Closed
Wavesonics opened this issue Feb 1, 2014 · 8 comments
Closed

Need to be able to get size in bytes from GifDrawables #29

Wavesonics opened this issue Feb 1, 2014 · 8 comments
Assignees
Milestone

Comments

@Wavesonics
Copy link
Contributor

I don't think this should be particularly difficult, but with other drawables, like Bitmaps, we can determine their size in bytes, which is very useful for caching strategies. But with GifDrawable, once we create one, we have no way of querying it for it's size in bytes.

Just a method like: getNumBytes() or what ever would be very useful!

@ghost ghost assigned koral-- Feb 2, 2014
@koral--
Copy link
Owner

koral-- commented Feb 3, 2014

I've added getNumBytes() method in 909ec38
It returns number of bytes needed to hold single frame.

@koral-- koral-- closed this as completed Feb 3, 2014
@Wavesonics
Copy link
Contributor Author

I think being able to get the total memory foot print for the backing GIF data is more important than getting the frame size. At least for dealing with cache sizes.

However I actually think there is a larger problem to solve here. So I've created a new bug: #30

@koral-- koral-- reopened this Feb 3, 2014
@koral--
Copy link
Owner

koral-- commented Feb 3, 2014

So how should we exactly count total memory foot print ? Just number of bytes in input source (affected by compression)?
If GifDrawable is created from File or path there is no additional data hold in memory unlike when created from byte array. If InputStream is the source then its content can be stored in memory as well as on disk. Should we distinguish these cases?
GifDrawable itself contains only all pixels of current frame (drawn in onDraw() method) and optionally may contain previous frame (only if animation uses "restore to previous" disposal method) subsequent frames are decoded when needed.

@Wavesonics
Copy link
Contributor Author

Well we could have the method be smart enough to determine the actual in-memory footprint depending on the input source, and the GIF it's self (store to previous). Or we could just name it specifically enough to be clear it is giving you the compressed, backing data.

My use case would be served by either solution. However I could see a simpler solution potentially being more useful. Have a method that specifically gets the size of the backing data. And another method that gets you the size of the frames it's storing.

@koral--
Copy link
Owner

koral-- commented Feb 3, 2014

OK, so to sum up, we need the following changes:

  • rename getByteCount() to getFrameByteCount() so name won't be confusing
  • add getAllocatedByteCount() which will return overall number of bytes allocated by GifDrawable (including pixels for one or two frames but not data backed by input source), I see that Bitmap counts only buffer for pixels but not other metadata which has relatively small size (like in GifDrawable)
  • add getInputSourceByteCount() which returns length of backing data

@Wavesonics
Copy link
Contributor Author

Ya that looks like it'd solve all the possible use cases I can foresee!

@koral-- koral-- added this to the 1.0.6 milestone Feb 8, 2014
@koral--
Copy link
Owner

koral-- commented Feb 10, 2014

#getAllocationByteCount() added in 5e05c14
There is no way to just obtain length of backing data for InputStream and FileDescriptor unless counting bytes during reading.

@koral--
Copy link
Owner

koral-- commented Feb 11, 2014

#getInputSourceByteCount() added in d4a2a81

@koral-- koral-- closed this as completed Feb 11, 2014
@niplus niplus mentioned this issue Aug 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants