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 // gives Pixel in N-channel image. channel in {0..N-1}
40 #define PIXELN(img, x, y, w, h, N,channel , def) ((x) < 0 || (y) < 0) ? def \
41 : (((x) >=w || (y) >= h) ? def : img[((x) + (y) * w)*N + channel])
44 int framesize_src; // size of frame buffer in bytes (src)
45 int framesize_dest; // size of frame buffer in bytes (dest)
46 unsigned char* src; // copy of the current frame buffer
47 unsigned char* dest; // pointer to the current frame buffer (to overwrite)
50 int width_src, height_src;
51 int width_dest, height_dest;
52 Transform* trans; // array of transformations
53 int current_trans; // index to current transformation
54 int trans_len; // length of trans array
55 short warned_transform_end; // whether we warned that there is no transform left
58 int maxshift; // maximum number of pixels we will shift
59 double maxangle; // maximum angle in rad
61 /* whether to consider transforms as relative (to previous frame)
62 * or absolute transforms
65 /* number of frames (forward and backward)
66 * to use for smoothing transforms */
68 int crop; // 1: black bg, 0: keep border from last frame(s)
69 int invert; // 1: invert transforms, 0: nothing
71 /* threshhold below which no rotation is performed */
72 double rotation_threshhold;
73 double zoom; // percentage to zoom: 0->no zooming 10:zoom in 10%
74 int optzoom; // 1: determine optimal zoom, 0: nothing
75 int interpoltype; // type of interpolation: 0->Zero,1->Lin,2->BiLin,3->Sqr
76 double sharpen; // amount of sharpening
84 /* forward declarations, please look below for documentation*/
85 void interpolateBiLinBorder(unsigned char *rv, float x, float y,
86 unsigned char* img, int w, int h, unsigned char def);
87 void interpolateBiCub(unsigned char *rv, float x, float y,
88 unsigned char* img, int width, int height, unsigned char def);
89 void interpolateSqr(unsigned char *rv, float x, float y,
90 unsigned char* img, int w, int h, unsigned char def);
91 void interpolateBiLin(unsigned char *rv, float x, float y,
92 unsigned char* img, int w, int h, unsigned char def);
93 void interpolateLin(unsigned char *rv, float x, float y,
94 unsigned char* img, int w, int h, unsigned char def);
95 void interpolateZero(unsigned char *rv, float x, float y,
96 unsigned char* img, int w, int h, unsigned char def);
97 void interpolateN(unsigned char *rv, float x, float y,
98 unsigned char* img, int width, int height,
99 unsigned char N, unsigned char channel, unsigned char def);
100 int transformRGB(TransformData* td);
101 int transformYUV(TransformData* td);
102 int read_input_file(TransformData* td,tlist* list);
103 int preprocess_transforms(TransformData* td);
107 * interpolate: general interpolation function pointer for one channel image data
110 * rv: destination pixel (call by reference)
111 * x,y: the source coordinates in the image img. Note this
112 * are real-value coordinates, that's why we interpolate
114 * width,height: dimension of image
115 * def: default value if coordinates are out of range
118 /*void (*interpolate)(unsigned char *rv, float x, float y,
119 unsigned char* img, int width, int height,
120 unsigned char def) = 0;
122 /** interpolateBiLinBorder: bi-linear interpolation function that also works at the border.
123 This is used by many other interpolation methods at and outsize the border, see interpolate */
124 int transform_configure(TransformData *self,int width,int height, mlt_image_format pixelformat, unsigned char* image,Transform* tx,int trans_len) ;
126 int transform_filter_video(TransformData *self,
127 unsigned char *frame,mlt_image_format pixelformat);