Move color scheme definitions to the config file
Originally committed to SVN as r5947.
This commit is contained in:
parent
f0e98151f1
commit
598a85c6cd
5 changed files with 79 additions and 65 deletions
|
@ -42,46 +42,42 @@
|
|||
|
||||
#include "audio_colorscheme.h"
|
||||
|
||||
#include "audio_renderer.h"
|
||||
#include "audio_rendering_style.h"
|
||||
#include "colorspace.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <libaegisub/exception.h>
|
||||
|
||||
static int lum_icy_normal(float t)
|
||||
AudioColorScheme::AudioColorScheme(int prec, std::string const& scheme_name, int audio_rendering_style)
|
||||
: palette((3<<prec) + 3)
|
||||
, factor(1<<prec)
|
||||
{
|
||||
return std::min(255, (int)(128 * 2 * t));
|
||||
}
|
||||
|
||||
static int lum_icy_selected(float t)
|
||||
{
|
||||
return std::min(255, (int)(128 * (3 * t/2 + 0.5f)));
|
||||
}
|
||||
|
||||
static int lum_icy_inactive(float t)
|
||||
{
|
||||
return 32 + (int)(192 * t);
|
||||
}
|
||||
|
||||
void AudioColorScheme::InitIcyBlue(int audio_rendering_style)
|
||||
{
|
||||
int (*lum_func)(float);
|
||||
std::string opt_base = "Colour/Schemes/" + scheme_name + "/";
|
||||
switch (static_cast<AudioRenderingStyle>(audio_rendering_style))
|
||||
{
|
||||
case AudioStyle_Normal: lum_func = lum_icy_normal; break;
|
||||
case AudioStyle_Inactive: lum_func = lum_icy_inactive; break;
|
||||
case AudioStyle_Active: lum_func = lum_icy_normal; break;
|
||||
case AudioStyle_Selected: lum_func = lum_icy_selected; break;
|
||||
case AudioStyle_Normal: opt_base += "Normal/"; break;
|
||||
case AudioStyle_Inactive: opt_base += "Inactive/"; break;
|
||||
case AudioStyle_Active: opt_base += "Active/"; break;
|
||||
case AudioStyle_Selected: opt_base += "Selected/"; break;
|
||||
default: throw agi::InternalError("Unknown audio rendering styling", 0);
|
||||
}
|
||||
|
||||
unsigned char *palptr = palette;
|
||||
double h_base = OPT_GET(opt_base + "Hue Offset")->GetDouble();
|
||||
double h_scale = OPT_GET(opt_base + "Hue Scale")->GetDouble();
|
||||
double s_base = OPT_GET(opt_base + "Saturation Offset")->GetDouble();
|
||||
double s_scale = OPT_GET(opt_base + "Saturation Scale")->GetDouble();
|
||||
double l_base = OPT_GET(opt_base + "Lightness Offset")->GetDouble();
|
||||
double l_scale = OPT_GET(opt_base + "Lightness Scale")->GetDouble();
|
||||
|
||||
for (size_t i = 0; i <= factor; ++i)
|
||||
{
|
||||
float t = (float)i / factor;
|
||||
int H = (int)(255 * (1.5 - t) / 2);
|
||||
int S = (int)(255 * (0.5 + t/2));
|
||||
int L = lum_func(t);
|
||||
hsl_to_rgb(H, S, L, palptr + 0, palptr + 1, palptr + 2);
|
||||
palptr += 4;
|
||||
hsl_to_rgb(
|
||||
mid<int>(0, h_base + t * h_scale, 255),
|
||||
mid<int>(0, s_base + t * s_scale, 255),
|
||||
mid<int>(0, l_base + t * l_scale, 255),
|
||||
&palette[i * 3 + 0],
|
||||
&palette[i * 3 + 1],
|
||||
&palette[i * 3 + 2]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <vector>
|
||||
|
||||
#include <wx/colour.h>
|
||||
#endif
|
||||
|
||||
|
@ -50,44 +52,28 @@
|
|||
///
|
||||
/// First create an instance of this class, then call an initialisation function
|
||||
/// in it to fill the palette with a colour map.
|
||||
///
|
||||
/// @todo Let consumers of this class specify their own palette generation function.
|
||||
class AudioColorScheme {
|
||||
/// The palette data for the map
|
||||
unsigned char *palette;
|
||||
std::vector<unsigned char> palette;
|
||||
|
||||
/// Factor to multiply 0..1 values by to map them into the palette range
|
||||
size_t factor;
|
||||
|
||||
/// @brief Get a floating point value's colour as a 24-bit RGB pixel
|
||||
/// @param val The value to map from
|
||||
unsigned char *get_color(float val) const
|
||||
const unsigned char *get_color(float val) const
|
||||
{
|
||||
return palette + mid<size_t>(0, val * factor, factor) * 4;
|
||||
return &palette[mid<size_t>(0, val * factor, factor) * 3];
|
||||
}
|
||||
|
||||
public:
|
||||
/// @brief Constructor
|
||||
/// @param prec Bit precision to create the colour map with
|
||||
/// @param scheme_name Name of the colour scheme to use
|
||||
/// @param audio_rendering_style AudioRenderingStyle to init this colorscheme for
|
||||
///
|
||||
/// Allocates the palette array to 2^prec entries
|
||||
AudioColorScheme(int prec)
|
||||
: palette(new unsigned char[(4<<prec) + 4])
|
||||
, factor(1<<prec)
|
||||
{
|
||||
}
|
||||
|
||||
/// @brief Destructor
|
||||
///
|
||||
/// De-allocates the palette array
|
||||
~AudioColorScheme()
|
||||
{
|
||||
delete[] palette;
|
||||
}
|
||||
|
||||
/// @brief Initialise the palette to the Aegisub 2.1 "Icy Blue" scheme
|
||||
/// @param audio_rendering_style AudioRenderingStyle to init this colorscheme for
|
||||
void InitIcyBlue(int audio_rendering_style);
|
||||
AudioColorScheme(int prec, std::string const& scheme_name, int audio_rendering_style);
|
||||
|
||||
/// @brief Map a floating point value to RGB
|
||||
/// @param val [in] The value to map from
|
||||
|
@ -98,7 +84,7 @@ public:
|
|||
void map(float val, unsigned char *pixel) const
|
||||
{
|
||||
// Find the colour in the palette
|
||||
unsigned char *color = get_color(val);
|
||||
const unsigned char *color = get_color(val);
|
||||
// Copy to the destination.
|
||||
// Has to be done one byte at a time since we're writing RGB and not RGBX or RGBA
|
||||
// data, and we otherwise write past the end of the pixel we're writing, possibly
|
||||
|
@ -115,7 +101,7 @@ public:
|
|||
/// @return The corresponding wxColour
|
||||
wxColour get(float val) const
|
||||
{
|
||||
unsigned char *color = get_color(val);
|
||||
const unsigned char *color = get_color(val);
|
||||
return wxColour(color[0], color[1], color[2]);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -106,9 +106,9 @@ public:
|
|||
|
||||
|
||||
AudioSpectrumRenderer::AudioSpectrumRenderer()
|
||||
: colors_normal(new AudioColorScheme(12))
|
||||
, colors_selected(new AudioColorScheme(12))
|
||||
, colors_inactive(new AudioColorScheme(12))
|
||||
: colors_normal(new AudioColorScheme(12, "Icy Blue", AudioStyle_Normal))
|
||||
, colors_selected(new AudioColorScheme(12, "Icy Blue", AudioStyle_Selected))
|
||||
, colors_inactive(new AudioColorScheme(12, "Icy Blue", AudioStyle_Inactive))
|
||||
, derivation_size(8)
|
||||
, derivation_dist(8)
|
||||
#ifdef WITH_FFTW
|
||||
|
@ -117,9 +117,6 @@ AudioSpectrumRenderer::AudioSpectrumRenderer()
|
|||
, dft_output(0)
|
||||
#endif
|
||||
{
|
||||
colors_normal->InitIcyBlue(AudioStyle_Normal);
|
||||
colors_selected->InitIcyBlue(AudioStyle_Selected);
|
||||
colors_inactive->InitIcyBlue(AudioStyle_Inactive);
|
||||
}
|
||||
|
||||
AudioSpectrumRenderer::~AudioSpectrumRenderer()
|
||||
|
|
|
@ -51,14 +51,11 @@
|
|||
|
||||
AudioWaveformRenderer::AudioWaveformRenderer()
|
||||
: AudioRendererBitmapProvider()
|
||||
, colors_normal(6)
|
||||
, colors_selected(6)
|
||||
, colors_inactive(6)
|
||||
, colors_normal(6, "Icy Blue", AudioStyle_Normal)
|
||||
, colors_selected(6, "Icy Blue", AudioStyle_Selected)
|
||||
, colors_inactive(6, "Icy Blue", AudioStyle_Inactive)
|
||||
, audio_buffer(0)
|
||||
{
|
||||
colors_normal.InitIcyBlue(AudioStyle_Normal);
|
||||
colors_selected.InitIcyBlue(AudioStyle_Selected);
|
||||
colors_inactive.InitIcyBlue(AudioStyle_Inactive);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,8 +97,46 @@
|
|||
"Line boundary Start" : "rgb(216, 0, 0)",
|
||||
"Play Cursor" : "rgb(255,255,255)",
|
||||
"Seconds Boundaries" : "rgb(0, 100, 255)",
|
||||
"Spectrum" : "Icy Blue",
|
||||
"Syllable Boundaries" : "rgb(255,255,0)",
|
||||
"Syllable Text" : "rgb(255,0,0)"
|
||||
"Syllable Text" : "rgb(255,0,0)",
|
||||
"Waveform" : "Icy Blue"
|
||||
},
|
||||
"Schemes" : {
|
||||
"Icy Blue" : {
|
||||
"Normal" : {
|
||||
"Hue Offset" : 191.01,
|
||||
"Hue Scale" : -128.01,
|
||||
"Saturation Offset" : 127.01,
|
||||
"Saturation Scale" : 128.01,
|
||||
"Lightness Offset" : 0.01,
|
||||
"Lightness Scale" : 255.01
|
||||
},
|
||||
"Inactive" : {
|
||||
"Hue Offset" : 191.01,
|
||||
"Hue Scale" : -128.01,
|
||||
"Saturation Offset" : 127.01,
|
||||
"Saturation Scale" : 128.01,
|
||||
"Lightness Offset" : 32.01,
|
||||
"Lightness Scale" : 192.01
|
||||
},
|
||||
"Active" : {
|
||||
"Hue Offset" : 191.01,
|
||||
"Hue Scale" : -128.01,
|
||||
"Saturation Offset" : 127.01,
|
||||
"Saturation Scale" : 128.01,
|
||||
"Lightness Offset" : 0.01,
|
||||
"Lightness Scale" : 0.01
|
||||
},
|
||||
"Selected" : {
|
||||
"Hue Offset" : 191.01,
|
||||
"Hue Scale" : -128.01,
|
||||
"Saturation Offset" : 127.01,
|
||||
"Saturation Scale" : 128.01,
|
||||
"Lightness Offset" : 64.01,
|
||||
"Lightness Scale" : 192.01
|
||||
}
|
||||
}
|
||||
},
|
||||
"Style Editor" : {
|
||||
"Background" : {
|
||||
|
|
Loading…
Reference in a new issue