(SoftFilters) Reimplement all filters - take out softfilter_prototypes

header file
This commit is contained in:
twinaphex 2014-05-10 02:12:00 +02:00
parent 94157eabed
commit e037e2555e
10 changed files with 355 additions and 208 deletions

View File

@ -15,20 +15,39 @@
*/
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#include "boolean.h"
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation blargg_ntsc_snes_rf_get_implementation
#endif
#include "snes_ntsc/snes_ntsc.h"
#include "snes_ntsc/snes_ntsc.c"
static struct snes_ntsc_t *ntsc_rf;
static int burst_rf;
static int burst_toggle_rf;
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation blargg_ntsc_snes_rf_get_implementation
#define softfilter_thread_data blargg_ntsc_snes_rf_softfilter_thread_data
#define filter_data blargg_ntsc_snes_rf_filter_data
#endif
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
struct snes_ntsc_t *ntsc;
int burst;
int burst_toggle;
};
static unsigned blargg_ntsc_snes_rf_generic_input_fmts(void)
{
@ -46,6 +65,20 @@ static unsigned blargg_ntsc_snes_rf_generic_threads(void *data)
return filt->threads;
}
static void blargg_ntsc_snes_rf_initialize(void *data)
{
snes_ntsc_setup_t setup;
struct filter_data *filt = (struct filter_data*)data;
filt->ntsc = (snes_ntsc_t*)calloc(1, sizeof(*filt->ntsc));
setup = snes_ntsc_composite;
setup.merge_fields = 0;
snes_ntsc_init(filt->ntsc, &setup);
filt->burst = 0;
filt->burst_toggle = (setup.merge_fields ? 0 : 1);
}
static void *blargg_ntsc_snes_rf_generic_create(unsigned in_fmt, unsigned out_fmt,
unsigned max_width, unsigned max_height,
unsigned threads, softfilter_simd_mask_t simd)
@ -63,30 +96,14 @@ static void *blargg_ntsc_snes_rf_generic_create(unsigned in_fmt, unsigned out_fm
free(filt);
return NULL;
}
blargg_ntsc_snes_rf_initialize(filt);
return filt;
}
static void blargg_ntsc_snes_rf_initialize(void)
{
snes_ntsc_setup_t setup;
static bool initialized = false;
if(initialized == true)
return;
initialized = true;
ntsc_rf = (snes_ntsc_t*)malloc(sizeof(*ntsc_rf));
setup = snes_ntsc_composite;
setup.merge_fields = 0;
snes_ntsc_init(ntsc_rf, &setup);
burst_rf = 0;
burst_toggle_rf = (setup.merge_fields ? 0 : 1);
}
static void blargg_ntsc_snes_rf_generic_output(void *data, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height)
{
blargg_ntsc_snes_rf_initialize();
*out_width = SNES_NTSC_OUT_WIDTH(256);
*out_height = height;
}
@ -95,34 +112,31 @@ static void blargg_ntsc_snes_rf_generic_destroy(void *data)
{
struct filter_data *filt = (struct filter_data*)data;
if(ntsc_rf)
free(ntsc_rf);
if(filt->ntsc)
free(filt->ntsc);
free(filt->workers);
free(filt);
}
static void blargg_ntsc_snes_rf_render_rgb565(int width, int height,
static void blargg_ntsc_snes_rf_render_rgb565(void *data, int width, int height,
int first, int last,
uint16_t *input, int pitch, uint16_t *output, int outpitch)
{
blargg_ntsc_snes_rf_initialize();
if(!ntsc_rf)
return;
struct filter_data *filt = (struct filter_data*)data;
if(width <= 256)
snes_ntsc_blit(ntsc_rf, input, pitch, burst_rf, width, height, output, outpitch * 2, first, last);
snes_ntsc_blit(filt->ntsc, input, pitch, filt->burst, width, height, output, outpitch * 2, first, last);
else
snes_ntsc_blit_hires(ntsc_rf, input, pitch, burst_rf, width, height, output, outpitch * 2, first, last);
snes_ntsc_blit_hires(filt->ntsc, input, pitch, filt->burst, width, height, output, outpitch * 2, first, last);
burst_rf ^= burst_toggle_rf;
filt->burst ^= filt->burst_toggle;
}
static void blargg_ntsc_snes_rf_rgb565(unsigned width, unsigned height,
static void blargg_ntsc_snes_rf_rgb565(void *data, unsigned width, unsigned height,
int first, int last, uint16_t *src,
unsigned src_stride, uint16_t *dst, unsigned dst_stride)
{
blargg_ntsc_snes_rf_render_rgb565(width, height,
blargg_ntsc_snes_rf_render_rgb565(data, width, height,
first, last,
src, src_stride,
dst, dst_stride);
@ -137,7 +151,7 @@ static void blargg_ntsc_snes_rf_work_cb_rgb565(void *data, void *thread_data)
unsigned width = thr->width;
unsigned height = thr->height;
blargg_ntsc_snes_rf_rgb565(width, height,
blargg_ntsc_snes_rf_rgb565(data, width, height,
thr->first, thr->last, input, thr->in_pitch / SOFTFILTER_BPP_RGB565, output, thr->out_pitch / SOFTFILTER_BPP_RGB565);
}
@ -193,4 +207,6 @@ const struct softfilter_implementation *softfilter_get_implementation(softfilter
#ifdef RARCH_INTERNAL
#undef softfilter_get_implementation
#undef softfilter_thread_data
#undef filter_data
#endif

View File

@ -15,20 +15,39 @@
*/
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#include "boolean.h"
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation blargg_ntsc_snes_svideo_get_implementation
#endif
#include "snes_ntsc/snes_ntsc.h"
#include "snes_ntsc/snes_ntsc.c"
static struct snes_ntsc_t *ntsc_svideo;
static int burst_svideo;
static int burst_toggle_svideo;
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation blargg_ntsc_snes_svideo_get_implementation
#define softfilter_thread_data blargg_ntsc_snes_svideo_softfilter_thread_data
#define filter_data blargg_ntsc_snes_svideo_filter_data
#endif
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
struct snes_ntsc_t *ntsc;
int burst;
int burst_toggle;
};
static unsigned blargg_ntsc_snes_svideo_generic_input_fmts(void)
{
@ -46,6 +65,20 @@ static unsigned blargg_ntsc_snes_svideo_generic_threads(void *data)
return filt->threads;
}
static void blargg_ntsc_snes_svideo_initialize(void *data)
{
snes_ntsc_setup_t setup;
struct filter_data *filt = (struct filter_data*)data;
filt->ntsc = (snes_ntsc_t*)calloc(1, sizeof(*filt->ntsc));
setup = snes_ntsc_svideo;
setup.merge_fields = 1;
snes_ntsc_init(filt->ntsc, &setup);
filt->burst = 0;
filt->burst_toggle = (setup.merge_fields ? 0 : 1);
}
static void *blargg_ntsc_snes_svideo_generic_create(unsigned in_fmt, unsigned out_fmt,
unsigned max_width, unsigned max_height,
unsigned threads, softfilter_simd_mask_t simd)
@ -63,30 +96,14 @@ static void *blargg_ntsc_snes_svideo_generic_create(unsigned in_fmt, unsigned ou
free(filt);
return NULL;
}
blargg_ntsc_snes_svideo_initialize(filt);
return filt;
}
static void blargg_ntsc_snes_svideo_initialize(void)
{
snes_ntsc_setup_t setup;
static bool initialized = false;
if(initialized == true)
return;
initialized = true;
ntsc_svideo = (snes_ntsc_t*)malloc(sizeof(*ntsc_svideo));
setup = snes_ntsc_svideo;
setup.merge_fields = 1;
snes_ntsc_init(ntsc_svideo, &setup);
burst_svideo = 0;
burst_toggle_svideo = (setup.merge_fields ? 0 : 1);
}
static void blargg_ntsc_snes_svideo_generic_output(void *data, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height)
{
blargg_ntsc_snes_svideo_initialize();
*out_width = SNES_NTSC_OUT_WIDTH(256);
*out_height = height;
}
@ -95,34 +112,31 @@ static void blargg_ntsc_snes_svideo_generic_destroy(void *data)
{
struct filter_data *filt = (struct filter_data*)data;
if(ntsc_svideo)
free(ntsc_svideo);
if(filt->ntsc)
free(filt->ntsc);
free(filt->workers);
free(filt);
}
static void blargg_ntsc_snes_svideo_render_rgb565(int width, int height,
static void blargg_ntsc_snes_svideo_render_rgb565(void *data, int width, int height,
int first, int last,
uint16_t *input, int pitch, uint16_t *output, int outpitch)
{
blargg_ntsc_snes_svideo_initialize();
if(!ntsc_svideo)
return;
struct filter_data *filt = (struct filter_data*)data;
if(width <= 256)
snes_ntsc_blit(ntsc_svideo, input, pitch, burst_svideo, width, height, output, outpitch * 2, first, last);
snes_ntsc_blit(filt->ntsc, input, pitch, filt->burst, width, height, output, outpitch * 2, first, last);
else
snes_ntsc_blit_hires(ntsc_svideo, input, pitch, burst_svideo, width, height, output, outpitch * 2, first, last);
snes_ntsc_blit_hires(filt->ntsc, input, pitch, filt->burst, width, height, output, outpitch * 2, first, last);
burst_svideo ^= burst_toggle_svideo;
filt->burst ^= filt->burst_toggle;
}
static void blargg_ntsc_snes_svideo_rgb565(unsigned width, unsigned height,
static void blargg_ntsc_snes_svideo_rgb565(void *data, unsigned width, unsigned height,
int first, int last, uint16_t *src,
unsigned src_stride, uint16_t *dst, unsigned dst_stride)
{
blargg_ntsc_snes_svideo_render_rgb565(width, height,
blargg_ntsc_snes_svideo_render_rgb565(data, width, height,
first, last,
src, src_stride,
dst, dst_stride);
@ -137,7 +151,7 @@ static void blargg_ntsc_snes_svideo_work_cb_rgb565(void *data, void *thread_data
unsigned width = thr->width;
unsigned height = thr->height;
blargg_ntsc_snes_svideo_rgb565(width, height,
blargg_ntsc_snes_svideo_rgb565(data, width, height,
thr->first, thr->last, input, thr->in_pitch / SOFTFILTER_BPP_RGB565, output, thr->out_pitch / SOFTFILTER_BPP_RGB565);
}
@ -193,4 +207,6 @@ const struct softfilter_implementation *softfilter_get_implementation(softfilter
#ifdef RARCH_INTERNAL
#undef softfilter_get_implementation
#undef softfilter_thread_data
#undef filter_data
#endif

View File

@ -19,13 +19,34 @@
// Useless filter, just nice as a reference for other filters.
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation darken_get_implementation
#define softfilter_thread_data darken_softfilter_thread_data
#define filter_data darken_filter_data
#endif
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
};
static unsigned darken_input_fmts(void)
{
return SOFTFILTER_FMT_XRGB8888 | SOFTFILTER_FMT_RGB565;
@ -153,4 +174,6 @@ const struct softfilter_implementation *softfilter_get_implementation(softfilter
#ifdef RARCH_INTERNAL
#undef softfilter_get_implementation
#undef softfilter_thread_data
#undef filter_data
#endif

View File

@ -17,15 +17,36 @@
// Compile: gcc -o epx.so -shared epx.c -std=c99 -O3 -Wall -pedantic -fPIC
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation epx_get_implementation
#define softfilter_thread_data epx_softfilter_thread_data
#define filter_data epx_filter_data
#endif
#define EPX_SCALE 2
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
};
static unsigned epx_generic_input_fmts(void)
{
return SOFTFILTER_FMT_RGB565;
@ -405,4 +426,6 @@ const struct softfilter_implementation *softfilter_get_implementation(softfilter
#ifdef RARCH_INTERNAL
#undef softfilter_get_implementation
#undef softfilter_thread_data
#undef filter_data
#endif

View File

@ -17,15 +17,36 @@
// Compile: gcc -o lq2x.so -shared lq2x.c -std=c99 -O3 -Wall -pedantic -fPIC
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation lq2x_get_implementation
#define softfilter_thread_data lq2x_softfilter_thread_data
#define filter_data lq2x_filter_data
#endif
#define LQ2X_SCALE 2
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
};
static unsigned lq2x_generic_input_fmts(void)
{
return SOFTFILTER_FMT_RGB565 | SOFTFILTER_FMT_XRGB8888;

View File

@ -17,7 +17,6 @@
// Compile: gcc -o phosphor2x.so -shared phosphor2x.c -std=c99 -O3 -Wall -pedantic -fPIC
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include "boolean.h"
#include <stdlib.h>
#include <string.h>
@ -25,21 +24,41 @@
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation phosphor2x_get_implementation
#define softfilter_thread_data phosphor2x_softfilter_thread_data
#define filter_data phosphor2x_filter_data
#endif
#define PHOSPHOR2X_SCALE 2
static const float phosphor_bleed = 0.78;
static const float scale_add = 1.0;
static const float scale_times = 0.8;
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
static const float scanrange_low = 0.5;
static const float scanrange_high = 0.65;
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
float phosphor_bleed;
float scale_add;
float scale_times;
float scanrange_low;
float scanrange_high;
float phosphor_bloom_8888[256];
float phosphor_bloom_565[64];
float scan_range_8888[256];
float scan_range_565[64];
};
static float phosphor_bloom_8888[256];
static float scan_range_8888[256];
static float phosphor_bloom_565[64];
static float scan_range_565[64];
#define clamp8(x) ((x) > 255 ? 255 : ((x < 0) ? 0 : (uint32_t)x))
#define clamp6(x) ((x) > 63 ? 63 : ((x < 0) ? 0 : (uint32_t)x))
@ -119,15 +138,16 @@ static void blit_linear_line_rgb565(uint16_t * out, const uint16_t *in, unsigned
out[(width << 1) - 1] = blend_pixels_rgb565(out[(width << 1) - 1], 0);
}
static void bleed_phosphors_xrgb8888(uint32_t *scanline, unsigned width)
static void bleed_phosphors_xrgb8888(void *data, uint32_t *scanline, unsigned width)
{
unsigned x;
struct filter_data *filt = (struct filter_data*)data;
// Red phosphor
for (x = 0; x < width; x += 2)
{
unsigned r = red_xrgb8888(scanline[x]);
unsigned r_set = clamp8(r * phosphor_bleed * phosphor_bloom_8888[r]);
unsigned r_set = clamp8(r * filt->phosphor_bleed * filt->phosphor_bloom_8888[r]);
set_red_xrgb8888(scanline[x + 1], r_set);
}
@ -135,7 +155,7 @@ static void bleed_phosphors_xrgb8888(uint32_t *scanline, unsigned width)
for (x = 0; x < width; x++)
{
unsigned g = green_xrgb8888(scanline[x]);
unsigned g_set = clamp8((g >> 1) + 0.5 * g * phosphor_bleed * phosphor_bloom_8888[g]);
unsigned g_set = clamp8((g >> 1) + 0.5 * g * filt->phosphor_bleed * filt->phosphor_bloom_8888[g]);
set_green_xrgb8888(scanline[x], g_set);
}
@ -144,20 +164,21 @@ static void bleed_phosphors_xrgb8888(uint32_t *scanline, unsigned width)
for (x = 1; x < width; x += 2)
{
unsigned b = blue_xrgb8888(scanline[x]);
unsigned b_set = clamp8(b * phosphor_bleed * phosphor_bloom_8888[b]);
unsigned b_set = clamp8(b * filt->phosphor_bleed * filt->phosphor_bloom_8888[b]);
set_blue_xrgb8888(scanline[x + 1], b_set);
}
}
static void bleed_phosphors_rgb565(uint16_t *scanline, unsigned width)
static void bleed_phosphors_rgb565(void *data, uint16_t *scanline, unsigned width)
{
unsigned x;
struct filter_data *filt = (struct filter_data*)data;
// Red phosphor
for (x = 0; x < width; x += 2)
{
unsigned r = red_rgb565(scanline[x]);
unsigned r_set = clamp6(r * phosphor_bleed * phosphor_bloom_565[r]);
unsigned r_set = clamp6(r * filt->phosphor_bleed * filt->phosphor_bloom_565[r]);
set_red_rgb565(scanline[x + 1], r_set);
}
@ -165,7 +186,7 @@ static void bleed_phosphors_rgb565(uint16_t *scanline, unsigned width)
for (x = 0; x < width; x++)
{
unsigned g = green_rgb565(scanline[x]);
unsigned g_set = clamp6((g >> 1) + 0.5 * g * phosphor_bleed * phosphor_bloom_565[g]);
unsigned g_set = clamp6((g >> 1) + 0.5 * g * filt->phosphor_bleed * filt->phosphor_bloom_565[g]);
set_green_rgb565(scanline[x], g_set);
}
@ -174,35 +195,11 @@ static void bleed_phosphors_rgb565(uint16_t *scanline, unsigned width)
for (x = 1; x < width; x += 2)
{
unsigned b = blue_rgb565(scanline[x]);
unsigned b_set = clamp6(b * phosphor_bleed * phosphor_bloom_565[b]);
unsigned b_set = clamp6(b * filt->phosphor_bleed * filt->phosphor_bloom_565[b]);
set_blue_rgb565(scanline[x + 1], b_set);
}
}
static void stretch_scanline_xrgb8888(const uint32_t * scan_in, uint32_t * scan_out, unsigned width)
{
unsigned x;
for (x = 0; x < width; x++)
{
unsigned max = max_component_xrgb8888(scan_in[x]);
set_red_xrgb8888(scan_out[x], (uint32_t)(scan_range_8888[max] * red_xrgb8888(scan_in[x])));
set_green_xrgb8888(scan_out[x], (uint32_t)(scan_range_8888[max] * green_xrgb8888(scan_in[x])));
set_blue_xrgb8888(scan_out[x], (uint32_t)(scan_range_8888[max] * blue_xrgb8888(scan_in[x])));
}
}
static void stretch_scanline_rgb565(const uint16_t * scan_in, uint16_t * scan_out, unsigned width)
{
unsigned x;
for (x = 0; x < width; x++)
{
unsigned max = max_component_rgb565(scan_in[x]);
set_red_rgb565(scan_out[x], (uint16_t)(scan_range_565[max] * red_rgb565(scan_in[x])));
set_green_rgb565(scan_out[x], (uint16_t)(scan_range_565[max] * green_rgb565(scan_in[x])));
set_blue_rgb565(scan_out[x], (uint16_t)(scan_range_565[max] * blue_rgb565(scan_in[x])));
}
}
static unsigned phosphor2x_generic_input_fmts(void)
{
return SOFTFILTER_FMT_RGB565 | SOFTFILTER_FMT_XRGB8888;
@ -224,8 +221,9 @@ static void *phosphor2x_generic_create(unsigned in_fmt, unsigned out_fmt,
unsigned threads, softfilter_simd_mask_t simd)
{
(void)simd;
unsigned i;
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
if (!filt)
return NULL;
filt->workers = (struct softfilter_thread_data*)calloc(threads, sizeof(struct softfilter_thread_data));
@ -236,6 +234,27 @@ static void *phosphor2x_generic_create(unsigned in_fmt, unsigned out_fmt,
free(filt);
return NULL;
}
filt->phosphor_bleed = 0.78;
filt->scale_add = 1.0;
filt->scale_times = 0.8;
filt->scanrange_low = 0.5;
filt->scanrange_high = 0.65;
// Init lookup tables:
// phosphorBloom = (scaleTimes .* linspace(0, 1, 255) .^ (1/2.2)) + scaleAdd;
// Not exactly sure of order of operations here ...
for (i = 0; i < 256; i++)
{
filt->phosphor_bloom_8888[i] = filt->scale_times * powf((float)i / 255.0f, 1.0f/2.2f) + filt->scale_add;
filt->scan_range_8888[i] = filt->scanrange_low + i * (filt->scanrange_high - filt->scanrange_low) / 255.0f;
}
for (i = 0; i < 64; i++)
{
filt->phosphor_bloom_565[i] = filt->scale_times * powf((float)i / 31.0f, 1.0f/2.2f) + filt->scale_add;
filt->scan_range_565[i] = filt->scanrange_low + i * (filt->scanrange_high - filt->scanrange_low) / 31.0f;
}
return filt;
}
@ -253,71 +272,70 @@ static void phosphor2x_generic_destroy(void *data)
free(filt);
}
static void phosphor2x_generic_xrgb8888(unsigned width, unsigned height,
static void phosphor2x_generic_xrgb8888(void *data, unsigned width, unsigned height,
int first, int last, uint32_t *src,
unsigned src_stride, uint32_t *dst, unsigned dst_stride)
{
unsigned y;
static bool filter_inited = false;
if (!filter_inited)
{
unsigned i;
// Init lookup tables:
// phosphorBloom = (scaleTimes .* linspace(0, 1, 255) .^ (1/2.2)) + scaleAdd;
// Not exactly sure of order of operations here ...
for (i = 0; i < 256; i++)
{
phosphor_bloom_8888[i] = scale_times * powf((float)i / 255.0f, 1.0f/2.2f) + scale_add;
scan_range_8888[i] = scanrange_low + i * (scanrange_high - scanrange_low) / 255.0f;
}
filter_inited = true;
}
struct filter_data *filt = (struct filter_data*)data;
memset(dst, 0, height * dst_stride);
for (y = 0; y < height; y++)
{
uint32_t *out_line = (uint32_t*)(dst + y * (dst_stride) * 2); // Output in a scanlines fashion.
uint32_t *out_line, *scan_out;
unsigned x;
const uint32_t *in_line = (const uint32_t*)(src + y * (src_stride)); // Input
blit_linear_line_xrgb8888(out_line, in_line, width); // Bilinear stretch horizontally.
bleed_phosphors_xrgb8888(out_line, width << 1); // Mask 'n bleed phosphors.
stretch_scanline_xrgb8888(out_line, out_line + (dst_stride), width << 1); // Apply scanlines.
out_line = (uint32_t*)(dst + y * (dst_stride) * 2); // Output in a scanlines fashion.
blit_linear_line_xrgb8888(out_line, in_line, width); // Bilinear stretch horizontally.
bleed_phosphors_xrgb8888(filt, out_line, width << 1); // Mask 'n bleed phosphors.
// Apply scanlines
scan_out = (uint32_t*)out_line + (dst_stride);
for (x = 0; x < (width << 1); x++)
{
unsigned max = max_component_xrgb8888(out_line[x]);
set_red_xrgb8888(scan_out[x], (uint32_t)(filt->scan_range_8888[max] * red_xrgb8888(out_line[x])));
set_green_xrgb8888(scan_out[x], (uint32_t)(filt->scan_range_8888[max] * green_xrgb8888(out_line[x])));
set_blue_xrgb8888(scan_out[x], (uint32_t)(filt->scan_range_8888[max] * blue_xrgb8888(out_line[x])));
}
}
}
static void phosphor2x_generic_rgb565(unsigned width, unsigned height,
static void phosphor2x_generic_rgb565(void *data, unsigned width, unsigned height,
int first, int last, uint16_t *src,
unsigned src_stride, uint16_t *dst, unsigned dst_stride)
{
unsigned y;
static bool filter_inited = false;
if (!filter_inited)
{
unsigned i;
// Init lookup tables:
// phosphorBloom = (scaleTimes .* linspace(0, 1, 255) .^ (1/2.2)) + scaleAdd;
// Not exactly sure of order of operations here ...
for (i = 0; i < 64; i++)
{
phosphor_bloom_565[i] = scale_times * powf((float)i / 31.0f, 1.0f/2.2f) + scale_add;
scan_range_565[i] = scanrange_low + i * (scanrange_high - scanrange_low) / 31.0f;
}
filter_inited = true;
}
struct filter_data *filt = (struct filter_data*)data;
memset(dst, 0, height * dst_stride);
for (y = 0; y < height; y++)
{
uint16_t *scan_out;
unsigned x;
uint16_t *out_line = (uint16_t*)(dst + y * (dst_stride) * 2); // Output in a scanlines fashion.
const uint16_t *in_line = (const uint16_t*)(src + y * (src_stride)); // Input
blit_linear_line_rgb565(out_line, in_line, width); // Bilinear stretch horizontally.
bleed_phosphors_rgb565(out_line, width << 1); // Mask 'n bleed phosphors.
stretch_scanline_rgb565(out_line, out_line + (dst_stride), width << 1); // Apply scanlines.
blit_linear_line_rgb565(out_line, in_line, width); // Bilinear stretch horizontally.
bleed_phosphors_rgb565(filt, out_line, width << 1); // Mask 'n bleed phosphors.
// Apply scanlines.
scan_out = (uint16_t*)(out_line + (dst_stride));
for (x = 0; x < (width << 1); x++)
{
unsigned max = max_component_rgb565(out_line[x]);
set_red_rgb565(scan_out[x], (uint16_t)(filt->scan_range_565[max] * red_rgb565(out_line[x])));
set_green_rgb565(scan_out[x], (uint16_t)(filt->scan_range_565[max] * green_rgb565(out_line[x])));
set_blue_rgb565(scan_out[x], (uint16_t)(filt->scan_range_565[max] * blue_rgb565(out_line[x])));
}
}
}
@ -329,7 +347,7 @@ static void phosphor2x_work_cb_xrgb8888(void *data, void *thread_data)
unsigned width = thr->width;
unsigned height = thr->height;
phosphor2x_generic_xrgb8888(width, height,
phosphor2x_generic_xrgb8888(data, width, height,
thr->first, thr->last, input, thr->in_pitch / SOFTFILTER_BPP_XRGB8888, output, thr->out_pitch / SOFTFILTER_BPP_XRGB8888);
}
@ -341,7 +359,7 @@ static void phosphor2x_work_cb_rgb565(void *data, void *thread_data)
unsigned width = thr->width;
unsigned height = thr->height;
phosphor2x_generic_rgb565(width, height,
phosphor2x_generic_rgb565(data, width, height,
thr->first, thr->last, input, thr->in_pitch / SOFTFILTER_BPP_RGB565, output, thr->out_pitch / SOFTFILTER_BPP_RGB565);
}
@ -401,4 +419,6 @@ const struct softfilter_implementation *softfilter_get_implementation(softfilter
#ifdef RARCH_INTERNAL
#undef softfilter_get_implementation
#undef softfilter_thread_data
#undef filter_data
#endif

View File

@ -17,15 +17,36 @@
// Compile: gcc -o scale2x.so -shared scale2x.c -std=c99 -O3 -Wall -pedantic -fPIC
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation scale2x_get_implementation
#define softfilter_thread_data scale2x_softfilter_thread_data
#define filter_data scale2x_filter_data
#endif
#define SCALE2X_SCALE 2
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
};
#define SCALE2X_GENERIC(typename_t, width, height, first, last, src, src_stride, dst, dst_stride, out0, out1) \
for (y = 0; y < height; ++y) \
{ \
@ -213,4 +234,6 @@ const struct softfilter_implementation *softfilter_get_implementation(softfilter
#ifdef RARCH_INTERNAL
#undef softfilter_get_implementation
#undef softfilter_thread_data
#undef filter_data
#endif

View File

@ -1,39 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _RARCH_SOFTFILTER_PROTOTYPES_H
#define _RARCH_SOFTFILTER_PROTOTYPES_H
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
};
#endif

View File

@ -17,15 +17,36 @@
// Compile: gcc -o supertwoxsai.so -shared supertwoxsai.c -std=c99 -O3 -Wall -pedantic -fPIC
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation supertwoxsai_get_implementation
#define softfilter_thread_data supertwoxsai_softfilter_thread_data
#define filter_data supertwoxsai_filter_data
#endif
#define SUPERTWOXSAI_SCALE 2
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
};
static unsigned supertwoxsai_generic_input_fmts(void)
{
return SOFTFILTER_FMT_RGB565 | SOFTFILTER_FMT_XRGB8888;

View File

@ -17,15 +17,36 @@
// Compile: gcc -o supereagle.so -shared supereagle.c -std=c99 -O3 -Wall -pedantic -fPIC
#include "softfilter.h"
#include "softfilter_prototypes.h"
#include <stdlib.h>
#ifdef RARCH_INTERNAL
#define softfilter_get_implementation supereagle_get_implementation
#define softfilter_thread_data supereagle_softfilter_thread_data
#define filter_data supereagle_filter_data
#endif
#define SUPEREAGLE_SCALE 2
struct softfilter_thread_data
{
void *out_data;
const void *in_data;
size_t out_pitch;
size_t in_pitch;
unsigned colfmt;
unsigned width;
unsigned height;
int first;
int last;
};
struct filter_data
{
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
};
static unsigned supereagle_generic_input_fmts(void)
{
return SOFTFILTER_FMT_RGB565 | SOFTFILTER_FMT_XRGB8888;
@ -313,4 +334,6 @@ const struct softfilter_implementation *softfilter_get_implementation(softfilter
#ifdef RARCH_INTERNAL
#undef softfilter_get_implementation
#undef softfilter_thread_data
#undef filter_data
#endif