void smiWaitAvail(SmiCardInfo *smic, int n) { if (smic->avail < n) { while (!FIFO_EMPTY (smic)) ; smic->avail = MAX_FIFO; } smic->avail -= n; }
int test_enable(void) { keyboard_clear_buffer(); clear_state(); TEST_ASSERT(set_kb_scan_enabled(0)); TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS); TEST_ASSERT(FIFO_EMPTY()); TEST_ASSERT(set_kb_scan_enabled(1)); TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS); TEST_ASSERT(FIFO_NOT_EMPTY()); TEST_ASSERT(verify_key(0, 0, 1)); return EC_SUCCESS; }
int test_fifo_size(void) { keyboard_clear_buffer(); clear_state(); TEST_ASSERT(set_fifo_size(1)); TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS); TEST_ASSERT(press_key(0, 0, 0) == EC_ERROR_OVERFLOW); clear_state(); TEST_ASSERT(verify_key(0, 0, 1)); TEST_ASSERT(FIFO_EMPTY()); /* Restore FIFO size */ TEST_ASSERT(set_fifo_size(100)); return EC_SUCCESS; }
int single_key_press(void) { keyboard_clear_buffer(); clear_state(); TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS); TEST_ASSERT(FIFO_NOT_EMPTY()); TEST_ASSERT(press_key(0, 0, 0) == EC_SUCCESS); TEST_ASSERT(FIFO_NOT_EMPTY()); clear_state(); TEST_ASSERT(verify_key(0, 0, 1)); TEST_ASSERT(FIFO_NOT_EMPTY()); TEST_ASSERT(verify_key(0, 0, 0)); TEST_ASSERT(FIFO_EMPTY()); return EC_SUCCESS; }
/* 7.3 */ WML_STATUS WML_Encode(UINT32 iBytes, const BYTE * wmlDoc, const char * iCharEnc, UINT32 * oBytes, BYTE * binDoc, const char * oCharEnc, int * arraySize, UINT16 ** metaHttpEquiv, int * stringLength, UINT16 ** metaContent, const char * altDTDID, const BYTE * URLofDoc) { /* ----------------------------------------------------------------------------- */ /* Data structures */ WML_STATUS rc = WML_OK; SEncBuffers _buffers; WCHAR* _uBuffer; SDocData * _pWmlData; UINT32 _oSize = 0; /* Code */ if(oBytes) { _oSize = *oBytes; *oBytes = 0; } /***** CHECK ARGUMENTS *****/ if(!s_isInitialized) { wmlLOGs(WSL_LOG_ERROR, "Not initialized"); return WML_ERROR_NOT_INITIALIZED; } if( !wmlDoc || !binDoc || !iCharEnc || !oCharEnc || !oBytes) { wmlLOGs(WSL_LOG_ERROR, "WML_Encode: NULL pointer as argument"); return WML_ERROR_EMPTY_ARG; } if(!iBytes || !_oSize || (iBytes>=XML_BUFFER_SIZE)) { wmlLOGs(WSL_LOG_ERROR, "WML_Encode: Invalid buffer size."); return WML_ERROR_INVALID_BUFFER_SIZE; } if(!getCharEncoding(iCharEnc)) { wmlLOGss(WSL_LOG_ERROR, "WML_Encode: Character set does not exist: ",iCharEnc); return WML_ERROR_INVALID_ENCODING; } if(!getCharEncoding(oCharEnc)) { wmlLOGss(WSL_LOG_ERROR, "WML_Encode: Character set does not exist: ",oCharEnc); return WML_ERROR_INVALID_ENCODING; } /***** PREPARE THE BUFFERS *****/ _uBuffer = XML_ALLOC(sizeof(WCHAR)*iBytes); _buffers.m_enc = getCharEncoding(iCharEnc); _buffers.m_src = wmlDoc; _buffers.m_srcSize = iBytes; _buffers.m_dst = _uBuffer; _buffers.m_dstSize = iBytes; /***** CONVERT *****/ if(!convertToUnicode(&_buffers)) { XML_FREE(_uBuffer); return WML_ERROR_CONVERSION_FAILED; } /***** DATA STRUCTURES FOR CALLBACK FUNCTIONS *****/ _pWmlData = newSDocData(oCharEnc, oBytes, binDoc, arraySize, metaHttpEquiv, stringLength, metaContent, URLofDoc); /***** XML - WML *****/ if (parseXML(_pWmlData, _uBuffer, _buffers.m_dstSize, TokenHandler, ErrorHandler, altDTDID, URLofDoc) != 0) { if(_pWmlData->m_error) { rc = _pWmlData->m_error; } else if(FIFO_EMPTY(_pWmlData->m_eventList)) { rc = WML_ERROR_XMLPARSER_FAILED; } else { *oBytes = _oSize; rc = isValidWMLDocument(_pWmlData); if(rc!=WML_OK) { *oBytes = 0; } } } else { rc = WML_ERROR_XMLPARSER_FAILED; if(_pWmlData->m_error) { rc = _pWmlData->m_error; } } /***** RELEASE MEMORY *****/ deleteSDocData(_pWmlData); XML_FREE(_uBuffer); return rc; }
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; }