You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB

  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. #include "spilcd_gfx.h"
  5. void lcd_drawPixel(lcd_t* lcd, uint8 x, uint8 y, uint8 r, uint8 g, uint8 b)
  6. {
  7. if(lcd_setWindow(lcd, x, y, x, y)) return;
  8. lcd_pushPixel(lcd, r, g, b);
  9. }
  10. void lcd_fillRect(lcd_t* lcd, uint8 x, uint8 y, uint8 w, uint8 h,
  11. uint8 r, uint8 g, uint8 b)
  12. {
  13. if((w == 0) || (h == 0)) return;
  14. if((x+w-1) >= lcd->width) w = lcd->width - x;
  15. if((y+h-1) >= lcd->height) h = lcd->height - y;
  16. if(lcd_setWindow(lcd, x, y, x+w-1, y+h-1)) return;
  17. #define BUFFER_PIXELS 64
  18. int wh = w*h;
  19. uint8 buffer[BUFFER_PIXELS * sizeof(uint8) * 3];
  20. for (int p = 0; p < wh; p += BUFFER_PIXELS) {
  21. for(int pb = 0; pb < BUFFER_PIXELS; pb++) {
  22. buffer[pb * 3 + 0] = r;
  23. buffer[pb * 3 + 1] = g;
  24. buffer[pb * 3 + 2] = b;
  25. }
  26. int rem = wh - p;
  27. lcd_pushPixels(lcd, buffer, ((rem < BUFFER_PIXELS) ? rem : BUFFER_PIXELS));
  28. }
  29. }
  30. void lcd_fillScreen(lcd_t* lcd, uint8 r, uint8 g, uint8 b)
  31. {
  32. lcd_fillRect(lcd, 0, 0,
  33. lcd->width, lcd->height,
  34. r, g, b);
  35. }