Commit | Line | Data |
---|---|---|
80f575fc DM |
1 | /* |
2 | * transformtype_operations.h | |
3 | * | |
4 | * Copyright (C) Georg Martius - June 2007 - 2013 | |
5 | * | |
6 | * This file is part of transcode, a video stream processing tool | |
7 | * | |
8 | * transcode is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2, or (at your option) | |
11 | * any later version. | |
12 | * | |
13 | * transcode is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with GNU Make; see the file COPYING. If not, write to | |
20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | * | |
22 | */ | |
23 | #ifndef __TRANSFORMTYPE_OPERATIONS_H | |
24 | #define __TRANSFORMTYPE_OPERATIONS_H | |
25 | ||
26 | #include "transformtype.h" | |
27 | #include "vidstabdefines.h" | |
28 | #include "vsvector.h" | |
29 | #include "frameinfo.h" | |
30 | ||
31 | /// helper macro to access a localmotion in the VSVector | |
32 | #define LMGet(localmotions,index) \ | |
33 | ((LocalMotion*)vs_vector_get(localmotions,index)) | |
34 | ||
35 | /* helper functions to create and operate with transforms. | |
36 | * all functions are non-destructive | |
37 | * the "_" version uses non-pointer Transforms. This is slower | |
38 | * but useful when cascading calculations like | |
39 | * add_transforms_(mult_transform(&t1, 5.0), &t2) | |
40 | */ | |
41 | VSTransform null_transform(void); | |
42 | VSTransform new_transform(double x, double y, double alpha, | |
43 | double zoom, double barrel, double rshutter, int extra); | |
44 | VSTransform add_transforms(const VSTransform* t1, const VSTransform* t2); | |
45 | VSTransform add_transforms_(const VSTransform t1, const VSTransform t2); | |
46 | VSTransform sub_transforms(const VSTransform* t1, const VSTransform* t2); | |
47 | VSTransform mult_transform(const VSTransform* t1, double f); | |
48 | VSTransform mult_transform_(const VSTransform t1, double f); | |
49 | ||
50 | void storeVSTransform(FILE* f, const VSTransform* t); | |
51 | ||
52 | ||
53 | typedef struct _preparedtransform { | |
54 | const VSTransform* t; | |
55 | double zcos_a; | |
56 | double zsin_a; | |
57 | double c_x; | |
58 | double c_y; | |
59 | } PreparedTransform; | |
60 | ||
61 | // transforms vector | |
62 | PreparedTransform prepare_transform(const VSTransform* t, const VSFrameInfo* fi); | |
63 | // transforms vector (attention, only integer) | |
64 | Vec transform_vec(const PreparedTransform* t, const Vec* v); | |
65 | void transform_vec_double(double *x, double* y, const PreparedTransform* t, const Vec* v); | |
66 | ||
67 | // subtract two vectors | |
68 | Vec sub_vec(Vec v1, Vec v2); | |
69 | // adds two vectors | |
70 | Vec add_vec(Vec v1, Vec v2); | |
71 | Vec field_to_vec(Field f); | |
72 | ||
73 | /* compares a transform with respect to x (for sort function) */ | |
74 | int cmp_trans_x(const void *t1, const void* t2); | |
75 | /* compares a transform with respect to y (for sort function) */ | |
76 | int cmp_trans_y(const void *t1, const void* t2); | |
77 | /* static int cmp_trans_alpha(const void *t1, const void* t2); */ | |
78 | ||
79 | /* compares two double values (for sort function)*/ | |
80 | int cmp_double(const void *t1, const void* t2); | |
81 | /* compares two int values (for sort function)*/ | |
82 | int cmp_int(const void *t1, const void* t2); | |
83 | ||
84 | ||
85 | /** square of a number */ | |
86 | double sqr(double x); | |
87 | ||
88 | /* calculates the median of an array of transforms, | |
89 | * considering only x and y | |
90 | */ | |
91 | VSTransform median_xy_transform(const VSTransform* transforms, int len); | |
92 | /* median of a double array */ | |
93 | double median(double* ds, int len); | |
94 | /* mean of a double array */ | |
95 | double mean(const double* ds, int len); | |
96 | /* standard deviation of a double array */ | |
97 | double stddev(const double* ds, int len, double mean); | |
98 | /* mean with cutted upper and lower pentile | |
99 | * (min and max are optionally returned) | |
100 | */ | |
101 | double cleanmean(double* ds, int len, double* minimum, double* maximum); | |
102 | /* calulcates the cleaned mean of an array of transforms, | |
103 | * considerung only x and y | |
104 | */ | |
105 | VSTransform cleanmean_xy_transform(const VSTransform* transforms, int len); | |
106 | ||
107 | /* calculates the cleaned (cutting of x-th percentil) | |
108 | * maximum and minimum of an array of transforms, | |
109 | * considerung only x and y | |
110 | */ | |
111 | void cleanmaxmin_xy_transform(const VSTransform* transforms, int len, | |
112 | int percentil, | |
113 | VSTransform* min, VSTransform* max); | |
114 | ||
115 | /* calculates the required zoom value to have no borders visible | |
116 | */ | |
117 | double transform_get_required_zoom(const VSTransform* transform, int width, int height); | |
118 | ||
119 | /* helper function to work with local motions */ | |
120 | ||
121 | LocalMotion null_localmotion(void); | |
122 | /// a new array of the v.x values is returned (vs_free has to be called) | |
123 | int* localmotions_getx(const LocalMotions* localmotions); | |
124 | /// a new array of the v.y values is returned (vs_free has to be called) | |
125 | int* localmotions_gety(const LocalMotions* localmotions); | |
126 | /// lm1 - lm2 only for the Vec (the remaining values are taken from lm1) | |
127 | LocalMotion sub_localmotion(const LocalMotion* lm1, const LocalMotion* lm2); | |
128 | ||
129 | /* calulcates the cleaned mean of the vector of localmotions | |
130 | * considerung only v.x and v.y | |
131 | */ | |
132 | LocalMotion cleanmean_localmotions(const LocalMotions* localmotions); | |
133 | ||
134 | VSArray localmotionsGetMatch(const LocalMotions* localmotions); | |
135 | ||
136 | /* helper functions */ | |
137 | ||
138 | /* optimized round function */ | |
139 | inline static int myround(float x) { | |
140 | if(x>0) | |
141 | return x + 0.5; | |
142 | else | |
143 | return x - 0.5; | |
144 | } | |
145 | ||
146 | ||
147 | /* optimized floor function | |
148 | This does not give the correct value for negative integer values like -1.0. In this case | |
149 | it will produce -2.0. | |
150 | */ | |
151 | inline static int myfloor(float x) { | |
152 | if(x<0) | |
153 | return x - 1; | |
154 | else | |
155 | return x; | |
156 | } | |
157 | ||
158 | #endif | |
159 | ||
160 | /* | |
161 | * Local variables: | |
162 | * c-file-style: "stroustrup" | |
163 | * c-file-offsets: ((case-label . *) (statement-case-intro . *)) | |
164 | * indent-tabs-mode: nil | |
165 | * c-basic-offset: 2 t | |
166 | * End: | |
167 | * | |
168 | * vim: expandtab shiftwidth=2: | |
169 | */ |