uint8_t irmp_read (irmp_data_t * irmp_data_p) { if (irmp_rx_fifo.read == irmp_rx_fifo.write) return 0; *irmp_data_p = irmp_rx_fifo.buffer[irmp_rx_fifo.read = FIFO_NEXT (irmp_rx_fifo.read)]; #ifdef DEBUG_IRMP printf_P (PSTR ("IRMP RX: proto %02"PRId8" "), irmp_data_p->protocol); printf_P ((const char *)pgm_read_word (&irmp_proto_names[irmp_data_p->protocol])); printf_P (PSTR (", address %04"PRIX16", command %04"PRIX16", flags %02"PRIX8"\n"), irmp_data_p->address, irmp_data_p->command, irmp_data_p->flags); #endif return 1; }
void irmp_write (irmp_data_t * irmp_data_p) { #ifdef DEBUG_IRMP printf_P (PSTR ("IRMP TX: proto %02"PRId8" "), irmp_data_p->protocol); printf_P ((const char *)pgm_read_word (&irmp_proto_names[irmp_data_p->protocol])); printf_P (PSTR (", address %04"PRIX16", command %04"PRIX16", flags %02"PRIX8"\n"), irmp_data_p->address, irmp_data_p->command, irmp_data_p->flags); #endif uint8_t tmphead = FIFO_NEXT (irmp_tx_fifo.write); while (tmphead == *(volatile uint8_t *) &irmp_tx_fifo.read) _delay_ms (10); irmp_tx_fifo.buffer[tmphead] = *irmp_data_p; irmp_tx_fifo.write = tmphead; }
int camFillColor(CamImage *image, int x, int y, int fillcolor, int tolerance) { int first=0,last=0; int i,j,d,xp,yp; CAM_PIXEL *ptr,*ptrx; const int nx[4]={-1,0,+1,0},ny[4]={0,-1,0,+1}; CAM_PIXEL pcolor[4],initcolor[4]; // 4 is the maximum number of channels CamInternalROIPolicyStruct iROI; int acc=1; int queuex[FIFO_SIZE]; int queuey[FIFO_SIZE]; // ROI (Region Of Interest) management CAM_CHECK(camFillColor,camInternalROIPolicy(image, NULL, &iROI, 0)); CAM_CHECK_ARGS(camFillColor, ((iROI.nChannels==1)||(image->dataOrder==CAM_DATA_ORDER_PIXEL))); if ((x>=iROI.srcroi.xOffset)&&(y>=iROI.srcroi.yOffset)&&(x<iROI.srcroi.xOffset+iROI.srcroi.width)&&(y<iROI.srcroi.yOffset+iROI.srcroi.height)) { for (i=0;i<iROI.nChannels;i++) { pcolor[i]=(fillcolor>>(i*8))&0xff; } ptr=ptrx=(CAM_PIXEL*)(image->imageData+iROI.srcchoffset+y*image->widthStep)+x*iROI.srcinc; if (tolerance>=0) { for (i=0;i<iROI.nChannels;i++) { initcolor[i]=*ptrx++; } FIFO_ADD(x,y); for (ptrx=ptr,i=0;i<iROI.nChannels;i++,ptrx++) { *ptrx=pcolor[i]; } while (!FIFO_EMPTY()) { x=queuex[first]; y=queuey[first]; FIFO_NEXT(); for (j=0;j<4;j++) { xp=x+nx[j]; yp=y+ny[j]; if ((xp>=iROI.srcroi.xOffset)&&(yp>=iROI.srcroi.yOffset)&&(xp<iROI.srcroi.xOffset+iROI.srcroi.width)&&(yp<iROI.srcroi.yOffset+iROI.srcroi.height)) { // Get the color at (xp,yp) ptr=ptrx=(CAM_PIXEL*)(image->imageData+iROI.srcchoffset+yp*image->widthStep)+xp*iROI.srcinc; // Is it the same color as the initial color? // Compute distance between colors d=0; for (i=0;i<iROI.nChannels;i++,ptrx++) { if (*ptrx>initcolor[i]) d+=*ptrx-initcolor[i]; else d+=initcolor[i]-*ptrx; } if (d<=tolerance) { // Yes, then this pixel should be repainted and added to the queue FIFO_ADD(xp,yp); for (ptrx=ptr,i=0;i<iROI.nChannels;i++,ptrx++) { *ptrx=pcolor[i]; } acc++; } } } } } else { FIFO_ADD(x,y); for (ptrx=ptr,i=0;i<iROI.nChannels;i++,ptrx++) { *ptrx=pcolor[i]; } while (!FIFO_EMPTY()) { x=queuex[first]; y=queuey[first]; FIFO_NEXT(); for (j=0;j<4;j++) { xp=x+nx[j]; yp=y+ny[j]; if ((xp>=iROI.srcroi.xOffset)&&(yp>=iROI.srcroi.yOffset)&&(xp<iROI.srcroi.xOffset+iROI.srcroi.width)&&(yp<iROI.srcroi.yOffset+iROI.srcroi.height)) { // Get the color at (xp,yp) ptr=ptrx=(CAM_PIXEL*)(image->imageData+iROI.srcchoffset+yp*image->widthStep)+xp*iROI.srcinc; for (i=0;i<iROI.nChannels;i++,ptrx++) if (*ptrx!=pcolor[i]) break; // Is it the same color as the fill color? if (i!=iROI.nChannels) { // Yes, then this pixel should be repainted and added to the queue FIFO_ADD(xp,yp); for (ptrx=ptr,i=0;i<iROI.nChannels;i++,ptrx++) { *ptrx=pcolor[i]; } acc++; } } } } } } return acc; }