#pragma once #include #include #include #include #include "core/effect.hpp" namespace effector { // Lays one picture from disk over its input: a logo, a texture, a frame. The // overlay is fitted to the canvas in the chosen way, placed from the top left // or from the centre, nudged by an offset and mixed in by its opacity, with a // soft shadow or glow cut from its own outline beneath it if asked. Like the // blur it needs no source images of its own, so it can lead a chain; given // sources it fills the canvas from a randomly chosen one first. class OverlayEffect : public Effect { public: std::string name() const override { return "overlay"; } std::string title() const override { return "Image overlay"; } std::string description() const override { return "Lays a single image from disk over its input, fitted to the canvas, centred or " "not, nudged by an offset and mixed in by its opacity, optionally with a shadow or " "a glow around it."; } const std::vector& params() const override; bool needsSources() const override { return false; } Image render(const std::vector& sources, int width, int height, Rng& rng, const ParamValues& values) const override; private: // The same file is re-read on every param change otherwise, and a render is // a keystroke away in the interface. Renders can overlap, so it is guarded. // Returns the decoded file and its alpha, reading it only when the path // differs from the one already held. void loadOverlay(const std::string& path, Image& image, std::vector& alpha) const; mutable std::mutex cacheMutex_; mutable std::string cachedPath_; mutable Image cached_; mutable std::vector cachedAlpha_; }; } // namespace effector