Debian Codegraph @

docs/develop-plugin.md

raw symbols SCIP
1 # Develop a frei0r plugin
2
3 A frei0r plugin is a shared library implementing a small C ABI. The repository
4 also provides a C++ wrapper that handles exported functions and parameter
5 plumbing for common plugins.
6
7 Start with the maintained
8 [`src/filter/tutorial`](https://github.com/dyne/frei0r/tree/master/src/filter/tutorial)
9 example and keep
10 [`include/frei0r.h`](https://github.com/dyne/frei0r/blob/master/include/frei0r.h)
11 open as the specification.
12
13 ## 1. Choose a plugin type
14
15 | Type | Frames in | Purpose |
16 | --- | ---: | --- |
17 | `F0R_PLUGIN_TYPE_SOURCE` | 0 | Generate a frame |
18 | `F0R_PLUGIN_TYPE_FILTER` | 1 | Transform a frame |
19 | `F0R_PLUGIN_TYPE_MIXER2` | 2 | Combine two frames |
20 | `F0R_PLUGIN_TYPE_MIXER3` | 3 | Combine three frames |
21
22 Choose the narrowest type that represents the effect. Hosts use this metadata
23 to decide how many inputs to connect.
24
25 ## 2. Choose a color model
26
27 New plugins should normally use `F0R_COLOR_MODEL_RGBA8888`. The API also
28 defines BGRA and packed 32-bit models for compatibility. A frame is a
29 width-by-height array of 32-bit pixels in the declared model.
30
31 ## 3. Implement the effect
32
33 The C++ wrapper provides base classes named `source`, `filter`, `mixer2` and
34 `mixer3`. A minimal filter stores its parameters and implements `update`:
35
36 ```cpp
37 #include "frei0r.hpp"
38
39 class MyFilter : public frei0r::filter {
40 public:
41 MyFilter(unsigned int width, unsigned int height) {
42 register_param(amount, "Amount", "Strength of the effect");
43 amount = 0.5;
44 }
45
46 void update(double time, uint32_t* out, const uint32_t* in) override {
47 // Transform width * height pixels from in to out.
48 }
49
50 private:
51 double amount;
52 };
53
54 frei0r::construct<MyFilter> plugin(
55 "My filter", "A short description", "Your name", 0, 1,
56 F0R_COLOR_MODEL_RGBA8888);
57 ```
58
59 The wrapper's constructor receives `(width, height)`, and its base class stores
60 both dimensions. Initialize every parameter in the constructor.
61
62 ## 4. Register parameters
63
64 frei0r supports Boolean values, normalized doubles, colors, positions and
65 strings. Hosts generally present doubles in a normalized `0.0` to `1.0` range.
66 Convert that range to the useful domain inside the plugin and document any
67 special mapping in the parameter description.
68
69 ## 5. Process frames safely
70
71 - Treat input frame pointers as read-only.
72 - Write every output pixel unless the effect first copies the input.
73 - Handle in-place operation only if the algorithm explicitly supports it.
74 - Keep allocation and expensive lookup-table setup in construction.
75 - Use `time` for deterministic animation rather than a private wall clock.
76 - Validate dimensions and arithmetic before calculating buffer offsets.
77
78 The tutorial demonstrates pixel iteration, parameter registration, lookup
79 tables and clamping. It is a collection of ideas, not an installed effect.
80
81 ## 6. Add the CMake target
82
83 Create a directory under the matching `src` category with a `CMakeLists.txt`:
84
85 ```cmake
86 set(SOURCES myfilter.cpp)
87 set(TARGET myfilter)
88
89 if(MSVC)
90 set(SOURCES ${SOURCES} ${FREI0R_DEF})
91 endif()
92
93 add_library(${TARGET} MODULE ${SOURCES})
94 set_target_properties(${TARGET} PROPERTIES PREFIX "")
95 install(TARGETS ${TARGET} LIBRARY DESTINATION ${LIBDIR})
96 ```
97
98 Add the directory with `add_subdirectory(myfilter)` in the parent category's
99 `CMakeLists.txt`.
100
101 ## 7. Build and inspect it
102
103 ```sh
104 cmake -S . -B build -G Ninja
105 cmake --build build --target myfilter
106
107 cd test
108 make frei0r-meta
109 ./frei0r-meta ../build/src/filter/myfilter/myfilter.so
110 ```
111
112 Adjust the library suffix and path for the platform. Check the displayed name,
113 author, explanation, type, color model, version and every parameter.
114
115 ## 8. Run the plugin tests
116
117 ```sh
118 cd test
119 make frei0r-asan
120 make check
121 ```
122
123 New plugins should also include focused tests for their invariants where
124 practical. At minimum, exercise unusual frame dimensions, parameter boundaries
125 and repeated update calls.
126
127 ## 9. Contribute
128
129 1. Keep the plugin focused on one reusable effect.
130 2. Use a clear, unique plugin name and human-readable metadata.
131 3. Confirm builds with and without optional dependencies as applicable.
132 4. Open a [pull request](https://github.com/dyne/frei0r/pulls).
133
134 Use [GitHub issues](https://github.com/dyne/frei0r/issues) for defects and
135 [Telegram](https://t.me/frei0r) for design discussion.