Skip to content

Commit

Permalink
Arduino_ESP32SPI implement writeYCbCrPixels
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Mar 5, 2024
1 parent 9a60955 commit 0c10364
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/databus/Arduino_ESP32SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,53 @@ void Arduino_ESP32SPI::writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, ui
}
}

void Arduino_ESP32SPI::writeYCbCrPixels(uint8_t *yData, uint8_t *cbData, uint8_t *crData, uint16_t w, uint16_t h)
{
if (
(_dc == GFX_NOT_DEFINED) // 9-bit SPI
|| (w > (ESP32SPI_MAX_PIXELS_AT_ONCE / 2)))
{
Arduino_DataBus::writeYCbCrPixels(yData, cbData, crData, w, h);
}
else
{
int cols = w >> 1;
int rows = h >> 1;
uint8_t *yData2 = yData + w;
uint16_t *dest = _buffer16;
uint16_t *dest2 = dest + w;

uint16_t out_bits = w << 5;
for (int row = 0; row < rows; ++row)
{
for (int col = 0; col < cols; ++col)
{
uint8_t cb = *cbData++;
uint8_t cr = *crData++;
int16_t r = CR2R16[cr];
int16_t g = -CB2G16[cb] - CR2G16[cr];
int16_t b = CB2B16[cb];
int16_t y;

y = Y2I16[*yData++];
*dest++ = CLIPRBE[y + r] | CLIPGBE[y + g] | CLIPBBE[y + b];
y = Y2I16[*yData++];
*dest++ = CLIPRBE[y + r] | CLIPGBE[y + g] | CLIPBBE[y + b];
y = Y2I16[*yData2++];
*dest2++ = CLIPRBE[y + r] | CLIPGBE[y + g] | CLIPBBE[y + b];
y = Y2I16[*yData2++];
*dest2++ = CLIPRBE[y + r] | CLIPGBE[y + g] | CLIPBBE[y + b];
}
POLL(out_bits);

yData += w;
yData2 += w;
dest = _buffer16;
dest2 = dest + w;
}
}
}

/**
* @brief flush_data_buf
*
Expand Down
1 change: 1 addition & 0 deletions src/databus/Arduino_ESP32SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Arduino_ESP32SPI : public Arduino_DataBus

void writeIndexedPixels(uint8_t *data, uint16_t *idx, uint32_t len) override;
void writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len) override;
void writeYCbCrPixels(uint8_t *yData, uint8_t *cbData, uint8_t *crData, uint16_t w, uint16_t h) override;

protected:
void flush_data_buf();
Expand Down

0 comments on commit 0c10364

Please sign in to comment.