From 598a85c6cded81f296a77b558daf14a0a7fd9166 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 30 Nov 2011 21:03:57 +0000 Subject: [PATCH] Move color scheme definitions to the config file Originally committed to SVN as r5947. --- aegisub/src/audio_colorscheme.cpp | 52 +++++++++++------------- aegisub/src/audio_colorscheme.h | 34 +++++----------- aegisub/src/audio_renderer_spectrum.cpp | 9 ++-- aegisub/src/audio_renderer_waveform.cpp | 9 ++-- aegisub/src/libresrc/default_config.json | 40 +++++++++++++++++- 5 files changed, 79 insertions(+), 65 deletions(-) diff --git a/aegisub/src/audio_colorscheme.cpp b/aegisub/src/audio_colorscheme.cpp index 1c9612d52..012d3478b 100644 --- a/aegisub/src/audio_colorscheme.cpp +++ b/aegisub/src/audio_colorscheme.cpp @@ -42,46 +42,42 @@ #include "audio_colorscheme.h" -#include "audio_renderer.h" +#include "audio_rendering_style.h" #include "colorspace.h" +#include "main.h" #include -static int lum_icy_normal(float t) +AudioColorScheme::AudioColorScheme(int prec, std::string const& scheme_name, int audio_rendering_style) +: palette((3<(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(0, h_base + t * h_scale, 255), + mid(0, s_base + t * s_scale, 255), + mid(0, l_base + t * l_scale, 255), + &palette[i * 3 + 0], + &palette[i * 3 + 1], + &palette[i * 3 + 2]); } } diff --git a/aegisub/src/audio_colorscheme.h b/aegisub/src/audio_colorscheme.h index 789c37c15..7dd9fd734 100644 --- a/aegisub/src/audio_colorscheme.h +++ b/aegisub/src/audio_colorscheme.h @@ -37,6 +37,8 @@ #ifndef AGI_PRE +#include + #include #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 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(0, val * factor, factor) * 4; + return &palette[mid(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<InitIcyBlue(AudioStyle_Normal); - colors_selected->InitIcyBlue(AudioStyle_Selected); - colors_inactive->InitIcyBlue(AudioStyle_Inactive); } AudioSpectrumRenderer::~AudioSpectrumRenderer() diff --git a/aegisub/src/audio_renderer_waveform.cpp b/aegisub/src/audio_renderer_waveform.cpp index 3df7facd7..91a31fe7f 100644 --- a/aegisub/src/audio_renderer_waveform.cpp +++ b/aegisub/src/audio_renderer_waveform.cpp @@ -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); } diff --git a/aegisub/src/libresrc/default_config.json b/aegisub/src/libresrc/default_config.json index 12a0187a4..3f91a22d0 100644 --- a/aegisub/src/libresrc/default_config.json +++ b/aegisub/src/libresrc/default_config.json @@ -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" : {