Replies: 1 comment 2 replies
-
I strong suggest just creating your own screen buffer outside this library, and store the pixel values there if memory isn't an issue. I take it you're trying to drive a huge resolution and therefore don't have the luxary of your own buffer? Something like (this needs FastLED) works for me and deals with the flicker issue completely, and allows one to read the value back of a pixel coord. Also negates the need to have 'double buffering' enabled in the library. struct layerPixels {
CRGB data[LAYER_HEIGHT][LAYER_WIDTH];
};
class Layer : public GFX
{
public:
Layer(MatrixPanel_I2S_DMA &disp) : GFX (LAYER_WIDTH, LAYER_HEIGHT) {
matrix = &disp;
}
inline void init()
{
// https://stackoverflow.com/questions/5914422/proper-way-to-initialize-c-structs
pixels = new layerPixels();
} // end Layer
void drawPixel(int16_t x, int16_t y, uint16_t color); // overwrite adafruit implementation
void drawPixel(int16_t x, int16_t y, int r, int g, int b); // Layer implementation
void drawPixel(int16_t x, int16_t y, CRGB color); // Layer implementation
void clear();
void display(); // flush to display / LED matrix
inline uint16_t color565(uint8_t r, uint8_t g, uint8_t b) {
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}
// For layer composition - accessed publically
layerPixels *pixels;
// Release Memory
~Layer(void);
private:
MatrixPanel_I2S_DMA *matrix = NULL;
};
// For adafruit
void Layer::drawPixel(int16_t x, int16_t y, uint16_t color) {
// 565 color conversion
uint8_t r = ((((color >> 11) & 0x1F) * 527) + 23) >> 6;
uint8_t g = ((((color >> 5) & 0x3F) * 259) + 33) >> 6;
uint8_t b = (((color & 0x1F) * 527) + 23) >> 6;
drawPixel(x, y, CRGB(r,g,b));
}
void Layer::drawPixel(int16_t x, int16_t y, int r, int g, int b) {
drawPixel(x, y, CRGB(r,g,b));
}
void Layer::drawPixel(int16_t x, int16_t y, CRGB color) {
if( x >= LAYER_WIDTH || x < 0) return; // 0;
if( y >= LAYER_HEIGHT || y < 0) return; // 0;
pixels->data[y][x] = color;
}
void Layer::clear() {
memset(pixels, BLACK_BACKGROUND_PIXEL_COLOUR, sizeof(layerPixels) );
}
/**
* Send the layer to the display device.
*/
void Layer::display() {
CRGB _pixel = 0 ;
for (int y = 0; y < LAYER_HEIGHT; y++) {
for (int x = 0; x < LAYER_WIDTH; x++)
{
//_pixel = pixel[XY(x, y)];
_pixel = pixels->data[y][x];
matrix->drawPixelRGB888( x, y, _pixel.r, _pixel.g, _pixel.b);
} // end loop to copy fast led to the dma matrix
}
} // display
Layer::~Layer(void)
{
free(pixels);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would be adding this to the end of the post asking if there's a way to copy the screen buffer, but that discussion is locked. Probably copying the DMA buffers is the best way if you want an actual copy.
I needed a way to read the pixel back from a buffer (for compositing). The caveat here is that the write operation is lossy - a pixel is luminance adjusted before being written. But this gets you as far as seeing what the actual led values that are being shifted out are:
Beta Was this translation helpful? Give feedback.
All reactions