Mercurial > mplayer.hg
annotate libswscale/swscale.c @ 20066:4d1d50643826
Remove stray $ from sync tag.
author | diego |
---|---|
date | Thu, 05 Oct 2006 12:37:02 +0000 |
parents | f00912e9480b |
children | aca9e9783f67 |
rev | line source |
---|---|
18861 | 1 /* |
2 Copyright (C) 2001-2003 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19594
4678e9f81334
make the C code of the swscaler which i wrote LGPL
michael
parents:
19431
diff
changeset
|
17 |
4678e9f81334
make the C code of the swscaler which i wrote LGPL
michael
parents:
19431
diff
changeset
|
18 the C code (not assembly, mmx, ...) of the swscaler which has been written |
4678e9f81334
make the C code of the swscaler which i wrote LGPL
michael
parents:
19431
diff
changeset
|
19 by Michael Niedermayer can be used under the LGPL license too |
18861 | 20 */ |
21 | |
22 /* | |
23 supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8/Y800, YVU9/IF09 | |
24 supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09 | |
25 {BGR,RGB}{1,4,8,15,16} support dithering | |
26 | |
27 unscaled special converters (YV12=I420=IYUV, Y800=Y8) | |
28 YV12 -> {BGR,RGB}{1,4,8,15,16,24,32} | |
29 x -> x | |
30 YUV9 -> YV12 | |
31 YUV9/YV12 -> Y800 | |
32 Y800 -> YUV9/YV12 | |
33 BGR24 -> BGR32 & RGB24 -> RGB32 | |
34 BGR32 -> BGR24 & RGB32 -> RGB24 | |
35 BGR15 -> BGR16 | |
36 */ | |
37 | |
38 /* | |
39 tested special converters (most are tested actually but i didnt write it down ...) | |
40 YV12 -> BGR16 | |
41 YV12 -> YV12 | |
42 BGR15 -> BGR16 | |
43 BGR16 -> BGR16 | |
44 YVU9 -> YV12 | |
45 | |
46 untested special converters | |
47 YV12/I420 -> BGR15/BGR24/BGR32 (its the yuv2rgb stuff, so it should be ok) | |
48 YV12/I420 -> YV12/I420 | |
49 YUY2/BGR15/BGR24/BGR32/RGB24/RGB32 -> same format | |
50 BGR24 -> BGR32 & RGB24 -> RGB32 | |
51 BGR32 -> BGR24 & RGB32 -> RGB24 | |
52 BGR24 -> YV12 | |
53 */ | |
54 | |
55 #include <inttypes.h> | |
56 #include <string.h> | |
57 #include <math.h> | |
58 #include <stdio.h> | |
59 #include <unistd.h> | |
60 #include "config.h" | |
61 #include <assert.h> | |
62 #ifdef HAVE_MALLOC_H | |
63 #include <malloc.h> | |
64 #else | |
65 #include <stdlib.h> | |
66 #endif | |
67 #ifdef HAVE_SYS_MMAN_H | |
68 #include <sys/mman.h> | |
69 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) | |
70 #define MAP_ANONYMOUS MAP_ANON | |
71 #endif | |
72 #endif | |
73 #include "swscale.h" | |
74 #include "swscale_internal.h" | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
75 #include "x86_cpu.h" |
18861 | 76 #include "bswap.h" |
77 #include "rgb2rgb.h" | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
78 #ifdef USE_FASTMEMCPY |
18861 | 79 #include "libvo/fastmemcpy.h" |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
80 #endif |
18861 | 81 |
82 #undef MOVNTQ | |
83 #undef PAVGB | |
84 | |
85 //#undef HAVE_MMX2 | |
86 //#define HAVE_3DNOW | |
87 //#undef HAVE_MMX | |
88 //#undef ARCH_X86 | |
89 //#define WORDS_BIGENDIAN | |
90 #define DITHER1XBPP | |
91 | |
92 #define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit | |
93 | |
94 #define RET 0xC3 //near return opcode for X86 | |
95 | |
96 #ifdef MP_DEBUG | |
97 #define ASSERT(x) assert(x); | |
98 #else | |
99 #define ASSERT(x) ; | |
100 #endif | |
101 | |
102 #ifdef M_PI | |
103 #define PI M_PI | |
104 #else | |
105 #define PI 3.14159265358979323846 | |
106 #endif | |
107 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
108 #define isSupportedIn(x) ((x)==PIX_FMT_YUV420P || (x)==PIX_FMT_YUYV422 || (x)==PIX_FMT_UYVY422\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
109 || (x)==PIX_FMT_RGB32|| (x)==PIX_FMT_BGR24|| (x)==PIX_FMT_BGR565|| (x)==PIX_FMT_BGR555\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
110 || (x)==PIX_FMT_BGR32|| (x)==PIX_FMT_RGB24\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
111 || (x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_YUV410P\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
112 || (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_YUV422P || (x)==PIX_FMT_YUV411P) |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
113 #define isSupportedOut(x) ((x)==PIX_FMT_YUV420P || (x)==PIX_FMT_YUYV422 || (x)==PIX_FMT_UYVY422\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
114 || (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_YUV422P || (x)==PIX_FMT_YUV411P\ |
18861 | 115 || isRGB(x) || isBGR(x)\ |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
116 || (x)==PIX_FMT_NV12 || (x)==PIX_FMT_NV21\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
117 || (x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_YUV410P) |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
118 #define isPacked(x) ((x)==PIX_FMT_YUYV422 || (x)==PIX_FMT_UYVY422 ||isRGB(x) || isBGR(x)) |
18861 | 119 |
120 #define RGB2YUV_SHIFT 16 | |
121 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5)) | |
122 #define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5)) | |
123 #define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5)) | |
124 #define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5)) | |
125 #define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5)) | |
126 #define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5)) | |
127 #define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5)) | |
128 #define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5)) | |
129 #define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5)) | |
130 | |
131 extern const int32_t Inverse_Table_6_9[8][4]; | |
132 | |
133 /* | |
134 NOTES | |
135 Special versions: fast Y 1:1 scaling (no interpolation in y direction) | |
136 | |
137 TODO | |
138 more intelligent missalignment avoidance for the horizontal scaler | |
139 write special vertical cubic upscale version | |
140 Optimize C code (yv12 / minmax) | |
141 add support for packed pixel yuv input & output | |
142 add support for Y8 output | |
143 optimize bgr24 & bgr32 | |
144 add BGR4 output support | |
145 write special BGR->BGR scaler | |
146 */ | |
147 | |
148 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
149 static uint64_t attribute_used __attribute__((aligned(8))) bF8= 0xF8F8F8F8F8F8F8F8LL; | |
150 static uint64_t attribute_used __attribute__((aligned(8))) bFC= 0xFCFCFCFCFCFCFCFCLL; | |
151 static uint64_t __attribute__((aligned(8))) w10= 0x0010001000100010LL; | |
152 static uint64_t attribute_used __attribute__((aligned(8))) w02= 0x0002000200020002LL; | |
153 static uint64_t attribute_used __attribute__((aligned(8))) bm00001111=0x00000000FFFFFFFFLL; | |
154 static uint64_t attribute_used __attribute__((aligned(8))) bm00000111=0x0000000000FFFFFFLL; | |
155 static uint64_t attribute_used __attribute__((aligned(8))) bm11111000=0xFFFFFFFFFF000000LL; | |
156 static uint64_t attribute_used __attribute__((aligned(8))) bm01010101=0x00FF00FF00FF00FFLL; | |
157 | |
158 static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither; | |
159 static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither; | |
160 static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither; | |
161 static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither; | |
162 | |
163 static uint64_t __attribute__((aligned(8))) dither4[2]={ | |
164 0x0103010301030103LL, | |
165 0x0200020002000200LL,}; | |
166 | |
167 static uint64_t __attribute__((aligned(8))) dither8[2]={ | |
168 0x0602060206020602LL, | |
169 0x0004000400040004LL,}; | |
170 | |
171 static uint64_t __attribute__((aligned(8))) b16Mask= 0x001F001F001F001FLL; | |
172 static uint64_t attribute_used __attribute__((aligned(8))) g16Mask= 0x07E007E007E007E0LL; | |
173 static uint64_t attribute_used __attribute__((aligned(8))) r16Mask= 0xF800F800F800F800LL; | |
174 static uint64_t __attribute__((aligned(8))) b15Mask= 0x001F001F001F001FLL; | |
175 static uint64_t attribute_used __attribute__((aligned(8))) g15Mask= 0x03E003E003E003E0LL; | |
176 static uint64_t attribute_used __attribute__((aligned(8))) r15Mask= 0x7C007C007C007C00LL; | |
177 | |
178 static uint64_t attribute_used __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFLL; | |
179 static uint64_t attribute_used __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00LL; | |
180 static uint64_t attribute_used __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000LL; | |
181 | |
182 #ifdef FAST_BGR2YV12 | |
183 static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL; | |
184 static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL; | |
185 static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL; | |
186 #else | |
187 static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL; | |
188 static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL; | |
189 static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL; | |
19206 | 190 #endif /* FAST_BGR2YV12 */ |
18861 | 191 static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL; |
192 static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL; | |
193 static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL; | |
19206 | 194 #endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */ |
18861 | 195 |
196 // clipping helper table for C implementations: | |
197 static unsigned char clip_table[768]; | |
198 | |
199 static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b); | |
200 | |
201 extern const uint8_t dither_2x2_4[2][8]; | |
202 extern const uint8_t dither_2x2_8[2][8]; | |
203 extern const uint8_t dither_8x8_32[8][8]; | |
204 extern const uint8_t dither_8x8_73[8][8]; | |
205 extern const uint8_t dither_8x8_220[8][8]; | |
206 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
207 char *sws_format_name(enum PixelFormat format) |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
208 { |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
209 switch (format) { |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
210 case PIX_FMT_YUV420P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
211 return "yuv420p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
212 case PIX_FMT_YUYV422: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
213 return "yuyv422"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
214 case PIX_FMT_RGB24: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
215 return "rgb24"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
216 case PIX_FMT_BGR24: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
217 return "bgr24"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
218 case PIX_FMT_YUV422P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
219 return "yuv422p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
220 case PIX_FMT_YUV444P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
221 return "yuv444p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
222 case PIX_FMT_RGB32: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
223 return "rgb32"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
224 case PIX_FMT_YUV410P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
225 return "yuv410p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
226 case PIX_FMT_YUV411P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
227 return "yuv411p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
228 case PIX_FMT_RGB565: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
229 return "rgb565"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
230 case PIX_FMT_RGB555: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
231 return "rgb555"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
232 case PIX_FMT_GRAY8: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
233 return "gray8"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
234 case PIX_FMT_MONOWHITE: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
235 return "mono white"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
236 case PIX_FMT_MONOBLACK: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
237 return "mono black"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
238 case PIX_FMT_PAL8: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
239 return "Palette"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
240 case PIX_FMT_YUVJ420P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
241 return "yuvj420p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
242 case PIX_FMT_YUVJ422P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
243 return "yuvj422p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
244 case PIX_FMT_YUVJ444P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
245 return "yuvj444p"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
246 case PIX_FMT_XVMC_MPEG2_MC: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
247 return "xvmc_mpeg2_mc"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
248 case PIX_FMT_XVMC_MPEG2_IDCT: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
249 return "xvmc_mpeg2_idct"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
250 case PIX_FMT_UYVY422: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
251 return "uyvy422"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
252 case PIX_FMT_UYYVYY411: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
253 return "uyyvyy411"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
254 case PIX_FMT_RGB32_1: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
255 return "rgb32x"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
256 case PIX_FMT_BGR32_1: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
257 return "bgr32x"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
258 case PIX_FMT_BGR32: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
259 return "bgr32"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
260 case PIX_FMT_BGR565: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
261 return "bgr565"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
262 case PIX_FMT_BGR555: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
263 return "bgr555"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
264 case PIX_FMT_BGR8: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
265 return "bgr8"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
266 case PIX_FMT_BGR4: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
267 return "bgr4"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
268 case PIX_FMT_BGR4_BYTE: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
269 return "bgr4 byte"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
270 case PIX_FMT_RGB8: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
271 return "rgb8"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
272 case PIX_FMT_RGB4: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
273 return "rgb4"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
274 case PIX_FMT_RGB4_BYTE: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
275 return "rgb4 byte"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
276 case PIX_FMT_NV12: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
277 return "nv12"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
278 case PIX_FMT_NV21: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
279 return "nv21"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
280 default: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
281 return "Unknown format"; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
282 } |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
283 } |
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
284 |
18861 | 285 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
286 void in_asm_used_var_warning_killer() | |
287 { | |
288 volatile int i= bF8+bFC+w10+ | |
289 bm00001111+bm00000111+bm11111000+b16Mask+g16Mask+r16Mask+b15Mask+g15Mask+r15Mask+ | |
290 M24A+M24B+M24C+w02 + b5Dither+g5Dither+r5Dither+g6Dither+dither4[0]+dither8[0]+bm01010101; | |
291 if(i) i=0; | |
292 } | |
293 #endif | |
294 | |
295 static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, | |
296 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, | |
297 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) | |
298 { | |
299 //FIXME Optimize (just quickly writen not opti..) | |
300 int i; | |
301 for(i=0; i<dstW; i++) | |
302 { | |
303 int val=1<<18; | |
304 int j; | |
305 for(j=0; j<lumFilterSize; j++) | |
306 val += lumSrc[j][i] * lumFilter[j]; | |
307 | |
19181 | 308 dest[i]= FFMIN(FFMAX(val>>19, 0), 255); |
18861 | 309 } |
310 | |
311 if(uDest != NULL) | |
312 for(i=0; i<chrDstW; i++) | |
313 { | |
314 int u=1<<18; | |
315 int v=1<<18; | |
316 int j; | |
317 for(j=0; j<chrFilterSize; j++) | |
318 { | |
319 u += chrSrc[j][i] * chrFilter[j]; | |
320 v += chrSrc[j][i + 2048] * chrFilter[j]; | |
321 } | |
322 | |
19181 | 323 uDest[i]= FFMIN(FFMAX(u>>19, 0), 255); |
324 vDest[i]= FFMIN(FFMAX(v>>19, 0), 255); | |
18861 | 325 } |
326 } | |
327 | |
328 static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, | |
329 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, | |
330 uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) | |
331 { | |
332 //FIXME Optimize (just quickly writen not opti..) | |
333 int i; | |
334 for(i=0; i<dstW; i++) | |
335 { | |
336 int val=1<<18; | |
337 int j; | |
338 for(j=0; j<lumFilterSize; j++) | |
339 val += lumSrc[j][i] * lumFilter[j]; | |
340 | |
19181 | 341 dest[i]= FFMIN(FFMAX(val>>19, 0), 255); |
18861 | 342 } |
343 | |
344 if(uDest == NULL) | |
345 return; | |
346 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
347 if(dstFormat == PIX_FMT_NV12) |
18861 | 348 for(i=0; i<chrDstW; i++) |
349 { | |
350 int u=1<<18; | |
351 int v=1<<18; | |
352 int j; | |
353 for(j=0; j<chrFilterSize; j++) | |
354 { | |
355 u += chrSrc[j][i] * chrFilter[j]; | |
356 v += chrSrc[j][i + 2048] * chrFilter[j]; | |
357 } | |
358 | |
19181 | 359 uDest[2*i]= FFMIN(FFMAX(u>>19, 0), 255); |
360 uDest[2*i+1]= FFMIN(FFMAX(v>>19, 0), 255); | |
18861 | 361 } |
362 else | |
363 for(i=0; i<chrDstW; i++) | |
364 { | |
365 int u=1<<18; | |
366 int v=1<<18; | |
367 int j; | |
368 for(j=0; j<chrFilterSize; j++) | |
369 { | |
370 u += chrSrc[j][i] * chrFilter[j]; | |
371 v += chrSrc[j][i + 2048] * chrFilter[j]; | |
372 } | |
373 | |
19181 | 374 uDest[2*i]= FFMIN(FFMAX(v>>19, 0), 255); |
375 uDest[2*i+1]= FFMIN(FFMAX(u>>19, 0), 255); | |
18861 | 376 } |
377 } | |
378 | |
379 #define YSCALE_YUV_2_PACKEDX_C(type) \ | |
380 for(i=0; i<(dstW>>1); i++){\ | |
381 int j;\ | |
382 int Y1=1<<18;\ | |
383 int Y2=1<<18;\ | |
384 int U=1<<18;\ | |
385 int V=1<<18;\ | |
386 type *r, *b, *g;\ | |
387 const int i2= 2*i;\ | |
388 \ | |
389 for(j=0; j<lumFilterSize; j++)\ | |
390 {\ | |
391 Y1 += lumSrc[j][i2] * lumFilter[j];\ | |
392 Y2 += lumSrc[j][i2+1] * lumFilter[j];\ | |
393 }\ | |
394 for(j=0; j<chrFilterSize; j++)\ | |
395 {\ | |
396 U += chrSrc[j][i] * chrFilter[j];\ | |
397 V += chrSrc[j][i+2048] * chrFilter[j];\ | |
398 }\ | |
399 Y1>>=19;\ | |
400 Y2>>=19;\ | |
401 U >>=19;\ | |
402 V >>=19;\ | |
403 if((Y1|Y2|U|V)&256)\ | |
404 {\ | |
405 if(Y1>255) Y1=255;\ | |
406 else if(Y1<0)Y1=0;\ | |
407 if(Y2>255) Y2=255;\ | |
408 else if(Y2<0)Y2=0;\ | |
409 if(U>255) U=255;\ | |
410 else if(U<0) U=0;\ | |
411 if(V>255) V=255;\ | |
412 else if(V<0) V=0;\ | |
413 } | |
414 | |
415 #define YSCALE_YUV_2_RGBX_C(type) \ | |
416 YSCALE_YUV_2_PACKEDX_C(type)\ | |
417 r = c->table_rV[V];\ | |
418 g = c->table_gU[U] + c->table_gV[V];\ | |
419 b = c->table_bU[U];\ | |
420 | |
421 #define YSCALE_YUV_2_PACKED2_C \ | |
422 for(i=0; i<(dstW>>1); i++){\ | |
423 const int i2= 2*i;\ | |
424 int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19;\ | |
425 int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19;\ | |
426 int U= (uvbuf0[i ]*uvalpha1+uvbuf1[i ]*uvalpha)>>19;\ | |
427 int V= (uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19;\ | |
428 | |
429 #define YSCALE_YUV_2_RGB2_C(type) \ | |
430 YSCALE_YUV_2_PACKED2_C\ | |
431 type *r, *b, *g;\ | |
432 r = c->table_rV[V];\ | |
433 g = c->table_gU[U] + c->table_gV[V];\ | |
434 b = c->table_bU[U];\ | |
435 | |
436 #define YSCALE_YUV_2_PACKED1_C \ | |
437 for(i=0; i<(dstW>>1); i++){\ | |
438 const int i2= 2*i;\ | |
439 int Y1= buf0[i2 ]>>7;\ | |
440 int Y2= buf0[i2+1]>>7;\ | |
441 int U= (uvbuf1[i ])>>7;\ | |
442 int V= (uvbuf1[i+2048])>>7;\ | |
443 | |
444 #define YSCALE_YUV_2_RGB1_C(type) \ | |
445 YSCALE_YUV_2_PACKED1_C\ | |
446 type *r, *b, *g;\ | |
447 r = c->table_rV[V];\ | |
448 g = c->table_gU[U] + c->table_gV[V];\ | |
449 b = c->table_bU[U];\ | |
450 | |
451 #define YSCALE_YUV_2_PACKED1B_C \ | |
452 for(i=0; i<(dstW>>1); i++){\ | |
453 const int i2= 2*i;\ | |
454 int Y1= buf0[i2 ]>>7;\ | |
455 int Y2= buf0[i2+1]>>7;\ | |
456 int U= (uvbuf0[i ] + uvbuf1[i ])>>8;\ | |
457 int V= (uvbuf0[i+2048] + uvbuf1[i+2048])>>8;\ | |
458 | |
459 #define YSCALE_YUV_2_RGB1B_C(type) \ | |
460 YSCALE_YUV_2_PACKED1B_C\ | |
461 type *r, *b, *g;\ | |
462 r = c->table_rV[V];\ | |
463 g = c->table_gU[U] + c->table_gV[V];\ | |
464 b = c->table_bU[U];\ | |
465 | |
466 #define YSCALE_YUV_2_ANYRGB_C(func, func2)\ | |
467 switch(c->dstFormat)\ | |
468 {\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
469 case PIX_FMT_RGB32:\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
470 case PIX_FMT_BGR32:\ |
18861 | 471 func(uint32_t)\ |
472 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\ | |
473 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\ | |
474 } \ | |
475 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
476 case PIX_FMT_RGB24:\ |
18861 | 477 func(uint8_t)\ |
478 ((uint8_t*)dest)[0]= r[Y1];\ | |
479 ((uint8_t*)dest)[1]= g[Y1];\ | |
480 ((uint8_t*)dest)[2]= b[Y1];\ | |
481 ((uint8_t*)dest)[3]= r[Y2];\ | |
482 ((uint8_t*)dest)[4]= g[Y2];\ | |
483 ((uint8_t*)dest)[5]= b[Y2];\ | |
484 dest+=6;\ | |
485 }\ | |
486 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
487 case PIX_FMT_BGR24:\ |
18861 | 488 func(uint8_t)\ |
489 ((uint8_t*)dest)[0]= b[Y1];\ | |
490 ((uint8_t*)dest)[1]= g[Y1];\ | |
491 ((uint8_t*)dest)[2]= r[Y1];\ | |
492 ((uint8_t*)dest)[3]= b[Y2];\ | |
493 ((uint8_t*)dest)[4]= g[Y2];\ | |
494 ((uint8_t*)dest)[5]= r[Y2];\ | |
495 dest+=6;\ | |
496 }\ | |
497 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
498 case PIX_FMT_RGB565:\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
499 case PIX_FMT_BGR565:\ |
18861 | 500 {\ |
501 const int dr1= dither_2x2_8[y&1 ][0];\ | |
502 const int dg1= dither_2x2_4[y&1 ][0];\ | |
503 const int db1= dither_2x2_8[(y&1)^1][0];\ | |
504 const int dr2= dither_2x2_8[y&1 ][1];\ | |
505 const int dg2= dither_2x2_4[y&1 ][1];\ | |
506 const int db2= dither_2x2_8[(y&1)^1][1];\ | |
507 func(uint16_t)\ | |
508 ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ | |
509 ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ | |
510 }\ | |
511 }\ | |
512 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
513 case PIX_FMT_RGB555:\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
514 case PIX_FMT_BGR555:\ |
18861 | 515 {\ |
516 const int dr1= dither_2x2_8[y&1 ][0];\ | |
517 const int dg1= dither_2x2_8[y&1 ][1];\ | |
518 const int db1= dither_2x2_8[(y&1)^1][0];\ | |
519 const int dr2= dither_2x2_8[y&1 ][1];\ | |
520 const int dg2= dither_2x2_8[y&1 ][0];\ | |
521 const int db2= dither_2x2_8[(y&1)^1][1];\ | |
522 func(uint16_t)\ | |
523 ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ | |
524 ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ | |
525 }\ | |
526 }\ | |
527 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
528 case PIX_FMT_RGB8:\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
529 case PIX_FMT_BGR8:\ |
18861 | 530 {\ |
531 const uint8_t * const d64= dither_8x8_73[y&7];\ | |
532 const uint8_t * const d32= dither_8x8_32[y&7];\ | |
533 func(uint8_t)\ | |
534 ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];\ | |
535 ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];\ | |
536 }\ | |
537 }\ | |
538 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
539 case PIX_FMT_RGB4:\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
540 case PIX_FMT_BGR4:\ |
18861 | 541 {\ |
542 const uint8_t * const d64= dither_8x8_73 [y&7];\ | |
543 const uint8_t * const d128=dither_8x8_220[y&7];\ | |
544 func(uint8_t)\ | |
545 ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]\ | |
546 + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\ | |
547 }\ | |
548 }\ | |
549 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
550 case PIX_FMT_RGB4_BYTE:\ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
551 case PIX_FMT_BGR4_BYTE:\ |
18861 | 552 {\ |
553 const uint8_t * const d64= dither_8x8_73 [y&7];\ | |
554 const uint8_t * const d128=dither_8x8_220[y&7];\ | |
555 func(uint8_t)\ | |
556 ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\ | |
557 ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\ | |
558 }\ | |
559 }\ | |
560 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
561 case PIX_FMT_MONOBLACK:\ |
18861 | 562 {\ |
563 const uint8_t * const d128=dither_8x8_220[y&7];\ | |
564 uint8_t *g= c->table_gU[128] + c->table_gV[128];\ | |
565 for(i=0; i<dstW-7; i+=8){\ | |
566 int acc;\ | |
567 acc = g[((buf0[i ]*yalpha1+buf1[i ]*yalpha)>>19) + d128[0]];\ | |
568 acc+= acc + g[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19) + d128[1]];\ | |
569 acc+= acc + g[((buf0[i+2]*yalpha1+buf1[i+2]*yalpha)>>19) + d128[2]];\ | |
570 acc+= acc + g[((buf0[i+3]*yalpha1+buf1[i+3]*yalpha)>>19) + d128[3]];\ | |
571 acc+= acc + g[((buf0[i+4]*yalpha1+buf1[i+4]*yalpha)>>19) + d128[4]];\ | |
572 acc+= acc + g[((buf0[i+5]*yalpha1+buf1[i+5]*yalpha)>>19) + d128[5]];\ | |
573 acc+= acc + g[((buf0[i+6]*yalpha1+buf1[i+6]*yalpha)>>19) + d128[6]];\ | |
574 acc+= acc + g[((buf0[i+7]*yalpha1+buf1[i+7]*yalpha)>>19) + d128[7]];\ | |
575 ((uint8_t*)dest)[0]= acc;\ | |
576 dest++;\ | |
577 }\ | |
578 \ | |
579 /*\ | |
580 ((uint8_t*)dest)-= dstW>>4;\ | |
581 {\ | |
582 int acc=0;\ | |
583 int left=0;\ | |
584 static int top[1024];\ | |
585 static int last_new[1024][1024];\ | |
586 static int last_in3[1024][1024];\ | |
587 static int drift[1024][1024];\ | |
588 int topLeft=0;\ | |
589 int shift=0;\ | |
590 int count=0;\ | |
591 const uint8_t * const d128=dither_8x8_220[y&7];\ | |
592 int error_new=0;\ | |
593 int error_in3=0;\ | |
594 int f=0;\ | |
595 \ | |
596 for(i=dstW>>1; i<dstW; i++){\ | |
597 int in= ((buf0[i ]*yalpha1+buf1[i ]*yalpha)>>19);\ | |
598 int in2 = (76309 * (in - 16) + 32768) >> 16;\ | |
599 int in3 = (in2 < 0) ? 0 : ((in2 > 255) ? 255 : in2);\ | |
600 int old= (left*7 + topLeft + top[i]*5 + top[i+1]*3)/20 + in3\ | |
601 + (last_new[y][i] - in3)*f/256;\ | |
602 int new= old> 128 ? 255 : 0;\ | |
603 \ | |
604 error_new+= ABS(last_new[y][i] - new);\ | |
605 error_in3+= ABS(last_in3[y][i] - in3);\ | |
606 f= error_new - error_in3*4;\ | |
607 if(f<0) f=0;\ | |
608 if(f>256) f=256;\ | |
609 \ | |
610 topLeft= top[i];\ | |
611 left= top[i]= old - new;\ | |
612 last_new[y][i]= new;\ | |
613 last_in3[y][i]= in3;\ | |
614 \ | |
615 acc+= acc + (new&1);\ | |
616 if((i&7)==6){\ | |
617 ((uint8_t*)dest)[0]= acc;\ | |
618 ((uint8_t*)dest)++;\ | |
619 }\ | |
620 }\ | |
621 }\ | |
622 */\ | |
623 }\ | |
624 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
625 case PIX_FMT_YUYV422:\ |
18861 | 626 func2\ |
627 ((uint8_t*)dest)[2*i2+0]= Y1;\ | |
628 ((uint8_t*)dest)[2*i2+1]= U;\ | |
629 ((uint8_t*)dest)[2*i2+2]= Y2;\ | |
630 ((uint8_t*)dest)[2*i2+3]= V;\ | |
631 } \ | |
632 break;\ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
633 case PIX_FMT_UYVY422:\ |
18861 | 634 func2\ |
635 ((uint8_t*)dest)[2*i2+0]= U;\ | |
636 ((uint8_t*)dest)[2*i2+1]= Y1;\ | |
637 ((uint8_t*)dest)[2*i2+2]= V;\ | |
638 ((uint8_t*)dest)[2*i2+3]= Y2;\ | |
639 } \ | |
640 break;\ | |
641 }\ | |
642 | |
643 | |
644 static inline void yuv2packedXinC(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, | |
645 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, | |
646 uint8_t *dest, int dstW, int y) | |
647 { | |
648 int i; | |
649 switch(c->dstFormat) | |
650 { | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
651 case PIX_FMT_BGR32: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
652 case PIX_FMT_RGB32: |
18861 | 653 YSCALE_YUV_2_RGBX_C(uint32_t) |
654 ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1]; | |
655 ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2]; | |
656 } | |
657 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
658 case PIX_FMT_RGB24: |
18861 | 659 YSCALE_YUV_2_RGBX_C(uint8_t) |
660 ((uint8_t*)dest)[0]= r[Y1]; | |
661 ((uint8_t*)dest)[1]= g[Y1]; | |
662 ((uint8_t*)dest)[2]= b[Y1]; | |
663 ((uint8_t*)dest)[3]= r[Y2]; | |
664 ((uint8_t*)dest)[4]= g[Y2]; | |
665 ((uint8_t*)dest)[5]= b[Y2]; | |
666 dest+=6; | |
667 } | |
668 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
669 case PIX_FMT_BGR24: |
18861 | 670 YSCALE_YUV_2_RGBX_C(uint8_t) |
671 ((uint8_t*)dest)[0]= b[Y1]; | |
672 ((uint8_t*)dest)[1]= g[Y1]; | |
673 ((uint8_t*)dest)[2]= r[Y1]; | |
674 ((uint8_t*)dest)[3]= b[Y2]; | |
675 ((uint8_t*)dest)[4]= g[Y2]; | |
676 ((uint8_t*)dest)[5]= r[Y2]; | |
677 dest+=6; | |
678 } | |
679 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
680 case PIX_FMT_RGB565: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
681 case PIX_FMT_BGR565: |
18861 | 682 { |
683 const int dr1= dither_2x2_8[y&1 ][0]; | |
684 const int dg1= dither_2x2_4[y&1 ][0]; | |
685 const int db1= dither_2x2_8[(y&1)^1][0]; | |
686 const int dr2= dither_2x2_8[y&1 ][1]; | |
687 const int dg2= dither_2x2_4[y&1 ][1]; | |
688 const int db2= dither_2x2_8[(y&1)^1][1]; | |
689 YSCALE_YUV_2_RGBX_C(uint16_t) | |
690 ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1]; | |
691 ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2]; | |
692 } | |
693 } | |
694 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
695 case PIX_FMT_RGB555: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
696 case PIX_FMT_BGR555: |
18861 | 697 { |
698 const int dr1= dither_2x2_8[y&1 ][0]; | |
699 const int dg1= dither_2x2_8[y&1 ][1]; | |
700 const int db1= dither_2x2_8[(y&1)^1][0]; | |
701 const int dr2= dither_2x2_8[y&1 ][1]; | |
702 const int dg2= dither_2x2_8[y&1 ][0]; | |
703 const int db2= dither_2x2_8[(y&1)^1][1]; | |
704 YSCALE_YUV_2_RGBX_C(uint16_t) | |
705 ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1]; | |
706 ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2]; | |
707 } | |
708 } | |
709 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
710 case PIX_FMT_RGB8: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
711 case PIX_FMT_BGR8: |
18861 | 712 { |
713 const uint8_t * const d64= dither_8x8_73[y&7]; | |
714 const uint8_t * const d32= dither_8x8_32[y&7]; | |
715 YSCALE_YUV_2_RGBX_C(uint8_t) | |
716 ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]]; | |
717 ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]]; | |
718 } | |
719 } | |
720 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
721 case PIX_FMT_RGB4: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
722 case PIX_FMT_BGR4: |
18861 | 723 { |
724 const uint8_t * const d64= dither_8x8_73 [y&7]; | |
725 const uint8_t * const d128=dither_8x8_220[y&7]; | |
726 YSCALE_YUV_2_RGBX_C(uint8_t) | |
727 ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]] | |
728 +((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4); | |
729 } | |
730 } | |
731 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
732 case PIX_FMT_RGB4_BYTE: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
733 case PIX_FMT_BGR4_BYTE: |
18861 | 734 { |
735 const uint8_t * const d64= dither_8x8_73 [y&7]; | |
736 const uint8_t * const d128=dither_8x8_220[y&7]; | |
737 YSCALE_YUV_2_RGBX_C(uint8_t) | |
738 ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]; | |
739 ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]]; | |
740 } | |
741 } | |
742 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
743 case PIX_FMT_MONOBLACK: |
18861 | 744 { |
745 const uint8_t * const d128=dither_8x8_220[y&7]; | |
746 uint8_t *g= c->table_gU[128] + c->table_gV[128]; | |
747 int acc=0; | |
748 for(i=0; i<dstW-1; i+=2){ | |
749 int j; | |
750 int Y1=1<<18; | |
751 int Y2=1<<18; | |
752 | |
753 for(j=0; j<lumFilterSize; j++) | |
754 { | |
755 Y1 += lumSrc[j][i] * lumFilter[j]; | |
756 Y2 += lumSrc[j][i+1] * lumFilter[j]; | |
757 } | |
758 Y1>>=19; | |
759 Y2>>=19; | |
760 if((Y1|Y2)&256) | |
761 { | |
762 if(Y1>255) Y1=255; | |
763 else if(Y1<0)Y1=0; | |
764 if(Y2>255) Y2=255; | |
765 else if(Y2<0)Y2=0; | |
766 } | |
767 acc+= acc + g[Y1+d128[(i+0)&7]]; | |
768 acc+= acc + g[Y2+d128[(i+1)&7]]; | |
769 if((i&7)==6){ | |
770 ((uint8_t*)dest)[0]= acc; | |
771 dest++; | |
772 } | |
773 } | |
774 } | |
775 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
776 case PIX_FMT_YUYV422: |
18861 | 777 YSCALE_YUV_2_PACKEDX_C(void) |
778 ((uint8_t*)dest)[2*i2+0]= Y1; | |
779 ((uint8_t*)dest)[2*i2+1]= U; | |
780 ((uint8_t*)dest)[2*i2+2]= Y2; | |
781 ((uint8_t*)dest)[2*i2+3]= V; | |
782 } | |
783 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
784 case PIX_FMT_UYVY422: |
18861 | 785 YSCALE_YUV_2_PACKEDX_C(void) |
786 ((uint8_t*)dest)[2*i2+0]= U; | |
787 ((uint8_t*)dest)[2*i2+1]= Y1; | |
788 ((uint8_t*)dest)[2*i2+2]= V; | |
789 ((uint8_t*)dest)[2*i2+3]= Y2; | |
790 } | |
791 break; | |
792 } | |
793 } | |
794 | |
795 | |
796 //Note: we have C, X86, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one | |
797 //Plain C versions | |
798 #if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT) | |
799 #define COMPILE_C | |
800 #endif | |
801 | |
802 #ifdef ARCH_POWERPC | |
803 #if defined (HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT) | |
804 #define COMPILE_ALTIVEC | |
805 #endif //HAVE_ALTIVEC | |
806 #endif //ARCH_POWERPC | |
807 | |
808 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
809 | |
810 #if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT) | |
811 #define COMPILE_MMX | |
812 #endif | |
813 | |
814 #if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT) | |
815 #define COMPILE_MMX2 | |
816 #endif | |
817 | |
818 #if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT) | |
819 #define COMPILE_3DNOW | |
820 #endif | |
821 #endif //ARCH_X86 || ARCH_X86_64 | |
822 | |
823 #undef HAVE_MMX | |
824 #undef HAVE_MMX2 | |
825 #undef HAVE_3DNOW | |
826 | |
827 #ifdef COMPILE_C | |
828 #undef HAVE_MMX | |
829 #undef HAVE_MMX2 | |
830 #undef HAVE_3DNOW | |
831 #undef HAVE_ALTIVEC | |
832 #define RENAME(a) a ## _C | |
833 #include "swscale_template.c" | |
834 #endif | |
835 | |
836 #ifdef ARCH_POWERPC | |
837 #ifdef COMPILE_ALTIVEC | |
838 #undef RENAME | |
839 #define HAVE_ALTIVEC | |
840 #define RENAME(a) a ## _altivec | |
841 #include "swscale_template.c" | |
842 #endif | |
843 #endif //ARCH_POWERPC | |
844 | |
845 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
846 | |
847 //X86 versions | |
848 /* | |
849 #undef RENAME | |
850 #undef HAVE_MMX | |
851 #undef HAVE_MMX2 | |
852 #undef HAVE_3DNOW | |
853 #define ARCH_X86 | |
854 #define RENAME(a) a ## _X86 | |
855 #include "swscale_template.c" | |
856 */ | |
857 //MMX versions | |
858 #ifdef COMPILE_MMX | |
859 #undef RENAME | |
860 #define HAVE_MMX | |
861 #undef HAVE_MMX2 | |
862 #undef HAVE_3DNOW | |
863 #define RENAME(a) a ## _MMX | |
864 #include "swscale_template.c" | |
865 #endif | |
866 | |
867 //MMX2 versions | |
868 #ifdef COMPILE_MMX2 | |
869 #undef RENAME | |
870 #define HAVE_MMX | |
871 #define HAVE_MMX2 | |
872 #undef HAVE_3DNOW | |
873 #define RENAME(a) a ## _MMX2 | |
874 #include "swscale_template.c" | |
875 #endif | |
876 | |
877 //3DNOW versions | |
878 #ifdef COMPILE_3DNOW | |
879 #undef RENAME | |
880 #define HAVE_MMX | |
881 #undef HAVE_MMX2 | |
882 #define HAVE_3DNOW | |
883 #define RENAME(a) a ## _3DNow | |
884 #include "swscale_template.c" | |
885 #endif | |
886 | |
887 #endif //ARCH_X86 || ARCH_X86_64 | |
888 | |
889 // minor note: the HAVE_xyz is messed up after that line so don't use it | |
890 | |
891 static double getSplineCoeff(double a, double b, double c, double d, double dist) | |
892 { | |
893 // printf("%f %f %f %f %f\n", a,b,c,d,dist); | |
894 if(dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; | |
895 else return getSplineCoeff( 0.0, | |
896 b+ 2.0*c + 3.0*d, | |
897 c + 3.0*d, | |
898 -b- 3.0*c - 6.0*d, | |
899 dist-1.0); | |
900 } | |
901 | |
19172
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
902 static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, |
18861 | 903 int srcW, int dstW, int filterAlign, int one, int flags, |
904 SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) | |
905 { | |
906 int i; | |
907 int filterSize; | |
908 int filter2Size; | |
909 int minFilterSize; | |
910 double *filter=NULL; | |
911 double *filter2=NULL; | |
912 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
913 if(flags & SWS_CPU_CAPS_MMX) | |
914 asm volatile("emms\n\t"::: "memory"); //FIXME this shouldnt be required but it IS (even for non mmx versions) | |
915 #endif | |
916 | |
917 // Note the +1 is for the MMXscaler which reads over the end | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
918 *filterPos = av_malloc((dstW+1)*sizeof(int16_t)); |
18861 | 919 |
920 if(ABS(xInc - 0x10000) <10) // unscaled | |
921 { | |
922 int i; | |
923 filterSize= 1; | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
924 filter= av_malloc(dstW*sizeof(double)*filterSize); |
18861 | 925 for(i=0; i<dstW*filterSize; i++) filter[i]=0; |
926 | |
927 for(i=0; i<dstW; i++) | |
928 { | |
929 filter[i*filterSize]=1; | |
930 (*filterPos)[i]=i; | |
931 } | |
932 | |
933 } | |
934 else if(flags&SWS_POINT) // lame looking point sampling mode | |
935 { | |
936 int i; | |
937 int xDstInSrc; | |
938 filterSize= 1; | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
939 filter= av_malloc(dstW*sizeof(double)*filterSize); |
18861 | 940 |
941 xDstInSrc= xInc/2 - 0x8000; | |
942 for(i=0; i<dstW; i++) | |
943 { | |
944 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; | |
945 | |
946 (*filterPos)[i]= xx; | |
947 filter[i]= 1.0; | |
948 xDstInSrc+= xInc; | |
949 } | |
950 } | |
951 else if((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) // bilinear upscale | |
952 { | |
953 int i; | |
954 int xDstInSrc; | |
955 if (flags&SWS_BICUBIC) filterSize= 4; | |
956 else if(flags&SWS_X ) filterSize= 4; | |
957 else filterSize= 2; // SWS_BILINEAR / SWS_AREA | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
958 filter= av_malloc(dstW*sizeof(double)*filterSize); |
18861 | 959 |
960 xDstInSrc= xInc/2 - 0x8000; | |
961 for(i=0; i<dstW; i++) | |
962 { | |
963 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; | |
964 int j; | |
965 | |
966 (*filterPos)[i]= xx; | |
967 //Bilinear upscale / linear interpolate / Area averaging | |
968 for(j=0; j<filterSize; j++) | |
969 { | |
970 double d= ABS((xx<<16) - xDstInSrc)/(double)(1<<16); | |
971 double coeff= 1.0 - d; | |
972 if(coeff<0) coeff=0; | |
973 filter[i*filterSize + j]= coeff; | |
974 xx++; | |
975 } | |
976 xDstInSrc+= xInc; | |
977 } | |
978 } | |
979 else | |
980 { | |
981 double xDstInSrc; | |
982 double sizeFactor, filterSizeInSrc; | |
983 const double xInc1= (double)xInc / (double)(1<<16); | |
984 | |
985 if (flags&SWS_BICUBIC) sizeFactor= 4.0; | |
986 else if(flags&SWS_X) sizeFactor= 8.0; | |
987 else if(flags&SWS_AREA) sizeFactor= 1.0; //downscale only, for upscale it is bilinear | |
988 else if(flags&SWS_GAUSS) sizeFactor= 8.0; // infinite ;) | |
989 else if(flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? 2.0*param[0] : 6.0; | |
990 else if(flags&SWS_SINC) sizeFactor= 20.0; // infinite ;) | |
991 else if(flags&SWS_SPLINE) sizeFactor= 20.0; // infinite ;) | |
992 else if(flags&SWS_BILINEAR) sizeFactor= 2.0; | |
993 else { | |
994 sizeFactor= 0.0; //GCC warning killer | |
995 ASSERT(0) | |
996 } | |
997 | |
998 if(xInc1 <= 1.0) filterSizeInSrc= sizeFactor; // upscale | |
999 else filterSizeInSrc= sizeFactor*srcW / (double)dstW; | |
1000 | |
1001 filterSize= (int)ceil(1 + filterSizeInSrc); // will be reduced later if possible | |
1002 if(filterSize > srcW-2) filterSize=srcW-2; | |
1003 | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
1004 filter= av_malloc(dstW*sizeof(double)*filterSize); |
18861 | 1005 |
1006 xDstInSrc= xInc1 / 2.0 - 0.5; | |
1007 for(i=0; i<dstW; i++) | |
1008 { | |
1009 int xx= (int)(xDstInSrc - (filterSize-1)*0.5 + 0.5); | |
1010 int j; | |
1011 (*filterPos)[i]= xx; | |
1012 for(j=0; j<filterSize; j++) | |
1013 { | |
1014 double d= ABS(xx - xDstInSrc)/filterSizeInSrc*sizeFactor; | |
1015 double coeff; | |
1016 if(flags & SWS_BICUBIC) | |
1017 { | |
1018 double B= param[0] != SWS_PARAM_DEFAULT ? param[0] : 0.0; | |
1019 double C= param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6; | |
1020 | |
1021 if(d<1.0) | |
1022 coeff = (12-9*B-6*C)*d*d*d + (-18+12*B+6*C)*d*d + 6-2*B; | |
1023 else if(d<2.0) | |
1024 coeff = (-B-6*C)*d*d*d + (6*B+30*C)*d*d + (-12*B-48*C)*d +8*B+24*C; | |
1025 else | |
1026 coeff=0.0; | |
1027 } | |
1028 /* else if(flags & SWS_X) | |
1029 { | |
1030 double p= param ? param*0.01 : 0.3; | |
1031 coeff = d ? sin(d*PI)/(d*PI) : 1.0; | |
1032 coeff*= pow(2.0, - p*d*d); | |
1033 }*/ | |
1034 else if(flags & SWS_X) | |
1035 { | |
1036 double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; | |
1037 | |
1038 if(d<1.0) | |
1039 coeff = cos(d*PI); | |
1040 else | |
1041 coeff=-1.0; | |
1042 if(coeff<0.0) coeff= -pow(-coeff, A); | |
1043 else coeff= pow( coeff, A); | |
1044 coeff= coeff*0.5 + 0.5; | |
1045 } | |
1046 else if(flags & SWS_AREA) | |
1047 { | |
1048 double srcPixelSize= 1.0/xInc1; | |
1049 if(d + srcPixelSize/2 < 0.5) coeff= 1.0; | |
1050 else if(d - srcPixelSize/2 < 0.5) coeff= (0.5-d)/srcPixelSize + 0.5; | |
1051 else coeff=0.0; | |
1052 } | |
1053 else if(flags & SWS_GAUSS) | |
1054 { | |
1055 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; | |
1056 coeff = pow(2.0, - p*d*d); | |
1057 } | |
1058 else if(flags & SWS_SINC) | |
1059 { | |
1060 coeff = d ? sin(d*PI)/(d*PI) : 1.0; | |
1061 } | |
1062 else if(flags & SWS_LANCZOS) | |
1063 { | |
1064 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; | |
1065 coeff = d ? sin(d*PI)*sin(d*PI/p)/(d*d*PI*PI/p) : 1.0; | |
1066 if(d>p) coeff=0; | |
1067 } | |
1068 else if(flags & SWS_BILINEAR) | |
1069 { | |
1070 coeff= 1.0 - d; | |
1071 if(coeff<0) coeff=0; | |
1072 } | |
1073 else if(flags & SWS_SPLINE) | |
1074 { | |
1075 double p=-2.196152422706632; | |
1076 coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, d); | |
1077 } | |
1078 else { | |
1079 coeff= 0.0; //GCC warning killer | |
1080 ASSERT(0) | |
1081 } | |
1082 | |
1083 filter[i*filterSize + j]= coeff; | |
1084 xx++; | |
1085 } | |
1086 xDstInSrc+= xInc1; | |
1087 } | |
1088 } | |
1089 | |
1090 /* apply src & dst Filter to filter -> filter2 | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1091 av_free(filter); |
18861 | 1092 */ |
1093 ASSERT(filterSize>0) | |
1094 filter2Size= filterSize; | |
1095 if(srcFilter) filter2Size+= srcFilter->length - 1; | |
1096 if(dstFilter) filter2Size+= dstFilter->length - 1; | |
1097 ASSERT(filter2Size>0) | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
1098 filter2= av_malloc(filter2Size*dstW*sizeof(double)); |
18861 | 1099 |
1100 for(i=0; i<dstW; i++) | |
1101 { | |
1102 int j; | |
1103 SwsVector scaleFilter; | |
1104 SwsVector *outVec; | |
1105 | |
1106 scaleFilter.coeff= filter + i*filterSize; | |
1107 scaleFilter.length= filterSize; | |
1108 | |
1109 if(srcFilter) outVec= sws_getConvVec(srcFilter, &scaleFilter); | |
1110 else outVec= &scaleFilter; | |
1111 | |
1112 ASSERT(outVec->length == filter2Size) | |
1113 //FIXME dstFilter | |
1114 | |
1115 for(j=0; j<outVec->length; j++) | |
1116 { | |
1117 filter2[i*filter2Size + j]= outVec->coeff[j]; | |
1118 } | |
1119 | |
1120 (*filterPos)[i]+= (filterSize-1)/2 - (filter2Size-1)/2; | |
1121 | |
1122 if(outVec != &scaleFilter) sws_freeVec(outVec); | |
1123 } | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1124 av_free(filter); filter=NULL; |
18861 | 1125 |
1126 /* try to reduce the filter-size (step1 find size and shift left) */ | |
1127 // Assume its near normalized (*0.5 or *2.0 is ok but * 0.001 is not) | |
1128 minFilterSize= 0; | |
1129 for(i=dstW-1; i>=0; i--) | |
1130 { | |
1131 int min= filter2Size; | |
1132 int j; | |
1133 double cutOff=0.0; | |
1134 | |
1135 /* get rid off near zero elements on the left by shifting left */ | |
1136 for(j=0; j<filter2Size; j++) | |
1137 { | |
1138 int k; | |
1139 cutOff += ABS(filter2[i*filter2Size]); | |
1140 | |
1141 if(cutOff > SWS_MAX_REDUCE_CUTOFF) break; | |
1142 | |
1143 /* preserve Monotonicity because the core can't handle the filter otherwise */ | |
1144 if(i<dstW-1 && (*filterPos)[i] >= (*filterPos)[i+1]) break; | |
1145 | |
1146 // Move filter coeffs left | |
1147 for(k=1; k<filter2Size; k++) | |
1148 filter2[i*filter2Size + k - 1]= filter2[i*filter2Size + k]; | |
1149 filter2[i*filter2Size + k - 1]= 0.0; | |
1150 (*filterPos)[i]++; | |
1151 } | |
1152 | |
1153 cutOff=0.0; | |
1154 /* count near zeros on the right */ | |
1155 for(j=filter2Size-1; j>0; j--) | |
1156 { | |
1157 cutOff += ABS(filter2[i*filter2Size + j]); | |
1158 | |
1159 if(cutOff > SWS_MAX_REDUCE_CUTOFF) break; | |
1160 min--; | |
1161 } | |
1162 | |
1163 if(min>minFilterSize) minFilterSize= min; | |
1164 } | |
1165 | |
1166 if (flags & SWS_CPU_CAPS_ALTIVEC) { | |
1167 // we can handle the special case 4, | |
1168 // so we don't want to go to the full 8 | |
1169 if (minFilterSize < 5) | |
1170 filterAlign = 4; | |
1171 | |
1172 // we really don't want to waste our time | |
1173 // doing useless computation, so fall-back on | |
1174 // the scalar C code for very small filter. | |
1175 // vectorizing is worth it only if you have | |
1176 // decent-sized vector. | |
1177 if (minFilterSize < 3) | |
1178 filterAlign = 1; | |
1179 } | |
1180 | |
19172
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1181 if (flags & SWS_CPU_CAPS_MMX) { |
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1182 // special case for unscaled vertical filtering |
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1183 if(minFilterSize == 1 && filterAlign == 2) |
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1184 filterAlign= 1; |
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1185 } |
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1186 |
18861 | 1187 ASSERT(minFilterSize > 0) |
1188 filterSize= (minFilterSize +(filterAlign-1)) & (~(filterAlign-1)); | |
1189 ASSERT(filterSize > 0) | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
1190 filter= av_malloc(filterSize*dstW*sizeof(double)); |
19172
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1191 if(filterSize >= MAX_FILTER_SIZE) |
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1192 return -1; |
18861 | 1193 *outFilterSize= filterSize; |
1194 | |
1195 if(flags&SWS_PRINT_INFO) | |
1196 MSG_V("SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); | |
1197 /* try to reduce the filter-size (step2 reduce it) */ | |
1198 for(i=0; i<dstW; i++) | |
1199 { | |
1200 int j; | |
1201 | |
1202 for(j=0; j<filterSize; j++) | |
1203 { | |
1204 if(j>=filter2Size) filter[i*filterSize + j]= 0.0; | |
1205 else filter[i*filterSize + j]= filter2[i*filter2Size + j]; | |
1206 } | |
1207 } | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1208 av_free(filter2); filter2=NULL; |
18861 | 1209 |
1210 | |
1211 //FIXME try to align filterpos if possible | |
1212 | |
1213 //fix borders | |
1214 for(i=0; i<dstW; i++) | |
1215 { | |
1216 int j; | |
1217 if((*filterPos)[i] < 0) | |
1218 { | |
1219 // Move filter coeffs left to compensate for filterPos | |
1220 for(j=1; j<filterSize; j++) | |
1221 { | |
19181 | 1222 int left= FFMAX(j + (*filterPos)[i], 0); |
18861 | 1223 filter[i*filterSize + left] += filter[i*filterSize + j]; |
1224 filter[i*filterSize + j]=0; | |
1225 } | |
1226 (*filterPos)[i]= 0; | |
1227 } | |
1228 | |
1229 if((*filterPos)[i] + filterSize > srcW) | |
1230 { | |
1231 int shift= (*filterPos)[i] + filterSize - srcW; | |
1232 // Move filter coeffs right to compensate for filterPos | |
1233 for(j=filterSize-2; j>=0; j--) | |
1234 { | |
19181 | 1235 int right= FFMIN(j + shift, filterSize-1); |
18861 | 1236 filter[i*filterSize +right] += filter[i*filterSize +j]; |
1237 filter[i*filterSize +j]=0; | |
1238 } | |
1239 (*filterPos)[i]= srcW - filterSize; | |
1240 } | |
1241 } | |
1242 | |
1243 // Note the +1 is for the MMXscaler which reads over the end | |
1244 /* align at 16 for AltiVec (needed by hScale_altivec_real) */ | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
1245 *outFilter= av_malloc(*outFilterSize*(dstW+1)*sizeof(int16_t)); |
18861 | 1246 memset(*outFilter, 0, *outFilterSize*(dstW+1)*sizeof(int16_t)); |
1247 | |
1248 /* Normalize & Store in outFilter */ | |
1249 for(i=0; i<dstW; i++) | |
1250 { | |
1251 int j; | |
1252 double error=0; | |
1253 double sum=0; | |
1254 double scale= one; | |
1255 | |
1256 for(j=0; j<filterSize; j++) | |
1257 { | |
1258 sum+= filter[i*filterSize + j]; | |
1259 } | |
1260 scale/= sum; | |
1261 for(j=0; j<*outFilterSize; j++) | |
1262 { | |
1263 double v= filter[i*filterSize + j]*scale + error; | |
1264 int intV= floor(v + 0.5); | |
1265 (*outFilter)[i*(*outFilterSize) + j]= intV; | |
1266 error = v - intV; | |
1267 } | |
1268 } | |
1269 | |
1270 (*filterPos)[dstW]= (*filterPos)[dstW-1]; // the MMX scaler will read over the end | |
1271 for(i=0; i<*outFilterSize; i++) | |
1272 { | |
1273 int j= dstW*(*outFilterSize); | |
1274 (*outFilter)[j + i]= (*outFilter)[j + i - (*outFilterSize)]; | |
1275 } | |
1276 | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1277 av_free(filter); |
19172
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
1278 return 0; |
18861 | 1279 } |
1280 | |
19368
eb51949c73eb
Use COMPILE_MMX2 instead of HAVE_MMX2 to determine whether to compile
uau
parents:
19336
diff
changeset
|
1281 #ifdef COMPILE_MMX2 |
18861 | 1282 static void initMMX2HScaler(int dstW, int xInc, uint8_t *funnyCode, int16_t *filter, int32_t *filterPos, int numSplits) |
1283 { | |
1284 uint8_t *fragmentA; | |
1285 long imm8OfPShufW1A; | |
1286 long imm8OfPShufW2A; | |
1287 long fragmentLengthA; | |
1288 uint8_t *fragmentB; | |
1289 long imm8OfPShufW1B; | |
1290 long imm8OfPShufW2B; | |
1291 long fragmentLengthB; | |
1292 int fragmentPos; | |
1293 | |
1294 int xpos, i; | |
1295 | |
1296 // create an optimized horizontal scaling routine | |
1297 | |
1298 //code fragment | |
1299 | |
1300 asm volatile( | |
1301 "jmp 9f \n\t" | |
1302 // Begin | |
1303 "0: \n\t" | |
1304 "movq (%%"REG_d", %%"REG_a"), %%mm3\n\t" | |
1305 "movd (%%"REG_c", %%"REG_S"), %%mm0\n\t" | |
1306 "movd 1(%%"REG_c", %%"REG_S"), %%mm1\n\t" | |
1307 "punpcklbw %%mm7, %%mm1 \n\t" | |
1308 "punpcklbw %%mm7, %%mm0 \n\t" | |
1309 "pshufw $0xFF, %%mm1, %%mm1 \n\t" | |
1310 "1: \n\t" | |
1311 "pshufw $0xFF, %%mm0, %%mm0 \n\t" | |
1312 "2: \n\t" | |
1313 "psubw %%mm1, %%mm0 \n\t" | |
1314 "movl 8(%%"REG_b", %%"REG_a"), %%esi\n\t" | |
1315 "pmullw %%mm3, %%mm0 \n\t" | |
1316 "psllw $7, %%mm1 \n\t" | |
1317 "paddw %%mm1, %%mm0 \n\t" | |
1318 | |
1319 "movq %%mm0, (%%"REG_D", %%"REG_a")\n\t" | |
1320 | |
1321 "add $8, %%"REG_a" \n\t" | |
1322 // End | |
1323 "9: \n\t" | |
1324 // "int $3\n\t" | |
1325 "lea 0b, %0 \n\t" | |
1326 "lea 1b, %1 \n\t" | |
1327 "lea 2b, %2 \n\t" | |
1328 "dec %1 \n\t" | |
1329 "dec %2 \n\t" | |
1330 "sub %0, %1 \n\t" | |
1331 "sub %0, %2 \n\t" | |
1332 "lea 9b, %3 \n\t" | |
1333 "sub %0, %3 \n\t" | |
1334 | |
1335 | |
1336 :"=r" (fragmentA), "=r" (imm8OfPShufW1A), "=r" (imm8OfPShufW2A), | |
1337 "=r" (fragmentLengthA) | |
1338 ); | |
1339 | |
1340 asm volatile( | |
1341 "jmp 9f \n\t" | |
1342 // Begin | |
1343 "0: \n\t" | |
1344 "movq (%%"REG_d", %%"REG_a"), %%mm3\n\t" | |
1345 "movd (%%"REG_c", %%"REG_S"), %%mm0\n\t" | |
1346 "punpcklbw %%mm7, %%mm0 \n\t" | |
1347 "pshufw $0xFF, %%mm0, %%mm1 \n\t" | |
1348 "1: \n\t" | |
1349 "pshufw $0xFF, %%mm0, %%mm0 \n\t" | |
1350 "2: \n\t" | |
1351 "psubw %%mm1, %%mm0 \n\t" | |
1352 "movl 8(%%"REG_b", %%"REG_a"), %%esi\n\t" | |
1353 "pmullw %%mm3, %%mm0 \n\t" | |
1354 "psllw $7, %%mm1 \n\t" | |
1355 "paddw %%mm1, %%mm0 \n\t" | |
1356 | |
1357 "movq %%mm0, (%%"REG_D", %%"REG_a")\n\t" | |
1358 | |
1359 "add $8, %%"REG_a" \n\t" | |
1360 // End | |
1361 "9: \n\t" | |
1362 // "int $3\n\t" | |
1363 "lea 0b, %0 \n\t" | |
1364 "lea 1b, %1 \n\t" | |
1365 "lea 2b, %2 \n\t" | |
1366 "dec %1 \n\t" | |
1367 "dec %2 \n\t" | |
1368 "sub %0, %1 \n\t" | |
1369 "sub %0, %2 \n\t" | |
1370 "lea 9b, %3 \n\t" | |
1371 "sub %0, %3 \n\t" | |
1372 | |
1373 | |
1374 :"=r" (fragmentB), "=r" (imm8OfPShufW1B), "=r" (imm8OfPShufW2B), | |
1375 "=r" (fragmentLengthB) | |
1376 ); | |
1377 | |
1378 xpos= 0; //lumXInc/2 - 0x8000; // difference between pixel centers | |
1379 fragmentPos=0; | |
1380 | |
1381 for(i=0; i<dstW/numSplits; i++) | |
1382 { | |
1383 int xx=xpos>>16; | |
1384 | |
1385 if((i&3) == 0) | |
1386 { | |
1387 int a=0; | |
1388 int b=((xpos+xInc)>>16) - xx; | |
1389 int c=((xpos+xInc*2)>>16) - xx; | |
1390 int d=((xpos+xInc*3)>>16) - xx; | |
1391 | |
1392 filter[i ] = (( xpos & 0xFFFF) ^ 0xFFFF)>>9; | |
1393 filter[i+1] = (((xpos+xInc ) & 0xFFFF) ^ 0xFFFF)>>9; | |
1394 filter[i+2] = (((xpos+xInc*2) & 0xFFFF) ^ 0xFFFF)>>9; | |
1395 filter[i+3] = (((xpos+xInc*3) & 0xFFFF) ^ 0xFFFF)>>9; | |
1396 filterPos[i/2]= xx; | |
1397 | |
1398 if(d+1<4) | |
1399 { | |
1400 int maxShift= 3-(d+1); | |
1401 int shift=0; | |
1402 | |
1403 memcpy(funnyCode + fragmentPos, fragmentB, fragmentLengthB); | |
1404 | |
1405 funnyCode[fragmentPos + imm8OfPShufW1B]= | |
1406 (a+1) | ((b+1)<<2) | ((c+1)<<4) | ((d+1)<<6); | |
1407 funnyCode[fragmentPos + imm8OfPShufW2B]= | |
1408 a | (b<<2) | (c<<4) | (d<<6); | |
1409 | |
1410 if(i+3>=dstW) shift=maxShift; //avoid overread | |
1411 else if((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align | |
1412 | |
1413 if(shift && i>=shift) | |
1414 { | |
1415 funnyCode[fragmentPos + imm8OfPShufW1B]+= 0x55*shift; | |
1416 funnyCode[fragmentPos + imm8OfPShufW2B]+= 0x55*shift; | |
1417 filterPos[i/2]-=shift; | |
1418 } | |
1419 | |
1420 fragmentPos+= fragmentLengthB; | |
1421 } | |
1422 else | |
1423 { | |
1424 int maxShift= 3-d; | |
1425 int shift=0; | |
1426 | |
1427 memcpy(funnyCode + fragmentPos, fragmentA, fragmentLengthA); | |
1428 | |
1429 funnyCode[fragmentPos + imm8OfPShufW1A]= | |
1430 funnyCode[fragmentPos + imm8OfPShufW2A]= | |
1431 a | (b<<2) | (c<<4) | (d<<6); | |
1432 | |
1433 if(i+4>=dstW) shift=maxShift; //avoid overread | |
1434 else if((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //partial align | |
1435 | |
1436 if(shift && i>=shift) | |
1437 { | |
1438 funnyCode[fragmentPos + imm8OfPShufW1A]+= 0x55*shift; | |
1439 funnyCode[fragmentPos + imm8OfPShufW2A]+= 0x55*shift; | |
1440 filterPos[i/2]-=shift; | |
1441 } | |
1442 | |
1443 fragmentPos+= fragmentLengthA; | |
1444 } | |
1445 | |
1446 funnyCode[fragmentPos]= RET; | |
1447 } | |
1448 xpos+=xInc; | |
1449 } | |
1450 filterPos[i/2]= xpos>>16; // needed to jump to the next part | |
1451 } | |
19368
eb51949c73eb
Use COMPILE_MMX2 instead of HAVE_MMX2 to determine whether to compile
uau
parents:
19336
diff
changeset
|
1452 #endif /* COMPILE_MMX2 */ |
18861 | 1453 |
1454 static void globalInit(void){ | |
1455 // generating tables: | |
1456 int i; | |
1457 for(i=0; i<768; i++){ | |
19181 | 1458 int c= FFMIN(FFMAX(i-256, 0), 255); |
18861 | 1459 clip_table[i]=c; |
1460 } | |
1461 } | |
1462 | |
1463 static SwsFunc getSwsFunc(int flags){ | |
1464 | |
1465 #ifdef RUNTIME_CPUDETECT | |
1466 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
1467 // ordered per speed fasterst first | |
1468 if(flags & SWS_CPU_CAPS_MMX2) | |
1469 return swScale_MMX2; | |
1470 else if(flags & SWS_CPU_CAPS_3DNOW) | |
1471 return swScale_3DNow; | |
1472 else if(flags & SWS_CPU_CAPS_MMX) | |
1473 return swScale_MMX; | |
1474 else | |
1475 return swScale_C; | |
1476 | |
1477 #else | |
1478 #ifdef ARCH_POWERPC | |
1479 if(flags & SWS_CPU_CAPS_ALTIVEC) | |
1480 return swScale_altivec; | |
1481 else | |
1482 return swScale_C; | |
1483 #endif | |
1484 return swScale_C; | |
19206 | 1485 #endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */ |
18861 | 1486 #else //RUNTIME_CPUDETECT |
1487 #ifdef HAVE_MMX2 | |
1488 return swScale_MMX2; | |
1489 #elif defined (HAVE_3DNOW) | |
1490 return swScale_3DNow; | |
1491 #elif defined (HAVE_MMX) | |
1492 return swScale_MMX; | |
1493 #elif defined (HAVE_ALTIVEC) | |
1494 return swScale_altivec; | |
1495 #else | |
1496 return swScale_C; | |
1497 #endif | |
1498 #endif //!RUNTIME_CPUDETECT | |
1499 } | |
1500 | |
1501 static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
1502 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ | |
1503 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; | |
1504 /* Copy Y plane */ | |
1505 if(dstStride[0]==srcStride[0] && srcStride[0] > 0) | |
1506 memcpy(dst, src[0], srcSliceH*dstStride[0]); | |
1507 else | |
1508 { | |
1509 int i; | |
1510 uint8_t *srcPtr= src[0]; | |
1511 uint8_t *dstPtr= dst; | |
1512 for(i=0; i<srcSliceH; i++) | |
1513 { | |
1514 memcpy(dstPtr, srcPtr, c->srcW); | |
1515 srcPtr+= srcStride[0]; | |
1516 dstPtr+= dstStride[0]; | |
1517 } | |
1518 } | |
1519 dst = dstParam[1] + dstStride[1]*srcSliceY/2; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1520 if (c->dstFormat == PIX_FMT_NV12) |
18861 | 1521 interleaveBytes( src[1],src[2],dst,c->srcW/2,srcSliceH/2,srcStride[1],srcStride[2],dstStride[0] ); |
1522 else | |
1523 interleaveBytes( src[2],src[1],dst,c->srcW/2,srcSliceH/2,srcStride[2],srcStride[1],dstStride[0] ); | |
1524 | |
1525 return srcSliceH; | |
1526 } | |
1527 | |
1528 static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
1529 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ | |
1530 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; | |
1531 | |
1532 yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); | |
1533 | |
1534 return srcSliceH; | |
1535 } | |
1536 | |
1537 static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
1538 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ | |
1539 uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; | |
1540 | |
1541 yv12touyvy( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); | |
1542 | |
1543 return srcSliceH; | |
1544 } | |
1545 | |
1546 /* {RGB,BGR}{15,16,24,32} -> {RGB,BGR}{15,16,24,32} */ | |
1547 static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
1548 int srcSliceH, uint8_t* dst[], int dstStride[]){ | |
1549 const int srcFormat= c->srcFormat; | |
1550 const int dstFormat= c->dstFormat; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1551 const int srcBpp= (fmt_depth(srcFormat) + 7) >> 3; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1552 const int dstBpp= (fmt_depth(dstFormat) + 7) >> 3; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1553 const int srcId= fmt_depth(srcFormat) >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1554 const int dstId= fmt_depth(dstFormat) >> 2; |
18861 | 1555 void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL; |
1556 | |
1557 /* BGR -> BGR */ | |
1558 if( (isBGR(srcFormat) && isBGR(dstFormat)) | |
1559 || (isRGB(srcFormat) && isRGB(dstFormat))){ | |
1560 switch(srcId | (dstId<<4)){ | |
1561 case 0x34: conv= rgb16to15; break; | |
1562 case 0x36: conv= rgb24to15; break; | |
1563 case 0x38: conv= rgb32to15; break; | |
1564 case 0x43: conv= rgb15to16; break; | |
1565 case 0x46: conv= rgb24to16; break; | |
1566 case 0x48: conv= rgb32to16; break; | |
1567 case 0x63: conv= rgb15to24; break; | |
1568 case 0x64: conv= rgb16to24; break; | |
1569 case 0x68: conv= rgb32to24; break; | |
1570 case 0x83: conv= rgb15to32; break; | |
1571 case 0x84: conv= rgb16to32; break; | |
1572 case 0x86: conv= rgb24to32; break; | |
1573 default: MSG_ERR("swScaler: internal error %s -> %s converter\n", | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1574 sws_format_name(srcFormat), sws_format_name(dstFormat)); break; |
18861 | 1575 } |
1576 }else if( (isBGR(srcFormat) && isRGB(dstFormat)) | |
1577 || (isRGB(srcFormat) && isBGR(dstFormat))){ | |
1578 switch(srcId | (dstId<<4)){ | |
1579 case 0x33: conv= rgb15tobgr15; break; | |
1580 case 0x34: conv= rgb16tobgr15; break; | |
1581 case 0x36: conv= rgb24tobgr15; break; | |
1582 case 0x38: conv= rgb32tobgr15; break; | |
1583 case 0x43: conv= rgb15tobgr16; break; | |
1584 case 0x44: conv= rgb16tobgr16; break; | |
1585 case 0x46: conv= rgb24tobgr16; break; | |
1586 case 0x48: conv= rgb32tobgr16; break; | |
1587 case 0x63: conv= rgb15tobgr24; break; | |
1588 case 0x64: conv= rgb16tobgr24; break; | |
1589 case 0x66: conv= rgb24tobgr24; break; | |
1590 case 0x68: conv= rgb32tobgr24; break; | |
1591 case 0x83: conv= rgb15tobgr32; break; | |
1592 case 0x84: conv= rgb16tobgr32; break; | |
1593 case 0x86: conv= rgb24tobgr32; break; | |
1594 case 0x88: conv= rgb32tobgr32; break; | |
1595 default: MSG_ERR("swScaler: internal error %s -> %s converter\n", | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1596 sws_format_name(srcFormat), sws_format_name(dstFormat)); break; |
18861 | 1597 } |
1598 }else{ | |
1599 MSG_ERR("swScaler: internal error %s -> %s converter\n", | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1600 sws_format_name(srcFormat), sws_format_name(dstFormat)); |
18861 | 1601 } |
1602 | |
1603 if(dstStride[0]*srcBpp == srcStride[0]*dstBpp) | |
1604 conv(src[0], dst[0] + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]); | |
1605 else | |
1606 { | |
1607 int i; | |
1608 uint8_t *srcPtr= src[0]; | |
1609 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; | |
1610 | |
1611 for(i=0; i<srcSliceH; i++) | |
1612 { | |
1613 conv(srcPtr, dstPtr, c->srcW*srcBpp); | |
1614 srcPtr+= srcStride[0]; | |
1615 dstPtr+= dstStride[0]; | |
1616 } | |
1617 } | |
1618 return srcSliceH; | |
1619 } | |
1620 | |
1621 static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
1622 int srcSliceH, uint8_t* dst[], int dstStride[]){ | |
1623 | |
1624 rgb24toyv12( | |
1625 src[0], | |
1626 dst[0]+ srcSliceY *dstStride[0], | |
1627 dst[1]+(srcSliceY>>1)*dstStride[1], | |
1628 dst[2]+(srcSliceY>>1)*dstStride[2], | |
1629 c->srcW, srcSliceH, | |
1630 dstStride[0], dstStride[1], srcStride[0]); | |
1631 return srcSliceH; | |
1632 } | |
1633 | |
1634 static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
1635 int srcSliceH, uint8_t* dst[], int dstStride[]){ | |
1636 int i; | |
1637 | |
1638 /* copy Y */ | |
1639 if(srcStride[0]==dstStride[0] && srcStride[0] > 0) | |
1640 memcpy(dst[0]+ srcSliceY*dstStride[0], src[0], srcStride[0]*srcSliceH); | |
1641 else{ | |
1642 uint8_t *srcPtr= src[0]; | |
1643 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; | |
1644 | |
1645 for(i=0; i<srcSliceH; i++) | |
1646 { | |
1647 memcpy(dstPtr, srcPtr, c->srcW); | |
1648 srcPtr+= srcStride[0]; | |
1649 dstPtr+= dstStride[0]; | |
1650 } | |
1651 } | |
1652 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1653 if(c->dstFormat==PIX_FMT_YUV420P){ |
18861 | 1654 planar2x(src[1], dst[1], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[1]); |
1655 planar2x(src[2], dst[2], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[2]); | |
1656 }else{ | |
1657 planar2x(src[1], dst[2], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[2]); | |
1658 planar2x(src[2], dst[1], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[1]); | |
1659 } | |
1660 return srcSliceH; | |
1661 } | |
1662 | |
1663 /* unscaled copy like stuff (assumes nearly identical formats) */ | |
1664 static int simpleCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
1665 int srcSliceH, uint8_t* dst[], int dstStride[]){ | |
1666 | |
1667 if(isPacked(c->srcFormat)) | |
1668 { | |
1669 if(dstStride[0]==srcStride[0] && srcStride[0] > 0) | |
1670 memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]); | |
1671 else | |
1672 { | |
1673 int i; | |
1674 uint8_t *srcPtr= src[0]; | |
1675 uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; | |
1676 int length=0; | |
1677 | |
1678 /* universal length finder */ | |
1679 while(length+c->srcW <= ABS(dstStride[0]) | |
1680 && length+c->srcW <= ABS(srcStride[0])) length+= c->srcW; | |
1681 ASSERT(length!=0); | |
1682 | |
1683 for(i=0; i<srcSliceH; i++) | |
1684 { | |
1685 memcpy(dstPtr, srcPtr, length); | |
1686 srcPtr+= srcStride[0]; | |
1687 dstPtr+= dstStride[0]; | |
1688 } | |
1689 } | |
1690 } | |
1691 else | |
1692 { /* Planar YUV or gray */ | |
1693 int plane; | |
1694 for(plane=0; plane<3; plane++) | |
1695 { | |
1696 int length= plane==0 ? c->srcW : -((-c->srcW )>>c->chrDstHSubSample); | |
1697 int y= plane==0 ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample); | |
1698 int height= plane==0 ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample); | |
1699 | |
1700 if((isGray(c->srcFormat) || isGray(c->dstFormat)) && plane>0) | |
1701 { | |
1702 if(!isGray(c->dstFormat)) | |
1703 memset(dst[plane], 128, dstStride[plane]*height); | |
1704 } | |
1705 else | |
1706 { | |
1707 if(dstStride[plane]==srcStride[plane] && srcStride[plane] > 0) | |
1708 memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]); | |
1709 else | |
1710 { | |
1711 int i; | |
1712 uint8_t *srcPtr= src[plane]; | |
1713 uint8_t *dstPtr= dst[plane] + dstStride[plane]*y; | |
1714 for(i=0; i<height; i++) | |
1715 { | |
1716 memcpy(dstPtr, srcPtr, length); | |
1717 srcPtr+= srcStride[plane]; | |
1718 dstPtr+= dstStride[plane]; | |
1719 } | |
1720 } | |
1721 } | |
1722 } | |
1723 } | |
1724 return srcSliceH; | |
1725 } | |
1726 | |
1727 static void getSubSampleFactors(int *h, int *v, int format){ | |
1728 switch(format){ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1729 case PIX_FMT_UYVY422: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1730 case PIX_FMT_YUYV422: |
18861 | 1731 *h=1; |
1732 *v=0; | |
1733 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1734 case PIX_FMT_YUV420P: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1735 case PIX_FMT_GRAY8: //FIXME remove after different subsamplings are fully implemented |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1736 case PIX_FMT_NV12: |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1737 case PIX_FMT_NV21: |
18861 | 1738 *h=1; |
1739 *v=1; | |
1740 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1741 case PIX_FMT_YUV410P: |
18861 | 1742 *h=2; |
1743 *v=2; | |
1744 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1745 case PIX_FMT_YUV444P: |
18861 | 1746 *h=0; |
1747 *v=0; | |
1748 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1749 case PIX_FMT_YUV422P: |
18861 | 1750 *h=1; |
1751 *v=0; | |
1752 break; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1753 case PIX_FMT_YUV411P: |
18861 | 1754 *h=2; |
1755 *v=0; | |
1756 break; | |
1757 default: | |
1758 *h=0; | |
1759 *v=0; | |
1760 break; | |
1761 } | |
1762 } | |
1763 | |
1764 static uint16_t roundToInt16(int64_t f){ | |
1765 int r= (f + (1<<15))>>16; | |
1766 if(r<-0x7FFF) return 0x8000; | |
1767 else if(r> 0x7FFF) return 0x7FFF; | |
1768 else return r; | |
1769 } | |
1770 | |
1771 /** | |
1772 * @param inv_table the yuv2rgb coeffs, normally Inverse_Table_6_9[x] | |
1773 * @param fullRange if 1 then the luma range is 0..255 if 0 its 16..235 | |
1774 * @return -1 if not supported | |
1775 */ | |
1776 int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation){ | |
1777 int64_t crv = inv_table[0]; | |
1778 int64_t cbu = inv_table[1]; | |
1779 int64_t cgu = -inv_table[2]; | |
1780 int64_t cgv = -inv_table[3]; | |
1781 int64_t cy = 1<<16; | |
1782 int64_t oy = 0; | |
1783 | |
1784 if(isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; | |
1785 memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4); | |
1786 memcpy(c->dstColorspaceTable, table, sizeof(int)*4); | |
1787 | |
1788 c->brightness= brightness; | |
1789 c->contrast = contrast; | |
1790 c->saturation= saturation; | |
1791 c->srcRange = srcRange; | |
1792 c->dstRange = dstRange; | |
1793 | |
1794 c->uOffset= 0x0400040004000400LL; | |
1795 c->vOffset= 0x0400040004000400LL; | |
1796 | |
1797 if(!srcRange){ | |
1798 cy= (cy*255) / 219; | |
1799 oy= 16<<16; | |
1800 } | |
1801 | |
1802 cy = (cy *contrast )>>16; | |
1803 crv= (crv*contrast * saturation)>>32; | |
1804 cbu= (cbu*contrast * saturation)>>32; | |
1805 cgu= (cgu*contrast * saturation)>>32; | |
1806 cgv= (cgv*contrast * saturation)>>32; | |
1807 | |
1808 oy -= 256*brightness; | |
1809 | |
1810 c->yCoeff= roundToInt16(cy *8192) * 0x0001000100010001ULL; | |
1811 c->vrCoeff= roundToInt16(crv*8192) * 0x0001000100010001ULL; | |
1812 c->ubCoeff= roundToInt16(cbu*8192) * 0x0001000100010001ULL; | |
1813 c->vgCoeff= roundToInt16(cgv*8192) * 0x0001000100010001ULL; | |
1814 c->ugCoeff= roundToInt16(cgu*8192) * 0x0001000100010001ULL; | |
1815 c->yOffset= roundToInt16(oy * 8) * 0x0001000100010001ULL; | |
1816 | |
1817 yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); | |
1818 //FIXME factorize | |
1819 | |
1820 #ifdef COMPILE_ALTIVEC | |
1821 if (c->flags & SWS_CPU_CAPS_ALTIVEC) | |
1822 yuv2rgb_altivec_init_tables (c, inv_table, brightness, contrast, saturation); | |
1823 #endif | |
1824 return 0; | |
1825 } | |
1826 | |
1827 /** | |
1828 * @return -1 if not supported | |
1829 */ | |
1830 int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation){ | |
1831 if(isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; | |
1832 | |
1833 *inv_table = c->srcColorspaceTable; | |
1834 *table = c->dstColorspaceTable; | |
1835 *srcRange = c->srcRange; | |
1836 *dstRange = c->dstRange; | |
1837 *brightness= c->brightness; | |
1838 *contrast = c->contrast; | |
1839 *saturation= c->saturation; | |
1840 | |
1841 return 0; | |
1842 } | |
1843 | |
19987 | 1844 static int handle_jpeg(int *format) |
1845 { | |
1846 switch (*format) { | |
1847 case PIX_FMT_YUVJ420P: | |
1848 *format = PIX_FMT_YUV420P; | |
1849 return 1; | |
1850 case PIX_FMT_YUVJ422P: | |
1851 *format = PIX_FMT_YUV422P; | |
1852 return 1; | |
1853 case PIX_FMT_YUVJ444P: | |
1854 *format = PIX_FMT_YUV444P; | |
1855 return 1; | |
1856 default: | |
1857 return 0; | |
1858 } | |
1859 } | |
1860 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1861 SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags, |
18861 | 1862 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param){ |
1863 | |
1864 SwsContext *c; | |
1865 int i; | |
1866 int usesVFilter, usesHFilter; | |
1867 int unscaled, needsDither; | |
19987 | 1868 int srcRange, dstRange; |
18861 | 1869 SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; |
1870 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
1871 if(flags & SWS_CPU_CAPS_MMX) | |
1872 asm volatile("emms\n\t"::: "memory"); | |
1873 #endif | |
1874 | |
1875 #ifndef RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off | |
1876 flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC); | |
1877 #ifdef HAVE_MMX2 | |
1878 flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2; | |
1879 #elif defined (HAVE_3DNOW) | |
1880 flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_3DNOW; | |
1881 #elif defined (HAVE_MMX) | |
1882 flags |= SWS_CPU_CAPS_MMX; | |
1883 #elif defined (HAVE_ALTIVEC) | |
1884 flags |= SWS_CPU_CAPS_ALTIVEC; | |
1885 #endif | |
19206 | 1886 #endif /* RUNTIME_CPUDETECT */ |
18861 | 1887 if(clip_table[512] != 255) globalInit(); |
1888 if(rgb15to16 == NULL) sws_rgb2rgb_init(flags); | |
1889 | |
1890 unscaled = (srcW == dstW && srcH == dstH); | |
1891 needsDither= (isBGR(dstFormat) || isRGB(dstFormat)) | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1892 && (fmt_depth(dstFormat))<24 |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1893 && ((fmt_depth(dstFormat))<(fmt_depth(srcFormat)) || (!(isRGB(srcFormat) || isBGR(srcFormat)))); |
18861 | 1894 |
19987 | 1895 srcRange = handle_jpeg(&srcFormat); |
1896 dstRange = handle_jpeg(&dstFormat); | |
1897 | |
18861 | 1898 if(!isSupportedIn(srcFormat)) |
1899 { | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1900 MSG_ERR("swScaler: %s is not supported as input format\n", sws_format_name(srcFormat)); |
18861 | 1901 return NULL; |
1902 } | |
1903 if(!isSupportedOut(dstFormat)) | |
1904 { | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
1905 MSG_ERR("swScaler: %s is not supported as output format\n", sws_format_name(dstFormat)); |
18861 | 1906 return NULL; |
1907 } | |
1908 | |
1909 /* sanity check */ | |
1910 if(srcW<4 || srcH<1 || dstW<8 || dstH<1) //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code | |
1911 { | |
1912 MSG_ERR("swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", | |
1913 srcW, srcH, dstW, dstH); | |
1914 return NULL; | |
1915 } | |
1916 | |
1917 if(!dstFilter) dstFilter= &dummyFilter; | |
1918 if(!srcFilter) srcFilter= &dummyFilter; | |
1919 | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
1920 c= av_malloc(sizeof(SwsContext)); |
18861 | 1921 memset(c, 0, sizeof(SwsContext)); |
1922 | |
1923 c->srcW= srcW; | |
1924 c->srcH= srcH; | |
1925 c->dstW= dstW; | |
1926 c->dstH= dstH; | |
1927 c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW; | |
1928 c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH; | |
1929 c->flags= flags; | |
1930 c->dstFormat= dstFormat; | |
1931 c->srcFormat= srcFormat; | |
1932 c->vRounder= 4* 0x0001000100010001ULL; | |
1933 | |
1934 usesHFilter= usesVFilter= 0; | |
1935 if(dstFilter->lumV!=NULL && dstFilter->lumV->length>1) usesVFilter=1; | |
1936 if(dstFilter->lumH!=NULL && dstFilter->lumH->length>1) usesHFilter=1; | |
1937 if(dstFilter->chrV!=NULL && dstFilter->chrV->length>1) usesVFilter=1; | |
1938 if(dstFilter->chrH!=NULL && dstFilter->chrH->length>1) usesHFilter=1; | |
1939 if(srcFilter->lumV!=NULL && srcFilter->lumV->length>1) usesVFilter=1; | |
1940 if(srcFilter->lumH!=NULL && srcFilter->lumH->length>1) usesHFilter=1; | |
1941 if(srcFilter->chrV!=NULL && srcFilter->chrV->length>1) usesVFilter=1; | |
1942 if(srcFilter->chrH!=NULL && srcFilter->chrH->length>1) usesHFilter=1; | |
1943 | |
1944 getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat); | |
1945 getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat); | |
1946 | |
1947 // reuse chroma for 2 pixles rgb/bgr unless user wants full chroma interpolation | |
1948 if((isBGR(dstFormat) || isRGB(dstFormat)) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1; | |
1949 | |
1950 // drop some chroma lines if the user wants it | |
1951 c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; | |
1952 c->chrSrcVSubSample+= c->vChrDrop; | |
1953 | |
1954 // drop every 2. pixel for chroma calculation unless user wants full chroma | |
1955 if((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP)) | |
1956 c->chrSrcHSubSample=1; | |
1957 | |
1958 if(param){ | |
1959 c->param[0] = param[0]; | |
1960 c->param[1] = param[1]; | |
1961 }else{ | |
1962 c->param[0] = | |
1963 c->param[1] = SWS_PARAM_DEFAULT; | |
1964 } | |
1965 | |
1966 c->chrIntHSubSample= c->chrDstHSubSample; | |
1967 c->chrIntVSubSample= c->chrSrcVSubSample; | |
1968 | |
1969 // note the -((-x)>>y) is so that we allways round toward +inf | |
1970 c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); | |
1971 c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample); | |
1972 c->chrDstW= -((-dstW) >> c->chrDstHSubSample); | |
1973 c->chrDstH= -((-dstH) >> c->chrDstVSubSample); | |
1974 | |
19987 | 1975 sws_setColorspaceDetails(c, Inverse_Table_6_9[SWS_CS_DEFAULT], srcRange, Inverse_Table_6_9[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); |
18861 | 1976 |
1977 /* unscaled special Cases */ | |
1978 if(unscaled && !usesHFilter && !usesVFilter) | |
1979 { | |
1980 /* yv12_to_nv12 */ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1981 if(srcFormat == PIX_FMT_YUV420P && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) |
18861 | 1982 { |
1983 c->swScale= PlanarToNV12Wrapper; | |
1984 } | |
1985 /* yuv2bgr */ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1986 if((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P) && (isBGR(dstFormat) || isRGB(dstFormat))) |
18861 | 1987 { |
1988 c->swScale= yuv2rgb_get_func_ptr(c); | |
1989 } | |
1990 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1991 if( srcFormat==PIX_FMT_YUV410P && dstFormat==PIX_FMT_YUV420P ) |
18861 | 1992 { |
1993 c->swScale= yvu9toyv12Wrapper; | |
1994 } | |
1995 | |
1996 /* bgr24toYV12 */ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
1997 if(srcFormat==PIX_FMT_BGR24 && dstFormat==PIX_FMT_YUV420P) |
18861 | 1998 c->swScale= bgr24toyv12Wrapper; |
1999 | |
2000 /* rgb/bgr -> rgb/bgr (no dither needed forms) */ | |
2001 if( (isBGR(srcFormat) || isRGB(srcFormat)) | |
2002 && (isBGR(dstFormat) || isRGB(dstFormat)) | |
2003 && !needsDither) | |
2004 c->swScale= rgb2rgbWrapper; | |
2005 | |
2006 /* LQ converters if -sws 0 or -sws 4*/ | |
2007 if(c->flags&(SWS_FAST_BILINEAR|SWS_POINT)){ | |
2008 /* rgb/bgr -> rgb/bgr (dither needed forms) */ | |
2009 if( (isBGR(srcFormat) || isRGB(srcFormat)) | |
2010 && (isBGR(dstFormat) || isRGB(dstFormat)) | |
2011 && needsDither) | |
2012 c->swScale= rgb2rgbWrapper; | |
2013 | |
2014 /* yv12_to_yuy2 */ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2015 if(srcFormat == PIX_FMT_YUV420P && |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2016 (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422)) |
18861 | 2017 { |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2018 if (dstFormat == PIX_FMT_YUYV422) |
18861 | 2019 c->swScale= PlanarToYuy2Wrapper; |
2020 else | |
2021 c->swScale= PlanarToUyvyWrapper; | |
2022 } | |
2023 } | |
2024 | |
2025 #ifdef COMPILE_ALTIVEC | |
2026 if ((c->flags & SWS_CPU_CAPS_ALTIVEC) && | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2027 ((srcFormat == PIX_FMT_YUV420P && |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2028 (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422)))) { |
18861 | 2029 // unscaled YV12 -> packed YUV, we want speed |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2030 if (dstFormat == PIX_FMT_YUYV422) |
18861 | 2031 c->swScale= yv12toyuy2_unscaled_altivec; |
2032 else | |
2033 c->swScale= yv12touyvy_unscaled_altivec; | |
2034 } | |
2035 #endif | |
2036 | |
2037 /* simple copy */ | |
2038 if( srcFormat == dstFormat | |
2039 || (isPlanarYUV(srcFormat) && isGray(dstFormat)) | |
2040 || (isPlanarYUV(dstFormat) && isGray(srcFormat)) | |
2041 ) | |
2042 { | |
2043 c->swScale= simpleCopy; | |
2044 } | |
2045 | |
2046 if(c->swScale){ | |
2047 if(flags&SWS_PRINT_INFO) | |
2048 MSG_INFO("SwScaler: using unscaled %s -> %s special converter\n", | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2049 sws_format_name(srcFormat), sws_format_name(dstFormat)); |
18861 | 2050 return c; |
2051 } | |
2052 } | |
2053 | |
2054 if(flags & SWS_CPU_CAPS_MMX2) | |
2055 { | |
2056 c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0; | |
2057 if(!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) | |
2058 { | |
2059 if(flags&SWS_PRINT_INFO) | |
2060 MSG_INFO("SwScaler: output Width is not a multiple of 32 -> no MMX2 scaler\n"); | |
2061 } | |
2062 if(usesHFilter) c->canMMX2BeUsed=0; | |
2063 } | |
2064 else | |
2065 c->canMMX2BeUsed=0; | |
2066 | |
2067 c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; | |
2068 c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; | |
2069 | |
2070 // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst | |
2071 // but only for the FAST_BILINEAR mode otherwise do correct scaling | |
2072 // n-2 is the last chrominance sample available | |
2073 // this is not perfect, but noone shuld notice the difference, the more correct variant | |
2074 // would be like the vertical one, but that would require some special code for the | |
2075 // first and last pixel | |
2076 if(flags&SWS_FAST_BILINEAR) | |
2077 { | |
2078 if(c->canMMX2BeUsed) | |
2079 { | |
2080 c->lumXInc+= 20; | |
2081 c->chrXInc+= 20; | |
2082 } | |
2083 //we don't use the x86asm scaler if mmx is available | |
2084 else if(flags & SWS_CPU_CAPS_MMX) | |
2085 { | |
2086 c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; | |
2087 c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; | |
2088 } | |
2089 } | |
2090 | |
2091 /* precalculate horizontal scaler filter coefficients */ | |
2092 { | |
2093 const int filterAlign= | |
2094 (flags & SWS_CPU_CAPS_MMX) ? 4 : | |
2095 (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : | |
2096 1; | |
2097 | |
2098 initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, | |
2099 srcW , dstW, filterAlign, 1<<14, | |
2100 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, | |
2101 srcFilter->lumH, dstFilter->lumH, c->param); | |
2102 initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, | |
2103 c->chrSrcW, c->chrDstW, filterAlign, 1<<14, | |
2104 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, | |
2105 srcFilter->chrH, dstFilter->chrH, c->param); | |
2106 | |
19333
4f5e2e0529b1
Do not assemble MMX, MMX2 or 3DNOW code unconditionally on X86 and X86_64.
diego
parents:
19270
diff
changeset
|
2107 #define MAX_FUNNY_CODE_SIZE 10000 |
19368
eb51949c73eb
Use COMPILE_MMX2 instead of HAVE_MMX2 to determine whether to compile
uau
parents:
19336
diff
changeset
|
2108 #if defined(COMPILE_MMX2) |
18861 | 2109 // can't downscale !!! |
2110 if(c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) | |
2111 { | |
2112 #ifdef MAP_ANONYMOUS | |
2113 c->funnyYCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); | |
2114 c->funnyUVCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); | |
2115 #else | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2116 c->funnyYCode = av_malloc(MAX_FUNNY_CODE_SIZE); |
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2117 c->funnyUVCode = av_malloc(MAX_FUNNY_CODE_SIZE); |
18861 | 2118 #endif |
2119 | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2120 c->lumMmx2Filter = av_malloc((dstW /8+8)*sizeof(int16_t)); |
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2121 c->chrMmx2Filter = av_malloc((c->chrDstW /4+8)*sizeof(int16_t)); |
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2122 c->lumMmx2FilterPos= av_malloc((dstW /2/8+8)*sizeof(int32_t)); |
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2123 c->chrMmx2FilterPos= av_malloc((c->chrDstW/2/4+8)*sizeof(int32_t)); |
18861 | 2124 |
2125 initMMX2HScaler( dstW, c->lumXInc, c->funnyYCode , c->lumMmx2Filter, c->lumMmx2FilterPos, 8); | |
2126 initMMX2HScaler(c->chrDstW, c->chrXInc, c->funnyUVCode, c->chrMmx2Filter, c->chrMmx2FilterPos, 4); | |
2127 } | |
19368
eb51949c73eb
Use COMPILE_MMX2 instead of HAVE_MMX2 to determine whether to compile
uau
parents:
19336
diff
changeset
|
2128 #endif /* defined(COMPILE_MMX2) */ |
18861 | 2129 } // Init Horizontal stuff |
2130 | |
2131 | |
2132 | |
2133 /* precalculate vertical scaler filter coefficients */ | |
2134 { | |
2135 const int filterAlign= | |
19172
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
2136 (flags & SWS_CPU_CAPS_MMX) && (flags & SWS_ACCURATE_RND) ? 2 : |
18861 | 2137 (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : |
2138 1; | |
2139 | |
2140 initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, | |
2141 srcH , dstH, filterAlign, (1<<12)-4, | |
2142 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, | |
2143 srcFilter->lumV, dstFilter->lumV, c->param); | |
2144 initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, | |
2145 c->chrSrcH, c->chrDstH, filterAlign, (1<<12)-4, | |
2146 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, | |
2147 srcFilter->chrV, dstFilter->chrV, c->param); | |
2148 | |
2149 #ifdef HAVE_ALTIVEC | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2150 c->vYCoeffsBank = av_malloc(sizeof (vector signed short)*c->vLumFilterSize*c->dstH); |
19169
70ea0a8d3b4a
Fix typo introduced in the memalign->av_malloc conversion (there is no
pacman
parents:
19168
diff
changeset
|
2151 c->vCCoeffsBank = av_malloc(sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH); |
18861 | 2152 |
2153 for (i=0;i<c->vLumFilterSize*c->dstH;i++) { | |
2154 int j; | |
2155 short *p = (short *)&c->vYCoeffsBank[i]; | |
2156 for (j=0;j<8;j++) | |
2157 p[j] = c->vLumFilter[i]; | |
2158 } | |
2159 | |
2160 for (i=0;i<c->vChrFilterSize*c->chrDstH;i++) { | |
2161 int j; | |
2162 short *p = (short *)&c->vCCoeffsBank[i]; | |
2163 for (j=0;j<8;j++) | |
2164 p[j] = c->vChrFilter[i]; | |
2165 } | |
2166 #endif | |
2167 } | |
2168 | |
2169 // Calculate Buffer Sizes so that they won't run out while handling these damn slices | |
2170 c->vLumBufSize= c->vLumFilterSize; | |
2171 c->vChrBufSize= c->vChrFilterSize; | |
2172 for(i=0; i<dstH; i++) | |
2173 { | |
2174 int chrI= i*c->chrDstH / dstH; | |
19181 | 2175 int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, |
18861 | 2176 ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample)); |
2177 | |
2178 nextSlice>>= c->chrSrcVSubSample; | |
2179 nextSlice<<= c->chrSrcVSubSample; | |
2180 if(c->vLumFilterPos[i ] + c->vLumBufSize < nextSlice) | |
2181 c->vLumBufSize= nextSlice - c->vLumFilterPos[i ]; | |
2182 if(c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample)) | |
2183 c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI]; | |
2184 } | |
2185 | |
2186 // allocate pixbufs (we use dynamic allocation because otherwise we would need to | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2187 c->lumPixBuf= av_malloc(c->vLumBufSize*2*sizeof(int16_t*)); |
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2188 c->chrPixBuf= av_malloc(c->vChrBufSize*2*sizeof(int16_t*)); |
18861 | 2189 //Note we need at least one pixel more at the end because of the mmx code (just in case someone wanna replace the 4000/8000) |
2190 /* align at 16 bytes for AltiVec */ | |
2191 for(i=0; i<c->vLumBufSize; i++) | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2192 c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= av_malloc(4000); |
18861 | 2193 for(i=0; i<c->vChrBufSize; i++) |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2194 c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= av_malloc(8000); |
18861 | 2195 |
2196 //try to avoid drawing green stuff between the right end and the stride end | |
2197 for(i=0; i<c->vLumBufSize; i++) memset(c->lumPixBuf[i], 0, 4000); | |
2198 for(i=0; i<c->vChrBufSize; i++) memset(c->chrPixBuf[i], 64, 8000); | |
2199 | |
2200 ASSERT(c->chrDstH <= dstH) | |
2201 | |
2202 if(flags&SWS_PRINT_INFO) | |
2203 { | |
2204 #ifdef DITHER1XBPP | |
2205 char *dither= " dithered"; | |
2206 #else | |
2207 char *dither= ""; | |
2208 #endif | |
2209 if(flags&SWS_FAST_BILINEAR) | |
2210 MSG_INFO("\nSwScaler: FAST_BILINEAR scaler, "); | |
2211 else if(flags&SWS_BILINEAR) | |
2212 MSG_INFO("\nSwScaler: BILINEAR scaler, "); | |
2213 else if(flags&SWS_BICUBIC) | |
2214 MSG_INFO("\nSwScaler: BICUBIC scaler, "); | |
2215 else if(flags&SWS_X) | |
2216 MSG_INFO("\nSwScaler: Experimental scaler, "); | |
2217 else if(flags&SWS_POINT) | |
2218 MSG_INFO("\nSwScaler: Nearest Neighbor / POINT scaler, "); | |
2219 else if(flags&SWS_AREA) | |
2220 MSG_INFO("\nSwScaler: Area Averageing scaler, "); | |
2221 else if(flags&SWS_BICUBLIN) | |
2222 MSG_INFO("\nSwScaler: luma BICUBIC / chroma BILINEAR scaler, "); | |
2223 else if(flags&SWS_GAUSS) | |
2224 MSG_INFO("\nSwScaler: Gaussian scaler, "); | |
2225 else if(flags&SWS_SINC) | |
2226 MSG_INFO("\nSwScaler: Sinc scaler, "); | |
2227 else if(flags&SWS_LANCZOS) | |
2228 MSG_INFO("\nSwScaler: Lanczos scaler, "); | |
2229 else if(flags&SWS_SPLINE) | |
2230 MSG_INFO("\nSwScaler: Bicubic spline scaler, "); | |
2231 else | |
2232 MSG_INFO("\nSwScaler: ehh flags invalid?! "); | |
2233 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2234 if(dstFormat==PIX_FMT_BGR555 || dstFormat==PIX_FMT_BGR565) |
18861 | 2235 MSG_INFO("from %s to%s %s ", |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2236 sws_format_name(srcFormat), dither, sws_format_name(dstFormat)); |
18861 | 2237 else |
2238 MSG_INFO("from %s to %s ", | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2239 sws_format_name(srcFormat), sws_format_name(dstFormat)); |
18861 | 2240 |
2241 if(flags & SWS_CPU_CAPS_MMX2) | |
2242 MSG_INFO("using MMX2\n"); | |
2243 else if(flags & SWS_CPU_CAPS_3DNOW) | |
2244 MSG_INFO("using 3DNOW\n"); | |
2245 else if(flags & SWS_CPU_CAPS_MMX) | |
2246 MSG_INFO("using MMX\n"); | |
2247 else if(flags & SWS_CPU_CAPS_ALTIVEC) | |
2248 MSG_INFO("using AltiVec\n"); | |
2249 else | |
2250 MSG_INFO("using C\n"); | |
2251 } | |
2252 | |
2253 if(flags & SWS_PRINT_INFO) | |
2254 { | |
2255 if(flags & SWS_CPU_CAPS_MMX) | |
2256 { | |
2257 if(c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) | |
2258 MSG_V("SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); | |
2259 else | |
2260 { | |
2261 if(c->hLumFilterSize==4) | |
2262 MSG_V("SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n"); | |
2263 else if(c->hLumFilterSize==8) | |
2264 MSG_V("SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n"); | |
2265 else | |
2266 MSG_V("SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n"); | |
2267 | |
2268 if(c->hChrFilterSize==4) | |
2269 MSG_V("SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n"); | |
2270 else if(c->hChrFilterSize==8) | |
2271 MSG_V("SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n"); | |
2272 else | |
2273 MSG_V("SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n"); | |
2274 } | |
2275 } | |
2276 else | |
2277 { | |
2278 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
2279 MSG_V("SwScaler: using X86-Asm scaler for horizontal scaling\n"); | |
2280 #else | |
2281 if(flags & SWS_FAST_BILINEAR) | |
2282 MSG_V("SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n"); | |
2283 else | |
2284 MSG_V("SwScaler: using C scaler for horizontal scaling\n"); | |
2285 #endif | |
2286 } | |
2287 if(isPlanarYUV(dstFormat)) | |
2288 { | |
2289 if(c->vLumFilterSize==1) | |
2290 MSG_V("SwScaler: using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); | |
2291 else | |
2292 MSG_V("SwScaler: using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); | |
2293 } | |
2294 else | |
2295 { | |
2296 if(c->vLumFilterSize==1 && c->vChrFilterSize==2) | |
2297 MSG_V("SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" | |
2298 "SwScaler: 2-tap scaler for vertical chrominance scaling (BGR)\n",(flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); | |
2299 else if(c->vLumFilterSize==2 && c->vChrFilterSize==2) | |
2300 MSG_V("SwScaler: using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); | |
2301 else | |
2302 MSG_V("SwScaler: using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); | |
2303 } | |
2304 | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2305 if(dstFormat==PIX_FMT_BGR24) |
18861 | 2306 MSG_V("SwScaler: using %s YV12->BGR24 Converter\n", |
2307 (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2308 else if(dstFormat==PIX_FMT_RGB32) |
18861 | 2309 MSG_V("SwScaler: using %s YV12->BGR32 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2310 else if(dstFormat==PIX_FMT_BGR565) |
18861 | 2311 MSG_V("SwScaler: using %s YV12->BGR16 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2312 else if(dstFormat==PIX_FMT_BGR555) |
18861 | 2313 MSG_V("SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
2314 | |
2315 MSG_V("SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); | |
2316 } | |
2317 if(flags & SWS_PRINT_INFO) | |
2318 { | |
2319 MSG_DBG2("SwScaler:Lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", | |
2320 c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); | |
2321 MSG_DBG2("SwScaler:Chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", | |
2322 c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); | |
2323 } | |
2324 | |
2325 c->swScale= getSwsFunc(flags); | |
2326 return c; | |
2327 } | |
2328 | |
2329 /** | |
2330 * swscale warper, so we don't need to export the SwsContext. | |
2331 * assumes planar YUV to be in YUV order instead of YVU | |
2332 */ | |
2333 int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
2334 int srcSliceH, uint8_t* dst[], int dstStride[]){ | |
2335 if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { | |
2336 MSG_ERR("swScaler: slices start in the middle!\n"); | |
2337 return 0; | |
2338 } | |
2339 if (c->sliceDir == 0) { | |
2340 if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; | |
2341 } | |
2342 | |
2343 // copy strides, so they can safely be modified | |
2344 if (c->sliceDir == 1) { | |
2345 // slices go from top to bottom | |
2346 int srcStride2[3]= {srcStride[0], srcStride[1], srcStride[2]}; | |
2347 int dstStride2[3]= {dstStride[0], dstStride[1], dstStride[2]}; | |
2348 return c->swScale(c, src, srcStride2, srcSliceY, srcSliceH, dst, dstStride2); | |
2349 } else { | |
2350 // slices go from bottom to top => we flip the image internally | |
2351 uint8_t* src2[3]= {src[0] + (srcSliceH-1)*srcStride[0], | |
2352 src[1] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1], | |
2353 src[2] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2] | |
2354 }; | |
2355 uint8_t* dst2[3]= {dst[0] + (c->dstH-1)*dstStride[0], | |
2356 dst[1] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1], | |
2357 dst[2] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]}; | |
2358 int srcStride2[3]= {-srcStride[0], -srcStride[1], -srcStride[2]}; | |
2359 int dstStride2[3]= {-dstStride[0], -dstStride[1], -dstStride[2]}; | |
2360 | |
2361 return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); | |
2362 } | |
2363 } | |
2364 | |
2365 /** | |
2366 * swscale warper, so we don't need to export the SwsContext | |
2367 */ | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2368 int sws_scale(SwsContext *c, uint8_t* srcParam[], int srcStride[], int srcSliceY, |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2369 int srcSliceH, uint8_t* dstParam[], int dstStride[]){ |
18861 | 2370 uint8_t *src[3]; |
2371 uint8_t *dst[3]; | |
19872
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2372 src[0] = srcParam[0]; src[1] = srcParam[1]; src[2] = srcParam[2]; |
8e50cba9fe03
Remove the dependency of libswscale on img_format.h
lucabe
parents:
19869
diff
changeset
|
2373 dst[0] = dstParam[0]; dst[1] = dstParam[1]; dst[2] = dstParam[2]; |
18861 | 2374 //printf("sws: slice %d %d\n", srcSliceY, srcSliceH); |
2375 | |
2376 return c->swScale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); | |
2377 } | |
2378 | |
2379 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, | |
2380 float lumaSharpen, float chromaSharpen, | |
2381 float chromaHShift, float chromaVShift, | |
2382 int verbose) | |
2383 { | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2384 SwsFilter *filter= av_malloc(sizeof(SwsFilter)); |
18861 | 2385 |
2386 if(lumaGBlur!=0.0){ | |
2387 filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0); | |
2388 filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0); | |
2389 }else{ | |
2390 filter->lumH= sws_getIdentityVec(); | |
2391 filter->lumV= sws_getIdentityVec(); | |
2392 } | |
2393 | |
2394 if(chromaGBlur!=0.0){ | |
2395 filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0); | |
2396 filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0); | |
2397 }else{ | |
2398 filter->chrH= sws_getIdentityVec(); | |
2399 filter->chrV= sws_getIdentityVec(); | |
2400 } | |
2401 | |
2402 if(chromaSharpen!=0.0){ | |
2403 SwsVector *id= sws_getIdentityVec(); | |
2404 sws_scaleVec(filter->chrH, -chromaSharpen); | |
2405 sws_scaleVec(filter->chrV, -chromaSharpen); | |
2406 sws_addVec(filter->chrH, id); | |
2407 sws_addVec(filter->chrV, id); | |
2408 sws_freeVec(id); | |
2409 } | |
2410 | |
2411 if(lumaSharpen!=0.0){ | |
2412 SwsVector *id= sws_getIdentityVec(); | |
2413 sws_scaleVec(filter->lumH, -lumaSharpen); | |
2414 sws_scaleVec(filter->lumV, -lumaSharpen); | |
2415 sws_addVec(filter->lumH, id); | |
2416 sws_addVec(filter->lumV, id); | |
2417 sws_freeVec(id); | |
2418 } | |
2419 | |
2420 if(chromaHShift != 0.0) | |
2421 sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5)); | |
2422 | |
2423 if(chromaVShift != 0.0) | |
2424 sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5)); | |
2425 | |
2426 sws_normalizeVec(filter->chrH, 1.0); | |
2427 sws_normalizeVec(filter->chrV, 1.0); | |
2428 sws_normalizeVec(filter->lumH, 1.0); | |
2429 sws_normalizeVec(filter->lumV, 1.0); | |
2430 | |
2431 if(verbose) sws_printVec(filter->chrH); | |
2432 if(verbose) sws_printVec(filter->lumH); | |
2433 | |
2434 return filter; | |
2435 } | |
2436 | |
2437 /** | |
2438 * returns a normalized gaussian curve used to filter stuff | |
2439 * quality=3 is high quality, lowwer is lowwer quality | |
2440 */ | |
2441 SwsVector *sws_getGaussianVec(double variance, double quality){ | |
2442 const int length= (int)(variance*quality + 0.5) | 1; | |
2443 int i; | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2444 double *coeff= av_malloc(length*sizeof(double)); |
18861 | 2445 double middle= (length-1)*0.5; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2446 SwsVector *vec= av_malloc(sizeof(SwsVector)); |
18861 | 2447 |
2448 vec->coeff= coeff; | |
2449 vec->length= length; | |
2450 | |
2451 for(i=0; i<length; i++) | |
2452 { | |
2453 double dist= i-middle; | |
2454 coeff[i]= exp( -dist*dist/(2*variance*variance) ) / sqrt(2*variance*PI); | |
2455 } | |
2456 | |
2457 sws_normalizeVec(vec, 1.0); | |
2458 | |
2459 return vec; | |
2460 } | |
2461 | |
2462 SwsVector *sws_getConstVec(double c, int length){ | |
2463 int i; | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2464 double *coeff= av_malloc(length*sizeof(double)); |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2465 SwsVector *vec= av_malloc(sizeof(SwsVector)); |
18861 | 2466 |
2467 vec->coeff= coeff; | |
2468 vec->length= length; | |
2469 | |
2470 for(i=0; i<length; i++) | |
2471 coeff[i]= c; | |
2472 | |
2473 return vec; | |
2474 } | |
2475 | |
2476 | |
2477 SwsVector *sws_getIdentityVec(void){ | |
2478 return sws_getConstVec(1.0, 1); | |
2479 } | |
2480 | |
2481 double sws_dcVec(SwsVector *a){ | |
2482 int i; | |
2483 double sum=0; | |
2484 | |
2485 for(i=0; i<a->length; i++) | |
2486 sum+= a->coeff[i]; | |
2487 | |
2488 return sum; | |
2489 } | |
2490 | |
2491 void sws_scaleVec(SwsVector *a, double scalar){ | |
2492 int i; | |
2493 | |
2494 for(i=0; i<a->length; i++) | |
2495 a->coeff[i]*= scalar; | |
2496 } | |
2497 | |
2498 void sws_normalizeVec(SwsVector *a, double height){ | |
2499 sws_scaleVec(a, height/sws_dcVec(a)); | |
2500 } | |
2501 | |
2502 static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b){ | |
2503 int length= a->length + b->length - 1; | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2504 double *coeff= av_malloc(length*sizeof(double)); |
18861 | 2505 int i, j; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2506 SwsVector *vec= av_malloc(sizeof(SwsVector)); |
18861 | 2507 |
2508 vec->coeff= coeff; | |
2509 vec->length= length; | |
2510 | |
2511 for(i=0; i<length; i++) coeff[i]= 0.0; | |
2512 | |
2513 for(i=0; i<a->length; i++) | |
2514 { | |
2515 for(j=0; j<b->length; j++) | |
2516 { | |
2517 coeff[i+j]+= a->coeff[i]*b->coeff[j]; | |
2518 } | |
2519 } | |
2520 | |
2521 return vec; | |
2522 } | |
2523 | |
2524 static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b){ | |
19181 | 2525 int length= FFMAX(a->length, b->length); |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2526 double *coeff= av_malloc(length*sizeof(double)); |
18861 | 2527 int i; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2528 SwsVector *vec= av_malloc(sizeof(SwsVector)); |
18861 | 2529 |
2530 vec->coeff= coeff; | |
2531 vec->length= length; | |
2532 | |
2533 for(i=0; i<length; i++) coeff[i]= 0.0; | |
2534 | |
2535 for(i=0; i<a->length; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; | |
2536 for(i=0; i<b->length; i++) coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i]; | |
2537 | |
2538 return vec; | |
2539 } | |
2540 | |
2541 static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b){ | |
19181 | 2542 int length= FFMAX(a->length, b->length); |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2543 double *coeff= av_malloc(length*sizeof(double)); |
18861 | 2544 int i; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2545 SwsVector *vec= av_malloc(sizeof(SwsVector)); |
18861 | 2546 |
2547 vec->coeff= coeff; | |
2548 vec->length= length; | |
2549 | |
2550 for(i=0; i<length; i++) coeff[i]= 0.0; | |
2551 | |
2552 for(i=0; i<a->length; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; | |
2553 for(i=0; i<b->length; i++) coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i]; | |
2554 | |
2555 return vec; | |
2556 } | |
2557 | |
2558 /* shift left / or right if "shift" is negative */ | |
2559 static SwsVector *sws_getShiftedVec(SwsVector *a, int shift){ | |
2560 int length= a->length + ABS(shift)*2; | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2561 double *coeff= av_malloc(length*sizeof(double)); |
18861 | 2562 int i; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2563 SwsVector *vec= av_malloc(sizeof(SwsVector)); |
18861 | 2564 |
2565 vec->coeff= coeff; | |
2566 vec->length= length; | |
2567 | |
2568 for(i=0; i<length; i++) coeff[i]= 0.0; | |
2569 | |
2570 for(i=0; i<a->length; i++) | |
2571 { | |
2572 coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i]; | |
2573 } | |
2574 | |
2575 return vec; | |
2576 } | |
2577 | |
2578 void sws_shiftVec(SwsVector *a, int shift){ | |
2579 SwsVector *shifted= sws_getShiftedVec(a, shift); | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2580 av_free(a->coeff); |
18861 | 2581 a->coeff= shifted->coeff; |
2582 a->length= shifted->length; | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2583 av_free(shifted); |
18861 | 2584 } |
2585 | |
2586 void sws_addVec(SwsVector *a, SwsVector *b){ | |
2587 SwsVector *sum= sws_sumVec(a, b); | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2588 av_free(a->coeff); |
18861 | 2589 a->coeff= sum->coeff; |
2590 a->length= sum->length; | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2591 av_free(sum); |
18861 | 2592 } |
2593 | |
2594 void sws_subVec(SwsVector *a, SwsVector *b){ | |
2595 SwsVector *diff= sws_diffVec(a, b); | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2596 av_free(a->coeff); |
18861 | 2597 a->coeff= diff->coeff; |
2598 a->length= diff->length; | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2599 av_free(diff); |
18861 | 2600 } |
2601 | |
2602 void sws_convVec(SwsVector *a, SwsVector *b){ | |
2603 SwsVector *conv= sws_getConvVec(a, b); | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2604 av_free(a->coeff); |
18861 | 2605 a->coeff= conv->coeff; |
2606 a->length= conv->length; | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2607 av_free(conv); |
18861 | 2608 } |
2609 | |
2610 SwsVector *sws_cloneVec(SwsVector *a){ | |
19168
624173ae90b9
Missing part of the malloc -> av_malloc patch: memalign must be replaced as well!
reimar
parents:
19143
diff
changeset
|
2611 double *coeff= av_malloc(a->length*sizeof(double)); |
18861 | 2612 int i; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2613 SwsVector *vec= av_malloc(sizeof(SwsVector)); |
18861 | 2614 |
2615 vec->coeff= coeff; | |
2616 vec->length= a->length; | |
2617 | |
2618 for(i=0; i<a->length; i++) coeff[i]= a->coeff[i]; | |
2619 | |
2620 return vec; | |
2621 } | |
2622 | |
2623 void sws_printVec(SwsVector *a){ | |
2624 int i; | |
2625 double max=0; | |
2626 double min=0; | |
2627 double range; | |
2628 | |
2629 for(i=0; i<a->length; i++) | |
2630 if(a->coeff[i]>max) max= a->coeff[i]; | |
2631 | |
2632 for(i=0; i<a->length; i++) | |
2633 if(a->coeff[i]<min) min= a->coeff[i]; | |
2634 | |
2635 range= max - min; | |
2636 | |
2637 for(i=0; i<a->length; i++) | |
2638 { | |
2639 int x= (int)((a->coeff[i]-min)*60.0/range +0.5); | |
2640 MSG_DBG2("%1.3f ", a->coeff[i]); | |
2641 for(;x>0; x--) MSG_DBG2(" "); | |
2642 MSG_DBG2("|\n"); | |
2643 } | |
2644 } | |
2645 | |
2646 void sws_freeVec(SwsVector *a){ | |
2647 if(!a) return; | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2648 av_free(a->coeff); |
18861 | 2649 a->coeff=NULL; |
2650 a->length=0; | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2651 av_free(a); |
18861 | 2652 } |
2653 | |
2654 void sws_freeFilter(SwsFilter *filter){ | |
2655 if(!filter) return; | |
2656 | |
2657 if(filter->lumH) sws_freeVec(filter->lumH); | |
2658 if(filter->lumV) sws_freeVec(filter->lumV); | |
2659 if(filter->chrH) sws_freeVec(filter->chrH); | |
2660 if(filter->chrV) sws_freeVec(filter->chrV); | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2661 av_free(filter); |
18861 | 2662 } |
2663 | |
2664 | |
2665 void sws_freeContext(SwsContext *c){ | |
2666 int i; | |
2667 if(!c) return; | |
2668 | |
2669 if(c->lumPixBuf) | |
2670 { | |
2671 for(i=0; i<c->vLumBufSize; i++) | |
2672 { | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2673 av_free(c->lumPixBuf[i]); |
18861 | 2674 c->lumPixBuf[i]=NULL; |
2675 } | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2676 av_free(c->lumPixBuf); |
18861 | 2677 c->lumPixBuf=NULL; |
2678 } | |
2679 | |
2680 if(c->chrPixBuf) | |
2681 { | |
2682 for(i=0; i<c->vChrBufSize; i++) | |
2683 { | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2684 av_free(c->chrPixBuf[i]); |
18861 | 2685 c->chrPixBuf[i]=NULL; |
2686 } | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2687 av_free(c->chrPixBuf); |
18861 | 2688 c->chrPixBuf=NULL; |
2689 } | |
2690 | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2691 av_free(c->vLumFilter); |
18861 | 2692 c->vLumFilter = NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2693 av_free(c->vChrFilter); |
18861 | 2694 c->vChrFilter = NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2695 av_free(c->hLumFilter); |
18861 | 2696 c->hLumFilter = NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2697 av_free(c->hChrFilter); |
18861 | 2698 c->hChrFilter = NULL; |
2699 #ifdef HAVE_ALTIVEC | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2700 av_free(c->vYCoeffsBank); |
18861 | 2701 c->vYCoeffsBank = NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2702 av_free(c->vCCoeffsBank); |
18861 | 2703 c->vCCoeffsBank = NULL; |
2704 #endif | |
2705 | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2706 av_free(c->vLumFilterPos); |
18861 | 2707 c->vLumFilterPos = NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2708 av_free(c->vChrFilterPos); |
18861 | 2709 c->vChrFilterPos = NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2710 av_free(c->hLumFilterPos); |
18861 | 2711 c->hLumFilterPos = NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2712 av_free(c->hChrFilterPos); |
18861 | 2713 c->hChrFilterPos = NULL; |
2714 | |
2715 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
2716 #ifdef MAP_ANONYMOUS | |
2717 if(c->funnyYCode) munmap(c->funnyYCode, MAX_FUNNY_CODE_SIZE); | |
2718 if(c->funnyUVCode) munmap(c->funnyUVCode, MAX_FUNNY_CODE_SIZE); | |
2719 #else | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2720 av_free(c->funnyYCode); |
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2721 av_free(c->funnyUVCode); |
18861 | 2722 #endif |
2723 c->funnyYCode=NULL; | |
2724 c->funnyUVCode=NULL; | |
19206 | 2725 #endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */ |
18861 | 2726 |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2727 av_free(c->lumMmx2Filter); |
18861 | 2728 c->lumMmx2Filter=NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2729 av_free(c->chrMmx2Filter); |
18861 | 2730 c->chrMmx2Filter=NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2731 av_free(c->lumMmx2FilterPos); |
18861 | 2732 c->lumMmx2FilterPos=NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2733 av_free(c->chrMmx2FilterPos); |
18861 | 2734 c->chrMmx2FilterPos=NULL; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2735 av_free(c->yuvTable); |
18861 | 2736 c->yuvTable=NULL; |
2737 | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
2738 av_free(c); |
18861 | 2739 } |
2740 | |
19661
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2741 /** |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2742 * Checks if context is valid or reallocs a new one instead. |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2743 * If context is NULL, just calls sws_getContext() to get a new one. |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2744 * Otherwise, checks if the parameters are the same already saved in context. |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2745 * If that is the case, returns the current context. |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2746 * Otherwise, frees context and gets a new one. |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2747 * |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2748 * Be warned that srcFilter, dstFilter are not checked, they are |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2749 * asumed to remain valid. |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2750 */ |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2751 struct SwsContext *sws_getCachedContext(struct SwsContext *context, |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2752 int srcW, int srcH, int srcFormat, |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2753 int dstW, int dstH, int dstFormat, int flags, |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2754 SwsFilter *srcFilter, SwsFilter *dstFilter, double *param) |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2755 { |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2756 if (context != NULL) { |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2757 if ((context->srcW != srcW) || (context->srcH != srcH) || |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2758 (context->srcFormat != srcFormat) || |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2759 (context->dstW != dstW) || (context->dstH != dstH) || |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2760 (context->dstFormat != dstFormat) || (context->flags != flags) || |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2761 (context->param != param)) |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2762 { |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2763 sws_freeContext(context); |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2764 context = NULL; |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2765 } |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2766 } |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2767 if (context == NULL) { |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2768 return sws_getContext(srcW, srcH, srcFormat, |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2769 dstW, dstH, dstFormat, flags, |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2770 srcFilter, dstFilter, param); |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2771 } |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2772 return context; |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2773 } |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
2774 |