uint QColormap::pixel(const QColor &color) const { const QColor c = color.toRgb(); COLORREF rgb = RGB(c.red(), c.green(), c.blue()); if (d->hpal) return PALETTEINDEX(GetNearestPaletteIndex(d->hpal, rgb)); return rgb; }
// Make a color darker if it's too bright QColor make_color_readable(QColor clr) { // Gray if (clr.red() == clr.green() && clr.green() == clr.blue()) { return QColor("black"); } clr = clr.toHsv(); int value = MIN(clr.value(), 150); int saturation = 255; clr.setHsv(clr.hue(), saturation, value, 255); return clr.toRgb(); }
uint QColormap::pixel(const QColor &color) const { const QColor c = color.toRgb(); const uint r = (c.ct.argb.red * d->r_max) >> 16; const uint g = (c.ct.argb.green * d->g_max) >> 16; const uint b = (c.ct.argb.blue * d->b_max) >> 16; if (d->mode != Direct) { if (d->mode == Gray) return d->pixels.at((r * 30 + g * 59 + b * 11) / 100); return d->pixels.at(r * d->g_max * d->b_max + g * d->b_max + b); } return (r << d->r_shift) + (g << d->g_shift) + (b << d->b_shift); }
void Theme::fillDefault() { addToTheme(mFormats, "text", QColor(Qt::black), QColor(Qt::white)); QPalette appPlt(QApplication::palette()); QColor bkg = appPlt.color(QPalette::Base); int value = bkg.value(); if (value > 40) bkg.setHsv(bkg.hue(), bkg.saturation(), value - 11); else bkg.setHsv(bkg.hue(), bkg.saturation(), value + 20); addToTheme(mFormats, "currentLine", QColor(Qt::black), bkg.toRgb()); addToTheme(mFormats, "searchResult", appPlt.color(QPalette::HighlightedText).darker(200), appPlt.color(QPalette::Highlight).darker(200)); addToTheme(mFormats, "matchingBrackets", QColor("#2bc93d"), Qt::yellow, true); addToTheme(mFormats, "mismatchedBrackets", Qt::white, QColor(150,0,0)); addToTheme(mFormats, "evaluatedCode", Qt::black, QColor("#F8A200")); QPalette plt(QApplication::palette()); QColor base = plt.color(QPalette::Base); QColor text = plt.color(QPalette::Text); int shade = (base.red() + base.green() + base.blue() < 380) ? 160 : 100; QColor whitespace_color((base.red() + text.red()) / 2, (base.green() + text.green()) / 2, (base.blue() + text.blue()) / 2); addToTheme(mFormats, "whitespace", whitespace_color); addToTheme(mFormats, "keyword", QColor(0,0,230).lighter(shade), QColor(Qt::transparent), true); addToTheme(mFormats, "built-in", QColor(51,51,191).lighter(shade)); addToTheme(mFormats, "env-var", QColor(140,70,20).lighter(shade)); addToTheme(mFormats, "class", QColor(0,0,210).lighter(shade)); addToTheme(mFormats, "number", QColor(152,0,153).lighter(shade)); addToTheme(mFormats, "symbol", QColor(0,115,0).lighter(shade)); addToTheme(mFormats, "string", QColor(95,95,95).lighter(shade)); addToTheme(mFormats, "char", QColor(0,115,0).lighter(shade)); addToTheme(mFormats, "comment", QColor(191,0,0).lighter(shade)); addToTheme(mFormats, "primitive", QColor(51,51,191).lighter(shade)); addToTheme(mFormats, "lineNumbers", plt.color(QPalette::ButtonText), plt.color(QPalette::Mid)); addToTheme(mFormats, "selection", plt.color(QPalette::HighlightedText), plt.color(QPalette::Highlight)); addToTheme(mFormats, "postwindowtext", plt.color(QPalette::ButtonText)); addToTheme(mFormats, "postwindowerror", QColor(209, 28, 36)); addToTheme(mFormats, "postwindowwarning", QColor(165, 119, 6)); addToTheme(mFormats, "postwindowsuccess", QColor(115, 138, 5)); addToTheme(mFormats, "postwindowemphasis", Qt::black, Qt::transparent, true); }
QColor TCS34725Driver::getCurrentColor() { QByteArray clear = writeThenRead(TCS34725Address_, clear_low, 2); QByteArray red = writeThenRead(TCS34725Address_, red_low, 2); QByteArray green = writeThenRead(TCS34725Address_, green_low, 2); QByteArray blue = writeThenRead(TCS34725Address_, blue_low, 2); clearvalue_ = clear[1] << 8 | clear[0]; redvalue_ = red[1] << 8 | red[0]; greenvalue_ = green[1] << 8 | green[0]; bluevalue_ = blue[1] << 8 | blue[0]; QColor color = QColor(static_cast<quint8>(redvalue_), static_cast<quint8>(greenvalue_), static_cast<quint8>(bluevalue_)); qDebug() << color.toRgb().name(); lastColor_ = color; return color; }
/** * Envia um comando de transição de cor para o arduino. * @param color * Cor destino da transição. * @return * Estado de comunicação com o arduíno. */ bool Arduino::sendColor(const QColor &color) { if(this->port == nullptr) return false; QColor rgb = color.toRgb(); char temp[3]; temp[0]= (char)rgb.red(); temp[1]= (char)rgb.green(); temp[2]= (char)rgb.blue(); qint64 transf = this->port->write(temp, 3); if(transf > 0) { this->recentColor = rgb; return true; } else { return false; } }
void tst_QColor::toRgbNonDestructive() { QColor aColor = QColor::fromRgbF(0.11, 0.22, 0.33, 0.44); QCOMPARE(aColor, aColor.toRgb()); }
void BaseLayer( QImage* img, QImage* canvas, int radius, double strength) /// /// Covers the canvas in large points. Hues are taken from the palette /// but no color distortion is added at this point. /// /// @param img /// The reference image. /// /// @param canvas /// The canvas to store the filtered image. /// /// @param radius /// The radius of the points being used for the pointillism algorithm /// (actual point radius used will be larger for this stage of the algorithm). /// /// @param strength /// The strength of the pointillistic filter, where 1.0 is very strong and 0.0 is very weak. /// /// @return /// Nothing. /// { // Adjust the point radius based on the strength of the filter if(strength < 0.5) { int new_radius = (int)radius*strength*2; if(1.0*new_radius < radius*strength*2) new_radius++; radius = new_radius; if(radius < 3) radius = 3; } // Clear the depth buffer ready for drawing uchar* depth_buffer = new uchar[img->width()*img->height()]; for( int i = 0; i < img->width()*img->height(); i++ ) { depth_buffer[i] = 0; } // Get a poisson disk sampling of the area, and repaint the sampled areas with a brush of small radius int spacing = radius*2; std::vector<QPoint> poisson = ImageProcessing::GetPoissonDisks(canvas->width(), canvas->height(), spacing); while(!poisson.empty()) { QPoint pos = poisson.back(); poisson.pop_back(); // Get the hue at this point and find the closest hue in the color palette QColor hsv = QColor(img->pixel(pos)).toHsv(); int hue = hsv.hue(); int sat = hsv.saturation(); int val = hsv.value(); hue = chevreul[ GetPaletteHuePosition( hue ) ]; // Paint a point of the chosen hue at a random depth value hsv.setHsv(hue, sat, val); int z = rand()%256; DrawRandomCircle(canvas, pos, hsv.toRgb(), radius, z, depth_buffer); } poisson.clear(); delete [] depth_buffer; }
void EdgeLayer(QImage* img, QImage* canvas, int radius, double hue_distortion, double strength) /// /// This final layer repaints over areas determined to be edges in order to bring smaller details /// that have been covered by points back into the picture. The same color distortions are used /// as in the main layer. /// /// @param img /// The reference image. /// /// @param canvas /// The canvas to be painted to. /// /// @param radius /// The radius of the points to be painted. /// /// @param hue_distortion /// Determines the strength of the hue distortion where 1.0 is very distorted and 0.0 is not distorted. /// /// @param strength /// The strength of the pointillistic filter, where 1.0 is very strong and 0.0 is very weak. /// /// @return /// Nothing. /// { hue_distortion = hue_distortion*strength; if( strength < 0.5 ) { int new_radius = (int)radius*strength*2; if( 1.0*new_radius < radius*strength*2 ) new_radius++; radius = new_radius; if( radius < 1 ) radius = 1; } uchar* edges = new uchar[img->width()*img->height()]; ImageProcessing::CannyEdgeDetection( img->bits(), edges, img->width(), img->height(), 4 ); uchar* gray = new uchar[img->width()*img->height()]; ImageProcessing::ConvertToOneChannel( img->bits(), gray, img->width(), img->height()); uchar* smoothed_gray = new uchar[img->width()*img->height()]; int kernel = radius; if(kernel%2 == 0) kernel++; if(kernel < 3) kernel = 3; ImageProcessing::GaussianBlur( gray, smoothed_gray, img->width(), img->height(), 1, kernel ); delete [] gray; // Clear the depth buffer ready for painting uchar* depth_buffer = new uchar[img->width()*img->height()]; for( int i = 0; i < img->width()*img->height(); i++ ) { depth_buffer[i] = 0; } // If there is an edge, find the greatest error in the edge's neighbourhood // and at a new stroke at this point. for( int y = 0; y < img->height(); y++ ) { for( int x = 0; x < img->width(); x++ ) { if( edges[y*img->width() + x] > 0 ) { // Find the brightest and and darkest spots in the neighbourhood int brightest = 0; int darkest = 255; QPoint brightest_pos = QPoint(0, 0); QPoint darkest_pos = QPoint(0, 0); for( int j = y - radius; j <= y + radius; j++ ) { for( int i = x - radius; i <= x + radius; i++ ) { if( i >= 0 && j >= 0 && i < img->width() && j < img->height() ) { int intensity = smoothed_gray[j*img->width() + i]; if(intensity > brightest) { brightest_pos = QPoint(i, j); brightest = intensity; } if(intensity < darkest) { darkest_pos = QPoint(i, j); darkest = intensity; } } } } // For each position in the neighbourhood, find if most spots // are closer to the brightest or darkest int dark = 0; int bright = 0; for( int j = y - radius; j <= y + radius; j++ ) { for( int i = x - radius; i <= x + radius; i++ ) { if( i >= 0 && j >= 0 && i < img->width() && j < img->height() ) { int intensity = smoothed_gray[j*img->width() + i]; int bright_diff = brightest - intensity; int dark_diff = intensity - darkest; if(bright_diff < dark_diff) { bright++; } else { dark++; } } } } // Paint at the side that needs defining QPoint new_point; if(bright < dark && bright != 0) { new_point = brightest_pos; } else if(dark != 0) { new_point = darkest_pos; } else { new_point = QPoint(x, y); } // Paint circle at this position QColor hsv = QColor(img->pixel( new_point )).toHsv(); int hue = hsv.hue(); int val = hsv.value(); int sat = hsv.saturation(); // Find closest hue in palette int new_pos = GetPaletteHuePosition( hsv.hue() ); if( ( rand()%100)/100.0 < strength ) { hue = GetRandomNeighbour( new_pos ); } else { hue = chevreul[new_pos]; } // Hue distortion double r = ( rand()%100 )/100.0; if( ( r < hue_distortion && new_pos != 8 ) || r < hue_distortion/3 ) { int n = ChangeHue(smoothed_gray[new_point.y()*img->width() + new_point.x()]/256.0)*2; if( n > -1 ) { new_pos = n; if( sat < 70 && val < 0.3 ) sat = 70; } hue = chevreul[new_pos]; } sat = ChangeSaturation( sat, val, 0.35*strength, strength ); int z = rand()%256; hsv.setHsv( hue, sat, val ); DrawRandomCircle( canvas, new_point, hsv.toRgb(), radius - 1, z, depth_buffer ); } } } delete [] smoothed_gray; delete [] edges; delete [] depth_buffer; }
void MainLayer( QImage* img, QImage* canvas, int radius, double strength ) /// /// Paint the main pointillism layer, adding smaller details and more color distortion. /// Points are painted where the color error between the canvas and the original image /// is high. Color difference is based on color intensity (i.e. brightness) to avoid /// difference due to hue distortion. Saturation distortion and divisionism are applied /// in addition to palette restriction. /// /// @param img /// The reference image. /// /// @param canvas /// The canvas to be painted to. /// /// @param radius /// The radius of the points being painted. /// /// @param strength /// The strength of the pointillistic filter, where 1.0 is very strong and 0.0 is very weak. /// /// @return /// Nothing. /// { // Adjust the point radius based on the strength of the filter if(strength < 0.5) { int new_radius = (int)radius*strength*2; if(1.0*new_radius < radius*strength*2) new_radius++; radius = new_radius; if(radius < 1) radius = 1; } // Get gray scale of original image uchar* gray = new uchar[img->width()*img->height()]; ImageProcessing::ConvertToOneChannel( img->bits(), gray, img->width(), img->height() ); // Blur the grayscale image uchar* smoothed_gray = new uchar[img->width()*img->height()]; int kernel = radius; if(kernel%2 == 0) kernel++; if(kernel < 3) kernel = 3; ImageProcessing::GaussianBlur( gray, smoothed_gray, img->width(), img->height(), 1, kernel ); delete [] gray; // Clear the depth buffer ready for painting uchar* depth_buffer = new uchar[img->width()*img->height()]; for( int i = 0; i < img->width()*img->height(); i++ ) { depth_buffer[i] = 0; } // At each grid point, find maximum error based on difference // between intensity at canvas and intensity of blurred image // Paint stroke at this location for( int y = (int)radius/2; y < img->height(); y += radius ) { for( int x = (int)radius/2; x < img->width(); x += radius ) { int total_error = 0; int max_error = 0; QPoint max_error_at = QPoint(0, 0); // Get error of each pixel in the neighbourhood int min_x = x - radius/2; int min_y = y - radius/2; int max_x = x + radius/2; int max_y = y + radius/2; if(min_x < 0) min_x = 0; if(min_y < 0) min_y = 0; if(max_x >= img->width()) max_x = img->width() - 1; if(max_y >= img->height()) max_y = img->height() - 1; for( int j = min_y; j <= max_y; j++ ) { for( int i = min_x; i <= max_x; i++ ) { // Get error at this pixel int intensity = QColor(canvas->pixel( i, j )).toHsv().value(); int error = abs(intensity - smoothed_gray[j*img->width() + i]); // Update error stats total_error += error; if( error > max_error ) { max_error = error; max_error_at = QPoint( i, j ); } } } // If the total error is above a threshold // Paint a stroke at the area of max error if( total_error > 10*strength ) { QColor hsv = QColor(img->pixel( x, y )).toHsv(); int hue = hsv.hue(); int sat = hsv.saturation(); int v = hsv.value(); // Find closest hue in palette, make a method that does this int new_pos = GetPaletteHuePosition( hsv.hue() ); if( (rand()%100)/100.0 < strength ) { hue = GetRandomNeighbour(new_pos); } else { hue = chevreul[new_pos]; } sat = ChangeSaturation(sat, v, 0.35*strength, strength); hsv.setHsv( hue, sat, v ); int z = rand()%256; DrawRandomCircle(canvas, max_error_at, hsv.toRgb(), radius, z, depth_buffer); } } } delete [] smoothed_gray; delete [] depth_buffer; }
void Manager::initDefaults() { QPalette appPlt( QApplication::palette() ); beginGroup("IDE"); setDefault("startWithSession", "last"); beginGroup("interpreter"); setDefault("autoStart", true); endGroup(); setDefault("postWindow/scrollback", 1000); beginGroup("editor"); setDefault("spaceIndent", false); setDefault("indentWidth", 4); setDefault("stepForwardEvaluation", false); setDefault("lineWrap", true); setDefault("disableBlinkingCursor", false); setDefault("highlightBracketContents", true); setDefault("inactiveEditorFadeAlpha", 64); setDefault("insertMatchingTokens", false); setDefault("blinkDuration", 600); setDefault("font/family", "monospace"); setDefault("font/antialias", true); beginGroup("colors"); QTextCharFormat matchingBracketsFormat; matchingBracketsFormat.setForeground(Qt::red); matchingBracketsFormat.setBackground(QColor("#ffff7f")); matchingBracketsFormat.setFontWeight(QFont::Bold); setDefault("matchingBrackets", QVariant::fromValue(matchingBracketsFormat)); QTextCharFormat bracketMismatchFormat; bracketMismatchFormat.setBackground(QColor(150,0,0)); bracketMismatchFormat.setForeground(Qt::white); setDefault("mismatchedBrackets", QVariant::fromValue(bracketMismatchFormat)); QTextCharFormat evaluatedCodeFormat; evaluatedCodeFormat.setBackground(QColor("#F8A200")); evaluatedCodeFormat.setForeground(Qt::black); setDefault("evaluatedCode", QVariant::fromValue(evaluatedCodeFormat)); QTextCharFormat currentLineFormat; { QColor bkg = appPlt.color(QPalette::Base); int value = bkg.value(); if (value > 40) bkg.setHsv( bkg.hue(), bkg.saturation(), value - 11); else bkg.setHsv( bkg.hue(), bkg.saturation(), value + 20 ); currentLineFormat.setBackground(bkg.toRgb()); } setDefault("currentLine", QVariant::fromValue(currentLineFormat)); QTextCharFormat searchResultFormat; searchResultFormat.setBackground(appPlt.color(QPalette::Highlight).darker(200)); searchResultFormat.setForeground(appPlt.color(QPalette::HighlightedText).darker(200)); setDefault("searchResult", QVariant::fromValue(searchResultFormat)); endGroup(); // colors beginGroup("highlighting"); initHighlightingDefaults(); endGroup(); // highlighting endGroup(); // editor endGroup(); // IDE }
void ColorInspector::setColor(QColor newColor) { // this is a UI update function, never emit any signals // grab the color from color manager, and then update itself, that's it. // compare under the same color spec newColor = (isRgbColors) ? newColor.toRgb() : newColor.toHsv(); if (newColor == mCurrentColor) { return; } if(isRgbColors) { QSignalBlocker b1(ui->red_slider); QSignalBlocker b2(ui->green_slider); QSignalBlocker b3(ui->blue_slider); QSignalBlocker b4(ui->alpha_slider); ui->red_slider->setRgb(newColor); ui->green_slider->setRgb(newColor); ui->blue_slider->setRgb(newColor); ui->alpha_slider->setRgb(newColor); QSignalBlocker b5(ui->RedspinBox); QSignalBlocker b6(ui->GreenspinBox); QSignalBlocker b7(ui->BluespinBox); QSignalBlocker b8(ui->AlphaspinBox); ui->RedspinBox->setValue(newColor.red()); ui->GreenspinBox->setValue(newColor.green()); ui->BluespinBox->setValue(newColor.blue()); ui->AlphaspinBox->setValue(newColor.alpha()); } else { QSignalBlocker b1(ui->red_slider); QSignalBlocker b2(ui->green_slider); QSignalBlocker b3(ui->blue_slider); QSignalBlocker b4(ui->alpha_slider); ui->red_slider->setHsv(newColor); ui->green_slider->setHsv(newColor); ui->blue_slider->setHsv(newColor); ui->alpha_slider->setHsv(newColor); QSignalBlocker b5(ui->RedspinBox); QSignalBlocker b6(ui->GreenspinBox); QSignalBlocker b7(ui->BluespinBox); QSignalBlocker b8(ui->AlphaspinBox); ui->RedspinBox->setValue(newColor.hsvHue()); ui->GreenspinBox->setValue(qRound(newColor.hsvSaturation() / 2.55)); ui->BluespinBox->setValue(qRound(newColor.value() / 2.55)); ui->AlphaspinBox->setValue(qRound(newColor.alpha() / 2.55)); } mCurrentColor = newColor; QPalette p1 = ui->colorWrapper->palette(), p2 = ui->color->palette(); p1.setBrush(QPalette::Background, QBrush(QImage(":/background/checkerboard.png"))); p2.setColor(QPalette::Background, mCurrentColor); ui->colorWrapper->setPalette(p1); ui->color->setPalette(p2); update(); }