int WarpSpectrum(Canvas *c, EffectManager *em, char mode) { static uint8_t ci = 0; static unsigned short pos[CANVAS_WIDTH]; static char currentMode = -1; if(mode != currentMode){ // performed only once switch(mode){ case EFFECTMODE_INTRO: for(uint8_t x = 0; x < CANVAS_WIDTH; x++){ pos[x] = CANVAS_HM1; for(uint8_t y = 0; y < CANVAS_HEIGHT; y++) c->PutPixel(x, y, 0); } break; } currentMode = mode; } else{ // step unsigned short *spectrum = em->GetSpectrum(); for(uint8_t x = 0; x < CANVAS_WIDTH; x++){ short spc = spectrum[(x >> 1) + 3]; if(spc > 800) ci = MOD32(ci + 1); pos[x] -= (spc - 150) * 10; } } for(uint8_t x = 0; x < CANVAS_WIDTH; x++){ uint8_t px = pos[x] / 6554; for(uint8_t y = 0; y < CANVAS_HEIGHT; y++){ if(y == px){ // shot of color c->PutPixel(x, y, lerpColor(c->GetPixel(x, y), colorwheel_lut[ci], 0.5)); } else if(y == px - 1 || y == px + 1){ // shot of color c->PutPixel(x, y, lerpColor(c->GetPixel(x, y), colorwheel_lut[ci], 0.1)); } else{ // fade out Color_t px_color = c->GetPixel(x, y); c->PutPixel(x, y, COLOR_B( MAX(0, char(RED(px_color)) - 2), MAX(0, char(GREEN(px_color)) - 2), MAX(0, char(BLUE(px_color)) - 2) )); } } } return 1; }
ovis_uint32 Colorscale::lerpColor(const float position) const { ovis_uint8 a,b,g,r; lerpColor(position,a,b,g,r); return (((ovis_uint32)a)<<24)|(((ovis_uint32)b)<<16)|(((ovis_uint32)g)<<8)|((ovis_uint32)r); }
void ColorUpdater::update(ParticleData *data, float dt) { const int endId = data->countAlive; for (int i = 0; i < endId; ++i) { float a = data->time[i].z; data->col[i] = lerpColor(data->startCol[i], data->endCol[i], a); } }
// Interpolate colors between control points (bilinear, should be good enough). void sampleColor(float u, float v, u8 color[4]) const { u *= 3.0f; v *= 3.0f; int iu = (int)floorf(u); int iv = (int)floorf(v); int iu2 = iu + 1; int iv2 = iv + 1; float fracU = u - iu; float fracV = v - iv; if (iu2 > 3) iu2 = 3; if (iv2 > 3) iv2 = 3; int tl = iu + 4 * iv; int tr = iu2 + 4 * iv; int bl = iu + 4 * iv2; int br = iu2 + 4 * iv2; u8 upperColor[4], lowerColor[4]; lerpColor(points[tl]->color, points[tr]->color, fracU, upperColor); lerpColor(points[bl]->color, points[br]->color, fracU, lowerColor); lerpColor(upperColor, lowerColor, fracV, color); }
QColor ColorGradient::linearInterpolateColor(qreal position) const { if (!isValid()) return QColor(); position = clamp(position, 0.0, 1.0); auto upperBound = std::lower_bound( m_stops.begin(), m_stops.end(), ColorGradientStop(position)); if (upperBound == m_stops.begin()) return upperBound->color(); if (upperBound == m_stops.end()) return (--upperBound)->color(); const auto lowerBound = upperBound - 1; return lerpColor(*lowerBound, *upperBound, position); }
color_pt lerpColor(color_pt c1, color_pt c2, float amt, int mode) { return lerpColor( c1, c2, amt); }