void AdaptAver::adArAv(int curx, int cury, int powerX, int powerY) { //Adaptive Arithmetic Average //qDebug() << "adarav"; QList<int> proxArrayR; //массивы пикселей окрестности точки QList<int> proxArrayG; //для трёх цветов (red, green, blue) QList<int> proxArrayB; for (int y = cury - powerY; y <= cury+ powerY; y++) for (int x = curx - powerX; x <= curx+ powerX; x++) {//проверяем окрестные пиксели if ((0 <= x && x <= image.width()-1) && (0 <= y && y <= image.height()-1)) { //записываем значения QColor pixel = image.pixel(x, y); proxArrayR.append(pixel.red()); proxArrayG.append(pixel.green()); proxArrayB.append(pixel.blue()); } else { //если мы за пределами картинки - записываем чёрный цвет proxArrayR.append(0); proxArrayG.append(0); proxArrayB.append(0); } } QColor pixel = image.pixel(curx, cury);//(QColor(0, 0, 0, 255)); //makin a pixel int aveRed = listAverage(proxArrayR); //устанавливаем значение его цветов равным int aveGreen = listAverage(proxArrayG);//среднему арифметическому массива ближайших пикселей int aveBlue = listAverage(proxArrayB); double dispRed = listDisp(proxArrayR, aveRed); //считаем дисперсии значений этих массивов double dispGreen = listDisp(proxArrayG, aveGreen); double dispBlue = listDisp(proxArrayB, aveBlue); if (dispNoise > dispRed) //если значение дисперсии шума выше, чем дисперсия массива окрестности pixel.setRed(aveRed); //фильтр работает как фильтр арифметического среднего if (dispNoise <= dispRed) //иначе значение задается по формуле z' = z - (Dшум/Dz)*(z - u), u - локальное среднее яркости пикселей pixel.setRed(pixel.red()- (dispNoise/dispRed)*(pixel.red()-aveRed)); if (dispNoise > dispGreen) pixel.setGreen(aveGreen); if (dispNoise <= dispGreen) pixel.setGreen(pixel.green()- (dispNoise/dispGreen)*(pixel.green()-aveGreen)); if (dispNoise > dispBlue) pixel.setBlue(aveBlue); if (dispNoise <= dispBlue) pixel.setBlue(pixel.blue()- (dispNoise/dispBlue)*(pixel.blue()-aveBlue)); if ((0 <= curx && curx <= image.width()-1) && (0 <= cury && cury <= image.height()-1)) result.setPixel(curx, cury, pixel.rgb()); //записываем значение в результат }
void Widget::SetColor(double cosDifuse,double cosSpecular) { // qDebug() << cosDifuse; if (cosDifuse < 0) {cosDifuse = 0;} if (cosSpecular < 0) {cosSpecular = 0 ;} double red,green,blue; red = color_anbient.red()/255.0+ cosDifuse*color_diffuse.red()/255.0+ // pow(cosSpecular*color_specular.red()/255.0,intense); cosSpecular*color_specular.red()/255.0; color.setRed(max(0,min(red*255,255))); green = color_anbient.green()/255.0+ cosDifuse*color_diffuse.green()/255.0+ // pow(cosSpecular*color_specular.green()/255.0,intense); cosSpecular*color_specular.green()/255.0; color.setGreen(max(0,min(green*255,255))); blue = color_anbient.blue()/255.0+ cosDifuse*color_diffuse.blue()/255.0+ // pow(cosSpecular*color_specular.blue()/255.0,intense); cosSpecular*color_specular.blue()/255.0; color.setBlue(max(0,min(blue*255,255))); }
static QColor red2yellow2green(qreal x) { QColor color; x = clamp(x, 0.0, 1.0); if (x <= 0.5) { x *= 2; color.setRed(255); color.setGreen(255 * x); } else { x = 2 * x - 1; color.setRed(255 - 255 * x); color.setGreen(255); } return color; }
void QgsColorWidget::alterColor( QColor& color, const QgsColorWidget::ColorComponent component, const int newValue ) const { int h, s, v, a; color.getHsv( &h, &s, &v, &a ); //clip value to sensible range int clippedValue = qMin( qMax( 0, newValue ), componentRange( component ) ); switch ( component ) { case QgsColorWidget::Red: color.setRed( clippedValue ); return; case QgsColorWidget::Green: color.setGreen( clippedValue ); return; case QgsColorWidget::Blue: color.setBlue( clippedValue ); return; case QgsColorWidget::Hue: color.setHsv( clippedValue, s, v, a ); return; case QgsColorWidget::Saturation: color.setHsv( h, clippedValue, v, a ); return; case QgsColorWidget::Value: color.setHsv( h, s, clippedValue, a ); return; case QgsColorWidget::Alpha: color.setAlpha( clippedValue ); return; default: return; } }
static QColor Vec3ToQColor(idVec3 v) { QColor c; c.setRed( static_cast<int>(v.x * 255) ); c.setGreen( static_cast<int>(v.y * 255) ); c.setBlue( static_cast<int>(v.z * 255) ); return c; }
QColor ColorMappingGenerator::GetColor(ColorMappingType color_type, float current_value, float min_value, float max_value){ float value = current_value; if ( value < min_value ) value = min_value; if ( value > max_value ) value = max_value; if ( value < color_index_vec_[color_type][0].value_index ) value = color_index_vec_[color_type][0].value_index; if ( value > color_index_vec_[color_type][color_index_vec_[color_type].size() - 1].value_index ) value = color_index_vec_[color_type][color_index_vec_[color_type].size() - 1].value_index; int current_index = 0; while ( current_index < color_index_vec_[color_type].size() && value > color_index_vec_[color_type][current_index].value_index ) current_index++; if ( current_index == 0 ) return color_index_vec_[color_type][0].color; else { QColor color; if ( is_linear_[color_type] ){ float scale = (color_index_vec_[color_type][current_index].value_index - value) / (color_index_vec_[color_type][current_index].value_index - color_index_vec_[color_type][current_index - 1].value_index); color.setRed(scale * color_index_vec_[color_type][current_index - 1].color.red() + (1.0 - scale) * color_index_vec_[color_type][current_index].color.red()); color.setGreen(scale * color_index_vec_[color_type][current_index - 1].color.green() + (1.0 - scale) * color_index_vec_[color_type][current_index].color.green()); color.setBlue(scale * color_index_vec_[color_type][current_index - 1].color.blue() + (1.0 - scale) * color_index_vec_[color_type][current_index].color.blue()); } else { color = color_index_vec_[color_type][current_index - 1].color; } return color; } }
void RedEyeReductionImageOperation::apply(QImage* img, const QRectF& rectF) { const QRect rect = PaintUtils::containingRect(rectF); const qreal radius = rectF.width() / 2; const qreal centerX = rectF.x() + radius; const qreal centerY = rectF.y() + radius; const Ramp radiusRamp(qMin(double(radius * 0.7), double(radius - 1)), radius, 1., 0.); uchar* line = img->scanLine(rect.top()) + rect.left() * 4; for (int y = rect.top(); y < rect.bottom(); ++y, line += img->bytesPerLine()) { QRgb* ptr = (QRgb*)line; for (int x = rect.left(); x < rect.right(); ++x, ++ptr) { const qreal currentRadius = sqrt(pow(y - centerY, 2) + pow(x - centerX, 2)); qreal alpha = radiusRamp(currentRadius); if (qFuzzyCompare(alpha, 0)) { continue; } const QColor src(*ptr); alpha *= computeRedEyeAlpha(src); int r = src.red(); int g = src.green(); int b = src.blue(); QColor dst; // Replace red with green, and blend according to alpha dst.setRed(int((1 - alpha) * r + alpha * g)); dst.setGreen(int((1 - alpha) * g + alpha * g)); dst.setBlue(int((1 - alpha) * b + alpha * b)); *ptr = dst.rgba(); } } }
QColor KDReports::XmlHelper::readBackground( const QDomElement& element ) { QColor ret; if ( element.hasAttribute( QLatin1String( "background" ) ) ) { const QString name = element.attribute( QLatin1String( "background" ) ); ret = QColor( name ); } else if( element.hasAttribute( QLatin1String( "bgred" ) ) && element.hasAttribute( QLatin1String( "bggreen" ) ) && element.hasAttribute( QLatin1String( "bgblue" ) ) ) { int red = 0, green = 0, blue = 0; bool ok = true; red = element.attribute( QLatin1String( "bgred" ) ).toInt( &ok ); if( ok ) { green = element.attribute( QLatin1String( "bggreen" ) ).toInt( &ok ); if( ok ) { blue = element.attribute( QLatin1String( "bgblue" ) ).toInt( &ok ); if( ok ) { ret.setRed( red ); ret.setGreen( green ); ret.setBlue( blue ); } } } } return ret; }
QColor Viewport::determineColor(const QColor &basecolor, float weight, float totalweight, bool highlighted, bool single) { QColor color = basecolor; qreal alpha; /* TODO: this is far from optimal yet. challenge is to give a good view where important information is not lost, yet not clutter the view with too much low-weight information */ /* logarithm is used to prevent single data points to get lost. this should be configurable. */ alpha = useralpha; if (drawLog->isChecked()) alpha *= (0.01 + 0.99*(std::log(weight+1) / std::log(totalweight))); else alpha *= (0.01 + 0.99*(weight / totalweight)); color.setAlphaF(std::min(alpha, 1.)); // cap at 1 if (highlighted) { if (basecolor == Qt::white) { color = Qt::yellow; } else { color.setGreen(std::min(color.green() + 195, 255)); color.setRed(std::min(color.red() + 195, 255)); color.setBlue(color.blue()/2); } color.setAlphaF(1.); } // recolor singleLabel (and make 100% opaque) if (single) { color.setRgbF(1., 1., 0., 1.); } return color; }
//render the square on the screen void Square::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { QColor color; if(selected) { //if the user clicked it, draw it purple color.setBlue(100); color.setRed(100); color.setGreen(0); } else { //otherwise draw it white color.setBlue(255); color.setRed(255); color.setGreen(255); } painter->setBrush(color); painter->drawRect(xcoor1,ycoor1,xcoor2-xcoor1,ycoor2-ycoor1); }
void MIPS32SyntaxHighlighter::setBackgroundColor(QColor const &color){ MIPS32SyntaxHighlighter::backgroundColor = color; int red = color.red(); int blue = color.blue(); int green = color.green(); int offset = (int)(DEFAULT_COLOR_BACKGROUND_HIGHLIGHT_RATIO * 256.0); if(offset < 0){ if(red+offset < 0){red-=offset;}else{red+=offset;} if(green+offset < 0){green-=offset;}else{green+=offset;} if(blue+offset < 0){blue-=offset;}else{blue+=offset;} }else if(offset > 0){ if(red+offset > 255){red-=offset;}else{red+=offset;} if(green+offset > 255){green-=offset;}else{green+=offset;} if(blue+offset > 255){blue-=offset;}else{blue+=offset;} }else{ //don't change color } QColor tmpColor; tmpColor.setRed(red); tmpColor.setBlue(blue); tmpColor.setGreen(green); MIPS32SyntaxHighlighter::backgroundHighlightColor = tmpColor; }
void EyedropperTool::mouseReleaseEvent(QMouseEvent *event) { Layer* layer = mEditor->layers()->currentLayer(); if (layer == NULL) { return; } if (event->button() == Qt::LeftButton) { if (layer->type() == Layer::BITMAP) { BitmapImage* targetImage = ((LayerBitmap *)layer)->getLastBitmapImageAtFrame( mEditor->currentFrame(), 0); //QColor pickedColour = targetImage->pixel(getLastPoint().x(), getLastPoint().y()); QColor pickedColour; pickedColour.setRgba( targetImage->pixel( getLastPoint().x(), getLastPoint().y() ) ); int transp = 255 - pickedColour.alpha(); pickedColour.setRed( pickedColour.red() + transp ); pickedColour.setGreen( pickedColour.green() + transp ); pickedColour.setBlue( pickedColour.blue() + transp ); if (pickedColour.alpha() != 0) { mEditor->color()->setColor(pickedColour); } } else if (layer->type() == Layer::VECTOR) { VectorImage *vectorImage = ((LayerVector *)layer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0); int colourNumber = vectorImage->getColourNumber(getLastPoint()); if (colourNumber != -1) { mEditor->color()->setColorNumber(colourNumber); } } } }
void Renderer::initialize(xqtgl::window* surface) { m_backgroundColor = QColor::fromRgbF(0.1f, 0.1f, 0.2f, 1.0f); m_backgroundColor.setRed(qrand() % 64); m_backgroundColor.setGreen(qrand() % 128); m_backgroundColor.setBlue(qrand() % 256); }
QColor Style::mergeColors(const QColor &colorA, const QColor &colorB, int factor) const { QColor tmp = colorA; tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor); tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor); tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor); return tmp; }
QColor ColorWidget::TranslateToQColor(const float3 color) { QColor qcolor; qcolor.setRed(color[0]); qcolor.setGreen(color[1]); qcolor.setBlue(color[2]); return qcolor; }
QColor readColor(QDomElement e) { QColor c; c.setRed(e.attribute("r").toInt()); c.setGreen(e.attribute("g").toInt()); c.setBlue(e.attribute("b").toInt()); return c; }
void MainWindow::colorImage() { int x, y; Mat image; QColor color; QFileDialog *dialog = new QFileDialog(); dialog->setNameFilter("PNG Files (*.png)"); dialog->setOption(QFileDialog::ReadOnly); //dialog->setOption(QFileDialog::DontUseNativeDialog); dialog->setDirectory("."); QStringList fileNames; if (dialog->exec()) { fileNames = dialog->selectedFiles(); QString fileName = fileNames.at(0); image = imread(fileName.toStdString(), CV_LOAD_IMAGE_COLOR); for( y=0; y!=image.rows; ++y) { if((y%2) == 0) { for(x=0;x!=image.cols;++x) { color.setBlue(image.data[((y*image.cols)+x)*3]); color.setGreen(image.data[((y*image.cols)+x)*3+1]); color.setRed(image.data[((y*image.cols)+x)*3+2]); motorControl.setLedColor(color); motorControl.commandMotor1(3, -4); } } else { for(x=image.cols-1;x!=-1;--x) { color.setBlue(image.data[((y*image.cols)+x)*3]); color.setGreen(image.data[((y*image.cols)+x)*3+1]); color.setRed(image.data[((y*image.cols)+x)*3+2]); motorControl.setLedColor(color); motorControl.commandMotor1(3, 4); } } motorControl.commandMotor2(6, -4); } color.setRed(0); color.setGreen(0); color.setBlue(0); motorControl.setLedColor(color); motorControl.releaseMotor1(); motorControl.releaseMotor2(); } }
void QtGradientStopsControllerPrivate::slotChangeSaturation(int color) { QColor c = m_ui->saturationColorLine->color(); if (m_ui->hsvRadioButton->isChecked()) c.setHsvF(c.hueF(), (qreal)color / 255, c.valueF(), c.alphaF()); else c.setGreen(color); slotChangeSaturation(c); }
QString QmitkStdMultiWidgetEditor::MitkColorToHex(const mitk::Color& color) { QColor returnColor; float colorMax = 255.0f; returnColor.setRed(static_cast<int>(color[0]* colorMax + 0.5)); returnColor.setGreen(static_cast<int>(color[1]* colorMax + 0.5)); returnColor.setBlue(static_cast<int>(color[2]* colorMax + 0.5)); return returnColor.name(); }
QColor readColor(const QDomElement& e) { QColor c; c.setRed(e.attribute("r").toInt()); c.setGreen(e.attribute("g").toInt()); c.setBlue(e.attribute("b").toInt()); c.setAlpha(e.attribute("a", "255").toInt()); return c; }
void GrBar::hoverLeaveEvent(QGraphicsSceneHoverEvent *pe){ QApplication::restoreOverrideCursor(); QColor color = brushList.at(curIndexBrush).color(); color.setRed( color.red()*2 ); color.setGreen( color.green()*2 ); color.setBlue( color.blue()*2 ); brushList[curIndexBrush].setColor( color ); QGraphicsItem::hoverLeaveEvent( pe ); }
void GrBar::hoverEnterEvent(QGraphicsSceneHoverEvent *pe){ QApplication::setOverrideCursor( Qt::PointingHandCursor ); QColor color = brushList.at(curIndexBrush).color(); color.setRed( color.red()/2 ); color.setGreen( color.green()/2 ); color.setBlue( color.blue()/2 ); brushList[curIndexBrush].setColor( color ); QGraphicsItem::hoverEnterEvent( pe ); }
QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int factor) { const int maxFactor = 100; QColor tmp = colorA; tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor); tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor); tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor); return tmp; }
QColor fromARGBString(const QString &c) { Q_ASSERT(c.length() == 8); QColor color; color.setRed(c.mid(2, 2).toInt(0, 16)); color.setGreen(c.mid(4, 2).toInt(0, 16)); color.setBlue(c.mid(6, 2).toInt(0, 16)); return color; }
private: void setColourForIteration(QColor &farbe, int iter) { if(model->getIterationen() == iter) { farbe.setRed(0); farbe.setGreen(0); farbe.setBlue(0); return; } double anteil = (double)iter / (double)model->getIterationen(); int r = getFarbAnteilMitDif(anteil, farbenMaske[0]); int g = getFarbAnteilMitDif(anteil, farbenMaske[1]); int b = getFarbAnteilMitDif(anteil, farbenMaske[2]); farbe.setRed(r); farbe.setGreen(g); farbe.setBlue(b); }
QColor ZPunctum::highlightingColor(const QColor &color) const { QColor highlight; highlight.setRed(imin2(255, color.red() + 96)); highlight.setGreen(imin2(255, color.green() + 96)); highlight.setBlue(imin2(255, color.blue() + 96)); return highlight; }
// Mix colors a and b with a ratio in the range [0-255] QColor QCommandLinkButtonPrivate::mergedColors(const QColor &a, const QColor &b, int value = 50) const { Q_ASSERT(value >= 0); Q_ASSERT(value <= 255); QColor tmp = a; tmp.setRed((tmp.red() * value) / 255 + (b.red() * (255 - value)) / 255); tmp.setGreen((tmp.green() * value) / 255 + (b.green() * (255 - value)) / 255); tmp.setBlue((tmp.blue() * value) / 255 + (b.blue() * (255 - value)) / 255); return tmp; }
QColor DetailSection::ColorFromString(QString s) { QStringList l= s.split(","); QColor c; c.setRed(l.at(0).toDouble()); c.setGreen(l.at(1).toDouble()); c.setBlue(l.at(2).toDouble()); c.setAlpha(l.at(3).toDouble()); return c; }
bool QSanProtocol::Utils::tryParse(const Json::Value &arg, QColor &color) { if (!arg.isArray() && arg.size() < 3) return false; color.setRed(arg[0].asInt()); color.setGreen(arg[1].asInt()); color.setBlue(arg[2].asInt()); if (arg.size() > 3) color.setAlpha(arg[3].asInt()); else color.setAlpha(255); return true; }
QColor XmlReader::readColor() { Q_ASSERT(tokenType() == QXmlStreamReader::StartElement); QColor c; c.setRed(intAttribute("r")); c.setGreen(intAttribute("g")); c.setBlue(intAttribute("b")); c.setAlpha(intAttribute("a", 255)); skipCurrentElement(); return c; }