示例#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 ) );
}
示例#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);
}
示例#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;
}
示例#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();
 }
示例#5
0
QString CColor::toString ( void ) const
{
	return ( QString::number ( getRed()   ) + QString ( " " ) +
		     QString::number ( getGreen() ) + QString ( " " ) +
		     QString::number ( getBlue()  ) + QString ( " " ) +
		     QString::number ( getAlpha() ) );
}
示例#6
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));
 }
示例#7
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;
}
示例#8
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 );
}
示例#9
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));
 }
示例#10
0
INT_PTR TquantPage::msgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg) {
        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                case IDC_ED_Q_I_MIN:
                case IDC_ED_Q_I_MAX:
                case IDC_ED_Q_P_MIN:
                case IDC_ED_Q_P_MAX:
                case IDC_ED_Q_B_MIN:
                case IDC_ED_Q_B_MAX:
                case IDC_ED_Q_MB_MIN:
                case IDC_ED_Q_MB_MAX:
                    if (HIWORD(wParam) == EN_CHANGE && !isSetWindowText) {
                        HWND hed = GetDlgItem(m_hwnd, LOWORD(wParam));
                        if (hed != GetFocus()) {
                            return FALSE;
                        }
                        repaint(hed);
                        switch (LOWORD(wParam)) {
                            case IDC_ED_Q_I_MIN :
                                eval(hed, parent->qmin, parent->qmax, IDFF_enc_q_i_min);
                                break;
                            case IDC_ED_Q_I_MAX :
                                eval(hed, parent->qmin, parent->qmax, IDFF_enc_q_i_max);
                                break;
                        }
                        return TRUE;
                    }
                    break;
            }
            break;
        case WM_CTLCOLOREDIT: {
            HWND hwnd = HWND(lParam);
            bool ok;
            switch (getId(hwnd)) {
                case IDC_ED_Q_I_MIN:
                case IDC_ED_Q_I_MAX:
                    ok = eval(hwnd, parent->qmin, parent->qmax);
                    break;
                default:
                    goto colorEnd;
            }
            if (!ok) {
                HDC dc = HDC(wParam);
                SetBkColor(dc, RGB(255, 0, 0));
                return INT_PTR(getRed());
            } else {
                return FALSE;
            }
colorEnd:
            ;
        }
    }
    return TconfPageEnc::msgProc(uMsg, wParam, lParam);
}
示例#11
0
INT_PTR TquantTablesPageBase::msgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg) {
        case WM_COMMAND:
            if (HIWORD(wParam)==EN_CHANGE && !isSetWindowText) {
                HWND hed=GetDlgItem(m_hwnd,LOWORD(wParam));
                if (hed!=GetFocus()) {
                    return FALSE;
                }
                repaint(hed);
                TwidgetMatrix *item=(TwidgetMatrix*)Twidget::getDlgItem(hed);
                if (item->id) {
                    int valI;
                    if (eval(hed,1,255,&valI)) {
                        uint8_t *intra8,*inter8,*intra4Y,*inter4Y,*intra4C,*inter4C;
                        getCustomQuantMatrixes(&intra8,&inter8,&intra4Y,&inter4Y,&intra4C,&inter4C);
                        uint8_t *intra,*inter;
                        switch (cbxGetCurSel(IDC_CBX_QUANT_TABLE)) {
                            case 1:
                                intra=intra4Y;
                                inter=inter4Y;
                                break;
                            case 2:
                                intra=intra4C;
                                inter=inter4C;
                                break;
                            default:
                                intra=intra8;
                                inter=inter8;
                                break;
                        }
                        (item->intra?intra:inter)[item->id-1]=(uint8_t)valI;
                        setChange();
                    }
                }
                return TRUE;
            }
            break;
        case WM_CTLCOLOREDIT: {
            HWND hwnd=HWND(lParam);
            if (hwnd==GetDlgItem(m_hwnd,IDC_CBX_QUANT_TABLE)) {
                break;
            }
            bool ok=eval(hwnd,1,255);
            if (!ok) {
                HDC dc=HDC(wParam);
                SetBkColor(dc,RGB(255,0,0));
                return INT_PTR(getRed());
            } else {
                return FALSE;
            }
        }
    }
    return Twindow::msgProc(uMsg,wParam,lParam);
}
示例#12
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;
}
示例#13
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);
    }
}
示例#14
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;
}
示例#15
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();
}
示例#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;
}
示例#17
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();
}
示例#18
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;
}
示例#19
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;
}
示例#20
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;
}
示例#21
0
文件: Vertex.cpp 项目: alwalker/TTU
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;
}
示例#22
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;
 }
示例#23
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();        
}
示例#24
0
文件: Vertex.cpp 项目: alwalker/TTU
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;
}
示例#25
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;
		}
	}
}
示例#26
0
文件: main.c 项目: hluk/red
void processMessages(int sock)
{
    const int sz = strlen(command) + BUFFER_SIZE;
    struct sockaddr_in cli_addr;
    char buffer[sz];
    char arg[BUFFER_SIZE];
    int red = RED_MAX;
    NotifyNotification *notification = NULL;
    while(1) {
        socklen_t clilen = sizeof(cli_addr);
        int newsock = accept(sock, (struct sockaddr *)&cli_addr, &clilen);
        if (newsock < 0)
            die("Cannot accept connection");

        int n = read(newsock, arg, BUFFER_SIZE);
        if (n < 0)
            die("Cannot read from socket");
        else if (n == 0)
            break;

        arg[n] = '\0';
        int num = getRed(arg, red, RED_MIN, RED_MAX);
        if (snprintf(buffer, sz, command, num) > 0) {
            red = num;
            system(buffer);
            // FIXME: Sometimes gives error:
            //        GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name :1.167 was not provided by any .service files
            if (notify(&notification, red, RED_MIN, RED_MAX) == -1) {
                notifyUninit(&notification);
                notifyInit(&notification);
                notify(&notification, red, RED_MIN, RED_MAX);
            }
        }
        close(newsock);
    };

    notifyUninit(&notification);
}
示例#27
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;
			}
		}
	}
示例#28
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;
}
示例#29
0
void PoolColor::saveState(SaveGame *state) const {
	state->writeByte(getRed());
	state->writeByte(getGreen());
	state->writeByte(getBlue());
}
示例#30
0
void PoolColor::restoreState(SaveGame *state) {
	getRed() = state->readByte();
	getGreen() = state->readByte();
	getBlue() = state->readByte();
}