kopia lustrzana https://github.com/pimoroni/pimoroni-pico
				
				
				
			Added RGB88 pen type
							rodzic
							
								
									d1765f2271
								
							
						
					
					
						commit
						6ab9c8b1c7
					
				| 
						 | 
				
			
			@ -24,6 +24,7 @@
 | 
			
		|||
namespace pimoroni {
 | 
			
		||||
  typedef uint8_t RGB332;
 | 
			
		||||
  typedef uint16_t RGB565;
 | 
			
		||||
  typedef uint32_t RGB888;
 | 
			
		||||
  struct RGB {
 | 
			
		||||
    int16_t r, g, b;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -83,6 +84,10 @@ namespace pimoroni {
 | 
			
		|||
    constexpr RGB565 to_rgb332() {
 | 
			
		||||
      return (r & 0b11100000) | ((g & 0b11100000) >> 3) | ((b & 0b11000000) >> 6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    constexpr RGB888 to_rgb888() {
 | 
			
		||||
      return (r << 16) | (g << 8) | (b << 0);
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  typedef int Pen;
 | 
			
		||||
| 
						 | 
				
			
			@ -419,6 +424,23 @@ namespace pimoroni {
 | 
			
		|||
      }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  class PicoGraphics_PenRGB888 : public PicoGraphics {
 | 
			
		||||
    public:
 | 
			
		||||
      RGB src_color;
 | 
			
		||||
      RGB888 color;
 | 
			
		||||
      PicoGraphics_PenRGB888(uint16_t width, uint16_t height, void *frame_buffer);
 | 
			
		||||
      void set_pen(uint c) override;
 | 
			
		||||
      void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
 | 
			
		||||
      int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
 | 
			
		||||
      void set_pixel(const Point &p) override;
 | 
			
		||||
      void set_pixel_span(const Point &p, uint l) override;
 | 
			
		||||
      static size_t buffer_size(uint w, uint h) {
 | 
			
		||||
        return w * h * sizeof(uint32_t);
 | 
			
		||||
      }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  class DisplayDriver {
 | 
			
		||||
    public:
 | 
			
		||||
      uint16_t width;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
#include "pico_graphics.hpp"
 | 
			
		||||
 | 
			
		||||
namespace pimoroni {
 | 
			
		||||
    PicoGraphics_PenRGB888::PicoGraphics_PenRGB888(uint16_t width, uint16_t height, void *frame_buffer)
 | 
			
		||||
    : PicoGraphics(width, height, frame_buffer) {
 | 
			
		||||
        this->pen_type = PEN_RGB888;
 | 
			
		||||
        if(this->frame_buffer == nullptr) {
 | 
			
		||||
            this->frame_buffer = (void *)(new uint8_t[buffer_size(width, height)]);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    void PicoGraphics_PenRGB888::set_pen(uint c) {
 | 
			
		||||
        color = {c, c, c};
 | 
			
		||||
    }
 | 
			
		||||
    void PicoGraphics_PenRGB888::set_pen(uint8_t r, uint8_t g, uint8_t b) {
 | 
			
		||||
        color = {r, g, b};
 | 
			
		||||
    }
 | 
			
		||||
    int PicoGraphics_PenRGB888::create_pen(uint8_t r, uint8_t g, uint8_t b) {
 | 
			
		||||
        return RGB(r, g, b).to_rgb888();
 | 
			
		||||
    }
 | 
			
		||||
    void PicoGraphics_PenRGB888::set_pixel(const Point &p) {
 | 
			
		||||
        uint32_t *buf = (uint32_t *)frame_buffer;
 | 
			
		||||
        buf[p.y * bounds.w + p.x] = color;
 | 
			
		||||
    }
 | 
			
		||||
    void PicoGraphics_PenRGB888::set_pixel_span(const Point &p, uint l) {
 | 
			
		||||
        // pointer to byte in framebuffer that contains this pixel
 | 
			
		||||
        uint32_t *buf = (uint32_t *)frame_buffer;
 | 
			
		||||
        buf = &buf[p.y * bounds.w + p.x];
 | 
			
		||||
 | 
			
		||||
        while(l--) {
 | 
			
		||||
            *buf++ = color;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Ładowanie…
	
		Reference in New Issue