Skip to content

Commit

Permalink
#260 facilitate direct use color index
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Feb 17, 2023
1 parent d4193ee commit 9424aed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/canvas/Arduino_Canvas_Indexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ bool Arduino_Canvas_Indexed::begin(int32_t speed)

void Arduino_Canvas_Indexed::writePixelPreclipped(int16_t x, int16_t y, uint16_t color)
{
_framebuffer[((int32_t)y * _width) + x] = get_color_index(color);
if (_isDirectUseColorIndex)
{
_framebuffer[((int32_t)y * _width) + x] = (uint8_t)color;
}
else
{
_framebuffer[((int32_t)y * _width) + x] = get_color_index(color);
}
}

void Arduino_Canvas_Indexed::writeFastVLine(int16_t x, int16_t y,
Expand Down Expand Up @@ -74,7 +81,15 @@ void Arduino_Canvas_Indexed::writeFastVLine(int16_t x, int16_t y,
h = _max_y - y + 1;
} // Clip bottom

uint8_t idx = get_color_index(color);
uint8_t idx;
if (_isDirectUseColorIndex)
{
idx = color;
}
else
{
idx = get_color_index(color);
}

uint8_t *fb = _framebuffer + ((int32_t)y * _width) + x;
while (h--)
Expand Down Expand Up @@ -113,7 +128,15 @@ void Arduino_Canvas_Indexed::writeFastHLine(int16_t x, int16_t y,
w = _max_x - x + 1;
} // Clip right

uint8_t idx = get_color_index(color);
uint8_t idx;
if (_isDirectUseColorIndex)
{
idx = color;
}
else
{
idx = get_color_index(color);
}

uint8_t *fb = _framebuffer + ((int32_t)y * _width) + x;
while (w--)
Expand All @@ -135,6 +158,16 @@ uint8_t *Arduino_Canvas_Indexed::getFramebuffer()
return _framebuffer;
}

uint16_t *Arduino_Canvas_Indexed::getColorIndex()
{
return _color_index;
}

void Arduino_Canvas_Indexed::setDirectUseColorIndex(bool isEnable)
{
_isDirectUseColorIndex = isEnable;
}

uint8_t Arduino_Canvas_Indexed::get_color_index(uint16_t color)
{
color &= _color_mask;
Expand Down
4 changes: 4 additions & 0 deletions src/canvas/Arduino_Canvas_Indexed.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Arduino_Canvas_Indexed : public Arduino_GFX
void flush(void) override;

uint8_t *getFramebuffer();
uint16_t *getColorIndex();
void setDirectUseColorIndex(bool isEnable);

uint8_t get_color_index(uint16_t color);
uint16_t get_index_color(uint8_t idx);
Expand All @@ -31,6 +33,8 @@ class Arduino_Canvas_Indexed : public Arduino_GFX
int16_t _output_x, _output_y;
uint16_t _color_index[COLOR_IDX_SIZE];
uint8_t _indexed_size = 0;
bool _isDirectUseColorIndex = false;

uint8_t _current_mask_level;
uint16_t _color_mask;
#define MAXMASKLEVEL 3
Expand Down

0 comments on commit 9424aed

Please sign in to comment.