~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libswscale/utils.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 */
20
20
 
 
21
#define _SVID_SOURCE //needed for MAP_ANONYMOUS
21
22
#include <inttypes.h>
22
23
#include <string.h>
23
24
#include <math.h>
42
43
#include "libavutil/cpu.h"
43
44
#include "libavutil/avutil.h"
44
45
#include "libavutil/bswap.h"
 
46
#include "libavutil/mathematics.h"
45
47
#include "libavutil/opt.h"
46
48
#include "libavutil/pixdesc.h"
47
49
 
63
65
 
64
66
#define RET 0xC3 //near return opcode for x86
65
67
 
66
 
#define isSupportedIn(x)    (       \
67
 
           (x)==PIX_FMT_YUV420P     \
68
 
        || (x)==PIX_FMT_YUVA420P    \
69
 
        || (x)==PIX_FMT_YUYV422     \
70
 
        || (x)==PIX_FMT_UYVY422     \
71
 
        || (x)==PIX_FMT_RGB48BE     \
72
 
        || (x)==PIX_FMT_RGB48LE     \
73
 
        || (x)==PIX_FMT_RGB32       \
74
 
        || (x)==PIX_FMT_RGB32_1     \
75
 
        || (x)==PIX_FMT_BGR48BE     \
76
 
        || (x)==PIX_FMT_BGR48LE     \
77
 
        || (x)==PIX_FMT_BGR24       \
78
 
        || (x)==PIX_FMT_BGR565LE    \
79
 
        || (x)==PIX_FMT_BGR565BE    \
80
 
        || (x)==PIX_FMT_BGR555LE    \
81
 
        || (x)==PIX_FMT_BGR555BE    \
82
 
        || (x)==PIX_FMT_BGR32       \
83
 
        || (x)==PIX_FMT_BGR32_1     \
84
 
        || (x)==PIX_FMT_RGB24       \
85
 
        || (x)==PIX_FMT_RGB565LE    \
86
 
        || (x)==PIX_FMT_RGB565BE    \
87
 
        || (x)==PIX_FMT_RGB555LE    \
88
 
        || (x)==PIX_FMT_RGB555BE    \
89
 
        || (x)==PIX_FMT_GRAY8       \
90
 
        || (x)==PIX_FMT_Y400A       \
91
 
        || (x)==PIX_FMT_YUV410P     \
92
 
        || (x)==PIX_FMT_YUV440P     \
93
 
        || (x)==PIX_FMT_NV12        \
94
 
        || (x)==PIX_FMT_NV21        \
95
 
        || (x)==PIX_FMT_GRAY16BE    \
96
 
        || (x)==PIX_FMT_GRAY16LE    \
97
 
        || (x)==PIX_FMT_YUV444P     \
98
 
        || (x)==PIX_FMT_YUV422P     \
99
 
        || (x)==PIX_FMT_YUV411P     \
100
 
        || (x)==PIX_FMT_YUVJ420P    \
101
 
        || (x)==PIX_FMT_YUVJ422P    \
102
 
        || (x)==PIX_FMT_YUVJ440P    \
103
 
        || (x)==PIX_FMT_YUVJ444P    \
104
 
        || (x)==PIX_FMT_PAL8        \
105
 
        || (x)==PIX_FMT_BGR8        \
106
 
        || (x)==PIX_FMT_RGB8        \
107
 
        || (x)==PIX_FMT_BGR4_BYTE   \
108
 
        || (x)==PIX_FMT_RGB4_BYTE   \
109
 
        || (x)==PIX_FMT_YUV440P     \
110
 
        || (x)==PIX_FMT_MONOWHITE   \
111
 
        || (x)==PIX_FMT_MONOBLACK   \
112
 
        || (x)==PIX_FMT_YUV420P9LE    \
113
 
        || (x)==PIX_FMT_YUV444P9LE    \
114
 
        || (x)==PIX_FMT_YUV420P10LE   \
115
 
        || (x)==PIX_FMT_YUV422P10LE   \
