Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Convert bitmap to HARDWARE config #3

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,7 +53,10 @@ 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)
if (Build.VERSION.SDK_INT >= 26) {
bitmap = bitmap?.copy(Bitmap.Config.HARDWARE, false)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fallback to software bitmap if the copy fails.

}
return bitmap ?: error("Null region bitmap")
}

Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {

defaultConfig {
applicationId = "com.davemorrissey.labs.subscaleview.test"
minSdk = 24
minSdk = 21
targetSdk = 34

versionCode = 4
Expand Down