x265 update 2.7, findobj upgrade, fix svg init, fix for dragchkbox buttonpress, add...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / affine.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2014 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 AFFINE_H
23 #define AFFINE_H
24
25
26 #include "affine.inc"
27 #include "loadbalance.h"
28 #include "vframe.inc"
29
30 // Affine transform library
31
32 #define AFFINE_OVERSAMPLE 2
33
34 class AffineMatrix
35 {
36 public:
37         AffineMatrix();
38         void identity();
39         void translate(double x, double y);
40         void scale(double x, double y);
41 // Result is put in dst
42         void multiply(AffineMatrix *dst);
43         void copy_from(AffineMatrix *src);
44         void invert(AffineMatrix *dst);
45         void transform_point(float x, float y, float *newx, float *newy);
46         double determinant();
47         void dump();
48         double values[3][3];
49 };
50
51 class AffinePackage : public LoadPackage
52 {
53 public:
54         AffinePackage();
55         int y1, y2;
56 };
57
58 class AffineUnit : public LoadClient
59 {
60 public:
61         AffineUnit(AffineEngine *server);
62         void process_package(LoadPackage *package);
63         void calculate_matrix(
64                 double in_x1,
65                 double in_y1,
66                 double in_x2,
67                 double in_y2,
68                 double out_x1,
69                 double out_y1,
70                 double out_x2,
71                 double out_y2,
72                 double out_x3,
73                 double out_y3,
74                 double out_x4,
75                 double out_y4,
76                 AffineMatrix *result);
77 //      float transform_cubic(float dx, float jm1, float j, float jp1, float jp2);
78         AffineEngine *server;
79 };
80
81 class AffineEngine : public LoadServer
82 {
83 public:
84         AffineEngine(int total_clients,
85                 int total_packages);
86
87 // Range of coords is 0 to 100 for coordinates in the image.
88 // The coordinate locations are clockwise around the image.
89         void process(VFrame *output, VFrame *input, VFrame *temp, int mode,
90                 float x1, float y1, float x2, float y2,
91                 float x3, float y3, float x4, float y4,
92                 int forward);
93 // Do rotation with the affine/perspective transform.
94 // This removes some of the extremely faint artifacts in the trig rotation.
95         void rotate(VFrame *output, VFrame *input, float angle);
96         void set_matrix(AffineMatrix *matrix);
97 // set_matrix:
98 //  in x1,y1 - x2,y1   out x1,y1 - x2,y2 clockwise
99 //       |       |           |       |
100 //     x1,y2 - x2,y2       x4,y4 - x3,y3
101 //
102         void set_matrix( double in_x1,  double in_y1,  double in_x2,  double in_y2,
103                          double out_x1, double out_y1, double out_x2, double out_y2,
104                          double out_x3, double out_y3, double out_x4, double out_y4);
105 // Set the viewport to transform.  The transform is based on the input viewport.
106 // The output viewport clips the transformed output.
107         void set_in_viewport(int x, int y, int w, int h);
108 // Only used by motion tracker.  Not used in OpenGL.
109         void set_out_viewport(int x, int y, int w, int h);
110
111 // Set the viewport for both input and output.  Removed in HV 4.5.
112 // Compatibility function introduced to avoid having to rewrite old
113 // plugins.  Should be removed when no plugin uses it any more.
114         void set_viewport(int x, int y, int w, int h);
115 // For rotation, set the pivot point.  Also affects output in OpenGL.
116 // The default is in the middle of the viewport.
117         void set_in_pivot(int x, int y);
118 // Set the pivot point in the output.  Only used by motion tracker.
119         void set_out_pivot(int x, int y);
120 // Set the pivot point for both input and output.  Removed in HV 4.5.
121 // Compatibility function introduced to avoid having to rewrite old
122 // plugins.
123         void set_pivot(int x, int y);
124 // Never used
125         void unset_pivot();
126         void unset_viewport();
127 // default: AF_CUBIC
128         void set_interpolation(int type);
129 // To use OpenGL for the processing, set to 1
130         void set_opengl(int value);
131         void init_packages();
132         LoadClient* new_client();
133         LoadPackage* new_package();
134
135
136         VFrame *input, *output, *temp;
137         int mode;
138         enum {
139                 PERSPECTIVE,
140                 SHEER,
141                 STRETCH,
142                 ROTATE,
143 // multiply directly by a matrix.
144                 TRANSFORM
145         };
146         int interpolation;
147         enum {
148                 AF_DEFAULT,
149                 AF_NEAREST,
150                 AF_LINEAR,
151                 AF_CUBIC,
152                 AF_MODES
153         };
154
155 // arbitrary matrix
156         AffineMatrix matrix;
157 // Transformation coordinates
158         float x1, y1, x2, y2, x3, y3, x4, y4;
159 // Viewport coordinates
160         int in_x, in_y, in_w, in_h;
161         int out_x, out_y, out_w, out_h;
162 // Pivot coordinates
163         int in_pivot_x, in_pivot_y;
164         int out_pivot_x, out_pivot_y;
165         int user_in_pivot;
166         int user_out_pivot;
167         int user_in_viewport;
168         int user_out_viewport;
169         int forward;
170         int use_opengl;
171         int total_packages;
172 };
173
174
175
176 #endif