116
 
        || (x)==PIX_FMT_YUV444P10LE   \
117
 
        || (x)==PIX_FMT_YUV420P16LE   \
118
 
        || (x)==PIX_FMT_YUV422P16LE   \
119
 
        || (x)==PIX_FMT_YUV444P16LE   \
120
 
        || (x)==PIX_FMT_YUV420P9BE    \
121
 
        || (x)==PIX_FMT_YUV444P9BE    \
122
 
        || (x)==PIX_FMT_YUV420P10BE   \
123
 
        || (x)==PIX_FMT_YUV444P10BE   \
124
 
        || (x)==PIX_FMT_YUV422P10BE   \
125
 
        || (x)==PIX_FMT_YUV420P16BE   \
126
 
        || (x)==PIX_FMT_YUV422P16BE   \
127
 
        || (x)==PIX_FMT_YUV444P16BE   \
128
 
    )
 
68
typedef struct FormatEntry {
 
69
    int is_supported_in, is_supported_out;
 
70
} FormatEntry;
 
71
 
 
72
const static FormatEntry format_entries[PIX_FMT_NB] = {
 
73
    [PIX_FMT_YUV420P]     = { 1 , 1 },
 
74
    [PIX_FMT_YUYV422]     = { 1 , 1 },
 
75
    [PIX_FMT_RGB24]       = { 1 , 1 },
 
76
    [PIX_FMT_BGR24]       = { 1 , 1 },
 
77
    [PIX_FMT_YUV422P]     = { 1 , 1 },
 
78
    [PIX_FMT_YUV444P]     = { 1 , 1 },
 
79
    [PIX_FMT_YUV410P]     = { 1 , 1 },
 
80
    [PIX_FMT_YUV411P]     = { 1 , 1 },
 
81
    [PIX_FMT_GRAY8]       = { 1 , 1 },
 
82
    [PIX_FMT_MONOWHITE]   = { 1 , 1 },
 
83
    [PIX_FMT_MONOBLACK]   = { 1 , 1 },
 
84
    [PIX_FMT_PAL8]        = { 1 , 0 },
 
85
    [PIX_FMT_YUVJ420P]    = { 1 , 1 },
 
86
    [PIX_FMT_YUVJ422P]    = { 1 , 1 },
 
87
    [PIX_FMT_YUVJ444P]    = { 1 , 1 },
 
88
    [PIX_FMT_UYVY422]     = { 1 , 1 },
 
89
    [PIX_FMT_UYYVYY411]   = { 0 , 0 },
 
90
    [PIX_FMT_BGR8]        = { 1 , 1 },
 
91
    [PIX_FMT_BGR4]        = { 0 , 1 },
 
92
    [PIX_FMT_BGR4_BYTE]   = { 1 , 1 },
 
93
    [PIX_FMT_RGB8]        = { 1 , 1 },
 
94
    [PIX_FMT_RGB4]        = { 0 , 1 },
 
95
    [PIX_FMT_RGB4_BYTE]   = { 1 , 1 },
 
96
    [PIX_FMT_NV12]        = { 1 , 1 },
 
97
    [PIX_FMT_NV21]        = { 1 , 1 },
 
98
    [PIX_FMT_ARGB]        = { 1 , 1 },
 
99
    [PIX_FMT_RGBA]        = { 1 , 1 },
 
100
    [PIX_FMT_ABGR]        = { 1 , 1 },
 
101
    [PIX_FMT_BGRA]        = { 1 , 1 },
 
102
    [PIX_FMT_GRAY16BE]    = { 1 , 1 },
 
103
    [PIX_FMT_GRAY16LE]    = { 1 , 1 },
 
104
    [PIX_FMT_YUV440P]     = { 1 , 1 },
 
105
    [PIX_FMT_YUVJ440P]    = { 1 , 1 },
 
106
    [PIX_FMT_YUVA420P]    = { 1 , 1 },
 
107
    [PIX_FMT_RGB48BE]     = { 1 , 1 },
 
108
    [PIX_FMT_RGB48LE]     = { 1 , 1 },
 
109
    [PIX_FMT_RGB565BE]    = { 1 , 1 },
 
110
    [PIX_FMT_RGB565LE]    = { 1 , 1 },
 
111
    [PIX_FMT_RGB555BE]    = { 1 , 1 },
 
112
    [PIX_FMT_RGB555LE]    = { 1 , 1 },
 
113
    [PIX_FMT_BGR565BE]    = { 1 , 1 },
 
114
    [PIX_FMT_BGR565LE]    = { 1 , 1 },
 
115
    [PIX_FMT_BGR555BE]    = { 1 , 1 },
 
116
    [PIX_FMT_BGR555LE]    = { 1 , 1 },
 
117
    [PIX_FMT_YUV420P16LE] = { 1 , 1 },
 
118
    [PIX_FMT_YUV420P16BE] = { 1 , 1 },
 
119
    [PIX_FMT_YUV422P16LE] = { 1 , 1 },
 
120
    [PIX_FMT_YUV422P16BE] = { 1 , 1 },
 
121
    [PIX_FMT_YUV444P16LE] = { 1 , 1 },
 
122
    [PIX_FMT_YUV444P16BE] = { 1 , 1 },
 
123
    [PIX_FMT_RGB444LE]    = { 1 , 1 },
 
124
    [PIX_FMT_RGB444BE]    = { 1 , 1 },
 
125
    [PIX_FMT_BGR444LE]    = { 1 , 1 },
 
126
    [PIX_FMT_BGR444BE]    = { 1 , 1 },
 
127
    [PIX_FMT_Y400A]       = { 1 , 0 },
 
128
    [PIX_FMT_BGR48BE]     = { 1 , 1 },
 
129
    [PIX_FMT_BGR48LE]     = { 1 , 1 },
 
130
    [PIX_FMT_YUV420P9BE]  = { 1 , 1 },
 
131
    [PIX_FMT_YUV420P9LE]  = { 1 , 1 },
 
132
    [PIX_FMT_YUV420P10BE] = { 1 , 1 },
 
133
    [PIX_FMT_YUV420P10LE] = { 1 , 1 },
 
134
    [PIX_FMT_YUV422P9BE]  = { 1 , 1 },
 
135
    [PIX_FMT_YUV422P9LE]  = { 1 , 1 },
 
136
    [PIX_FMT_YUV422P10BE] = { 1 , 1 },
 
137
    [PIX_FMT_YUV422P10LE] = { 1 , 1 },
 
138
    [PIX_FMT_YUV444P9BE]  = { 1 , 1 },
 
139
    [PIX_FMT_YUV444P9LE]  = { 1 , 1 },
 
140
    [PIX_FMT_YUV444P10BE] = { 1 , 1 },
 
141
    [PIX_FMT_YUV444P10LE] = { 1 , 1 },
 
142
    [PIX_FMT_GBRP]        = { 1 , 0 },
 
143
    [PIX_FMT_GBRP9LE]     = { 1 , 0 },
 
144
    [PIX_FMT_GBRP9BE]     = { 1 , 0 },
 
145
    [PIX_FMT_GBRP10LE]    = { 1 , 0 },
 
146
    [PIX_FMT_GBRP10BE]    = { 1 , 0 },
 
147
    [PIX_FMT_GBRP16LE]    = { 1 , 0 },
 
148
    [PIX_FMT_GBRP16BE]    = { 1 , 0 },
 
149
};
129
150
 
