Make Pixel static.
This commit is contained in:
		
							parent
							
								
									fc0fd98426
								
							
						
					
					
						commit
						a91352ffcd
					
				@ -1,5 +1,6 @@
 | 
				
			|||||||
## IDF Component Manager Manifest File
 | 
					## IDF Component Manager Manifest File
 | 
				
			||||||
dependencies:
 | 
					dependencies:
 | 
				
			||||||
 | 
					  idf: '>=5.3.0'
 | 
				
			||||||
  espressif/arduino-esp32: ^3.1.1
 | 
					  espressif/arduino-esp32: ^3.1.1
 | 
				
			||||||
  lvgl/lvgl: "9.2.0"
 | 
					  lvgl/lvgl: "9.2.0"
 | 
				
			||||||
  esp_lcd_sh1107: "^1"
 | 
					  esp_lcd_sh1107: "^1"
 | 
				
			||||||
@ -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()
 | 
					  // lv_draw_sw_i1_convert_to_vtiled()
 | 
				
			||||||
  for (int32_t y = y1; y <= y2; y++) {
 | 
					  for (int32_t y = y1; y <= y2; y++) {
 | 
				
			||||||
    for (int32_t x = x1; x <= x2; x++) {
 | 
					    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.
 | 
					      // True if the pixel is lit, else false.
 | 
				
			||||||
      bool chroma_color =
 | 
					      bool chroma_color = px_map[h_offset] & Pixel::msb_mask(x);
 | 
				
			||||||
          px_map[pixel.horizontal_byte_offset()] & Pixel::msb_mask(x);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // We need an additional buffer for transposing the pixel data to the
 | 
					      // We need an additional buffer for transposing the pixel data to the
 | 
				
			||||||
      // vertical format required by the display driver.
 | 
					      // vertical format required by the display driver.
 | 
				
			||||||
      uint8_t *buf = IPanelDevice::get_additional_draw_buffer();
 | 
					      uint8_t *buf = IPanelDevice::get_additional_draw_buffer();
 | 
				
			||||||
      // Move to the position in the auxillary buffer where the pixel is stored.
 | 
					      // 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.
 | 
					      // Write the single bit to the monochrome display mapped vertically.
 | 
				
			||||||
      // Take the Least Significant Bit mask of the Y coordinate to select the
 | 
					      // Take the Least Significant Bit mask of the Y coordinate to select the
 | 
				
			||||||
 | 
				
			|||||||
@ -33,9 +33,6 @@
 | 
				
			|||||||
 * but using this helper reduces the risk of errors.
 | 
					 * but using this helper reduces the risk of errors.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct Pixel {
 | 
					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
 | 
					   * Calculate byte offset for the pixel at [x,y] within a horizontally-mapped
 | 
				
			||||||
   * monochrome uint8 draw buffer, using the initialized horizontal resolution.
 | 
					   * 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
 | 
					   * column (x_) as `160 + (20 >> 3)`, or `160 + (20 / 8)` to get a final offset
 | 
				
			||||||
   * of 162.
 | 
					   * 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].
 | 
					   * @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.
 | 
					    // 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
 | 
					   * `128 + 20` to get a final offset of 148, because the pixels are stored in a
 | 
				
			||||||
   * columnar format.
 | 
					   * 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.
 | 
					    // 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
 | 
					  [[maybe_unused]] [[nodiscard]] static uint8_t
 | 
				
			||||||
  lsb_mask(const int32_t &i) { return 1 << (i % 8); }
 | 
					  lsb_mask(const int32_t &i) { return 1 << (i % 8); }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  int32_t x_, y_;
 | 
					 | 
				
			||||||
  uint16_t hor_res_;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user