mirror of https://github.com/stella-emu/stella.git
Code cleanups, commenting fixes, etc for Blargg-related code.
This commit is contained in:
parent
6da07d8dc7
commit
ea59fdd3f2
|
@ -66,7 +66,7 @@ void AtariNTSC::initializePalette(const uInt8* palette)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void AtariNTSC::blitSingle(const uInt8* atari_in, uInt32 in_width,
|
void AtariNTSC::render(const uInt8* atari_in, uInt32 in_width,
|
||||||
uInt32 in_height, void* rgb_out, uInt32 out_pitch)
|
uInt32 in_height, void* rgb_out, uInt32 out_pitch)
|
||||||
{
|
{
|
||||||
uInt32 const chunk_count = (in_width - 1) / PIXEL_in_chunk;
|
uInt32 const chunk_count = (in_width - 1) / PIXEL_in_chunk;
|
||||||
|
@ -146,14 +146,8 @@ void AtariNTSC::init(init_t& impl, const Setup& setup)
|
||||||
{
|
{
|
||||||
float hue = float(setup.hue) * PI + PI / 180 * ext_decoder_hue;
|
float hue = float(setup.hue) * PI + PI / 180 * ext_decoder_hue;
|
||||||
float sat = float(setup.saturation) + 1;
|
float sat = float(setup.saturation) + 1;
|
||||||
float const* decoder = setup.decoder_matrix;
|
|
||||||
if ( !decoder )
|
|
||||||
{
|
|
||||||
decoder = default_decoder;
|
|
||||||
hue += PI / 180 * (std_decoder_hue - ext_decoder_hue);
|
hue += PI / 180 * (std_decoder_hue - ext_decoder_hue);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
float s = float(sin( hue )) * sat;
|
float s = float(sin( hue )) * sat;
|
||||||
float c = float(cos( hue )) * sat;
|
float c = float(cos( hue )) * sat;
|
||||||
float* out = impl.to_rgb;
|
float* out = impl.to_rgb;
|
||||||
|
@ -162,7 +156,7 @@ void AtariNTSC::init(init_t& impl, const Setup& setup)
|
||||||
n = burst_count;
|
n = burst_count;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
float const* in = decoder;
|
float const* in = default_decoder;
|
||||||
int n2 = 3;
|
int n2 = 3;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -178,7 +172,6 @@ void AtariNTSC::init(init_t& impl, const Setup& setup)
|
||||||
}
|
}
|
||||||
while ( --n );
|
while ( --n );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -343,31 +336,22 @@ void AtariNTSC::genKernel(init_t& impl, float y, float i, float q, uInt32* out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ( alignment_count > 1 && --alignment_remain );
|
while ( alignment_count > 1 && --alignment_remain );
|
||||||
|
|
||||||
#if 0 // FIXME: dead code detected by Xcode
|
|
||||||
if ( burst_count <= 1 )
|
|
||||||
break;
|
|
||||||
|
|
||||||
to_rgb += 6;
|
|
||||||
|
|
||||||
ROTATE_IQ( i, q, -0.866025f, -0.5f ); /* -120 degrees */
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
while ( --burst_remain );
|
while ( --burst_remain );
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
const AtariNTSC::Setup AtariNTSC::TV_Composite = {
|
const AtariNTSC::Setup AtariNTSC::TV_Composite = {
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.15, 0.0, 0.0, 0.0, 0
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.15, 0.0, 0.0, 0.0
|
||||||
};
|
};
|
||||||
const AtariNTSC::Setup AtariNTSC::TV_SVideo = {
|
const AtariNTSC::Setup AtariNTSC::TV_SVideo = {
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.45, -1.0, -1.0, 0.0, 0
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.45, -1.0, -1.0, 0.0
|
||||||
};
|
};
|
||||||
const AtariNTSC::Setup AtariNTSC::TV_RGB = {
|
const AtariNTSC::Setup AtariNTSC::TV_RGB = {
|
||||||
0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.70, -1.0, -1.0, -1.0, 0
|
0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.70, -1.0, -1.0, -1.0
|
||||||
};
|
};
|
||||||
const AtariNTSC::Setup AtariNTSC::TV_Bad = {
|
const AtariNTSC::Setup AtariNTSC::TV_Bad = {
|
||||||
0.1, -0.3, 0.3, 0.25, 0.2, 0.0, 0.1, 0.5, 0.5, 0.5, 0
|
0.1, -0.3, 0.3, 0.25, 0.2, 0.0, 0.1, 0.5, 0.5, 0.5
|
||||||
};
|
};
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -53,7 +53,7 @@ class AtariNTSC
|
||||||
|
|
||||||
// Image parameters, ranging from -1.0 to 1.0. Actual internal values shown
|
// Image parameters, ranging from -1.0 to 1.0. Actual internal values shown
|
||||||
// in parenthesis and should remain fairly stable in future versions.
|
// in parenthesis and should remain fairly stable in future versions.
|
||||||
struct Setup // atari_ntsc_setup_t
|
struct Setup
|
||||||
{
|
{
|
||||||
// Basic parameters
|
// Basic parameters
|
||||||
double hue; // -1 = -180 degrees +1 = +180 degrees
|
double hue; // -1 = -180 degrees +1 = +180 degrees
|
||||||
|
@ -68,7 +68,6 @@ class AtariNTSC
|
||||||
double artifacts; // artifacts caused by color changes
|
double artifacts; // artifacts caused by color changes
|
||||||
double fringing; // color artifacts caused by brightness changes
|
double fringing; // color artifacts caused by brightness changes
|
||||||
double bleed; // color bleed (color resolution reduction)
|
double bleed; // color bleed (color resolution reduction)
|
||||||
float const* decoder_matrix; // optional RGB decoder matrix, 6 elements
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Video format presets
|
// Video format presets
|
||||||
|
@ -85,7 +84,7 @@ class AtariNTSC
|
||||||
// palette colors.
|
// palette colors.
|
||||||
// In_row_width is the number of pixels to get to the next input row.
|
// In_row_width is the number of pixels to get to the next input row.
|
||||||
// Out_pitch is the number of *bytes* to get to the next output row.
|
// Out_pitch is the number of *bytes* to get to the next output row.
|
||||||
void blitSingle(const uInt8* atari_in, uInt32 in_width, uInt32 in_height,
|
void render(const uInt8* atari_in, uInt32 in_width, uInt32 in_height,
|
||||||
void* rgb_out, uInt32 out_pitch);
|
void* rgb_out, uInt32 out_pitch);
|
||||||
|
|
||||||
// Number of input pixels that will fit within given output width.
|
// Number of input pixels that will fit within given output width.
|
||||||
|
|
|
@ -111,9 +111,9 @@ string NTSCFilter::increaseAdjustable()
|
||||||
if(myPreset != PRESET_CUSTOM)
|
if(myPreset != PRESET_CUSTOM)
|
||||||
return "'Custom' TV mode not selected";
|
return "'Custom' TV mode not selected";
|
||||||
|
|
||||||
uInt32 newval = SCALE_TO_100(*ourCustomAdjustables[myCurrentAdjustable].value);
|
uInt32 newval = scaleTo100(*ourCustomAdjustables[myCurrentAdjustable].value);
|
||||||
newval += 2; if(newval > 100) newval = 100;
|
newval += 2; if(newval > 100) newval = 100;
|
||||||
*ourCustomAdjustables[myCurrentAdjustable].value = SCALE_FROM_100(newval);
|
*ourCustomAdjustables[myCurrentAdjustable].value = scaleFrom100(newval);
|
||||||
|
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
buf << "Custom '" << ourCustomAdjustables[myCurrentAdjustable].type
|
buf << "Custom '" << ourCustomAdjustables[myCurrentAdjustable].type
|
||||||
|
@ -129,10 +129,10 @@ string NTSCFilter::decreaseAdjustable()
|
||||||
if(myPreset != PRESET_CUSTOM)
|
if(myPreset != PRESET_CUSTOM)
|
||||||
return "'Custom' TV mode not selected";
|
return "'Custom' TV mode not selected";
|
||||||
|
|
||||||
uInt32 newval = SCALE_TO_100(*ourCustomAdjustables[myCurrentAdjustable].value);
|
uInt32 newval = scaleTo100(*ourCustomAdjustables[myCurrentAdjustable].value);
|
||||||
if(newval < 2) newval = 0;
|
if(newval < 2) newval = 0;
|
||||||
else newval -= 2;
|
else newval -= 2;
|
||||||
*ourCustomAdjustables[myCurrentAdjustable].value = SCALE_FROM_100(newval);
|
*ourCustomAdjustables[myCurrentAdjustable].value = scaleFrom100(newval);
|
||||||
|
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
buf << "Custom '" << ourCustomAdjustables[myCurrentAdjustable].type
|
buf << "Custom '" << ourCustomAdjustables[myCurrentAdjustable].type
|
||||||
|
@ -197,32 +197,32 @@ void NTSCFilter::getAdjustables(Adjustable& adjustable, Preset preset) const
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void NTSCFilter::setCustomAdjustables(Adjustable& adjustable)
|
void NTSCFilter::setCustomAdjustables(Adjustable& adjustable)
|
||||||
{
|
{
|
||||||
myCustomSetup.hue = SCALE_FROM_100(adjustable.hue);
|
myCustomSetup.hue = scaleFrom100(adjustable.hue);
|
||||||
myCustomSetup.saturation = SCALE_FROM_100(adjustable.saturation);
|
myCustomSetup.saturation = scaleFrom100(adjustable.saturation);
|
||||||
myCustomSetup.contrast = SCALE_FROM_100(adjustable.contrast);
|
myCustomSetup.contrast = scaleFrom100(adjustable.contrast);
|
||||||
myCustomSetup.brightness = SCALE_FROM_100(adjustable.brightness);
|
myCustomSetup.brightness = scaleFrom100(adjustable.brightness);
|
||||||
myCustomSetup.sharpness = SCALE_FROM_100(adjustable.sharpness);
|
myCustomSetup.sharpness = scaleFrom100(adjustable.sharpness);
|
||||||
myCustomSetup.gamma = SCALE_FROM_100(adjustable.gamma);
|
myCustomSetup.gamma = scaleFrom100(adjustable.gamma);
|
||||||
myCustomSetup.resolution = SCALE_FROM_100(adjustable.resolution);
|
myCustomSetup.resolution = scaleFrom100(adjustable.resolution);
|
||||||
myCustomSetup.artifacts = SCALE_FROM_100(adjustable.artifacts);
|
myCustomSetup.artifacts = scaleFrom100(adjustable.artifacts);
|
||||||
myCustomSetup.fringing = SCALE_FROM_100(adjustable.fringing);
|
myCustomSetup.fringing = scaleFrom100(adjustable.fringing);
|
||||||
myCustomSetup.bleed = SCALE_FROM_100(adjustable.bleed);
|
myCustomSetup.bleed = scaleFrom100(adjustable.bleed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void NTSCFilter::convertToAdjustable(Adjustable& adjustable,
|
void NTSCFilter::convertToAdjustable(Adjustable& adjustable,
|
||||||
const AtariNTSC::Setup& setup) const
|
const AtariNTSC::Setup& setup) const
|
||||||
{
|
{
|
||||||
adjustable.hue = SCALE_TO_100(setup.hue);
|
adjustable.hue = scaleTo100(setup.hue);
|
||||||
adjustable.saturation = SCALE_TO_100(setup.saturation);
|
adjustable.saturation = scaleTo100(setup.saturation);
|
||||||
adjustable.contrast = SCALE_TO_100(setup.contrast);
|
adjustable.contrast = scaleTo100(setup.contrast);
|
||||||
adjustable.brightness = SCALE_TO_100(setup.brightness);
|
adjustable.brightness = scaleTo100(setup.brightness);
|
||||||
adjustable.sharpness = SCALE_TO_100(setup.sharpness);
|
adjustable.sharpness = scaleTo100(setup.sharpness);
|
||||||
adjustable.gamma = SCALE_TO_100(setup.gamma);
|
adjustable.gamma = scaleTo100(setup.gamma);
|
||||||
adjustable.resolution = SCALE_TO_100(setup.resolution);
|
adjustable.resolution = scaleTo100(setup.resolution);
|
||||||
adjustable.artifacts = SCALE_TO_100(setup.artifacts);
|
adjustable.artifacts = scaleTo100(setup.artifacts);
|
||||||
adjustable.fringing = SCALE_TO_100(setup.fringing);
|
adjustable.fringing = scaleTo100(setup.fringing);
|
||||||
adjustable.bleed = SCALE_TO_100(setup.bleed);
|
adjustable.bleed = scaleTo100(setup.bleed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -24,9 +24,6 @@ class Settings;
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
#include "AtariNTSC.hxx"
|
#include "AtariNTSC.hxx"
|
||||||
|
|
||||||
#define SCALE_FROM_100(x) ((x/50.0)-1.0)
|
|
||||||
#define SCALE_TO_100(x) uInt32(50*(x+1.0))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class is based on the Blargg NTSC filter code from Atari800,
|
This class is based on the Blargg NTSC filter code from Atari800,
|
||||||
and is derived from 'filter_ntsc.(h|c)'. Original code based on
|
and is derived from 'filter_ntsc.(h|c)'. Original code based on
|
||||||
|
@ -108,10 +105,10 @@ class NTSCFilter
|
||||||
|
|
||||||
// Perform Blargg filtering on input buffer, place results in
|
// Perform Blargg filtering on input buffer, place results in
|
||||||
// output buffer
|
// output buffer
|
||||||
inline void blit_single(uInt8* src_buf, uInt32 src_width, uInt32 src_height,
|
inline void render(uInt8* src_buf, uInt32 src_width, uInt32 src_height,
|
||||||
uInt32* dest_buf, uInt32 dest_pitch)
|
uInt32* dest_buf, uInt32 dest_pitch)
|
||||||
{
|
{
|
||||||
myNTSC.blitSingle(src_buf, src_width, src_height, dest_buf, dest_pitch);
|
myNTSC.render(src_buf, src_width, src_height, dest_buf, dest_pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -119,6 +116,9 @@ class NTSCFilter
|
||||||
void convertToAdjustable(Adjustable& adjustable,
|
void convertToAdjustable(Adjustable& adjustable,
|
||||||
const AtariNTSC::Setup& setup) const;
|
const AtariNTSC::Setup& setup) const;
|
||||||
|
|
||||||
|
constexpr double scaleFrom100(double x) const { return (x/50.0) - 1.0; }
|
||||||
|
constexpr uInt32 scaleTo100(double x) const { return uInt32(50*(x+1.0)); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The NTSC object
|
// The NTSC object
|
||||||
AtariNTSC myNTSC;
|
AtariNTSC myNTSC;
|
||||||
|
@ -134,15 +134,8 @@ class NTSCFilter
|
||||||
// Current preset in use
|
// Current preset in use
|
||||||
Preset myPreset;
|
Preset myPreset;
|
||||||
|
|
||||||
// The base 2600 palette contains 128 colours
|
// The base 2600 palette contains 128 normal colours
|
||||||
// However, 'phosphor' mode needs a 128x128 matrix to simulate
|
// and 128 black&white colours (PAL colour loss)
|
||||||
// low-flicker output, so we need 128x128 + 128, or 129x128
|
|
||||||
// Note that this is a huge hack, which hopefully will go
|
|
||||||
// away once the phosphor effect can be more properly emulated
|
|
||||||
// Memory layout is as follows:
|
|
||||||
//
|
|
||||||
// 128x128 in first bytes of array
|
|
||||||
// 128 in last bytes of array
|
|
||||||
// Each colour is represented by 3 bytes, in R,G,B order
|
// Each colour is represented by 3 bytes, in R,G,B order
|
||||||
uInt8 myTIAPalette[AtariNTSC::palette_size * 3];
|
uInt8 myTIAPalette[AtariNTSC::palette_size * 3];
|
||||||
|
|
||||||
|
|
|
@ -360,16 +360,14 @@ void TIASurface::render()
|
||||||
|
|
||||||
case Filter::BlarggNormal:
|
case Filter::BlarggNormal:
|
||||||
{
|
{
|
||||||
myNTSCFilter.blit_single(myTIA->frameBuffer(), width, height,
|
myNTSCFilter.render(myTIA->frameBuffer(), width, height, out, outPitch << 2);
|
||||||
out, outPitch << 2);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Filter::BlarggPhosphor:
|
case Filter::BlarggPhosphor:
|
||||||
{
|
{
|
||||||
// First do Blargg filtering
|
// First do Blargg filtering
|
||||||
myNTSCFilter.blit_single(myTIA->frameBuffer(), width, height,
|
myNTSCFilter.render(myTIA->frameBuffer(), width, height, out, outPitch << 2);
|
||||||
out, outPitch << 2);
|
|
||||||
|
|
||||||
// Then do phosphor mode (blend the resulting frames)
|
// Then do phosphor mode (blend the resulting frames)
|
||||||
uInt32* rgbIn = myRGBFramebuffer;
|
uInt32* rgbIn = myRGBFramebuffer;
|
||||||
|
|
Loading…
Reference in New Issue