Skip to content

Commit 64aae85

Browse files
implement drawYCbCrBitmap()
1 parent 03bb9db commit 64aae85

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

src/display/Arduino_DSI_Display.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,62 @@ void Arduino_DSI_Display::flush(bool force_flush)
490490
}
491491
}
492492

493+
void Arduino_DSI_Display::drawYCbCrBitmap(int16_t x, int16_t y, uint8_t *yData, uint8_t *cbData, uint8_t *crData, int16_t w, int16_t h)
494+
{
495+
if (
496+
((x + w - 1) < 0) || // Outside left
497+
((y + h - 1) < 0) || // Outside top
498+
(x > _max_x) || // Outside right
499+
(y > _max_y) // Outside bottom
500+
)
501+
{
502+
return;
503+
}
504+
else
505+
{
506+
int cols = w >> 1;
507+
int rows = h >> 1;
508+
509+
uint16_t *dest = _framebuffer;
510+
dest += y * _fb_width;
511+
uint16_t *cachePos = dest;
512+
dest += x;
513+
uint16_t *dest2 = dest + _fb_width;
514+
uint8_t *yData2 = yData + w;
515+
516+
uint8_t pxCb, pxCr;
517+
int16_t pxR, pxG, pxB, pxY;
518+
519+
for (int row = 0; row < rows; ++row)
520+
{
521+
for (int col = 0; col < w;)
522+
{
523+
pxCb = *cbData++;
524+
pxCr = *crData++;
525+
pxR = CR2R16[pxCr];
526+
pxG = -CB2G16[pxCb] - CR2G16[pxCr];
527+
pxB = CB2B16[pxCb];
528+
pxY = Y2I16[*yData++];
529+
dest[col] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
530+
pxY = Y2I16[*yData2++];
531+
dest2[col++] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
532+
pxY = Y2I16[*yData++];
533+
dest[col] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
534+
pxY = Y2I16[*yData2++];
535+
dest2[col++] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
536+
}
537+
yData += w;
538+
yData2 += w;
539+
dest = dest2 + _fb_width;
540+
dest2 = dest + _fb_width;
541+
}
542+
if (_auto_flush)
543+
{
544+
esp_cache_msync(cachePos, _fb_width * h * 2, ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_UNALIGNED);
545+
}
546+
}
547+
}
548+
493549
uint16_t *Arduino_DSI_Display::getFramebuffer()
494550
{
495551
return _framebuffer;

src/display/Arduino_DSI_Display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Arduino_DSI_Display : public Arduino_GFX
9797
void draw16bitBeRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) override;
9898
void flush(bool force_flush = false) override;
9999

100+
void drawYCbCrBitmap(int16_t x, int16_t y, uint8_t *yData, uint8_t *cbData, uint8_t *crData, int16_t w, int16_t h);
100101
uint16_t *getFramebuffer();
101102

102103
protected:

src/display/Arduino_RGB_Display.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,62 @@ void Arduino_RGB_Display::draw16bitBeRGBBitmap(int16_t x, int16_t y,
505505
}
506506
}
507507

508+
void Arduino_RGB_Display::drawYCbCrBitmap(int16_t x, int16_t y, uint8_t *yData, uint8_t *cbData, uint8_t *crData, int16_t w, int16_t h)
509+
{
510+
if (
511+
((x + w - 1) < 0) || // Outside left
512+
((y + h - 1) < 0) || // Outside top
513+
(x > _max_x) || // Outside right
514+
(y > _max_y) // Outside bottom
515+
)
516+
{
517+
return;
518+
}
519+
else
520+
{
521+
int cols = w >> 1;
522+
int rows = h >> 1;
523+
524+
uint16_t *dest = _framebuffer;
525+
dest += y * _fb_width;
526+
uint16_t *cachePos = dest;
527+
dest += x;
528+
uint16_t *dest2 = dest + _fb_width;
529+
uint8_t *yData2 = yData + w;
530+
531+
uint8_t pxCb, pxCr;
532+
int16_t pxR, pxG, pxB, pxY;
533+
534+
for (int row = 0; row < rows; ++row)
535+
{
536+
for (int col = 0; col < w;)
537+
{
538+
pxCb = *cbData++;
539+
pxCr = *crData++;
540+
pxR = CR2R16[pxCr];
541+
pxG = -CB2G16[pxCb] - CR2G16[pxCr];
542+
pxB = CB2B16[pxCb];
543+
pxY = Y2I16[*yData++];
544+
dest[col] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
545+
pxY = Y2I16[*yData2++];
546+
dest2[col++] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
547+
pxY = Y2I16[*yData++];
548+
dest[col] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
549+
pxY = Y2I16[*yData2++];
550+
dest2[col++] = CLIPR[pxY + pxR] | CLIPG[pxY + pxG] | CLIPB[pxY + pxB];
551+
}
552+
yData += w;
553+
yData2 += w;
554+
dest = dest2 + _fb_width;
555+
dest2 = dest + _fb_width;
556+
}
557+
if (_auto_flush)
558+
{
559+
Cache_WriteBack_Addr(cachePos, _fb_width * h * 2);
560+
}
561+
}
562+
}
563+
508564
void Arduino_RGB_Display::flush(bool force_flush)
509565
{
510566
if (force_flush || (!_auto_flush))

src/display/Arduino_RGB_Display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,7 @@ class Arduino_RGB_Display : public Arduino_GFX
24722472
void draw16bitBeRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) override;
24732473
void flush(bool force_flush = false) override;
24742474

2475+
void drawYCbCrBitmap(int16_t x, int16_t y, uint8_t *yData, uint8_t *cbData, uint8_t *crData, int16_t w, int16_t h);
24752476
uint16_t *getFramebuffer();
24762477

24772478
protected:

0 commit comments

Comments
 (0)