From 87ca842eb9453b604cecff7883ab217602735c7e Mon Sep 17 00:00:00 2001 From: Rupert Carmichael <5050061-carmiker@users.noreply.gitlab.com> Date: Sat, 15 Jun 2024 11:09:50 -0400 Subject: [PATCH] libretro: Add colour adjustment core options --- bsnes/target-libretro/libretro.cpp | 28 +++++++ bsnes/target-libretro/libretro_core_options.h | 79 +++++++++++++++++++ bsnes/target-libretro/program.cpp | 4 - bsnes/target-libretro/program.h | 6 +- 4 files changed, 112 insertions(+), 5 deletions(-) diff --git a/bsnes/target-libretro/libretro.cpp b/bsnes/target-libretro/libretro.cpp index 8099f1a69..8893dd084 100644 --- a/bsnes/target-libretro/libretro.cpp +++ b/bsnes/target-libretro/libretro.cpp @@ -465,6 +465,33 @@ static void update_variables(void) } } + var.key = "bsnes_video_luminance"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + { + int val = atoi(var.value); + program->luminance = val / 100.0; + } + + var.key = "bsnes_video_saturation"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + { + int val = atoi(var.value); + program->saturation = val / 100.0; + } + + var.key = "bsnes_video_gamma"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + { + int val = atoi(var.value); + program->gamma = val / 100.0; + } + update_option_visibility(); } @@ -763,6 +790,7 @@ void retro_run() { update_variables(); update_geometry(); + program->updateVideoPalette(); } bool is_fast_forwarding = false; diff --git a/bsnes/target-libretro/libretro_core_options.h b/bsnes/target-libretro/libretro_core_options.h index fed5e46de..3a987ca6d 100644 --- a/bsnes/target-libretro/libretro_core_options.h +++ b/bsnes/target-libretro/libretro_core_options.h @@ -153,6 +153,85 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "None" }, + { + "bsnes_video_luminance", + "Color Adjustment - Luminance", + NULL, + "Adjust Luminance", + NULL, + "video", + { + { "0", "0%" }, + { "10", "10%" }, + { "20", "20%" }, + { "30", "30%" }, + { "40", "40%" }, + { "50", "50%" }, + { "60", "60%" }, + { "70", "70%" }, + { "80", "80%" }, + { "90", "90%" }, + { "100", "100% (Default)" }, + { NULL, NULL }, + }, + "100" + }, + { + "bsnes_video_saturation", + "Color Adjustment - Saturation", + NULL, + "Adjust Saturation", + NULL, + "video", + { + { "0", "0%" }, + { "10", "10%" }, + { "20", "20%" }, + { "30", "30%" }, + { "40", "40%" }, + { "50", "50%" }, + { "60", "60%" }, + { "70", "70%" }, + { "80", "80%" }, + { "90", "90%" }, + { "100", "100% (Default)" }, + { "110", "110%" }, + { "120", "120%" }, + { "130", "130%" }, + { "140", "140%" }, + { "150", "150%" }, + { "160", "160%" }, + { "170", "170%" }, + { "180", "180%" }, + { "190", "190%" }, + { "200", "200%" }, + { NULL, NULL }, + }, + "100" + }, + { + "bsnes_video_gamma", + "Color Adjustment - Gamma", + NULL, + "Adjust Gamma", + NULL, + "video", + { + { "100", "100%" }, + { "110", "110%" }, + { "120", "120%" }, + { "130", "130%" }, + { "140", "140%" }, + { "150", "150% (Default)" }, + { "160", "160%" }, + { "170", "170%" }, + { "180", "180%" }, + { "190", "190%" }, + { "200", "200%" }, + { NULL, NULL }, + }, + "150" + }, { "bsnes_ppu_fast", "PPU (Video) - Fast Mode", diff --git a/bsnes/target-libretro/program.cpp b/bsnes/target-libretro/program.cpp index d8bf5ddcb..d9448114e 100644 --- a/bsnes/target-libretro/program.cpp +++ b/bsnes/target-libretro/program.cpp @@ -808,10 +808,6 @@ auto Program::hackPatchMemory(vector& data) -> void } auto Program::updateVideoPalette() -> void { - double luminance = 100.0 / 100.0; - double saturation = 100.0 / 100.0; - double gamma = 150.0 / 100.0; - uint depth = 24; for(uint color : range(32768)) { diff --git a/bsnes/target-libretro/program.h b/bsnes/target-libretro/program.h index 3fd33085c..32a9d13ad 100644 --- a/bsnes/target-libretro/program.h +++ b/bsnes/target-libretro/program.h @@ -40,7 +40,7 @@ struct Program : Emulator::Platform string base_name; - bool overscan = false; + bool overscan{false}; public: struct Game { @@ -77,4 +77,8 @@ struct Program : Emulator::Platform Filter::Render filterRender; Filter::Size filterSize; + + double luminance{1.0}; + double saturation{1.0}; + double gamma{1.5}; };