Mercurial > mplayer.hg
annotate libswscale/utils.c @ 32163:51622e94f85a
cosmetics: Replace some double quotes by single quotes for consistency.
author | diego |
---|---|
date | Tue, 14 Sep 2010 17:08:54 +0000 |
parents | 5c9310a4d2e9 |
children | c475ed274718 |
rev | line source |
---|---|
18861 | 1 /* |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
2 * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at> |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
3 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
4 * This file is part of FFmpeg. |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
5 * |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
10 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
14 * Lesser General Public License for more details. |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
15 * |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
23702 | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19987
diff
changeset
|
19 */ |
18861 | 20 |
27511 | 21 #define _SVID_SOURCE //needed for MAP_ANONYMOUS |
31694
e251996735b5
darwin: allow 64-bit darwin to allocate executable memory
ramiro
parents:
31234
diff
changeset
|
22 #define _DARWIN_C_SOURCE // needed for MAP_ANON |
18861 | 23 #include <inttypes.h> |
24 #include <string.h> | |
25 #include <math.h> | |
26 #include <stdio.h> | |
27 #include "config.h" | |
28 #include <assert.h> | |
28276 | 29 #if HAVE_SYS_MMAN_H |
18861 | 30 #include <sys/mman.h> |
31 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) | |
32 #define MAP_ANONYMOUS MAP_ANON | |
33 #endif | |
34 #endif | |
28971
b8e356a9dbb1
Allocate executable memory with VirtualAlloc() in Windows.
ramiro
parents:
28970
diff
changeset
|
35 #if HAVE_VIRTUALALLOC |
b8e356a9dbb1
Allocate executable memory with VirtualAlloc() in Windows.
ramiro
parents:
28970
diff
changeset
|
36 #define WIN32_LEAN_AND_MEAN |
b8e356a9dbb1
Allocate executable memory with VirtualAlloc() in Windows.
ramiro
parents:
28970
diff
changeset
|
37 #include <windows.h> |
b8e356a9dbb1
Allocate executable memory with VirtualAlloc() in Windows.
ramiro
parents:
28970
diff
changeset
|
38 #endif |
18861 | 39 #include "swscale.h" |
40 #include "swscale_internal.h" | |
41 #include "rgb2rgb.h" | |
29475 | 42 #include "libavutil/intreadwrite.h" |
26670
e6774798e913
Use full path for #includes from another directory.
diego
parents:
26238
diff
changeset
|
43 #include "libavutil/x86_cpu.h" |
29542 | 44 #include "libavutil/avutil.h" |
26670
e6774798e913
Use full path for #includes from another directory.
diego
parents:
26238
diff
changeset
|
45 #include "libavutil/bswap.h" |
29926
916134a82d74
Make sws_format_name() use av_pix_fmt_descriptors.
stefano
parents:
29890
diff
changeset
|
46 #include "libavutil/pixdesc.h" |
18861 | 47 |
27460 | 48 unsigned swscale_version(void) |
49 { | |
50 return LIBSWSCALE_VERSION_INT; | |
51 } | |
52 | |
30138 | 53 const char *swscale_configuration(void) |
29890
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
54 { |
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
55 return FFMPEG_CONFIGURATION; |
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
56 } |
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
57 |
30138 | 58 const char *swscale_license(void) |
29890
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
59 { |
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
60 #define LICENSE_PREFIX "libswscale license: " |
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
61 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; |
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
62 } |
e8e1f8cc7c5b
Add functions to return library license and library configuration.
diego
parents:
29843
diff
changeset
|
63 |
28316 | 64 #define RET 0xC3 //near return opcode for x86 |
18861 | 65 |
23278 | 66 #define isSupportedIn(x) ( \ |
67 (x)==PIX_FMT_YUV420P \ | |
24581
a7fe1ee84511
add support for yuva420p colorspace (yuv420p + alpha)
aurel
parents:
24289
diff
changeset
|
68 || (x)==PIX_FMT_YUVA420P \ |
23278 | 69 || (x)==PIX_FMT_YUYV422 \ |
70 || (x)==PIX_FMT_UYVY422 \ | |
29299
24954ec81529
Partial (low bits ignored, no direct transcoding into other RGB formats) support
kostya
parents:
29278
diff
changeset
|
71 || (x)==PIX_FMT_RGB48BE \ |
24954ec81529
Partial (low bits ignored, no direct transcoding into other RGB formats) support
kostya
parents:
29278
diff
changeset
|
72 || (x)==PIX_FMT_RGB48LE \ |
23278 | 73 || (x)==PIX_FMT_RGB32 \ |
27490 | 74 || (x)==PIX_FMT_RGB32_1 \ |
23278 | 75 || (x)==PIX_FMT_BGR24 \ |
76 || (x)==PIX_FMT_BGR565 \ | |
77 || (x)==PIX_FMT_BGR555 \ | |
78 || (x)==PIX_FMT_BGR32 \ | |
27490 | 79 || (x)==PIX_FMT_BGR32_1 \ |
23278 | 80 || (x)==PIX_FMT_RGB24 \ |
81 || (x)==PIX_FMT_RGB565 \ | |
82 || (x)==PIX_FMT_RGB555 \ | |
83 || (x)==PIX_FMT_GRAY8 \ | |
84 || (x)==PIX_FMT_YUV410P \ | |
27557 | 85 || (x)==PIX_FMT_YUV440P \ |
29932 | 86 || (x)==PIX_FMT_NV12 \ |
87 || (x)==PIX_FMT_NV21 \ | |
23278 | 88 || (x)==PIX_FMT_GRAY16BE \ |
89 || (x)==PIX_FMT_GRAY16LE \ | |
90 || (x)==PIX_FMT_YUV444P \ | |
91 || (x)==PIX_FMT_YUV422P \ | |
92 || (x)==PIX_FMT_YUV411P \ | |
30432 | 93 || (x)==PIX_FMT_YUVJ420P \ |
94 || (x)==PIX_FMT_YUVJ422P \ | |
95 || (x)==PIX_FMT_YUVJ440P \ | |
96 || (x)==PIX_FMT_YUVJ444P \ | |
23278 | 97 || (x)==PIX_FMT_PAL8 \ |
98 || (x)==PIX_FMT_BGR8 \ | |
99 || (x)==PIX_FMT_RGB8 \ | |
100 || (x)==PIX_FMT_BGR4_BYTE \ | |
101 || (x)==PIX_FMT_RGB4_BYTE \ | |
23791 | 102 || (x)==PIX_FMT_YUV440P \ |
27555 | 103 || (x)==PIX_FMT_MONOWHITE \ |
104 || (x)==PIX_FMT_MONOBLACK \ | |
29608
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
105 || (x)==PIX_FMT_YUV420P16LE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
106 || (x)==PIX_FMT_YUV422P16LE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
107 || (x)==PIX_FMT_YUV444P16LE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
108 || (x)==PIX_FMT_YUV420P16BE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
109 || (x)==PIX_FMT_YUV422P16BE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
110 || (x)==PIX_FMT_YUV444P16BE \ |
23278 | 111 ) |
30194
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
112 |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
113 int sws_isSupportedInput(enum PixelFormat pix_fmt) |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
114 { |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
115 return isSupportedIn(pix_fmt); |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
116 } |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
117 |
23278 | 118 #define isSupportedOut(x) ( \ |
119 (x)==PIX_FMT_YUV420P \ | |
28977 | 120 || (x)==PIX_FMT_YUVA420P \ |
23278 | 121 || (x)==PIX_FMT_YUYV422 \ |
122 || (x)==PIX_FMT_UYVY422 \ | |
123 || (x)==PIX_FMT_YUV444P \ | |
124 || (x)==PIX_FMT_YUV422P \ | |
125 || (x)==PIX_FMT_YUV411P \ | |
30432 | 126 || (x)==PIX_FMT_YUVJ420P \ |
127 || (x)==PIX_FMT_YUVJ422P \ | |
128 || (x)==PIX_FMT_YUVJ440P \ | |
129 || (x)==PIX_FMT_YUVJ444P \ | |
30393 | 130 || isAnyRGB(x) \ |
23278 | 131 || (x)==PIX_FMT_NV12 \ |
132 || (x)==PIX_FMT_NV21 \ | |
133 || (x)==PIX_FMT_GRAY16BE \ | |
134 || (x)==PIX_FMT_GRAY16LE \ | |
135 || (x)==PIX_FMT_GRAY8 \ | |
136 || (x)==PIX_FMT_YUV410P \ | |
27557 | 137 || (x)==PIX_FMT_YUV440P \ |
29608
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
138 || (x)==PIX_FMT_YUV420P16LE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
139 || (x)==PIX_FMT_YUV422P16LE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
140 || (x)==PIX_FMT_YUV444P16LE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
141 || (x)==PIX_FMT_YUV420P16BE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
142 || (x)==PIX_FMT_YUV422P16BE \ |
ff34398b14b1
Make 16bit YUV formats compatible with NE avcodec_get_pix_fmt().
ramiro
parents:
29545
diff
changeset
|
143 || (x)==PIX_FMT_YUV444P16BE \ |
23278 | 144 ) |
30194
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
145 |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
146 int sws_isSupportedOutput(enum PixelFormat pix_fmt) |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
147 { |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
148 return isSupportedOut(pix_fmt); |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
149 } |
bd9db1814611
Implement sws_isSupportedInput() and sws_isSupportedOutput().
stefano
parents:
30142
diff
changeset
|
150 |
28460 | 151 extern const int32_t ff_yuv2rgb_coeffs[8][4]; |
18861 | 152 |
26151
5884743208b6
change sws_format_name to return const char*, supress many warnings
bcoudurier
parents:
26150
diff
changeset
|
153 const 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
|
154 { |
29926
916134a82d74
Make sws_format_name() use av_pix_fmt_descriptors.
stefano
parents:
29890
diff
changeset
|
155 if ((unsigned)format < PIX_FMT_NB && av_pix_fmt_descriptors[format].name) |
916134a82d74
Make sws_format_name() use av_pix_fmt_descriptors.
stefano
parents:
29890
diff
changeset
|
156 return av_pix_fmt_descriptors[format].name; |
916134a82d74
Make sws_format_name() use av_pix_fmt_descriptors.
stefano
parents:
29890
diff
changeset
|
157 else |
29480 | 158 return "Unknown format"; |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
159 } |
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
160 |
18861 | 161 static double getSplineCoeff(double a, double b, double c, double d, double dist) |
162 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
163 // printf("%f %f %f %f %f\n", a,b,c,d,dist); |
29480 | 164 if (dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; |
165 else return getSplineCoeff( 0.0, | |
166 b+ 2.0*c + 3.0*d, | |
167 c + 3.0*d, | |
168 -b- 3.0*c - 6.0*d, | |
169 dist-1.0); | |
18861 | 170 } |
171 | |
30307 | 172 static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, |
30308 | 173 int srcW, int dstW, int filterAlign, int one, int flags, |
174 SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) | |
18861 | 175 { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
176 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
177 int filterSize; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
178 int filter2Size; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
179 int minFilterSize; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
180 int64_t *filter=NULL; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
181 int64_t *filter2=NULL; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
182 const int64_t fone= 1LL<<54; |
27300 | 183 int ret= -1; |
28276 | 184 #if ARCH_X86 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
185 if (flags & SWS_CPU_CAPS_MMX) |
27744 | 186 __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions) |
18861 | 187 #endif |
188 | |
28316 | 189 // NOTE: the +1 is for the MMX scaler which reads over the end |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
190 FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW+1)*sizeof(int16_t), fail); |
18861 | 191 |
29481 | 192 if (FFABS(xInc - 0x10000) <10) { // unscaled |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
193 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
194 filterSize= 1; |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
195 FF_ALLOCZ_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); |
18861 | 196 |
29481 | 197 for (i=0; i<dstW; i++) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
198 filter[i*filterSize]= fone; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
199 (*filterPos)[i]=i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
200 } |
18861 | 201 |
29481 | 202 } else if (flags&SWS_POINT) { // lame looking point sampling mode |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
203 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
204 int xDstInSrc; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
205 filterSize= 1; |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
206 FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); |
23129 | 207 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
208 xDstInSrc= xInc/2 - 0x8000; |
29481 | 209 for (i=0; i<dstW; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
210 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; |
18861 | 211 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
212 (*filterPos)[i]= xx; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
213 filter[i]= fone; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
214 xDstInSrc+= xInc; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
215 } |
29481 | 216 } else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) { // bilinear upscale |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
217 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
218 int xDstInSrc; |
29407 | 219 filterSize= 2; |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
220 FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); |
18861 | 221 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
222 xDstInSrc= xInc/2 - 0x8000; |
29481 | 223 for (i=0; i<dstW; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
224 int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
225 int j; |
18861 | 226 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
227 (*filterPos)[i]= xx; |
29480 | 228 //bilinear upscale / linear interpolate / area averaging |
29481 | 229 for (j=0; j<filterSize; j++) { |
29480 | 230 int64_t coeff= fone - FFABS((xx<<16) - xDstInSrc)*(fone>>16); |
231 if (coeff<0) coeff=0; | |
232 filter[i*filterSize + j]= coeff; | |
233 xx++; | |
234 } | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
235 xDstInSrc+= xInc; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
236 } |
29481 | 237 } else { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
238 int xDstInSrc; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
239 int sizeFactor; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
240 |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
241 if (flags&SWS_BICUBIC) sizeFactor= 4; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
242 else if (flags&SWS_X) sizeFactor= 8; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
243 else if (flags&SWS_AREA) sizeFactor= 1; //downscale only, for upscale it is bilinear |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
244 else if (flags&SWS_GAUSS) sizeFactor= 8; // infinite ;) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
245 else if (flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? ceil(2*param[0]) : 6; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
246 else if (flags&SWS_SINC) sizeFactor= 20; // infinite ;) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
247 else if (flags&SWS_SPLINE) sizeFactor= 20; // infinite ;) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
248 else if (flags&SWS_BILINEAR) sizeFactor= 2; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
249 else { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
250 sizeFactor= 0; //GCC warning killer |
27182
f7b6d1014b6b
Remove ASSERT() macro. SoC Patch from Keiji Costantini
lu_zero
parents:
27181
diff
changeset
|
251 assert(0); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
252 } |
23129 | 253 |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
254 if (xInc <= 1<<16) filterSize= 1 + sizeFactor; // upscale |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
255 else filterSize= 1 + (sizeFactor*srcW + dstW - 1)/ dstW; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
256 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
257 if (filterSize > srcW-2) filterSize=srcW-2; |
18861 | 258 |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
259 FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); |
18861 | 260 |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
261 xDstInSrc= xInc - 0x10000; |
29481 | 262 for (i=0; i<dstW; i++) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
263 int xx= (xDstInSrc - ((filterSize-2)<<16)) / (1<<17); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
264 int j; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
265 (*filterPos)[i]= xx; |
29481 | 266 for (j=0; j<filterSize; j++) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
267 int64_t d= ((int64_t)FFABS((xx<<17) - xDstInSrc))<<13; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
268 double floatd; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
269 int64_t coeff; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
270 |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
271 if (xInc > 1<<16) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
272 d= d*dstW/srcW; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
273 floatd= d * (1.0/(1<<30)); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
274 |
29481 | 275 if (flags & SWS_BICUBIC) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
276 int64_t B= (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1<<24); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
277 int64_t C= (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1<<24); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
278 int64_t dd = ( d*d)>>30; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
279 int64_t ddd= (dd*d)>>30; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
280 |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
281 if (d < 1LL<<30) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
282 coeff = (12*(1<<24)-9*B-6*C)*ddd + (-18*(1<<24)+12*B+6*C)*dd + (6*(1<<24)-2*B)*(1<<30); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
283 else if (d < 1LL<<31) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
284 coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
285 else |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
286 coeff=0.0; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
287 coeff *= fone>>(30+24); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
288 } |
29481 | 289 /* else if (flags & SWS_X) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
290 double p= param ? param*0.01 : 0.3; |
31128 | 291 coeff = d ? sin(d*M_PI)/(d*M_PI) : 1.0; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
292 coeff*= pow(2.0, - p*d*d); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
293 }*/ |
29481 | 294 else if (flags & SWS_X) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
295 double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
296 double c; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
297 |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
298 if (floatd<1.0) |
30370
a8c94e9dc653
Don't redefine M_PI. It is already defined from libavutil/mathematics.h.
ramiro
parents:
30369
diff
changeset
|
299 c = cos(floatd*M_PI); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
300 else |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
301 c=-1.0; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
302 if (c<0.0) c= -pow(-c, A); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
303 else c= pow( c, A); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
304 coeff= (c*0.5 + 0.5)*fone; |
29481 | 305 } else if (flags & SWS_AREA) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
306 int64_t d2= d - (1<<29); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
307 if (d2*xInc < -(1LL<<(29+16))) coeff= 1.0 * (1LL<<(30+16)); |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
308 else if (d2*xInc < (1LL<<(29+16))) coeff= -d2*xInc + (1LL<<(29+16)); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
309 else coeff=0.0; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
310 coeff *= fone>>(30+16); |
29481 | 311 } else if (flags & SWS_GAUSS) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
312 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
313 coeff = (pow(2.0, - p*floatd*floatd))*fone; |
29481 | 314 } else if (flags & SWS_SINC) { |
30370
a8c94e9dc653
Don't redefine M_PI. It is already defined from libavutil/mathematics.h.
ramiro
parents:
30369
diff
changeset
|
315 coeff = (d ? sin(floatd*M_PI)/(floatd*M_PI) : 1.0)*fone; |
29481 | 316 } else if (flags & SWS_LANCZOS) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
317 double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; |
30370
a8c94e9dc653
Don't redefine M_PI. It is already defined from libavutil/mathematics.h.
ramiro
parents:
30369
diff
changeset
|
318 coeff = (d ? sin(floatd*M_PI)*sin(floatd*M_PI/p)/(floatd*floatd*M_PI*M_PI/p) : 1.0)*fone; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
319 if (floatd>p) coeff=0; |
29481 | 320 } else if (flags & SWS_BILINEAR) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
321 coeff= (1<<30) - d; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
322 if (coeff<0) coeff=0; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
323 coeff *= fone >> 30; |
29481 | 324 } else if (flags & SWS_SPLINE) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
325 double p=-2.196152422706632; |
27637
5abf906c09c8
Fix infinite loop with spline, bug was introduced in r27612 by me.
michael
parents:
27596
diff
changeset
|
326 coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, floatd) * fone; |
29481 | 327 } else { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
328 coeff= 0.0; //GCC warning killer |
27182
f7b6d1014b6b
Remove ASSERT() macro. SoC Patch from Keiji Costantini
lu_zero
parents:
27181
diff
changeset
|
329 assert(0); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
330 } |
18861 | 331 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
332 filter[i*filterSize + j]= coeff; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
333 xx++; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
334 } |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
335 xDstInSrc+= 2*xInc; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
336 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
337 } |
18861 | 338 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
339 /* apply src & dst Filter to filter -> filter2 |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
340 av_free(filter); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
341 */ |
27182
f7b6d1014b6b
Remove ASSERT() macro. SoC Patch from Keiji Costantini
lu_zero
parents:
27181
diff
changeset
|
342 assert(filterSize>0); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
343 filter2Size= filterSize; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
344 if (srcFilter) filter2Size+= srcFilter->length - 1; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
345 if (dstFilter) filter2Size+= dstFilter->length - 1; |
27182
f7b6d1014b6b
Remove ASSERT() macro. SoC Patch from Keiji Costantini
lu_zero
parents:
27181
diff
changeset
|
346 assert(filter2Size>0); |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
347 FF_ALLOCZ_OR_GOTO(NULL, filter2, filter2Size*dstW*sizeof(*filter2), fail); |
18861 | 348 |
29481 | 349 for (i=0; i<dstW; i++) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
350 int j, k; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
351 |
29481 | 352 if(srcFilter) { |
353 for (k=0; k<srcFilter->length; k++) { | |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
354 for (j=0; j<filterSize; j++) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
355 filter2[i*filter2Size + k + j] += srcFilter->coeff[k]*filter[i*filterSize + j]; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
356 } |
29481 | 357 } else { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
358 for (j=0; j<filterSize; j++) |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
359 filter2[i*filter2Size + j]= filter[i*filterSize + j]; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
360 } |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
361 //FIXME dstFilter |
18861 | 362 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
363 (*filterPos)[i]+= (filterSize-1)/2 - (filter2Size-1)/2; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
364 } |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
365 av_freep(&filter); |
18861 | 366 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
367 /* try to reduce the filter-size (step1 find size and shift left) */ |
23536 | 368 // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not). |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
369 minFilterSize= 0; |
29481 | 370 for (i=dstW-1; i>=0; i--) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
371 int min= filter2Size; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
372 int j; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
373 int64_t cutOff=0.0; |
18861 | 374 |
30296 | 375 /* get rid of near zero elements on the left by shifting left */ |
29481 | 376 for (j=0; j<filter2Size; j++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
377 int k; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
378 cutOff += FFABS(filter2[i*filter2Size]); |
18861 | 379 |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
380 if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break; |
18861 | 381 |
23536 | 382 /* preserve monotonicity because the core can't handle the filter otherwise */ |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
383 if (i<dstW-1 && (*filterPos)[i] >= (*filterPos)[i+1]) break; |
18861 | 384 |
28316 | 385 // move filter coefficients left |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
386 for (k=1; k<filter2Size; k++) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
387 filter2[i*filter2Size + k - 1]= filter2[i*filter2Size + k]; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
388 filter2[i*filter2Size + k - 1]= 0; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
389 (*filterPos)[i]++; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
390 } |
18861 | 391 |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
392 cutOff=0; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
393 /* count near zeros on the right */ |
29481 | 394 for (j=filter2Size-1; j>0; j--) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
395 cutOff += FFABS(filter2[i*filter2Size + j]); |
18861 | 396 |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
397 if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
398 min--; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
399 } |
18861 | 400 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
401 if (min>minFilterSize) minFilterSize= min; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
402 } |
18861 | 403 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
404 if (flags & SWS_CPU_CAPS_ALTIVEC) { |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
405 // we can handle the special case 4, |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
406 // so we don't want to go to the full 8 |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
407 if (minFilterSize < 5) |
18861 | 408 filterAlign = 4; |
409 | |
28316 | 410 // We really don't want to waste our time |
411 // doing useless computation, so fall back on | |
412 // the scalar C code for very small filters. | |
413 // Vectorizing is worth it only if you have a | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
414 // decent-sized vector. |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
415 if (minFilterSize < 3) |
18861 | 416 filterAlign = 1; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
417 } |
18861 | 418 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
419 if (flags & SWS_CPU_CAPS_MMX) { |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
420 // special case for unscaled vertical filtering |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
421 if (minFilterSize == 1 && filterAlign == 2) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
422 filterAlign= 1; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
423 } |
19172
bae6c99a99cc
vertical scaler with accurate rounding, some people on doom9 can see +-1 errors
michael
parents:
19169
diff
changeset
|
424 |
27182
f7b6d1014b6b
Remove ASSERT() macro. SoC Patch from Keiji Costantini
lu_zero
parents:
27181
diff
changeset
|
425 assert(minFilterSize > 0); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
426 filterSize= (minFilterSize +(filterAlign-1)) & (~(filterAlign-1)); |
27182
f7b6d1014b6b
Remove ASSERT() macro. SoC Patch from Keiji Costantini
lu_zero
parents:
27181
diff
changeset
|
427 assert(filterSize > 0); |
27579 | 428 filter= av_malloc(filterSize*dstW*sizeof(*filter)); |
27513 | 429 if (filterSize >= MAX_FILTER_SIZE*16/((flags&SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter) |
29542 | 430 goto fail; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
431 *outFilterSize= filterSize; |
18861 | 432 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
433 if (flags&SWS_PRINT_INFO) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
434 av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
435 /* try to reduce the filter-size (step2 reduce it) */ |
29481 | 436 for (i=0; i<dstW; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
437 int j; |
18861 | 438 |
29481 | 439 for (j=0; j<filterSize; j++) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
440 if (j>=filter2Size) filter[i*filterSize + j]= 0; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
441 else filter[i*filterSize + j]= filter2[i*filter2Size + j]; |
27563
39c8d234b98e
Ensure that additional filter coeffs that exist due to alignment
michael
parents:
27562
diff
changeset
|
442 if((flags & SWS_BITEXACT) && j>=minFilterSize) |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
443 filter[i*filterSize + j]= 0; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
444 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
445 } |
23129 | 446 |
28316 | 447 //FIXME try to align filterPos if possible |
18861 | 448 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
449 //fix borders |
29481 | 450 for (i=0; i<dstW; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
451 int j; |
29481 | 452 if ((*filterPos)[i] < 0) { |
28316 | 453 // move filter coefficients left to compensate for filterPos |
29481 | 454 for (j=1; j<filterSize; j++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
455 int left= FFMAX(j + (*filterPos)[i], 0); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
456 filter[i*filterSize + left] += filter[i*filterSize + j]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
457 filter[i*filterSize + j]=0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
458 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
459 (*filterPos)[i]= 0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
460 } |
18861 | 461 |
29481 | 462 if ((*filterPos)[i] + filterSize > srcW) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
463 int shift= (*filterPos)[i] + filterSize - srcW; |
28316 | 464 // move filter coefficients right to compensate for filterPos |
29481 | 465 for (j=filterSize-2; j>=0; j--) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
466 int right= FFMIN(j + shift, filterSize-1); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
467 filter[i*filterSize +right] += filter[i*filterSize +j]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
468 filter[i*filterSize +j]=0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
469 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
470 (*filterPos)[i]= srcW - filterSize; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
471 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
472 } |
18861 | 473 |
28316 | 474 // Note the +1 is for the MMX scaler which reads over the end |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
475 /* align at 16 for AltiVec (needed by hScale_altivec_real) */ |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
476 FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize*(dstW+1)*sizeof(int16_t), fail); |
18861 | 477 |
28316 | 478 /* normalize & store in outFilter */ |
29481 | 479 for (i=0; i<dstW; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
480 int j; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
481 int64_t error=0; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
482 int64_t sum=0; |
18861 | 483 |
29481 | 484 for (j=0; j<filterSize; j++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
485 sum+= filter[i*filterSize + j]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
486 } |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
487 sum= (sum + one/2)/ one; |
29481 | 488 for (j=0; j<*outFilterSize; j++) { |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
489 int64_t v= filter[i*filterSize + j] + error; |
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
490 int intV= ROUNDED_DIV(v, sum); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
491 (*outFilter)[i*(*outFilterSize) + j]= intV; |
27580
9ff7a64a51fa
Avoid using floating point for calculating filter coefficients.
michael
parents:
27579
diff
changeset
|
492 error= v - intV*sum; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
493 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
494 } |
23129 | 495 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
496 (*filterPos)[dstW]= (*filterPos)[dstW-1]; // the MMX scaler will read over the end |
29481 | 497 for (i=0; i<*outFilterSize; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
498 int j= dstW*(*outFilterSize); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
499 (*outFilter)[j + i]= (*outFilter)[j + i - (*outFilterSize)]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
500 } |
18861 | 501 |
27300 | 502 ret=0; |
29542 | 503 fail: |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
504 av_free(filter); |
27300 | 505 av_free(filter2); |
506 return ret; | |
18861 | 507 } |
508 | |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
509 #if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
510 static int initMMX2HScaler(int dstW, int xInc, uint8_t *filterCode, int16_t *filter, int32_t *filterPos, int numSplits) |
18861 | 511 { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
512 uint8_t *fragmentA; |
28957 | 513 x86_reg imm8OfPShufW1A; |
514 x86_reg imm8OfPShufW2A; | |
515 x86_reg fragmentLengthA; | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
516 uint8_t *fragmentB; |
28957 | 517 x86_reg imm8OfPShufW1B; |
518 x86_reg imm8OfPShufW2B; | |
519 x86_reg fragmentLengthB; | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
520 int fragmentPos; |
18861 | 521 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
522 int xpos, i; |
18861 | 523 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
524 // create an optimized horizontal scaling routine |
29936
f43f03c00402
Document the differences between the two asm fragments in initMMX2HScaler().
ramiro
parents:
29932
diff
changeset
|
525 /* This scaler is made of runtime-generated MMX2 code using specially |
f43f03c00402
Document the differences between the two asm fragments in initMMX2HScaler().
ramiro
parents:
29932
diff
changeset
|
526 * tuned pshufw instructions. For every four output pixels, if four |
f43f03c00402
Document the differences between the two asm fragments in initMMX2HScaler().
ramiro
parents:
29932
diff
changeset
|
527 * input pixels are enough for the fast bilinear scaling, then a chunk |
f43f03c00402
Document the differences between the two asm fragments in initMMX2HScaler().
ramiro
parents:
29932
diff
changeset
|
528 * of fragmentB is used. If five input pixels are needed, then a chunk |
f43f03c00402
Document the differences between the two asm fragments in initMMX2HScaler().
ramiro
parents:
29932
diff
changeset
|
529 * of fragmentA is used. |
f43f03c00402
Document the differences between the two asm fragments in initMMX2HScaler().
ramiro
parents:
29932
diff
changeset
|
530 */ |
18861 | 531 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
532 //code fragment |
18861 | 533 |
27744 | 534 __asm__ volatile( |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
535 "jmp 9f \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
536 // Begin |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
537 "0: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
538 "movq (%%"REG_d", %%"REG_a"), %%mm3 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
539 "movd (%%"REG_c", %%"REG_S"), %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
540 "movd 1(%%"REG_c", %%"REG_S"), %%mm1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
541 "punpcklbw %%mm7, %%mm1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
542 "punpcklbw %%mm7, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
543 "pshufw $0xFF, %%mm1, %%mm1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
544 "1: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
545 "pshufw $0xFF, %%mm0, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
546 "2: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
547 "psubw %%mm1, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
548 "movl 8(%%"REG_b", %%"REG_a"), %%esi \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
549 "pmullw %%mm3, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
550 "psllw $7, %%mm1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
551 "paddw %%mm1, %%mm0 \n\t" |
18861 | 552 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
553 "movq %%mm0, (%%"REG_D", %%"REG_a") \n\t" |
18861 | 554 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
555 "add $8, %%"REG_a" \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
556 // End |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
557 "9: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
558 // "int $3 \n\t" |
26238
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
559 "lea " LOCAL_MANGLE(0b) ", %0 \n\t" |
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
560 "lea " LOCAL_MANGLE(1b) ", %1 \n\t" |
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
561 "lea " LOCAL_MANGLE(2b) ", %2 \n\t" |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
562 "dec %1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
563 "dec %2 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
564 "sub %0, %1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
565 "sub %0, %2 \n\t" |
26238
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
566 "lea " LOCAL_MANGLE(9b) ", %3 \n\t" |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
567 "sub %0, %3 \n\t" |
18861 | 568 |
569 | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
570 :"=r" (fragmentA), "=r" (imm8OfPShufW1A), "=r" (imm8OfPShufW2A), |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
571 "=r" (fragmentLengthA) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
572 ); |
18861 | 573 |
27744 | 574 __asm__ volatile( |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
575 "jmp 9f \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
576 // Begin |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
577 "0: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
578 "movq (%%"REG_d", %%"REG_a"), %%mm3 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
579 "movd (%%"REG_c", %%"REG_S"), %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
580 "punpcklbw %%mm7, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
581 "pshufw $0xFF, %%mm0, %%mm1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
582 "1: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
583 "pshufw $0xFF, %%mm0, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
584 "2: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
585 "psubw %%mm1, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
586 "movl 8(%%"REG_b", %%"REG_a"), %%esi \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
587 "pmullw %%mm3, %%mm0 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
588 "psllw $7, %%mm1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
589 "paddw %%mm1, %%mm0 \n\t" |
18861 | 590 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
591 "movq %%mm0, (%%"REG_D", %%"REG_a") \n\t" |
18861 | 592 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
593 "add $8, %%"REG_a" \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
594 // End |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
595 "9: \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
596 // "int $3 \n\t" |
26238
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
597 "lea " LOCAL_MANGLE(0b) ", %0 \n\t" |
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
598 "lea " LOCAL_MANGLE(1b) ", %1 \n\t" |
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
599 "lea " LOCAL_MANGLE(2b) ", %2 \n\t" |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
600 "dec %1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
601 "dec %2 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
602 "sub %0, %1 \n\t" |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
603 "sub %0, %2 \n\t" |
26238
726b915c2b45
Fix 64 bit shared library compilation with MMX2 by properly using PIC mangling.
diego
parents:
26232
diff
changeset
|
604 "lea " LOCAL_MANGLE(9b) ", %3 \n\t" |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
605 "sub %0, %3 \n\t" |
18861 | 606 |
607 | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
608 :"=r" (fragmentB), "=r" (imm8OfPShufW1B), "=r" (imm8OfPShufW2B), |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
609 "=r" (fragmentLengthB) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
610 ); |
18861 | 611 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
612 xpos= 0; //lumXInc/2 - 0x8000; // difference between pixel centers |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
613 fragmentPos=0; |
23129 | 614 |
29481 | 615 for (i=0; i<dstW/numSplits; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
616 int xx=xpos>>16; |
18861 | 617 |
29481 | 618 if ((i&3) == 0) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
619 int a=0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
620 int b=((xpos+xInc)>>16) - xx; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
621 int c=((xpos+xInc*2)>>16) - xx; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
622 int d=((xpos+xInc*3)>>16) - xx; |
29410
fd9b0bd6c908
MMX2 scaler: add variable to ease factorization of initMMX2Scaler().
ramiro
parents:
29407
diff
changeset
|
623 int inc = (d+1<4); |
29411 | 624 uint8_t *fragment = (d+1<4) ? fragmentB : fragmentA; |
625 x86_reg imm8OfPShufW1 = (d+1<4) ? imm8OfPShufW1B : imm8OfPShufW1A; | |
626 x86_reg imm8OfPShufW2 = (d+1<4) ? imm8OfPShufW2B : imm8OfPShufW2A; | |
627 x86_reg fragmentLength = (d+1<4) ? fragmentLengthB : fragmentLengthA; | |
29412
139af822b6ce
MMX2 scaler: Remove {} block leftover from factorization in initMMX2Scaler().
ramiro
parents:
29411
diff
changeset
|
628 int maxShift= 3-(d+inc); |
139af822b6ce
MMX2 scaler: Remove {} block leftover from factorization in initMMX2Scaler().
ramiro
parents:
29411
diff
changeset
|
629 int shift=0; |
18861 | 630 |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
631 if (filterCode) { |
29470 | 632 filter[i ] = (( xpos & 0xFFFF) ^ 0xFFFF)>>9; |
633 filter[i+1] = (((xpos+xInc ) & 0xFFFF) ^ 0xFFFF)>>9; | |
634 filter[i+2] = (((xpos+xInc*2) & 0xFFFF) ^ 0xFFFF)>>9; | |
635 filter[i+3] = (((xpos+xInc*3) & 0xFFFF) ^ 0xFFFF)>>9; | |
636 filterPos[i/2]= xx; | |
637 | |
638 memcpy(filterCode + fragmentPos, fragment, fragmentLength); | |
639 | |
640 filterCode[fragmentPos + imm8OfPShufW1]= | |
641 (a+inc) | ((b+inc)<<2) | ((c+inc)<<4) | ((d+inc)<<6); | |
642 filterCode[fragmentPos + imm8OfPShufW2]= | |
643 a | (b<<2) | (c<<4) | (d<<6); | |
644 | |
645 if (i+4-inc>=dstW) shift=maxShift; //avoid overread | |
646 else if ((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align | |
647 | |
29481 | 648 if (shift && i>=shift) { |
29470 | 649 filterCode[fragmentPos + imm8OfPShufW1]+= 0x55*shift; |
650 filterCode[fragmentPos + imm8OfPShufW2]+= 0x55*shift; | |
651 filterPos[i/2]-=shift; | |
652 } | |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
653 } |
18861 | 654 |
29412
139af822b6ce
MMX2 scaler: Remove {} block leftover from factorization in initMMX2Scaler().
ramiro
parents:
29411
diff
changeset
|
655 fragmentPos+= fragmentLength; |
139af822b6ce
MMX2 scaler: Remove {} block leftover from factorization in initMMX2Scaler().
ramiro
parents:
29411
diff
changeset
|
656 |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
657 if (filterCode) |
29470 | 658 filterCode[fragmentPos]= RET; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
659 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
660 xpos+=xInc; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
661 } |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
662 if (filterCode) |
29470 | 663 filterPos[((i/2)+1)&(~1)]= xpos>>16; // needed to jump to the next part |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
664 |
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
665 return fragmentPos + 1; |
18861 | 666 } |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
667 #endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) */ |
18861 | 668 |
30142
bd5ab02f84f8
Prefer enum PixelFormat over int for the type of the format parameter
stefano
parents:
30138
diff
changeset
|
669 static void getSubSampleFactors(int *h, int *v, enum PixelFormat format) |
29481 | 670 { |
30129
a8283bcc8d2e
Simplify getSubSampleFactors(), make it use the values provided by
stefano
parents:
30045
diff
changeset
|
671 *h = av_pix_fmt_descriptors[format].log2_chroma_w; |
a8283bcc8d2e
Simplify getSubSampleFactors(), make it use the values provided by
stefano
parents:
30045
diff
changeset
|
672 *v = av_pix_fmt_descriptors[format].log2_chroma_h; |
18861 | 673 } |
674 | |
29481 | 675 int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation) |
676 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
677 memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
678 memcpy(c->dstColorspaceTable, table, sizeof(int)*4); |
18861 | 679 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
680 c->brightness= brightness; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
681 c->contrast = contrast; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
682 c->saturation= saturation; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
683 c->srcRange = srcRange; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
684 c->dstRange = dstRange; |
29146
d6d87abb137f
Make sws_setColorspaceDetails() return -1 if the destination format is
stefano
parents:
29145
diff
changeset
|
685 if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; |
18861 | 686 |
28953
1e56ea9937ce
Consistently use ff_ prefixes for internal symbols.
diego
parents:
28951
diff
changeset
|
687 ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
688 //FIXME factorize |
18861 | 689 |
30912
f91ad62a2281
AltiVec implies a PPC CPU, so there is no need to check for both.
diego
parents:
30910
diff
changeset
|
690 #if HAVE_ALTIVEC |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
691 if (c->flags & SWS_CPU_CAPS_ALTIVEC) |
28953
1e56ea9937ce
Consistently use ff_ prefixes for internal symbols.
diego
parents:
28951
diff
changeset
|
692 ff_yuv2rgb_init_tables_altivec(c, inv_table, brightness, contrast, saturation); |
23129 | 693 #endif |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
694 return 0; |
18861 | 695 } |
696 | |
29481 | 697 int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation) |
698 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
699 if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; |
18861 | 700 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
701 *inv_table = c->srcColorspaceTable; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
702 *table = c->dstColorspaceTable; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
703 *srcRange = c->srcRange; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
704 *dstRange = c->dstRange; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
705 *brightness= c->brightness; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
706 *contrast = c->contrast; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
707 *saturation= c->saturation; |
23129 | 708 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
709 return 0; |
18861 | 710 } |
711 | |
27696
0c2dc440984b
Change one more variable type from int to enum PixelFormat.
aurel
parents:
27695
diff
changeset
|
712 static int handle_jpeg(enum PixelFormat *format) |
19987 | 713 { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
714 switch (*format) { |
31129
8639a950e856
Cosmetics: make more compact the code for handle_jpeg(), this also allows
stefano
parents:
31128
diff
changeset
|
715 case PIX_FMT_YUVJ420P: *format = PIX_FMT_YUV420P; return 1; |
8639a950e856
Cosmetics: make more compact the code for handle_jpeg(), this also allows
stefano
parents:
31128
diff
changeset
|
716 case PIX_FMT_YUVJ422P: *format = PIX_FMT_YUV422P; return 1; |
8639a950e856
Cosmetics: make more compact the code for handle_jpeg(), this also allows
stefano
parents:
31128
diff
changeset
|
717 case PIX_FMT_YUVJ444P: *format = PIX_FMT_YUV444P; return 1; |
8639a950e856
Cosmetics: make more compact the code for handle_jpeg(), this also allows
stefano
parents:
31128
diff
changeset
|
718 case PIX_FMT_YUVJ440P: *format = PIX_FMT_YUV440P; return 1; |
8639a950e856
Cosmetics: make more compact the code for handle_jpeg(), this also allows
stefano
parents:
31128
diff
changeset
|
719 default: return 0; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
720 } |
19987 | 721 } |
722 | |
31968
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
723 static int update_flags_cpu(int flags) |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
724 { |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
725 #if !CONFIG_RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
726 flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC|SWS_CPU_CAPS_BFIN); |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
727 flags |= ff_hardcodedcpuflags(); |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
728 #endif /* CONFIG_RUNTIME_CPUDETECT */ |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
729 return flags; |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
730 } |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
731 |
30336 | 732 SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, |
733 int dstW, int dstH, enum PixelFormat dstFormat, int flags, | |
29246
8861e08033eb
Add const qualifier to param argument of sws_getContext() and
diego
parents:
29245
diff
changeset
|
734 SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param) |
8861e08033eb
Add const qualifier to param argument of sws_getContext() and
diego
parents:
29245
diff
changeset
|
735 { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
736 SwsContext *c; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
737 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
738 int usesVFilter, usesHFilter; |
30369
8c479cb29c7a
Split swscale.c into scaler code (swscale.c) and utility code (utils.c).
ramiro
parents:
30343
diff
changeset
|
739 int unscaled; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
740 int srcRange, dstRange; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
741 SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; |
28276 | 742 #if ARCH_X86 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
743 if (flags & SWS_CPU_CAPS_MMX) |
27744 | 744 __asm__ volatile("emms\n\t"::: "memory"); |
18861 | 745 #endif |
746 | |
31968
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
747 flags = update_flags_cpu(flags); |
25752
559b0e9d47fb
Change (a == NULL) condition to (!a) and (a != NULL) condition to (a).
benoit
parents:
25750
diff
changeset
|
748 if (!rgb15to16) sws_rgb2rgb_init(flags); |
18861 | 749 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
750 unscaled = (srcW == dstW && srcH == dstH); |
18861 | 751 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
752 srcRange = handle_jpeg(&srcFormat); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
753 dstRange = handle_jpeg(&dstFormat); |
19987 | 754 |
29481 | 755 if (!isSupportedIn(srcFormat)) { |
25967
87331ea89425
More explicit unsupported pixel format error messages.
benoit
parents:
25935
diff
changeset
|
756 av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat)); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
757 return NULL; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
758 } |
29481 | 759 if (!isSupportedOut(dstFormat)) { |
25967
87331ea89425
More explicit unsupported pixel format error messages.
benoit
parents:
25935
diff
changeset
|
760 av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat)); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
761 return NULL; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
762 } |
18861 | 763 |
27285 | 764 i= flags & ( SWS_POINT |
765 |SWS_AREA | |
27286 | 766 |SWS_BILINEAR |
27285 | 767 |SWS_FAST_BILINEAR |
768 |SWS_BICUBIC | |
769 |SWS_X | |
770 |SWS_GAUSS | |
771 |SWS_LANCZOS | |
772 |SWS_SINC | |
773 |SWS_SPLINE | |
774 |SWS_BICUBLIN); | |
29481 | 775 if(!i || (i & (i-1))) { |
28316 | 776 av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n"); |
27285 | 777 return NULL; |
778 } | |
779 | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
780 /* sanity check */ |
29481 | 781 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 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
782 av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
783 srcW, srcH, dstW, dstH); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
784 return NULL; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
785 } |
29481 | 786 if(srcW > VOFW || dstW > VOFW) { |
28316 | 787 av_log(NULL, AV_LOG_ERROR, "swScaler: Compile-time maximum width is "AV_STRINGIFY(VOFW)" change VOF/VOFW and recompile\n"); |
26133
94cc4bac8cd0
Turn ancient V offset numerical constants into named ones.
michael
parents:
26028
diff
changeset
|
788 return NULL; |
94cc4bac8cd0
Turn ancient V offset numerical constants into named ones.
michael
parents:
26028
diff
changeset
|
789 } |
18861 | 790 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
791 if (!dstFilter) dstFilter= &dummyFilter; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
792 if (!srcFilter) srcFilter= &dummyFilter; |
18861 | 793 |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
794 FF_ALLOCZ_OR_GOTO(NULL, c, sizeof(SwsContext), fail); |
18861 | 795 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
796 c->av_class = &sws_context_class; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
797 c->srcW= srcW; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
798 c->srcH= srcH; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
799 c->dstW= dstW; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
800 c->dstH= dstH; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
801 c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
802 c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
803 c->flags= flags; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
804 c->dstFormat= dstFormat; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
805 c->srcFormat= srcFormat; |
30377
2eea1f09e2c5
Use av_get_bits_per_pixel() for computing the bits per pixel of the
stefano
parents:
30370
diff
changeset
|
806 c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[dstFormat]); |
2eea1f09e2c5
Use av_get_bits_per_pixel() for computing the bits per pixel of the
stefano
parents:
30370
diff
changeset
|
807 c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[srcFormat]); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
808 c->vRounder= 4* 0x0001000100010001ULL; |
18861 | 809 |
30478
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
810 usesVFilter = (srcFilter->lumV && srcFilter->lumV->length>1) || |
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
811 (srcFilter->chrV && srcFilter->chrV->length>1) || |
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
812 (dstFilter->lumV && dstFilter->lumV->length>1) || |
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
813 (dstFilter->chrV && dstFilter->chrV->length>1); |
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
814 usesHFilter = (srcFilter->lumH && srcFilter->lumH->length>1) || |
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
815 (srcFilter->chrH && srcFilter->chrH->length>1) || |
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
816 (dstFilter->lumH && dstFilter->lumH->length>1) || |
838bbf6bc6ff
Simplify how usesVFilter and usesHFilter are set.
stefano
parents:
30432
diff
changeset
|
817 (dstFilter->chrH && dstFilter->chrH->length>1); |
18861 | 818 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
819 getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
820 getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat); |
18861 | 821 |
28316 | 822 // reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation |
30393 | 823 if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1; |
18861 | 824 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
825 // drop some chroma lines if the user wants it |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
826 c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
827 c->chrSrcVSubSample+= c->vChrDrop; |
18861 | 828 |
28316 | 829 // drop every other pixel for chroma calculation unless user wants full chroma |
30393 | 830 if (isAnyRGB(srcFormat) && !(flags&SWS_FULL_CHR_H_INP) |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
831 && srcFormat!=PIX_FMT_RGB8 && srcFormat!=PIX_FMT_BGR8 |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
832 && srcFormat!=PIX_FMT_RGB4 && srcFormat!=PIX_FMT_BGR4 |
27529
ffb573fae5e8
Rewrite bgr24->yuv mmx code, the new code is cleaner, more accurate,
michael
parents:
27526
diff
changeset
|
833 && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE |
27532 | 834 && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&(SWS_FAST_BILINEAR|SWS_POINT)))) |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
835 c->chrSrcHSubSample=1; |
18861 | 836 |
29481 | 837 if (param) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
838 c->param[0] = param[0]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
839 c->param[1] = param[1]; |
29481 | 840 } else { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
841 c->param[0] = |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
842 c->param[1] = SWS_PARAM_DEFAULT; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
843 } |
18861 | 844 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
845 // Note the -((-x)>>y) is so that we always round toward +inf. |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
846 c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
847 c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
848 c->chrDstW= -((-dstW) >> c->chrDstHSubSample); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
849 c->chrDstH= -((-dstH) >> c->chrDstVSubSample); |
18861 | 850 |
28460 | 851 sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); |
18861 | 852 |
28316 | 853 /* unscaled special cases */ |
30393 | 854 if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isAnyRGB(dstFormat))) { |
30369
8c479cb29c7a
Split swscale.c into scaler code (swscale.c) and utility code (utils.c).
ramiro
parents:
30343
diff
changeset
|
855 ff_get_unscaled_swscale(c); |
23585
d3ae6979d3df
integrating ff_bfin_get_unscaled_swscale into the system
mhoffman
parents:
23536
diff
changeset
|
856 |
29481 | 857 if (c->swScale) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
858 if (flags&SWS_PRINT_INFO) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
859 av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n", |
29480 | 860 sws_format_name(srcFormat), sws_format_name(dstFormat)); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
861 return c; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
862 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
863 } |
18861 | 864 |
29481 | 865 if (flags & SWS_CPU_CAPS_MMX2) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
866 c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0; |
29481 | 867 if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
868 if (flags&SWS_PRINT_INFO) |
28316 | 869 av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
870 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
871 if (usesHFilter) c->canMMX2BeUsed=0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
872 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
873 else |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
874 c->canMMX2BeUsed=0; |
18861 | 875 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
876 c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
877 c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; |
18861 | 878 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
879 // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
880 // but only for the FAST_BILINEAR mode otherwise do correct scaling |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
881 // n-2 is the last chrominance sample available |
23536 | 882 // this is not perfect, but no one should notice the difference, the more correct variant |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
883 // would be like the vertical one, but that would require some special code for the |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
884 // first and last pixel |
29481 | 885 if (flags&SWS_FAST_BILINEAR) { |
886 if (c->canMMX2BeUsed) { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
887 c->lumXInc+= 20; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
888 c->chrXInc+= 20; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
889 } |
28316 | 890 //we don't use the x86 asm scaler if MMX is available |
29481 | 891 else if (flags & SWS_CPU_CAPS_MMX) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
892 c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
893 c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
894 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
895 } |
18861 | 896 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
897 /* precalculate horizontal scaler filter coefficients */ |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
898 { |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
899 #if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) |
18861 | 900 // can't downscale !!! |
29481 | 901 if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) { |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
902 c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8); |
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
903 c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4); |
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
904 |
18861 | 905 #ifdef MAP_ANONYMOUS |
31903 | 906 c->lumMmx2FilterCode = mmap(NULL, c->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
907 c->chrMmx2FilterCode = mmap(NULL, c->chrMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
28971
b8e356a9dbb1
Allocate executable memory with VirtualAlloc() in Windows.
ramiro
parents:
28970
diff
changeset
|
908 #elif HAVE_VIRTUALALLOC |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
909 c->lumMmx2FilterCode = VirtualAlloc(NULL, c->lumMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); |
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
910 c->chrMmx2FilterCode = VirtualAlloc(NULL, c->chrMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); |
18861 | 911 #else |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
912 c->lumMmx2FilterCode = av_malloc(c->lumMmx2FilterCodeSize); |
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
913 c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize); |
18861 | 914 #endif |
915 | |
30822
ed3b3682cdde
Check for allocation failure for c->lumMmx2FilterCode and c->chrMmx2FilterCode.
reimar
parents:
30821
diff
changeset
|
916 if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode) |
ed3b3682cdde
Check for allocation failure for c->lumMmx2FilterCode and c->chrMmx2FilterCode.
reimar
parents:
30821
diff
changeset
|
917 goto fail; |
30285
042ec58ab0e2
Reuse h{lum,chr}Filter{,Pos} variables for MMX2 fast_bilinear horizontal scaler.
ramiro
parents:
30284
diff
changeset
|
918 FF_ALLOCZ_OR_GOTO(c, c->hLumFilter , (dstW /8+8)*sizeof(int16_t), fail); |
042ec58ab0e2
Reuse h{lum,chr}Filter{,Pos} variables for MMX2 fast_bilinear horizontal scaler.
ramiro
parents:
30284
diff
changeset
|
919 FF_ALLOCZ_OR_GOTO(c, c->hChrFilter , (c->chrDstW /4+8)*sizeof(int16_t), fail); |
042ec58ab0e2
Reuse h{lum,chr}Filter{,Pos} variables for MMX2 fast_bilinear horizontal scaler.
ramiro
parents:
30284
diff
changeset
|
920 FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW /2/8+8)*sizeof(int32_t), fail); |
042ec58ab0e2
Reuse h{lum,chr}Filter{,Pos} variables for MMX2 fast_bilinear horizontal scaler.
ramiro
parents:
30284
diff
changeset
|
921 FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail); |
042ec58ab0e2
Reuse h{lum,chr}Filter{,Pos} variables for MMX2 fast_bilinear horizontal scaler.
ramiro
parents:
30284
diff
changeset
|
922 |
042ec58ab0e2
Reuse h{lum,chr}Filter{,Pos} variables for MMX2 fast_bilinear horizontal scaler.
ramiro
parents:
30284
diff
changeset
|
923 initMMX2HScaler( dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, c->hLumFilterPos, 8); |
042ec58ab0e2
Reuse h{lum,chr}Filter{,Pos} variables for MMX2 fast_bilinear horizontal scaler.
ramiro
parents:
30284
diff
changeset
|
924 initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, c->hChrFilterPos, 4); |
29467
1acbe8b170ed
Protect mmx2 filter code buffers so they are not executable and writeable at
ramiro
parents:
29465
diff
changeset
|
925 |
1acbe8b170ed
Protect mmx2 filter code buffers so they are not executable and writeable at
ramiro
parents:
29465
diff
changeset
|
926 #ifdef MAP_ANONYMOUS |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
927 mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ); |
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
928 mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ); |
29467
1acbe8b170ed
Protect mmx2 filter code buffers so they are not executable and writeable at
ramiro
parents:
29465
diff
changeset
|
929 #endif |
30271
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
930 } else |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
931 #endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) */ |
30271
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
932 { |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
933 const int filterAlign= |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
934 (flags & SWS_CPU_CAPS_MMX) ? 4 : |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
935 (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
936 1; |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
937 |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
938 if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
939 srcW , dstW, filterAlign, 1<<14, |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
940 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
941 srcFilter->lumH, dstFilter->lumH, c->param) < 0) |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
942 goto fail; |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
943 if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
944 c->chrSrcW, c->chrDstW, filterAlign, 1<<14, |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
945 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
946 srcFilter->chrH, dstFilter->chrH, c->param) < 0) |
2fad32dd128c
Don't initialize normal horizontal filter if MMX2 filter is used.
ramiro
parents:
30264
diff
changeset
|
947 goto fail; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
948 } |
28316 | 949 } // initialize horizontal stuff |
18861 | 950 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
951 /* precalculate vertical scaler filter coefficients */ |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
952 { |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
953 const int filterAlign= |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
954 (flags & SWS_CPU_CAPS_MMX) && (flags & SWS_ACCURATE_RND) ? 2 : |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
955 (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
956 1; |
18861 | 957 |
29544 | 958 if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, |
30045 | 959 srcH , dstH, filterAlign, (1<<12), |
960 (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, | |
961 srcFilter->lumV, dstFilter->lumV, c->param) < 0) | |
29544 | 962 goto fail; |
963 if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, | |
30045 | 964 c->chrSrcH, c->chrDstH, filterAlign, (1<<12), |
965 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, | |
966 srcFilter->chrV, dstFilter->chrV, c->param) < 0) | |
29544 | 967 goto fail; |
18861 | 968 |
30912
f91ad62a2281
AltiVec implies a PPC CPU, so there is no need to check for both.
diego
parents:
30910
diff
changeset
|
969 #if HAVE_ALTIVEC |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
970 FF_ALLOC_OR_GOTO(c, c->vYCoeffsBank, sizeof (vector signed short)*c->vLumFilterSize*c->dstH, fail); |
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
971 FF_ALLOC_OR_GOTO(c, c->vCCoeffsBank, sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH, fail); |
18861 | 972 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
973 for (i=0;i<c->vLumFilterSize*c->dstH;i++) { |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
974 int j; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
975 short *p = (short *)&c->vYCoeffsBank[i]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
976 for (j=0;j<8;j++) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
977 p[j] = c->vLumFilter[i]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
978 } |
18861 | 979 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
980 for (i=0;i<c->vChrFilterSize*c->chrDstH;i++) { |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
981 int j; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
982 short *p = (short *)&c->vCCoeffsBank[i]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
983 for (j=0;j<8;j++) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
984 p[j] = c->vChrFilter[i]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
985 } |
18861 | 986 #endif |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
987 } |
18861 | 988 |
28316 | 989 // calculate buffer sizes so that they won't run out while handling these damn slices |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
990 c->vLumBufSize= c->vLumFilterSize; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
991 c->vChrBufSize= c->vChrFilterSize; |
29481 | 992 for (i=0; i<dstH; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
993 int chrI= i*c->chrDstH / dstH; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
994 int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
995 ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample)); |
18861 | 996 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
997 nextSlice>>= c->chrSrcVSubSample; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
998 nextSlice<<= c->chrSrcVSubSample; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
999 if (c->vLumFilterPos[i ] + c->vLumBufSize < nextSlice) |
25749 | 1000 c->vLumBufSize= nextSlice - c->vLumFilterPos[i]; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1001 if (c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample)) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1002 c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI]; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1003 } |
18861 | 1004 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1005 // allocate pixbufs (we use dynamic allocation because otherwise we would need to |
29540 | 1006 // allocate several megabytes to handle all possible cases) |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
1007 FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail); |
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
1008 FF_ALLOC_OR_GOTO(c, c->chrPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail); |
28976 | 1009 if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
1010 FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail); |
28316 | 1011 //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) |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1012 /* align at 16 bytes for AltiVec */ |
29545 | 1013 for (i=0; i<c->vLumBufSize; i++) { |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
1014 FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], VOF+1, fail); |
29542 | 1015 c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize]; |
1016 } | |
29545 | 1017 for (i=0; i<c->vChrBufSize; i++) { |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
1018 FF_ALLOC_OR_GOTO(c, c->chrPixBuf[i+c->vChrBufSize], (VOF+1)*2, fail); |
29542 | 1019 c->chrPixBuf[i] = c->chrPixBuf[i+c->vChrBufSize]; |
1020 } | |
28976 | 1021 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) |
29545 | 1022 for (i=0; i<c->vLumBufSize; i++) { |
29610
c35359578f8d
Rename CHECKED_ALLOC(Z) to FF_ALLOC(Z)_OR_GOTO and add context and label
ramiro
parents:
29609
diff
changeset
|
1023 FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], VOF+1, fail); |
29542 | 1024 c->alpPixBuf[i] = c->alpPixBuf[i+c->vLumBufSize]; |
1025 } | |
18861 | 1026 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1027 //try to avoid drawing green stuff between the right end and the stride end |
26133
94cc4bac8cd0
Turn ancient V offset numerical constants into named ones.
michael
parents:
26028
diff
changeset
|
1028 for (i=0; i<c->vChrBufSize; i++) memset(c->chrPixBuf[i], 64, (VOF+1)*2); |
94cc4bac8cd0
Turn ancient V offset numerical constants into named ones.
michael
parents:
26028
diff
changeset
|
1029 |
26225 | 1030 assert(2*VOFW == VOF); |
18861 | 1031 |
27182
f7b6d1014b6b
Remove ASSERT() macro. SoC Patch from Keiji Costantini
lu_zero
parents:
27181
diff
changeset
|
1032 assert(c->chrDstH <= dstH); |
18861 | 1033 |
29481 | 1034 if (flags&SWS_PRINT_INFO) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1035 if (flags&SWS_FAST_BILINEAR) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1036 av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1037 else if (flags&SWS_BILINEAR) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1038 av_log(c, AV_LOG_INFO, "BILINEAR scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1039 else if (flags&SWS_BICUBIC) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1040 av_log(c, AV_LOG_INFO, "BICUBIC scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1041 else if (flags&SWS_X) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1042 av_log(c, AV_LOG_INFO, "Experimental scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1043 else if (flags&SWS_POINT) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1044 av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1045 else if (flags&SWS_AREA) |
30262 | 1046 av_log(c, AV_LOG_INFO, "Area Averaging scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1047 else if (flags&SWS_BICUBLIN) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1048 av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1049 else if (flags&SWS_GAUSS) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1050 av_log(c, AV_LOG_INFO, "Gaussian scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1051 else if (flags&SWS_SINC) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1052 av_log(c, AV_LOG_INFO, "Sinc scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1053 else if (flags&SWS_LANCZOS) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1054 av_log(c, AV_LOG_INFO, "Lanczos scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1055 else if (flags&SWS_SPLINE) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1056 av_log(c, AV_LOG_INFO, "Bicubic spline scaler, "); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1057 else |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1058 av_log(c, AV_LOG_INFO, "ehh flags invalid?! "); |
18861 | 1059 |
30288
4ee0cedb32f2
Prefer "to %s%s" over "to%s %s", slightly more readable.
stefano
parents:
30287
diff
changeset
|
1060 av_log(c, AV_LOG_INFO, "from %s to %s%s ", |
30284
03f99130b7c3
Factorize code which logs the source and destination formats in
stefano
parents:
30275
diff
changeset
|
1061 sws_format_name(srcFormat), |
30287
67cace3e3df7
Simplify code in sws_getContext() which logs if the destination format
stefano
parents:
30285
diff
changeset
|
1062 #ifdef DITHER1XBPP |
30892
e052716dcb5b
Extend the generic path of the yuv2rgb converter with support for rgb444
cehoyos
parents:
30822
diff
changeset
|
1063 dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 || |
e052716dcb5b
Extend the generic path of the yuv2rgb converter with support for rgb444
cehoyos
parents:
30822
diff
changeset
|
1064 dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE || |
e052716dcb5b
Extend the generic path of the yuv2rgb converter with support for rgb444
cehoyos
parents:
30822
diff
changeset
|
1065 dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE ? "dithered " : "", |
30287
67cace3e3df7
Simplify code in sws_getContext() which logs if the destination format
stefano
parents:
30285
diff
changeset
|
1066 #else |
67cace3e3df7
Simplify code in sws_getContext() which logs if the destination format
stefano
parents:
30285
diff
changeset
|
1067 "", |
67cace3e3df7
Simplify code in sws_getContext() which logs if the destination format
stefano
parents:
30285
diff
changeset
|
1068 #endif |
30284
03f99130b7c3
Factorize code which logs the source and destination formats in
stefano
parents:
30275
diff
changeset
|
1069 sws_format_name(dstFormat)); |
18861 | 1070 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1071 if (flags & SWS_CPU_CAPS_MMX2) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1072 av_log(c, AV_LOG_INFO, "using MMX2\n"); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1073 else if (flags & SWS_CPU_CAPS_3DNOW) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1074 av_log(c, AV_LOG_INFO, "using 3DNOW\n"); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1075 else if (flags & SWS_CPU_CAPS_MMX) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1076 av_log(c, AV_LOG_INFO, "using MMX\n"); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1077 else if (flags & SWS_CPU_CAPS_ALTIVEC) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1078 av_log(c, AV_LOG_INFO, "using AltiVec\n"); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1079 else |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1080 av_log(c, AV_LOG_INFO, "using C\n"); |
18861 | 1081 |
29481 | 1082 if (flags & SWS_CPU_CAPS_MMX) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1083 if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1084 av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); |
29481 | 1085 else { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1086 if (c->hLumFilterSize==4) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1087 av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1088 else if (c->hLumFilterSize==8) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1089 av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1090 else |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1091 av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n"); |
18861 | 1092 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1093 if (c->hChrFilterSize==4) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1094 av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1095 else if (c->hChrFilterSize==8) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1096 av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1097 else |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1098 av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1099 } |
29481 | 1100 } else { |
28276 | 1101 #if ARCH_X86 |
28316 | 1102 av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n"); |
18861 | 1103 #else |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1104 if (flags & SWS_FAST_BILINEAR) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1105 av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1106 else |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1107 av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n"); |
18861 | 1108 #endif |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1109 } |
29481 | 1110 if (isPlanarYUV(dstFormat)) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1111 if (c->vLumFilterSize==1) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1112 av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1113 else |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1114 av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
29481 | 1115 } else { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1116 if (c->vLumFilterSize==1 && c->vChrFilterSize==2) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1117 av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" |
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1118 " 2-tap scaler for vertical chrominance scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1119 else if (c->vLumFilterSize==2 && c->vChrFilterSize==2) |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1120 av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1121 else |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1122 av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1123 } |
18861 | 1124 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1125 if (dstFormat==PIX_FMT_BGR24) |
28316 | 1126 av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n", |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1127 (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1128 else if (dstFormat==PIX_FMT_RGB32) |
28316 | 1129 av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1130 else if (dstFormat==PIX_FMT_BGR565) |
28316 | 1131 av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1132 else if (dstFormat==PIX_FMT_BGR555) |
28316 | 1133 av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
30892
e052716dcb5b
Extend the generic path of the yuv2rgb converter with support for rgb444
cehoyos
parents:
30822
diff
changeset
|
1134 else if (dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE || |
e052716dcb5b
Extend the generic path of the yuv2rgb converter with support for rgb444
cehoyos
parents:
30822
diff
changeset
|
1135 dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE) |
e052716dcb5b
Extend the generic path of the yuv2rgb converter with support for rgb444
cehoyos
parents:
30822
diff
changeset
|
1136 av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); |
26150
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1137 |
1df4a811aa9c
remove redundant SwScaler text since av_log uses AVClass context
bcoudurier
parents:
26134
diff
changeset
|
1138 av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); |
28316 | 1139 av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1140 c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); |
28316 | 1141 av_log(c, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1142 c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1143 } |
18861 | 1144 |
30369
8c479cb29c7a
Split swscale.c into scaler code (swscale.c) and utility code (utils.c).
ramiro
parents:
30343
diff
changeset
|
1145 c->swScale= ff_getSwsFunc(c); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1146 return c; |
29542 | 1147 |
1148 fail: | |
1149 sws_freeContext(c); | |
1150 return NULL; | |
18861 | 1151 } |
1152 | |
23129 | 1153 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1154 float lumaSharpen, float chromaSharpen, |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1155 float chromaHShift, float chromaVShift, |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1156 int verbose) |
18861 | 1157 { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1158 SwsFilter *filter= av_malloc(sizeof(SwsFilter)); |
29542 | 1159 if (!filter) |
1160 return NULL; | |
18861 | 1161 |
29481 | 1162 if (lumaGBlur!=0.0) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1163 filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1164 filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0); |
29481 | 1165 } else { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1166 filter->lumH= sws_getIdentityVec(); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1167 filter->lumV= sws_getIdentityVec(); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1168 } |
18861 | 1169 |
29481 | 1170 if (chromaGBlur!=0.0) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1171 filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1172 filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0); |
29481 | 1173 } else { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1174 filter->chrH= sws_getIdentityVec(); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1175 filter->chrV= sws_getIdentityVec(); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1176 } |
18861 | 1177 |
29481 | 1178 if (chromaSharpen!=0.0) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1179 SwsVector *id= sws_getIdentityVec(); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1180 sws_scaleVec(filter->chrH, -chromaSharpen); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1181 sws_scaleVec(filter->chrV, -chromaSharpen); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1182 sws_addVec(filter->chrH, id); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1183 sws_addVec(filter->chrV, id); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1184 sws_freeVec(id); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1185 } |
18861 | 1186 |
29481 | 1187 if (lumaSharpen!=0.0) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1188 SwsVector *id= sws_getIdentityVec(); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1189 sws_scaleVec(filter->lumH, -lumaSharpen); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1190 sws_scaleVec(filter->lumV, -lumaSharpen); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1191 sws_addVec(filter->lumH, id); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1192 sws_addVec(filter->lumV, id); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1193 sws_freeVec(id); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1194 } |
18861 | 1195 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1196 if (chromaHShift != 0.0) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1197 sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5)); |
18861 | 1198 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1199 if (chromaVShift != 0.0) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1200 sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5)); |
18861 | 1201 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1202 sws_normalizeVec(filter->chrH, 1.0); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1203 sws_normalizeVec(filter->chrV, 1.0); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1204 sws_normalizeVec(filter->lumH, 1.0); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1205 sws_normalizeVec(filter->lumV, 1.0); |
18861 | 1206 |
28532
e5a0c2f38f96
Use sws_printVec2() instead of the deprecated sws_printVec().
stefano
parents:
28531
diff
changeset
|
1207 if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG); |
e5a0c2f38f96
Use sws_printVec2() instead of the deprecated sws_printVec().
stefano
parents:
28531
diff
changeset
|
1208 if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG); |
18861 | 1209 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1210 return filter; |
18861 | 1211 } |
1212 | |
29494 | 1213 SwsVector *sws_allocVec(int length) |
1214 { | |
1215 SwsVector *vec = av_malloc(sizeof(SwsVector)); | |
1216 if (!vec) | |
1217 return NULL; | |
1218 vec->length = length; | |
1219 vec->coeff = av_malloc(sizeof(double) * length); | |
1220 if (!vec->coeff) | |
1221 av_freep(&vec); | |
1222 return vec; | |
1223 } | |
1224 | |
29481 | 1225 SwsVector *sws_getGaussianVec(double variance, double quality) |
1226 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1227 const int length= (int)(variance*quality + 0.5) | 1; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1228 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1229 double middle= (length-1)*0.5; |
29494 | 1230 SwsVector *vec= sws_allocVec(length); |
18861 | 1231 |
29501
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1232 if (!vec) |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1233 return NULL; |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1234 |
29481 | 1235 for (i=0; i<length; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1236 double dist= i-middle; |
30370
a8c94e9dc653
Don't redefine M_PI. It is already defined from libavutil/mathematics.h.
ramiro
parents:
30369
diff
changeset
|
1237 vec->coeff[i]= exp(-dist*dist/(2*variance*variance)) / sqrt(2*variance*M_PI); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1238 } |
18861 | 1239 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1240 sws_normalizeVec(vec, 1.0); |
18861 | 1241 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1242 return vec; |
18861 | 1243 } |
1244 | |
29481 | 1245 SwsVector *sws_getConstVec(double c, int length) |
1246 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1247 int i; |
29494 | 1248 SwsVector *vec= sws_allocVec(length); |
18861 | 1249 |
29501
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1250 if (!vec) |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1251 return NULL; |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1252 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1253 for (i=0; i<length; i++) |
29494 | 1254 vec->coeff[i]= c; |
18861 | 1255 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1256 return vec; |
18861 | 1257 } |
1258 | |
29481 | 1259 SwsVector *sws_getIdentityVec(void) |
1260 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1261 return sws_getConstVec(1.0, 1); |
18861 | 1262 } |
1263 | |
30745
c5a49657b3e4
Make sws_dcVec static: It is only used inside libswscale/utils.c.
cehoyos
parents:
30688
diff
changeset
|
1264 static double sws_dcVec(SwsVector *a) |
29481 | 1265 { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1266 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1267 double sum=0; |
18861 | 1268 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1269 for (i=0; i<a->length; i++) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1270 sum+= a->coeff[i]; |
18861 | 1271 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1272 return sum; |
18861 | 1273 } |
1274 | |
29481 | 1275 void sws_scaleVec(SwsVector *a, double scalar) |
1276 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1277 int i; |
18861 | 1278 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1279 for (i=0; i<a->length; i++) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1280 a->coeff[i]*= scalar; |
18861 | 1281 } |
1282 | |
29481 | 1283 void sws_normalizeVec(SwsVector *a, double height) |
1284 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1285 sws_scaleVec(a, height/sws_dcVec(a)); |
18861 | 1286 } |
1287 | |
29481 | 1288 static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b) |
1289 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1290 int length= a->length + b->length - 1; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1291 int i, j; |
29493 | 1292 SwsVector *vec= sws_getConstVec(0.0, length); |
18861 | 1293 |
29501
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1294 if (!vec) |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1295 return NULL; |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1296 |
29481 | 1297 for (i=0; i<a->length; i++) { |
1298 for (j=0; j<b->length; j++) { | |
29493 | 1299 vec->coeff[i+j]+= a->coeff[i]*b->coeff[j]; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1300 } |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1301 } |
18861 | 1302 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1303 return vec; |
18861 | 1304 } |
1305 | |
29481 | 1306 static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b) |
1307 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1308 int length= FFMAX(a->length, b->length); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1309 int i; |
29493 | 1310 SwsVector *vec= sws_getConstVec(0.0, length); |
1311 | |
29501
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1312 if (!vec) |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1313 return NULL; |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1314 |
29493 | 1315 for (i=0; i<a->length; i++) vec->coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; |
1316 for (i=0; i<b->length; i++) vec->coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i]; | |
18861 | 1317 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1318 return vec; |
18861 | 1319 } |
1320 | |
29481 | 1321 static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b) |
1322 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1323 int length= FFMAX(a->length, b->length); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1324 int i; |
29493 | 1325 SwsVector *vec= sws_getConstVec(0.0, length); |
1326 | |
29501
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1327 if (!vec) |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1328 return NULL; |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1329 |
29493 | 1330 for (i=0; i<a->length; i++) vec->coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; |
1331 for (i=0; i<b->length; i++) vec->coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i]; | |
18861 | 1332 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1333 return vec; |
18861 | 1334 } |
1335 | |
1336 /* shift left / or right if "shift" is negative */ | |
29481 | 1337 static SwsVector *sws_getShiftedVec(SwsVector *a, int shift) |
1338 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1339 int length= a->length + FFABS(shift)*2; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1340 int i; |
29493 | 1341 SwsVector *vec= sws_getConstVec(0.0, length); |
18861 | 1342 |
29501
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1343 if (!vec) |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1344 return NULL; |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1345 |
29481 | 1346 for (i=0; i<a->length; i++) { |
29493 | 1347 vec->coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i]; |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1348 } |
18861 | 1349 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1350 return vec; |
18861 | 1351 } |
1352 | |
29481 | 1353 void sws_shiftVec(SwsVector *a, int shift) |
1354 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1355 SwsVector *shifted= sws_getShiftedVec(a, shift); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1356 av_free(a->coeff); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1357 a->coeff= shifted->coeff; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1358 a->length= shifted->length; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1359 av_free(shifted); |
18861 | 1360 } |
1361 | |
29481 | 1362 void sws_addVec(SwsVector *a, SwsVector *b) |
1363 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1364 SwsVector *sum= sws_sumVec(a, b); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1365 av_free(a->coeff); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1366 a->coeff= sum->coeff; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1367 a->length= sum->length; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1368 av_free(sum); |
18861 | 1369 } |
1370 | |
29481 | 1371 void sws_subVec(SwsVector *a, SwsVector *b) |
1372 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1373 SwsVector *diff= sws_diffVec(a, b); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1374 av_free(a->coeff); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1375 a->coeff= diff->coeff; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1376 a->length= diff->length; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1377 av_free(diff); |
18861 | 1378 } |
1379 | |
29481 | 1380 void sws_convVec(SwsVector *a, SwsVector *b) |
1381 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1382 SwsVector *conv= sws_getConvVec(a, b); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1383 av_free(a->coeff); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1384 a->coeff= conv->coeff; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1385 a->length= conv->length; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1386 av_free(conv); |
18861 | 1387 } |
1388 | |
29481 | 1389 SwsVector *sws_cloneVec(SwsVector *a) |
1390 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1391 int i; |
29494 | 1392 SwsVector *vec= sws_allocVec(a->length); |
1393 | |
29501
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1394 if (!vec) |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1395 return NULL; |
a0ba51e33912
Check return values of sws_allocVec() and sws_getConstVec().
ramiro
parents:
29494
diff
changeset
|
1396 |
29494 | 1397 for (i=0; i<a->length; i++) vec->coeff[i]= a->coeff[i]; |
18861 | 1398 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1399 return vec; |
18861 | 1400 } |
1401 | |
29481 | 1402 void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level) |
1403 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1404 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1405 double max=0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1406 double min=0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1407 double range; |
18861 | 1408 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1409 for (i=0; i<a->length; i++) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1410 if (a->coeff[i]>max) max= a->coeff[i]; |
18861 | 1411 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1412 for (i=0; i<a->length; i++) |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1413 if (a->coeff[i]<min) min= a->coeff[i]; |
18861 | 1414 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1415 range= max - min; |
18861 | 1416 |
29481 | 1417 for (i=0; i<a->length; i++) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1418 int x= (int)((a->coeff[i]-min)*60.0/range +0.5); |
28531
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1419 av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]); |
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1420 for (;x>0; x--) av_log(log_ctx, log_level, " "); |
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1421 av_log(log_ctx, log_level, "|\n"); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1422 } |
18861 | 1423 } |
1424 | |
28531
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1425 #if LIBSWSCALE_VERSION_MAJOR < 1 |
29481 | 1426 void sws_printVec(SwsVector *a) |
1427 { | |
28531
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1428 sws_printVec2(a, NULL, AV_LOG_DEBUG); |
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1429 } |
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1430 #endif |
a14b65e14dc9
Implement sws_printVec2() and deprecate sws_printVec().
stefano
parents:
28520
diff
changeset
|
1431 |
29481 | 1432 void sws_freeVec(SwsVector *a) |
1433 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1434 if (!a) return; |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1435 av_freep(&a->coeff); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1436 a->length=0; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1437 av_free(a); |
18861 | 1438 } |
1439 | |
29481 | 1440 void sws_freeFilter(SwsFilter *filter) |
1441 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1442 if (!filter) return; |
18861 | 1443 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1444 if (filter->lumH) sws_freeVec(filter->lumH); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1445 if (filter->lumV) sws_freeVec(filter->lumV); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1446 if (filter->chrH) sws_freeVec(filter->chrH); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1447 if (filter->chrV) sws_freeVec(filter->chrV); |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1448 av_free(filter); |
18861 | 1449 } |
1450 | |
29481 | 1451 void sws_freeContext(SwsContext *c) |
1452 { | |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1453 int i; |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1454 if (!c) return; |
18861 | 1455 |
29481 | 1456 if (c->lumPixBuf) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1457 for (i=0; i<c->vLumBufSize; i++) |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1458 av_freep(&c->lumPixBuf[i]); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1459 av_freep(&c->lumPixBuf); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1460 } |
18861 | 1461 |
29481 | 1462 if (c->chrPixBuf) { |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1463 for (i=0; i<c->vChrBufSize; i++) |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1464 av_freep(&c->chrPixBuf[i]); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1465 av_freep(&c->chrPixBuf); |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1466 } |
18861 | 1467 |
29481 | 1468 if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { |
28976 | 1469 for (i=0; i<c->vLumBufSize; i++) |
1470 av_freep(&c->alpPixBuf[i]); | |
1471 av_freep(&c->alpPixBuf); | |
1472 } | |
1473 | |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1474 av_freep(&c->vLumFilter); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1475 av_freep(&c->vChrFilter); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1476 av_freep(&c->hLumFilter); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1477 av_freep(&c->hChrFilter); |
30912
f91ad62a2281
AltiVec implies a PPC CPU, so there is no need to check for both.
diego
parents:
30910
diff
changeset
|
1478 #if HAVE_ALTIVEC |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1479 av_freep(&c->vYCoeffsBank); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1480 av_freep(&c->vCCoeffsBank); |
18861 | 1481 #endif |
1482 | |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1483 av_freep(&c->vLumFilterPos); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1484 av_freep(&c->vChrFilterPos); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1485 av_freep(&c->hLumFilterPos); |
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1486 av_freep(&c->hChrFilterPos); |
18861 | 1487 |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
1488 #if ARCH_X86 |
18861 | 1489 #ifdef MAP_ANONYMOUS |
29468
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
1490 if (c->lumMmx2FilterCode) munmap(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize); |
947a942221c4
MMX2 horizontal scaler: Determine code size at runtime.
ramiro
parents:
29467
diff
changeset
|
1491 if (c->chrMmx2FilterCode) munmap(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize); |
28971
b8e356a9dbb1
Allocate executable memory with VirtualAlloc() in Windows.
ramiro
parents:
28970
diff
changeset
|
1492 #elif HAVE_VIRTUALALLOC |
30821
d59dfdf82fca
Fix memleak due to incorrect VirtualFree arguments: size must be 0 for MEM_RELEASE.
reimar
parents:
30814
diff
changeset
|
1493 if (c->lumMmx2FilterCode) VirtualFree(c->lumMmx2FilterCode, 0, MEM_RELEASE); |
d59dfdf82fca
Fix memleak due to incorrect VirtualFree arguments: size must be 0 for MEM_RELEASE.
reimar
parents:
30814
diff
changeset
|
1494 if (c->chrMmx2FilterCode) VirtualFree(c->chrMmx2FilterCode, 0, MEM_RELEASE); |
18861 | 1495 #else |
29465 | 1496 av_free(c->lumMmx2FilterCode); |
1497 av_free(c->chrMmx2FilterCode); | |
18861 | 1498 #endif |
29465 | 1499 c->lumMmx2FilterCode=NULL; |
1500 c->chrMmx2FilterCode=NULL; | |
30923
0be6ed163321
libswscale: Relicense almost all x86 assembler optimizations as LGPL.
diego
parents:
30912
diff
changeset
|
1501 #endif /* ARCH_X86 */ |
18861 | 1502 |
27299
4e57d47ee5db
Cleanup, use av_freep() instead of av_free(x); x=NULL
michael
parents:
27286
diff
changeset
|
1503 av_freep(&c->yuvTable); |
18861 | 1504 |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1505 av_free(c); |
18861 | 1506 } |
1507 | |
19661
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
1508 struct SwsContext *sws_getCachedContext(struct SwsContext *context, |
27695
9cf6c7c5c7cd
Change variable types from int to enum PixelFormat.
cehoyos
parents:
27686
diff
changeset
|
1509 int srcW, int srcH, enum PixelFormat srcFormat, |
9cf6c7c5c7cd
Change variable types from int to enum PixelFormat.
cehoyos
parents:
27686
diff
changeset
|
1510 int dstW, int dstH, enum PixelFormat dstFormat, int flags, |
29246
8861e08033eb
Add const qualifier to param argument of sws_getContext() and
diego
parents:
29245
diff
changeset
|
1511 SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param) |
19661
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
1512 { |
25747 | 1513 static const double default_param[2] = {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT}; |
1514 | |
1515 if (!param) | |
1516 param = default_param; | |
1517 | |
31968
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
1518 flags = update_flags_cpu(flags); |
5c9310a4d2e9
swscale: also update flags on sws_getCachedContext()
ramiro
parents:
31903
diff
changeset
|
1519 |
30599
7c1fea45bfc8
Merge two if conditions, allow to decrese the level of indentation of
stefano
parents:
30478
diff
changeset
|
1520 if (context && |
30600
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1521 (context->srcW != srcW || |
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1522 context->srcH != srcH || |
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1523 context->srcFormat != srcFormat || |
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1524 context->dstW != dstW || |
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1525 context->dstH != dstH || |
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1526 context->dstFormat != dstFormat || |
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1527 context->flags != flags || |
e2935c75f1aa
Vertically align a list of comparisons in sws_getCachedContext().
stefano
parents:
30599
diff
changeset
|
1528 context->param[0] != param[0] || |
30601 | 1529 context->param[1] != param[1])) { |
1530 sws_freeContext(context); | |
1531 context = NULL; | |
1532 } | |
30599
7c1fea45bfc8
Merge two if conditions, allow to decrese the level of indentation of
stefano
parents:
30478
diff
changeset
|
1533 |
25752
559b0e9d47fb
Change (a == NULL) condition to (!a) and (a != NULL) condition to (a).
benoit
parents:
25750
diff
changeset
|
1534 if (!context) { |
19661
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
1535 return sws_getContext(srcW, srcH, srcFormat, |
23155
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1536 dstW, dstH, dstFormat, flags, |
1befc8d767cd
cosmetics attack, part II: Remove all tabs and prettyprint/reindent the code.
diego
parents:
23129
diff
changeset
|
1537 srcFilter, dstFilter, param); |
19661
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
1538 } |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
1539 return context; |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
1540 } |
7b24faac56fd
Add sws_getCachedContext(), which checks if context is valid or reallocs a new one instead.
gpoirier
parents:
19594
diff
changeset
|
1541 |