Exemple #1
0
Manipulation::ImageData& Manipulation::masking(ImageData* inputImageData)
{
    int width = inputImageData->width;
    int height = inputImageData->height;
    int channels = inputImageData->channels;
    imageData.width = width;
    imageData.height = height;
    imageData.channels = 4;
    GLubyte* pixels = inputImageData->pixels;
    imageData.pixels = new GLubyte[width* height * 4];
    float h, s, v;
    for(int i = 0; i< height; i++)
    {
        for(int j = 0; j< width; j++)
        {
            imageData.pixels[i*width* 4 +j* 4] = pixels[i*width*channels + j*channels];
            imageData.pixels[i*width* 4 +j* 4 + 1] = pixels[i*width*channels + j*channels + 1];
            imageData.pixels[i*width* 4 +j* 4 + 2] = pixels[i*width*channels + j*channels + 2];
            RGBtoHSV(pixels[i*width*channels + j*channels], pixels[i*width*channels +j*channels +1], pixels[i*width*channels +j*channels +2], h, s, v);
            if(h > 100 && h < 140)
            {
                imageData.pixels[i*width* 4 +j* 4 + 3] = 0;
            }
            imageData.pixels[i*width* 4 +j* 4 + 3] = 255;
        }
    }
    return imageData;
}
Exemple #2
0
int main() {
	init();
	SerialHandler serialHandler(PORT, BAUD_RATE);
	while(true) {
		updatePixels();
		int sumR = 0, sumG = 0, sumB = 0;
		const int x1 = 0, y1 = 0, x2 = SCR_W, y2 = SCR_H, SAMPLES = 5;
		for(int x = x1; x < x2; x += SAMPLES) {
			for(int y = y1; y < y2; y += SAMPLES) {
				Color color = getPixel(x, y);
				sumR += color.r; sumG += color.g; sumB += color.b;
			}
		}
		int totalPixels = ((x2 - x1) * (y2 - y1)) / (SAMPLES * SAMPLES);
		sumR /= totalPixels; sumG /= totalPixels; sumB /= totalPixels;
		int h = 0, s = 0, v = 0;
		RGBtoHSV(sumR, sumG, sumB, &h, &s, &v);
        v = (v * s) / 255;
		s = 255;
		HSVtoRGB(&sumR, &sumG, &sumB, h, s, v);
		serialHandler.writeSerial(sumR, sumG, sumB);
		delay(10);
	}
	deinit();
	return 0;
}
Exemple #3
0
void Window::rgbChanged()
{
    HSVColor hsv = RGBtoHSV(RGBColor((GLfloat)rSlider->value()/255.0f, (GLfloat)gSlider->value()/255.0f, (GLfloat)bSlider->value()/255.0f));

    int h = (int)floor((double)hsv.h);


    hSlider->blockSignals(true);
    sSlider->blockSignals(true);
    vSlider->blockSignals(true);

    // update RGB slider positions
    hSlider->setValue(h);
    sSlider->setValue(hsv.s*100);
    vSlider->setValue(hsv.v*100);

    hSlider->blockSignals(false);
    sSlider->blockSignals(false);
    vSlider->blockSignals(false);

    // update RGB label values
    hLabel->setNum(h);
    sLabel->setNum((double)hsv.s);
    vLabel->setNum((double)hsv.v);

    // update color frame
    setColorFrame(rSlider->value(), gSlider->value(), bSlider->value());

    // signal the glwidget
    emit colorChanged(RGBColor((GLfloat)rSlider->value()/255.0f, (GLfloat)gSlider->value()/255.0f, (GLfloat)bSlider->value()/255.0f));

}
Exemple #4
0
void *DrawClockPicture(double r){
  double dang=3.0;
  void *img;
  DIG *G;
  int L,i;
  double l,fac,ang,dl;
  float h,s,v,vorg;
  float Red,Green,Blue;
  L = r*0.5+1;
  l= L;
  dl = l*0.15;
  fac = atan(1.0)/45.0;
  

  G = (DIG *)kgInitImage(2*L+1,2*L+1,8);
  kgUserFrame(G,-l,-l,l,l);
  ang =0.0;
  dang *= fac;
  kgLineColor(G,3);
  RGBtoHSV(Dred,Dgreen,Dblue,&h,&s,&vorg);
  v =0.75*vorg;
  HSVtoRGB(&Red,&Green,&Blue,h,s,v);
  kgChangeColor(G,251,30,30,30);
  kgChangeColor(G,253,(int)Red,(int)Green,(int)Blue);
   
  if(vorg < 0.9 ) {
       v = vorg*1.4;
       if(v>1.0) v=1.0;
       HSVtoRGB(&Red,&Green,&Blue,h,s,v);
       kgChangeColor(G,252,(int)Red,(int)Green,(int)Blue);
  }
  else kgChangeColor(G,252,250,250,250);
  ang =0.0;
  for(i=0;i<12;i++) {
    DrawMark(G,ang,dang,l,dl,+2.,-2.,251);
    ang += (30*fac);
  }
  ang =0.0;
  for(i=0;i<12;i++) {
    DrawMark(G,ang,dang,l,dl,-1.,0.0,252);
    ang += (30*fac);
  }
#if 1
  ang =0.0;
  for(i=0;i<12;i++) {
    DrawMark(G,ang,dang,l,dl,+1.0,-1.0,253);
    ang += (30*fac);
  }
#endif
  ang =0.0;
  for(i=0;i<12;i++) {
    DrawMark(G,ang,dang,l,dl,0.,0.,DateColor);
    ang += (30*fac);
  }
  img = kgGetResizedImage(G);
  
  kgCloseImage(G);
  return img;
}
Exemple #5
0
void D_GetPlayerColor (int player, float *h, float *s, float *v, FPlayerColorSet **set)
{
	userinfo_t *info = &players[player].userinfo;
	FPlayerColorSet *colorset = NULL;
	uint32 color;
	int team;

	if (players[player].mo != NULL)
	{
		colorset = P_GetPlayerColorSet(players[player].mo->GetClass()->TypeName, info->GetColorSet());
	}
	if (colorset != NULL)
	{
		color = GPalette.BaseColors[GPalette.Remap[colorset->RepresentativeColor]];
	}
	else
	{
		color = info->GetColor();
	}

	RGBtoHSV (RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f,
		h, s, v);

	if (teamplay && TeamLibrary.IsValidTeam((team = info->GetTeam())) && !Teams[team].GetAllowCustomPlayerColor())
	{
		// In team play, force the player to use the team's hue
		// and adjust the saturation and value so that the team
		// hue is visible in the final color.
		float ts, tv;
		int tcolor = Teams[team].GetPlayerColor ();

		RGBtoHSV (RPART(tcolor)/255.f, GPART(tcolor)/255.f, BPART(tcolor)/255.f,
			h, &ts, &tv);

		*s = clamp(ts + *s * 0.15f - 0.075f, 0.f, 1.f);
		*v = clamp(tv + *v * 0.5f - 0.25f, 0.f, 1.f);

		// Make sure not to pass back any colorset in teamplay.
		colorset = NULL;
	}
	if (set != NULL)
	{
		*set = colorset;
	}
}
void ColorSpace::RGBtoHSV (const Mat& src, Mat& dst)
{
	dst.Create (src.SizeObject(), MAT_Tfloat3);
	BYTE*	pbyte = src.data.ptr[0];
	float*	pfloat = dst.data.fl[0];
	int d=0;
	for (int i=0; i<src.SizeObject().Area(); i++, d+=3)
		RGBtoHSV(pbyte[d], pbyte[d+1], pbyte[d+2], &pfloat[d], &pfloat[d+1], &pfloat[d+2]);
}
Exemple #7
0
/** This function converts HSV to RGB 
 * Every parameter is ∈ [0, 255] */
