| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 4 | * 2013-2022 by the Falcon Player Developers. | ||
| 5 | * | ||
| 6 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 7 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 8 | * file for descriptions of what files are covered by each license. | ||
| 9 | * | ||
| 10 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 11 | * included LICENSE.LGPL file. | ||
| 12 | */ | ||
| 13 | |||
| 14 | // PLUGIN ABI: native plugins compile against this header and are loaded with | ||
| 15 | // dlopen(), so parts of it are baked into binaries FPP did not build. | ||
| 16 | // - RunningEffect and PixelOverlayEffect are subclassed by plugins and FPP | ||
| 17 | // calls their virtuals: inserting, removing, reordering or even | ||
| 18 | // appending a virtual breaks them. Plugins also read RunningEffect's data | ||
| 19 | // members (model). | ||
| 20 | // Any such change must bump FPP_PLUGIN_API_VERSION in Plugin.h. Without the | ||
| 21 | // bump, a plugin built against the previous header still loads and silently | ||
| 22 | // uses the old layout - FPP 10.2 shipped exactly that and crash-looped fppd. | ||
| 23 | // See .claude/PLUGIN-ABI.md for which plugins use what. | ||
| 24 | |||
| 25 | #include <cstdint> | ||
| 26 | #include <list> | ||
| 27 | #include "fpp-json-fwd.h" | ||
| 28 | #include <string> | ||
| 29 | #include <vector> | ||
| 30 | |||
| 31 | #include "../commands/Commands.h" | ||
| 32 | |||
| 33 | class PixelOverlayModel; | ||
| 34 | class PixelOverlayState; | ||
| 35 | |||
| 36 | namespace Magick | ||
| 37 | { | ||
| 38 | class Image; | ||
| 39 | }; | ||
| 40 | |||
| 41 | // Scale an already-decoded image to exactly w x h pixels. Shared by the Image | ||
| 42 | // overlay effect and PlaylistEntryImage so both size images identically. | ||
| 43 | // | ||
| 44 | // mode: | ||
| 45 | // "Scale to Fit" - preserve aspect, letterbox/pillarbox the remainder black | ||
| 46 | // "Crop to Fill" - preserve aspect, cover the box, centre-crop the overflow | ||
| 47 | // "Stretch" - ignore aspect, resize to exactly w x h | ||
| 48 | // Any other value (including "None") leaves the image untouched. | ||
| 49 | void ScaleOverlayImage(Magick::Image& image, int w, int h, const std::string& mode); | ||
| 50 | |||
| 51 | // Whether a path names a regular file with an image extension the overlays | ||
| 52 | // read (.png, .jpg, .gif, ...). Shared by the Image effect's file list and | ||
| 53 | // PlaylistEntryImage's folders, so both offer and pick the same files. | ||
| 54 | bool IsOverlayImageFile(const std::string& path); | ||
| 55 | |||
| 56 | // Decode an encoded image held in memory (PNG/JPEG/GIF/BMP/...) and draw it on | ||
| 57 | // a model. Shared by the Image overlay effect's file path and the bulk-data | ||
| 58 | // HTTP endpoint so an uploaded image is sized and placed exactly like a local | ||
| 59 | // one. | ||
| 60 | // | ||
| 61 | // The image is scaled to a boxW x boxH box using ScaleOverlayImage()'s mode | ||
| 62 | // vocabulary ("Scale to Fit", "Crop to Fill", "Stretch", "None"), then drawn | ||
| 63 | // with its top-left at (xOffset, yOffset) -- or centred within the box when | ||
| 64 | // `center` is set, which is what "None" wants by default. Anything falling | ||
| 65 | // outside the model is clipped. `st` is the per-blit blend, not the model's | ||
| 66 | // enable state. | ||
| 67 | // | ||
| 68 | // Returns false and fills `err` on a decode failure or if nothing landed | ||
| 69 | // inside the model. | ||
| 70 | bool DrawEncodedImageOnModel(PixelOverlayModel* m, const void* data, size_t len, | ||
| 71 | const std::string& scaling, int boxW, int boxH, | ||
| 72 | int xOffset, int yOffset, bool center, | ||
| 73 | const PixelOverlayState& st, bool toOverlayBuffer, | ||
| 74 | std::string& err); | ||
| 75 | |||
| 76 | class RunningEffect { | ||
| 77 | public: | ||
| 78 | static constexpr int32_t EFFECT_DONE = 0; | ||
| 79 | static constexpr int32_t EFFECT_AFTER_NEXT_OUTPUT = -1; | ||
| 80 | |||
| 81 | 37509 | RunningEffect(PixelOverlayModel* m) : | |
| 82 | 37509 | model(m) {} | |
| 83 | 74936 | virtual ~RunningEffect() {} | |
| 84 | ✗ | virtual int32_t update() { | |
| 85 | ✗ | return 0; | |
| 86 | } | ||
| 87 | |||
| 88 | virtual const std::string& name() const = 0; | ||
| 89 | 339 | virtual void toJson(Json::Value& v) const { | |
| 90 |
3/6✓ Branch 0 taken 339 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 339 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 339 times.
✗ Branch 5 not taken.
|
339 | v["name"] = name(); |
| 91 | 339 | }; | |
| 92 | |||
| 93 | PixelOverlayModel* model; | ||
| 94 | }; | ||
| 95 | |||
| 96 | class PixelOverlayEffect : public Command { | ||
| 97 | public: | ||
| 98 | 511428 | PixelOverlayEffect(const std::string& name) : | |
| 99 | 511428 | Command(name) {} | |
| 100 | 199688 | virtual ~PixelOverlayEffect() {} | |
| 101 | |||
| 102 | ✗ | virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) { | |
| 103 | ✗ | return std::make_unique<Command::Result>("Ignored"); | |
| 104 | }; | ||
| 105 | |||
| 106 | ✗ | virtual bool apply(PixelOverlayModel* model, bool autoEnable, const std::vector<std::string>& args) { return false; } | |
| 107 | ✗ | virtual bool apply(PixelOverlayModel* model, const std::string& enableState, const std::vector<std::string>& args) { | |
| 108 | ✗ | return apply(model, enableState != "false", args); | |
| 109 | } | ||
| 110 | |||
| 111 | static PixelOverlayEffect* GetPixelOverlayEffect(const std::string& name); | ||
| 112 | static const std::list<std::string>& GetPixelOverlayEffects(); | ||
| 113 | |||
| 114 | // Bumped whenever an effect is registered or unregistered. The described | ||
| 115 | // effect list is otherwise fixed: every list in it that varies at runtime | ||
| 116 | // (fonts, images) is declared as a contentListUrl the client fetches | ||
| 117 | // separately rather than inlined, so registration is the only thing that | ||
| 118 | // can change what /api/overlays/effects returns. | ||
| 119 | static uint64_t GetPixelOverlayEffectsGeneration(); | ||
| 120 | |||
| 121 | static void AddPixelOverlayEffect(PixelOverlayEffect* effect); | ||
| 122 | static void RemovePixelOverlayEffect(PixelOverlayEffect* effect); | ||
| 123 | }; | ||
| 124 |