merged hv7 mod
[goodguy/history.git] / cinelerra-5.1 / plugins / threshold / threshold.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 THRESHOLD_H
23 #define THRESHOLD_H
24
25
26 #include "histogramengine.inc"
27 #include "loadbalance.h"
28 #include "thresholdwindow.inc"
29 #include "bccolors.h"
30 #include "pluginvclient.h"
31
32
33 class ThresholdEngine;
34 class RGBA;
35
36 // Color components are in range [0, 255].
37 class RGBA
38 {
39  public:
40         RGBA();   // Initialize to transparent black.
41         RGBA(int r, int g, int b, int a);
42         void set(int r, int g, int b, int a);
43         void set(int rgb, int alpha);  // red in byte 2, green in byte 1, blue in byte 0.
44         int getRGB() const; // Encode red in byte 2, green in byte 1, blue in byte 0.
45
46         // Set R, G, B, A properties from this RGBA.
47         void set_property(XMLTag & tag, const char * prefix) const;
48
49         // Load R, G, B, A properties and return in an RGBA.
50         // Use values in this RGBA as default.
51         RGBA get_property(XMLTag & tag, const char * prefix) const;
52
53         int  r, g, b, a;
54 };
55
56 bool operator==(const RGBA & a, const RGBA & b);
57
58 // General purpose scale function.
59 template<typename T>
60 T interpolate(const T & prev, const double & prev_scale, const T & next, const double & next_scale);
61
62 // Specialization for RGBA class.
63 template<>
64 RGBA interpolate(const RGBA & prev_color, const double & prev_scale, const RGBA &next_color, const double & next_scale);
65
66
67
68 class ThresholdConfig
69 {
70 public:
71         ThresholdConfig();
72         int equivalent(ThresholdConfig &that);
73         void copy_from(ThresholdConfig &that);
74         void interpolate(ThresholdConfig &prev,
75                 ThresholdConfig &next,
76                 int64_t prev_frame,
77                 int64_t next_frame,
78                 int64_t current_frame);
79         void reset();
80         void boundaries();
81
82         float min;
83         float max;
84         int plot;
85         RGBA low_color;
86         RGBA mid_color;
87         RGBA high_color;
88 };
89
90
91
92 class ThresholdMain : public PluginVClient
93 {
94 public:
95         ThresholdMain(PluginServer *server);
96         ~ThresholdMain();
97
98         int process_buffer(VFrame *frame,
99                 int64_t start_position,
100                 double frame_rate);
101         int is_realtime();
102         void save_data(KeyFrame *keyframe);
103         void read_data(KeyFrame *keyframe);
104         void update_gui();
105         void render_gui(void *data);
106         void calculate_histogram(VFrame *frame);
107         int handle_opengl();
108
109         PLUGIN_CLASS_MEMBERS(ThresholdConfig);
110         HistogramEngine *engine;
111         ThresholdEngine *threshold_engine;
112 };
113
114
115
116
117
118
119 class ThresholdPackage : public LoadPackage
120 {
121 public:
122         ThresholdPackage();
123         int start;
124         int end;
125 };
126
127
128 class ThresholdUnit : public LoadClient
129 {
130 public:
131         ThresholdUnit(ThresholdEngine *server);
132         void process_package(LoadPackage *package);
133
134         ThresholdEngine *server;
135 private:
136         template<typename TYPE, int COMPONENTS, bool USE_YUV>
137         void render_data(LoadPackage *package);
138 };
139
140
141 class ThresholdEngine : public LoadServer
142 {
143 public:
144         ThresholdEngine(ThresholdMain *plugin);
145         ~ThresholdEngine();
146
147         void process_packages(VFrame *data);
148         void init_packages();
149         LoadClient* new_client();
150         LoadPackage* new_package();
151
152         YUV *yuv;
153         ThresholdMain *plugin;
154         VFrame *data;
155 };
156
157
158
159
160
161
162 #endif