Repository navigation
Conversation
With `displaySize`, `inSampleSize` was computed from the crop rect but the
decode asked for `Rect(0, 0, decoder.width, decoder.height)` — the entire
source image. So a small crop of a huge photo picked a small sample size
and allocated a full-resolution bitmap: a 10000x7500 panorama cropped to
200x200 with `displaySize {100, 100}` decoded to 5000x3750 ARGB_8888,
about 75 MB, to produce a 100x100 thumbnail. Passing `displaySize` made
memory strictly worse than omitting it, and the intermediate bitmap was
never recycled. `cropTask` already decoded just the crop rect.
Decode the orientation-mapped crop rect instead and size `inSampleSize`
from the region actually decoded. Take the downsample factor from the
decoded bitmap rather than assuming `inSampleSize` was honoured, since
`decodeRegion` ignores it on API 21-23 (minSdk is 21), and recycle the
decoded bitmap once it has been scaled (unless `createBitmap` returned
that same instance). Also recycle the decoder, which this path never
released.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
K2: OOM. Decode only the crop region instead of the whole image.
inSampleSizenow comes from the actual decoded bitmap. Intermediate bitmaps are recycled, anddecoder.recycle()now runs in afinally.When
displaySizewas set,inSampleSizewas computed from the crop rect, but the decode usedRect(0, 0, decoder.width, decoder.height), which is the whole image. Example: a 200×200 crop withdisplaySize: 100on a 10000×7500 panorama pickedinSampleSize=2and decoded ~75 MB to make a 100×100 thumbnail (ideal ≈160 KB). So passingdisplaySizemade memory use worse than leaving it out.inSampleSizeis now derived from the region that was actually decoded. That also fixes itself on API 21–23, wheredecodeRegionignoresinSampleSize, so noBuild.VERSIONbranch is needed.No out-of-bounds clamping was added on purpose.
decodeRegionalready throwsIOExceptionfor that case, and clamping silently would turn a rejection into different output.Note: without K1 (#224), an
OutOfMemoryErrorstill escapescatch (Exception).Verification
Not compiled. No
:android:compileDebugKotlinrun and nothing run on a device. The Kotlin was checked for syntax errors only, and the external API signatures were checked against the published artifacts.Split out of #221 (now closed), which bundled six Android fixes in
ImageEditorModuleImpl.kt. Each one can be reviewed and merged separately.