Example #1
0
boolean _blackfinGetPixel(CAMERA* cam,uint16_t x, uint16_t y, COLOR * color){
	BLACKFIN_CAMERA* camera = (BLACKFIN_CAMERA*)cam;
	boolean rtn = FALSE;

	int32_t values[3];

	// Make rprintf go to _blackfin_command
	 Writer old = rprintfInit(&_blackfin_putcmd);
	_blackfin_index=0;

	// send 'vp' command
	rprintf("vp");
	rprintfNum(10,4,FALSE,'0',x);
	rprintfNum(10,4,FALSE,'0',y);

	// process the command

	int args = __blackfinCommand(camera,PSTR("##vp "),null,values,3);

	if(args==3){
		rtn = TRUE;
		colorSetYUV(color,(uint8_t)(values[0]), (uint8_t)(values[1]),(uint8_t)(values[2]));
		#ifdef BLACKFIN_DEBUG
		_blackfin_set_active(camera->debug);	//Send rprintf to the debugger
		rprintf(" Color = "); colorDump(color);
		rprintfCRLF();
		#endif
	}

	// Restore rprintf to original position
	rprintfInit(old);
	return rtn;
}
Example #2
0
// Convert the color to YUV
COLOR_YUV* color2yuv(const COLOR * src, COLOR* dest){
	switch(src->colorSpace){
	case YUV:
		// Nothing to do
		if(src != dest){
			memcpy(dest, src, sizeof(COLOR));
		}
		break;
	case RGB:{
			/*
			Y  =  16 + 1/256 * (  65.738 * R'd + 129.057 * G'd +  25.064 * B'd)
			Cb = 128 + 1/256 * (- 37.945 * R'd -  74.494 * G'd + 112.439 * B'd)
			Cr = 128 + 1/256 * ( 112.439 * R'd -  94.154 * G'd -  18.285 * B'd)
			*/

			int r = src->bands.rgb.r;
			int g = src->bands.rgb.g;
			int b = src->bands.rgb.b;


			int y =  16.0 + 1.0/256.0 * (  65.738 * r + 129.057 * g +  25.064 * b);
			int u = 128.0 + 1.0/256.0 * (- 37.945 * r -  74.494 * g + 112.439 * b);
			int v = 128.0 + 1.0/256.0 * ( 112.439 * r -  94.154 * g -  18.285 * b);

			y = CLAMP(y,0,255);
			u = CLAMP(u,0,255);
			v = CLAMP(v,0,255);

			// Convert rgb to yuv
			colorSetYUV(dest,y,u,v);
			break;
		}
	}
	return &dest->bands.yuv;

}