Skip to content

Commit

Permalink
Better code documentation of Spectrogram's colors
Browse files Browse the repository at this point in the history
  • Loading branch information
twitham1 authored and linuxdude42 committed Aug 18, 2023
1 parent 357baab commit b787b1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
42 changes: 22 additions & 20 deletions mythplugins/mythmusic/mythmusic/visualize.cpp
Expand Up @@ -899,30 +899,32 @@ Spectrogram::Spectrogram()
m_sigL.resize(m_fftlen);
m_sigR.resize(m_fftlen);

// cache a continuous color spectrum:
// 0000ff blue
// 00ffff cyan
// 00ff00 green
// ffff00 yellow
// ff0000 red
// ff00ff magenta
// 0000ff blue
int red[] = {0, 0, 9, 1, 1, 8}; // 8 = ramp down
int green[] = {9, 1, 1, 8, 0, 0}; // 9 = ramp up
int blue[] = {1, 8, 0, 0, 9, 1};
m_red = (int *) malloc(sizeof(int) * 257 * 6);
m_green = (int *) malloc(sizeof(int) * 257 * 6);
m_blue = (int *) malloc(sizeof(int) * 257 * 6);
for (int i = 0; i < 6; i++)
{
int r = red[i];
// cache a continuous color spectrum ([0-1535] = 256 colors * 6 ramps):
// 0000ff blue from here, G of RGB ramps UP to:
// 00ffff cyan then B ramps down to:
// 00ff00 green then R ramps UP to:
// ffff00 yellow then G ramps down to:
// ff0000 red then B ramps UP to:
// ff00ff magenta then R ramps down to:
// 0000ff blue we end where we started!
static constexpr int UP { 2 };
static constexpr int DN { 3 };
int red[] = { 0, 0, UP, 1, 1, DN }; // 0=OFF, 1=ON
int green[] = { UP, 1, 1, DN, 0, 0 };
int blue[] = { 1, DN, 0, 0, UP, 1 };
m_red = (int *) malloc(sizeof(int) * 256 * 6);
m_green = (int *) malloc(sizeof(int) * 256 * 6);
m_blue = (int *) malloc(sizeof(int) * 256 * 6);
for (int i = 0; i < 6; i++) // for 6 color transitions...
{
int r = red[i]; // 0=OFF, 1=ON, UP, or DN
int g = green[i];
int b = blue[i];
for (int u = 0; u < 256; u++) { // u ramps up
int d = 256 - u; // d ramps down
m_red[ i * 256 + u] = r == 9 ? u : r == 8 ? d : r * 255;
m_green[i * 256 + u] = g == 9 ? u : g == 8 ? d : g * 255;
m_blue[ i * 256 + u] = b == 9 ? u : b == 8 ? d : b * 255;
m_red[ i * 256 + u] = r == UP ? u : r == DN ? d : r * 255;
m_green[i * 256 + u] = g == UP ? u : g == DN ? d : g * 255;
m_blue[ i * 256 + u] = b == UP ? u : b == DN ? d : b * 255;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythmusic/mythmusic/visualize.h
Expand Up @@ -217,7 +217,7 @@ class Spectrogram : public VisualBase
static inline double clamp(double cur, double max, double min);
QSize m_sgsize {1920, 1080}; // picture size
QSize m_size; // displayed dize
LogScale m_scale;
LogScale m_scale; // Y-axis
int m_fftlen {16 * 1024}; // window width
QVector<float> m_sigL; // decaying signal window
QVector<float> m_sigR;
Expand Down

0 comments on commit b787b1e

Please sign in to comment.