MCPcopy Create free account
hub / github.com/BruceDevices/firmware / drawBmp

Function drawBmp

src/core/display.cpp:1643–1718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1641 return result;
1642}
1643bool drawBmp(FS &fs, String filename, int x, int y, bool center) {
1644 if ((x >= tft.width()) || (y >= tft.height())) return false;
1645 uint32_t startTime = millis();
1646
1647 File bmpFS;
1648
1649 // Open requested file on SD card
1650 bmpFS = fs.open(filename, "r");
1651
1652 if (!bmpFS) {
1653 Serial.print("File not found");
1654 goto ERROR;
1655 }
1656
1657 uint32_t seekOffset;
1658 uint16_t w, h, row, col;
1659 uint8_t r, g, b;
1660
1661 if (read16(bmpFS) == 0x4D42) {
1662 read32(bmpFS);
1663 read32(bmpFS);
1664 seekOffset = read32(bmpFS);
1665 read32(bmpFS);
1666 w = read32(bmpFS);
1667 h = read32(bmpFS);
1668 if (center) {
1669 x = x + (tftWidth - w) / 2;
1670 y = y + (tftHeight - h) / 2;
1671 }
1672
1673 if ((read16(bmpFS) == 1) && (read16(bmpFS) == 24) && (read32(bmpFS) == 0)) {
1674 y += h - 1;
1675
1676 bool oldSwapBytes = tft.getSwapBytes();
1677 tft.setSwapBytes(true);
1678 bmpFS.seek(seekOffset);
1679
1680 uint16_t padding = (4 - ((w * 3) & 3)) & 3;
1681 uint8_t lineBuffer[w * 3 + padding];
1682
1683 for (row = 0; row < h; row++) {
1684
1685 bmpFS.read(lineBuffer, sizeof(lineBuffer));
1686 uint8_t *bptr = lineBuffer;
1687 uint16_t *tptr = (uint16_t *)lineBuffer;
1688 // Convert 24 to 16-bit colours
1689 for (uint16_t col = 0; col < w; col++) {
1690 b = *bptr++;
1691 g = *bptr++;
1692 r = *bptr++;
1693 *tptr++ = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
1694 }
1695
1696 // Push the pixel row to screen, pushImage will crop the line if needed
1697 // y is decremented as the BMP image is drawn bottom up
1698 tft.drawPixel(
1699 0, 0, 0
1700 ); // shared TFT_Spi devices struggle to work, need call a line first sometimes

Callers 1

drawImgFunction · 0.85

Calls 13

millisFunction · 0.85
read16Function · 0.85
read32Function · 0.85
closeMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45
printMethod · 0.45
getSwapBytesMethod · 0.45
setSwapBytesMethod · 0.45
readMethod · 0.45
drawPixelMethod · 0.45
pushImageMethod · 0.45

Tested by

no test coverage detected