//******************************************************************************* //* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 //* a = xRadius //* b = yRadius //******************************************************************************* void dispFillEllipse(int xCenter, int yCenter, int xRadius, int yRadius) { int xx = 0; int yy = yRadius; unsigned int width = 1; long a2 = (long)xRadius * xRadius; long b2 = (long)yRadius * yRadius; long crit1 = -(a2 / 4 + xRadius % 2 + b2); long crit2 = -(b2 / 4 + yRadius % 2 + a2); long crit3 = -(b2/4 + yRadius % 2); long t = -a2 * yy; /* e(x+1/2,y-1/2) - (a^2+b^2)/4 */ long dxt = 2 * b2 * xx; long dyt = -2 * a2 * yy; long d2xt = 2 * b2; long d2yt = 2 * a2; while (yy >= 0 && xx <= xRadius) { if (t + b2 * xx <= crit1 || /* e(x+1,y-1/2) <= 0 */ t + a2 * yy <= crit3) { /* e(x+1/2,y) <= 0 */ incx(); width += 2; } else if (t - a2 * yy > crit2) { /* e(x+1/2,y-1) > 0 */ //dispRectangle(xCenter - x, yCenter - y, width, 1); dispRectangle(xCenter - xx, yCenter - yy, width, 1); if (yy != 0) { //dispRectangle(xCenter- xx, yCenter + y, width, 1); dispRectangle(xCenter - xx, yCenter + yy, width, 1); } incy(); } else { //dispRectangle(xCenter - xx, yCenter - y, width, 1); dispRectangle(xCenter - xx, yCenter - yy, width, 1); if (yy != 0) { //dispRectangle(xCenter - xx, yCenter + y, width, 1); dispRectangle(xCenter - xx, yCenter + yy, width, 1); } incx(); incy(); width += 2; } } if (yRadius == 0) { //dispRectangle(xCenter - xRadius, yCenter, 2 * xRadius + 1, 1); dispRectangle(xCenter - xRadius, yCenter, 2 * xRadius + 1, 1); } }
//******************************************************************************* //* returns TRUE if image was drawn char bmp_draw_imageN(int imageIndex, int xLoc, int yLoc) { unsigned long bmp_loc; unsigned char bmp_buff[DATAFLASH_PAGESIZE]; int bmpWidth; int bmpHeight; long length; int byteCnt; int pixelX, pixelY; long longByte1, longByte2, longByte3, longByte4; FLASH_FILE_ENTRY myFileEntry; char imageOK; imageOK = FALSE; cli(); //disable interrupts GetFlashFileEntry(imageIndex, &myFileEntry); if (myFileEntry.fileName[0] >= 0x20) { //* OK, it looks like a valid file imageOK = TRUE; #ifdef _USE_7LETTER_NAMES_ longByte1 = (myFileEntry.flashOffsetByte1 & 0x0ff); longByte2 = (myFileEntry.flashOffsetByte2 & 0x0ff); longByte3 = (myFileEntry.flashOffsetByte3 & 0x0ff); longByte4 = (myFileEntry.flashOffsetByte4 & 0x0ff); bmp_loc = longByte1 << 24; bmp_loc |= longByte2 << 16; bmp_loc |= longByte3 << 8; bmp_loc |= longByte4; #else bmp_loc = myFileEntry.flashOffset; #endif /* Get the width and height */ dataflash_read_block(bmp_buff, bmp_loc, 2); longByte1 = bmp_buff[0]; longByte2 = bmp_buff[1]; // longByte3 = bmp_buff[2]; // longByte4 = bmp_buff[3]; bmpWidth = longByte1 & 0x0ff; bmpHeight = longByte2 & 0x0ff; length = (uint32_t)bmpWidth * (uint32_t)bmpHeight; //* Incremement the bmp pointer passed the width/height bmp_loc += 2; dataflash_read_block(bmp_buff, bmp_loc, DATAFLASH_PAGESIZE); byteCnt = 0; if ((xLoc == -1) && (yLoc == -1)) { //* if xLoc and yLoc are -1, then CENTER the image xLoc = (gWidth - bmpWidth) / 2; yLoc = (gHeight - bmpHeight) / 2; if (xLoc < 0) { xLoc = 0; } if (yLoc < 0) { yLoc = 0; } GraphicsColor.red = 0; GraphicsColor.blue = 0; GraphicsColor.green = 0; dispRectangle(0, 0, gWidth-1, gHeight-1); } pixelX = 0; pixelY = 0; while ((pixelY < bmpHeight) && (length > 0)) { GraphicsColor.red = bmp_buff[byteCnt++]; GraphicsColor.blue = bmp_buff[byteCnt++]; GraphicsColor.green = bmp_buff[byteCnt++]; dispPixel(xLoc + pixelX, yLoc + pixelY); pixelX++; if (pixelX >= bmpWidth) { pixelX = 0; pixelY++; } if (byteCnt >= DATAFLASH_PAGESIZE) { bmp_loc += DATAFLASH_PAGESIZE; dataflash_read_block(bmp_buff, bmp_loc, DATAFLASH_PAGESIZE); byteCnt = 0; } length--; } } sei(); //enable interrupts return(imageOK); }