float Color::Hue() const { float min, max; Bounds(&min, &max, true); return Hue(min, max); }
void ColorScreening(IplImage *src, IplImage *dst) { for (int i = 0; i < src->height; i++) { uchar* srcp = (uchar*)(src->imageData + i*src->widthStep); uchar* dstp = (uchar*)(dst->imageData + i*src->widthStep); for (int j = 0; j < src->width; j++) { unsigned int b = srcp[3*j]; unsigned int g = srcp[3*j+1]; unsigned int r = srcp[3*j+2]; unsigned int hue = Hue(r, g, b); float sat = Saturation(r, g, b); unsigned int ins = Intensity(r, g, b); //printf("src: %d %d %d\n", r, g, b); //printf("cal: %d %f %d\n", hue, sat, ins); if (((hue >= H_MIN1 && hue <= H_MAX1) || (hue >= H_MIN2 && hue <= H_MAX2)) && sat >= S_THRESHOLD && ins >= I_THRESHOLD){ dstp[3*j] = 0; dstp[3*j+1] = 0; dstp[3*j+2] = r; //printf("sto: %d %d %d\n", dstp[3*j], dstp[3*j+1], dstp[3*j+2]); } else { dstp[3*j] = 0; dstp[3*j+1] = 0; dstp[3*j+2] = 0; //printf("sto: %d %d %d\n", dstp[3*j], dstp[3*j+1], dstp[3*j+2]); } } } }
void printline(RGB pal[], int i) { /* R G B i Y V S(hsv) S(hls) L H */ printf("(%3d,%3d,%3d)%3d %6.3f %6.3f %6.3f %6.3f %6.3f %+6.1f %s\n", pal[i].red, pal[i].green, pal[i].blue, i, y_yiq[i], v_hsv[i], s_hsv[i], s_hls[i], l_hls[i], hue[i], Hue(i) ); }
Vector3 Color::ToHSV() const { float min, max; Bounds(&min, &max, true); float h = Hue(min, max); float s = SaturationHSV(min, max); float v = max; return Vector3(h, s, v); }
Vector3 Color::ToHSL() const { float min, max; Bounds(&min, &max, true); float h = Hue(min, max); float s = SaturationHSL(min, max); float l = (max + min) * 0.5f; return Vector3(h, s, l); }
//----------------------------------------------------------------------------- bool tIMX51Video::SetHueInternal() { if(m_pGstSource) { GParamSpec *param = g_object_class_find_property(G_OBJECT_GET_CLASS(m_pGstSource), "hue"); if(!param) return false; GParamSpecInt *pint = G_PARAM_SPEC_INT (param); if(!pint) return false; int val = (pint->maximum - pint->minimum) * Hue() / 100 + pint->minimum; //qDebug() << "Setting hue" << val; g_object_set(m_pGstSource, "hue", val, NULL); } return false; }
void HexagonView::Draw(sf::RenderTarget* rt) const { if(!m_model) { return; } const double time = m_model->GetTime(); const double hexagonRadius = 1.0 + 0.15 * sin(time * 10); const double playerRadius = 1.4; const int numSides = m_model->GetNumSides(); const double zoom = 1.0; const double w = zoom * 16; const double h = zoom * 9; sf::View view(sf::FloatRect(-w/2,-h/2,w,h)); view.setRotation(m_model->GetRotation()); rt->setView(view); //Draw bg sf::ConvexShape bgSide(4); for(int i = 0; i < numSides; ++i) { bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.8)); const double in = hexagonRadius - 0.1 + 0.05 * sin(time * 5); ConstructSideShape(bgSide, i, numSides, in, hexagonRadius); rt->draw(bgSide); bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.2)); ConstructSideShape(bgSide, i, numSides, 0, in); rt->draw(bgSide); if(i % 2) { bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.2)); } else { bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.3)); } ConstructSideShape(bgSide, i, numSides, hexagonRadius, 32); rt->draw(bgSide); } //Draw obstacles sf::ConvexShape obsShape(4); obsShape.setFillColor(HSVtoRGB(Hue(), Sat(), 0.8)); for(int i = 0; i < numSides; i++) { Obstacle* obs = m_model->GetObstacle(i); while(obs) { const double pd = m_model->GetPlayerDistance(); double start = obs->start - pd + playerRadius; const double end = start + obs->end - obs->start; if(start < hexagonRadius) { start = hexagonRadius; } if(end > hexagonRadius) { ConstructSideShape(obsShape, i, numSides, start, end); rt->draw(obsShape); } obs = obs->next; } } //Draw player if(m_drawPlayer) { sf::ConvexShape playerShape(3); const double pos = m_model->GetPlayerPosition(); //Get the two corners the player is between const int posMin = floor(pos); const int posMax = ceil(pos); const double posMinX = playerRadius * cos(posMin * 2 * M_PI / numSides); const double posMinY = playerRadius * sin(posMin * 2 * M_PI / numSides); const double posMaxX = playerRadius * cos(posMax * 2 * M_PI / numSides); const double posMaxY = playerRadius * sin(posMax * 2 * M_PI / numSides); const double lerp = pos - posMin; const double posX = LInterp(lerp, posMinX, posMaxX); const double posY = LInterp(lerp, posMinY, posMaxY); const double pulseScale = 0.1 + 0.025 * sin(time * 10); const double turnMod = m_model->IsGameOver() ? 0 : m_model->GetPlayerDirection() * 15; playerShape.setPoint(0, sf::Vector2f( -0.20, -pulseScale ) ); playerShape.setPoint(1, sf::Vector2f( 0, 0 ) ); playerShape.setPoint(2, sf::Vector2f( -0.20, pulseScale ) ); playerShape.setFillColor(HSVtoRGB(Hue(), Sat(), 1.0)); playerShape.setPosition(posX,posY); playerShape.setRotation(pos * 360 / numSides + turnMod); rt->draw(playerShape); } }