Added different rendering modes for the subpixel stuff.
This commit is contained in:
parent
1c1c3a8054
commit
2395e51e88
@ -3,9 +3,16 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
|
enum SubpixelRenderingMode {
|
||||||
|
SUBPIXEL_RENDERING_SET,
|
||||||
|
SUBPIXEL_RENDERING_ADD,
|
||||||
|
SUBPIXEL_RENDERING_RAISE
|
||||||
|
};
|
||||||
|
|
||||||
class Window {
|
class Window {
|
||||||
private:
|
private:
|
||||||
void _circle_point(int x0, int y0, int x1, int y1, CRGB* color);
|
void _circle_point(int x0, int y0, int x1, int y1, CRGB* color);
|
||||||
|
void _subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderingMode m);
|
||||||
public:
|
public:
|
||||||
const uint8_t x, y;
|
const uint8_t x, y;
|
||||||
const uint8_t width, height;
|
const uint8_t width, height;
|
||||||
@ -19,7 +26,7 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
void clear(CRGB* color);
|
void clear(CRGB* color);
|
||||||
void setPixel(uint8_t x, uint8_t y, CRGB* color);
|
void setPixel(uint8_t x, uint8_t y, CRGB* color);
|
||||||
void setSubPixel(accum88 x, accum88 y, CRGB* color);
|
void setSubPixel(accum88 x, accum88 y, CRGB* color, SubpixelRenderingMode m = SUBPIXEL_RENDERING_ADD);
|
||||||
void setPixelByIndex(uint16_t index, CRGB* color);
|
void setPixelByIndex(uint16_t index, CRGB* color);
|
||||||
void raisePixel(uint8_t x, uint8_t y, CRGB* color);
|
void raisePixel(uint8_t x, uint8_t y, CRGB* color);
|
||||||
void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color);
|
void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color);
|
||||||
|
@ -54,6 +54,7 @@ void Window::drawSubText(Font* font, accum88 x, accum88 y, String text, CRGB* co
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Window::drawChar(Font* font, accum88 xPos, accum88 yPos, const char c, CRGB* color, bool mask) {
|
void Window::drawChar(Font* font, accum88 xPos, accum88 yPos, const char c, CRGB* color, bool mask) {
|
||||||
|
SubpixelRenderingMode mode = mask ? SUBPIXEL_RENDERING_SET : SUBPIXEL_RENDERING_ADD;
|
||||||
if (!font->isCharAllowed(c)) return;
|
if (!font->isCharAllowed(c)) return;
|
||||||
uint16_t position = font->getCharPosition(c);
|
uint16_t position = font->getCharPosition(c);
|
||||||
uint8_t* data = new uint8_t[font->width];
|
uint8_t* data = new uint8_t[font->width];
|
||||||
@ -62,7 +63,7 @@ void Window::drawChar(Font* font, accum88 xPos, accum88 yPos, const char c, CRGB
|
|||||||
for(uint8_t y=0; y<font->height; y++) for(uint8_t x=0; x<font->width; x++) {
|
for(uint8_t y=0; y<font->height; y++) for(uint8_t x=0; x<font->width; x++) {
|
||||||
bool on = (data[x]>>(font->height - 1 - y) & 1) * 255;
|
bool on = (data[x]>>(font->height - 1 - y) & 1) * 255;
|
||||||
if (mask) on = !on;
|
if (mask) on = !on;
|
||||||
if (on) this->setSubPixel(xPos + (x<<8), yPos + (y<<8), color);
|
if (on) this->setSubPixel(xPos + (x<<8), yPos + (y<<8), color, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
@ -79,7 +80,7 @@ void Window::shift_down() {
|
|||||||
leds[coordsToGlobalIndex(x, y)] = leds[coordsToGlobalIndex(x, y-1)];
|
leds[coordsToGlobalIndex(x, y)] = leds[coordsToGlobalIndex(x, y-1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_row(0);
|
clear_row(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,12 +154,12 @@ void Window::line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color) {
|
|||||||
// Bresenham algorithm
|
// Bresenham algorithm
|
||||||
int dx = x2-x1;
|
int dx = x2-x1;
|
||||||
int dy = y2-y1;
|
int dy = y2-y1;
|
||||||
|
|
||||||
int x = x1;
|
int x = x1;
|
||||||
int y = y1;
|
int y = y1;
|
||||||
|
|
||||||
int p = 2*dy - dx;
|
int p = 2*dy - dx;
|
||||||
|
|
||||||
while (x < x2) {
|
while (x < x2) {
|
||||||
if (p >= 0) {
|
if (p >= 0) {
|
||||||
setPixel(x, y, color);
|
setPixel(x, y, color);
|
||||||
@ -219,7 +220,7 @@ void Window::lineWithAngle(uint8_t x, uint8_t y, uint8_t angle, uint8_t startdis
|
|||||||
line(x1, y1, x2, y2, color);
|
line(x1, y1, x2, y2, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setSubPixel(accum88 x, accum88 y, CRGB* color) {
|
void Window::setSubPixel(accum88 x, accum88 y, CRGB* color, SubpixelRenderingMode mode) {
|
||||||
uint8_t px, py;
|
uint8_t px, py;
|
||||||
// px = Part of next pixel to fill
|
// px = Part of next pixel to fill
|
||||||
// x = "Origin pixel"
|
// x = "Origin pixel"
|
||||||
@ -227,31 +228,39 @@ void Window::setSubPixel(accum88 x, accum88 y, CRGB* color) {
|
|||||||
py = y & 0xFF;
|
py = y & 0xFF;
|
||||||
x = x >> 8;
|
x = x >> 8;
|
||||||
y = y >> 8;
|
y = y >> 8;
|
||||||
|
|
||||||
CRGB c;
|
CRGB c;
|
||||||
c = CRGB(scale8( scale8( color->r, 255-py), 255-px),
|
c = CRGB(scale8( scale8( color->r, 255-py), 255-px),
|
||||||
scale8( scale8( color->g, 255-py), 255-px),
|
scale8( scale8( color->g, 255-py), 255-px),
|
||||||
scale8( scale8( color->b, 255-py), 255-px));
|
scale8( scale8( color->b, 255-py), 255-px));
|
||||||
this->addPixelColor(x, y, &c);
|
_subpixel_render(x, y, &c, mode);
|
||||||
|
|
||||||
if (px) {
|
if (px) {
|
||||||
c = CRGB(scale8( scale8( color->r, 255-py), px),
|
c = CRGB(scale8( scale8( color->r, 255-py), px),
|
||||||
scale8( scale8( color->g, 255-py), px),
|
scale8( scale8( color->g, 255-py), px),
|
||||||
scale8( scale8( color->b, 255-py), px));
|
scale8( scale8( color->b, 255-py), px));
|
||||||
this->addPixelColor(x+1, y, &c);
|
_subpixel_render(x+1, y, &c, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (py) {
|
if (py) {
|
||||||
c = CRGB(scale8( scale8( color->r, py), 255-px),
|
c = CRGB(scale8( scale8( color->r, py), 255-px),
|
||||||
scale8( scale8( color->g, py), 255-px),
|
scale8( scale8( color->g, py), 255-px),
|
||||||
scale8( scale8( color->b, py), 255-px));
|
scale8( scale8( color->b, py), 255-px));
|
||||||
this->addPixelColor(x, y+1, &c);
|
_subpixel_render(x, y+1, &c, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (px || py) {
|
if (px || py) {
|
||||||
c = CRGB(scale8( scale8( color->r, py), px),
|
c = CRGB(scale8( scale8( color->r, py), px),
|
||||||
scale8( scale8( color->g, py), px),
|
scale8( scale8( color->g, py), px),
|
||||||
scale8( scale8( color->b, py), px));
|
scale8( scale8( color->b, py), px));
|
||||||
this->addPixelColor(x+1, y+1, &c);
|
_subpixel_render(x+1, y+1, &c, mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::_subpixel_render(uint8_t x, uint8_t y, CRGB* color, SubpixelRenderingMode mode) {
|
||||||
|
switch(mode) {
|
||||||
|
case SUBPIXEL_RENDERING_ADD: addPixelColor(x, y, color); break;
|
||||||
|
case SUBPIXEL_RENDERING_RAISE: raisePixel(x, y, color); break;
|
||||||
|
case SUBPIXEL_RENDERING_SET: setPixel(x, y, color); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user