Example #1
0
void Buffer::setPixel( int led, ws2811_led_t c, double alpha ) {
  ws2811_led_t previouscolor = getPixel( led );
  int r = getRed( previouscolor ) * ( 1.0 - alpha ) + getRed( c ) * alpha;
  int g = getGreen( previouscolor ) * ( 1.0 - alpha ) + getGreen( c ) * alpha;
  int b = getBlue( previouscolor ) * ( 1.0 - alpha ) + getBlue( c ) * alpha;
  setPixel( led, color( r, g, b ) );
}
Example #2
0
uint16_t convertRGB888toRGB565(unsigned int color, unsigned int background)
{
	// color is ARGB
	//
	// remove alpha
	uint8_t alpha = getAlpha(color);
	alpha = 0xff;
	float diff = 1.0 - alpha / 255.0;

	uint8_t red = (getRed(color) * (1 - diff)) + getRed(background) * diff;
	uint8_t blue = (getBlue(color) * (1 - diff)) + getBlue(background) * diff;
	uint8_t green = (getGreen(color) * (1 - diff)) + getGreen(background) * diff;

	return (((31 * (red + 4)) / 255) << 11) | (((63 * (green + 2)) / 255) << 5) | ((31 * (blue + 4)) / 255);
}
Example #3
0
ArcVertexData ArcTerrain::getVertexData()
{
  ArcVertexData data;
  int halfSize = mSize / 2;

  for (int i = 0; i < mSize; i++)
  {
    for (int j = 0; j < mSize; j++)
    {
      float value = mMap[i][j];
      float red   = getRed(value);
      float green = getGreen(value);//value / mMaxHeight;//getGreen(value);
      float blue  = getBlue(value);
      ArcVertex vertex = {{(i - halfSize), mMap[i][j], (j - halfSize), 1}, 
			  {red, green, blue, 1}};
      data.addVertex(vertex);
    }
  }
  
  for (int i = 0; i < mSize - 1; i++)
  {
    for (int j = 0; j < mSize - 1; j++)
    {
      data.addIndex(i * mSize + j);
      data.addIndex(i * mSize + j + 1);
      data.addIndex((i + 1) * mSize + j + 1);
      
      data.addIndex(i * mSize + j);
      data.addIndex((i + 1) * mSize + j + 1);
      data.addIndex((i + 1) * mSize + j);
    }
  }
  return data;
}
Example #4
0
 /** From ARGB to RGBA in 4 byte components for endian aware
 passing to OpenGL
 \param dest: address where the 4x8 bit OpenGL color is stored. */
 void toOpenGLColor(unsigned char* dest) const
 {
     *dest =   (unsigned char)getRed();
     *++dest = (unsigned char)getGreen();
     *++dest = (unsigned char)getBlue();
     *++dest = (unsigned char)getAlpha();
 }
Example #5
0
 /** \param other Color to add to this color
 \return Addition of the two colors, clamped to 0..255 values */
 NColor operator+(const NColor& other) const
 {
     return NColor( (std::min)( getAlpha() + other.getAlpha(), 255 ),
                    (std::min)(getRed() + other.getRed(), 255),
                    (std::min)(getGreen() + other.getGreen(), 255),
                    (std::min)(getBlue() + other.getBlue(), 255));
 }
Example #6
0
QString CColor::toString ( void ) const
{
	return ( QString::number ( getRed()   ) + QString ( " " ) +
		     QString::number ( getGreen() ) + QString ( " " ) +
		     QString::number ( getBlue()  ) + QString ( " " ) +
		     QString::number ( getAlpha() ) );
}
Example #7
0
 /** \param other: Other color
 \param d: value between 0.0f and 1.0f
 \return Interpolated color. */
 NColor getInterpolated(const NColor &other, float d) const
 {
     d = math::clamp(d, 0.f, 1.f);
     const float inv = 1.0f - d;
     return NColor((unsigned int)floor(other.getAlpha()*inv + getAlpha()*d),
                   (unsigned int)floor(other.getRed()*inv + getRed()*d),
                   (unsigned int)floor(other.getGreen()*inv + getGreen()*d),
                   (unsigned int)floor(other.getBlue()*inv + getBlue()*d));
 }
