/** * @brief Draws an ellipse on LCD. * @param Xpos: X position * @param Ypos: Y position * @param XRadius: Ellipse X radius * @param YRadius: Ellipse Y radius * @retval None */ void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) { int x = 0, y = -YRadius, err = 2-2*XRadius, e2; float K = 0, rad1 = 0, rad2 = 0; rad1 = XRadius; rad2 = YRadius; K = (float)(rad2/rad1); do { LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp.TextColor); LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp.TextColor); LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp.TextColor); LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp.TextColor); e2 = err; if (e2 <= x) { err += ++x*2+1; if (-y == x && e2 <= y) e2 = 0; } if (e2 > y) err += ++y*2+1; } while (y <= 0); }
/*=====================================================================================================*/ void LCD_DrawCircle( u16 CoordiX, u16 CoordiY, u16 Radius, u16 Color ) { int a,b; int di; a=0; b=Radius; di=3-(Radius<<1); while(a<=b) { LCD_DrawPixel(CoordiX-b, CoordiY-a, Color); //3 LCD_DrawPixel(CoordiX+b, CoordiY-a, Color); //0 LCD_DrawPixel(CoordiX-a, CoordiY+b, Color); //1 LCD_DrawPixel(CoordiX-b, CoordiY-a, Color); //7 LCD_DrawPixel(CoordiX-a, CoordiY-b, Color); //2 LCD_DrawPixel(CoordiX+b, CoordiY+a, Color); //4 LCD_DrawPixel(CoordiX+a, CoordiY-b, Color); //5 LCD_DrawPixel(CoordiX+a, CoordiY+b, Color); //6 LCD_DrawPixel(CoordiX-b, CoordiY+a, Color); a++; // 使用Bresenham算法畫圓 if(di<0) di += 4*a+6; else { di+=10+4*(a-b); b--; } LCD_DrawPixel(CoordiX+a, CoordiY+b, Color); } }
/*====================================================================================================*/ void LCD_DrawCircle( uint16_t coordiX, uint16_t coordiY, uint16_t radius, uint16_t color ) { int a, b; int di; a = 0; b = radius; di = 3 - (radius << 1); while(a <= b) { LCD_DrawPixel(coordiX-b, coordiY-a, color); //3 LCD_DrawPixel(coordiX+b, coordiY-a, color); //0 LCD_DrawPixel(coordiX-a, coordiY+b, color); //1 LCD_DrawPixel(coordiX-b, coordiY-a, color); //7 LCD_DrawPixel(coordiX-a, coordiY-b, color); //2 LCD_DrawPixel(coordiX+b, coordiY+a, color); //4 LCD_DrawPixel(coordiX+a, coordiY-b, color); //5 LCD_DrawPixel(coordiX+a, coordiY+b, color); //6 LCD_DrawPixel(coordiX-b, coordiY+a, color); a++; // Bresenham if(di < 0) di += 4 * a + 6; else { di += 10 + 4* (a - b); b--; } LCD_DrawPixel(coordiX+a, coordiY+b, color); } }
/********************************************************************* * * _DrawFocusRect */ static void _DrawFocusRect(const GUI_RECT* pr) { int i; for (i = pr->x0; i <= pr->x1; i += 2) { LCD_DrawPixel(i, pr->y0); LCD_DrawPixel(i, pr->y1); } for (i = pr->y0; i <= pr->y1; i += 2) { LCD_DrawPixel(pr->x0, i); LCD_DrawPixel(pr->x1, i); } }
/*=====================================================================================================*/ void WaveFormPrint( WaveForm_Struct* WaveForm ) { u16 i, j; s16 TempY[WaveChannelMax] = {0}; s16 CoordiY[WaveChannelMax] = {0}; static u16 WavePic[WaveChannelMax][WaveFormW] = {0}; /* 更新顯示座標 */ for(i=0; i<WaveForm->Channel; i++) { for(j=0; j<WaveFormW-1; j++) WavePic[i][j] = WavePic[i][j+1]; TempY[i] = (s16)((double)WaveForm->Data[i]/WaveForm->Scale[i]+0.5); CoordiY[i] = WaveFormH - TempY[i]; if(CoordiY[i]<0) WavePic[i][WaveFormW-1] = 0; else if(CoordiY[i]>WaveForm2H) WavePic[i][WaveFormW-1] = WaveForm2H; else WavePic[i][WaveFormW-1] = CoordiY[i]; } /* 畫邊框 */ LCD_DrawLineX(WaveWindowX, WaveWindowY, WaveFormW, WaveForm->WindowColor); LCD_DrawLineX(WaveWindowX, WaveWindowY+WaveForm2H, WaveFormW, WaveForm->WindowColor); LCD_DrawLineY(WaveWindowX, WaveWindowY, WaveForm2H, WaveForm->WindowColor); LCD_DrawLineY(WaveWindowX+WaveFormW, WaveWindowY, WaveForm2H, WaveForm->WindowColor); /* 顯示 */ for(i=0; i<WaveFormW-1; i++) { /* 清除上筆數據 */ for(j=0; j<WaveForm->Channel; j++) { if(WavePic[j][i] == 0) LCD_DrawPixel(WaveWindowX+i+1, WaveWindowY+WavePic[j][i], WaveForm->WindowColor); else if(WavePic[j][i] == WaveForm2H) LCD_DrawPixel(WaveWindowX+i+1, WaveWindowY+WavePic[j][i], WaveForm->WindowColor); else LCD_DrawPixel(WaveWindowX+i+1, WaveWindowY+WavePic[j][i], WaveForm->BackColor); } /* 畫輔助線 */ if((i%10) < 3) { for(j=0; j<=WaveFormH; j+=(WaveFormH/10)) { LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WaveFormH+j, WaveForm->WindowColor); LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WaveFormH-j, WaveForm->WindowColor); } } /* 畫中線 */ LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WaveFormH, WaveForm->WindowColor); /* 更新顯示新數據 */ for(j=0; j<WaveForm->Channel; j++) { if(WavePic[j][i] == 0) LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WavePic[j][i], WaveForm->WindowColor); else if(WavePic[j][i] == WaveForm2H) LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WavePic[j][i], WaveForm->WindowColor); else LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WavePic[j][i], WaveForm->PointColor[j]); } } }
/*====================================================================================================*/ void LCD_DrawRectangle( uint16_t CoordiX, uint16_t CoordiY, uint16_t Width, uint16_t Height, uint16_t Color ) { uint16_t i; for(i = 0; i <= Height; i++) { LCD_DrawPixel(CoordiX+i, CoordiY, Color); LCD_DrawPixel(CoordiX+i, CoordiY+Width, Color); } for(i = 1; i < Width; i++) { LCD_DrawPixel(CoordiX, CoordiY+i, Color); LCD_DrawPixel(CoordiX+Height, CoordiY+i, Color); } }
/*====================================================================================================*/ void LCD_DrawRectangle( uint16_t coordiX, uint16_t coordiY, uint16_t width, uint16_t height, uint16_t color ) { uint16_t i; for(i = 0; i <= height; i++) { LCD_DrawPixel(coordiX + i, coordiY, color); LCD_DrawPixel(coordiX + i, coordiY + width, color); } for(i = 1; i < width; i++) { LCD_DrawPixel(coordiX, coordiY + i, color); LCD_DrawPixel(coordiX + height, coordiY + i, color); } }
/*=====================================================================================================*/ void LCD_DrawRectangle( u16 CoordiX, u16 CoordiY, u16 Width, u16 Height, u16 Color ) { u16 i; for(i=0; i<=Height; i++) { LCD_DrawPixel(CoordiX+i, CoordiY, Color); LCD_DrawPixel(CoordiX+i, CoordiY+Width, Color); } for(i=1; i<Width; i++) { LCD_DrawPixel(CoordiX, CoordiY+i, Color); LCD_DrawPixel(CoordiX+Height, CoordiY+i, Color); } }
/*====================================================================================================*/ void LCD_PutChar( uint16_t coordiX, uint16_t coordiY, char *chWord, uint16_t fontColor, uint16_t backColor ) { uint8_t tmpChar = 0; uint16_t i = 0, j = 0; for(i = 0; i < 16; i++) { tmpChar = ASCII_16x8[*chWord - 32][i]; for(j = 0; j < 8; j++) { if(((tmpChar >> (7 - j)) & 0x01) == 0x01) LCD_DrawPixel(coordiX + j, coordiY + i, fontColor); else LCD_DrawPixel(coordiX + j, coordiY + i, backColor); } }
/*====================================================================================================*/ void LCD_PutChar( uint16_t CoordiX, uint16_t CoordiY, char *ChWord, uint16_t FontColor, uint16_t BackColor ) { uint8_t Tmp_Char = 0; uint16_t i = 0, j = 0; for(i = 0; i < 16; i++) { Tmp_Char = ASCII_16x8[*ChWord-32][i]; for(j = 0; j < 8; j++) { if(((Tmp_Char >> (7 - j)) & 0x01) == 0x01) LCD_DrawPixel(CoordiX+j, CoordiY+i, FontColor); // 字符顏色 else LCD_DrawPixel(CoordiX+j, CoordiY+i, BackColor); // 背景顏色 } }
/*=====================================================================================================*/ void LCD_PutChar1206( u16 CoordiX, u16 CoordiY, u8* ChWord, u16 FontColor, u16 BackColor ) { u8 Tmp_Char = 0; u16 i = 0, j = 0; for(i=0; i<12; i++) { Tmp_Char = ASCII_12x6[*ChWord-32][i]; for(j=0; j<6; j++) { if(((Tmp_Char>>j)&0x01) == 0x01) LCD_DrawPixel(CoordiX+j, CoordiY+i, FontColor); // 字符顏色 else LCD_DrawPixel(CoordiX+j, CoordiY+i, BackColor); // 背景顏色 } }
void LCD_DrawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { LCD_DrawStart(x, y, x, y + h -1, DRAW_NWSE); // bug fix: should be y+ h-1 while(h--) LCD_DrawPixel(color); LCD_DrawStop(); }
/*=====================================================================================================*/ void LCD_DrawLineY( u16 CoordiX, u16 CoordiY, u16 Length, u16 Color ) { u16 i; for(i=0; i<Length; i++) LCD_DrawPixel(CoordiX, CoordiY+i, Color); }
/*====================================================================================================*/ void LCD_DrawLineY( uint16_t CoordiX, uint16_t CoordiY, uint16_t Length, uint16_t Color ) { uint16_t i; for(i = 0; i < Length; i++) LCD_DrawPixel(CoordiX, CoordiY+i, Color); }
void LCD_FillRect(u16 x, u16 y, u16 w, u16 h, u16 color) { u32 bytes = (u32)w * h; LCD_DrawStart(x, y, x + w - 1, y + h -1, DRAW_NWSE); // Bug fix: should be y+h-1 instead of y+h while(bytes--) LCD_DrawPixel(color); LCD_DrawStop(); }
/*====================================================================================================*/ void LCD_DrawRectangleFill( uint16_t CoordiX, uint16_t CoordiY, uint16_t Width, uint16_t Height, uint16_t Color ) { uint16_t i, j; for(i = 0; i < Width; i++) for(j = 0; j < Height; j++) LCD_DrawPixel(CoordiX+j, CoordiY+i, Color); }
/*====================================================================================================*/ void LCD_DrawRectangleFill( uint16_t coordiX, uint16_t coordiY, uint16_t width, uint16_t height, uint16_t color ) { uint16_t i, j; for(i = 0; i < width; i++) for(j = 0; j < height; j++) LCD_DrawPixel(coordiX + j, coordiY + i, color); }
/*=====================================================================================================*/ void LCD_DrawRectangleFill( u16 CoordiX, u16 CoordiY, u16 Width, u16 Height, u16 Color ) { u16 i, j; for(i=0; i<Width; i++) for(j=0; j<Height; j++) LCD_DrawPixel(CoordiX+j, CoordiY+i, Color); }
/*=====================================================================================================*/ void WaveFormPrint( WaveForm_Struct *WaveForm, uint8_t display ) { int16_t i, j; int16_t TempY[WaveChannelMax] = {0}; int16_t CoordiY[WaveChannelMax] = {0}; static uint16_t WavePic[WaveChannelMax][WaveFormW] = {0}; /* 更新顯示座標 */ for(i = 0; i < WaveForm->Channel; i++) { for(j = 0; j < WaveFormW - 1; j++) WavePic[i][j] = WavePic[i][j+1]; TempY[i] = (int16_t)((float)WaveForm->Data[i] / WaveForm->Scale[i] + 0.5f); CoordiY[i] = WaveFormH - TempY[i]; if((CoordiY[i] > 0) && (CoordiY[i] < WaveForm2H)) WavePic[i][WaveFormW-1] = CoordiY[i]; } if(display == ENABLE) { /* 顯示 */ for(i = 0; i < WaveFormW - 1; i++) { /* 清除上筆數據 */ for(j = 0; j < WaveForm->Channel; j++) LCD_DrawPixel(WaveWindowX+i+1, WaveWindowY+WavePic[j][i], WaveForm->BackColor); // /* 畫輔助線 */ // if((i % 10) < 3) { // for(j = 0; j <= WaveFormH; j += (WaveFormH / 10)) { // LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WaveFormH+j, WaveForm->WindowColor); // LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WaveFormH-j, WaveForm->WindowColor); // } // } /* 畫中線 */ LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WaveFormH, WaveForm->WindowColor); /* 更新顯示新數據 */ for(j = 0; j < WaveForm->Channel; j++) LCD_DrawPixel(WaveWindowX+i, WaveWindowY+WavePic[j][i], WaveForm->PointColor[j]); } for(j = 0; j < WaveForm->Channel; j++) LCD_DrawPixel(WaveWindowX, WaveWindowY+WavePic[j][0], WaveForm->BackColor); /* 畫邊框 */ LCD_DrawLineX(WaveWindowX, WaveWindowY, WaveFormW, WaveForm->WindowColor); LCD_DrawLineX(WaveWindowX, WaveWindowY+WaveForm2H, WaveFormW, WaveForm->WindowColor); LCD_DrawLineY(WaveWindowX, WaveWindowY, WaveForm2H, WaveForm->WindowColor); LCD_DrawLineY(WaveWindowX+WaveFormW, WaveWindowY, WaveForm2H, WaveForm->WindowColor); } }
/********************************************************************* * * _WritePixelsGray */ static void _WritePixelsGray(const U8*p, int x0, int y0, int xSize) { U8 u; while (xSize) { u = *p++; LCD_SetColor(u * (U32)0x10101); LCD_DrawPixel(x0++, y0); xSize--; } }
void DrawLine(u8 x0, u8 y0, u8 x1, u8 y1, u16 color) { int dx, dy, dx2, dy2, stepx, stepy, err; if((x0 == x1) || (y0 == y1)) //horizontal or vertical line { FillRect(x0, y0, x1, y1, color); } else { //calculate direction dx = x1 - x0; dy = y1 - y0; if(dx < 0) { dx = -dx; stepx = -1; } else { stepx = +1; } if(dy < 0) { dy = -dy; stepy = -1; } else { stepy = +1; } dx2 = dx << 1; dy2 = dy << 1; //draw line //LCD_SetArea(0, 0, (LCD_WIDTH-1), (LCD_HEIGHT-1)); LCD_DrawPixel(x0, y0, color); if(dx > dy) { err = dy2 - dx; while(x0 != x1) { if(err >= 0) { err -= dx2; y0 += stepy; } err += dy2; x0 += stepx; LCD_DrawPixel(x0, y0, color); } } else { err = dx2 - dy; while(y0 != y1) { if(err >= 0) { err -= dy2; x0 += stepx; } err += dx2; y0 += stepy; LCD_DrawPixel(x0, y0, color); } } } }
/********************************************************************* * * _WritePixelsRGB */ static void _WritePixelsRGB(const U8*p, int x0, int y0, int xSize) { U8 r,g,b; while (xSize) { r = *p++; g = *p++; b = *p++; LCD_SetColor(r | (g << 8) | (U32)((U32)b << 16)); LCD_DrawPixel(x0++, y0); xSize--; } }
void LCD_DrawRLE(const u8 *data, int len, u32 color) { while(len) { u32 c = (*data & 0x80) ? color : 0; for(int i = 0; i < (*data & 0x7f); i++) { LCD_DrawPixel(c); } data++; len--; } }
/** * @brief Draws a vertical line. * @param Xpos: X position * @param Ypos: Y position * @param Length: Line length * @retval None */ void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint32_t index = 0; if(lcd_drv->DrawVLine != NULL) { lcd_drv->DrawVLine(DrawProp.TextColor, Xpos, Ypos, Length); } else { for(index = 0; index < Length; index++) { LCD_DrawPixel(Xpos, Ypos + index, DrawProp.TextColor); } } }
/** * @brief Draws a circle. * @param Xpos: X position * @param Ypos: Y position * @param Radius: Circle radius * @retval None */ void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) { int32_t D; /* Decision Variable */ uint32_t CurX; /* Current X Value */ uint32_t CurY; /* Current Y Value */ D = 3 - (Radius << 1); CurX = 0; CurY = Radius; while (CurX <= CurY) { LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp.TextColor); LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp.TextColor); LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp.TextColor); LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp.TextColor); LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp.TextColor); LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp.TextColor); LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp.TextColor); LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp.TextColor); /* Initialize the font */ BSP_LCD_SetFont(&LCD_DEFAULT_FONT); if (D < 0) { D += (CurX << 2) + 6; } else { D += ((CurX - CurY) << 2) + 10; CurY--; } CurX++; } }
void LCD_DrawFastHLine(u16 x, u16 y, u16 w, u16 color) { LCD_DrawStart(x, y, x + w -1, y, DRAW_NWSE); while(w--) LCD_DrawPixel(color); LCD_DrawStop(); }
/** * @brief Draws an uni-line (between two points). * @param x1: Point 1 X position * @param y1: Point 1 Y position * @param x2: Point 2 X position * @param y2: Point 2 Y position * @retval None */ void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, curpixel = 0; deltax = ABS(x2 - x1); /* The difference between the x's */ deltay = ABS(y2 - y1); /* The difference between the y's */ x = x1; /* Start x off at the first pixel */ y = y1; /* Start y off at the first pixel */ if (x2 >= x1) /* The x-values are increasing */ { xinc1 = 1; xinc2 = 1; } else /* The x-values are decreasing */ { xinc1 = -1; xinc2 = -1; } if (y2 >= y1) /* The y-values are increasing */ { yinc1 = 1; yinc2 = 1; } else /* The y-values are decreasing */ { yinc1 = -1; yinc2 = -1; } if (deltax >= deltay) /* There is at least one x-value for every y-value */ { xinc1 = 0; /* Don't change the x when numerator >= denominator */ yinc2 = 0; /* Don't change the y for every iteration */ den = deltax; num = deltax / 2; numadd = deltay; numpixels = deltax; /* There are more x-values than y-values */ } else /* There is at least one y-value for every x-value */ { xinc2 = 0; /* Don't change the x for every iteration */ yinc1 = 0; /* Don't change the y when numerator >= denominator */ den = deltay; num = deltay / 2; numadd = deltax; numpixels = deltay; /* There are more y-values than x-values */ } for (curpixel = 0; curpixel <= numpixels; curpixel++) { LCD_DrawPixel(x, y, DrawProp.TextColor); /* Draw the current pixel */ num += numadd; /* Increase the numerator by the top of the fraction */ if (num >= den) /* Check if numerator >= denominator */ { num -= den; /* Calculate the new numerator value */ x += xinc1; /* Change the x as appropriate */ y += yinc1; /* Change the y as appropriate */ } x += xinc2; /* Change the x as appropriate */ y += yinc2; /* Change the y as appropriate */ } }
void LCD_DrawPixelXY(unsigned int x, unsigned int y, unsigned int color) { xpos = x; ypos = y; LCD_DrawPixel(color); }
/* * draw a circle * algorithm by Jack Bresenham * */ void DrawCircle(u8 X1, u8 Y1, u8 Radius, u16 color) { int f; int ddF_x; int ddF_y; int x; int y; f = 1 - Radius; ddF_x = 0; ddF_y = -2 * Radius; x = 0; y = Radius; LCD_DrawPixel(X1, Y1 + Radius, color); LCD_DrawPixel(X1, Y1 - Radius, color); LCD_DrawPixel(X1 + Radius, Y1, color); LCD_DrawPixel(X1 - Radius, Y1, color); while (x < y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x + 1; LCD_DrawPixel(X1 + x, Y1 + y, color); LCD_DrawPixel(X1 - x, Y1 + y, color); LCD_DrawPixel(X1 + x, Y1 - y, color); LCD_DrawPixel(X1 - x, Y1 - y, color); LCD_DrawPixel(X1 + y, Y1 + x, color); LCD_DrawPixel(X1 - y, Y1 + x, color); LCD_DrawPixel(X1 + y, Y1 - x, color); LCD_DrawPixel(X1 - y, Y1 - x, color); } }
void LCD_DrawWindowedImageFromFile(u16 x, u16 y, const char *file, s16 w, s16 h, u16 x_off, u16 y_off) { u16 i, j; FILE *fh; u8 transparent = 0; u8 row_has_transparency = 0; (void)row_has_transparency; u8 buf[480 * 2]; if (w == 0 || h == 0) return; fh = fopen(file, "rb"); if(! fh) { printf("DEBUG: LCD_DrawWindowedImageFromFile: Image not found: %s\n", file); if (w > 0 && h > 0) LCD_FillRect(x, y, w, h, 0); return; } setbuf(fh, 0); u32 img_w, img_h, offset, compression; if(fread(buf, 0x46, 1, fh) != 1 || buf[0] != 'B' || buf[1] != 'M') { fclose(fh); printf("DEBUG: LCD_DrawWindowedImageFromFile: Buffer read issue?\n"); return; } compression = *((u32 *)(buf + 0x1e)); if(*((u16 *)(buf + 0x1a)) != 1 /* 1 plane */ || *((u16 *)(buf + 0x1c)) != 16 /* 16bpp */ || (compression != 0 && compression != 3) /* BI_RGB or BI_BITFIELDS */ ) { fclose(fh); printf("DEBUG: LCD_DrawWindowedImageFromFile: BMP Format not correct\n"); return; } if(compression == 3) { if(*((u16 *)(buf + 0x36)) == 0x7c00 && *((u16 *)(buf + 0x3a)) == 0x03e0 && *((u16 *)(buf + 0x3e)) == 0x001f && *((u16 *)(buf + 0x42)) == 0x8000) { transparent = 1; } else if(*((u16 *)(buf + 0x36)) != 0xf800 || *((u16 *)(buf + 0x3a)) != 0x07e0 || *((u16 *)(buf + 0x3e)) != 0x001f) { fclose(fh); printf("DEBUG: LCD_DrawWindowedImageFromFile: BMP Format not correct second check\n"); return; } } offset = *((u32 *)(buf + 0x0a)); img_w = *((u32 *)(buf + 0x12)); img_h = *((u32 *)(buf + 0x16)); if(w < 0) w = img_w; if(h < 0) h = img_h; if((u16)w + x_off > img_w || (u16)h + y_off > img_h) { printf("DEBUG: LCD_DrawWindowedImageFromFile: Dimensions asked for are out of bounds\n"); printf("size: (%d x %d) bounds(%d x %d)\n", (u16)img_w, (u16)img_h, (u16)(w + x_off), (u16)(h + y_off)); fclose(fh); return; } offset += (img_w * (img_h - (y_off + h)) + x_off) * 2; fseek(fh, offset, SEEK_SET); LCD_DrawStart(x, y, x + w - 1, y + h - 1, DRAW_SWNE); /* Bitmap start is at lower-left corner */ for (j = 0; j < h; j++) { if (fread(buf, 2 * w, 1, fh) != 1) break; u16 *color = (u16 *)buf; if(transparent) { #ifdef TRANSPARENT_COLOR //Display supports a transparent color for (i = 0; i < w; i++ ) { u32 c; if((*color & 0x8000)) { //convert 1555 -> 565 c = ((*color & 0x7fe0) << 1) | (*color & 0x1f); } else { c = TRANSPARENT_COLOR; } LCD_DrawPixel(c); color++; } #else u8 last_pixel_transparent = row_has_transparency; row_has_transparency = 0; for (i = 0; i < w; i++ ) { if((*color & 0x8000)) { //convert 1555 -> 565 u16 c = ((*color & 0x7fe0) << 1) | (*color & 0x1f); if(last_pixel_transparent) { LCD_DrawPixelXY(x + i, y + h - j - 1, c); last_pixel_transparent = 0; } else { LCD_DrawPixel(c); } } else { //When we see a transparent pixel, the next real pixel // will need to be drawn with XY coordinates row_has_transparency = 1; last_pixel_transparent = 1; } color++; } #endif } else { for (i = 0; i < w; i++ ) { if (LCD_DEPTH == 1) *color = (*color & 0x8410) == 0x8410 ? 0 : 0xffff; LCD_DrawPixel(*color++); } } if((u16)w < img_w) { fseek(fh, 2 * (img_w - w), SEEK_CUR); } } LCD_DrawStop(); fclose(fh); }