Skip to content

Commit

Permalink
libretro: Add colour adjustment core options
Browse files Browse the repository at this point in the history
  • Loading branch information
carmiker committed Jun 15, 2024
1 parent df24653 commit 87ca842
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 5 deletions.
28 changes: 28 additions & 0 deletions bsnes/target-libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -763,6 +790,7 @@ void retro_run()
{
update_variables();
update_geometry();
program->updateVideoPalette();
}

bool is_fast_forwarding = false;
Expand Down
79 changes: 79 additions & 0 deletions bsnes/target-libretro/libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions bsnes/target-libretro/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,6 @@ auto Program::hackPatchMemory(vector<uint8_t>& 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)) {
Expand Down
6 changes: 5 additions & 1 deletion bsnes/target-libretro/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Program : Emulator::Platform

string base_name;

bool overscan = false;
bool overscan{false};

public:
struct Game {
Expand Down Expand Up @@ -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};
};

0 comments on commit 87ca842

Please sign in to comment.