Example #8
0
void TCS3200::imprimirValores() //Se usa para imprimir el color que detecta a la pantalla de la computadora
{

 
  Serial.print("verde: ");  
  Serial.println(getGreen(), DEC);  
  

}
Example #9
0
CColor CColor::modulate ( const CColor& color ) const
{
    unsigned char R = static_cast<unsigned char> ( getRed()   * color.getRed()   / 255 );
    unsigned char G = static_cast<unsigned char> ( getGreen() * color.getGreen() / 255 );
    unsigned char B = static_cast<unsigned char> ( getBlue()  * color.getBlue()  / 255 );
    unsigned char A = static_cast<unsigned char> ( getAlpha() * color.getAlpha() / 255 );

    return CColor ( R , G , B , A );
}
Example #10
0
void CColor::toFloat ( float dest[] ) const
{
    dest[0] = getRed() / 255.0f;
    dest[1] = getGreen() / 255.0f;
    dest[2] = getBlue() / 255.0f;
    dest[3] = getAlpha() / 255.0f;

    return;
}
Example #11
0
const CColor& CColor::operator *= ( float k )
{
    int R = static_cast<int> ( getRed() * k );
    int G = static_cast<int> ( getGreen() * k );
    int B = static_cast<int> ( getBlue() * k );
    int A = static_cast<int> ( getAlpha() * k );

    setInt ( R , G , B , A );

    return *this;
}
Example #12
0
void Circle::draw(QPainter *renderArea) {
    if (this->isVisible()){

//        renderArea->setPen(QColor(getRed(),getGreen(),getBlue()));
//        renderArea->setBrush(QBrush(QColor(getRed(),getGreen(),getBlue()),Qt::SolidPattern));
        QColor curr_color(getRed(),getGreen(),getBlue());
        renderArea->setPen(curr_color);
        renderArea->setBrush(QBrush(curr_color,Qt::SolidPattern));
        renderArea->drawEllipse(QPointF(getX(),getY()),radius,radius);
    }
}
Example #13
0
const CColor& CColor::operator -= ( const CColor& color )
{
    int R = getRed()   - color.getRed();
    int G = getGreen() - color.getGreen();
    int B = getBlue()  - color.getBlue();
    int A = getAlpha() - color.getAlpha();

    setInt ( R , G , B , A );

    return *this;
}
Example #14
0
CColor CColor::operator * ( float k ) const
{
    int R = static_cast<int> ( getRed() * k );
    int G = static_cast<int> ( getGreen() * k );
    int B = static_cast<int> ( getBlue() * k );
    int A = static_cast<int> ( getAlpha() * k );

    CColor newc;
    newc.setInt ( R , G , B , A );

    return newc;
}
Example #15
0
CColor CColor::operator - ( const CColor& color ) const
{
    int R = getRed()   - color.getRed();
    int G = getGreen() - color.getGreen();
    int B = getBlue()  - color.getBlue();
    int A = getAlpha() - color.getAlpha();

    CColor newc;
    newc.setInt ( R , G , B , A );

    return newc;
}
Example #16
0
static bool get_named_rgb_internal(const char *name_no_space, int *red, int *green, int *blue)
{
    QByteArray name = QByteArray(name_no_space).toLower();
    const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name.constData());
    if (r != rgbTbl + rgbTblSize) {
        getRed(r->value, red);
        getGreen(r->value, green);
        getBlue(r->value, blue);
        return true;
    }
    return false;
}
Example #17
0
//-----------------------------------------------------------------
void elementVideo::drawRight(int x, int y, int w, int h)
{
    fboRight.begin();
    if (bDrawCalibrationImg) warper.draw(calibrationImg.getTextureReference());
    else warper.draw(getRightTexture());
    fboRight.end();
    
    ofPushStyle();
    ofSetColor(getRed(), getGreen(), getBlue(),int(ofMap(getOpacity(), 0, 1, 0, 255)));
    fboRight.draw(x,y,w,h);
    ofPopStyle();
}
Example #18
0
//-----------------------------------------------------------------
void elementVideo::drawRight(int x, int y, int w, int h)
{
    fboRight.begin();
    if (isWarpable) warper.draw(getRightTexture());
    else rightChannelPlayer.draw(x,y,w,h);	
    fboRight.end();
    
    ofPushStyle();
    ofSetColor(getRed(), getGreen(), getBlue(),int(ofMap(getOpacity(), 0, 1, 0, 255)));
    fboRight.draw(x,y,w,h);
    ofPopStyle();
}
Example #19
0
Color& Color::operator-=( const Color &n )
{
  int red = static_cast<int>( getRed() ) - static_cast<int>( n.getRed() );
  int green = static_cast<int>( getGreen() ) - static_cast<int>( n.getGreen() );
  int blue = static_cast<int>( getBlue() ) - static_cast<int>( n. getBlue() );
  red = ( red < 0 ? 0 : red );
  green = ( green < 0 ? 0 : green );
  blue = ( blue < 0 ? 0 : blue );
  setRed( static_cast<uint8_t>( red ) );
  setGreen( static_cast<uint8_t>( green ) );
  setBlue( static_cast<uint8_t>( blue ) );
  return *this;
}
Example #20
0
Vertex* Vertex::homogenize()
{
   Vertex* result = new Vertex(0, 0, 0);

   result->setX(getX()/getH());
   result->setY(getY()/getH());
   result->setZ(getZ()/getH());
   result->setH(getH());
   result->setRed(getRed());
   result->setGreen(getGreen());
   result->setBlue(getBlue());

   return result;
}
Example #21
0
 int& JColor::getPixel() {
   if (hnd > -1) return hnd;
   JColor *dest = (JColor*)JUNIX::JObjectCache[*this];
   if (!dest) {
     XColor color;
     color.red = getRed() << 8;
     color.green = getGreen() << 8;
     color.blue = getBlue() << 8;
     if (!XAllocColor(JUNIX::theDisplay, JUNIX::theColormap, &color)) 
       color.pixel = WhitePixel(JUNIX::theDisplay, JUNIX::theScreen);
     Allocate(color.pixel);
     JUNIX::JObjectCache.add(*this);
   } else *this = *dest;
   return hnd;
 }
