Ejemplo n.º 1
0
QColor Function::interpolateHSV(double delta, QColor const& col1, QColor const& col2) const
{
   if (delta <= 0.0) return col1;
   if (delta >= 1.0) return col2;

   double h1, h2, s1, s2, v1, v2;
   col1.getHsvF(&h1, &s1, &v1);
   col2.getHsvF(&h2, &s2, &v2);

   if (h1 < 0.0) h1 = h2;
   if (h2 < 0.0) h2 = h1;
   if (h1 < 0.0 && h2 < 0.0) { h1 = 0.0; h2 = 0.0; }

   s1 += delta*(s2-s1);
   v1 += delta*(v2-v1);

   // For hue we need to work out which direction we are going on the wheel.
   double dh(h2-h1);
   if (dh > 0.5) {
      dh -= 1.0;
   }else if(dh < -0.5) {
      dh += 1.0;
   }


   h1 += delta*dh;
   if (h1 > 1.0) h1 -= 1.0;
   if (h1 < 0.0) h1 += 1.0;

   QColor color;
   color.setHsvF(h1, s1, v1);
   return color;
}
Ejemplo n.º 2
0
Gradient::Gradient(const QColor &c1, const QColor &c2, bool reverseHue) {
  qreal h1, s1, v1, a1;
  qreal h2, s2, v2, a2;

  c1.getHsvF(&h1, &s1, &v1, &a1);
  c2.getHsvF(&h2, &s2, &v2, &a2);

  if (s1 < ACHROMATIC_THRESHOLD || v1 < ACHROMATIC_THRESHOLD) {
    // color1 is achromatic
    hue.set(0, h2);
  } else if (s2 < ACHROMATIC_THRESHOLD || v2 < ACHROMATIC_THRESHOLD) {
    // color 2 is achromatic
    hue.set(0, h1);
  } else {
    qreal a = h2 - h1;
    if (a > 0.5) {
      a = a - 1;
    } else if (a < -0.5) {
      a = a + 1;
    }

    if (reverseHue) {
      a = a - 1;
    }

    hue.set(a, h1);
  }

  sat.set(0, s1, 1, s2);
  val.set(0, v1, 1, v2);
  alpha.set(0, a1, 1, a2);
}
Ejemplo n.º 3
0
/**
 * Update the gradient bar colors
 */
