From 7862088b940f9881bf59c3d8460baccf5c48c5b0 Mon Sep 17 00:00:00 2001 From: w Date: Thu, 21 Mar 2024 00:20:29 -0700 Subject: [PATCH] Update image-decoder, color management (#523) * Update image-decoder, color management * move display profile pref * remove true color pref * Move Display Profile settings to a new section * Partially revert "remove true color pref" This partially reverts commit e1a75816950e100936699279e1618adb2fa341aa. * Tweak label --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- .../eu/kanade/domain/base/BasePreferences.kt | 2 ++ .../settings/screen/SettingsAdvancedScreen.kt | 31 +++++++++++++++++++ .../settings/screen/SettingsReaderScreen.kt | 6 +--- .../data/coil/TachiyomiImageDecoder.kt | 2 +- .../tachiyomi/ui/reader/ReaderActivity.kt | 24 +++++++++----- .../ui/reader/setting/ReaderPreferences.kt | 3 -- .../ui/reader/viewer/ViewerConfig.kt | 4 --- gradle/libs.versions.toml | 4 +-- .../commonMain/resources/MR/base/strings.xml | 3 +- 9 files changed, 54 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt b/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt index 9fa63d2cd..1700f0a02 100644 --- a/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt +++ b/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt @@ -28,4 +28,6 @@ class BasePreferences( SHIZUKU(MR.strings.ext_installer_shizuku, false), PRIVATE(MR.strings.ext_installer_private, false), } + + fun displayProfile() = preferenceStore.getString("pref_display_profile_key", "") } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index 509f2196a..646c8c042 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -6,6 +6,8 @@ import android.content.Intent import android.provider.Settings import android.webkit.WebStorage import android.webkit.WebView +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.material3.AlertDialog import androidx.compose.material3.Text import androidx.compose.material3.TextButton @@ -123,6 +125,7 @@ object SettingsAdvancedScreen : SearchableSettings { getDataGroup(), getNetworkGroup(networkPreferences = networkPreferences), getLibraryGroup(), + getReaderGroup(basePreferences = basePreferences), getExtensionsGroup(basePreferences = basePreferences), ) } @@ -313,6 +316,34 @@ object SettingsAdvancedScreen : SearchableSettings { ) } + @Composable + private fun getReaderGroup( + basePreferences: BasePreferences, + ): Preference.PreferenceGroup { + val context = LocalContext.current + val chooseColorProfile = rememberLauncherForActivityResult( + contract = ActivityResultContracts.OpenDocument(), + ) { uri -> + uri?.let { + val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION + context.contentResolver.takePersistableUriPermission(uri, flags) + basePreferences.displayProfile().set(uri.toString()) + } + } + return Preference.PreferenceGroup( + title = stringResource(MR.strings.pref_category_reader), + preferenceItems = persistentListOf( + Preference.PreferenceItem.TextPreference( + title = stringResource(MR.strings.pref_display_profile), + subtitle = basePreferences.displayProfile().get(), + onClick = { + chooseColorProfile.launch(arrayOf("*/*")) + }, + ), + ) + ) + } + @Composable private fun getExtensionsGroup( basePreferences: BasePreferences, diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt index bc60037e9..86bdd97c2 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt @@ -29,6 +29,7 @@ object SettingsReaderScreen : SearchableSettings { @Composable override fun getPreferences(): List { val readerPref = remember { Injekt.get() } + return listOf( Preference.PreferenceItem.ListPreference( pref = readerPref.defaultReadingMode(), @@ -56,11 +57,6 @@ object SettingsReaderScreen : SearchableSettings { title = stringResource(MR.strings.pref_show_navigation_mode), subtitle = stringResource(MR.strings.pref_show_navigation_mode_summary), ), - Preference.PreferenceItem.SwitchPreference( - pref = readerPref.trueColor(), - title = stringResource(MR.strings.pref_true_color), - subtitle = stringResource(MR.strings.pref_true_color_summary), - ), Preference.PreferenceItem.SwitchPreference( pref = readerPref.pageTransitions(), title = stringResource(MR.strings.pref_page_transitions), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt b/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt index acbda8cc5..a984fc919 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/coil/TachiyomiImageDecoder.kt @@ -24,7 +24,7 @@ class TachiyomiImageDecoder(private val resources: ImageSource, private val opti check(decoder != null && decoder.width > 0 && decoder.height > 0) { "Failed to initialize decoder" } - val bitmap = decoder.decode(rgb565 = options.allowRgb565) + val bitmap = decoder.decode() decoder.recycle() check(bitmap != null) { "Failed to decode image" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index f170f7e1a..197d1f9dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -38,6 +38,7 @@ import androidx.lifecycle.lifecycleScope import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.elevation.SurfaceColors import com.google.android.material.transition.platform.MaterialContainerTransform +import com.hippo.unifile.UniFile import dev.chrisbanes.insetter.applyInsetter import eu.kanade.domain.base.BasePreferences import eu.kanade.presentation.reader.DisplayRefreshHost @@ -92,6 +93,7 @@ import tachiyomi.i18n.MR import tachiyomi.presentation.core.util.collectAsState import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import java.io.ByteArrayOutputStream class ReaderActivity : BaseActivity() { @@ -795,8 +797,8 @@ class ReaderActivity : BaseActivity() { } .launchIn(lifecycleScope) - readerPreferences.trueColor().changes() - .onEach(::setTrueColor) + preferences.displayProfile().changes() + .onEach { setDisplayProfile(it) } .launchIn(lifecycleScope) readerPreferences.cutoutShort().changes() @@ -835,13 +837,19 @@ class ReaderActivity : BaseActivity() { } /** - * Sets the 32-bit color mode according to [enabled]. + * Sets the display profile to [path]. */ - private fun setTrueColor(enabled: Boolean) { - if (enabled) { - SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.ARGB_8888) - } else { - SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.RGB_565) + private fun setDisplayProfile(path: String) { + val file = UniFile.fromUri(baseContext, path.toUri()) + if (file != null && file.exists()) { + val inputStream = file.openInputStream() + val outputStream = ByteArrayOutputStream() + inputStream.use { input -> + outputStream.use { output -> + input.copyTo(output) + } + } + SubsamplingScaleImageView.setDisplayProfile(outputStream.toByteArray()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt index 6c079b836..39045175f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderPreferences.kt @@ -23,9 +23,6 @@ class ReaderPreferences( fun showReadingMode() = preferenceStore.getBoolean("pref_show_reading_mode", true) - // TODO: default this to true if reader long strip ever goes stable - fun trueColor() = preferenceStore.getBoolean("pref_true_color_key", false) - fun fullscreen() = preferenceStore.getBoolean("fullscreen", true) fun cutoutShort() = preferenceStore.getBoolean("cutout_short", true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt index 0d973d239..c84f8f51b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt @@ -22,7 +22,6 @@ abstract class ViewerConfig(readerPreferences: ReaderPreferences, private val sc var doubleTapAnimDuration = 500 var volumeKeysEnabled = false var volumeKeysInverted = false - var trueColor = false var alwaysShowChapterTransition = true var navigationMode = 0 protected set @@ -62,9 +61,6 @@ abstract class ViewerConfig(readerPreferences: ReaderPreferences, private val sc readerPreferences.readWithVolumeKeysInverted() .register({ volumeKeysInverted = it }) - readerPreferences.trueColor() - .register({ trueColor = it }, { imagePropertyChangedListener?.invoke() }) - readerPreferences.alwaysShowChapterTransition() .register({ alwaysShowChapterTransition = it }) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 576d08176..bd306d843 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -47,8 +47,8 @@ coil-core = { module = "io.coil-kt:coil" } coil-gif = { module = "io.coil-kt:coil-gif" } coil-compose = { module = "io.coil-kt:coil-compose" } -subsamplingscaleimageview = "com.github.tachiyomiorg:subsampling-scale-image-view:7e57335" -image-decoder = "com.github.tachiyomiorg:image-decoder:fbd6601290" +subsamplingscaleimageview = "com.github.tachiyomiorg:subsampling-scale-image-view:aeaa170036" +image-decoder = "com.github.tachiyomiorg:image-decoder:e08e9be535" natural-comparator = "com.github.gpanther:java-nat-sort:natural-comparator-1.1" diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml index 5214e41a8..08fe9eeda 100644 --- a/i18n/src/commonMain/resources/MR/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/base/strings.xml @@ -364,8 +364,7 @@ Show page number Show reading mode Briefly show current mode when reader is opened - 32-bit color - Reduces banding, but may impact performance + Custom display profile Crop borders Custom brightness Grayscale