2 #ifndef __BLARGG_SNES_NTSC_IMPLEMENTATION_H 3 #define __BLARGG_SNES_NTSC_IMPLEMENTATION_H 21 #define DISABLE_CORRECTION 0 24 #define PI 3.14159265358979323846f 27 #define LUMA_CUTOFF 0.20 36 #define artifacts_max (artifacts_mid * 1.5f) 39 #define fringing_max (fringing_mid * 2) 41 #ifndef STD_HUE_CONDITION 42 #define STD_HUE_CONDITION( setup ) 1 45 #define ext_decoder_hue (std_decoder_hue + 15) 46 #define rgb_unit (1 << rgb_bits) 47 #define rgb_offset (rgb_unit * 2 + 0.5f) 64 #define ROTATE_IQ( i, q, sin_b, cos_b ) {\ 66 t = i * cos_b - q * sin_b;\ 67 q = i * sin_b + q * cos_b;\ 76 float*
const kernels = impl->
kernel;
82 float const rolloff = 1 + (float)
setup->sharpness * (
float) 0.032;
83 float const maxh = 32;
84 float const pow_a_n = (float)
pow( rolloff, maxh );
88 float to_angle = (float)
setup->resolution + 1;
89 to_angle =
PI / maxh * (
float)
LUMA_CUTOFF * (to_angle * to_angle + 1);
95 float angle =
x * to_angle;
97 if (
x || pow_a_n > (
float) 1.056 || pow_a_n < (float) 0.981 )
99 float rolloff_cos_a = rolloff * (float)
cos(
angle );
100 float num = 1 - rolloff_cos_a -
101 pow_a_n * (float)
cos( maxh *
angle ) +
102 pow_a_n * rolloff * (float)
cos( (maxh - 1) *
angle );
103 float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff;
104 float dsf =
num / den;
114 float blackman = 0.42f - 0.5f * (float)
cos(
x ) + 0.08f * (float)
cos(
x * 2 );
130 float const cutoff_factor = -0.03125f;
131 float cutoff = (float)
setup->bleed;
140 cutoff *= -30.0f / 0.65f;
142 cutoff = cutoff_factor - 0.65f * cutoff_factor * cutoff;
148 for ( i = 0; i < 2; i++ )
186 float cur = kernels [i];
198 { 0.956f, 0.621f, -0.272f, -0.647f, -1.105f, 1.702f };
204 #ifdef default_palette_contrast 205 if ( !
setup->palette )
206 impl->
contrast *= default_palette_contrast;
225 float const gamma = 1.1333f - (float)
setup->gamma * 0.5f;
236 float sat = (
float)
setup->saturation + 1;
237 float const* decoder =
setup->decoder_matrix;
246 float s = (float)
sin( hue ) * sat;
247 float c = (float)
cos( hue ) * sat;
254 float const*
in = decoder;
275 #define RGB_TO_YIQ( r, g, b, y, i ) (\ 276 (y = (r) * 0.299f + (g) * 0.587f + (b) * 0.114f),\ 277 (i = (r) * 0.596f - (g) * 0.275f - (b) * 0.321f),\ 278 ((r) * 0.212f - (g) * 0.523f + (b) * 0.311f)\ 281 #define YIQ_TO_RGB( y, i, q, to_rgb, type, r, g ) (\ 282 r = (type) (y + to_rgb [0] * i + to_rgb [1] * q),\ 283 g = (type) (y + to_rgb [2] * i + to_rgb [3] * q),\ 284 (type) (y + to_rgb [4] * i + to_rgb [5] * q)\ 287 #define PACK_RGB( r, g, b ) ((r) << 21 | (g) << 11 | (b) << 1) 300 #define PIXEL_OFFSET_( ntsc, scaled ) \ 301 (kernel_size / 2 + ntsc + (scaled != 0) + (rescale_out - scaled) % rescale_out + \ 302 (kernel_size * 2 * scaled)) 304 #define PIXEL_OFFSET( ntsc, scaled ) \ 305 PIXEL_OFFSET_( ((ntsc) - (scaled) / rescale_out * rescale_in),\ 306 (((scaled) + rescale_out * 10) % rescale_out) ),\ 307 (1.0f - (((ntsc) + 100) & 2)) 309 #define PIXEL_OFFSET( ntsc, scaled ) \ 310 (kernel_size / 2 + (ntsc) - (scaled)),\ 311 (1.0f - (((ntsc) + 100) & 2)) 320 float const* to_rgb = impl->
to_rgb;
335 float const ic0 = (i + yy) * pixel->
kernel [0];
336 float const qc1 = (
q + yy) * pixel->
kernel [1];
337 float const ic2 = (i - yy) * pixel->
kernel [2];
338 float const qc3 = (
q - yy) * pixel->
kernel [3];
341 float const ii = i * factor;
342 float const yc0 = (
y + ii) * pixel->
kernel [0];
343 float const yc2 = (
y - ii) * pixel->
kernel [2];
345 float const qq =
q * factor;
346 float const yc1 = (
y + qq) * pixel->
kernel [1];
347 float const yc3 = (
y - qq) * pixel->
kernel [3];
354 float i = k[0]*ic0 + k[2]*ic2;
355 float q = k[1]*qc1 + k[3]*qc3;
379 while ( --burst_remain );
384 #if DISABLE_CORRECTION 385 #define CORRECT_ERROR( a ) { out [i] += rgb_bias; } 386 #define DISTRIBUTE_ERROR( a, b, c ) { out [i] += rgb_bias; } 388 #define CORRECT_ERROR( a ) { out [a] += error; } 389 #define DISTRIBUTE_ERROR( a, b, c ) {\ 390 snes_ntsc_rgb_t fourth = (error + 2 * snes_ntsc_rgb_builder) >> 2;\ 391 fourth &= (rgb_bias >> 1) - snes_ntsc_rgb_builder;\ 392 fourth -= rgb_bias >> 2;\ 396 out [i] += error - (fourth * 3);\ 400 #define RGB_PALETTE_OUT( rgb, out_ )\ 402 unsigned char* out = (out_);\ 403 snes_ntsc_rgb_t clamped = (rgb);\ 404 SNES_NTSC_CLAMP_( clamped, (8 - rgb_bits) );\ 405 out [0] = (unsigned char) (clamped >> 21);\ 406 out [1] = (unsigned char) (clamped >> 11);\ 407 out [2] = (unsigned char) (clamped >> 1);\ 413 #if defined (__GNUC__) 414 #define restrict __restrict__ 415 #elif defined (_MSC_VER) && _MSC_VER > 1300 416 #define restrict __restrict 425 #if SNES_NTSC_OUT_DEPTH <= 16 426 #if USHRT_MAX == 0xFFFF 427 typedef unsigned short snes_ntsc_out_t;
429 #error "Need 16-bit int type" 433 #if UINT_MAX == 0xFFFFFFFF 434 typedef unsigned int snes_ntsc_out_t;
435 #elif ULONG_MAX == 0xFFFFFFFF 436 typedef unsigned long snes_ntsc_out_t;
438 #error "Need 32-bit int type" float fringing
Definition: snes_ntsc_impl.h:60
Definition: snes_ntsc_impl.h:51
#define burst_count
Definition: snes_ntsc.c:24
unsigned long snes_ntsc_rgb_t
Definition: snes_ntsc.h:136
Definition: snes_ntsc_impl.h:292
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
static overlayled_t * cur
Definition: led_overlay.c:18
GLfloat f
Definition: glext.h:8207
GLfloat angle
Definition: glext.h:11760
GLdouble s
Definition: glext.h:6390
struct passwd out
Definition: missing_libc_functions.c:51
#define snes_ntsc_rgb_builder
Definition: snes_ntsc.h:171
#define exp(a)
Definition: math.h:32
static void correct_errors(snes_ntsc_rgb_t color, snes_ntsc_rgb_t *out)
#define PI
Definition: snes_ntsc_impl.h:24
#define YIQ_TO_RGB(y, i, q, to_rgb, type, r, g)
Definition: snes_ntsc_impl.h:281
GLuint GLuint GLfloat weight
Definition: glext.h:12626
#define ext_decoder_hue
Definition: snes_ntsc_impl.h:45
Definition: snes_ntsc.h:15
const GLubyte * c
Definition: glext.h:9812
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
GLuint GLuint num
Definition: glext.h:10525
float contrast
Definition: snes_ntsc_impl.h:57
Definition: snes_ntsc.h:134
#define std_decoder_hue
Definition: snes_ntsc.c:30
Definition: snes_ntsc_impl.h:289
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Definition: pixman-arm-neon-asm.h:469
Definition: snes_ntsc_impl.h:53
#define alignment_count
Definition: snes_ntsc.c:23
#define fringing_max
Definition: snes_ntsc_impl.h:39
float artifacts
Definition: snes_ntsc_impl.h:59
#define artifacts_mid
Definition: snes_ntsc.c:28
int offset
Definition: snes_ntsc_impl.h:294
struct pixel_info_t pixel_info_t
#define gamma_size
Definition: snes_ntsc_impl.h:30
pixel_info_t const snes_ntsc_pixels[alignment_count]
Definition: snes_ntsc.c:38
GLint GLint GLint GLint GLint GLint y
Definition: glext.h:6295
#define artifacts_max
Definition: snes_ntsc_impl.h:36
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
GLuint in
Definition: glext.h:10523
#define rgb_offset
Definition: snes_ntsc_impl.h:47
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:6414
#define retro_assert(cond)
Definition: retro_assert.h:34
#define PACK_RGB(r, g, b)
Definition: snes_ntsc_impl.h:287
float to_float[gamma_size]
Definition: snes_ntsc_impl.h:56
static void init(init_t *impl, snes_ntsc_setup_t const *setup)
Definition: snes_ntsc_impl.h:200
float kernel[rescale_out *kernel_size *2]
Definition: snes_ntsc_impl.h:61
#define rescale_out
Definition: snes_ntsc.c:26
#define sin(x)
Definition: math.h:23
Definition: snes_ntsc_impl.h:49
#define pow(x, y)
Definition: math.h:22
static float const default_decoder[6]
Definition: snes_ntsc_impl.h:197
float kernel[4]
Definition: snes_ntsc_impl.h:296
#define rgb_unit
Definition: snes_ntsc_impl.h:46
Definition: snes_ntsc_impl.h:50
float brightness
Definition: snes_ntsc_impl.h:58
GLboolean GLboolean g
Definition: glext.h:6844
GLuint color
Definition: glext.h:6883
static void gen_kernel(init_t *impl, float y, float i, float q, snes_ntsc_rgb_t *out)
Definition: snes_ntsc_impl.h:317
#define ROTATE_IQ(i, q, sin_b, cos_b)
Definition: snes_ntsc_impl.h:64
#define fringing_mid
Definition: snes_ntsc.c:29
#define cos(x)
Definition: math.h:21
#define STD_HUE_CONDITION(setup)
Definition: snes_ntsc_impl.h:42
float negate
Definition: snes_ntsc_impl.h:295
#define LUMA_CUTOFF
Definition: snes_ntsc_impl.h:27
static void init_filters(init_t *impl, snes_ntsc_setup_t const *setup)
Definition: snes_ntsc_impl.h:71
float to_rgb[burst_count *6]
Definition: snes_ntsc_impl.h:55
#define rescale_in
Definition: snes_ntsc.c:25
GLdouble n
Definition: glext.h:8396
const GLfloat * m
Definition: glext.h:11755
Definition: snes_ntsc_impl.h:290