Effective but not large
It is not a bottleneck because the operation speed is fast enough.
c_table
[c_table] is quicker to put in the method, but it may be an error category.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
/*************************************************************************************** ** Function name: pushImage ** Description: plot 8 bit image or sprite using a line buffer ***************************************************************************************/ //2019/4/1 T.K KAI void TFT_eSPI::pushImage(int32_t x, int32_t y, uint32_t w, uint32_t h, uint8_t *data, bool bpp8) { uint16_t c_table[] = {0,2816,5376,7936,8193,11009,13569,16129,16386,19202,21762,24322,24579,27395,29955,32515,32772,35588,38148,40708,40965,43781,46341,48901,49158,51974,54534,57094,57351,60167,62727,65287,32,2848,5408,7968,8225,11041,13601,16161,16418,19234,21794,24354,24611,27427,29987,32547,32804,35620,38180,40740,40997,43813,46373,48933,49190,52006,54566,57126,57383,60199,62759,65319,72,2888,5448,8008,8265,11081,13641,16201,16458,19274,21834,24394,24651,27467,30027,32587,32844,35660,38220,40780,41037,43853,46413,48973,49230,52046,54606,57166,57423,60239,62799,65359,104,2920,5480,8040,8297,11113,13673,16233,16490,19306,21866,24426,24683,27499,30059,32619,32876,35692,38252,40812,41069,43885,46445,49005,49262,52078,54638,57198,57455,60271,62831,65391,144,2960,5520,8080,8337,11153,13713,16273,16530,19346,21906,24466,24723,27539,30099,32659,32916,35732,38292,40852,41109,43925,46485,49045,49302,52118,54678,57238,57495,60311,62871,65431,176,2992,5552,8112,8369,11185,13745,16305,16562,19378,21938,24498,24755,27571,30131,32691,32948,35764,38324,40884,41141,43957,46517,49077,49334,52150,54710,57270,57527,60343,62903,65463,216,3032,5592,8152,8409,11225,13785,16345,16602,19418,21978,24538,24795,27611,30171,32731,32988,35804,38364,40924,41181,43997,46557,49117,49374,52190,54750,57310,57567,60383,62943,65503,248,3064,5624,8184,8441,11257,13817,16377,16634,19450,22010,24570,24827,27643,30203,32763,33020,35836,38396,40956,41213,44029,46589,49149,49406,52222,54782,57342,57599,60415,62975,65535}; if ((x >= (int32_t)_width) || (y >= (int32_t)_height)) return; int32_t dx = 0; int32_t dy = 0; int32_t dw = w; int32_t dh = h; if (x < 0) { dw += x; dx = -x; x = 0; } if (y < 0) { dh += y; dy = -y; y = 0; } if ((x + w) > _width ) dw = _width - x; if ((y + h) > _height) dh = _height - y; if (dw < 1 || dh < 1) return; spi_begin(); inTransaction = true; setAddrWindow(x, y, x + dw - 1, y + dh - 1); // Sets CS low and sent RAMWR // Line buffer makes plotting faster uint16_t lineBuf[dw]; if (bpp8) { //uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table _lastColor = -1; // Set to illegal value // Used to store last shifted colour //uint8_t msbColor = 0; //uint8_t lsbColor = 0; data += dx + dy * w; while (dh--) { uint32_t len = dw; uint8_t* ptr = data; uint16_t* linePtr = lineBuf; while(len--) { *linePtr++ = c_table[*ptr++]; /* // Shifts are slow so check if colour has changed first if (color != _lastColor) { // =====Green===== ===============Red============== msbColor = (color & 0x1C)>>2 | (color & 0xC0)>>3 | (color & 0xE0); // =====Green===== =======Blue====== lsbColor = (color & 0x1C)<<3 | blue[color & 0x03]; _lastColor = color; } *linePtr++ = msbColor; *linePtr++ = lsbColor;*/ } SPI.writeBytes((uint8_t*)lineBuf,dw<<1); data += w; } } else { while (dh--) { w = (w+7) & 0xFFF8; int32_t len = dw; uint8_t* ptr = data; uint8_t* linePtr = (uint8_t*)lineBuf; uint8_t bits = 8; while(len>0) { if (len < 8) bits = len; uint32_t xp = dx; for (uint16_t i = 0; i < bits; i++) { uint8_t col = (ptr[(xp + dy * w)>>3] << (xp & 0x7)) & 0x80; if (col) {*linePtr++ = bitmap_fg>>8; *linePtr++ = (uint8_t) bitmap_fg;} else {*linePtr++ = bitmap_bg>>8; *linePtr++ = (uint8_t) bitmap_bg;} //if (col) drawPixel((dw-len)+xp,h-dh,bitmap_fg); //else drawPixel((dw-len)+xp,h-dh,bitmap_bg); xp++; } ptr++; len -= 8; } pushColors(lineBuf, dw, false); dy++; } } CS_H; inTransaction = false; spi_end(); } /*************************************************************************************** ** Function name: pushImage ** Description: plot 8 or 1 bit image or sprite with a transparent colour ***************************************************************************************/ //2019/4/1 T.K KAI void TFT_eSPI::pushImage(int32_t x, int32_t y, uint32_t w, uint32_t h, uint8_t *data, uint8_t transp, bool bpp8) { uint16_t c_table[] = {0,11,21,31,288,299,309,319,576,587,597,607,864,875,885,895,1152,1163,1173,1183,1440,1451,1461,1471,1728,1739,1749,1759,2016,2027,2037,2047,8192,8203,8213,8223,8480,8491,8501,8511,8768,8779,8789,8799,9056,9067,9077,9087,9344,9355,9365,9375,9632,9643,9653,9663,9920,9931,9941,9951,10208,10219,10229,10239,18432,18443,18453,18463,18720,18731,18741,18751,19008,19019,19029,19039,19296,19307,19317,19327,19584,19595,19605,19615,19872,19883,19893,19903,20160,20171,20181,20191,20448,20459,20469,20479,26624,26635,26645,26655,26912,26923,26933,26943,27200,27211,27221,27231,27488,27499,27509,27519,27776,27787,27797,27807,28064,28075,28085,28095,28352,28363,28373,28383,28640,28651,28661,28671,36864,36875,36885,36895,37152,37163,37173,37183,37440,37451,37461,37471,37728,37739,37749,37759,38016,38027,38037,38047,38304,38315,38325,38335,38592,38603,38613,38623,38880,38891,38901,38911,45056,45067,45077,45087,45344,45355,45365,45375,45632,45643,45653,45663,45920,45931,45941,45951,46208,46219,46229,46239,46496,46507,46517,46527,46784,46795,46805,46815,47072,47083,47093,47103,55296,55307,55317,55327,55584,55595,55605,55615,55872,55883,55893,55903,56160,56171,56181,56191,56448,56459,56469,56479,56736,56747,56757,56767,57024,57035,57045,57055,57312,57323,57333,57343,63488,63499,63509,63519,63776,63787,63797,63807,64064,64075,64085,64095,64352,64363,64373,64383,64640,64651,64661,64671,64928,64939,64949,64959,65216,65227,65237,65247,65504,65515,65525,65535}; if ((x >= (int32_t)_width) || (y >= (int32_t)_height)) return; int32_t dx = 0; int32_t dy = 0; int32_t dw = w; int32_t dh = h; if (x < 0) { dw += x; dx = -x; x = 0; } if (y < 0) { dh += y; dy = -y; y = 0; } if ((x + w) > _width ) dw = _width - x; if ((y + h) > _height) dh = _height - y; if (dw < 1 || dh < 1) return; spi_begin(); inTransaction = true; int32_t xe = x + dw - 1, ye = y + dh - 1; // Line buffer makes plotting faster uint16_t lineBuf[dw]; if (bpp8) { data += dx + dy * w; //uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table _lastColor = -1; // Set to illegal value // Used to store last shifted colour uint8_t msbColor = 0; uint8_t lsbColor = 0; int32_t spx = x, spy = y; while (dh--) { int32_t len = dw; uint8_t* ptr = data; uint16_t* linePtr = lineBuf; int32_t px = x; boolean move = true; uint16_t np = 0; while (len--) { if (transp != *ptr) { if (move) { move = false; setAddrWindow(px, y, xe, ye);} *linePtr++ = c_table[*ptr]; /* // Shifts are slow so check if colour has changed first if (color != _lastColor) { // =====Green===== ===============Red============== msbColor = (color & 0x1C)>>2 | (color & 0xC0)>>3 | (color & 0xE0); // =====Green===== =======Blue====== lsbColor = (color & 0x1C)<<3 | blue[color & 0x03]; _lastColor = color; } *linePtr++ = msbColor; *linePtr++ = lsbColor;*/ np++; } else { move = true; if (np) { SPI.writeBytes((uint8_t*)lineBuf,np<<1); linePtr = lineBuf; np = 0; } } px++; ptr++; } if (np) SPI.writeBytes((uint8_t*)lineBuf,np<<1); y++; data += w; } } else { w = (w+7) & 0xFFF8; while (dh--) { int32_t px = x; boolean move = true; uint16_t np = 0; int32_t len = dw; uint8_t* ptr = data; uint8_t bits = 8; while(len>0) { if (len < 8) bits = len; uint32_t xp = dx; uint32_t yp = (dy * w)>>3; for (uint16_t i = 0; i < bits; i++) { //uint8_t col = (ptr[(xp + dy * w)>>3] << (xp & 0x7)) & 0x80; if ((ptr[(xp>>3) + yp] << (xp & 0x7)) & 0x80) { if (move) { move = false; setAddrWindow(px, y, xe, ye); } np++; } else { if (np) { pushColor(bitmap_fg, np); np = 0; move = true; } } px++; xp++; } ptr++; len -= 8; } if (np) pushColor(bitmap_fg, np); y++; dy++; } } CS_H; inTransaction = false; spi_end(); } |