add auto zoombar/status color, fix 3 batchrender boobies, rotate plugin tweaks, add...
[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         void reset();
51
52         int equivalent(BlurConfig &that);
53         void copy_from(BlurConfig &that);
54         void interpolate(BlurConfig &prev,
55                 BlurConfig &next,
56                 int64_t prev_frame,
57                 int64_t next_frame,
58                 int64_t current_frame);
59
60         int vertical;
61         int horizontal;
62         int radius;
63         int a, r ,g ,b;
64         int a_key;
65 };
66
67 class BlurMain : public PluginVClient
68 {
69 public:
70         BlurMain(PluginServer *server);
71         ~BlurMain();
72
73 // required for all realtime plugins
74         int process_buffer(VFrame *frame,
75                 int64_t start_position,
76                 double frame_rate);
77         int is_realtime();
78         void save_data(KeyFrame *keyframe);
79         void read_data(KeyFrame *keyframe);
80         void update_gui();
81
82         PLUGIN_CLASS_MEMBERS(BlurConfig)
83
84         int need_reconfigure;
85
86 private:
87         BlurEngine **engine;
88         OverlayFrame *overlayer;
89         VFrame *input_frame;
90 };
91
92
93 class BlurConstants
94 {
95 public:
96     double n_p[5], n_m[5];
97     double d_p[5], d_m[5];
98     double bd_p[5], bd_m[5];
99 };
100
101 class BlurEngine : public Thread
102 {
103 public:
104         BlurEngine(BlurMain *plugin);
105         ~BlurEngine();
106
107         void run();
108         void set_range(int start_y,
109                 int end_y,
110                 int start_x,
111                 int end_x);
112         int start_process_frame(VFrame *frame);
113         int wait_process_frame();
114
115 // parameters needed for blur
116         int get_constants(BlurConstants *ptr, double std_dev);
117         int reconfigure(BlurConstants *constants, double alpha);
118         int transfer_pixels(pixel_f *src1,
119                 pixel_f *src2,
120                 pixel_f *src,
121                 double *radius,
122                 pixel_f *dest,
123                 int size);
124         int multiply_alpha(pixel_f *row, int size);
125         int separate_alpha(pixel_f *row, int size);
126         int blur_strip3(int &size);
127         int blur_strip4(int &size);
128
129         int color_model;
130         double vmax;
131         pixel_f *val_p, *val_m;
132         double *radius;
133         BlurConstants forward_constants;
134         BlurConstants reverse_constants;
135         pixel_f *src, *dst;
136     pixel_f initial_p;
137     pixel_f initial_m;
138         int terms;
139         BlurMain *plugin;
140 // A margin is introduced between the input and output to give a seemless transition between blurs
141         int start_y, start_x;
142         int end_y, end_x;
143         int last_frame;
144         int do_horizontal;
145 // Detect changes in alpha for alpha radius mode
146         double prev_forward_radius, prev_reverse_radius;
147         Mutex input_lock, output_lock;
148         VFrame *frame;
149 };
150
151 #endif