1 /* 2 * Copyright (C) 2010 Georg Martius <georg.martius@web.de> 3 * Copyright (C) 2010 Daniel G. Taylor <dan@programmer-art.org> 4 * 5 * This file is part of FFmpeg. 6 * 7 * FFmpeg is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * FFmpeg is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with FFmpeg; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 #ifndef AVFILTER_TRANSFORM_H 23 #define AVFILTER_TRANSFORM_H 24 25 #include <stdint.h> 26 27 /** 28 * @file 29 * transform input video 30 * 31 * All matrices are defined as a single 9-item block of contiguous memory. For 32 * example, the identity matrix would be: 33 * 34 * float *matrix = {1, 0, 0, 35 * 0, 1, 0, 36 * 0, 0, 1}; 37 */ 38 39 enum InterpolateMethod { 40 INTERPOLATE_NEAREST, //< Nearest-neighbor (fast) 41 INTERPOLATE_BILINEAR, //< Bilinear 42 INTERPOLATE_BIQUADRATIC, //< Biquadratic (best) 43 INTERPOLATE_COUNT, //< Number of interpolation methods 44 }; 45 46 // Shortcuts for the fastest and best interpolation methods 47 #define INTERPOLATE_DEFAULT INTERPOLATE_BILINEAR 48 #define INTERPOLATE_FAST INTERPOLATE_NEAREST 49 #define INTERPOLATE_BEST INTERPOLATE_BIQUADRATIC 50 51 enum FillMethod { 52 FILL_BLANK, //< Fill zeroes at blank locations 53 FILL_ORIGINAL, //< Original image at blank locations 54 FILL_CLAMP, //< Extruded edge value at blank locations 55 FILL_MIRROR, //< Mirrored edge at blank locations 56 FILL_COUNT, //< Number of edge fill methods 57 }; 58 59 // Shortcuts for fill methods 60 #define FILL_DEFAULT FILL_ORIGINAL 61 62 /** 63 * Get an affine transformation matrix from given translation, rotation, and 64 * zoom factors. The matrix will look like: 65 * 66 * [ scale_x * cos(angle), -sin(angle), x_shift, 67 * sin(angle), scale_y * cos(angle), y_shift, 68 * 0, 0, 1 ] 69 * 70 * @param x_shift horizontal translation 71 * @param y_shift vertical translation 72 * @param angle rotation in radians 73 * @param scale_x x scale percent (1.0 = 100%) 74 * @param scale_y y scale percent (1.0 = 100%) 75 * @param matrix 9-item affine transformation matrix 76 */ 77 void ff_get_matrix( 78 float x_shift, 79 float y_shift, 80 float angle, 81 float scale_x, 82 float scale_y, 83 float *matrix 84 ); 85 86 /** 87 * Do an affine transformation with the given interpolation method. This 88 * multiplies each vector [x,y,1] by the matrix and then interpolates to 89 * get the final value. 90 * 91 * @param src source image 92 * @param dst destination image 93 * @param src_stride source image line size in bytes 94 * @param dst_stride destination image line size in bytes 95 * @param width image width in pixels 96 * @param height image height in pixels 97 * @param matrix 9-item affine transformation matrix 98 * @param interpolate pixel interpolation method 99 * @param fill edge fill method 100 * @return negative on error 101 */ 102 int ff_affine_transform(const uint8_t *src, uint8_t *dst, 103 int src_stride, int dst_stride, 104 int width, int height, const float *matrix, 105 enum InterpolateMethod interpolate, 106 enum FillMethod fill); 107 108 #endif /* AVFILTER_TRANSFORM_H */ 109