Make Pixel static.

This commit is contained in:
Shaun Reed 2025-03-01 16:49:15 -05:00
parent fc0fd98426
commit a91352ffcd
3 changed files with 16 additions and 15 deletions

View File

@ -1,5 +1,6 @@
## IDF Component Manager Manifest File
dependencies:
idf: '>=5.3.0'
espressif/arduino-esp32: ^3.1.1
lvgl/lvgl: "9.2.0"
esp_lcd_sh1107: "^1"

View File

@ -44,17 +44,16 @@ void IPanelDevice::lvgl_flush_cb(lv_display_t *display, const lv_area_t *area,
// lv_draw_sw_i1_convert_to_vtiled()
for (int32_t y = y1; y <= y2; y++) {
for (int32_t x = x1; x <= x2; x++) {
Pixel pixel(x, y, hor_res);
// Get the byte offset of the pixel coordinates using horizontal-mapping.
int h_offset = Pixel::horizontal_byte_offset(x, y, hor_res);
// True if the pixel is lit, else false.
bool chroma_color =
px_map[pixel.horizontal_byte_offset()] & Pixel::msb_mask(x);
bool chroma_color = px_map[h_offset] & Pixel::msb_mask(x);
// We need an additional buffer for transposing the pixel data to the
// vertical format required by the display driver.
uint8_t *buf = IPanelDevice::get_additional_draw_buffer();
// Move to the position in the auxillary buffer where the pixel is stored.
buf += pixel.vertical_byte_offset();
buf += Pixel::vertical_byte_offset(x, y, hor_res);
// Write the single bit to the monochrome display mapped vertically.
// Take the Least Significant Bit mask of the Y coordinate to select the

View File

@ -33,9 +33,6 @@
* but using this helper reduces the risk of errors.
*/
struct Pixel {
Pixel(int32_t x, int32_t y, uint16_t horizontal_res) :
x_(x), y_(y), hor_res_(horizontal_res) { }
/**
* Calculate byte offset for the pixel at [x,y] within a horizontally-mapped
* monochrome uint8 draw buffer, using the initialized horizontal resolution.
@ -56,12 +53,15 @@ struct Pixel {
* column (x_) as `160 + (20 >> 3)`, or `160 + (20 / 8)` to get a final offset
* of 162.
*
* @param x X pixel coordinate to find byte offset.
* @param y Y pixel coordinate to find byte offset.
* @return byte offset for a single-byte monochrome pixel at [x,y].
*/
[[nodiscard]] ptrdiff_t horizontal_byte_offset() const
[[maybe_unused]] [[nodiscard]] static ptrdiff_t
horizontal_byte_offset(const int32_t &x, const int32_t &y, const int32_t& hor_res)
{
// Convert pixel (bit) coordinates to byte coordinates in the draw buffer.
return (hor_res_ >> 3) * y_ + (x_ >> 3);
return (hor_res >> 3) * y + (x >> 3);
}
/**
@ -85,11 +85,15 @@ struct Pixel {
* `128 + 20` to get a final offset of 148, because the pixels are stored in a
* columnar format.
*
* @param x X pixel coordinate to find byte offset.
* @param y Y pixel coordinate to find byte offset.
* @return byte offset for a single-byte monochrome pixel at [x,y].
*/
[[nodiscard]] ptrdiff_t vertical_byte_offset() const
[[maybe_unused]] [[nodiscard]] static ptrdiff_t
vertical_byte_offset(const int32_t &x, const int32_t &y, const int32_t& hor_res)
{
// Convert pixel (bit) coordinates to byte coordinates in the draw buffer.
return hor_res_ * (y_ >> 3) + x_;
return hor_res * (y >> 3) + x;
}
/**
@ -117,9 +121,6 @@ struct Pixel {
*/
[[maybe_unused]] [[nodiscard]] static uint8_t
lsb_mask(const int32_t &i) { return 1 << (i % 8); }
int32_t x_, y_;
uint16_t hor_res_;
};