Change logic in BitmapFactory.Options.splitData (#7989)

This commit is contained in:
AntsyLich 2022-09-12 03:59:57 +06:00 committed by GitHub
parent 19be0d68b6
commit 935c8e7d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -310,19 +310,19 @@ object ImageUtil {
} }
return mutableListOf<SplitData>().apply { return mutableListOf<SplitData>().apply {
for (index in (0 until partCount)) { val range = 0 until partCount
for (index in range) {
// Only continue if the list is empty or there is image remaining // Only continue if the list is empty or there is image remaining
if (isNotEmpty() && imageHeight <= last().bottomOffset) break if (isNotEmpty() && imageHeight <= last().bottomOffset) break
val topOffset = index * optimalSplitHeight val topOffset = index * optimalSplitHeight
var splitHeight = min(optimalSplitHeight, imageHeight - topOffset) var splitHeight = min(optimalSplitHeight, imageHeight - topOffset)
val remainingHeight = imageHeight - (topOffset + splitHeight) if (index == range.last) {
// If remaining height is smaller or equal to 1/10th of val remainingHeight = imageHeight - (topOffset + splitHeight)
// optimal split height then include it in current page
if (remainingHeight <= (optimalSplitHeight / 10)) {
splitHeight += remainingHeight splitHeight += remainingHeight
} }
add(SplitData(index, topOffset, splitHeight, imageWidth)) add(SplitData(index, topOffset, splitHeight, imageWidth))
} }
} }