From 09dabb2e351bb57516233792698557f3aab042f7 Mon Sep 17 00:00:00 2001 From: mrfaptastic <12006953+mrfaptastic@users.noreply.github.com> Date: Tue, 8 Dec 2020 07:35:47 +0000 Subject: [PATCH] GraphicsLayer minor tweaks --- examples/GraphicsLayer/GraphicsLayer.ino | 25 ++++++++++++++++++++++-- examples/GraphicsLayer/Layer.cpp | 22 +++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/examples/GraphicsLayer/GraphicsLayer.ino b/examples/GraphicsLayer/GraphicsLayer.ino index fbc33ad..2c15d18 100644 --- a/examples/GraphicsLayer/GraphicsLayer.ino +++ b/examples/GraphicsLayer/GraphicsLayer.ino @@ -86,6 +86,7 @@ void setup() { } +int LayerCompositor_mode = 0; void loop() { for (int x = 0; x < dma_display.width(); x++) { @@ -119,8 +120,28 @@ void loop() { * Step 3: Merge foreground and background layers and send to the matrix panel! * Use our special sauce LayerCompositor functions */ - LayerCompositor::Siloette(dma_display, bgLayer, textLayer); - //LayerCompositor::Stack(dma_display, bgLayer, textLayer); + switch (LayerCompositor_mode) + { + case 0: + LayerCompositor::Siloette(dma_display, bgLayer, textLayer); + break; + + case 1: + LayerCompositor::Stack(dma_display, bgLayer, textLayer); + break; + + case 2: + LayerCompositor::Blend(dma_display, bgLayer, textLayer); + break; + } + + EVERY_N_SECONDS(5) { // FastLED Macro + LayerCompositor_mode++; + dma_display.clearScreen(); + if (LayerCompositor_mode > 2) LayerCompositor_mode = 0; + } + + // // LayerCompositor::Blend(dma_display, bgLayer, textLayer, 127); } // end loop diff --git a/examples/GraphicsLayer/Layer.cpp b/examples/GraphicsLayer/Layer.cpp index 5c419c1..4352398 100644 --- a/examples/GraphicsLayer/Layer.cpp +++ b/examples/GraphicsLayer/Layer.cpp @@ -295,8 +295,6 @@ namespace LayerCompositor */ void Siloette(MatrixPanel_I2S_DMA &disp, const Layer &_bgLayer, const Layer &_fgLayer) { - //const Layer *bg = &_bgLayer; - //const Layer *fg = &_fgLayer; for (int y = 0; y < LAYER_HEIGHT; y++) { for (int x = 0; x < LAYER_WIDTH; x++) @@ -327,15 +325,19 @@ namespace LayerCompositor { for (int x = 0; x < LAYER_WIDTH; x++) { - /* - // set the blend ratio for the video cross fade - // (set ratio to 127 for a constant 50% / 50% blend) - uint8_t ratio = beatsin8(5); - */ - - // (set ratio to 127 for a constant 50% / 50% blend) - _pixel = blend(_bgLayer.pixels->data[y][x], _fgLayer.pixels->data[y][x], ratio); + + _pixel = _bgLayer.pixels->data[y][x]; + + // (set ratio to 127 for a constant 50% / 50% blend) + //_pixel = blend(_bgLayer.pixels->data[y][x], _fgLayer.pixels->data[y][x], ratio); + // Blend with background if foreground pixel isn't clear/transparent + if (_fgLayer.pixels->data[y][x] != _fgLayer.transparency_colour) + { + _pixel = blend(_bgLayer.pixels->data[y][x], _fgLayer.pixels->data[y][x], ratio); + } // if the foreground is transparent, then print whatever is the bg + + // https://gist.github.com/StefanPetrick/0c0d54d0f35ea9cca983 disp.drawPixelRGB888(x,y, _pixel.r, _pixel.g, _pixel.b );