initial commit
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / blur / blur.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef BLUR_H
23 #define BLUR_H
24
25 class BlurMain;
26 class BlurEngine;
27
28 #define MAXRADIUS 100
29
30 #include "blurwindow.inc"
31 #include "bchash.inc"
32 #include "mutex.h"
33 #include "overlayframe.h"
34 #include "pluginvclient.h"
35 #include "thread.h"
36 #include "vframe.inc"
37
38 typedef struct
39 {
40         double r;
41     double g;
42     double b;
43     double a;
44 } pixel_f;
45
46 class BlurConfig
47 {
48 public:
49         BlurConfig();
50
51         int equivalent(BlurConfig &that);
52         void copy_from(BlurConfig &that);
53         void interpolate(BlurConfig &prev,
54                 BlurConfig &next,
55                 int64_t prev_frame,
56                 int64_t next_frame,
57                 int64_t current_frame);
58
59         int vertical;
60         int horizontal;
61         int radius;
62         int a, r ,g ,b;
63         int a_key;
64 };
65
66 class BlurMain : public PluginVClient
67 {
68 public:
69         BlurMain(PluginServer *server);
70         ~BlurMain();
71
72 // required for all realtime plugins
73         int process_buffer(VFrame *frame,
74                 int64_t start_position,
75                 double frame_rate);
76         int is_realtime();
77         void save_data(KeyFrame *keyframe);
78         void read_data(KeyFrame *keyframe);
79         void update_gui();
80
81         PLUGIN_CLASS_MEMBERS(BlurConfig)
82
83         int need_reconfigure;
84
85 private:
86         BlurEngine **engine;
87         OverlayFrame *overlayer;
88         VFrame *input_frame;
89 };
90
91
92 class BlurConstants
93 {
94 public:
95     double n_p[5], n_m[5];
96     double d_p[5], d_m[5];
97     double bd_p[5], bd_m[5];
98 };
99
100 class BlurEngine : public Thread
101 {
102 public:
103         BlurEngine(BlurMain *plugin);
104         ~BlurEngine();
105
106         void run();
107         void set_range(int start_y,
108                 int end_y,
109                 int start_x,
110                 int end_x);
111         int start_process_frame(VFrame *frame);
112         int wait_process_frame();
113
114 // parameters needed for blur
115         int get_constants(BlurConstants *ptr, double std_dev);
116         int reconfigure(BlurConstants *constants, double alpha);
117         int transfer_pixels(pixel_f *src1,
118                 pixel_f *src2,
119                 pixel_f *src,
120                 double *radius,
121                 pixel_f *dest,
122                 int size);
123         int multiply_alpha(pixel_f *row, int size);
124         int separate_alpha(pixel_f *row, int size);
125         int blur_strip3(int &size);
126         int blur_strip4(int &size);
127
128         int color_model;
129         double vmax;
130         pixel_f *val_p, *val_m;
131         double *radius;
132         BlurConstants forward_constants;
133         BlurConstants reverse_constants;
134         pixel_f *src, *dst;
135     pixel_f initial_p;
136     pixel_f initial_m;
137         int terms;
138         BlurMain *plugin;
139 // A margin is introduced between the input and output to give a seemless transition between blurs
140         int start_y, start_x;
141         int end_y, end_x;
142         int last_frame;
143         int do_horizontal;
144 // Detect changes in alpha for alpha radius mode
145         double prev_forward_radius, prev_reverse_radius;
146         Mutex input_lock, output_lock;
147         VFrame *frame;
148 };
149
150 #endif