void ColorDialog::updateBars()
{
	QColor col = color();
	int r,g,b;
	qreal h,s,v;
	col.getRgb(&r,&g,&b);
	col.getHsvF(&h,&s,&v);
	if(h<0)
		h = validhue_/360.0;

	ui_->red->setColor1(QColor(0,g,b));
	ui_->red->setColor2(QColor(255,g,b));

	ui_->green->setColor1(QColor(r,0,b));
	ui_->green->setColor2(QColor(r,255,b));

	ui_->blue->setColor1(QColor(r,g,0));
	ui_->blue->setColor2(QColor(r,g,255));

	ui_->hue->setColorSaturation(s);
	ui_->hue->setColorValue(v);

	ui_->saturation->setColor1(QColor::fromHsvF(h,0,v));
	ui_->saturation->setColor2(QColor::fromHsvF(h,1,v));

	ui_->value->setColor1(QColor::fromHsvF(h,s,0));
	ui_->value->setColor2(QColor::fromHsvF(h,s,1));

	if(showalpha_) {
		ui_->alpha->setColor1(QColor(r,g,b,0));
		ui_->alpha->setColor2(QColor(r,g,b,255));
	}
}
Ejemplo n.º 4
0
void GradientWidgetHue::updateHueFromColor(const QColor &col)
{
    col.getHsvF(&hue,&saturation,&value,&alpha);
    if(hue<0.0)
        hue=0.0;
    m_selected_color.setHsvF(hue,saturation,value,alpha);
    updateCursorPosition();
}
Ejemplo n.º 5
0
QColor PrefDialog::Desaturate(QColor c)
{
    qreal h;
    qreal s;
    qreal v;
    qreal a;
    c.getHsvF(&h, &s, &v, &a);

    v = qMin((0.8 + v * 0.2), 1.0);
    c.setHsvF(h, (s * 0.2), v, 1.0);
    return c;
}
Ejemplo n.º 6
0
void GFX_SetBrightness(struct Tracker_Windows *tvisual, float how_much){
  EditorWidget *editorwidget=(EditorWidget *)tvisual->os_visual.widget;
  if(is_starting_up)
    return;
  return;
#if 0
  float threshold = QColor(SETTINGS_read_string(talloc_format("color%d",15),"#d0d5d0")).valueF();
  
  for(int i=0;i<15;i++){
    QColor color = QColor(SETTINGS_read_string(talloc_format("color%d",i),"#d0d5d0"));
      
    //QColor color = editorwidget->colors[i];
    float value = color.valueF();
    if (value > threshold)
      color = color.lighter(scale(how_much, 0, 1, 0, 200));
    else
      color = color.darker(scale(how_much, 0, 1, 0, 200));

    if (i!=11)
      setColor((enum ColorNums)i, color.rgb());
    printf("value for %d: %f\n",i,value);
    //color.setLightntess(lightness
  }
#else
  
  how_much = scale(how_much,0,1,-1,1);

  for(int i=0;i<16;i++){
    QColor color = QColor(SETTINGS_read_string(talloc_format("color%d",i),"#d0d5d0"));

    qreal h,s,v,a;
    color.getHsvF(&h,&s,&v,&a);

    float value = R_BOUNDARIES(0,v+how_much,1);
    color.setHsvF(h, s, value, a);
    
    //QColor color = editorwidget->colors[i];
    setColor((enum ColorNums)i, color.rgb());
    
    printf("value for %d: %f. s: %f, how_much: %f\n",i,value,s,how_much);
    //color.setLightntess(lightness
  }
#endif
  
  updateAll(editorwidget);
  tvisual->must_redraw = true;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[]) {
	QApplication App(argc, argv);
	QImage MemoryImage("D:/Vyzkumak/Workspace/Qt/Qt/Debug/Picture.png");
	QImage ShowImage("D:/Vyzkumak/Workspace/Qt/Qt/Debug/Picture.png");
	QLabel label;
	label.setPixmap(QPixmap::fromImage(ShowImage));
	label.show();

    int w = MemoryImage.width();
    int h = MemoryImage.height();
	start = time (NULL);
	for (int j=0; j<1; j++){
		qreal H, S, V;
		QColor Color;
		qreal cont=0;
		for (int i=0; i<100; i++){
			cont=cont+0.01;

			for ( int x = 0; x < w; x++ ){
				for ( int y = 0; y < h; y++ ){
					QRgb Rgb = MemoryImage.pixel( x, y);
					Color.setRgb(Rgb);
					Color.getHsvF(&H, &S, &V);
					qreal v=V*cont;
					Color.setHsvF(H, S, v);
					Rgb = Color.rgb();
					ShowImage.setPixel(x, y, Rgb);
				}
			}
			label.setPixmap(QPixmap::fromImage(ShowImage));
			label.repaint();
		}
	}
	end = time (NULL);
	int length = (int) (end - start);
	std::cout << "Length of rendering 100 frames was: " << length << " seconds.\n";
	std::cout << "Average fps is: " << 100. / (float)length << " frames per seconds.\n";
	App.exec();
}
Ejemplo n.º 8
0
void tst_QColor::setHsv()
{
    QColor color;

    for (int A = 0; A <= USHRT_MAX; ++A) {
        {
            // 0-255
            int a = A >> 8;
            color.setHsv(0, 0, 0, a);
            QCOMPARE(color.alpha(), a);

            int h, s, v, a2;
            color.getHsv(&h, &s, &v, &a2);
            QCOMPARE(a2, a);
        }

        {
            // 0.0-1.0
            qreal a = A / qreal(USHRT_MAX);
            color.setHsvF(0.0, 0.0, 0.0, a);
            QCOMPARE(color.alphaF(), a);

            qreal h, s, v, a2;
            color.getHsvF(&h, &s, &v, &a2);
            QCOMPARE(a2, a);
        }
    }

    for (int H = 0; H < 36000; ++H) {
        {
            // 0-255
            int h = H / 100;

            color.setHsv(h, 0, 0, 0);
            QCOMPARE(color.hue(), h);

            int h2, s, v, a;
            color.getHsv(&h2, &s, &v, &a);
            QCOMPARE(h2, h);
        }

        {
            // 0.0-1.0
            qreal h = H / 36000.0;
            color.setHsvF(h, 0.0, 0.0, 0.0);
            QCOMPARE(color.hueF(), h);

            qreal h2, s, v, a;
            color.getHsvF(&h2, &s, &v, &a);
            QCOMPARE(h2, h);
        }
    }

    for (int S = 0; S <= USHRT_MAX; ++S) {
        {
            // 0-255
            int s = S >> 8;
            color.setHsv(0, s, 0, 0);
            QCOMPARE(color.saturation(), s);

            int h, s2, v, a;
            color.getHsv(&h, &s2, &v, &a);
            QCOMPARE(s2, s);
        }

        {
            // 0.0-1.0
            qreal s = S / qreal(USHRT_MAX);
            color.setHsvF(0.0, s, 0.0, 0.0);
            QCOMPARE(color.saturationF(), s);

            qreal h, s2, v, a;
            color.getHsvF(&h, &s2, &v, &a);
            QCOMPARE(s2, s);
        }
    }

    for (int V = 0; V <= USHRT_MAX; ++V) {
        {
            // 0-255
            int v = V >> 8;
            color.setHsv(0, 0, v, 0);
            QCOMPARE(color.value(),  v);

            int h, s, v2, a;
            color.getHsv(&h, &s, &v2, &a);
            QCOMPARE(v2, v);
        }

        {
            // 0.0-1.0
            qreal v = V / qreal(USHRT_MAX);
            color.setHsvF(0.0, 0.0, v, 0.0);
            QCOMPARE(color.valueF(), v);

            qreal h, s, v2, a;
            color.getHsvF(&h, &s, &v2, &a);
            QCOMPARE(v2, v);
        }
    }
}
Ejemplo n.º 9
0
void Palette::setColor(const QColor &color)
{
	if (color.isValid())
		color.getHsvF(&_h, &_s, &_v, &_a);
}
Ejemplo n.º 10
0
void SkyQPainter::initStarImages()
{

    QMap<char, QColor> ColorMap;
    const int starColorIntensity = Options::starColorIntensity();

    switch( Options::starColorMode() ) {
    case 1: // Red stars.
        ColorMap.insert( 'O', QColor::fromRgb( 255,   0,   0 ) );
        ColorMap.insert( 'B', QColor::fromRgb( 255,   0,   0 ) );
        ColorMap.insert( 'A', QColor::fromRgb( 255,   0,   0 ) );
        ColorMap.insert( 'F', QColor::fromRgb( 255,   0,   0 ) );
        ColorMap.insert( 'G', QColor::fromRgb( 255,   0,   0 ) );
        ColorMap.insert( 'K', QColor::fromRgb( 255,   0,   0 ) );
        ColorMap.insert( 'M', QColor::fromRgb( 255,   0,   0 ) );
        break;
    case 2: // Black stars.
        ColorMap.insert( 'O', QColor::fromRgb(   0,   0,   0 ) );
        ColorMap.insert( 'B', QColor::fromRgb(   0,   0,   0 ) );
        ColorMap.insert( 'A', QColor::fromRgb(   0,   0,   0 ) );
        ColorMap.insert( 'F', QColor::fromRgb(   0,   0,   0 ) );
        ColorMap.insert( 'G', QColor::fromRgb(   0,   0,   0 ) );
        ColorMap.insert( 'K', QColor::fromRgb(   0,   0,   0 ) );
        ColorMap.insert( 'M', QColor::fromRgb(   0,   0,   0 ) );
        break;
    case 3: // White stars
        ColorMap.insert( 'O', QColor::fromRgb( 255, 255, 255 ) );
        ColorMap.insert( 'B', QColor::fromRgb( 255, 255, 255 ) );
        ColorMap.insert( 'A', QColor::fromRgb( 255, 255, 255 ) );
        ColorMap.insert( 'F', QColor::fromRgb( 255, 255, 255 ) );
        ColorMap.insert( 'G', QColor::fromRgb( 255, 255, 255 ) );
        ColorMap.insert( 'K', QColor::fromRgb( 255, 255, 255 ) );
        ColorMap.insert( 'M', QColor::fromRgb( 255, 255, 255 ) );
    case 0:  // Real color
    default: // And use real color for everything else
        ColorMap.insert( 'O', QColor::fromRgb(   0,   0, 255 ) );
        ColorMap.insert( 'B', QColor::fromRgb(   0, 200, 255 ) );
        ColorMap.insert( 'A', QColor::fromRgb(   0, 255, 255 ) );
        ColorMap.insert( 'F', QColor::fromRgb( 200, 255, 100 ) );
        ColorMap.insert( 'G', QColor::fromRgb( 255, 255,   0 ) );
        ColorMap.insert( 'K', QColor::fromRgb( 255, 100,   0 ) );
        ColorMap.insert( 'M', QColor::fromRgb( 255,   0,   0 ) );
    }

    foreach( char color, ColorMap.keys() ) {
        QPixmap BigImage( 15, 15 );
        BigImage.fill( Qt::transparent );

        QPainter p;
        p.begin( &BigImage );

        if ( Options::starColorMode() == 0 ) {
            qreal h, s, v, a;
            p.setRenderHint( QPainter::Antialiasing, false );
            QColor starColor = ColorMap[color];
            starColor.getHsvF(&h, &s, &v, &a);
            for (int i = 0; i < 8; i++ ) {
                for (int j = 0; j < 8; j++ ) {
                    qreal x = i - 7;
                    qreal y = j - 7;
                    qreal dist = sqrt( x*x + y*y ) / 7.0;
                    starColor.setHsvF(h,
                                      qMin( qreal(1), dist < (10-starColorIntensity)/10.0 ? 0 : dist ),
                                      v,
                                      qMax( qreal(0), dist < (10-starColorIntensity)/20.0 ? 1 : 1-dist ) );
                    p.setPen( starColor );
                    p.drawPoint( i, j );
                    p.drawPoint( 14-i, j );
                    p.drawPoint( i, 14-j );
                    p.drawPoint (14-i, 14-j);
                }
            }
        } else {
            p.setRenderHint(QPainter::Antialiasing, true );
            p.setPen( QPen(ColorMap[color], 2.0 ) );
            p.setBrush( p.pen().color() );
            p.drawEllipse( QRectF( 2, 2, 10, 10 ) );
        }
        p.end();

        // Cache array slice
        QPixmap** pmap = imageCache[ harvardToIndex(color) ];
        for( int size = 1; size < nStarSizes; size++ ) {
            if( !pmap[size] )
                pmap[size] = new QPixmap();
            *pmap[size] = BigImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
        }
    }
    starColorMode = Options::starColorMode();
}