]> git.sesse.net Git - mlt/blob - src/modules/videostab/transform.h
implement SSE optimized swab function
[mlt] / src / modules / videostab / transform.h
1 /*
2  *  transform.h
3  *
4  *  Copyright (C) Georg Martius - June 2007
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 __TRANSFORM_H
24 #define __TRANSFORM_H
25
26 #define DEFAULT_TRANS_FILE_NAME     "transforms.dat"
27
28 /* structure to hold information about frame transformations 
29    x,y are translations, alpha is a rotation around the center in RAD,
30    zoom is a percentage to zoom in and
31    extra is for additional information like scene cut (unused)
32  */
33 typedef struct _transform {
34     double x;
35     double y;
36     double alpha;
37     double zoom;
38     int extra;    /* -1: ignore transform (only internal use);
39                      0 for normal trans; 1 for inter scene cut (unused) */
40 } Transform;
41
42 /* helper functions to create and operate with transforms.
43  * all functions are non-destructive
44  * the "_" version uses non-pointer Transforms. This is slower
45  * but useful when cascading calculations like 
46  * add_transforms_(mult_transform(&t1, 5.0), &t2) 
47  */
48 Transform null_transform(void);
49 Transform new_transform(double x, double y, double alpha, 
50                         double zoom, int extra);
51 Transform add_transforms(const Transform* t1, const Transform* t2);
52 Transform add_transforms_(const Transform t1, const Transform t2);
53 Transform sub_transforms(const Transform* t1, const Transform* t2);
54 Transform mult_transform(const Transform* t1, double f);
55 Transform mult_transform_(const Transform t1, double f);
56
57 /* compares a transform with respect to x (for sort function) */
58 int cmp_trans_x(const void *t1, const void* t2);
59 /* compares a transform with respect to y (for sort function) */
60 int cmp_trans_y(const void *t1, const void* t2);
61 /* static int cmp_trans_alpha(const void *t1, const void* t2); */
62
63 /* compares two double values (for sort function)*/
64 int cmp_double(const void *t1, const void* t2);
65
66 /* calculates the median of an array of transforms, 
67  * considering only x and y
68  */
69 Transform median_xy_transform(const Transform* transforms, int len);
70 /* median of a double array */
71 double median(double* ds, int len);
72 /* mean of a double array */
73 double mean(const double* ds, int len);
74 /* mean with cutted upper and lower pentile 
75  * (min and max are optionally returned)
76  */
77 double cleanmean(double* ds, int len, double* minimum, double* maximum);
78 /* calculates the cleaned mean of an array of transforms,
79  * considering only x and y
80  */
81 Transform cleanmean_xy_transform(const Transform* transforms, int len);
82
83 /* calculates the cleaned (cutting of x-th percentil) 
84  * maximum and minimum of an array of transforms,
85  * considerung only x and y
86  */
87 void cleanmaxmin_xy_transform(const Transform* transforms, int len,
88                               int percentil, 
89                               Transform* min, Transform* max);
90
91 /* helper functions */
92
93 /* optimized round function */
94 inline static int myround(float x) {
95     if(x>0)
96         return x + 0.5;
97     else
98         return x - 0.5;
99 }
100
101
102 /* optimized floor function 
103    This does not give the correct value for negative integer values like -1.0. In this case
104    it will produce -2.0.
105 */
106 inline static int myfloor(float x) {
107     if(x<0)
108         return x - 1;
109     else
110         return x;
111 }
112
113
114 #endif
115
116 /*
117  * Local variables:
118  *   c-file-style: "stroustrup"
119  *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
120  *   indent-tabs-mode: nil
121  * End:
122  *
123  * vim: expandtab shiftwidth=4:
124  */