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

Method pushRotated

lib/TFT_eSPI/Extensions/Sprite.cpp:396–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394***************************************************************************************/
395#define FP_SCALE 10
396bool TFT_eSprite::pushRotated(int16_t angle, uint32_t transp)
397{
398 if ( !_created || _tft->_vpOoB) return false;
399
400 // Bounding box parameters
401 int16_t min_x;
402 int16_t min_y;
403 int16_t max_x;
404 int16_t max_y;
405
406 // Get the bounding box of this rotated source Sprite relative to Sprite pivot
407 if ( !getRotatedBounds(angle, &min_x, &min_y, &max_x, &max_y) ) return false;
408
409 uint16_t sline_buffer[max_x - min_x + 1];
410
411 int32_t xt = min_x - _tft->_xPivot;
412 int32_t yt = min_y - _tft->_yPivot;
413 uint32_t xe = _dwidth << FP_SCALE;
414 uint32_t ye = _dheight << FP_SCALE;
415 uint16_t tpcolor = (uint16_t)transp;
416
417 if (transp != 0x00FFFFFF) {
418 if (_bpp == 4) tpcolor = _colorMap[transp & 0x0F];
419 tpcolor = tpcolor>>8 | tpcolor<<8; // Working with swapped color bytes
420 }
421 _tft->startWrite(); // Avoid transaction overhead for every tft pixel
422
423 // Scan destination bounding box and fetch transformed pixels from source Sprite
424 for (int32_t y = min_y; y <= max_y; y++, yt++) {
425 int32_t x = min_x;
426 uint32_t xs = (_cosra * xt - (_sinra * yt - (_xPivot << FP_SCALE)) + (1 << (FP_SCALE - 1)));
427 uint32_t ys = (_sinra * xt + (_cosra * yt + (_yPivot << FP_SCALE)) + (1 << (FP_SCALE - 1)));
428
429 while ((xs >= xe || ys >= ye) && x < max_x) { x++; xs += _cosra; ys += _sinra; }
430 if (x == max_x) continue;
431
432 uint32_t pixel_count = 0;
433 do {
434 uint32_t rp;
435 int32_t xp = xs >> FP_SCALE;
436 int32_t yp = ys >> FP_SCALE;
437 if (_bpp == 16) {rp = _img[xp + yp * _iwidth]; }
438 else { rp = readPixel(xp, yp); rp = (uint16_t)(rp>>8 | rp<<8); }
439 if (transp != 0x00FFFFFF && tpcolor == rp) {
440 if (pixel_count) {
441 // TFT window is already clipped, so this is faster than pushImage()
442 _tft->setWindow(x - pixel_count, y, x - 1, y);
443 _tft->pushPixels(sline_buffer, pixel_count);
444 pixel_count = 0;
445 }
446 }
447 else {
448 sline_buffer[pixel_count++] = rp;
449 }
450 } while (++x < max_x && (xs += _cosra) < xe && (ys += _sinra) < ye);
451 if (pixel_count) {
452 // TFT window is already clipped, so this is faster than pushImage()
453 _tft->setWindow(x - pixel_count, y, x - 1, y);

Callers

nothing calls this directly

Calls 6

startWriteMethod · 0.80
endWriteMethod · 0.80
setWindowMethod · 0.45
getSwapBytesMethod · 0.45
setSwapBytesMethod · 0.45
pushImageMethod · 0.45

Tested by

no test coverage detected