130
151
int sws_isSupportedInput(enum PixelFormat pix_fmt)
131
152
{
132
 
    return isSupportedIn(pix_fmt);
 
153
    return (unsigned)pix_fmt < PIX_FMT_NB ?
 
154
        format_entries[pix_fmt].is_supported_in : 0;
133
155
}
134
156
 
135
 
#define isSupportedOut(x)   (       \
136
 
           (x)==PIX_FMT_YUV420P     \
137
 
        || (x)==PIX_FMT_YUVA420P    \
138
 
        || (x)==PIX_FMT_YUYV422     \
139
 
        || (x)==PIX_FMT_UYVY422     \
140
 
        || (x)==PIX_FMT_YUV444P     \
141
 
        || (x)==PIX_FMT_YUV422P     \
142
 
        || (x)==PIX_FMT_YUV411P     \
143
 
        || (x)==PIX_FMT_YUVJ420P    \
144
 
        || (x)==PIX_FMT_YUVJ422P    \
145
 
        || (x)==PIX_FMT_YUVJ440P    \
146
 
        || (x)==PIX_FMT_YUVJ444P    \
147
 
        || isRGBinBytes(x)          \
148
 
        || isBGRinBytes(x)          \
149
 
        || (x)==PIX_FMT_RGB565      \
150
 
        || (x)==PIX_FMT_RGB555      \
151
 
        || (x)==PIX_FMT_RGB444      \
152
 
        || (x)==PIX_FMT_BGR565      \
153
 
        || (x)==PIX_FMT_BGR555      \
154
 
        || (x)==PIX_FMT_BGR444      \
155
 
        || (x)==PIX_FMT_RGB8        \
156
 
        || (x)==PIX_FMT_BGR8        \
157
 
        || (x)==PIX_FMT_RGB4_BYTE   \
158
 
        || (x)==PIX_FMT_BGR4_BYTE   \
159
 
        || (x)==PIX_FMT_RGB4        \
160
 
        || (x)==PIX_FMT_BGR4        \
161
 
        || (x)==PIX_FMT_MONOBLACK   \
162
 
        || (x)==PIX_FMT_MONOWHITE   \
163
 
        || (x)==PIX_FMT_NV12        \
164
 
        || (x)==PIX_FMT_NV21        \
165
 
        || (x)==PIX_FMT_GRAY16BE    \
166
 
        || (x)==PIX_FMT_GRAY16LE    \
167
 
        || (x)==PIX_FMT_GRAY8       \
168
 
        || (x)==PIX_FMT_YUV410P     \
169
 
        || (x)==PIX_FMT_YUV440P     \
170
 
        || (x)==PIX_FMT_YUV420P9LE    \
171
 
        || (x)==PIX_FMT_YUV420P10LE   \
172
 
        || (x)==PIX_FMT_YUV420P16LE   \
173
 
        || (x)==PIX_FMT_YUV422P16LE   \
174
 
        || (x)==PIX_FMT_YUV444P16LE   \
175
 
        || (x)==PIX_FMT_YUV420P9BE    \
176
 
        || (x)==PIX_FMT_YUV420P10BE   \
177
 
        || (x)==PIX_FMT_YUV420P16BE   \
178
 
        || (x)==PIX_FMT_YUV422P16BE   \
179
 
        || (x)==PIX_FMT_YUV444P16BE   \
180
 
    )
181
 
 
182
157
int sws_isSupportedOutput(enum PixelFormat pix_fmt)
183
158
{
184
 
    return isSupportedOut(pix_fmt);
 
159
    return (unsigned)pix_fmt < PIX_FMT_NB ?
 
160
        format_entries[pix_fmt].is_supported_out : 0;
185
161
}
186
162
 
187
163
extern const int32_t ff_yuv2rgb_coeffs[8][4];
206
182
 
207
183
static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc,
208
184
                      int srcW, int dstW, int filterAlign, int one, int flags, int cpu_flags,
209
 
                      SwsVector *srcFilter, SwsVector *dstFilter, double param[2])
 
185
                      SwsVector *srcFilter, SwsVector *dstFilter, double param[2], int is_horizontal)
210
186
{
211
187
    int i;
212
188
    int filterSize;
219
195
 
220
196
    emms_c(); //FIXME this should not be required but it IS (even for non-MMX versions)
221
197
 
222
 
    // NOTE: the +1 is for the MMX scaler which reads over the end
223
 
    FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW+1)*sizeof(int16_t), fail);
 
198
    // NOTE: the +3 is for the MMX(+1)/SSE(+3) scaler which reads over the end
 
199
    FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW+3)*sizeof(int16_t), fail);
224
200
 
225
201
    if (FFABS(xInc - 0x10000) <10) { // unscaled
226
202
        int i;
308
284
                if (flags & SWS_BICUBIC) {
309
285
                    int64_t B= (param[0] != SWS_PARAM_DEFAULT ? param[0] :   0) * (1<<24);
310
286
                    int64_t C= (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1<<24);
311
 
                    int64_t dd = ( d*d)>>30;
312
 
                    int64_t ddd= (dd*d)>>30;
313
 
 
314
 
                    if      (d < 1LL<<30)
315
 
                        coeff = (12*(1<<24)-9*B-6*C)*ddd + (-18*(1<<24)+12*B+6*C)*dd + (6*(1<<24)-2*B)*(1<<30);
316
 
                    else if (d < 1LL<<31)
317
 
                        coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30);
318
 
                    else
319
 
                        coeff=0.0;
 
287
 
 
288
                    if (d >= 1LL<<31) {
 
289
                        coeff = 0.0;
 
290
                    } else {
 
291
                        int64_t dd  = (d  * d) >> 30;
 
292
                        int64_t ddd = (dd * d) >> 30;
 
293
 
 
294
                        if (d < 1LL<<30)
 
295
                            coeff = (12*(1<<24)-9*B-6*C)*ddd + (-18*(1<<24)+12*B+6*C)*dd + (6*(1<<24)-2*B)*(1<<30);
 
296
                        else
 
297
                            coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30);
 
298
                    }
320
299
                    coeff *= fone>>(30+24);
321
300
                }
322
301
/*                else if (flags & SWS_X) {
480
459
    //FIXME try to align filterPos if possible
481
460
 
482
461
    //fix borders
483
 
    for (i=0; i<dstW; i++) {
484
 
        int j;
485
 
        if ((*filterPos)[i] < 0) {
486
 
            // move filter coefficients left to compensate for filterPos
487
 
            for (j=1; j<filterSize; j++) {
488
 
                int left= FFMAX(j + (*filterPos)[i], 0);
489
 
                filter[i*filterSize + left] += filter[i*filterSize + j];
490
 
                filter[i*filterSize + j]=0;
 
462
    if (is_horizontal) {
 
463
        for (i = 0; i < dstW; i++) {
 
464
            int j;
 
465
            if ((*filterPos)[i] < 0) {
 
466
                // move filter coefficients left to compensate for filterPos
 
467
                for (j = 1; j < filterSize; j++) {
 
468
                    int left = FFMAX(j + (*filterPos)[i], 0);
 
469
                    filter[i * filterSize + left] += filter[i * filterSize + j];
 
470
                    filter[i * filterSize + j   ]  = 0;
 
471
                }
 
472
                (*filterPos)[i] = 0;
491
473
            }
492
 
            (*filterPos)[i]= 0;
493
 
        }
494
474
 
495
 
        if ((*filterPos)[i] + filterSize > srcW) {
496
 
            int shift= (*filterPos)[i] + filterSize - srcW;
497
 
            // move filter coefficients right to compensate for filterPos
498
 
            for (j=filterSize-2; j>=0; j--) {
499
 
                int right= FFMIN(j + shift, filterSize-1);
500
 
                filter[i*filterSize +right] += filter[i*filterSize +j];
501
 
                filter[i*filterSize +j]=0;
 
475
            if ((*filterPos)[i] + filterSize > srcW) {
 
476
                int shift = (*filterPos)[i] + filterSize - srcW;
 
477
                // move filter coefficients right to compensate for filterPos
 
478
                for (j = filterSize - 2; j >= 0; j--) {
 
479
                    int right = FFMIN(j + shift, filterSize - 1);
 
480
                    filter[i * filterSize + right] += filter[i * filterSize + j];
 
481
                    filter[i * filterSize + j    ]  = 0;
 
482
                }
 
483
                (*filterPos)[i] = srcW - filterSize;
502
484
            }
503
 
            (*filterPos)[i]= srcW - filterSize;
504
485
        }
505
486
    }
506
487
 
507
488
    // Note the +1 is for the MMX scaler which reads over the end
508
489
    /* align at 16 for AltiVec (needed by hScale_altivec_real) */
509
 
    FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize*(dstW+1)*sizeof(int16_t), fail);
 
490
    FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize*(dstW+3)*sizeof(int16_t), fail);
510
491
 
511
492
    /* normalize & store in outFilter */
512
493
    for (i=0; i<dstW; i++) {
526
507
        }
527
508
    }
528
509
 
529
 
    (*filterPos)[dstW]= (*filterPos)[dstW-1]; // the MMX scaler will read over the end
 
510
    (*filterPos)[dstW+0] =
 
511
    (*filterPos)[dstW+1] =
 
512
    (*filterPos)[dstW+2] = (*filterPos)[dstW-1]; // the MMX/SSE scaler will read over the end
530
513
    for (i=0; i<*outFilterSize; i++) {
531
 
        int j= dstW*(*outFilterSize);
532
 
        (*outFilter)[j + i]= (*outFilter)[j + i - (*outFilterSize)];
 
514
        int k= (dstW - 1) * (*outFilterSize) + i;
 
515
        (*outFilter)[k + 1 * (*outFilterSize)] =
 
516
        (*outFilter)[k + 2 * (*outFilterSize)] =
 
517
        (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];
533
518
    }
534
519
 
535
520
    ret=0;
705
690
    *v = av_pix_fmt_descriptors[format].log2_chroma_h;
706
691
}
707
692
 
708
 
int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
 
693
int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
 
694
                             int srcRange, const int table[4], int dstRange,
 
695
                             int brightness, int contrast, int saturation)
709
696
{
710
697
    memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4);
711
698
    memcpy(c->dstColorspaceTable,     table, sizeof(int)*4);
728
715
    return 0;
729
716
}
730
717
 
731
 
int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
 
718
int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
 
719
                             int *srcRange, int **table, int *dstRange,
 
720
                             int *brightness, int *contrast, int *saturation)
732
721
{
733
722
    if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1;
734
723
 
786
775
 
787
776
    unscaled = (srcW == dstW && srcH == dstH);
788
777
 
789
 
    if (!isSupportedIn(srcFormat)) {
 
778
    if (!sws_isSupportedInput(srcFormat)) {
790
779
        av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(srcFormat));
791
780
        return AVERROR(EINVAL);
792
781
    }
793
 
    if (!isSupportedOut(dstFormat)) {
 
782
    if (!sws_isSupportedOutput(dstFormat)) {
794
783
        av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(dstFormat));
795
784
        return AVERROR(EINVAL);
796
785
    }
839
828
    getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);
840
829
 
841
830
    // reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation
 
831
    if (flags & SWS_FULL_CHR_H_INT &&
 
832
        isAnyRGB(dstFormat)       &&
 
833
        dstFormat != PIX_FMT_RGBA &&
 
834
        dstFormat != PIX_FMT_ARGB &&
 
835
        dstFormat != PIX_FMT_BGRA &&
 
836
        dstFormat != PIX_FMT_ABGR &&
 
837
        dstFormat != PIX_FMT_RGB24 &&
 
838
        dstFormat != PIX_FMT_BGR24) {
 
839
        av_log(c, AV_LOG_ERROR,
 
840
               "full chroma interpolation for destination format '%s' not yet implemented\n",
 
841
               sws_format_name(dstFormat));
 
842
        flags &= ~SWS_FULL_CHR_H_INT;
 
843
        c->flags = flags;
 
844
    }
842
845
    if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1;
843
846
 
844
847
    // drop some chroma lines if the user wants it
871
874
        }
872
875
    }
873
876
 
874
 
    FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW, 16) * 2, fail);
875
 
    if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) {
 
877
    c->srcBpc = 1 + av_pix_fmt_descriptors[srcFormat].comp[0].depth_minus1;
 
878
    if (c->srcBpc < 8)
 
879
        c->srcBpc = 8;
 
880
    c->dstBpc = 1 + av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1;
 
881
    if (c->dstBpc < 8)
 
882
        c->dstBpc = 8;
 
883
    if (c->dstBpc == 16)
 
884
        dst_stride <<= 1;
 
885
    FF_ALLOC_OR_GOTO(c, c->formatConvBuffer,
 
886
                     (FFALIGN(srcW, 16) * 2 * FFALIGN(c->srcBpc, 8) >> 3) + 16,
 
887
                     fail);
 
888
    if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && c->srcBpc == 8 && c->dstBpc <= 10) {
876
889
        c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0;
877
890
        if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) {
878
891
            if (flags&SWS_PRINT_INFO)
948
961
            if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc,
949
962
                           srcW      ,       dstW, filterAlign, 1<<14,
950
963
                           (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC)  : flags, cpu_flags,
951
 
                           srcFilter->lumH, dstFilter->lumH, c->param) < 0)
 
964
                           srcFilter->lumH, dstFilter->lumH, c->param, 1) < 0)
952
965
                goto fail;
953
966
            if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc,
954
967
                           c->chrSrcW, c->chrDstW, filterAlign, 1<<14,
955
968
                           (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags,
956
 
                           srcFilter->chrH, dstFilter->chrH, c->param) < 0)
 
969
                           srcFilter->chrH, dstFilter->chrH, c->param, 1) < 0)
957
970
                goto fail;
958
971
        }
959
972
    } // initialize horizontal stuff
961
974
    /* precalculate vertical scaler filter coefficients */
962
975
    {
963
976
        const int filterAlign=
964
 
            (HAVE_MMX     && cpu_flags & AV_CPU_FLAG_MMX) && (flags & SWS_ACCURATE_RND) ? 2 :
 
977
            (HAVE_MMX     && cpu_flags & AV_CPU_FLAG_MMX) ? 2 :
965
978
            (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :
966
979
            1;
967
980
 
968
981
        if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc,
969
982
                       srcH      ,        dstH, filterAlign, (1<<12),
970
983
                       (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC)  : flags, cpu_flags,
971
 
                       srcFilter->lumV, dstFilter->lumV, c->param) < 0)
 
984
                       srcFilter->lumV, dstFilter->lumV, c->param, 0) < 0)
972
985
            goto fail;
973
986
        if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc,
974
987
                       c->chrSrcH, c->chrDstH, filterAlign, (1<<12),
975
988
                       (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags,
976
 
                       srcFilter->chrV, dstFilter->chrV, c->param) < 0)
 
989
                       srcFilter->chrV, dstFilter->chrV, c->param, 0) < 0)
977
990
            goto fail;
978
991
 
979
992
#if HAVE_ALTIVEC
1014
1027
 
1015
1028
    // allocate pixbufs (we use dynamic allocation because otherwise we would need to
1016
1029
    // allocate several megabytes to handle all possible cases)
1017
 
    FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail);
1018
 
    FF_ALLOC_OR_GOTO(c, c->chrUPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail);
1019
 
    FF_ALLOC_OR_GOTO(c, c->chrVPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail);
 
1030
    FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize*3*sizeof(int16_t*), fail);
 
1031
    FF_ALLOC_OR_GOTO(c, c->chrUPixBuf, c->vChrBufSize*3*sizeof(int16_t*), fail);
 
1032
    FF_ALLOC_OR_GOTO(c, c->chrVPixBuf, c->vChrBufSize*3*sizeof(int16_t*), fail);
1020
1033
    if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat))
1021
 
        FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail);
 
1034
        FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize*3*sizeof(int16_t*), fail);
1022
1035
    //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)
1023
1036
    /* align at 16 bytes for AltiVec */
1024
1037
    for (i=0; i<c->vLumBufSize; i++) {
1025
 
        FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+1, fail);
 
1038
        FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+16, fail);
1026
1039
        c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize];
1027
1040
    }
1028
 
    c->uv_off = dst_stride_px;
1029
 
    c->uv_offx2 = dst_stride;
 
1041
    // 64 / (c->dstBpc & ~7) is the same as 16 / sizeof(scaling_intermediate)
 
1042
    c->uv_off_px   = dst_stride_px + 64 / (c->dstBpc &~ 7);
 
1043
    c->uv_off_byte = dst_stride + 16;
1030
1044
    for (i=0; i<c->vChrBufSize; i++) {
1031
 
        FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+1, fail);
 
1045
        FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+32, fail);
1032
1046
        c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize];
1033
 
        c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + dst_stride_px;
 
1047
        c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + (dst_stride >> 1) + 8;
1034
1048
    }
1035
1049
    if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1036
1050
        for (i=0; i<c->vLumBufSize; i++) {
1037
 
            FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+1, fail);
 
1051
            FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+16, fail);
1038
1052
            c->alpPixBuf[i] = c->alpPixBuf[i+c->vLumBufSize];
1039
1053
        }
1040
1054
 
1075
1089
        else if (HAVE_ALTIVEC  && cpu_flags & AV_CPU_FLAG_ALTIVEC) av_log(c, AV_LOG_INFO, "using AltiVec\n");
1076
1090
        else                                   av_log(c, AV_LOG_INFO, "using C\n");
1077
1091
 
1078
 
        if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {
1079
 
            if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR))
1080
 
                av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");
1081
 
            else {
1082
 
                if (c->hLumFilterSize==4)
1083
 
                    av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n");
1084
 
                else if (c->hLumFilterSize==8)
1085
 
                    av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n");
1086
 
                else
1087
 
                    av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n");
1088
 
 
1089
 
                if (c->hChrFilterSize==4)
1090
 
                    av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n");
1091
 
                else if (c->hChrFilterSize==8)
1092
 
                    av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n");
1093
 
                else
1094
 
                    av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n");
1095
 
            }
1096
 
        } else {
1097
 
#if HAVE_MMX
1098
 
            av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n");
1099
 
#else
1100
 
            if (flags & SWS_FAST_BILINEAR)
1101
 
                av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n");
1102
 
            else
1103
 
                av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n");
1104
 
#endif
1105
 
        }
1106
 
        if (isPlanarYUV(dstFormat)) {
1107
 
            if (c->vLumFilterSize==1)
1108
 
                av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n",
1109
 
                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1110
 
            else
1111
 
                av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n",
1112
 
                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1113
 
        } else {
1114
 
            if (c->vLumFilterSize==1 && c->vChrFilterSize==2)
1115
 
                av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"
1116
 
                       "      2-tap scaler for vertical chrominance scaling (BGR)\n",
1117
 
                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1118
 
            else if (c->vLumFilterSize==2 && c->vChrFilterSize==2)
1119
 
                av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n",
1120
 
                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1121
 
            else
1122
 
                av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n",
1123
 
                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1124
 
        }
1125
 
 
1126
 
        if (dstFormat==PIX_FMT_BGR24)
1127
 
            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n",
1128
 
                   (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) ? "MMX2" :
1129
 
                   ((HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"));
1130
 
        else if (dstFormat==PIX_FMT_RGB32)
1131
 
            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n",
1132
 
                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1133
 
        else if (dstFormat==PIX_FMT_BGR565)
1134
 
            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n",
1135
 
                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1136
 
        else if (dstFormat==PIX_FMT_BGR555)
1137
 
            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n",
1138
 
                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1139
 
        else if (dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||
1140
 
                 dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE)
1141
 
            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n",
1142
 
                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");
1143
 
 
1144
1092
        av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
1145
1093
        av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
1146
1094
               c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);