void RGBtoHSV255 (double *r, double *g, double *b, double h, double s, double v) {
	h = (h / 255) * 360;
	s = (s / 255);
	v = (v / 255);
	
	RGBtoHSV(r, g, b, h, s, v);
	
	*r = *r * 255;
	*g = *g * 255;
	*b = *b * 255;
}
void _onMouse( int event, int x, int y, int flags, void* param )
{
    initx = (float)x; 
	inity = (float)y;

    if( event == CV_EVENT_LBUTTONDOWN )
    {
		//カルマンフィルタの初期値
		//kalman.statePre.at<float>(0) = initx;
		//kalman.statePre.at<float>(1) = inity;

		//最初に一回予測
		//cv::Mat prediction = kalman.predict();

		int r,g,b,count;
		int sumR, sumG, sumB;
		r = g = b = sumR = sumG = sumB = 0;
		count=0;

		int sumH, sumS, sumV;
		int _h, _s, _v;
		_h = _s = _v = sumH = sumS = sumV = 0;

  		for(int i=-3;i<3;i++)
			{			
				for(int j=-3;j<3;j++)
				{
					b = capframe.at<cv::Vec3b>(y+j, x+i)[0];
					g = capframe.at<cv::Vec3b>(y+j, x+i)[1];
					r = capframe.at<cv::Vec3b>(y+j, x+i)[2];
					sumR += r;
					sumG += g;
					sumB += b;

					RGBtoHSV(r, g, b, &_h, &_s, &_v);

					sumH += _h;
					sumS += _s;
					sumV += _v;

					count++;
				}
			}

				h = sumH / count;
				s = sumS / count;
				v = sumV / count;
				
				//平均値を検索対象にする
				blue = sumB/count;
				green = sumG/count;
				red = sumR/count;
    }
}
Exemple #9
0
wxColour GetLightColour(wxColour colour)
{
	float H, S, V;
	RGBtoHSV(((float)colour.Red())/256.0,((float)colour.Green())/256.0,((float)colour.Blue())/256.0,&H,&S,&V);
	S-=0.3;
	if (S<0)
		S=0;
	float R,G,B;
	HSVtoRGB(&R,&G,&B,H,S,V);
	wxColour result((unsigned char)(R*255),(unsigned char)(G*255),(unsigned char)(B*255));
	return result;
}
Exemple #10
0
Color GetColorGradient(Color c1, Color c2, int ratio1, int ratio2, double gamma)
{
	double h1, s1, v1;
	double h2, s2, v2;
	RGBtoHSV(pow(c1.GetR() / 255.0, gamma), pow(c1.GetG() / 255.0, gamma), pow(c1.GetB() / 255.0, gamma), h1, s1, v1);
	RGBtoHSV(pow(c2.GetR() / 255.0, gamma), pow(c2.GetG() / 255.0, gamma), pow(c2.GetB() / 255.0, gamma), h2, s2, v2);
	if(s1 == 0)
		h1 = h2;
	else if(s2 == 0)
		h2 = h1;
	double r = ratio1 / (double)ratio2;
	gamma = 1 / gamma;
	if(h2 > h1 + 0.5)
		h1 = ((h1 += (h2 - 1 - h1) * r) < 0 ? h1 + 1 : h1);
	else if(h1 > h2 + 0.5)
		h1 = ((h1 += (h2 + 1 - h1) * r) > 1 ? h1 - 1 : h1);
	else
		h1 += (h2 - h1) * r;
	HSVtoRGB(h1, s1 + (s2 - s1) * r, v1 + (v2 - v1) * r, h1, s1, v1);
	return Color(fround(pow(h1, gamma) * 255.0), fround(pow(s1, gamma) * 255.0), fround(pow(v1, gamma) * 255.0));
}
Exemple #11
0
void R_GetPlayerTranslation (int color, const FPlayerColorSet *colorset, FPlayerSkin *skin, FRemapTable *table)
{
	float h, s, v;

	if (colorset != NULL)
	{
		color = colorset->RepresentativeColor;
	}
	RGBtoHSV (RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f,
		&h, &s, &v);

	R_CreatePlayerTranslation (h, s, v, colorset, skin, table, NULL, NULL);
}
Exemple #12
0
int main() {
	double red = 0;
	double green = 0;
	double blue = 0;

	RGBtoHSV(&red, &green, &blue, 95, 0.658, 0.757);
	std::cout << "Red: ";
	std::cout << red;
	std::cout << " Green: ";
	std::cout << green;
	std::cout << " Blue: ";
	std::cout << blue;
}
Exemple #13
0
/** This function converts HSV to RGB 
 * Every parameter is ∈ [start, end] */
