]> git.sesse.net Git - mlt/blob - src/modules/videostab/transform_image.h
use calloc insteadt of malloc/memset
[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 #include <framework/mlt_types.h>
33
34 #define DEFAULT_TRANS_FILE_NAME     "transforms.dat"
35
36 #define PIXEL(img, x, y, w, h, def) ((x) < 0 || (y) < 0) ? def       \
37     : (((x) >=w || (y) >= h) ? def : img[(x) + (y) * w])
38 #define PIX(img, x, y, w, h) (img[(x) + (y) * w])
39 #define PIXN(img, x, y, w, h,N,channel) (img[((x) + (y) * w)*N+channel])
40 // gives Pixel in N-channel image. channel in {0..N-1}
41 #define PIXELN(img, x, y, w, h, N,channel , def) ((x) < 0 || (y) < 0) ? def  \
42     : (((x) >=w || (y) >= h) ? def : img[((x) + (y) * w)*N + channel])
43
44 typedef struct {
45     int framesize_src;  // size of frame buffer in bytes (src)
46     int framesize_dest; // size of frame buffer in bytes (dest)
47     unsigned char* src;  // copy of the current frame buffer
48     unsigned char* dest; // pointer to the current frame buffer (to overwrite)
49
50         int pixelformat;
51     int width_src, height_src;
52     int width_dest, height_dest;
53     Transform* trans;    // array of transformations
54     int current_trans;   // index to current transformation
55     int trans_len;       // length of trans array
56     short warned_transform_end; // whether we warned that there is no transform left
57
58     /* Options */
59     int maxshift;        // maximum number of pixels we will shift
60     double maxangle;     // maximum angle in rad
61
62     /* whether to consider transforms as relative (to previous frame)
63      * or absolute transforms
64      */
65     int relative;
66     /* number of frames (forward and backward)
67      * to use for smoothing transforms */
68     int smoothing;
69     int crop;       // 1: black bg, 0: keep border from last frame(s)
70     int invert;     // 1: invert transforms, 0: nothing
71     /* constants */
72     /* threshhold below which no rotation is performed */
73     double rotation_threshhold;
74     double zoom;      // percentage to zoom: 0->no zooming 10:zoom in 10%
75     int optzoom;      // 1: determine optimal zoom, 0: nothing
76     int interpoltype; // type of interpolation: 0->Zero,1->Lin,2->BiLin,3->Sqr
77     double sharpen;   // amount of sharpening
78
79     char conf_str[1024];
80 } TransformData;
81
82 /* forward declarations, please look below for documentation*/
83 void interpolateBiLinBorder(unsigned char *rv, float x, float y,
84                             unsigned char* img, int w, int h, unsigned char def,unsigned char N, unsigned char channel);
85 void interpolateBiCub(unsigned char *rv, float x, float y,
86                       unsigned char* img, int width, int height, unsigned char def,unsigned char N, unsigned char channel);
87 void interpolateSqr(unsigned char *rv, float x, float y,
88                     unsigned char* img, int w, int h, unsigned char def,unsigned char N, unsigned char channel);
89 void interpolateBiLin(unsigned char *rv, float x, float y,
90                       unsigned char* img, int w, int h, unsigned char def,unsigned char N, unsigned char channel);
91 void interpolateLin(unsigned char *rv, float x, float y,
92                       unsigned char* img, int w, int h, unsigned char def,unsigned char N, unsigned char channel);
93 void interpolateZero(unsigned char *rv, float x, float y,
94                      unsigned char* img, int w, int h, unsigned char def,unsigned char N, unsigned char channel);
95 void interpolateN(unsigned char *rv, float x, float y,
96                   unsigned char* img, int width, int height,
97                   unsigned char N, unsigned char channel, unsigned char def);
98 int transformRGB(TransformData* td);
99 int transformYUV(TransformData* td);
100 int read_input_file(TransformData* td,tlist* list);
101 int preprocess_transforms(TransformData* td);
102
103
104 /**
105  * interpolate: general interpolation function pointer for one channel image data
106  *
107  * Parameters:
108  *             rv: destination pixel (call by reference)
109  *            x,y: the source coordinates in the image img. Note this
110  *                 are real-value coordinates, that's why we interpolate
111  *            img: source image
112  *   width,height: dimension of image
113  *            def: default value if coordinates are out of range
114  * Return value:  None
115  */
116 /*void (*interpolate)(unsigned char *rv, float x, float y,
117                     unsigned char* img, int width, int height,
118                     unsigned char def) = 0;
119 */
120 /** interpolateBiLinBorder: bi-linear interpolation function that also works at the border.
121     This is used by many other interpolation methods at and outsize the border, see interpolate */
122 int transform_configure(TransformData *self,int width,int height, mlt_image_format pixelformat, unsigned char* image,Transform* tx,int trans_len) ;
123
124 int transform_filter_video(TransformData *self,
125                                                   unsigned char *frame,mlt_image_format pixelformat);