2 * transformtype_operations.h
4 * Copyright (C) Georg Martius - June 2007 - 2013
6 * This file is part of transcode, a video stream processing tool
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)
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.
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.
23 #ifndef __TRANSFORMTYPE_OPERATIONS_H
24 #define __TRANSFORMTYPE_OPERATIONS_H
26 #include "transformtype.h"
27 #include "vidstabdefines.h"
29 #include "frameinfo.h"
31 /// helper macro to access a localmotion in the VSVector
32 #define LMGet(localmotions,index) \
33 ((LocalMotion*)vs_vector_get(localmotions,index))
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)
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
);
50 void storeVSTransform(FILE* f
, const VSTransform
* t
);
53 typedef struct _preparedtransform
{
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
);
67 // subtract two vectors
68 Vec
sub_vec(Vec v1
, Vec v2
);
70 Vec
add_vec(Vec v1
, Vec v2
);
71 Vec
field_to_vec(Field f
);
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); */
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
);
85 /** square of a number */
88 /* calculates the median of an array of transforms,
89 * considering only x and y
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)
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
105 VSTransform
cleanmean_xy_transform(const VSTransform
* transforms
, int len
);
107 /* calculates the cleaned (cutting of x-th percentil)
108 * maximum and minimum of an array of transforms,
109 * considerung only x and y
111 void cleanmaxmin_xy_transform(const VSTransform
* transforms
, int len
,
113 VSTransform
* min
, VSTransform
* max
);
115 /* calculates the required zoom value to have no borders visible
117 double transform_get_required_zoom(const VSTransform
* transform
, int width
, int height
);
119 /* helper function to work with local motions */
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
);
129 /* calulcates the cleaned mean of the vector of localmotions
130 * considerung only v.x and v.y
132 LocalMotion
cleanmean_localmotions(const LocalMotions
* localmotions
);
134 VSArray
localmotionsGetMatch(const LocalMotions
* localmotions
);
136 /* helper functions */
138 /* optimized round function */
139 inline static int myround(float x
) {
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.
151 inline static int myfloor(float x
) {
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
168 * vim: expandtab shiftwidth=2: