]> git.sesse.net Git - mlt/blob - src/modules/videostab/transform_image.h
added vstab from http://public.hronopik.de/vid.stab/features.php?lang=en
[mlt] / src / modules / videostab / transform_image.h
1 /*
2  *  filter_transform.c
3  *
4  *  Copyright (C) Georg Martius - June 2007
5  *   georg dot martius at web dot de  
6  *
7  *  This file is part of transcode, a video stream processing tool
8  *      
9  *  transcode is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2, or (at your option)
12  *  any later version.
13  *   
14  *  transcode is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *   
19  *  You should have received a copy of the GNU General Public License
20  *  along with GNU Make; see the file COPYING.  If not, write to
21  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
22  *
23  * Typical call:
24  * transcode -J transform -i inp.mpeg -y xdiv,tcaud inp_stab.avi
25  */
26
27 #include "transform.h"
28
29 #include <math.h>
30 #include <stdio.h>
31 #include "tlist.h"
32
33 #define DEFAULT_TRANS_FILE_NAME     "transforms.dat"
34
35 #define PIXEL(img, x, y, w, h, def) ((x) < 0 || (y) < 0) ? def       \
36     : (((x) >=w || (y) >= h) ? def : img[(x) + (y) * w]) 
37 #define PIX(img, x, y, w, h) (img[(x) + (y) * w]) 
38 // gives Pixel in N-channel image. channel in {0..N-1}
39 #define PIXELN(img, x, y, w, h, N,channel , def) ((x) < 0 || (y) < 0) ? def  \
40     : (((x) >=w || (y) >= h) ? def : img[((x) + (y) * w)*N + channel]) 
41
42 typedef struct {
43     int framesize_src;  // size of frame buffer in bytes (src)
44     int framesize_dest; // size of frame buffer in bytes (dest)
45     unsigned char* src;  // copy of the current frame buffer
46     unsigned char* dest; // pointer to the current frame buffer (to overwrite)
47
48         int pixelformat;
49     int width_src, height_src;
50     int width_dest, height_dest;
51     Transform* trans;    // array of transformations
52     int current_trans;   // index to current transformation
53     int trans_len;       // length of trans array
54     short warned_transform_end; // whether we warned that there is no transform left
55  
56     /* Options */
57     int maxshift;        // maximum number of pixels we will shift
58     double maxangle;     // maximum angle in rad
59
60     /* whether to consider transforms as relative (to previous frame) 
61      * or absolute transforms  
62      */
63     int relative;  
64     /* number of frames (forward and backward) 
65      * to use for smoothing transforms */
66     int smoothing;  
67     int crop;       // 1: black bg, 0: keep border from last frame(s)
68     int invert;     // 1: invert transforms, 0: nothing
69     /* constants */
70     /* threshhold below which no rotation is performed */
71     double rotation_threshhold; 
72     double zoom;      // percentage to zoom: 0->no zooming 10:zoom in 10%
73     int optzoom;      // 1: determine optimal zoom, 0: nothing
74     int interpoltype; // type of interpolation: 0->Zero,1->Lin,2->BiLin,3->Sqr
75     double sharpen;   // amount of sharpening
76
77     char input[0124];
78     FILE* f;
79
80     char conf_str[1024];
81 } TransformData;
82
83 /* forward declarations, please look below for documentation*/
84 void interpolateBiLinBorder(unsigned char *rv, float x, float y, 
85                             unsigned char* img, int w, int h, unsigned char def);
86 void interpolateBiCub(unsigned char *rv, float x, float y, 
87                       unsigned char* img, int width, int height, unsigned char def);
88 void interpolateSqr(unsigned char *rv, float x, float y, 
89                     unsigned char* img, int w, int h, unsigned char def);
90 void interpolateBiLin(unsigned char *rv, float x, float y, 
91                       unsigned char* img, int w, int h, unsigned char def);
92 void interpolateLin(unsigned char *rv, float x, float y, 
93                       unsigned char* img, int w, int h, unsigned char def);
94 void interpolateZero(unsigned char *rv, float x, float y, 
95                      unsigned char* img, int w, int h, unsigned char def);
96 void interpolateN(unsigned char *rv, float x, float y, 
97                   unsigned char* img, int width, int height, 
98                   unsigned char N, unsigned char channel, unsigned char def);
99 int transformRGB(TransformData* td);
100 int transformYUV(TransformData* td);
101 int read_input_file(TransformData* td,tlist* list);
102 int preprocess_transforms(TransformData* td);
103
104
105 /** 
106  * interpolate: general interpolation function pointer for one channel image data
107  *
108  * Parameters:
109  *             rv: destination pixel (call by reference)
110  *            x,y: the source coordinates in the image img. Note this 
111  *                 are real-value coordinates, that's why we interpolate
112  *            img: source image
113  *   width,height: dimension of image
114  *            def: default value if coordinates are out of range
115  * Return value:  None
116  */
117 /*void (*interpolate)(unsigned char *rv, float x, float y, 
118                     unsigned char* img, int width, int height, 
119                     unsigned char def) = 0;
120 */
121 /** interpolateBiLinBorder: bi-linear interpolation function that also works at the border.
122     This is used by many other interpolation methods at and outsize the border, see interpolate */
123 int transform_configure(TransformData *self,int width,int height, int pixelformat, unsigned char* image,Transform* tx,int trans_len) ;
124
125 int transform_filter_video(TransformData *self,       
126                                                   unsigned char *frame,int pixelformat);