Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/gpgx/core/ntsc/sms_ntsc.txt
2 views
1
sms_ntsc 0.2.3: Sega Master System NTSC Video Filter
2
----------------------------------------------------
3
Author : Shay Green <[email protected]>
4
Website : http://www.slack.net/~ant/
5
Forum : http://groups.google.com/group/blargg-sound-libs
6
License : GNU Lesser General Public License (LGPL)
7
Language: C or C++
8
9
10
Overview
11
--------
12
To perform NTSC filtering, first allocate memory for a sms_ntsc_t object
13
and call sms_ntsc_init(), then call sms_ntsc_blit() to perform
14
filtering. You can call sms_ntsc_init() at any time to change image
15
parameters.
16
17
By default, sms_ntsc_blit() reads and writes pixels in 16-bit RGB. Edit
18
sms_ntsc_config.h to change this.
19
20
21
RGB Palette Generation
22
----------------------
23
A 4096-color RGB palette can be generated for use in a normal blitter.
24
In your sms_ntsc_setup_t structure, point palette_out to a 12288-byte
25
buffer (4096 * 3) to hold the palette, then call sms_ntsc_init(). If you
26
only need the palette and aren't going to be using the NTSC blitter,
27
pass 0 for the first parameter.
28
29
30
Image Parameters
31
----------------
32
Many image parameters can be adjusted and presets are provided for
33
composite video, S-video, RGB, and monochrome. Most are floating-point
34
values with a general range of -1.0 to 1.0, where 0 is normal. The
35
ranges are adjusted so that one parameter at an extreme (-1 or +1) and
36
the rest at zero shouldn't result in any internal overflow (garbage
37
pixels). Setting multiple parameters to their extreme can produce
38
garbage. Put another way, the state space defined by all parameters
39
within the range -1 to +1 is not fully usable, but some extreme corners
40
are very useful so I don't want to reduce the parameter ranges.
41
42
The sharpness and resolution parameters have similar effects. Resolution
43
affects how crisp pixels are. Sharpness merely enhances the edges by
44
increasing contrast, which makes things brighter at the edges. Artifacts
45
sets how much "junk" is around the edges where colors and brightness
46
change in the image, where -1 completely eliminates them. (Color) bleed
47
affects how much colors blend together and the artifact colors at the
48
edges of pixels surrounded by black. (Color) fringing affects how much
49
color fringing occurs around the edges of bright objects, especially
50
white text on a black background.
51
52
When using custom settings, initialize your sms_ntsc_setup_t using one
53
of the standard setups before customizing it. This will ensure that all
54
fields are properly initialized, including any added in future releases
55
of the library that your current code can't even know about.
56
57
sms_ntsc_setup_t setup;
58
setup = sms_ntsc_composite; /* do this first */
59
setup.sharpness = custom_sharpness;
60
sms_ntsc_init( ntsc, &setup );
61
62
63
Image Size
64
----------
65
For proper aspect ratio, the image generated by the library must be
66
doubled vertically.
67
68
Use the SMS_NTSC_OUT_WIDTH() and SMS_NTSC_IN_WIDTH() macros to convert
69
between input and output widths that the blitter uses. For example, if
70
you are blitting an image 256 pixels wide, use SMS_NTSC_OUT_WIDTH( 256 )
71
to find out how many output pixels are written per row. Another example,
72
use SMS_NTSC_IN_WIDTH( 640 ) to find how many input pixels will fit
73
within 640 output pixels.
74
75
76
Custom Blitter
77
--------------
78
You can write your own blitter, allowing customization of how input
79
pixels are obtained, the format of output pixels (15, 16, or 32-bit
80
RGB), optimizations for your platform, and additional effects like
81
efficient scanline doubling during blitting.
82
83
Macros are included in sms_ntsc.h for writing your blitter so that your
84
code can be carried over without changes to improved versions of the
85
library. The default blitter at the end of sms_ntsc.c shows how to use
86
the macros. Contact me for further assistance.
87
88
The SMS_NTSC_BEGIN_ROW macro allows starting up to three pixels. The
89
first pixel is cut off; its use is in specifying a background color
90
other than black for the sliver on the left edge. The next two pixels
91
can be used to handle the extra one or two pixels not handled by the
92
main chunks of three pixels. For example if you want to blit 257 input
93
pixels on a row (for whatever odd reason), you would start the first two
94
with SMS_NTSC_BEGIN_ROW( ... sms_ntsc_black, line_in [0], line_in [1] ),
95
then do the remaining 255 in chunks of three (255 is divisible by 3).
96
97
98
Limitations
99
-----------
100
The library's horizontal rescaling is too wide by about 3% in order to
101
allow a much more optimal implementation. This means that a 248 pixel
102
wide input image should appear as 563 output pixels, but with this
103
library appears as 581 output pixels. TV aspect ratios probably vary by
104
this much anyway. If you really need unscaled output, contact me and
105
I'll see about adding it.
106
107
108
Thanks
109
------
110
Thanks to NewRisingSun for his original code and explanations of NTSC,
111
which was a starting point for me learning about NTSC video and
112
decoding. Thanks to the Nesdev forum for feedback and encouragement.
113
Thanks to Martin Freij (Nestopia author) and Charles MacDonald (SMS Plus
114
author) for significant ongoing testing and feedback as the library has
115
improved. Thanks to byuu (bsnes author) and pagefault (ZSNES team) for
116
feedback about the SNES version.
117
118
--
119
Shay Green <[email protected]>
120
121