mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 16:20:27 +00:00
Added bleed 'n noise filter.
This commit is contained in:
parent
8c956f95a1
commit
cb00f4b07e
1
Makefile
1
Makefile
@ -28,6 +28,7 @@ endif
|
||||
ifeq ($(BUILD_FILTER), 1)
|
||||
OBJ += hqflt/hq.o
|
||||
OBJ += hqflt/grayscale.o
|
||||
OBJ += hqflt/bleed.o
|
||||
endif
|
||||
|
||||
CFLAGS = -Wall -O3 -march=native -std=gnu99
|
||||
|
5
config.h
5
config.h
@ -70,6 +70,7 @@ static const bool force_aspect = true;
|
||||
#define FILTER_HQ2X 1
|
||||
#define FILTER_HQ4X 2
|
||||
#define FILTER_GRAYSCALE 3
|
||||
#define FILTER_BLEED 4
|
||||
////////////////////////
|
||||
|
||||
// If you change this to something other than FILTER_NONE, make sure that you build the filter module in config.mk.
|
||||
@ -91,10 +92,10 @@ static const unsigned out_rate = 48000;
|
||||
static const unsigned in_rate = 31950;
|
||||
|
||||
// Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults.
|
||||
static const char* audio_device = "hw:0";
|
||||
static const char* audio_device = NULL;
|
||||
|
||||
// Desired audio latency in milliseconds. Might not be honored if driver can't provide given latency.
|
||||
static const int out_latency = 16;
|
||||
static const int out_latency = 64;
|
||||
|
||||
// Will sync audio. (recommended)
|
||||
static const bool audio_sync = true;
|
||||
|
45
hqflt/bleed.c
Normal file
45
hqflt/bleed.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include "bleed.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void bleed_filter(uint16_t *data, int width, int height)
|
||||
{
|
||||
uint16_t tmp[4];
|
||||
int ptr = 0;
|
||||
uint16_t r[4];
|
||||
uint16_t g[4];
|
||||
uint16_t b[4];
|
||||
uint16_t bleed_r;
|
||||
uint16_t bleed_g;
|
||||
uint16_t bleed_b;
|
||||
float rand_map[4];
|
||||
|
||||
for (int h = 0; h < height; h++ )
|
||||
{
|
||||
memcpy(tmp, data, sizeof(tmp));
|
||||
ptr = 3;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
rand_map[i] = (rand() % 20)/1000.0; // 0.02 * 4 = 0.08
|
||||
}
|
||||
|
||||
for (int i = 3; i < width; i++, ptr++)
|
||||
{
|
||||
tmp[ptr & 0x3] = data[i];
|
||||
for (int y = 0; y < 4; y++)
|
||||
{
|
||||
r[y] = (tmp[(ptr + y) & 0x3] >> 10) & 0x1F;
|
||||
g[y] = (tmp[(ptr + y) & 0x3] >> 5) & 0x1F;
|
||||
b[y] = (tmp[(ptr + y) & 0x3] >> 0) & 0x1F;
|
||||
}
|
||||
|
||||
bleed_r = r[0] * (0.05 + rand_map[0] ) + r[1] * (0.10 + rand_map[1] ) + r[2] * (0.20 + rand_map[2]) + r[3] * (0.57 + rand_map[3] ); // 0.92
|
||||
bleed_g = g[0] * (0.03 + rand_map[2]/3) + g[1] * (0.10 + rand_map[0]/3) + g[2] * (0.20 + rand_map[3]/3) + g[3] * (0.63 + rand_map[1]/3); // 0.96
|
||||
bleed_b = b[0] * (0.05 + rand_map[3] ) + b[1] * (0.10 + rand_map[2] ) + b[2] * (0.20 + rand_map[1]) + b[3] * (0.57 + rand_map[0] ); // 0.92
|
||||
|
||||
data[i] = (bleed_r << 10) | (bleed_g << 5) | (bleed_b);
|
||||
}
|
||||
data += width;
|
||||
}
|
||||
}
|
3
hqflt/bleed.h
Normal file
3
hqflt/bleed.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void bleed_filter(uint16_t *data, int width, int height);
|
7
ssnes.c
7
ssnes.c
@ -27,6 +27,7 @@
|
||||
#include "driver.h"
|
||||
#include "hqflt/pastlib.h"
|
||||
#include "hqflt/grayscale.h"
|
||||
#include "hqflt/bleed.h"
|
||||
|
||||
static bool video_active = true;
|
||||
static bool audio_active = true;
|
||||
@ -158,6 +159,8 @@ static void init_video_input(void)
|
||||
scale = 4;
|
||||
#elif VIDEO_FILTER == FILTER_GRAYSCALE
|
||||
scale = 1;
|
||||
#elif VIDEO_FILTER == FILTER_BLEED
|
||||
scale = 1;
|
||||
#else
|
||||
scale = 1;
|
||||
#endif
|
||||
@ -242,6 +245,10 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height)
|
||||
grayscale_filter(output, width, height);
|
||||
if ( !driver.video->frame(driver.video_data, output, width, height) )
|
||||
video_active = false;
|
||||
#elif VIDEO_FILTER == FILTER_BLEED
|
||||
bleed_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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user