Skip to content

Commit

Permalink
add debanding option
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Aug 28, 2023
1 parent 89e1da0 commit fb72afd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package eu.kanade.presentation.more.settings.screen

import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import eu.kanade.presentation.more.settings.Preference
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.player.settings.PlayerPreferences
import eu.kanade.tachiyomi.util.preference.asState
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

object AdvancedPlayerSettingsScreen : SearchableSettings {
@Composable
override fun getTitleRes() = R.string.pref_category_player_advanced

@Composable
override fun getPreferences(): List<Preference> {
val playerPreferences = remember { Injekt.get<PlayerPreferences>() }
val context = LocalContext.current
val mpvConf = playerPreferences.mpvConf()
val scope = rememberCoroutineScope()

return listOf(
Preference.PreferenceItem.MultiLineEditTextPreference(
pref = mpvConf,
title = context.getString(R.string.pref_mpv_conf),
subtitle = mpvConf.asState(scope).value
.lines().take(2)
.joinToString(
separator = "\n",
postfix = if (mpvConf.asState(scope).value.lines().size > 2) "\n..." else "",
),

),
Preference.PreferenceItem.ListPreference(
title = context.getString(R.string.pref_debanding_title),
pref = playerPreferences.deband(),
entries = mapOf(
0 to context.getString(R.string.pref_debanding_disabled),
1 to context.getString(R.string.pref_debanding_cpu),
2 to context.getString(R.string.pref_debanding_gpu),
),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.domain.base.BasePreferences
import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.util.collectAsState
Expand All @@ -34,7 +36,6 @@ import eu.kanade.tachiyomi.ui.player.NEXT_PLAYER
import eu.kanade.tachiyomi.ui.player.VLC_PLAYER
import eu.kanade.tachiyomi.ui.player.X_PLAYER
import eu.kanade.tachiyomi.ui.player.settings.PlayerPreferences
import eu.kanade.tachiyomi.util.preference.asState
import tachiyomi.presentation.core.components.WheelTextPicker
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
Expand Down Expand Up @@ -81,10 +82,9 @@ object SettingsPlayerScreen : SearchableSettings {

@Composable
private fun getInternalPlayerGroup(playerPreferences: PlayerPreferences): Preference.PreferenceGroup {
val scope = rememberCoroutineScope()
val playerFullscreen = playerPreferences.playerFullscreen()
val playerHideControls = playerPreferences.hideControls()
val mpvConf = playerPreferences.mpvConf()
val navigator = LocalNavigator.currentOrThrow

return Preference.PreferenceGroup(
title = stringResource(R.string.pref_category_internal_player),
Expand All @@ -98,16 +98,10 @@ object SettingsPlayerScreen : SearchableSettings {
pref = playerHideControls,
title = stringResource(R.string.pref_player_hide_controls),
),
Preference.PreferenceItem.MultiLineEditTextPreference(
pref = mpvConf,
title = stringResource(R.string.pref_mpv_conf),
subtitle = mpvConf.asState(scope).value
.lines().take(2)
.joinToString(
separator = "\n",
postfix = if (mpvConf.asState(scope).value.lines().size > 2) "\n..." else "",
),

Preference.PreferenceItem.TextPreference(
title = stringResource(R.string.pref_category_player_advanced),
subtitle = stringResource(R.string.pref_category_player_advanced_subtitle),
onClick = { navigator.push(AdvancedPlayerSettingsScreen) },
),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,15 @@ class PlayerActivity : BaseActivity() {
player.initialize(applicationContext.filesDir.path, logLevel)
MPVLib.observeProperty("chapter-list", MPVLib.mpvFormat.MPV_FORMAT_NONE)
MPVLib.setPropertyDouble("speed", playerPreferences.playerSpeed().get().toDouble())
mpvUpdateHwDec(HwDecState.get(playerPreferences.standardHwDec().get()))
MPVLib.setOptionString("keep-open", "always")
MPVLib.setOptionString("ytdl", "no")

mpvUpdateHwDec(HwDecState.get(playerPreferences.standardHwDec().get()))
when (playerPreferences.deband().get()) {
1 -> MPVLib.setOptionString("vf", "gradfun=radius=12")
2 -> MPVLib.setOptionString("deband", "yes")
}

MPVLib.addLogObserver(playerObserver)
player.addObserver(playerObserver)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ class PlayerPreferences(
fun enableNetflixStyleAniSkip() = preferenceStore.getBoolean("pref_enable_netflixStyle_aniskip", false)

fun standardHwDec() = preferenceStore.getString("pref_hwdec", HwDecState.defaultHwDec.mpvValue)

fun deband() = preferenceStore.getInt("pref_deband", 0)
}
6 changes: 6 additions & 0 deletions i18n/src/main/res/values/strings-aniyomi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@
<string name="stats_page_1">Page 1</string>
<string name="stats_page_2">Page 2</string>
<string name="stats_page_3">Page 3</string>
<string name="pref_category_player_advanced">Advanced player settings</string>
<string name="pref_category_player_advanced_subtitle">Debanding, mpv.conf… etc</string>
<string name="pref_debanding_title">Debanding</string>
<string name="pref_debanding_disabled">Disabled</string>
<string name="pref_debanding_cpu">CPU</string>
<string name="pref_debanding_gpu">GPU</string>
<string name="recent_anime_time">Ep. %1$s - %2$s</string>
<string name="download_insufficient_space">Couldn\'t download due to low storage space</string>
<string name="download_queue_size_warning">Warning: large bulk downloads may lead to sources becoming slower and/or blocking Aniyomi. Tap to learn more.</string>
Expand Down

0 comments on commit fb72afd

Please sign in to comment.