Hi,

I´m trying to write a program that does some color conversion, but I cannot get it to work right. It seem that that the compiler doesn´t like conversion between int and double. Here´s the code:

Code:
/* colorconvert.c */

int rgb2yuv(int xrgb){

	unsigned char r,g,b,y,u,v;
	
	r=(xrgb&&0x00FF0000)>>16;
	g=(xrgb&&0x0000FF00)>>8;
	b=(xrgb&&0x000000FF);

	y=(unsigned char) (0.257*(double)r)+(0.504*(float)g)+(0.098*(float)b) + 16;
	u=(unsigned char) -(0.148*(double)r)-(0.291*(float)g)+(0.439*(float)b) + 128;
	v=(unsigned char) (0.439*(double)r)-(0.368*(float)g)-(0.071*(float)b) + 128;

	return (y<<16+u<<8+v);
}


int yuv2rgb(int xyuv){ 	/* Actually xycrcb */

	unsigned char r,g,b,y,u,v;

	y=(xyuv&&0x00FF0000)>>16;
	u=(xyuv&&0x0000FF00)>>8;
	v=(xyuv&&0x000000FF);

	r=(unsigned char) 1.164*(y-16)+1.596*(v-128);
	g=(unsigned char) 1.164*(y-16)-0.813*(v-128)-0.391*(u-128);
	b=(unsigned char) 1.164*(y-16)+2.018*(u-128);

	return (r<<16+g<<8+b);
}
Any suggestions. I´ve written a sample main function if your interested:

Code:
/* main.cc */

#include <iostream>
using namespace std;

#include <colorconvert.c>

int main(){
	int c1,c2,c3;
	
	c1=0x0045B391;
	c2=0x001633A1;
	c3=0x00D543F1;
	
	cout << hex << "c1=" << c1 << endl;
	cout << hex << "c2=" << c2 << endl;
	cout << hex << "c3=" << c3 << endl << endl;
	
	c1=rgb2yuv(c1);
	c2=rgb2yuv(c2);
	c3=rgb2yuv(c3);
	
	cout << hex << "c1=" << c1 << endl;
	cout << hex << "c2=" << c2 << endl;
	cout << hex << "c3=" << c3 << endl << endl;
	
	c1=yuv2rgb(c1);
	c2=yuv2rgb(c2);
	c3=yuv2rgb(c3);
	
	cout << hex << "c1=" << c1 << endl;
	cout << hex << "c2=" << c2 << endl;
	cout << hex << "c3=" << c3 << endl << endl;
	
}
Any suggestions?