From 389ed7111e934452a7ed76c3df0b16c32c783f45 Mon Sep 17 00:00:00 2001 From: Themaister Date: Thu, 19 Aug 2010 15:21:30 +0200 Subject: [PATCH] Added grayscale filter. --- hqflt/grayscale.c | 21 +++++++++++++++++++++ hqflt/grayscale.h | 7 +++++++ ssnes.c | 7 +++++++ 3 files changed, 35 insertions(+) create mode 100644 hqflt/grayscale.c create mode 100644 hqflt/grayscale.h diff --git a/hqflt/grayscale.c b/hqflt/grayscale.c new file mode 100644 index 0000000000..dd2d5081ea --- /dev/null +++ b/hqflt/grayscale.c @@ -0,0 +1,21 @@ +/* Very simple grayscale filter. + * Author: Hans-Kristian Arntzen + * License: Public domain + */ + +#include "grayscale.h" + +// Input format 0RRRRRGGGGGBBBBB. Colors themselves could be switched around. +void grayscale_filter(uint16_t *data, int width, int height) +{ + for (int i = 0; i < width * height; i++ ) + { + int r, g, b, color; + r = (data[i] >> 10) & 0x1F; + g = (data[i] >> 5) & 0x1F; + b = (data[i] >> 0) & 0x1F; + + color = (int)(r * 0.3 + g * 0.59 + b * 0.11); + data[i] = (color << 10) | (color << 5) | color; + } +} diff --git a/hqflt/grayscale.h b/hqflt/grayscale.h new file mode 100644 index 0000000000..7333095112 --- /dev/null +++ b/hqflt/grayscale.h @@ -0,0 +1,7 @@ +/* Very simple grayscale filter. + * Author: Hans-Kristian Arntzen + * License: Public domain + */ + +#include +void grayscale_filter(uint16_t *data, int width, int height); diff --git a/ssnes.c b/ssnes.c index d0d46cc2eb..e4dcfdf874 100644 --- a/ssnes.c +++ b/ssnes.c @@ -26,6 +26,7 @@ #include "config.h" #include "driver.h" #include "hqflt/pastlib.h" +#include "hqflt/grayscale.h" static bool video_active = true; static bool audio_active = true; @@ -136,6 +137,8 @@ static void init_video_input(void) scale = 2; #elif VIDEO_FILTER == FILTER_HQ4X scale = 4; +#elif VIDEO_FILTER == FILTER_GRAYSCALE + scale = 1; #else scale = 1; #endif @@ -216,6 +219,10 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height) ProcessHQ4x(output, outputHQ4x); if ( !driver.video->frame(driver.video_data, outputHQ4x, width * 4, height * 4) ) video_active = false; +#elif VIDEO_FILTER == FILTER_GRAYSCALE + grayscale_filter(output, width, height); + if ( !driver.video->frame(driver.video_data, output, width, height) ) + video_active = false; #else if ( !driver.video->frame(driver.video_data, output, width, height) ) video_active = false;