4 * Copyright (C) Georg Martius - June 2007
5 * georg dot martius at web dot de
7 * This file is part of transcode, a video stream processing tool
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)
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.
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.
24 * transcode -J transform -i inp.mpeg -y xdiv,tcaud inp_stab.avi
27 #include "transform.h"
32 #include <framework/mlt_types.h>
34 #define DEFAULT_TRANS_FILE_NAME "transforms.dat"
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])
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)
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
59 int maxshift; // maximum number of pixels we will shift
60 double maxangle; // maximum angle in rad
62 /* whether to consider transforms as relative (to previous frame)
63 * or absolute transforms
66 /* number of frames (forward and backward)
67 * to use for smoothing transforms */
69 int crop; // 1: black bg, 0: keep border from last frame(s)
70 int invert; // 1: invert transforms, 0: nothing
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
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);
105 * interpolate: general interpolation function pointer for one channel image data
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
112 * width,height: dimension of image
113 * def: default value if coordinates are out of range
116 /*void (*interpolate)(unsigned char *rv, float x, float y,
117 unsigned char* img, int width, int height,
118 unsigned char def) = 0;
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) ;
124 int transform_filter_video(TransformData *self,
125 unsigned char *frame,mlt_image_format pixelformat);