| 54 | } |
| 55 | |
| 56 | void Blend2d::draw(DrawContext context) { |
| 57 | mFrame->clear(); |
| 58 | mFrameTransform->clear(); |
| 59 | |
| 60 | // Draw each layer in reverse order and applying the blending. |
| 61 | bool first = true; |
| 62 | for (auto it = mLayers.begin(); it != mLayers.end(); ++it) { |
| 63 | DrawContext tmp_ctx = context; |
| 64 | tmp_ctx.leds = mFrame->rgb(); |
| 65 | auto &fx = it->fx; |
| 66 | fx->draw(tmp_ctx); |
| 67 | DrawMode mode = first ? DrawMode::DRAW_MODE_OVERWRITE |
| 68 | : DrawMode::DRAW_MODE_BLEND_BY_MAX_BRIGHTNESS; |
| 69 | first = false; |
| 70 | // Apply the blur effect per effect. |
| 71 | u8 blur_amount = it->blur_amount; |
| 72 | if (blur_amount > 0) { |
| 73 | const XYMap &xyMap = fx->getXYMap(); |
| 74 | u8 blur_passes = fl::max(1, it->blur_passes); |
| 75 | for (u8 i = 0; i < blur_passes; ++i) { |
| 76 | // Apply the blur effect |
| 77 | blur2d(mFrame->rgb().data(), mXyMap.getWidth(), mXyMap.getHeight(), |
| 78 | blur_amount, xyMap); |
| 79 | } |
| 80 | } |
| 81 | mFrame->draw(mFrameTransform->rgb(), mode); |
| 82 | } |
| 83 | |
| 84 | if (mGlobalBlurAmount > 0) { |
| 85 | // Apply the blur effect |
| 86 | u16 width = mXyMap.getWidth(); |
| 87 | u16 height = mXyMap.getHeight(); |
| 88 | XYMap rect = XYMap::constructRectangularGrid(width, height); |
| 89 | fl::span<CRGB> rgb = mFrameTransform->rgb(); |
| 90 | u8 blur_passes = fl::max(1, mGlobalBlurPasses); |
| 91 | for (u8 i = 0; i < blur_passes; ++i) { |
| 92 | // Apply the blur effect |
| 93 | blur2d(rgb, width, height, mGlobalBlurAmount, rect); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Copy the final result to the output |
| 98 | // memcpy(mFrameTransform->rgb(), context.leds, sizeof(CRGB) * |
| 99 | // mXyMap.getTotal()); |
| 100 | mFrameTransform->drawXY(context.leds, mXyMap, |
| 101 | DrawMode::DRAW_MODE_OVERWRITE); |
| 102 | } |
| 103 | |
| 104 | void Blend2d::clear() { mLayers.clear(); } |
| 105 |
no test coverage detected