@@ -919,6 +919,24 @@ uint16_t TFT_eSprite::readPixelValue(int32_t x, int32_t y)
919919
920920 if (_bpp == 4 )
921921 {
922+ if (rotation == 1 )
923+ {
924+ uint16_t tx = x;
925+ x = _dheight - y - 1 ;
926+ y = tx;
927+ }
928+ else if (rotation == 2 )
929+ {
930+ x = _dwidth - x - 1 ;
931+ y = _dheight - y - 1 ;
932+ }
933+ else if (rotation == 3 )
934+ {
935+ uint16_t tx = x;
936+ x = y;
937+ y = _dwidth - tx - 1 ;
938+ }
939+
922940 if (x >= _dwidth) return 0xFF ;
923941 if ((x & 0x01 ) == 0 )
924942 return _img4[((x+y*_iwidth)>>1 )] >> 4 ; // even index = bits 7 .. 4
@@ -988,6 +1006,24 @@ uint16_t TFT_eSprite::readPixel(int32_t x, int32_t y)
9881006
9891007 if (_bpp == 4 )
9901008 {
1009+ if (rotation == 1 )
1010+ {
1011+ uint16_t tx = x;
1012+ x = _dheight - y - 1 ;
1013+ y = tx;
1014+ }
1015+ else if (rotation == 2 )
1016+ {
1017+ x = _dwidth - x - 1 ;
1018+ y = _dheight - y - 1 ;
1019+ }
1020+ else if (rotation == 3 )
1021+ {
1022+ uint16_t tx = x;
1023+ x = y;
1024+ y = _dwidth - tx - 1 ;
1025+ }
1026+
9911027 if (x >= _dwidth) return 0xFFFF ;
9921028 uint16_t color;
9931029 if ((x & 0x01 ) == 0 )
@@ -1111,7 +1147,7 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_
11111147 int sWidth = (_iwidth >> 1 );
11121148 uint8_t *ptr = (uint8_t *)data;
11131149
1114- if ((x & 0x01 ) == 0 && (dx & 0x01 ) == 0 && (dw & 0x01 ) == 0 )
1150+ if (!rotation && (x & 0x01 ) == 0 && (dx & 0x01 ) == 0 && (dw & 0x01 ) == 0 )
11151151 {
11161152 x = (x >> 1 ) + y * sWidth ;
11171153 dw = (dw >> 1 );
@@ -1555,7 +1591,7 @@ int16_t TFT_eSprite::width(void)
15551591{
15561592 if (!_created ) return 0 ;
15571593
1558- if (_bpp > 1 ) {
1594+ if (_bpp > 1 && _bpp != 4 ) {
15591595 if (_vpDatum) return _xWidth;
15601596 return _dwidth;
15611597 }
@@ -1578,7 +1614,7 @@ int16_t TFT_eSprite::height(void)
15781614{
15791615 if (!_created ) return 0 ;
15801616
1581- if (_bpp > 1 ) {
1617+ if (_bpp > 1 && _bpp != 4 ) {
15821618 if (_vpDatum) return _yHeight;
15831619 return _dheight;
15841620 }
@@ -1595,12 +1631,12 @@ int16_t TFT_eSprite::height(void)
15951631
15961632/* **************************************************************************************
15971633** Function name: setRotation
1598- ** Description: Rotate coordinate frame for 1bpp sprite
1634+ ** Description: Rotate coordinate frame for 1bpp and 4bpp sprite
15991635***************************************************************************************/
1600- // Does nothing for 4, 8 and 16 bpp sprites.
1636+ // Does nothing for 8 and 16 bpp sprites.
16011637void TFT_eSprite::setRotation (uint8_t r)
16021638{
1603- if (_bpp != 1 ) return ;
1639+ if (_bpp != 1 && _bpp != 4 ) return ;
16041640
16051641 rotation = r;
16061642
@@ -1648,6 +1684,24 @@ void TFT_eSprite::drawPixel(int32_t x, int32_t y, uint32_t color)
16481684 }
16491685 else if (_bpp == 4 )
16501686 {
1687+ if (rotation == 1 )
1688+ {
1689+ uint16_t tx = x;
1690+ x = _dwidth - y - 1 ;
1691+ y = tx;
1692+ }
1693+ else if (rotation == 2 )
1694+ {
1695+ x = _dwidth - x - 1 ;
1696+ y = _dheight - y - 1 ;
1697+ }
1698+ else if (rotation == 3 )
1699+ {
1700+ uint16_t tx = x;
1701+ x = y;
1702+ y = _dheight - tx - 1 ;
1703+ }
1704+
16511705 uint8_t c = color & 0x0F ;
16521706 int index = (x+y*_iwidth)>>1 ;;
16531707 if ((x & 0x01 ) == 0 ) {
@@ -1774,6 +1828,13 @@ void TFT_eSprite::drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color)
17741828 }
17751829 else if (_bpp == 4 )
17761830 {
1831+ if (rotation)
1832+ {
1833+ if (h < 1 ) return ;
1834+ while (h--) drawPixel (x, y++, color);
1835+ return ;
1836+ }
1837+
17771838 if ((x & 0x01 ) == 0 )
17781839 {
17791840 uint8_t c = (uint8_t ) (color & 0xF ) << 4 ;
@@ -1834,6 +1895,12 @@ void TFT_eSprite::drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color)
18341895 }
18351896 else if (_bpp == 4 )
18361897 {
1898+ if (rotation)
1899+ {
1900+ if (w < 1 ) return ;
1901+ while (w--) drawPixel (x++, y, color);
1902+ return ;
1903+ }
18371904 uint8_t c = (uint8_t )color & 0x0F ;
18381905 uint8_t c2 = (c | ((c << 4 ) & 0xF0 ));
18391906 if ((x & 0x01 ) == 1 )
@@ -1913,6 +1980,18 @@ void TFT_eSprite::fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t
19131980 }
19141981 else if (_bpp == 4 )
19151982 {
1983+ if (rotation)
1984+ {
1985+ if (w < 1 || h < 1 ) return ;
1986+ for (int32_t yy = 0 ; yy < h; yy++)
1987+ {
1988+ for (int32_t xx = 0 ; xx < w; xx++)
1989+ {
1990+ drawPixel (x + xx, y + yy, color);
1991+ }
1992+ }
1993+ return ;
1994+ }
19161995 uint8_t c1 = (uint8_t )color & 0x0F ;
19171996 uint8_t c2 = c1 | ((c1 << 4 ) & 0xF0 );
19181997 if ((x & 0x01 ) == 0 && (w & 0x01 ) == 0 )
0 commit comments