UFB_Image *UFB_ConvertRGBA32PixelsToImage(void *pixels, UFBuint16 w, UFBuint16 h) { UFB_Image *img = UFB_CreateImage(w, h, UFBtrue); UFBuint32 *end = (UFBuint32*)pixels + w * h; UFBuint32 *ip = (UFBuint32*)pixels; UFBuint8 *op = (UFBuint8*)img->pixels; UFB_RGBA8888 *irgba; UFB_RGBA5658 *orgba; int c = 0; while(ip != end) { irgba = (UFB_RGBA8888*)ip; orgba = (UFB_RGBA5658*)op; orgba->rgb = RGB888TO565(irgba->r, irgba->g, irgba->b); orgba->a = irgba->a; ++ip; op += 3; ++c; } return img; }
void PutPixel888To565( U32 base, int xpos, int ypos, int width, int height, U32 color ) { *(U16*)(base + (ypos * width + xpos) * 2) = (U16)RGB888TO565(color); }
UFB_Image *UFB_ConvertRGB24PixelsToImage(void *pixels, UFBuint16 w, UFBuint16 h) { UFB_Image *img = UFB_CreateImage(w, h, UFBfalse); UFBuint8 *end = (UFBuint8*)pixels + w * h * 3; UFBuint8 *ir = (UFBuint8*)pixels; UFBuint16 *op = (UFBuint16*)img->pixels; while(ir != end) { *op = RGB888TO565(*ir, *(ir + 1), *(ir + 2)); ir += 3; ++op; } return img; }
/** * @brief Draw the top bar (NO tft_clear and tft_update involved) * @param None * @retval None */ void draw_top_bar(void) { u16 prev_bg_color = tft_get_bg_color(); u16 prev_text_color = tft_get_text_color(); // Top bar - time tft_set_bg_color(BLUE2); tft_set_text_color(WHITE); tft_clear_line(0); tft_prints(0,0," %02d %02d", get_seconds() / 60, get_seconds() % 60); tft_set_text_color(RGB888TO565((500 - Abs(500 - get_ticks())) * 0xFF / 500 * 0x010101)); tft_prints(3,0,":"); tft_set_text_color(WHITE); // Top bar - battery (top-right) u8 pos = (tft_get_orientation() % 2 ? MAX_HEIGHT : MAX_WIDTH); draw_battery_icon(get_voltage_avg()/10); tft_set_bg_color(prev_bg_color); tft_set_text_color(prev_text_color); }