Example #22
0
//-----------------------------------------------------------------
void elementVideo::drawLeft(int x, int y, int w, int h)
{
    
    fboLeft.begin();
    if (bDrawCalibrationImg) warper.draw(calibrationImg.getTextureReference());
    else warper.draw(getLeftTexture());
    
    //    if (isWarpable) warper.draw(getLeftTexture());
//    else leftChannelPlayer.draw(x,y,w,h);	
    fboLeft.end();
    
    ofPushStyle();
    ofSetColor(getRed(), getGreen(), getBlue(),int(ofMap(getOpacity(), 0, 1, 0, 255)));
    fboLeft.draw(x,y,w,h);
    ofPopStyle();        
}
Example #23
0
Vertex* Vertex::multiply(Matrix* matrix)
{
   Vertex* result = new Vertex(0, 0, 0);  

   if (matrix->getNumRows() == 4 && matrix->getNumColumns() == 4)
   {
      Matrix* temp = matrix->multiply(vertex);  //vertex is on the right
      result->setX(temp->getElement(1, 1));
      result->setY(temp->getElement(2, 1));
      result->setZ(temp->getElement(3, 1));
      result->setH(temp->getElement(4, 1));
      result->setRed(getRed());
      result->setGreen(getGreen());
      result->setBlue(getBlue());
      delete temp;
   }

   return result;
}
Example #24
0
void CD3D8Texture::copy16BitMipMap(char* src, char* tgt,
				   s32 width, s32 height,
				   s32 pitchsrc, s32 pitchtgt) const
{
	u16 c;

	for (int x=0; x<width; ++x)
	{
		for (int y=0; y<height; ++y)
		{
			s32 a=0, r=0, g=0, b=0;

			for (int dx=0; dx<2; ++dx)
			{
				for (int dy=0; dy<2; ++dy)
				{
					int tgx = (x*2)+dx;
					int tgy = (y*2)+dy;

					c = *(u16*)((void*)&src[(tgx*2)+(tgy*pitchsrc)]);

					a += getAlpha(c);
					r += getRed(c);
					g += getGreen(c);
					b += getBlue(c);
				}
			}

			a /= 4;
			r /= 4;
			g /= 4;
			b /= 4;

			c = ((a & 0x1) <<15) | ((r & 0x1F)<<10) | ((g & 0x1F)<<5) | (b & 0x1F);
			*(u16*)((void*)&tgt[(x*2)+(y*pitchtgt)]) = c;
		}
	}
}
Example #25
0
	void FeatureCapture::getFeature2(int imIdx)
	{
		auto &markedPlaces = paramPtr->markedPlaces;
		for (auto &blockPlace : markedPlaces)
		{
			int blockRow = blockPlace.first;
			int blockCol = blockPlace.second;
			int red = 0, green = 0, blue = 0;
			for (int eachPixel = 0; eachPixel < blockSize; ++eachPixel)
			{
				red += getRed(blockRow, blockCol, eachPixel);
				green += getGreen(blockRow, blockCol, eachPixel);
				blue += getBlue(blockRow, blockCol, eachPixel);
			}		
			red /= 16;
			green /= 16;
			blue /= 16;
			switch((red*red+green*green+blue*blue)/40000)
			{
			case 0:
				featureMap.insert(std::make_pair(make_tuple(imIdx, blockRow, blockCol, 2), "0"));
				break;
			case 1:
				featureMap.insert(std::make_pair(make_tuple(imIdx, blockRow, blockCol, 2), "1"));				
				break;
			case 2:
				featureMap.insert(std::make_pair(make_tuple(imIdx, blockRow, blockCol, 2), "2"));
				break;
			case 3:
				featureMap.insert(std::make_pair(make_tuple(imIdx, blockRow, blockCol, 2), "3"));
				break;
			case 4:
				featureMap.insert(std::make_pair(make_tuple(imIdx, blockRow, blockCol, 2), "4"));
				break;
			}
		}
	}
