Debian Codegraph @

src/filter/kaleid0sc0pe/kaleid0sc0pe.h

raw symbols SCIP
1 /*
2 * kaleid0sc0pe.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 * The kaleidoscope class definition.
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_KALEID0SC0PE_H_
26 #define SRC_FILTER_KALEID0SC0PE_KALEID0SC0PE_H_cxx . . $ `src/filter/kaleid0sc0pe/kaleid0sc0pe.h:26:9`! 1
27
28 #include "ikaleid0sc0pe.h"cxx . . $ `<file>/src/filter/kaleid0sc0pe/ikaleid0sc0pe.h`/
29
30 #include <vector>
31 #include <cmath>
32 #include <functional>
33
34 #ifdef NO_SSE2
35 #ifdef __SSE2__
36 #undef __SSE2__
37 #endif
38 #elif !defined(__SSE2__cxx . . $ `<built-in>:422:9`!)
39 // set sse2 flag on windows
40 #if _M_IX86_FP == 2 || _M_X64 == 100
41 #ifndef _M_ARM
42 #define __SSE2__
43 #endif
44 #endif
45 #endif
46
47 #ifdef __SSE2__cxx . . $ `<built-in>:422:9`!
48 #include <emmintrin.h>
49 #endif
50
51 namespace libkaleid0sc0pecxx . . $ libkaleid0sc0pe/ {
52
53 /**
54 * Class which implements the kaleid0sc0pe effect
55 */
56 class Kaleid0sc0pecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#: public IKaleid0sc0pecxx . . $ libkaleid0sc0pe/IKaleid0sc0pe# {
57 public:
58 /**
59 * Constructor
60 * @param width the frame width
61 * @param height the frame height
62 * @param component_size the byte size of each frame pixel component
63 * @param num_components the number of components per pixel
64 * @param stride the image stride, if \c 0 then calculated as \p width * \p component_size * \p num_components
65 */
66 Kaleid0sc0pecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Kaleid0sc0pe(a9b0a938867453dc).(std::uint32_tcxx . . $ std/uint32_t# width, std::uint32_tcxx . . $ std/uint32_t# height, std::uint32_tcxx . . $ std/uint32_t# component_size, std::uint32_tcxx . . $ std/uint32_t# num_components, std::uint32_tcxx . . $ std/uint32_t# stride = 0);
67
68 virtual std::int32_tcxx . . $ std/int32_t# set_origincxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_origin(d492eb986ab7f0ea).(float x, float y);
69
70 virtual float get_origin_xcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_origin_x(5036dfe8d4170af2).() const;
71
72 virtual float get_origin_ycxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_origin_y(5036dfe8d4170af2).() const;
73
74 virtual std::int32_tcxx . . $ std/int32_t# set_segmentationcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_segmentation(4c679297bf94b9eb).(std::uint32_tcxx . . $ std/uint32_t# segmentation);
75
76 virtual std::uint32_tcxx . . $ std/uint32_t# get_segmentationcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_segmentation(ddd8539a2fcdd4ce).() const;
77
78 virtual std::int32_tcxx . . $ std/int32_t# set_edge_thresholdcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_edge_threshold(4c679297bf94b9eb).(std::uint32_tcxx . . $ std/uint32_t# threshold);
79
80 virtual std::uint32_tcxx . . $ std/uint32_t# get_edge_thresholdcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_edge_threshold(ddd8539a2fcdd4ce).() const;
81
82 virtual std::int32_tcxx . . $ std/int32_t# set_segment_directioncxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_segment_direction(353f52a649f12cd9).(Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# direction);
83
84 virtual Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# get_segment_directioncxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_segment_direction(8f08a92890f4a76).() const;
85
86 virtual std::int32_tcxx . . $ std/int32_t# set_preferred_cornercxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_preferred_corner(60b45789d1567f5a).(Cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner# corner);
87
88 virtual Cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner# get_preferred_cornercxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_preferred_corner(9be458cf2f8c5004).() const;
89
90 virtual std::int32_tcxx . . $ std/int32_t# set_preferred_corner_search_directioncxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_preferred_corner_search_direction(353f52a649f12cd9).(Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# direction);
91
92 virtual Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# get_preferred_corner_search_directioncxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_preferred_corner_search_direction(8f08a92890f4a76).() const;
93
94 virtual std::int32_tcxx . . $ std/int32_t# set_reflect_edgescxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_reflect_edges(73da94e76e6bd037).(bool reflect);
95
96 virtual bool get_reflect_edgescxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_reflect_edges(50ce9a9e25b4a850).() const;
97
98 virtual std::int32_tcxx . . $ std/int32_t# set_background_colourcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_background_colour(dedf1e9b1c614a07).(void* colour);
99
100 virtual void *get_background_colourcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_background_colour(45a5c5ac6be858a8).() const;
101
102 virtual std::int32_tcxx . . $ std/int32_t# set_source_segmentcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_source_segment(1bb0578f3efdc255).(float angle);
103
104 virtual float get_source_segmentcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_source_segment(5036dfe8d4170af2).() const;
105
106 virtual std::int32_tcxx . . $ std/int32_t# processcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#process(6232915893069c98).(const void* in_frame, void* out_frame);
107
108 virtual std::int32_tcxx . . $ std/int32_t# set_threadingcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#set_threading(4c679297bf94b9eb).(std::uint32_tcxx . . $ std/uint32_t# threading);
109
110 virtual std::uint32_tcxx . . $ std/uint32_t# get_threadingcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#get_threading(ddd8539a2fcdd4ce).() const;
111
112 virtual std::int32_tcxx . . $ std/int32_t# visualisecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#visualise(dedf1e9b1c614a07).(void* out_frame);
113
114 private:
115 void initcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#init(49f6e7a06ebc5aa8).();
116
117 #ifdef __SSE2__cxx . . $ `<built-in>:422:9`!
118 /// Defines reflection information for a given point in the frame
119 struct Reflect_infocxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info# {
120 __m128cxx . . $ __m128# screen_xcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info#screen_x.; ///< x coordinate in screen space (range -0.5->0.5, left negative)
121 __m128cxx . . $ __m128# screen_ycxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info#screen_y.; ///< y coordinate in screen space (range -0.5->0.5, top negative)
122 __m128cxx . . $ __m128# anglecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info#angle.; ///< angle from this point to the start of the source segment
123 __m128cxx . . $ __m128# segment_numbercxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info#segment_number.; ///< segment number the point resides in
124 __m128icxx . . $ __m128i# segment_number_icxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info#segment_number_i.;
125 __m128cxx . . $ __m128# reference_anglecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info#reference_angle.; ///< positive angle to start of source segment
126 };
127
128 Reflect_infocxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Reflect_info# calculate_reflect_infocxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#calculate_reflect_info(e35bad55186135e).(__m128icxx . . $ __m128i# *x, __m128icxx . . $ __m128i# *y);
129
130 /// Converts coordinates to screen space
131 /// @param x x coordinate
132 /// @param y y coordinate
133 /// @param sx source x coordinate
134 /// @param sy source y coordinate
135 void to_screencxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#to_screen(cc60a2613d21fc81).(__m128cxx . . $ __m128# *x, __m128cxx . . $ __m128# *y, __m128icxx . . $ __m128i# *sx, __m128icxx . . $ __m128i# *sy);
136
137 /// Converts coordinates from screen space in place
138 /// @param x x coordinate
139 /// @param y y coordinate
140 void from_screencxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#from_screen(31aeed7ee3ef8ddb).(__m128cxx . . $ __m128# *x, __m128cxx . . $ __m128# *y);
141
142 /// Rotate the four coordinates from <tt>x,y</tt> to <tt>x+4,y</tt> and store results in
143 /// <tt>source_x,source_y</tt>
144 /// @param x x coordinate to start rotate from
145 /// @param y y coordinate to rotate
146 /// @param source_x receives the x coordinate results
147 /// @param source_y receives the y coordinate results
148 inline void rotatecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#rotate(f1982a1c1b010a3b).(int x, int y, __m128cxx . . $ __m128# *source_x, __m128cxx . . $ __m128# *source_y);
149 #else
150 /// Defines reflection information for a given point in the frame
151 struct Reflect_info {
152 float screen_x; ///< x coordinate in screen space (range -0.5->0.5, left negative)
153 float screen_y; ///< y coordinate in screen space (range -0.5->0.5, top negative)
154 float angle; ///< angle from this point to the start of the source segment
155 std::uint32_t segment_number; ///< segment number the point resides in
156 float reference_angle; ///< positive angle to start of source segment
157 };
158
159 /// Calculates the reflection information for a given point.
160 /// NB: init() must have already been called.
161 /// @param x the x coordinate
162 /// @param x the y coordinate
163 /// @return the reflection information for the point
164 Reflect_info calculate_reflect_info(std::uint32_t x, std::uint32_t y);
165
166 /// Converts coordinates to screen space
167 /// @param x receives x coordinate
168 /// @param y receives y coordinate
169 /// @param sx source x coordinate
170 /// @param sy source y coordinate
171 void to_screen(float *x, float *y, std::uint32_t sx, std::uint32_t sy);
172
173 /// Converts coordinates from screen space in place
174 /// @param x x coordinate
175 /// @param y y coordinate
176 void from_screen(float *x, float *y);
177 #endif
178 /// A block of data to process
179 struct Blockcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block# {
180 const std::uint8_tcxx . . $ std/uint8_t#* in_framecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#in_frame.;
181 std::uint8_tcxx . . $ std/uint8_t#* out_framecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#out_frame.;
182 std::uint32_tcxx . . $ std/uint32_t# x_startcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#x_start.;
183 std::uint32_tcxx . . $ std/uint32_t# y_startcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#y_start.;
184 std::uint32_tcxx . . $ std/uint32_t# x_endcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#x_end.;
185 std::uint32_tcxx . . $ std/uint32_t# y_endcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#y_end.;
186
187 /// \param in_frame the input frame
188 /// \param out_frame the output frame
189 /// \param x_start start x coordinate of block to process
190 /// \param y_start start y coordinate of block to process
191 /// \param x_end end x coordinate of block to process (inclusive)
192 /// \param y_end end y coordinate of block to process (inclusive)
193 Blockcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#Block(c358b011fdb35479).(const std::uint8_tcxx . . $ std/uint8_t#* _in_frame, std::uint8_tcxx . . $ std/uint8_t#* _out_frame, std::uint32_tcxx . . $ std/uint32_t# _x_start, std::uint32_tcxx . . $ std/uint32_t# _y_start, std::uint32_tcxx . . $ std/uint32_t# _x_end, std::uint32_tcxx . . $ std/uint32_t# _y_end):
194 in_framecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#in_frame.(_in_frame),
195 out_framecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#out_frame.(_out_frame),
196 x_startcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#x_start.(_x_start),
197 y_startcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#y_start.(_y_start),
198 x_endcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#x_end.(_x_end),
199 y_endcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#y_end.(_y_end)
200 {}
201 };
202
203 /// Process a block
204 void process_blockcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#process_block(5fadc98ed64482aa).(Blockcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block# *block);
205
206 /// Copy pixel <tt>x,y</tt> from \p in to \p out using the background colour
207 /// if the pixel is out of range
208 /// @param x x coordinate to copy
209 /// @param y y coordinate to copy
210 /// @param in the first pixel in the source image
211 /// @param out destination
212 void process_bgcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#process_bg(cc4440d4a424271d).(float x, float y, const std::uint8_tcxx . . $ std/uint8_t#* in, std::uint8_tcxx . . $ std/uint8_t#* out);
213
214
215 #ifdef __SSE2__cxx . . $ `<built-in>:422:9`!
216 // Process a block using background colour copy
217 void process_block_bgcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#process_block_bg(5fadc98ed64482aa).(Blockcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#Block#* block);
218 #endif
219
220 std::uint8_tcxx . . $ std/uint8_t# *lookupcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#lookup(75cab8e1ec3de26e).(std::uint8_tcxx . . $ std/uint8_t# *p, std::uint32_tcxx . . $ std/uint32_t# x, std::uint32_tcxx . . $ std/uint32_t# y);
221
222 const std::uint8_tcxx . . $ std/uint8_t#* lookupcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#lookup(4728f6a7e5f4cbd9).(const std::uint8_tcxx . . $ std/uint8_t#* p, std::uint32_tcxx . . $ std/uint32_t# x, std::uint32_tcxx . . $ std/uint32_t# y);
223
224 std::uint32_tcxx . . $ std/uint32_t# m_widthcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_width.;
225 std::uint32_tcxx . . $ std/uint32_t# m_heightcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_height.;
226 std::uint32_tcxx . . $ std/uint32_t# m_component_sizecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_component_size.;
227 std::uint32_tcxx . . $ std/uint32_t# m_num_componentscxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_num_components.;
228 std::uint32_tcxx . . $ std/uint32_t# m_stridecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_stride.;
229 std::uint32_tcxx . . $ std/uint32_t# m_pixel_sizecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_pixel_size.;
230
231 float m_aspectcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_aspect.;
232
233 float m_origin_xcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_origin_x.;
234 float m_origin_ycxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_origin_y.;
235 float m_origin_native_xcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_origin_native_x.;
236 float m_origin_native_ycxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_origin_native_y.;
237
238 std::uint32_tcxx . . $ std/uint32_t# m_segmentationcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_segmentation.;
239 Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# m_segment_directioncxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_segment_direction.;
240
241 Cornercxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Corner# m_preferred_cornercxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_preferred_corner.;
242 Directioncxx . . $ libkaleid0sc0pe/IKaleid0sc0pe#Direction# m_preferred_search_dircxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_preferred_search_dir.;
243
244 bool m_edge_reflectcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_edge_reflect.;
245
246 void* m_background_colourcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_background_colour.;
247 std::uint32_tcxx . . $ std/uint32_t# m_edge_thresholdcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_edge_threshold.;
248
249 float m_source_segment_anglecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_source_segment_angle.;
250
251 std::uint32_tcxx . . $ std/uint32_t# m_n_segmentscxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_n_segments.;
252 float m_start_anglecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_start_angle.;
253 float m_segment_widthcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_segment_width.;
254
255 std::uint32_tcxx . . $ std/uint32_t# m_n_threadscxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_n_threads.;
256
257 #ifdef __SSE2__cxx . . $ `<built-in>:422:9`!
258 __m128cxx . . $ __m128# m_sse_aspectcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_aspect.;
259 __m128cxx . . $ __m128# m_sse_origin_native_xcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_origin_native_x.;
260 __m128cxx . . $ __m128# m_sse_origin_native_ycxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_origin_native_y.;
261 __m128cxx . . $ __m128# m_sse_start_anglecxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_start_angle.;
262 __m128cxx . . $ __m128# m_sse_segment_widthcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_segment_width.;
263 __m128cxx . . $ __m128# m_sse_half_segment_widthcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_half_segment_width.;
264 __m128cxx . . $ __m128# m_sse_ps_0cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_ps_0.;
265 __m128cxx . . $ __m128# m_sse_ps_1cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_ps_1.;
266 __m128cxx . . $ __m128# m_sse_ps_2cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_ps_2.;
267 __m128icxx . . $ __m128i# m_sse_epi32_1cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_epi32_1.;
268 __m128icxx . . $ __m128i# m_sse_epi32_2cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_epi32_2.;
269 __m128icxx . . $ __m128i# m_sse_shift_1cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_shift_1.;
270 __m128cxx . . $ __m128# m_sse_widthcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_width.;
271 __m128cxx . . $ __m128# m_sse_heightcxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_height.;
272 __m128cxx . . $ __m128# m_sse_width_m1cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_width_m1.;
273 __m128cxx . . $ __m128# m_sse_height_m1cxx . . $ libkaleid0sc0pe/Kaleid0sc0pe#m_sse_height_m1.;
274 #endif
275 };
276
277 } // namespace libkaleid0sc0pe
278
279 #endif // SRC_FILTER_KALEID0SC0PE_KALEID0SC0PE_H_