void RGBtoHSVRange (double *r, double *g, double *b, double h, double s, double v, double start, double end) {
	double mutliplier = end - start;
	
	h = ((h - start) / mutliplier) * 360;
	s = ((s - start) / mutliplier);
	v = ((v - start) / mutliplier);
	
	RGBtoHSV(r, g, b, h, s, v);
	
	*r = *r * mutliplier + start;
	*g = *g * mutliplier + start;
	*b = *b * mutliplier + start;
}
Exemple #14
0
static void SetPillarRemap(FRemapTable *table, int i, float h, float s, float v)
{
	float ph, ps, pv;
	float fr = GPalette.BaseColors[i].r / 255.f;
	float fg = GPalette.BaseColors[i].g / 255.f;
	float fb = GPalette.BaseColors[i].b / 255.f;
	RGBtoHSV(fr, fg, fb, &ph, &ps, &pv);
	HSVtoRGB(&fr, &fg, &fb, h, s, (v*0.2f + pv*0.8f));
	int ir = clamp (int(fr * 255.f), 0, 255);
	int ig = clamp (int(fg * 255.f), 0, 255);
	int ib = clamp (int(fb * 255.f), 0, 255);
	table->Remap[i] = ColorMatcher.Pick (ir, ig, ib);
	table->Palette[i] = PalEntry(255, ir, ig, ib);
}
void D_GetPlayerColor (int player, float *h, float *s, float *v)
{
	userinfo_t *info = &players[player].userinfo;
	int color = info->color;

	RGBtoHSV (RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f,
		h, s, v);

	if (teamplay && TeamLibrary.IsValidTeam(info->team) && !Teams[info->team].GetAllowCustomPlayerColor ())
	{
		// In team play, force the player to use the team's hue
		// and adjust the saturation and value so that the team
		// hue is visible in the final color.
		float ts, tv;
		int tcolor = Teams[info->team].GetPlayerColor ();

		RGBtoHSV (RPART(tcolor)/255.f, GPART(tcolor)/255.f, BPART(tcolor)/255.f,
			h, &ts, &tv);

		*s = clamp(ts + *s * 0.15f - 0.075f, 0.f, 1.f);
		*v = clamp(tv + *v * 0.5f - 0.25f, 0.f, 1.f);
	}
}
Exemple #16
0
wxColour GetDarkColour(wxColour colour)
{
	float H, S, V;
	float R, G, B;
	R=((float)colour.Red())/256.0;
	G=((float)colour.Green())/256.0;
	B=((float)colour.Blue())/256.0;
	RGBtoHSV(R,G,B,&H,&S,&V);
	V-=0.2;
	if (V<0)
		V=0;
	HSVtoRGB(&R,&G,&B,H,S,V);
	wxColour result((unsigned char)(R*255),(unsigned char)(G*255),(unsigned char)(B*255));
	return result;
}
//get average pixel colors in a square that is half the size;
Color HoughCircleDetection::getColor(cv::Mat frame, int x, int y, int size) {
	long r = 0, b = 0, g = 0, total=0;
	int squareWidth = size/2;
	for (int i = x-(squareWidth/2); i < x+(squareWidth/2); i++) {
		if (i < 0) {
			continue;
		} else if (i > frame.cols) {
			break;
		}
		for (int j = y-(squareWidth/2); j < y+(squareWidth/2); j++) {
			if (j < 0) {
				continue;
			} else if (j > frame.rows) {
				break;
			}
			total++;
			cv::Vec3b val = frame.at<cv::Vec3b>(i, j);
			r += val[RED];
			b += val[BLUE];
			g += val[GREEN];
		}
	}
	r /= total;
	b /= total;
	g /= total;

	float h, s, v;

	RGBtoHSV(((float)r)/255, ((float)g)/255, ((float)b)/255, &h, &s, &v);

	h *= 255;
	s *= 255;
	v *= 255;


	if (s < 70) {
		return WHITE;
	}
	if (v < 70) {
		return BLACK;
	}

	if (h < 280 && h > 200) {
		return BLUE;
	}

	return UNKNOWN;
}
Exemple #18
0
void Data::updateColor(int _hueChange)
{
  ngl::Vec4 newColHSV = RGBtoHSV(geoColor[0], geoColor[1], geoColor[2]);


  newColHSV[0] += _hueChange * hueChangeAmount;
  if(newColHSV[0] > 360.0){
    newColHSV[0] -= 360.0;
  }
  if(newColHSV[0] < 0){
    newColHSV[0] += 360;
  }
  geoColor = HSVtoRGB(newColHSV[0], newColHSV[1], newColHSV[2]);
  ghostColor = geoColor + ngl::Vec4(0.1, 0.1, 0.1, 0.0);
  ghostColor.m_w = 0;
}
void ColorSpace::RGBtoHSV (CoImage* pIn, CoImage* pOut)
{
	assert (pIn->GetType() == MAT_Tbyte);
	assert (pOut->GetType() == MAT_Tfloat);
	BYTE** ppbR = pIn->m_matX.data.ptr;
	BYTE** ppbG = pIn->m_matY.data.ptr;
	BYTE** ppbB = pIn->m_matZ.data.ptr;

	float** pprR = pOut->m_matX.data.fl;
	float** pprG = pOut->m_matY.data.fl;
	float** pprB = pOut->m_matZ.data.fl;

	for (int iH = 0; iH < pIn->GetHeight(); iH ++)
	for (int iW = 0; iW < pIn->GetWidth(); iW ++)
	{
		RGBtoHSV(ppbR[iH][iW], ppbG[iH][iW], ppbB[iH][iW], &pprR[iH][iW], &pprG[iH][iW], &pprB[iH][iW]);
	}
}
// functions for compatibility with ITK segmentation only
void mitk::OpenCVVideoSource::GetCurrentFrameAsItkHSVPixelImage(HSVPixelImageType::Pointer &Image)
{
    FetchFrame();

    // Prepare iteration
    HSVConstIteratorType itImage( Image, Image->GetLargestPossibleRegion());
    itImage.Begin();
    HSVPixelType pixel;
    int rowsize = 3 * m_CaptureWidth;

    char* bufferend;
    char* picture;
    picture = this->m_CurrentImage->imageData;
    bufferend = this->m_CurrentImage->imageData + 3*(m_CaptureHeight*m_CaptureWidth);

    float r,g,b,h,s,v;
    try
    {
        // we have to flip the image
        for(char* datapointer = bufferend - rowsize; datapointer >= picture; datapointer -= rowsize)
        {
            for(char* current = datapointer; current < datapointer + rowsize; current++)
            {
                b = *current;
                current++;
                g = *current;
                current++;
                r = *current;
                RGBtoHSV(r,g,b,h,s,v);
                pixel[0] = h;
                pixel[1] = s;
                pixel[2] = v;

                itImage.Set(pixel);
                ++itImage;
            }
        }
    }
    catch( ... )
    {
        std::cout << "Exception raised mitkOpenCVVideoSource: get hsv itk image conversion error." << std::endl;
    }

}
Exemple #21
0
int main(int argc, char *argv[])
{
    
    int hue;
    int saturation;
    int brightness;
    int r;
    int g;
    int b;
    
    r = atoi(argv[0]);
    g = atoi(argv[1]);
    b = atoi(argv[2]);
    
    printf("R: %d G: %d B: %d\n", r, g, b);
    RGBtoHSV(r, g, b, &hue, &saturation, &brightness);
    printf("H: %d S: %d V: %d\n", hue, saturation, brightness);
    HSVtoRGB(hue, saturation, brightness, &r, &g, &b);
    printf("R: %d G: %d B: %d\n", r, g, b);
    
    
}
Exemple #22
0
int SetColourR(Colour *c, int r)
{
	COLORREF col;

	if (c->r == r)
		return 0;

	if (r < 0)
		r = 0;

	if (r > 255)
		r = 255;

	c->r = r;

	col = RGBtoHSV(c->r, c->g, c->b);
	c->h = GetHValue(col);
	c->s = GetSValue(col);
	c->v = GetVValue(col);

	return 1;
}
Exemple #23
0
int SetColourB(Colour *c, int b)
{
	COLORREF col;

	if (c->b == b)
		return 0;

	if (b < 0)
		b = 0;

	if (b > 255)
		b = 255;

	c->b = b;

	col = RGBtoHSV(c->r, c->g, c->b);
	c->h = GetHValue(col);
	c->s = GetSValue(col);
	c->v = GetVValue(col);

	return 1;
}
Exemple #24
0
int SetColourG(Colour *c, int g)
{
	COLORREF col;

	if (c->g == g)
		return 0;

	if (g < 0)
		g = 0;

	if (g > 255)
		g = 255;

	c->g = g;

	col = RGBtoHSV(c->r, c->g, c->b);
	c->h = GetHValue(col);
	c->s = GetSValue(col);
	c->v = GetVValue(col);

	return 1;
}
//Creates lookup tables for each channel
void ImageBrowser5D::CreateLookupTable()
{
	if(!img) return;

	m_lookuptable.clear();
	int chs = img->GetImageInfo()->numChannels;
	for(int i=0; i<chs; ++i)
	{
		LookupTablePointerType table = vtkSmartPointer<vtkLookupTable>::New();
		table->SetRange(0, 255);				// image intensity range
		
		std::vector<double> hsv = RGBtoHSV( img->GetImageInfo()->channelColors.at(i) );
		//S and V should always be 1, it is H that I am most concerned about

		table->SetHueRange(hsv[0],hsv[0]);			// Split Range
		table->SetSaturationRange(hsv[1],hsv[1]);	// Full Color Saturation
		table->SetValueRange(hsv[2],hsv[2]);		// from black to white
		table->SetAlphaRange(0,1);
		table->Build();

		m_lookuptable.push_back(table);
	}
}
Exemple #26
0
void RGBtoHSV(Color c, double& h, double& s, double& v)
{
	RGBtoHSV(c.GetR() / 255.0, c.GetG() / 255.0, c.GetB() / 255.0, h, s, v);
}
Exemple #27
0
static void DoPrintStr(const char *cp, HWND edit, HANDLE StdOut)
{
	if (edit == NULL && StdOut == NULL)
		return;

	char buf[256];
	wchar_t wbuf[countof(buf)];
	int bpos = 0;
	CHARRANGE selection;
	CHARRANGE endselection;
	LONG lines_before = 0, lines_after;
	CHARFORMAT format;

	if (edit != NULL)
	{
		// Store the current selection and set it to the end so we can append text.
		SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&selection);
		endselection.cpMax = endselection.cpMin = GetWindowTextLength(edit);
		SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&endselection);

		// GetWindowTextLength and EM_EXSETSEL can disagree on where the end of
		// the text is. Find out what EM_EXSETSEL thought it was and use that later.
		SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&endselection);

		// Remember how many lines there were before we added text.
		lines_before = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0);
	}

	while (*cp != 0)
	{
		// 28 is the escape code for a color change.
		if ((*cp == 28 && bpos != 0) || bpos == 255)
		{
			buf[bpos] = 0;
			if (edit != NULL)
			{
				ToEditControl(edit, buf, wbuf, bpos);
			}
			if (StdOut != NULL)
			{
				DWORD bytes_written;
				WriteFile(StdOut, buf, bpos, &bytes_written, NULL);
			}
			bpos = 0;
		}
		if (*cp != 28)
		{
			buf[bpos++] = *cp++;
		}
		else
		{
			const BYTE *color_id = (const BYTE *)cp + 1;
			EColorRange range = V_ParseFontColor(color_id, CR_UNTRANSLATED, CR_YELLOW);
			cp = (const char *)color_id;

			if (range != CR_UNDEFINED)
			{
				// Change the color of future text added to the control.
				PalEntry color = V_LogColorFromColorRange(range);
				if (StdOut != NULL && FancyStdOut)
				{
					// Unfortunately, we are pretty limited here: There are only
					// eight basic colors, and each comes in a dark and a bright
					// variety.
					float h, s, v, r, g, b;
					WORD attrib = 0;

					RGBtoHSV(color.r / 255.f, color.g / 255.f, color.b / 255.f, &h, &s, &v);
					if (s != 0)
					{ // color
						HSVtoRGB(&r, &g, &b, h, 1, 1);
						if (r == 1)  attrib  = FOREGROUND_RED;
						if (g == 1)  attrib |= FOREGROUND_GREEN;
						if (b == 1)  attrib |= FOREGROUND_BLUE;
						if (v > 0.6) attrib |= FOREGROUND_INTENSITY;
					}
					else
					{ // gray
						     if (v < 0.33) attrib = FOREGROUND_INTENSITY;
						else if (v < 0.90) attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
						else			   attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
					}
					SetConsoleTextAttribute(StdOut, attrib);
				}
				if (edit != NULL)
				{
					// GDI uses BGR colors, but color is RGB, so swap the R and the B.
					swapvalues(color.r, color.b);
					// Change the color.
					format.cbSize = sizeof(format);
					format.dwMask = CFM_COLOR;
					format.dwEffects = 0;
					format.crTextColor = color;
					SendMessage(edit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
				}
			}
		}
	}
	if (bpos != 0)
	{
		buf[bpos] = 0;
		if (edit != NULL)
		{
			ToEditControl(edit, buf, wbuf, bpos);
		}
		if (StdOut != NULL)
		{
			DWORD bytes_written;
			WriteFile(StdOut, buf, bpos, &bytes_written, NULL);
		}
	}

	if (edit != NULL)
	{
		// If the old selection was at the end of the text, keep it at the end and
		// scroll. Don't scroll if the selection is anywhere else.
		if (selection.cpMin == endselection.cpMin && selection.cpMax == endselection.cpMax)
		{
			selection.cpMax = selection.cpMin = GetWindowTextLength (edit);
			lines_after = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0);
			if (lines_after > lines_before)
			{
				SendMessage(edit, EM_LINESCROLL, 0, lines_after - lines_before);
			}
		}
		// Restore the previous selection.
		SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&selection);
		// Give the edit control a chance to redraw itself.
		I_GetEvent();
	}
	if (StdOut != NULL && FancyStdOut)
	{ // Set text back to gray, in case it was changed.
		SetConsoleTextAttribute(StdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// TFTODO: Make the sniper dot get brighter the more damage it will do.
//-----------------------------------------------------------------------------
int CSniperDot::DrawModel( int flags )
{
	// Get the owning player.
	C_TFPlayer *pPlayer = ToTFPlayer( GetOwnerEntity() );
	if ( !pPlayer )
		return -1;

	// Get the sprite rendering position.
	Vector vecEndPos;

	float flSize = 6.0;

	if ( !pPlayer->IsDormant() )
	{
		Vector vecAttachment, vecDir;
		QAngle angles;

		float flDist = MAX_TRACE_LENGTH;

		// Always draw the dot in front of our faces when in first-person.
		if ( pPlayer->IsLocalPlayer() )
		{
			// Take our view position and orientation
			vecAttachment = CurrentViewOrigin();
			vecDir = CurrentViewForward();

			// Clamp the forward distance for the sniper's firstperson
			flDist = 384;

			flSize = 2.0;
		}
		else
		{
			// Take the owning player eye position and direction.
			vecAttachment = pPlayer->EyePosition();
			QAngle angles = pPlayer->EyeAngles();
			AngleVectors( angles, &vecDir );
		}

		trace_t tr;
		UTIL_TraceLine( vecAttachment, vecAttachment + ( vecDir * flDist ), MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr );

		// Backup off the hit plane, towards the source
		vecEndPos = tr.endpos + vecDir * -4;
	}
	else
	{
		// Just use our position if we can't predict it otherwise.
		vecEndPos = GetAbsOrigin();
	}

	// Draw our laser dot in space.
	CMatRenderContextPtr pRenderContext( materials );
	pRenderContext->Bind( m_hSpriteMaterial, this );

	float flLifeTime = gpGlobals->curtime - m_flChargeStartTime;
	float flStrength = RemapValClamped( flLifeTime, 0.0, TF_WEAPON_SNIPERRIFLE_DAMAGE_MAX / TF_WEAPON_SNIPERRIFLE_CHARGE_PER_SEC, 0.1, 1.0 );
	
	color32 innercolor = { 255, 255, 255, 255 };
	color32 outercolor = { 255, 255, 255, 128 };

	// PistonMiner: DM sniper point coloring
	if (TFGameRules()->IsDeathmatch())
	{
		// Get the color of the mercenary we are drawing the dot of.
		C_TF_PlayerResource *tf_PR = dynamic_cast<C_TF_PlayerResource *>(g_PR);
		Color ownercolor = tf_PR->GetPlayerColor(pPlayer->index);

		// Convert to HSV so we can edit the color better.
		Vector hsv, rgb;
		RGBtoHSV(Vector(ownercolor.r() / 255.f, ownercolor.g() / 255.f, ownercolor.b() / 255.f), hsv);

		// Set the Value to max for constant brightness.
		hsv.z = 1.0;

		// Convert back to RGB
		HSVtoRGB(hsv, rgb);

		// Apply the color to our sprite.
		m_hSpriteMaterial->ColorModulate( rgb.x, rgb.y, rgb.z );
	}

	DrawSprite( vecEndPos, flSize, flSize, outercolor );
	DrawSprite( vecEndPos, flSize * flStrength, flSize * flStrength, innercolor );

	// Successful.
	return 1;
}
int* quantize(char r, char g, char b){
    //convert from uint8 to int32, if you try to pass directly you FAIL!!!
    int tempr, tempb, tempg;
    tempr = r&0xFF;
    tempg = g&0xFF;
    tempb = b&0xFF;
    //printf("%d, %d, %d\n", tempr, tempg, tempb);
    
    float* Qhsv, *HSV = RGBtoHSV(tempr/256.f, tempg/256.f, tempb/256.f);
    int* RGB = (int*)malloc(sizeof(int)*3);
    float h, s, v;
    h = HSV[0];
    s = HSV[1];
    v = HSV[2];
    
   	
	
	//clamp h
	if (((h >= -15.0f) && (h < 15.0f)) || ((h >= 345.0f) && (h < 375.0f))){
	    h = 0.f;
	} else if ((h >= 15.0f) && (h < 45.0f)){
	    h = 30.0f;
	} else if ((h >= 45.0f) && (h < 75.0f)){    
	    h = 60.0f;
	} else if ((h >= 75.0f) && (h < 105.0f)){
	    h = 90.0f;
	} else if ((h >= 105.0f) && (h < 135.0f)){
	    h = 120.0f;
	} else if ((h >= 135.0f) && (h < 165.0f)){
	    h = 150.0f;
	} else if ((h >= 165.0f) && (h < 195.0f)){
		h = 180.0f;
	} else if ((h >= 195.0f) && (h < 225.0f)){
		h = 210.0f;
    } else if ((h >=225.0f) && (h < 255.0f)) {
		h = 240.0f;
    } else if ((h >= 255.0f) && (h < 285.0f)){
		h = 270.0f;
    } else if ((h >=285.0f) && (h < 315.0f)){
		h = 300.0f;
    } else if ((h >= 315.0f) && (h < 345.0f)){
		h = 330.0f;
	}
 
        


	//clamp s
       
    // SMR: My modified clamping to handle boundery conditions
	/*	 if(s < .15)
            s = .0f;
        else if(s >= .15 && s < .45)
            s = .3f;
        else if(s >= .45 && s < .75)
            s = .6f;
        else
            s = 1.f;
	*/
    if(v < .15)
         v = .0f;
    else if(v >= .15 && v < .45)
         v = .3f;
    else if(v >= .45 && v < .75)
         v = .6f;
    else
         v = 1.f;
        
	
	Qhsv = HSVtoRGB(h,s,v);
	
	RGB[0] = (int)Qhsv[0];
	RGB[1] = (int)Qhsv[1];
	RGB[2] = (int)Qhsv[2];
	
	free(HSV);
	free(Qhsv);
	return RGB;
 }	
Exemple #30
0
main ()
{
  char *name = alloca (256);
  char  red[3];
  char  green[3];
  char  blue[3];
  int   count = 0;

  FILE *file;

  file = fopen ("css_colour_table.c", "w");
  fprintf (file, "/* DO NOT MODIFY THIS FILE! */\n");
  fprintf (file, "/* It was automatically generated. */\n");
  fprintf (file, "/* Modify instead colours/buildcolourtable.c */\n");
  fprintf (file, "/* or colours/css-colours.txt. */\n");
  fprintf (file, "\n");
  fprintf (file, "#include <math.h>\n");
  fprintf (file, "#include <gtk/gtk.h>\n");
  fprintf (file, "#include \"css_colour_table.h\"\n");
  fprintf (file, "css_colours_s css_colours[CSS_COLOUR_COUNT] = {\n");

  while (EOF != scanf ("%s #%2s%2s%2s \n", name, &red, &green, &blue)) {
    double rv = ((double)strtol (red,   NULL, 16)) / 255.0;
    double gv = ((double)strtol (green, NULL, 16)) / 255.0;
    double bv = ((double)strtol (blue,  NULL, 16)) / 255.0;
    double hv, sv, vv;
    
    RGBtoHSV (rv, gv, bv, &hv, &sv, &vv);
    
#if USE_COLOUR_MARKUP
    fprintf (file, "  {\"<span background=\\\"#%2s%2s%2s\\\">%s</span>\", \"#%s%s%sFF\", TRUE, 1.0, %f, %f, %f, %f, %f, %f},\n",
	     red, green, blue,
	     name,
	     red, green, blue,
	     rv, gv, bv, hv, sv, vv);
#else
    fprintf (file, "  {\"%s\", TRUE, \"#%s%s%sFF\", 1.0, %f, %f, %f, %f, %f, %f},\n",
	     name,
	     red, green, blue,
	     rv, gv, bv, hv, sv, vv);
#endif
    count++;
  }
  fprintf (file, "};\n");
  fprintf (file, "\n");
  //  fprintf (file, "gint css_colour_count = %d;\n", count);
  fclose (file);

  file = fopen ("css_colour_table.h", "w");
  fprintf (file, "/* DO NOT MODIFY THIS FILE! */\n");
  fprintf (file, "/* It was automatically generated. */\n");
  fprintf (file, "/* Modify instead colours/buildcolourtable.c */\n");
  fprintf (file, "/* or colours/css-colours.txt. */\n");
  fprintf (file, "\n");
  fprintf (file, "#ifndef CSS_COLOUR_TABLE_H\n");
  fprintf (file, "#define CSS_COLOUR_TABLE_H\n");
  fprintf (file, "\n");
  fprintf (file, "typedef struct {\n");
  fprintf (file, "  gchar   *name;\n");
  fprintf (file, "  gboolean preset;\n");
  fprintf (file, "  gchar   *hex;\n");
  fprintf (file, "  gdouble  alpha;\n");
  fprintf (file, "  gdouble  red;\n");
  fprintf (file, "  gdouble  green;\n");
  fprintf (file, "  gdouble  blue;\n");
  fprintf (file, "  gdouble  hue;\n");
  fprintf (file, "  gdouble  saturation;\n");
  fprintf (file, "  gdouble  value;\n");
  fprintf (file, "} css_colours_s;\n");
  fprintf (file, "\n");
  fprintf (file, "#define colour_name(c)   ((c).name)\n");
  fprintf (file, "#define colour_preset(c) ((c).preset)\n");
  fprintf (file, "#define colour_hex(c)    ((c).hex)\n");
  fprintf (file, "#define colour_alpha(c)  ((c).alpha)\n");
  fprintf (file, "#define colour_red(c)    ((c).red)\n");
  fprintf (file, "#define colour_green(c)  ((c).green)\n");
  fprintf (file, "#define colour_blue(c)   ((c).blue)\n");
  fprintf (file, "#define colour_hue(c)    ((c).hue)\n");
  fprintf (file, "#define colour_saturation(c) ((c).saturation)\n");
  fprintf (file, "#define colour_value(c)  ((c).value)\n");
  fprintf (file, "\n");
  fprintf (file, "#define CSS_COLOUR_COUNT  %d\n", count);
  fprintf (file, "css_colours_s css_colours[CSS_COLOUR_COUNT];\n");
  fprintf (file, "#endif   /* CSS_COLOUR_TABLE_H */\n\n");
  fclose (file);
}