refactor(reader): Improve hardware bitmap threshold option

This commit is contained in:
AntsyLich 2024-11-21 13:50:09 +07:00 committed by Ahmad Ansori Palembani
parent 37ba0634ac
commit 9322836e48
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
4 changed files with 24 additions and 9 deletions

View file

@ -15,6 +15,8 @@ The format is simplified version of [Keep a Changelog](https://keepachangelog.co
- Sync DoH provider list with upstream (added Mullvad, Control D, Njalla, and Shecan)
- Added option to enable verbose logging
- Added category hopper long-press action to open random series from **any** category
- Added option to enable reader debug mode
- Added option to adjust reader's hardware bitmap threshold (@AntsyLich)
### Changes
- Enable 'Split Tall Images' by default (@Smol-Ame)

View file

@ -401,7 +401,15 @@ class SettingsAdvancedController : SettingsLegacyController() {
titleRes = MR.strings.pref_hardware_bitmap_threshold
val entryMap = GLUtil.CUSTOM_TEXTURE_LIMIT_OPTIONS
.associateWith { it.toString() }
.mapIndexed { index, option ->
val display = if (index == 0) {
context.getString(MR.strings.pref_hardware_bitmap_threshold_default, option)
} else {
option.toString()
}
option to display
}
.toMap()
.toImmutableMap()
entries = entryMap.values.toList()
entryValues = entryMap.keys.toList()
@ -409,7 +417,7 @@ class SettingsAdvancedController : SettingsLegacyController() {
isVisible = GLUtil.DEVICE_TEXTURE_LIMIT > GLUtil.SAFE_TEXTURE_LIMIT
basePreferences.hardwareBitmapThreshold().changesIn(viewScope) { threshold ->
summary = context.getString(MR.strings.pref_hardware_bitmap_threshold_summary, threshold)
summary = context.getString(MR.strings.pref_hardware_bitmap_threshold_summary, entryMap[threshold].orEmpty())
}
}

View file

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.util.system
import javax.microedition.khronos.egl.EGL10
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.egl.EGLContext
import kotlin.math.max
object GLUtil {
val DEVICE_TEXTURE_LIMIT: Int by lazy {
@ -38,18 +39,21 @@ object GLUtil {
egl.eglTerminate(display)
// Return largest texture size found (after making it a multiplier of [Multiplier]), or default
if (maximumTextureSize > SAFE_TEXTURE_LIMIT) {
(maximumTextureSize / MULTIPLIER) * MULTIPLIER
} else {
SAFE_TEXTURE_LIMIT
}
max(maximumTextureSize, SAFE_TEXTURE_LIMIT)
}
const val SAFE_TEXTURE_LIMIT: Int = 2048
val CUSTOM_TEXTURE_LIMIT_OPTIONS: List<Int> by lazy {
val steps = ((DEVICE_TEXTURE_LIMIT / MULTIPLIER) - 1)
List(steps) { (it + 2) * MULTIPLIER }.asReversed()
val steps = DEVICE_TEXTURE_LIMIT / MULTIPLIER
buildList(steps) {
add(DEVICE_TEXTURE_LIMIT)
for (step in steps downTo 2) {
val value = step * MULTIPLIER
if (value >= DEVICE_TEXTURE_LIMIT) continue
add(value)
}
}
}
}

View file

@ -514,6 +514,7 @@
<string name="pref_lowest">Lowest</string>
<string name="pref_display_profile">Custom display profile</string>
<string name="pref_hardware_bitmap_threshold">Custom hardware bitmap threshold</string>
<string name="pref_hardware_bitmap_threshold_default">Default (%d)</string>
<string name="pref_hardware_bitmap_threshold_summary">If reader loads a blank image incrementally reduce the threshold.\nSelected: %s</string>
<string name="pref_double_tap_zoom">Double tap to zoom</string>