void BinaryFormatter::writeAttr(std::ostream& into, const SumoXMLAttr attr, const RGBColor& val) { BinaryFormatter::writeAttrHeader(into, attr, BF_COLOR); FileHelpers::writeByte(into, val.red()); FileHelpers::writeByte(into, val.green()); FileHelpers::writeByte(into, val.blue()); FileHelpers::writeByte(into, val.alpha()); }
void EffectsGenerator::gradientSigmoidTransition(int transitionSize, std::string &os) { RGBColor tempColor; for (int j = 0; j < (int)colors.size() - 1; j++) { vector<double> RedOperations = SigmoidCalculator(0, transitionSize, colors[j].getR(), colors[j + 1].getR()); vector<double> GreenOperations = SigmoidCalculator(0, transitionSize, colors[j].getG(), colors[j + 1].getG()); vector<double> BlueOperations = SigmoidCalculator(0, transitionSize, colors[j].getB(), colors[j + 1].getB()); for (int i = 0; i < transitionSize; i++) { tempColor.calculateColor(RedOperations,GreenOperations,BlueOperations,i); //Envoyer les valeurs aux leds, ajouter un delais ou changer le transitionSize os += to_string(tempColor.getR()) + " " + to_string(tempColor.getG()) + " " + to_string(tempColor.getB()) + " "; //A remplacer par: //sendColorToServer(tempColor.getR(),tempColor.getG(),tempColor.getB()) } } }
void TetrisWidget::drawTextRightAligned(const Rect & inRect, const std::string & inText, int inFontSize, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); QPainter & painter(*mPainter); painter.setPen(QColor(inColor.red(), inColor.green(), inColor.blue())); // Paint the stats title QFont textFont(painter.font()); textFont.setPointSize(inFontSize); textFont.setBold(true); painter.setFont(textFont); int textWidth = painter.fontMetrics().width(inText.c_str()); int textHeight = painter.fontMetrics().height(); int x = inRect.right() - textWidth - margin(); int y = inRect.top() + (inRect.height() - textHeight)/2; drawText(x, y, inText); }
RGBColor MultiObjects::TraceRay(const Ray& ray) const { HitRec sr(*world); double t; double tmin = FLT_MAX; GeometricObject* obj_min = nullptr; HitRec sr_min(*world); for (auto obj : world->GetObjects()) { if (obj->Hit(ray, t, sr)) { if (t < tmin) { tmin = t; obj_min = obj; sr_min = sr; } } } if (obj_min != nullptr) { RGBColor col = AssetStore::Instance().GetMaterials().get(qui::Hash(obj_min->GetMaterial().c_str()).value)->shade(sr_min); col.Clamp(); return col; } return RGBColor::black; }
void GUIPerson::drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const { glPushName(getGlID()); glPushMatrix(); glTranslated(0, 0, getType() - .1); // don't draw on top of other cars if (hasActiveAddVisualisation(parent, VO_SHOW_WALKINGAREA_PATH)) { drawAction_drawWalkingareaPath(s); } if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) { if (getCurrentStageType() == MOVING_WITHOUT_VEHICLE) { setColor(s); RGBColor current = GLHelper::getColor(); RGBColor darker = current.changedBrightness(-51); GLHelper::setColor(darker); MSPersonStage_Walking* stage = dynamic_cast<MSPersonStage_Walking*>(getCurrentStage()); assert(stage != 0); const SUMOReal exaggeration = s.personSize.getExaggeration(s); const ConstMSEdgeVector& edges = stage->getRoute(); for (ConstMSEdgeVector::const_iterator it = edges.begin(); it != edges.end(); ++it) { GUILane* lane = static_cast<GUILane*>((*it)->getLanes()[0]); GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration); } } } glPopMatrix(); glPopName(); }
void TetrisWidget::drawTextCentered(const Rect & inRect, const std::string & inText, int inFontSize, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); QPainter & painter(*mPainter); // Set the new pen painter.setPen(QColor(inColor.red(), inColor.green(), inColor.blue())); // Paint the stats title QFont textFont(painter.font()); textFont.setPointSize(inFontSize); textFont.setBold(true); painter.setFont(textFont); int textWidth = painter.fontMetrics().width(inText.c_str()); int textHeight = painter.fontMetrics().height(); int x = inRect.left() + (inRect.width() - textWidth)/2; int y = inRect.top() + (inRect.height() - textHeight)/2; QRect theTextRect(x, y, game()->gameGrid().columnCount() * squareWidth(),squareHeight()); painter.drawText(theTextRect, inText.c_str()); }
void TetrisWidget::paintSquare(const Rect & inRect, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); QColor color(inColor.red(), inColor.green(), inColor.blue()); int x = inRect.x(); int y = inRect.y(); int width = inRect.width(); int height = inRect.height(); mPainter->fillRect(x + 1, y + 1, width - 2, height - 2, color); mPainter->setPen(color.light()); mPainter->drawLine(x, y + height - 1, x, y); mPainter->drawLine(x, y, x + width - 1, y); mPainter->setPen(color.dark()); mPainter->drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1); mPainter->drawLine(x + width - 1, y + height - 1, x + width - 1, y + 1); }
void Bitmap::SetPixel(int x, int y, const RGBColor &c) { CheckCoordinates(x, y); data_[y * bi_.width + x].red = c.r(); data_[y * bi_.width + x].green = c.g(); data_[y * bi_.width + x].blue = c.b(); return; }
/* Test the method 'interpolate'*/ TEST(RGBColor, test_interpolate) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(3,4,1); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0.5); EXPECT_EQ(2, colorResult.red()); EXPECT_EQ(3, colorResult.green()); EXPECT_EQ(2, colorResult.blue()); }
JSValue jsRGBColorBlue(ExecState* exec, JSValue slotBase, const Identifier&) { JSRGBColor* castedThis = static_cast<JSRGBColor*>(asObject(slotBase)); UNUSED_PARAM(exec); RGBColor* imp = static_cast<RGBColor*>(castedThis->impl()); JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->blue())); return result; }
/* Test the method 'interpolate'*/ TEST(RGBColor, test_interpolate) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(2,4,2); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0.5); EXPECT_FLOAT_EQ(SUMOReal(1.5), colorResult.red()); EXPECT_FLOAT_EQ(SUMOReal(3), colorResult.green()); EXPECT_FLOAT_EQ(SUMOReal(2.5), colorResult.blue()); }
void Bitmap::SetPixelImageCoordinates(int i, int j, const RGBColor &c) { CheckImageCoordinates(i, j); const int image_coordinates_i = height_ - i - 1; data_[image_coordinates_i * width_ + j].red = c.r(); data_[image_coordinates_i * width_ + j].green = c.g(); data_[image_coordinates_i * width_ + j].blue = c.b(); return; }
/* Test the method 'interpolate' with a weight of 1 and higher*/ TEST(RGBColor, test_interpolate_weight_1) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(2,4,2); RGBColor colorResult = RGBColor::interpolate(color1, color2, 1); RGBColor colorResult2 = RGBColor::interpolate(color1, color2, 1000); EXPECT_TRUE(colorResult==colorResult2); EXPECT_FLOAT_EQ(SUMOReal(2), colorResult.red()); EXPECT_FLOAT_EQ(SUMOReal(4), colorResult.green()); EXPECT_FLOAT_EQ(SUMOReal(2), colorResult.blue()); }
/* Test the method 'interpolate' with a weight of 0 and lower*/ TEST(RGBColor, test_interpolate_weight_0) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(2,4,2); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0); RGBColor colorResult2 = RGBColor::interpolate(color1, color2, -1000); EXPECT_TRUE(colorResult==colorResult2); EXPECT_EQ(1, colorResult.red()); EXPECT_EQ(2, colorResult.green()); EXPECT_EQ(3, colorResult.blue()); }
void TetrisWidget::drawLine(int x1, int y1, int x2, int y2, int inPenWidth, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); mPainter->setPen(QColor(inColor.red(), inColor.green(), inColor.blue())); mPainter->drawLine(x1, y1, x2, y2); }
/* Test the method 'interpolate' with a weight of 1 and higher*/ TEST(RGBColor, test_interpolate_weight_1) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(3,4,1); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0.5); RGBColor colorResult1 = RGBColor::interpolate(color1, color2, 0); RGBColor colorResult2 = RGBColor::interpolate(color1, color2, 1); EXPECT_TRUE(color1==colorResult1); EXPECT_TRUE(color2==colorResult2); EXPECT_EQ(2, colorResult.red()); EXPECT_EQ(3, colorResult.green()); EXPECT_EQ(2, colorResult.blue()); }
static v8::Handle<v8::Value> blueAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { RGBColor* imp = V8RGBColor::toNative(info.Holder()); RefPtr<CSSPrimitiveValue> result = imp->blue(); v8::Handle<v8::Value> wrapper = result.get() ? v8::Handle<v8::Value>(DOMDataStore::getWrapper(result.get(), info.GetIsolate())) : v8Undefined(); if (wrapper.IsEmpty()) { wrapper = toV8(result.get(), info.Holder(), info.GetIsolate()); if (!wrapper.IsEmpty()) V8DOMWrapper::setNamedHiddenReference(info.Holder(), "blue", wrapper); } return wrapper; }
RGB24Buffer * alphaBlend(RGB24Buffer *in1, RGB24Buffer *in2, G8Buffer *alpha) { RGB24Buffer *result = new RGB24Buffer(in1->getSize()); for (int i = 0; i < result->h; i++) { for (int j = 0; j < result->w; j++) { RGBColor maskEl = in1->element(i,j); RGBColor faceEl = in2->element(i,j); int a = alpha->element(i,j); int b = 255 - a; int r1 = maskEl.r(); int g1 = maskEl.g(); int b1 = maskEl.b(); int r2 = faceEl.r(); int g2 = faceEl.g(); int b2 = faceEl.b(); RGBColor resultEl( (r1 * a + r2 * b) / 255, (g1 * a + g2 * b) / 255, (b1 * a + b2 * b) / 255 ); result->element(i,j) = resultEl; } } return result; }
HSVColor RGB2HSV(const RGBColor & rgb) { double r = rgb.red() / 255.0; double g = rgb.green() / 255.0; double b = rgb.blue() / 255.0; // Calculate chroma double maxColor = Max(r, g, b); double minColor = Min(r, g, b); double chroma = maxColor - minColor; // Calculate hue double hue = 0; if (chroma != 0) { if (maxColor == r) { hue = (g - b / chroma) * 60.0; } else if (maxColor == g) { hue = (2 + (b - r) / chroma) * 60.0; } else // maxColor == b { assert(maxColor == b); hue = (4 + (r - g) / chroma) * 60.0; } if (hue < 0) { hue += 360.0; } assert(hue >= 0 && hue < 360); } double saturation = 0; if (maxColor != 0) { saturation = chroma / maxColor; } assert(saturation >= 0 && saturation <= 1); double value = maxColor; assert(value >= 0 && value <= 1); return HSVColor(static_cast<int>(0.5 + hue), static_cast<int>(0.5 + 100.0 * saturation), static_cast<int>(0.5 + 100.0 * value)); }
void GLHelper::drawTextBox(const std::string& text, const Position& pos, const double layer, const double size, const RGBColor& txtColor, const RGBColor& bgColor, const RGBColor& borderColor, const double angle, const double relBorder, const double relMargin) { if (!initFont()) { return; }; if (bgColor.alpha() != 0) { const double boxAngle = 90; const double stringWidth = size / myFontSize * fonsTextBounds(myFont, 0, 0, text.c_str(), nullptr, nullptr); const double borderWidth = size * relBorder; const double boxHeight = size * (0.32 + 0.6 * relMargin); const double boxWidth = stringWidth + size * relMargin; glPushMatrix(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glTranslated(pos.x(), pos.y(), layer); glRotated(-angle, 0, 0, 1); Position left(-boxWidth * 0.5, 0); setColor(borderColor); drawBoxLine(left, boxAngle, boxWidth, boxHeight); left.add(borderWidth * 1.5, 0); setColor(bgColor); glTranslated(0, 0, 0.01); drawBoxLine(left, boxAngle, boxWidth - 3 * borderWidth, boxHeight - 2 * borderWidth); glPopMatrix(); } drawText(text, pos, layer + 0.02, size, txtColor, angle); }
void PaintImageWidget::childRepaint(QPaintEvent *event, QWidget *who) { AdvancedImageWidget::childRepaint(event, who); if (mImage.isNull()) { return; } /* Now the points */ QPainter painter(who); for (unsigned i = 0; i < mFeatures.mPoints.size(); i ++) { SelectableGeometryFeatures::Vertex *vertex = mFeatures.mPoints[i]; painter.setPen(vertex->isSelected() ? Qt::red : Qt::green); if (vertex->ownerPath == NULL) { drawCircle(painter, imageToWidgetF(vertex->position), 5); } else { drawSquare(painter, imageToWidgetF(vertex->position), 5); } if (vertex->weight >= 0.0) { RGBColor color = RGBColor::rainbow1(vertex->weight); painter.setPen(QColor(color.r(), color.g(), color.b())); drawCircle(painter, imageToWidgetF(vertex->position), 7); } } for (unsigned i = 0; i < mFeatures.mPaths.size(); i++) { SelectableGeometryFeatures::VertexPath *path = mFeatures.mPaths[i]; painter.setPen(path->mSelected ? Qt::yellow : Qt::green); for (unsigned i = 1; i < path->vertexes.size(); i++) { Vector2dd point1 = path->vertexes[i ]->position; Vector2dd point2 = path->vertexes[i - 1]->position; drawLine(painter, imageToWidgetF(point1), imageToWidgetF(point2)); } } }
void SignalDisplay::DrawSignalField2d( const PaintInfo& p ) { int sampleBegin = 0, sampleEnd = mNumSamples; if( p.updateRgn ) { // We restrict drawing to the actually requested update region. QRect clipRect = p.updateRgn->boundingRect(); sampleBegin = PosToSample( clipRect.left() ); sampleBegin = max( sampleBegin - 1, 0 ); sampleEnd = PosToSample( clipRect.right() + 1 ); sampleEnd = min( sampleEnd + 1, mNumSamples ); } for( int i = 0; i < mNumDisplayChannels; ++i ) { for( int j = sampleBegin; j < sampleEnd; ++j ) { bool draw = true; double dataValue = NormData( i + mTopGroup * mChannelGroupSize, j ); if( dataValue < 0.0 ) dataValue = 0.0; else if( dataValue > 1.0 ) dataValue = 1.0; else if( IsNaN( dataValue ) ) dataValue = 0.0; QRect dotRect( SampleLeft( j ), ChannelTop( i ), SampleRight( j ) - SampleLeft( j ), ChannelBottom( i ) - ChannelTop( i ) ); RGBColor rgb; if( mDisplayColors ) rgb = RGBColor::FromHSV( dataValue - 1.0 / 3.0, 1.0, dataValue ); else rgb = RGBColor::FromHSV( 0.0, 0.0, dataValue ); p.painter->fillRect( dotRect, QColor( rgb.R(), rgb.G(), rgb.B() ) ); } # ifdef _WIN32 ::Sleep( 0 ); # endif // _WIN32 } }
void TextField::DoPaint( const GUI::DrawContext& inDC, RGBColor inTextColor, RGBColor inBackgroundColor ) { #if USE_QT QPainter* p = inDC.handle.painter; QRect rect( static_cast<int>( inDC.rect.left ), static_cast<int>( inDC.rect.top ), static_cast<int>( inDC.rect.right - inDC.rect.left ), static_cast<int>( inDC.rect.bottom - inDC.rect.top ) ); QBrush brush; brush.setStyle( Qt::SolidPattern ); if( mColor != RGBColor( RGBColor::NullColor ) ) { QColor backColor( mColor.R(), mColor.G(), mColor.B() ); brush.setColor( backColor ); p->fillRect( rect, brush ); } QFont font; font.fromString( QString( "Arial" ) ); font.setPixelSize( static_cast<int>( mTextHeight * ( inDC.rect.bottom - inDC.rect.top ) ) ); font.setBold( true ); QColor textColor( inTextColor.R(), inTextColor.G(), inTextColor.B() ); QPen pen; brush.setColor( textColor ); pen.setColor( textColor ); p->setPen( pen ); p->setBrush( brush ); p->setFont( font ); QString text = QString::fromLocal8Bit( mText.c_str() ); text.append( " " ).prepend( " " ); p->drawText( rect, Qt::AlignCenter, text ); #endif // USE_QT }
bool TraCIServer::readTypeCheckingColor(tcpip::Storage& inputStorage, RGBColor& into) { if (inputStorage.readUnsignedByte() != TYPE_COLOR) { return false; } unsigned char r = static_cast<unsigned char>(inputStorage.readUnsignedByte()); unsigned char g = static_cast<unsigned char>(inputStorage.readUnsignedByte()); unsigned char b = static_cast<unsigned char>(inputStorage.readUnsignedByte()); unsigned char a = static_cast<unsigned char>(inputStorage.readUnsignedByte()); into.set(r, g, b, a); return true; }
void SignalDisplay::DrawChannelLabels( const PaintInfo& p ) { p.painter->setFont( p.labelFont ); if( mShowChannelLabels && mChannelGroupSize > 1 ) { // Draw channel labels when channels don't coincide with groups. p.painter->setBackground( p.backgroundColor ); p.painter->setBackgroundMode( Qt::OpaqueMode ); QRect legendRect; for( size_t i = 0; i < mChannelLabels.size(); ++i ) { RGBColor textColor = ChannelColor( mChannelLabels[ i ].Address() ); if( mInverted && textColor == RGBColor::White ) textColor = RGBColor::Black; p.painter->setPen( QColor( textColor.R(), textColor.G(), textColor.B() ) ); p.painter->drawText( legendRect, Qt::TextSingleLine | Qt::AlignLeft | Qt::TextDontClip, mChannelLabels[ i ].Text().c_str() ); legendRect.setTop( legendRect.top() + p.painter->fontMetrics().height() ); } } }
void GLHelper::drawText(const std::string& text, const Position& pos, const double layer, const double size, const RGBColor& col, const double angle, const int align, double width) { if (width <= 0) { width = size; } if (!initFont()) { return; }; glPushMatrix(); glAlphaFunc(GL_GREATER, 0.5); glEnable(GL_ALPHA_TEST); glTranslated(pos.x(), pos.y(), layer); glScaled(width / myFontSize, size / myFontSize, 1.); glRotated(-angle, 0, 0, 1); fonsSetAlign(myFont, align == 0 ? FONS_ALIGN_CENTER | FONS_ALIGN_MIDDLE : align); fonsSetColor(myFont, glfonsRGBA(col.red(), col.green(), col.blue(), col.alpha())); fonsDrawText(myFont, 0., 0., text.c_str(), nullptr); glPopMatrix(); }
bool operator()(RGB24Buffer *buffer, int x, int y) { if (mMask->element(y,x) == 255) return false; if (!mLimit.contains(x,y)) return false; RGBColor currentColor = buffer->element(y,x); for (unsigned i = 0; i < mStartColor.size(); i++) { RGBColor &color = mStartColor[i]; int r = (int)currentColor.r() - (int)color.r(); int g = (int)currentColor.g() - (int)color.g(); int b = (int)currentColor.b() - (int)color.b(); int sum = abs(r) + abs(g) + abs(b); if (sum < mTolerance) { return true; } } return false; }
HSVColor::HSVColor(RGBColor color) { float r = color.getR(); float g = color.getG(); float b = color.getB(); float min, max; min = getMin(r, getMin(g, b)); max = getMax(r, getMax(g, b)); if (min == max) h = 0; else if (max == r && g >= b) h = 60.0f*((g-b)/(max-min)) + 0; else if (max == r && g < b) h = 60.0f*((g-b)/(max-min)) + 360; else if (max == g) h = 60.0f*((b-r)/(max-min)) + 120; else if (max == b) h = 60.0f*((r-g)/(max-min)) + 240; if (max == 0) s = 0; else s = 1 - (min/max); v = max; };
QString ScColor::nameRGB(const ScribusDoc* doc) { if ((m_Model != colorModelRGB) && (!doc)) qDebug("calling nameRGB with a cmyk color"); int r, g, b; RGBColor rgb; QString tmp, name = CommonStrings::None; ScColorEngine::getRGBValues(*this, doc, rgb); rgb.getValues(r, g, b); name="#"; tmp.setNum(r, 16); if (tmp.length() < 2) tmp.insert(0, "0"); name += tmp; tmp.setNum(g, 16); if (tmp.length() < 2) tmp.insert(0, "0"); name += tmp; tmp.setNum(b, 16); if (tmp.length() < 2) tmp.insert(0, "0"); name += tmp; return name; }
void BaseMesh::SetColor(RGBColor Color) { MeshVertex *V = Vertices(); UINT vc = VertexCount(); // // rgba to bgra // Color = Color.FlipBlueAndRed(); for(UINT i = 0; i < vc; i++) { V[i].Color = Color; } }