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

Method drawPixel

lib/TFT_eSPI/Extensions/Sprite.cpp:1630–1683  ·  view source on GitHub ↗

** Function name: drawPixel ** Description: push a single pixel at an arbitrary position ***************************************************************************************/

Source from the content-addressed store, hash-verified

1628** Description: push a single pixel at an arbitrary position
1629***************************************************************************************/
1630void TFT_eSprite::drawPixel(int32_t x, int32_t y, uint32_t color)
1631{
1632 if (!_created || _vpOoB) return;
1633
1634 x+= _xDatum;
1635 y+= _yDatum;
1636
1637 // Range checking
1638 if ((x < _vpX) || (y < _vpY) ||(x >= _vpW) || (y >= _vpH)) return;
1639
1640 if (_bpp == 16)
1641 {
1642 color = (color >> 8) | (color << 8);
1643 _img[x+y*_iwidth] = (uint16_t) color;
1644 }
1645 else if (_bpp == 8)
1646 {
1647 _img8[x+y*_iwidth] = (uint8_t)((color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3);
1648 }
1649 else if (_bpp == 4)
1650 {
1651 uint8_t c = color & 0x0F;
1652 int index = (x+y*_iwidth)>>1;;
1653 if ((x & 0x01) == 0) {
1654 _img4[index] = (uint8_t)((c << 4) | (_img4[index] & 0x0F));
1655 }
1656 else {
1657 _img4[index] = (uint8_t)(c | (_img4[index] & 0xF0));
1658 }
1659 }
1660 else // 1 bpp
1661 {
1662 if (rotation == 1)
1663 {
1664 uint16_t tx = x;
1665 x = _dwidth - y - 1;
1666 y = tx;
1667 }
1668 else if (rotation == 2)
1669 {
1670 x = _dwidth - x - 1;
1671 y = _dheight - y - 1;
1672 }
1673 else if (rotation == 3)
1674 {
1675 uint16_t tx = x;
1676 x = y;
1677 y = _dheight - tx - 1;
1678 }
1679
1680 if (color) _img8[(x + y * _bitwidth)>>3] |= (0x80 >> (x & 0x7));
1681 else _img8[(x + y * _bitwidth)>>3] &= ~(0x80 >> (x & 0x7));
1682 }
1683}
1684
1685
1686/***************************************************************************************

Callers 1

pushSpriteMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected