Fix center margin breaking image loading
This commit is contained in:
parent
8bab648b44
commit
11b9a71034
@ -343,13 +343,13 @@ class PagerPageHolder(
|
||||
private fun mergePages(imageStream: InputStream, imageStream2: InputStream?): InputStream {
|
||||
// Handle adding a center margin to wide images if requested
|
||||
if (imageStream2 == null) {
|
||||
if (imageStream is BufferedInputStream && ImageUtil.isWideImage(imageStream) &&
|
||||
return if (imageStream is BufferedInputStream && ImageUtil.isWideImage(imageStream) &&
|
||||
viewer.config.centerMarginType and PagerConfig.CenterMarginType.WIDE_PAGE_CENTER_MARGIN > 0 &&
|
||||
!viewer.config.imageCropBorders
|
||||
) {
|
||||
return ImageUtil.AddHorizontalCenterMargin(imageStream, getHeight(), context)
|
||||
ImageUtil.addHorizontalCenterMargin(imageStream, height, context)
|
||||
} else {
|
||||
return imageStream
|
||||
imageStream
|
||||
}
|
||||
}
|
||||
|
||||
@ -424,10 +424,8 @@ class PagerPageHolder(
|
||||
imageStream.close()
|
||||
imageStream2.close()
|
||||
|
||||
val centerMargin = if (viewer.config.centerMarginType and PagerConfig.CenterMarginType.DOUBLE_PAGE_CENTER_MARGIN > 0 &&
|
||||
!viewer.config.imageCropBorders
|
||||
) {
|
||||
96 / (max(1, getHeight()) / max(height, height2))
|
||||
val centerMargin = if (viewer.config.centerMarginType and PagerConfig.CenterMarginType.DOUBLE_PAGE_CENTER_MARGIN > 0 && !viewer.config.imageCropBorders) {
|
||||
96 / (getHeight().coerceAtLeast(1) / max(height, height2).coerceAtLeast(1)).coerceAtLeast(1)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
||||
*/
|
||||
private fun getPageHolder(page: ReaderPage): PagerPageHolder? =
|
||||
pager.children
|
||||
.filterIsInstance(PagerPageHolder::class.java)
|
||||
.filterIsInstance<PagerPageHolder>()
|
||||
.firstOrNull { it.item.first == page || it.item.second == page }
|
||||
|
||||
/**
|
||||
|
@ -195,7 +195,7 @@ object ImageUtil {
|
||||
* to compensate for scaling.
|
||||
*/
|
||||
|
||||
fun AddHorizontalCenterMargin(imageStream: InputStream, viewHeight: Int, backgroundContext: Context): InputStream {
|
||||
fun addHorizontalCenterMargin(imageStream: InputStream, viewHeight: Int, backgroundContext: Context): InputStream {
|
||||
val imageBitmap = ImageDecoder.newInstance(imageStream)?.decode()!!
|
||||
val height = imageBitmap.height
|
||||
val width = imageBitmap.width
|
||||
@ -642,18 +642,18 @@ object ImageUtil {
|
||||
canvas.drawColor(background)
|
||||
val upperPart = Rect(
|
||||
if (isLTR) 0 else width2 + centerMargin,
|
||||
(maxHeight - imageBitmap.height) / 2,
|
||||
(if (isLTR) 0 else width2 + centerMargin) + imageBitmap.width,
|
||||
imageBitmap.height + (maxHeight - imageBitmap.height) / 2,
|
||||
(maxHeight - height) / 2,
|
||||
(if (isLTR) 0 else width2 + centerMargin) + width,
|
||||
height + (maxHeight - height) / 2,
|
||||
)
|
||||
|
||||
canvas.drawBitmap(imageBitmap, imageBitmap.rect, upperPart, null)
|
||||
progressCallback?.invoke(98)
|
||||
val bottomPart = Rect(
|
||||
if (!isLTR) 0 else width + centerMargin,
|
||||
(maxHeight - imageBitmap2.height) / 2,
|
||||
(if (!isLTR) 0 else width + centerMargin) + imageBitmap2.width,
|
||||
imageBitmap2.height + (maxHeight - imageBitmap2.height) / 2,
|
||||
(maxHeight - height2) / 2,
|
||||
(if (!isLTR) 0 else width + centerMargin) + width2,
|
||||
height2 + (maxHeight - height2) / 2,
|
||||
)
|
||||
|
||||
canvas.drawBitmap(imageBitmap2, imageBitmap2.rect, bottomPart, null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user