Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/genplus-gx/core/ntsc/md_ntsc.c
2 views
1
/* md_ntsc 0.1.2. http://www.slack.net/~ant/ */
2
3
/* Modified for use with Genesis Plus GX -- EkeEke */
4
5
#include "shared.h"
6
#include "md_ntsc.h"
7
8
/* Copyright (C) 2006 Shay Green. This module is free software; you
9
can redistribute it and/or modify it under the terms of the GNU Lesser
10
General Public License as published by the Free Software Foundation; either
11
version 2.1 of the License, or (at your option) any later version. This
12
module is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15
details. You should have received a copy of the GNU Lesser General Public
16
License along with this module; if not, write to the Free Software Foundation,
17
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
18
19
md_ntsc_setup_t const md_ntsc_monochrome = { 0,-1, 0, 0,.2, 0, 0,-.2,-.2,-1, 0, 0 };
20
md_ntsc_setup_t const md_ntsc_composite = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
21
md_ntsc_setup_t const md_ntsc_svideo = { 0, 0, 0, 0, 0, 0,.2, -1, -1, 0, 0, 0 };
22
md_ntsc_setup_t const md_ntsc_rgb = { 0, 0, 0, 0,.2, 0,.7, -1, -1,-1, 0, 0 };
23
24
#define alignment_count 2
25
#define burst_count 1
26
#define rescale_in 1
27
#define rescale_out 1
28
29
#define artifacts_mid 0.40f
30
#define fringing_mid 0.30f
31
#define std_decoder_hue 0
32
33
#define gamma_size 8
34
#define artifacts_max 1.00f
35
#define LUMA_CUTOFF 0.1974
36
37
#include "md_ntsc_impl.h"
38
39
/* 2 input pixels -> 4 composite samples */
40
pixel_info_t const md_ntsc_pixels [alignment_count] = {
41
{ PIXEL_OFFSET( -4, -9 ), { 0.1f, 0.9f, 0.9f, 0.1f } },
42
{ PIXEL_OFFSET( -2, -7 ), { 0.1f, 0.9f, 0.9f, 0.1f } },
43
};
44
45
static void correct_errors( md_ntsc_rgb_t color, md_ntsc_rgb_t* out )
46
{
47
unsigned i;
48
for ( i = 0; i < rgb_kernel_size / 4; i++ )
49
{
50
md_ntsc_rgb_t error = color -
51
out [i ] - out [i + 2 +16] - out [i + 4 ] - out [i + 6 +16] -
52
out [i + 8] - out [(i+10)%16+16] - out [(i+12)%16] - out [(i+14)%16+16];
53
CORRECT_ERROR( i + 6 + 16 );
54
/*DISTRIBUTE_ERROR( 2+16, 4, 6+16 );*/
55
}
56
}
57
58
void md_ntsc_init( md_ntsc_t* ntsc, md_ntsc_setup_t const* setup )
59
{
60
int entry;
61
init_t impl;
62
if ( !setup )
63
setup = &md_ntsc_composite;
64
init( &impl, setup );
65
66
for ( entry = 0; entry < md_ntsc_palette_size; entry++ )
67
{
68
float bb = impl.to_float [entry >> 6 & 7];
69
float gg = impl.to_float [entry >> 3 & 7];
70
float rr = impl.to_float [entry & 7];
71
72
float y, i, q = RGB_TO_YIQ( rr, gg, bb, y, i );
73
74
int r, g, b = YIQ_TO_RGB( y, i, q, impl.to_rgb, int, r, g );
75
md_ntsc_rgb_t rgb = PACK_RGB( r, g, b );
76
77
if ( setup->palette_out )
78
RGB_PALETTE_OUT( rgb, &setup->palette_out [entry * 3] );
79
80
if ( ntsc )
81
{
82
gen_kernel( &impl, y, i, q, ntsc->table [entry] );
83
correct_errors( rgb, ntsc->table [entry] );
84
}
85
}
86
}
87
88
#ifndef CUSTOM_BLITTER
89
void md_ntsc_blit( md_ntsc_t const* ntsc, MD_NTSC_IN_T const* table, unsigned char* input,
90
int in_width, int vline)
91
{
92
int const chunk_count = in_width / md_ntsc_in_chunk - 1;
93
94
/* use palette entry 0 for unused pixels */
95
MD_NTSC_IN_T border = table[0];
96
97
MD_NTSC_BEGIN_ROW( ntsc, border,
98
MD_NTSC_ADJ_IN( table[*input++] ),
99
MD_NTSC_ADJ_IN( table[*input++] ),
100
MD_NTSC_ADJ_IN( table[*input++] ) );
101
102
md_ntsc_out_t* restrict line_out = (md_ntsc_out_t*)(&bitmap.data[(vline * bitmap.pitch)]);
103
104
int n;
105
106
for ( n = chunk_count; n; --n )
107
{
108
/* order of input and output pixels must not be altered */
109
MD_NTSC_COLOR_IN( 0, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) );
110
MD_NTSC_RGB_OUT( 0, *line_out++ );
111
MD_NTSC_RGB_OUT( 1, *line_out++ );
112
113
MD_NTSC_COLOR_IN( 1, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) );
114
MD_NTSC_RGB_OUT( 2, *line_out++ );
115
MD_NTSC_RGB_OUT( 3, *line_out++ );
116
117
MD_NTSC_COLOR_IN( 2, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) );
118
MD_NTSC_RGB_OUT( 4, *line_out++ );
119
MD_NTSC_RGB_OUT( 5, *line_out++ );
120
121
MD_NTSC_COLOR_IN( 3, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) );
122
MD_NTSC_RGB_OUT( 6, *line_out++ );
123
MD_NTSC_RGB_OUT( 7, *line_out++ );
124
}
125
126
/* finish final pixels */
127
MD_NTSC_COLOR_IN( 0, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) );
128
MD_NTSC_RGB_OUT( 0, *line_out++ );
129
MD_NTSC_RGB_OUT( 1, *line_out++ );
130
131
MD_NTSC_COLOR_IN( 1, ntsc, border );
132
MD_NTSC_RGB_OUT( 2, *line_out++ );
133
MD_NTSC_RGB_OUT( 3, *line_out++ );
134
135
MD_NTSC_COLOR_IN( 2, ntsc, border );
136
MD_NTSC_RGB_OUT( 4, *line_out++ );
137
MD_NTSC_RGB_OUT( 5, *line_out++ );
138
139
MD_NTSC_COLOR_IN( 3, ntsc, border );
140
MD_NTSC_RGB_OUT( 6, *line_out++ );
141
MD_NTSC_RGB_OUT( 7, *line_out++ );
142
}
143
#endif
144
145