]> git.sesse.net Git - ffmpeg/blob - postproc/swscale.h
cleanup
[ffmpeg] / postproc / swscale.h
1 /*
2     Copyright (C) 2001-2002 Michael Niedermayer <michaelni@gmx.at>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19 /* values for the flags, the stuff on the command line is different */
20 #define SWS_FAST_BILINEAR 1
21 #define SWS_BILINEAR 2
22 #define SWS_BICUBIC  4
23 #define SWS_X        8
24 #define SWS_POINT    0x10
25 #define SWS_AREA     0x20
26 #define SWS_BICUBLIN 0x40
27 #define SWS_GAUSS    0x80
28 #define SWS_SINC     0x100
29 #define SWS_LANCZOS  0x200
30 #define SWS_SPLINE   0x400
31
32 #define SWS_SRC_V_CHR_DROP_MASK         0x30000
33 #define SWS_SRC_V_CHR_DROP_SHIFT        16
34
35 #define SWS_PARAM_MASK                  0x3FC0000
36 #define SWS_PARAM_SHIFT                 18
37
38 #define SWS_PRINT_INFO          0x1000
39
40 //the following 3 flags are not completly implemented
41 //internal chrominace subsamling info
42 #define SWS_FULL_CHR_H_INT      0x2000
43 //input subsampling info
44 #define SWS_FULL_CHR_H_INP      0x4000
45 #define SWS_DIRECT_BGR          0x8000
46
47 #define MAX_FILTER_SIZE 256
48
49 #define SWS_MAX_REDUCE_CUTOFF 0.002
50
51 /* this struct should be aligned on at least 32-byte boundary */
52 typedef struct SwsContext{
53         int srcW, srcH, dstH;
54         int chrSrcW, chrSrcH, chrDstW, chrDstH;
55         int lumXInc, chrXInc;
56         int lumYInc, chrYInc;
57         int dstFormat, srcFormat;
58         int chrSrcHSubSample, chrSrcVSubSample;
59         int chrIntHSubSample, chrIntVSubSample;
60         int chrDstHSubSample, chrDstVSubSample;
61         int vChrDrop;
62
63         int16_t **lumPixBuf;
64         int16_t **chrPixBuf;
65         int16_t *hLumFilter;
66         int16_t *hLumFilterPos;
67         int16_t *hChrFilter;
68         int16_t *hChrFilterPos;
69         int16_t *vLumFilter;
70         int16_t *vLumFilterPos;
71         int16_t *vChrFilter;
72         int16_t *vChrFilterPos;
73
74         uint8_t formatConvBuffer[4000]; //FIXME dynamic alloc, but we have to change alot of code for this to be usefull
75
76         int hLumFilterSize;
77         int hChrFilterSize;
78         int vLumFilterSize;
79         int vChrFilterSize;
80         int vLumBufSize;
81         int vChrBufSize;
82
83         uint8_t __attribute__((aligned(32))) funnyYCode[10000];
84         uint8_t __attribute__((aligned(32))) funnyUVCode[10000];
85         int32_t *lumMmx2FilterPos;
86         int32_t *chrMmx2FilterPos;
87         int16_t *lumMmx2Filter;
88         int16_t *chrMmx2Filter;
89
90         int canMMX2BeUsed;
91
92         int lastInLumBuf;
93         int lastInChrBuf;
94         int lumBufIndex;
95         int chrBufIndex;
96         int dstY;
97         int flags;
98         void * yuvTable;
99         void * table_rV[256];
100         void * table_gU[256];
101         int    table_gV[256];
102         void * table_bU[256];
103
104         void (*swScale)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
105              int srcSliceH, uint8_t* dst[], int dstStride[]);
106
107 #define RED_DITHER   "0*8"
108 #define GREEN_DITHER "1*8"
109 #define BLUE_DITHER  "2*8"
110 #define Y_COEFF      "3*8"
111 #define VR_COEFF     "4*8"
112 #define UB_COEFF     "5*8"
113 #define VG_COEFF     "6*8"
114 #define UG_COEFF     "7*8"
115 #define Y_OFFSET     "8*8"
116 #define U_OFFSET     "9*8"
117 #define V_OFFSET     "10*8"
118 #define LUM_MMX_FILTER_OFFSET "11*8"
119 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
120 #define DSTW_OFFSET  "11*8+4*4*256*2"
121 #define ESP_OFFSET  "11*8+4*4*256*2+4"
122                   
123         uint64_t redDither   __attribute__((aligned(8)));
124         uint64_t greenDither __attribute__((aligned(8)));
125         uint64_t blueDither  __attribute__((aligned(8)));
126
127         uint64_t yCoeff      __attribute__((aligned(8)));
128         uint64_t vrCoeff     __attribute__((aligned(8)));
129         uint64_t ubCoeff     __attribute__((aligned(8)));
130         uint64_t vgCoeff     __attribute__((aligned(8)));
131         uint64_t ugCoeff     __attribute__((aligned(8)));
132         uint64_t yOffset     __attribute__((aligned(8)));
133         uint64_t uOffset     __attribute__((aligned(8)));
134         uint64_t vOffset     __attribute__((aligned(8)));
135         int32_t  lumMmxFilter[4*MAX_FILTER_SIZE];
136         int32_t  chrMmxFilter[4*MAX_FILTER_SIZE];
137         int dstW;
138         int esp;
139 } SwsContext;
140 //FIXME check init (where 0)
141 //FIXME split private & public
142
143
144 // when used for filters they must have an odd number of elements
145 // coeffs cannot be shared between vectors
146 typedef struct {
147         double *coeff;
148         int length;
149 } SwsVector;
150
151 // vectors can be shared
152 typedef struct {
153         SwsVector *lumH;
154         SwsVector *lumV;
155         SwsVector *chrH;
156         SwsVector *chrV;
157 } SwsFilter;
158
159
160 // *** bilinear scaling and yuv->rgb & yuv->yuv conversion of yv12 slices:
161 // *** Note: it's called multiple times while decoding a frame, first time y==0
162 // dstbpp == 12 -> yv12 output
163 // will use sws_flags
164 void SwScale_YV12slice(unsigned char* src[],int srcStride[], int srcSliceY,
165                              int srcSliceH, uint8_t* dst[], int dstStride, int dstbpp,
166                              int srcW, int srcH, int dstW, int dstH);
167
168 // Obsolete, will be removed soon
169 void SwScale_Init();
170
171
172
173 void freeSwsContext(SwsContext *swsContext);
174
175 SwsContext *getSwsContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat);
176 SwsContext *getSwsContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
177                          SwsFilter *srcFilter, SwsFilter *dstFilter);
178 void swsGetFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam);
179
180 SwsVector *getGaussianVec(double variance, double quality);
181 SwsVector *getConstVec(double c, int length);
182 SwsVector *getIdentityVec(void);
183 void scaleVec(SwsVector *a, double scalar);
184 void normalizeVec(SwsVector *a, double height);
185 void convVec(SwsVector *a, SwsVector *b);
186 void addVec(SwsVector *a, SwsVector *b);
187 void subVec(SwsVector *a, SwsVector *b);
188 void shiftVec(SwsVector *a, int shift);
189 SwsVector *cloneVec(SwsVector *a);
190
191 void printVec(SwsVector *a);
192 void freeVec(SwsVector *a);
193