Replace InitIcyBlue_Normal and InitIcyBlue_Selected with a single method which takes an audio rendering style as a parameter

Originally committed to SVN as r5883.
This commit is contained in:
Thomas Goyne 2011-11-18 22:57:36 +00:00
parent 13a281e9dc
commit 1eedb0c3d4
3 changed files with 31 additions and 24 deletions

View file

@ -41,32 +41,41 @@
#endif
#include "audio_colorscheme.h"
#include "audio_renderer.h"
#include "colorspace.h"
void AudioColorScheme::InitIcyBlue_Normal()
#include <libaegisub/exception.h>
static int lum_icy_normal(float t)
{
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.5)));
}
void AudioColorScheme::InitIcyBlue(int audio_rendering_style)
{
int (*lum_func)(float);
switch (static_cast<AudioRenderingStyle>(audio_rendering_style))
{
case AudioStyle_Normal: lum_func = lum_icy_normal; break;
case AudioStyle_Inactive: lum_func = lum_icy_normal; break;
case AudioStyle_Active: lum_func = lum_icy_normal; break;
case AudioStyle_Selected: lum_func = lum_icy_selected; break;
default: throw agi::InternalError("Unknown audio rendering styling", 0);
}
unsigned char *palptr = palette;
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 = std::min(255, (int)(128 * 2 * t));
hsl_to_rgb(H, S, L, palptr + 0, palptr + 1, palptr + 2);
palptr += 4;
}
}
void AudioColorScheme::InitIcyBlue_Selected()
{
unsigned char *palptr = palette;
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 = std::min(255, (int)(128 * (3 * t/2 + 0.5)));
int L = lum_func(t);
hsl_to_rgb(H, S, L, palptr + 0, palptr + 1, palptr + 2);
palptr += 4;
}

View file

@ -85,10 +85,9 @@ public:
delete[] palette;
}
/// @brief Initialise the palette to the Aegisub 2.1 "Icy Blue" scheme (unselected)
void InitIcyBlue_Normal();
/// @brief Initialise the palette to the Aegisub 2.1 "Icy Blue" scheme (selected)
void InitIcyBlue_Selected();
/// @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);
/// @brief Map a floating point value to RGB
/// @param val [in] The value to map from

View file

@ -127,11 +127,10 @@ AudioSpectrumRenderer::AudioSpectrumRenderer()
#endif
, audio_scratch(0)
{
colors_normal.InitIcyBlue_Normal();
colors_selected.InitIcyBlue_Selected();
colors_normal.InitIcyBlue(AudioStyle_Normal);
colors_selected.InitIcyBlue(AudioStyle_Selected);
}
AudioSpectrumRenderer::~AudioSpectrumRenderer()
{
// This sequence will clean up