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

fallback to imprecise scaling if low memory #1892

Merged
merged 1 commit into from
Sep 6, 2014

Conversation

mcginty
Copy link
Contributor

@mcginty mcginty commented Sep 4, 2014

Gracefully falls back to rough scaling to solve the OutOfMemoryErrors that I was able to reproduce on a GB emulator with low RAM. This helps a lot since it doesn't require two large Bitmap objects in memory at the same time.

Also moved away from BufferedInputStream to another workaround to the Android bitmap problems, which will save more memory. On top of that, we weren't closing the streams so that's also fixed.

/**
* Memory-friendly workaround found from https://code.google.com/p/android/issues/detail?id=6066#c23
* to solve decoding problems in bitmaps from InputStreams that don't skip if no more stream is available.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this happening? This link is talking about blocking network streams, where as read() from disk should always read the number of bytes requested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, wasn't aware. The Javadoc didn't say that read() always returns the number of bytes requested. Seemed like a good idea to make sure it worked with all InputStream objects anyway. Would you prefer I instead have the method signature only take in FileInputStreams?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract is not that strong, but in practice read() will only return short of the requested value if less than the requested value is available. That should only happen when reading from the network. I'm mostly curious how this came up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a while ago, but I think originally I was experiencing those "decoder false" errors when doing Bitmap work a while back, and wrapping it in a BufferedInputStream seemed to resolve the problem. This is supposedly a more memory-efficient way to do the same thing, and it feels safer to include it.

moxie0 added a commit that referenced this pull request Sep 6, 2014
fallback to imprecise scaling if low memory
@moxie0 moxie0 merged commit 2045c82 into signalapp:master Sep 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants