annotate libswscale/utils.c @ 30923:0be6ed163321

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