CropBorder use Compose IntRect

This commit is contained in:
GG Bond authored and renovate[bot] committed 2024-03-02 16:01:08 +08:00
1 parent 6e9c6e6269
commit 4dc0f7e02e
5 files changed
+12 -16

No files matched your search

@@ -1,7 +1,7 @@
package com.hippo.ehviewer.coil
import android.graphics.Bitmap
import android.graphics.Rect
import androidx.compose.ui.unit.IntRect
import coil3.BitmapImage
import coil3.Extras
import coil3.Image
@@ -28,7 +28,7 @@ val ImageRequest.maybeCropBorder: Boolean
get() = getExtra(maybeCropBorderKey)
class BitmapImageWithRect(
val rect: Rect,
val rect: IntRect,
val image: Image,
) : Image by image
@@ -48,7 +48,7 @@ object CropBorderInterceptor : Interceptor {
if (image is BitmapImage) {
val bitmap = image.bitmap
val array = detectBorder(bitmap)
val r = Rect(array[0], array[1], array[2], array[3])
val r = IntRect(array[0], array[1], array[2], array[3])
val minWidth = image.width * CROP_THRESHOLD
val minHeight = image.height * CROP_THRESHOLD
val maybeHwBitmap = if (hw) {
@@ -60,7 +60,7 @@ object CropBorderInterceptor : Interceptor {
} else {
bitmap
}
val shouldOverride = r.width() > minWidth && r.height() > minHeight
val shouldOverride = r.width > minWidth && r.height > minHeight
val maybeHwImage = maybeHwBitmap.asCoilImage()
val new = if (shouldOverride) {
BitmapImageWithRect(r, maybeHwImage)
@@ -19,10 +19,10 @@ package com.hippo.ehviewer.image
import android.graphics.Bitmap
import android.graphics.ColorSpace
import android.graphics.Rect
import android.graphics.drawable.Animatable
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.ui.unit.IntRect
import arrow.core.Either
import arrow.core.left
import arrow.core.right
@@ -56,7 +56,7 @@ class Image private constructor(image: CoilImage, private val src: AutoCloseable
val size = image.size
val rect = when (image) {
is BitmapImageWithRect -> image.rect
else -> image.run { Rect(0, 0, width, height) }
else -> image.run { IntRect(0, 0, width, height) }
}
var innerImage: CoilImage? = when (image) {
@@ -15,7 +15,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.unit.dp
import com.hippo.ehviewer.gallery.PageLoader2
import eu.kanade.tachiyomi.source.model.Page
@@ -31,8 +30,6 @@ import me.saket.telephoto.zoomable.ZoomSpec
import me.saket.telephoto.zoomable.rememberZoomableState
import me.saket.telephoto.zoomable.zoomable
typealias EdgeApplier = @Composable (Size) -> Unit
@Composable
fun GalleryPager(
type: ReadingModeType,
@@ -1,6 +1,5 @@
package com.hippo.ehviewer.ui.reader
import android.graphics.Rect
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -21,8 +20,7 @@ import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.IntRect
import coil3.BitmapImage
import coil3.DrawableImage
import coil3.Image
@@ -96,11 +94,11 @@ fun PagerItem(
}
}
private fun Image.toPainter(rect: Rect) = when (this) {
private fun Image.toPainter(rect: IntRect) = when (this) {
is BitmapImage -> BitmapPainter(
image = bitmap.asImageBitmap(),
srcOffset = IntOffset(rect.left, rect.top),
srcSize = IntSize(rect.width(), rect.height()),
srcOffset = rect.topLeft,
srcSize = rect.size,
)
is DrawableImage -> DrawablePainter(drawable)
else -> unreachable()
@@ -17,6 +17,7 @@ import androidx.annotation.AttrRes
import androidx.annotation.CallSuper
import androidx.annotation.StyleRes
import androidx.appcompat.widget.AppCompatImageView
import androidx.compose.ui.graphics.toAndroidRect
import androidx.core.os.postDelayed
import androidx.core.view.isVisible
import coil3.BitmapImage
@@ -133,7 +134,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
}
if (image is BitmapImage) {
prepareNonAnimatedImageView()
setNonAnimatedImage(image.bitmap, drawable.rect, config)
setNonAnimatedImage(image.bitmap, drawable.rect.toAndroidRect(), config)
}
}