Remove duplicate convert_to_8bit_color_ function. (#2469)

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
This commit is contained in:
Dave T 2022-05-12 11:18:51 +01:00 committed by GitHub
parent 03d5a0ec1d
commit 39c6c2417a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 28 deletions

View File

@ -66,6 +66,9 @@ class ColorUtil {
} }
return color_return; return color_return;
} }
static inline Color rgb332_to_color(uint8_t rgb332_color) {
return to_color((uint32_t) rgb332_color, COLOR_ORDER_RGB, COLOR_BITNESS_332);
}
static uint8_t color_to_332(Color color, ColorOrder color_order = ColorOrder::COLOR_ORDER_RGB) { static uint8_t color_to_332(Color color, ColorOrder color_order = ColorOrder::COLOR_ORDER_RGB) {
uint16_t red_color, green_color, blue_color; uint16_t red_color, green_color, blue_color;
@ -100,7 +103,6 @@ class ColorUtil {
} }
return 0; return 0;
} }
static uint32_t color_to_grayscale4(Color color) { static uint32_t color_to_grayscale4(Color color) {
uint32_t gs4 = esp_scale8(color.white, 15); uint32_t gs4 = esp_scale8(color.white, 15);
return gs4; return gs4;

View File

@ -112,29 +112,9 @@ void ILI9341Display::display_() {
this->y_high_ = 0; this->y_high_ = 0;
} }
uint16_t ILI9341Display::convert_to_16bit_color_(uint8_t color_8bit) {
int r = color_8bit >> 5;
int g = (color_8bit >> 2) & 0x07;
int b = color_8bit & 0x03;
uint16_t color = (r * 0x04) << 11;
color |= (g * 0x09) << 5;
color |= (b * 0x0A);
return color;
}
uint8_t ILI9341Display::convert_to_8bit_color_(uint16_t color_16bit) {
// convert 16bit color to 8 bit buffer
uint8_t r = color_16bit >> 11;
uint8_t g = (color_16bit >> 5) & 0x3F;
uint8_t b = color_16bit & 0x1F;
return ((b / 0x0A) | ((g / 0x09) << 2) | ((r / 0x04) << 5));
}
void ILI9341Display::fill(Color color) { void ILI9341Display::fill(Color color) {
auto color565 = display::ColorUtil::color_to_565(color); uint8_t color332 = display::ColorUtil::color_to_332(color, display::ColorOrder::COLOR_ORDER_RGB);
memset(this->buffer_, convert_to_8bit_color_(color565), this->get_buffer_length_()); memset(this->buffer_, color332, this->get_buffer_length_());
this->x_low_ = 0; this->x_low_ = 0;
this->y_low_ = 0; this->y_low_ = 0;
this->x_high_ = this->get_width_internal() - 1; this->x_high_ = this->get_width_internal() - 1;
@ -181,8 +161,8 @@ void HOT ILI9341Display::draw_absolute_pixel_internal(int x, int y, Color color)
this->y_high_ = (y > this->y_high_) ? y : this->y_high_; this->y_high_ = (y > this->y_high_) ? y : this->y_high_;
uint32_t pos = (y * width_) + x; uint32_t pos = (y * width_) + x;
auto color565 = display::ColorUtil::color_to_565(color); uint8_t color332 = display::ColorUtil::color_to_332(color, display::ColorOrder::COLOR_ORDER_RGB);
buffer_[pos] = convert_to_8bit_color_(color565); buffer_[pos] = color332;
} }
// should return the total size: return this->get_width_internal() * this->get_height_internal() * 2 // 16bit color // should return the total size: return this->get_width_internal() * this->get_height_internal() * 2 // 16bit color
@ -247,7 +227,7 @@ uint32_t ILI9341Display::buffer_to_transfer_(uint32_t pos, uint32_t sz) {
} }
for (uint32_t i = 0; i < sz; ++i) { for (uint32_t i = 0; i < sz; ++i) {
uint16_t color = convert_to_16bit_color_(*src++); uint16_t color = display::ColorUtil::color_to_565(display::ColorUtil::rgb332_to_color(*src++));
*dst++ = (uint8_t)(color >> 8); *dst++ = (uint8_t)(color >> 8);
*dst++ = (uint8_t) color; *dst++ = (uint8_t) color;
} }

View File

@ -51,8 +51,6 @@ class ILI9341Display : public PollingComponent,
void reset_(); void reset_();
void fill_internal_(Color color); void fill_internal_(Color color);
void display_(); void display_();
uint16_t convert_to_16bit_color_(uint8_t color_8bit);
uint8_t convert_to_8bit_color_(uint16_t color_16bit);
ILI9341Model model_; ILI9341Model model_;
int16_t width_{320}; ///< Display width as modified by current rotation int16_t width_{320}; ///< Display width as modified by current rotation