Debian Codegraph @

src/filter/shake0scillate/shake0scillate.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2024 Johann JEG ([email protected])
3 *
4 * This file is a Frei0r plugin.
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "frei0r.hpp"cxx . . $ `<file>/include/frei0r.hpp`/
21 #include <cairo.h>
22 #define _USE_MATH_DEFINEScxx . . $ `src/filter/shake0scillate/shake0scillate.cpp:22:9`!
23 #include <cmath>
24
25 class Shake0scillatecxx . . $ Shake0scillate# : public frei0rcxx . . $ frei0r/::filtercxx . . $ frei0r/filter# {
26
27 private:
28
29 double movement_amount_xcxx . . $ Shake0scillate#movement_amount_x.;
30 double movement_speed_xcxx . . $ Shake0scillate#movement_speed_x.;
31 double movement_amount_ycxx . . $ Shake0scillate#movement_amount_y.;
32 double movement_speed_ycxx . . $ Shake0scillate#movement_speed_y.;
33 double rotation_amountcxx . . $ Shake0scillate#rotation_amount.;
34 double rotation_speedcxx . . $ Shake0scillate#rotation_speed.;
35 double scalecxx . . $ Shake0scillate#scale.;
36 double phasecxx . . $ Shake0scillate#phase.;
37 bool mirroredcxx . . $ Shake0scillate#mirrored.;
38
39 const float MOVEMENT_AMOUNT_MULTIPLIERcxx . . $ Shake0scillate#MOVEMENT_AMOUNT_MULTIPLIER. = 0.3f;
40 const float ROTATION_AMOUNT_MULTIPLIERcxx . . $ Shake0scillate#ROTATION_AMOUNT_MULTIPLIER. = 0.2f;
41 const float SPEED_MULTIPLIERcxx . . $ Shake0scillate#SPEED_MULTIPLIER. = 10.0f;
42
43 public:
44
45 Shake0scillatecxx . . $ Shake0scillate#Shake0scillate(b4d55b1286ff73e8).(unsigned int width, unsigned int height) {
46 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->movement_amount_xcxx . . $ Shake0scillate#movement_amount_x., "movement_amount_x"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Amount of the X movement."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
47 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->movement_speed_xcxx . . $ Shake0scillate#movement_speed_x., "movement_speed_x"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "X Movement Speed."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
48 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->movement_amount_ycxx . . $ Shake0scillate#movement_amount_y., "movement_amount_y"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Amount of the Y movement."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
49 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->movement_speed_ycxx . . $ Shake0scillate#movement_speed_y., "movement_speed_y"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Y Movement Speed."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
50 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->rotation_amountcxx . . $ Shake0scillate#rotation_amount., "rotation_amount"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Rotation amount."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
51 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->rotation_speedcxx . . $ Shake0scillate#rotation_speed., "rotation_speed"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Rotation Speed."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
52 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->scalecxx . . $ Shake0scillate#scale., "scale"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Scale level."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
53 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(this->phasecxx . . $ Shake0scillate#phase., "phase"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "The phase of the sin and cos functions of this effect."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
54 register_paramcxx . . $ frei0r/fx#register_param(f12007cc47cdd2c7).(this->mirroredcxx . . $ Shake0scillate#mirrored., "mirrored"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "On/Off Image Mirror Extend"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
55
56 this->movement_amount_xcxx . . $ Shake0scillate#movement_amount_x. = 0.5; // Movement amount off is 0.5
57 this->movement_speed_xcxx . . $ Shake0scillate#movement_speed_x. = 0.2;
58 this->movement_amount_ycxx . . $ Shake0scillate#movement_amount_y. = 0.5; // Movement amount off is 0.5
59 this->movement_speed_ycxx . . $ Shake0scillate#movement_speed_y. = 0.1;
60 this->rotation_amountcxx . . $ Shake0scillate#rotation_amount. = 0.5; // Rotation amount off is 0.5
61 this->rotation_speedcxx . . $ Shake0scillate#rotation_speed. = 0.2;
62 this->scalecxx . . $ Shake0scillate#scale. = 0.5; // Original image size is 0.5
63 this->phasecxx . . $ Shake0scillate#phase. = 0.0;
64 this->mirroredcxx . . $ Shake0scillate#mirrored. = true;
65 }
66
67 ~cxx . . $ Shake0scillate#`~Shake0scillate`(49f6e7a06ebc5aa8).Shake0scillatecxx . . $ Shake0scillate#() {
68
69 }
70
71 void clearScreencxx . . $ Shake0scillate#clearScreen(21788b7825b29bf).(cairo_t* cr) {
72 cairo_save (cr);
73 cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
74 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
75 cairo_paint (cr);
76 cairo_restore (cr);
77 }
78
79 void oscillatecxx . . $ Shake0scillate#oscillate(3247a566bd960306).(cairo_matrix_t* matrix, double time) {
80 float x = 0.0f;
81 float y = 0.0f;
82
83 // Operations for the translation amount do not depend on the screen size
84 float movement_range_x = MOVEMENT_AMOUNT_MULTIPLIERcxx . . $ Shake0scillate#MOVEMENT_AMOUNT_MULTIPLIER. * this->heightcxx . . $ frei0r/fx#height.;
85 float movement_range_y = MOVEMENT_AMOUNT_MULTIPLIERcxx . . $ Shake0scillate#MOVEMENT_AMOUNT_MULTIPLIER. * this->widthcxx . . $ frei0r/fx#width.;
86
87 // Translate X
88 if(this->movement_amount_xcxx . . $ Shake0scillate#movement_amount_x. != 0.5){
89 float movement_x = (this->movement_amount_xcxx . . $ Shake0scillate#movement_amount_x. - 0.5f) * 2.0f;
90 float movement_speed_value_x = this->movement_speed_xcxx . . $ Shake0scillate#movement_speed_x. * SPEED_MULTIPLIERcxx . . $ Shake0scillate#SPEED_MULTIPLIER. * time;
91 x = movement_x * movement_range_x * std::sin(movement_speed_value_x + this->phasecxx . . $ Shake0scillate#phase.);
92 }
93
94 // Translate Y
95 if(this->movement_amount_ycxx . . $ Shake0scillate#movement_amount_y. != 0.5){
96 float movement_y = (this->movement_amount_ycxx . . $ Shake0scillate#movement_amount_y. - 0.5f) * 2.0f;
97 float movement_speed_value_y = this->movement_speed_ycxx . . $ Shake0scillate#movement_speed_y. * SPEED_MULTIPLIERcxx . . $ Shake0scillate#SPEED_MULTIPLIER. * time;
98 y = movement_y * movement_range_y * std::cos(movement_speed_value_y + this->phasecxx . . $ Shake0scillate#phase.);
99 }
100
101 // Translate by adding the half screen coordinates to scale and rotate from center
102 float center_x = this->widthcxx . . $ frei0r/fx#width. / 2.0f;
103 float center_y = this->heightcxx . . $ frei0r/fx#height. / 2.0f;
104 cairo_matrix_translate(matrix, center_x + x, center_y + y);
105
106 // Scale
107 if(this->scalecxx . . $ Shake0scillate#scale. != 0.5){
108 float scale_factor = 1.5f - this->scalecxx . . $ Shake0scillate#scale.;
109 cairo_matrix_scale(matrix, scale_factor, scale_factor);
110 }
111
112 // Rotation
113 if(this->rotation_amountcxx . . $ Shake0scillate#rotation_amount. != 0.5){
114 float rotation_speed_value = (this->rotation_speedcxx . . $ Shake0scillate#rotation_speed. * SPEED_MULTIPLIERcxx . . $ Shake0scillate#SPEED_MULTIPLIER. * time) + this->phasecxx . . $ Shake0scillate#phase.;
115 float rotation = ((this->rotation_amountcxx . . $ Shake0scillate#rotation_amount. - 0.5f) * ROTATION_AMOUNT_MULTIPLIERcxx . . $ Shake0scillate#ROTATION_AMOUNT_MULTIPLIER.) * std::sin(rotation_speed_value) * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1289:10`!;
116 cairo_matrix_rotate(matrix, rotation);
117 }
118
119 // Restore translate coordinates
120 cairo_matrix_translate(matrix, -center_x, -center_y);
121 }
122
123 virtual void updatecxx . . $ Shake0scillate#update(da7b4a17ceb4e697).(double time, uint32_t* out, const uint32_t* in) {
124 int w = this->widthcxx . . $ frei0r/fx#width.;
125 int h = this->heightcxx . . $ frei0r/fx#height.;
126
127 // Calculate the stride for the image surface based on width and format
128 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w);
129
130 // Create a Cairo surface for the destination image
131 cairo_surface_t* dest_image = cairo_image_surface_create_for_data((unsigned char*)out,
132 CAIRO_FORMAT_ARGB32,
133 w,
134 h,
135 stride);
136
137 // Create a Cairo drawing context for the destination surface
138 cairo_t *cr = cairo_create(dest_image);
139
140 // Clear the screen
141 clearScreencxx . . $ Shake0scillate#clearScreen(21788b7825b29bf).(cr);
142
143 // Create a Cairo surface for the source image
144 cairo_surface_t *image = cairo_image_surface_create_for_data((unsigned char*)in,
145 CAIRO_FORMAT_ARGB32,
146 w,
147 h,
148 stride);
149
150 // Create a pattern from the source image surface
151 cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
152
153 if(this->mirroredcxx . . $ Shake0scillate#mirrored.){
154 // Set the pattern extend mode to reflect (mirror) when the pattern is out of bounds
155 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT);
156 } else {
157 // Set the pattern extend mode to none (mirroring does not apply)
158 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
159 }
160
161 // Initialize the transformation matrix
162 cairo_matrix_t matrix;
163 cairo_matrix_init_identity(&matrix);
164
165 // Call the function that applies the movement
166 oscillatecxx . . $ Shake0scillate#oscillate(3247a566bd960306).(&matrix, time);
167
168 // Set the transformation matrix for the pattern
169 cairo_pattern_set_matrix(pattern, &matrix);
170 // Set the source pattern to be used for drawing
171 cairo_set_source(cr, pattern);
172
173 // Draw a rectangle covering the entire image area
174 cairo_rectangle(cr, 0, 0, w, h);
175 // Fill the rectangle with the source pattern
176 cairo_fill(cr);
177
178 // Clean up resources
179 cairo_pattern_destroy (pattern);
180 cairo_surface_destroy (image);
181 cairo_surface_destroy (dest_image);
182 cairo_destroy (cr);
183 }
184 };
185
186 frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<Shake0scillatecxx . . $ Shake0scillate#> plugincxx . . $ plugin.(
187 "Shake0scillate"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
188 "Animate the input image with adjustable parameters such as amount, speed, rotation, scale and option to mirror the image if it goes outside the screen bounds."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
189 "Johann JEG"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
190 1, 0,
191 F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!);