Example #26
0
void CVehicleEntity::SetColors(DWORD dwColor1, DWORD dwColor2, DWORD dwColor3, DWORD dwColor4, DWORD dwColor5)
{
	if (!GetGameVehicle())
		return;

	IVehicleColors* VehicleColors = *(IVehicleColors**) (GetGameVehicle()->GetVehicle()->m_pLivery + 4);

	VehicleColors->field_10.red = getRed(dwColor1);
	VehicleColors->field_10.green = getGreen(dwColor1);
	VehicleColors->field_10.blue = getBlue(dwColor1);
	VehicleColors->field_10.color = dwColor4;

	VehicleColors->field_20.red = getRed(dwColor2);
	VehicleColors->field_20.green = getGreen(dwColor2);
	VehicleColors->field_20.blue = getBlue(dwColor2);
	VehicleColors->field_20.color = dwColor4;

	VehicleColors->field_30.red = getRed(dwColor3);
	VehicleColors->field_30.green = getGreen(dwColor3);
	VehicleColors->field_30.blue = getBlue(dwColor3);
	VehicleColors->field_30.color = dwColor4;

	VehicleColors->field_40.red = getRed(dwColor4);
	VehicleColors->field_40.green = getGreen(dwColor4);
	VehicleColors->field_40.blue = getBlue(dwColor4);
	VehicleColors->field_40.color = dwColor4;

	VehicleColors->field_50.red = getRed(dwColor5);
	VehicleColors->field_50.green = getGreen(dwColor5);
	VehicleColors->field_50.blue = getBlue(dwColor5);
	VehicleColors->field_50.color = dwColor4;

	VehicleColors->field_60.red = getRed(dwColor3);
	VehicleColors->field_60.green = getGreen(dwColor3);
	VehicleColors->field_60.blue = getBlue(dwColor3);
	VehicleColors->field_60.color = dwColor4;
}
Example #27
0
void PoolColor::saveState(SaveGame *state) const {
	state->writeByte(getRed());
	state->writeByte(getGreen());
	state->writeByte(getBlue());
}
Example #28
0
void PoolColor::restoreState(SaveGame *state) {
	getRed() = state->readByte();
	getGreen() = state->readByte();
	getBlue() = state->readByte();
}
Example #29
0
uint8_t FramebufferGFX::drawChar(uint8_t c, int16_t xOffset, int16_t yOffset, const FONTSTRUCT* font, uint16_t col) {
  // Step 1: Bound checking
  
  // Step 2: Setup
  uint8_t bpp = font->bpp;
  uint8_t pixelsPerByte = font->pixelsPerByte;
  uint8_t sizeX = font->sizesX[c];
  uint8_t sizeY = font->sizesY[c];
  
  // Special Case: Space
  if (c == 32) {
    return font->spaceWidth;
  }
  
  // Return if character is not supported in this font
  if (sizeX == 0) {
    return 0;
  }
  
  uint16_t dataOffset = font->characterOffsets[c];
  // Mask
  uint8_t mask = 0;
  if (bpp == 1) mask = 0x01;
  if (bpp == 2) mask = 0x03;
  // Color
  uint8_t r = getRed(col);
  uint8_t g = getGreen(col);
  uint8_t b = getBlue(col);
  
  // Step 3: Draw character  
  for (uint16_t y=yOffset; y>yOffset - sizeY; y--) {
    for (uint16_t x=xOffset; x<xOffset + sizeX; x+=pixelsPerByte) {
      uint8_t data = font->fontData[dataOffset];
      for (uint8_t pixel=0; pixel<pixelsPerByte; pixel++) {
        uint8_t colorData = data & mask;
        if (colorData > 0) {
          if (((x + pixel) >= 0) && ((x + pixel) < display->width) && (y >= 0) && (y < display->height)) {
            uint32_t pos = display->fbXY(x + pixel, y);
            if (bpp == 1) {
              // Black/white -- just overwrite existing pixel color with font color
             display->framebuffer[pos] = col;                                    
            } else if (bpp == 2) {
              // 4-bit Greyscale -- blend font with existing background
              if (colorData == 3) {
                display->framebuffer[pos] = col;         
              } else {
                uint16_t existingCol = display->framebuffer[pos];
                uint8_t div = 4 - colorData;  // (0, 1, 2, 3) = (4, 3, 2, 1)
                uint8_t rE = getRed(existingCol);
                uint8_t gE = getGreen(existingCol);
                uint8_t bE = getBlue(existingCol);
                int16_t deltaR = (r - rE) / div;    // These three divisions are expensive
                int16_t deltaG = (g - gE) / div;
                int16_t deltaB = (b - bE) / div;
                uint16_t blendedCol = RGB(r+deltaR, g+deltaG, b+deltaB);
                display->framebuffer[pos] = blendedCol;         
              }
            }
          }
        }
        data = data >> bpp;
      } 
      dataOffset += 1;
    }
  }

  return sizeX;
}
Example #30
0
// Allows an angle to the gradient for extra effect. Angle can be between -60 to 60, in degrees)
// NOTE: This function takes around ~300+ bytes of RAM while it's running.
void FramebufferGFX::gradientRect(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int8_t gAngle, uint16_t col1, uint16_t col2) {
  // Step 0: Position Setup
  int16_t w = x1 - x0;
  int16_t h = y1 - y0;
  int16_t x = x0;
  int16_t y = y0;
  if (x0 > x1) {
    x = x1;
    w = -w;
  }
  if (y0 > y1) {
    y = y1;
    h = -h;
  }
  
  if ((w == 0) || (h == 0)) {
    // Nothing to draw
    return;
  }
  
  if (w >= GRAD_MAXWIDTH) {
    Serial.print("ERROR: FramebufferGFX::gradientRect: width exceeds GRAD_MAXWIDTH (");
    Serial.print(GRAD_MAXWIDTH, DEC);
    Serial.println (").  Gradient rectangle not drawn!");
    fillRect(x0, y0, x1, y1, col1);
    return;
  }    
  
  // Step 1: Gradient computation setup
  uint8_t r1 = getRed(col1);
  uint8_t g1 = getGreen(col1);
  uint8_t b1 = getBlue(col1);
  uint8_t r2 = getRed(col2);
  uint8_t g2 = getGreen(col2);
  uint8_t b2 = getBlue(col2);
  
  int16_t deltaR = 0;
  deltaR = ((r2 - r1) * FPMULT) / w;
  int16_t deltaG = 0;
  deltaG = ((g2 - g1) * FPMULT) / w;
  int16_t deltaB = 0;
  deltaB = ((b2 - b1) * FPMULT) / w;

  // Gradient Angle
  int16_t deltaH = 0;
  if (gAngle != 0) {
    if (gAngle < -60) gAngle = -60;
    if (gAngle > 60) gAngle = 60;
    float gAngleRad = (gAngle / 180.f) * 3.1415926f;
    int16_t dist = (int16_t)floor(tan(gAngleRad) * h);
    deltaH = (dist * FPMULT) / h;
  }

  // Step 2: Precompute gradient
  uint16_t gradient[GRAD_MAXWIDTH];    // Normally you'd use dynamic memory here to allocate width*2bpp,
                                       // But we're going to avoid dynamic memory for safety. 
  int16_t r = r1 * FPMULT;
  int16_t g = g1 * FPMULT;
  int16_t b = b1 * FPMULT;                                         
  for (int i=0; i<w; i++) {
    // Convert colours from fixed-point to uint8_t, and store
    uint8_t rc = (uint8_t)(r / FPMULT);
    uint8_t gc = (uint8_t)(g / FPMULT);
    uint8_t bc = (uint8_t)(b / FPMULT);
    gradient[i] = RGB(rc, gc, bc);
      
    // Increment gradient variables
    r += deltaR;
    g += deltaG;
    b += deltaB;      
  }
  
  // Step 3: Draw gradient
  // (x, y) is lower corner.  draw fill lines from top to bottom.   
  for (int16_t j=0; j<h; j++) {  
    int angleDelta = (deltaH * j) / FPMULT;    
    for (int16_t i=0; i<w; i++) {
      int offset = i + angleDelta;
      if (offset < 0) offset = 0;
      if (offset >= w) offset = w-1;
      drawPixel(x+i, y+j, gradient[offset]);
    }
  }
}