| 1 | /* |
| 2 | * ikaleid0sc0pe.h |
| 3 | * Copyright (C) 2020-2023 Brendan Hack ([email protected]) |
| 4 | * This file is part of a Frei0r plugin that applies a kaleidoscope |
| 5 | * effect. |
| 6 | * Version 1.1 july 2023 |
| 7 | * |
| 8 | * Interface and factory function to the kaleidoscope library |
| 9 | * |
| 10 | * This source code is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Public License as published by |
| 12 | * the Free Software Foundation; either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This source code is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer |
| 18 | * to the GNU Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Public License along |
| 21 | * with this source code; if not, write to: Free Software Foundation, |
| 22 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | * |
| 24 | */ |
| 25 | #ifndef SRC_FILTER_KALEID0SC0PE_IKALEID0SC0PE_H_ |
| 26 | #define SRC_FILTER_KALEID0SC0PE_IKALEID0SC0PE_H_cxx . . $ `src/filter/kaleid0sc0pe/ikaleid0sc0pe.h:26:9`! 1 |
| 27 | |
| 28 | #include <cstdint> |
| 29 | #include <memory> |
| 30 | |
| 31 | namespace libkaleid0sc0pecxx . . $ libkaleid0sc0pe/ { |
| 32 | class IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#; |
| 33 | } |
| 34 | |
| 35 | namespace stdcxx . . $ std/ |
| 36 | { |
| 37 | |
| 38 | // default delete for IKaleid0sc0pe |
| 39 | // this isn't going to work across an actual shared object boundary but |
| 40 | // not particular worried about that at the moment |
| 41 | template<> |
| 42 | class default_deletecxx . . $ std/default_delete#<libkaleid0sc0pecxx . . $ libkaleid0sc0pe/::IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#> |
| 43 | { |
| 44 | public: |
| 45 | void operatorcxx . . $ std/default_delete#`operator()`(7c097689af2f81c5).()(libkaleid0sc0pecxx . . $ libkaleid0sc0pe/::IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#* p); |
| 46 | }; |
| 47 | |
| 48 | } // namespace std |
| 49 | |
| 50 | namespace libkaleid0sc0pecxx . . $ libkaleid0sc0pe/ { |
| 51 | |
| 52 | /** |
| 53 | * Class which implements the kaleid0sc0pe effect |
| 54 | */ |
| 55 | class IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe# { |
| 56 | public: |
| 57 | /** |
| 58 | * Sets the origin of the kaleid0sc0pe effect. These are given in the range 0 -> 1. |
| 59 | * Values other than 0.5,0.5 may end up reflecting outside the source image. |
| 60 | * These areas will be filled depending on the settings in #set_reflect_edges and |
| 61 | * #set_background_colour. |
| 62 | * Defaults to 0.5, 0.5. |
| 63 | * @param x x coordinate of the origin |
| 64 | * @param y y coordinate of the origin |
| 65 | * @return |
| 66 | * - 0: Success |
| 67 | * - -1: Error |
| 68 | * - -2: Parameter out of range |
| 69 | */ |
| 70 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_origincxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_origin(d492eb986ab7f0ea).(float x, float y) = 0; |
| 71 | |
| 72 | /** |
| 73 | * Returns the origin x coordinate. |
| 74 | */ |
| 75 | virtual float get_origin_xcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_origin_x(5036dfe8d4170af2).() const = 0; |
| 76 | |
| 77 | /** |
| 78 | * Returns the origin y coordinate. |
| 79 | */ |
| 80 | virtual float get_origin_ycxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_origin_y(5036dfe8d4170af2).() const = 0; |
| 81 | |
| 82 | /** |
| 83 | * Sets the segmentation resulting in \p segmentation * 2 segments in the output frame. |
| 84 | * Segmentation values that are 1, 2 or a multiple of 4, are oriented to an image corner |
| 85 | * and centred will always reflect back to the source segment. |
| 86 | * Other settings may end up reflecting outside the source image. These areas will be filled |
| 87 | * depending on the settings in #set_reflect_edges and #set_background_colour. |
| 88 | * Defaults to 16. |
| 89 | * @param segmentation the segmentation value |
| 90 | * @return |
| 91 | * - 0: Success |
| 92 | * - -1: Error |
| 93 | * - -2: Parameter out of range |
| 94 | */ |
| 95 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_segmentationcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_segmentation(4c679297bf94b9eb).(stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# segmentation) = 0; |
| 96 | |
| 97 | /** |
| 98 | * Returns the segmentation value |
| 99 | */ |
| 100 | virtual stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# get_segmentationcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_segmentation(ddd8539a2fcdd4ce).() const = 0; |
| 101 | |
| 102 | /** |
| 103 | * When #set_reflect_edges is not true and a reflected pixel ends up outside the image |
| 104 | * we can clamp the pixels that fall outside the image but within \p threshold pixels |
| 105 | * of the edge to the edge. |
| 106 | * Defaults to 0 |
| 107 | * @param threshold the threshold in pixels. |
| 108 | * @return |
| 109 | * - 0: Success |
| 110 | * - -1: Error |
| 111 | */ |
| 112 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_edge_thresholdcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_edge_threshold(4c679297bf94b9eb).(stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# threshold) = 0; |
| 113 | |
| 114 | /** |
| 115 | * Returns the edge threshold |
| 116 | */ |
| 117 | virtual stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# get_edge_thresholdcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_edge_threshold(ddd8539a2fcdd4ce).() const = 0; |
| 118 | |
| 119 | /// Defines a corner |
| 120 | enum class Cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner# { |
| 121 | TLcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner#TL. = 0, //< Top Left |
| 122 | TRcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner#TR., //< Top Right |
| 123 | BRcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner#BR., //< Bottom Right |
| 124 | BLcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner#BL. //< Bottom Left |
| 125 | }; |
| 126 | |
| 127 | /// Defines an angular direction |
| 128 | enum class Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# { |
| 129 | CLOCKWISEcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction#CLOCKWISE. = 0, //< Clockwise |
| 130 | ANTICLOCKWISEcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction#ANTICLOCKWISE., //< Anti Clockwise |
| 131 | NONEcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction#NONE. //< No direction |
| 132 | }; |
| 133 | |
| 134 | /** |
| 135 | * Sets the direction that the source segment rotates in. If |
| 136 | * Direction::NONE then the source segment is centred on the corner. |
| 137 | * Otherwise it extends in the given direction. |
| 138 | * Defaults to Direction::NONE |
| 139 | * @param direction the direction |
| 140 | * @return |
| 141 | * - 0: Success |
| 142 | * - -1: Error |
| 143 | */ |
| 144 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_segment_directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_segment_direction(353f52a649f12cd9).(Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# direction) = 0; |
| 145 | |
| 146 | /** |
| 147 | * Returns the segment direction |
| 148 | */ |
| 149 | virtual Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# get_segment_directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_segment_direction(8f08a92890f4a76).() const = 0; |
| 150 | |
| 151 | /** |
| 152 | * Unless directly specified with #set_source_segment the source segment is always aligned to |
| 153 | * the furthest corner of the image from the origin. |
| 154 | * The source segment has it's edge (or centre) on a line from the origin to the furthest corner, |
| 155 | * and extends in the direction given by #set_segment_direction. |
| 156 | * If multiple corners are equidistant from the origin then this indicates which |
| 157 | * corner is preferred. The algorithm searches from this corner, in the direction |
| 158 | * specified in #set_preferred_corner_search_direction to find the furthest corner. |
| 159 | * Defaults to Corner::BR |
| 160 | * @param corner the preferred corner |
| 161 | * @return |
| 162 | * - 0: Success |
| 163 | * - -1: Error |
| 164 | */ |
| 165 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_preferred_cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_preferred_corner(60b45789d1567f5a).(Cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner# corner) = 0; |
| 166 | |
| 167 | /** |
| 168 | * Returns the preferred corner |
| 169 | */ |
| 170 | virtual Cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner# get_preferred_cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_preferred_corner(9be458cf2f8c5004).() const = 0; |
| 171 | |
| 172 | /** |
| 173 | * The direction to search for the furthest corner in. |
| 174 | * Defaults to Direction::CLOCKWISE |
| 175 | * @param direction the search direction |
| 176 | * @return |
| 177 | * - 0: Success |
| 178 | * - -1: Error |
| 179 | * - -2: Invalid parameter (\p direction cannot by Direction::NONE) |
| 180 | */ |
| 181 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_preferred_corner_search_directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_preferred_corner_search_direction(353f52a649f12cd9).(Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# direction) = 0; |
| 182 | |
| 183 | /** |
| 184 | * Returns the corner search direction |
| 185 | */ |
| 186 | virtual Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# get_preferred_corner_search_directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_preferred_corner_search_direction(8f08a92890f4a76).() const = 0; |
| 187 | |
| 188 | /** |
| 189 | * Reflected points can end up outside the source image depending on segmentation, |
| 190 | * source segment and origin settings. When this occurs three options are provided, |
| 191 | * lookup the pixel in a reflected tessellation of the original image, set the pixel |
| 192 | * to the background colour provided in #set_background_colour or write nothing to the |
| 193 | * output frame for that pixel. |
| 194 | * Defaults to \c true which is to lookup in the reflected tessellation. |
| 195 | * @param reflect if \c true then lookup in a reflection, if \c false use background color |
| 196 | * or do nothing if no background color was set. |
| 197 | * @return |
| 198 | * - 0: Success |
| 199 | * - -1: Error |
| 200 | */ |
| 201 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_reflect_edgescxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_reflect_edges(73da94e76e6bd037).(bool reflect) = 0; |
| 202 | |
| 203 | /** |
| 204 | * Returns the reflect edges setting |
| 205 | */ |
| 206 | virtual bool get_reflect_edgescxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_reflect_edges(50ce9a9e25b4a850).() const = 0; |
| 207 | |
| 208 | /** |
| 209 | * If not reflecting edges then this sets the colour to use when the kaleid0sc0pe effect |
| 210 | * for a point ends up outside the source image. The data pointed to should be at least as |
| 211 | * wide as a pixel and must be valid for the lifetime of the class instance. |
| 212 | * The caller retains ownership of the passed memory. |
| 213 | * Defaults to \c nullptr |
| 214 | * @param colour the background colour, if \c nullptr then the output buffer is not modified |
| 215 | * if reflection does not land in the source segment. |
| 216 | * @return |
| 217 | * - 0: Success |
| 218 | * - -1: Error |
| 219 | */ |
| 220 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_background_colourcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_background_colour(dedf1e9b1c614a07).(void* colour) = 0; |
| 221 | |
| 222 | /** |
| 223 | * Returns the background colour |
| 224 | */ |
| 225 | virtual void* get_background_colourcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_background_colour(45a5c5ac6be858a8).() const = 0; |
| 226 | |
| 227 | /** |
| 228 | * Allows to explicitly specify the location of the source segment. 0 radians is in the positive |
| 229 | * horizontal direction and +ve rotates anti-clockwise. |
| 230 | * @param angle If positive or 0 then the angle of the centre of the source segment in radians. If negative |
| 231 | * (the default) then the source segment is auto calculated based on origin, preferred corner, |
| 232 | * direction and corner search direction. |
| 233 | * @return |
| 234 | * - 0: Success |
| 235 | * - -1: Error |
| 236 | */ |
| 237 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_source_segmentcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_source_segment(1bb0578f3efdc255).(float angle) = 0; |
| 238 | |
| 239 | /** |
| 240 | * Returns the source segment |
| 241 | */ |
| 242 | virtual float get_source_segmentcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_source_segment(5036dfe8d4170af2).() const = 0; |
| 243 | |
| 244 | /** |
| 245 | * Applies the kaleid0sc0pe effect to \p in_frame and returns it in \p out_frame. |
| 246 | * Each parameter must point to enough memory to contain the image specified in the |
| 247 | * constructor and must be aligned to an integer multiple of 16 bytes in memory. |
| 248 | * @param in_frame the input frame to process |
| 249 | * @param out_frame receives the output image |
| 250 | * @return |
| 251 | * - 0: Success |
| 252 | * - -1: Error |
| 253 | * - -2: Invalid parameter (nullptr) |
| 254 | */ |
| 255 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# processcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#process(6232915893069c98).(const void* in_frame, void* out_frame) = 0; |
| 256 | |
| 257 | /** |
| 258 | * Sets the number of threads to use when processing. |
| 259 | * Default to 0. |
| 260 | * @param threading the number of threads to use. \c 0, calculate automatically, |
| 261 | * otherwise the explicit thread count. |
| 262 | * @return |
| 263 | * - 0: Success |
| 264 | * - -1: Error |
| 265 | */ |
| 266 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# set_threadingcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#set_threading(4c679297bf94b9eb).(stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# threading) = 0; |
| 267 | |
| 268 | /** |
| 269 | * Returns the number of threads to use. |
| 270 | */ |
| 271 | virtual stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# get_threadingcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#get_threading(ddd8539a2fcdd4ce).() const = 0; |
| 272 | |
| 273 | /** |
| 274 | * Visualises the currently configured segmentation. The pure green segment is the |
| 275 | * source segment. |
| 276 | * @param out_frame receives the output image |
| 277 | * @return |
| 278 | * - 0: Success |
| 279 | * - -1: Error |
| 280 | * - -2: Invalid parameter (nullptr) |
| 281 | */ |
| 282 | virtual stdcxx . . $ std/::int32_tcxx . . $ std/int32_t# visualisecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#visualise(dedf1e9b1c614a07).(void* out_frame) = 0; |
| 283 | |
| 284 | /** |
| 285 | * Virtual destructor |
| 286 | */ |
| 287 | virtual ~cxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#`~IKaleid0sc0pe`(49f6e7a06ebc5aa8).IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#() {}; |
| 288 | |
| 289 | /** |
| 290 | * Static factory function. Frame width and height must be a multiple of 4. |
| 291 | * @param width the frame width |
| 292 | * @param height the frame height |
| 293 | * @param component_size the byte size of each frame pixel component |
| 294 | * @param num_components the number of components per pixel |
| 295 | * @param stride the image stride, if \c 0 then calculated as \p width * \p component_size * \p num_components |
| 296 | */ |
| 297 | static stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#> factorycxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#factory(fb18042299083462).(stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# width, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# height, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# component_size, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# num_components, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# stride = 0) { |
| 298 | return stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#>(createcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#create(8b09b43ea4db254).(width, height, component_size, num_components, stride)); |
| 299 | } |
| 300 | |
| 301 | private: |
| 302 | static IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#* createcxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#create(8b09b43ea4db254).(stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# width, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# height, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# component_size, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# num_components, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# stride = 0); |
| 303 | |
| 304 | }; |
| 305 | |
| 306 | } // namespace libkaleid0sc0pe |
| 307 | |
| 308 | #endif // SRC_FILTER_KALEID0SC0PE_IKALEID0SC0PE_H_ |