From 9330084d4286c22cd993bd88365287af077ce3a5 Mon Sep 17 00:00:00 2001 From: w Date: Thu, 18 Apr 2024 10:41:59 -0700 Subject: [PATCH 1/2] Convert bitmap to HARDWARE config --- library/build.gradle.kts | 2 +- .../com/davemorrissey/labs/subscaleview/decoder/Decoder.kt | 3 ++- sample/build.gradle.kts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/library/build.gradle.kts b/library/build.gradle.kts index bb9995a3..4202d1a3 100755 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -9,7 +9,7 @@ android { compileSdk = 34 defaultConfig { - minSdk = 21 + minSdk = 26 consumerProguardFiles("proguard-rules.txt") } diff --git a/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt b/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt index 3f362843..00b31227 100755 --- a/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt +++ b/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt @@ -52,7 +52,8 @@ class Decoder( * @return The decoded region. It is safe to return null if decoding fails. */ override fun decodeRegion(sRect: Rect, sampleSize: Int): Bitmap { - val bitmap = decoder?.decode(sRect, sampleSize) + var bitmap = decoder?.decode(sRect, sampleSize) + bitmap = bitmap?.copy(Bitmap.Config.HARDWARE, false) return bitmap ?: error("Null region bitmap") } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index e6c6619c..beac9bf8 100755 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -9,7 +9,7 @@ android { defaultConfig { applicationId = "com.davemorrissey.labs.subscaleview.test" - minSdk = 24 + minSdk = 26 targetSdk = 34 versionCode = 4 From ff869caef6fd159b6ccdb1589fa5e254e437b224 Mon Sep 17 00:00:00 2001 From: w Date: Thu, 18 Apr 2024 10:54:29 -0700 Subject: [PATCH 2/2] optional on sdk 26 --- library/build.gradle.kts | 2 +- .../com/davemorrissey/labs/subscaleview/decoder/Decoder.kt | 5 ++++- sample/build.gradle.kts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 4202d1a3..bb9995a3 100755 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -9,7 +9,7 @@ android { compileSdk = 34 defaultConfig { - minSdk = 26 + minSdk = 21 consumerProguardFiles("proguard-rules.txt") } diff --git a/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt b/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt index 00b31227..e2f5d12f 100755 --- a/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt +++ b/library/src/main/java/com/davemorrissey/labs/subscaleview/decoder/Decoder.kt @@ -4,6 +4,7 @@ import android.content.Context import android.graphics.Bitmap import android.graphics.Point import android.graphics.Rect +import android.os.Build import android.util.Log import com.davemorrissey.labs.subscaleview.provider.InputProvider import tachiyomi.decoder.ImageDecoder @@ -53,7 +54,9 @@ class Decoder( */ override fun decodeRegion(sRect: Rect, sampleSize: Int): Bitmap { var bitmap = decoder?.decode(sRect, sampleSize) - bitmap = bitmap?.copy(Bitmap.Config.HARDWARE, false) + if (Build.VERSION.SDK_INT >= 26) { + bitmap = bitmap?.copy(Bitmap.Config.HARDWARE, false) + } return bitmap ?: error("Null region bitmap") } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index beac9bf8..ec699c86 100755 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -9,7 +9,7 @@ android { defaultConfig { applicationId = "com.davemorrissey.labs.subscaleview.test" - minSdk = 26 + minSdk = 21 targetSdk = 34 versionCode = 4