Added grayscale filter.

This commit is contained in:
Themaister 2010-08-19 15:21:30 +02:00
parent 520ccfabc5
commit 747b621afd
3 changed files with 35 additions and 0 deletions

21
hqflt/grayscale.c Normal file
View File

@ -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;
}
}

7
hqflt/grayscale.h Normal file
View File

@ -0,0 +1,7 @@
/* Very simple grayscale filter.
* Author: Hans-Kristian Arntzen
* License: Public domain
*/
#include <stdint.h>
void grayscale_filter(uint16_t *data, int width, int height);

View File

@ -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;