~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libswscale/swscale.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
 
/*
22
 
  supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR32_1, BGR24, BGR16, BGR15, RGB32, RGB32_1, RGB24, Y8/Y800, YVU9/IF09, PAL8
23
 
  supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09
24
 
  {BGR,RGB}{1,4,8,15,16} support dithering
25
 
 
26
 
  unscaled special converters (YV12=I420=IYUV, Y800=Y8)
27
 
  YV12 -> {BGR,RGB}{1,4,8,12,15,16,24,32}
28
 
  x -> x
29
 
  YUV9 -> YV12
30
 
  YUV9/YV12 -> Y800
31
 
  Y800 -> YUV9/YV12
32
 
  BGR24 -> BGR32 & RGB24 -> RGB32
33
 
  BGR32 -> BGR24 & RGB32 -> RGB24
34
 
  BGR15 -> BGR16
35
 
*/
36
 
 
37
 
/*
38
 
tested special converters (most are tested actually, but I did not write it down ...)
39
 
 YV12 -> BGR12/BGR16
40
 
 YV12 -> YV12
41
 
 BGR15 -> BGR16
42
 
 BGR16 -> BGR16
43
 
 YVU9 -> YV12
44
 
 
45
 
untested special converters
46
 
  YV12/I420 -> BGR15/BGR24/BGR32 (it is the yuv2rgb stuff, so it should be OK)
47
 
  YV12/I420 -> YV12/I420
48
 
  YUY2/BGR15/BGR24/BGR32/RGB24/RGB32 -> same format
49
 
  BGR24 -> BGR32 & RGB24 -> RGB32
50
 
  BGR32 -> BGR24 & RGB32 -> RGB24
51
 
  BGR24 -> YV12
52
 
*/
53
 
 
54
21
#include <inttypes.h>
55
22
#include <string.h>
56
23
#include <math.h>
80
47
#define RV ( (int)(0.500*224/255*(1<<RGB2YUV_SHIFT)+0.5))
81
48
#define RU (-(int)(0.169*224/255*(1<<RGB2YUV_SHIFT)+0.5))
82
49
 
83
 
static const double rgb2yuv_table[8][9]={
84
 
    {0.7152, 0.0722, 0.2126, -0.386, 0.5, -0.115, -0.454, -0.046, 0.5}, //ITU709
85
 
    {0.7152, 0.0722, 0.2126, -0.386, 0.5, -0.115, -0.454, -0.046, 0.5}, //ITU709
86
 
    {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
87
 
    {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
88
 
    {0.59  , 0.11  , 0.30  , -0.331, 0.5, -0.169, -0.421, -0.079, 0.5}, //FCC
89
 
    {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
90
 
    {0.587 , 0.114 , 0.299 , -0.331, 0.5, -0.169, -0.419, -0.081, 0.5}, //DEFAULT / ITU601 / ITU624 / SMPTE 170M
91
 
    {0.701 , 0.087 , 0.212 , -0.384, 0.5, -0.116, -0.445, -0.055, 0.5}, //SMPTE 240M
92
 
};
93
 
 
94
50
/*
95
51
NOTES
96
52
Special versions: fast Y 1:1 scaling (no interpolation in y direction)
193
149
{ 77,  23,  60,  15,  72,  21,  56,  14, },
194
150
};
195
151
#endif
196
 
 
197
 
static av_always_inline void
198
 
yuv2yuvX16_c_template(const int16_t *lumFilter, const int16_t **lumSrc,
199
 
                      int lumFilterSize, const int16_t *chrFilter,
200
 
                      const int16_t **chrUSrc, const int16_t **chrVSrc,
201
 
                      int chrFilterSize, const int16_t **alpSrc,
202
 
                      uint16_t *dest, uint16_t *uDest, uint16_t *vDest,
203
 
                      uint16_t *aDest, int dstW, int chrDstW,
204
 
                      int big_endian, int output_bits)
205
 
{
206
 
    //FIXME Optimize (just quickly written not optimized..)
 
152
DECLARE_ALIGNED(8, const uint8_t, dither_8x8_128)[8][8] = {
 
153
{  36, 68, 60, 92, 34, 66, 58, 90,},
 
154
{ 100,  4,124, 28, 98,  2,122, 26,},
 
155
{  52, 84, 44, 76, 50, 82, 42, 74,},
 
156
{ 116, 20,108, 12,114, 18,106, 10,},
 
157
{  32, 64, 56, 88, 38, 70, 62, 94,},
 
158
{  96,  0,120, 24,102,  6,126, 30,},
 
159
{  48, 80, 40, 72, 54, 86, 46, 78,},
 
160
{ 112, 16,104,  8,118, 22,110, 14,},
 
161
};
 
162
DECLARE_ALIGNED(8, const uint8_t, ff_sws_pb_64)[8] =
 
163
{  64, 64, 64, 64, 64, 64, 64, 64 };
 
164
 
 
165
#define output_pixel(pos, val, bias, signedness) \
 
166
    if (big_endian) { \
 
167
        AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
 
168
    } else { \
 
169
        AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
 
170
    }
 
171
 
 
172
static av_always_inline void
 
173
yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
 
174
                         int big_endian, int output_bits)
 
175
{
 
176
    int i;
 
177
    int shift = 19 - output_bits;
 
178
 
 
179
    for (i = 0; i < dstW; i++) {
 
180
        int val = src[i] + (1 << (shift - 1));
 
181
        output_pixel(&dest[i], val, 0, uint);
 
182
    }
 
183
}
 
184
 
 
185
static av_always_inline void
 
186
yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
 
187
                         const int32_t **src, uint16_t *dest, int dstW,
 
188
                         int big_endian, int output_bits)
 
189
{
 
190
    int i;
 
191
    int shift = 15 + 16 - output_bits;
 
192
 
 
193
    for (i = 0; i < dstW; i++) {
 
194
        int val = 1 << (30-output_bits);
 
195
        int j;
 
196
 
 
197
        /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
 
198
         * filters (or anything with negative coeffs, the range can be slightly
 
199
         * wider in both directions. To account for this overflow, we subtract
 
200
         * a constant so it always fits in the signed range (assuming a
 
201
         * reasonable filterSize), and re-add that at the end. */
 
202
        val -= 0x40000000;
 
203
        for (j = 0; j < filterSize; j++)
 
204
            val += src[j][i] * filter[j];
 
205
 
 
206
        output_pixel(&dest[i], val, 0x8000, int);
 
207
    }
 
208
}
 
209
 
 
210
#undef output_pixel
 
211
 
 
212
#define output_pixel(pos, val) \
 
213
    if (big_endian) { \
 
214
        AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
 
215
    } else { \
 
216
        AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
 
217
    }
 
218
 
 
219
static av_always_inline void
 
220
yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
 
221
                         int big_endian, int output_bits)
 
222
{
 
223
    int i;
 
224
    int shift = 15 - output_bits;
 
225
 
 
226
    for (i = 0; i < dstW; i++) {
 
227
        int val = src[i] + (1 << (shift - 1));
 
228
        output_pixel(&dest[i], val);
 
229
    }
 
230
}
 
231
 
 
232
static av_always_inline void
 
233
yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
 
234
                         const int16_t **src, uint16_t *dest, int dstW,
 
235
                         int big_endian, int output_bits)
 
236
{
207
237
    int i;
208
238
    int shift = 11 + 16 - output_bits;
209
239
 
210
 
#define output_pixel(pos, val) \
211
 
    if (big_endian) { \
212
 
        if (output_bits == 16) { \
213
 
            AV_WB16(pos, av_clip_uint16(val >> shift)); \
214
 
        } else { \
215
 
            AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
216
 
        } \
217
 
    } else { \
218
 
        if (output_bits == 16) { \
219
 
            AV_WL16(pos, av_clip_uint16(val >> shift)); \
220
 
        } else { \
221
 
            AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
222
 
        } \
223
 
    }
224
240
    for (i = 0; i < dstW; i++) {
225
241
        int val = 1 << (26-output_bits);
226
242
        int j;
227
243
 
228
 
        for (j = 0; j < lumFilterSize; j++)
229
 
            val += lumSrc[j][i] * lumFilter[j];
 
244
        for (j = 0; j < filterSize; j++)
 
245
            val += src[j][i] * filter[j];
230
246
 
231
247
        output_pixel(&dest[i], val);
232
248
    }
233
 
 
234
 
    if (uDest) {
235
 
        for (i = 0; i < chrDstW; i++) {
236
 
            int u = 1 << (26-output_bits);
237
 
            int v = 1 << (26-output_bits);
238
 
            int j;
239
 
 
240
 
            for (j = 0; j < chrFilterSize; j++) {
241
 
                u += chrUSrc[j][i] * chrFilter[j];
242
 
                v += chrVSrc[j][i] * chrFilter[j];
243
 
            }
244
 
 
245
 
            output_pixel(&uDest[i], u);
246
 
            output_pixel(&vDest[i], v);
247
 
        }
248
 
    }
249
 
 
250
 
    if (CONFIG_SWSCALE_ALPHA && aDest) {
251
 
        for (i = 0; i < dstW; i++) {
252
 
            int val = 1 << (26-output_bits);
253
 
            int j;
254
 
 
255
 
            for (j = 0; j < lumFilterSize; j++)
256
 
                val += alpSrc[j][i] * lumFilter[j];
257
 
 
258
 
            output_pixel(&aDest[i], val);
259
 
        }
260
 
    }
 
249
}
 
250
 
261
251
#undef output_pixel
262
 
}
263
 
 
264
 
#define yuv2NBPS(bits, BE_LE, is_be) \
265
 
static void yuv2yuvX ## bits ## BE_LE ## _c(SwsContext *c, const int16_t *lumFilter, \
266
 
                              const int16_t **lumSrc, int lumFilterSize, \
267
 
                              const int16_t *chrFilter, const int16_t **chrUSrc, \
268
 
                              const int16_t **chrVSrc, \
269
 
                              int chrFilterSize, const int16_t **alpSrc, \
270
 
                              uint8_t *_dest, uint8_t *_uDest, uint8_t *_vDest, \
271
 
                              uint8_t *_aDest, int dstW, int chrDstW) \
272
 
{ \
273
 
    uint16_t *dest  = (uint16_t *) _dest,  *uDest = (uint16_t *) _uDest, \
274
 
             *vDest = (uint16_t *) _vDest, *aDest = (uint16_t *) _aDest; \
275
 
    yuv2yuvX16_c_template(lumFilter, lumSrc, lumFilterSize, \
276
 
                          chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
277
 
                          alpSrc, \
278
 
                          dest, uDest, vDest, aDest, \
279
 
                          dstW, chrDstW, is_be, bits); \
280
 
}
281
 
yuv2NBPS( 9, BE, 1);
282
 
yuv2NBPS( 9, LE, 0);
283
 
yuv2NBPS(10, BE, 1);
284
 
yuv2NBPS(10, LE, 0);
285
 
yuv2NBPS(16, BE, 1);
286
 
yuv2NBPS(16, LE, 0);
287
 
 
288
 
static void yuv2yuvX_c(SwsContext *c, const int16_t *lumFilter,
289
 
                       const int16_t **lumSrc, int lumFilterSize,
290
 
                       const int16_t *chrFilter, const int16_t **chrUSrc,
291
 
                       const int16_t **chrVSrc,
292
 
                       int chrFilterSize, const int16_t **alpSrc,
293
 
                       uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
294
 
                       uint8_t *aDest, int dstW, int chrDstW)
 
252
 
 
253
#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
 
254
static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
 
255
                              uint8_t *dest, int dstW, \
 
256
                              const uint8_t *dither, int offset)\
 
257
{ \
 
258
    yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
 
259
                         (uint16_t *) dest, dstW, is_be, bits); \
 
260
}\
 
261
static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
 
262
                              const int16_t **src, uint8_t *dest, int dstW, \
 
263
                              const uint8_t *dither, int offset)\
 
264
{ \
 
265
    yuv2planeX_## template_size ## _c_template(filter, \
 
266
                         filterSize, (const typeX_t **) src, \
 
267
                         (uint16_t *) dest, dstW, is_be, bits); \
 
268
}
 
269
yuv2NBPS( 9, BE, 1, 10, int16_t)
 
270
yuv2NBPS( 9, LE, 0, 10, int16_t)
 
271
yuv2NBPS(10, BE, 1, 10, int16_t)
 
272
yuv2NBPS(10, LE, 0, 10, int16_t)
 
273
yuv2NBPS(16, BE, 1, 16, int32_t)
 
274
yuv2NBPS(16, LE, 0, 16, int32_t)
 
275
 
 
276
static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
 
277
                           const int16_t **src, uint8_t *dest, int dstW,
 
278
                           const uint8_t *dither, int offset)
295
279
{
296
 
    //FIXME Optimize (just quickly written not optimized..)
297
280
    int i;
298
281
    for (i=0; i<dstW; i++) {
299
 
        int val=1<<18;
 
282
        int val = dither[(i + offset) & 7] << 12;
300
283
        int j;
301
 
        for (j=0; j<lumFilterSize; j++)
302
 
            val += lumSrc[j][i] * lumFilter[j];
 
284
        for (j=0; j<filterSize; j++)
 
285
            val += src[j][i] * filter[j];
303
286
 
304
287
        dest[i]= av_clip_uint8(val>>19);
305
288
    }
306
 
 
307
 
    if (uDest)
308
 
        for (i=0; i<chrDstW; i++) {
309
 
            int u=1<<18;
310
 
            int v=1<<18;
311
 
            int j;
312
 
            for (j=0; j<chrFilterSize; j++) {
313
 
                u += chrUSrc[j][i] * chrFilter[j];
314
 
                v += chrVSrc[j][i] * chrFilter[j];
315
 
            }
316
 
 
317
 
            uDest[i]= av_clip_uint8(u>>19);
318
 
            vDest[i]= av_clip_uint8(v>>19);
319
 
        }
320
 
 
321
 
    if (CONFIG_SWSCALE_ALPHA && aDest)
322
 
        for (i=0; i<dstW; i++) {
323
 
            int val=1<<18;
324
 
            int j;
325
 
            for (j=0; j<lumFilterSize; j++)
326
 
                val += alpSrc[j][i] * lumFilter[j];
327
 
 
328
 
            aDest[i]= av_clip_uint8(val>>19);
329
 
        }
330
289
}
331
290
 
332
 
static void yuv2yuv1_c(SwsContext *c, const int16_t *lumSrc,
333
 
                       const int16_t *chrUSrc, const int16_t *chrVSrc,
334
 
                       const int16_t *alpSrc,
335
 
                       uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
336
 
                       uint8_t *aDest, int dstW, int chrDstW)
 
291
static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
 
292
                           const uint8_t *dither, int offset)
337
293
{
338
294
    int i;
339
295
    for (i=0; i<dstW; i++) {
340
 
        int val= (lumSrc[i]+64)>>7;
 
296
        int val = (src[i] + dither[(i + offset) & 7]) >> 7;
341
297
        dest[i]= av_clip_uint8(val);
342
298
    }
343
 
 
344
 
    if (uDest)
345
 
        for (i=0; i<chrDstW; i++) {
346
 
            int u=(chrUSrc[i]+64)>>7;
347
 
            int v=(chrVSrc[i]+64)>>7;
348
 
            uDest[i]= av_clip_uint8(u);
349
 
            vDest[i]= av_clip_uint8(v);
350
 
        }
351
 
 
352
 
    if (CONFIG_SWSCALE_ALPHA && aDest)
353
 
        for (i=0; i<dstW; i++) {
354
 
            int val= (alpSrc[i]+64)>>7;
355
 
            aDest[i]= av_clip_uint8(val);
356
 
        }
357
299
}
358
300
 
359
 
static void yuv2nv12X_c(SwsContext *c, const int16_t *lumFilter,
360
 
                        const int16_t **lumSrc, int lumFilterSize,
361
 
                        const int16_t *chrFilter, const int16_t **chrUSrc,
362
 
                        const int16_t **chrVSrc, int chrFilterSize,
363
 
                        const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest,
364
 
                        uint8_t *vDest, uint8_t *aDest,
365
 
                        int dstW, int chrDstW)
 
301
static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
 
302
                        const int16_t **chrUSrc, const int16_t **chrVSrc,
 
303
                        uint8_t *dest, int chrDstW)
366
304
{
367
305
    enum PixelFormat dstFormat = c->dstFormat;
368
 
 
369
 
    //FIXME Optimize (just quickly written not optimized..)
 
306
    const uint8_t *chrDither = c->chrDither8;
370
307
    int i;
371
 
    for (i=0; i<dstW; i++) {
372
 
        int val=1<<18;
373
 
        int j;
374
 
        for (j=0; j<lumFilterSize; j++)
375
 
            val += lumSrc[j][i] * lumFilter[j];
376
 
 
377
 
        dest[i]= av_clip_uint8(val>>19);
378
 
    }
379
 
 
380
 
    if (!uDest)
381
 
        return;
382
308
 
383
309
    if (dstFormat == PIX_FMT_NV12)
384
310
        for (i=0; i<chrDstW; i++) {
385
 
            int u=1<<18;
386
 
            int v=1<<18;
 
311
            int u = chrDither[i & 7] << 12;
 
312
            int v = chrDither[(i + 3) & 7] << 12;
387
313
            int j;
388
314
            for (j=0; j<chrFilterSize; j++) {
389
315
                u += chrUSrc[j][i] * chrFilter[j];
390
316
                v += chrVSrc[j][i] * chrFilter[j];
391
317
            }
392
318
 
393
 
            uDest[2*i]= av_clip_uint8(u>>19);
394
 
            uDest[2*i+1]= av_clip_uint8(v>>19);
 
319
            dest[2*i]= av_clip_uint8(u>>19);
 
320
            dest[2*i+1]= av_clip_uint8(v>>19);
395
321
        }
396
322
    else
397
323
        for (i=0; i<chrDstW; i++) {
398
 
            int u=1<<18;
399
 
            int v=1<<18;
 
324
            int u = chrDither[i & 7] << 12;
 
325
            int v = chrDither[(i + 3) & 7] << 12;
400
326
            int j;
401
327
            for (j=0; j<chrFilterSize; j++) {
402
328
                u += chrUSrc[j][i] * chrFilter[j];
403
329
                v += chrVSrc[j][i] * chrFilter[j];
404
330
            }
405
331
 
406
 
            uDest[2*i]= av_clip_uint8(v>>19);
407
 
            uDest[2*i+1]= av_clip_uint8(u>>19);
 
332
            dest[2*i]= av_clip_uint8(v>>19);
 
333
            dest[2*i+1]= av_clip_uint8(u>>19);
408
334
        }
409
335
}
410
336
 
417
343
 
418
344
static av_always_inline void
419
345
yuv2gray16_X_c_template(SwsContext *c, const int16_t *lumFilter,
420
 
                        const int16_t **lumSrc, int lumFilterSize,
421
 
                        const int16_t *chrFilter, const int16_t **chrUSrc,
422
 
                        const int16_t **chrVSrc, int chrFilterSize,
423
 
                        const int16_t **alpSrc, uint8_t *dest, int dstW,
 
346
                        const int32_t **lumSrc, int lumFilterSize,
 
347
                        const int16_t *chrFilter, const int32_t **chrUSrc,
 
348
                        const int32_t **chrVSrc, int chrFilterSize,
 
349
                        const int32_t **alpSrc, uint16_t *dest, int dstW,
424
350
                        int y, enum PixelFormat target)
425
351
{
426
352
    int i;
427
353
 
428
354
    for (i = 0; i < (dstW >> 1); i++) {
429
355
        int j;
430
 
        int Y1 = 1 << 18;
431
 
        int Y2 = 1 << 18;
432
 
        const int i2 = 2 * i;
 
356
        int Y1 = (1 << 14) - 0x40000000;
 
357
        int Y2 = (1 << 14) - 0x40000000;
433
358
 
434
359
        for (j = 0; j < lumFilterSize; j++) {
435
 
            Y1 += lumSrc[j][i2]   * lumFilter[j];
436
 
            Y2 += lumSrc[j][i2+1] * lumFilter[j];
437
 
        }
438
 
        Y1 >>= 11;
439
 
        Y2 >>= 11;
440
 
        if ((Y1 | Y2) & 0x10000) {
441
 
            Y1 = av_clip_uint16(Y1);
442
 
            Y2 = av_clip_uint16(Y2);
443
 
        }
444
 
        output_pixel(&dest[2 * i2 + 0], Y1);
445
 
        output_pixel(&dest[2 * i2 + 2], Y2);
 
360
            Y1 += lumSrc[j][i * 2]     * lumFilter[j];
 
361
            Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
 
362
        }
 
363
        Y1 >>= 15;
 
364
        Y2 >>= 15;
 
365
        Y1 = av_clip_int16(Y1);
 
366
        Y2 = av_clip_int16(Y2);
 
367
        output_pixel(&dest[i * 2 + 0], 0x8000 + Y1);
 
368
        output_pixel(&dest[i * 2 + 1], 0x8000 + Y2);
446
369
    }
447
370
}
448
371
 
449
372
static av_always_inline void
450
 
yuv2gray16_2_c_template(SwsContext *c, const uint16_t *buf0,
451
 
                        const uint16_t *buf1, const uint16_t *ubuf0,
452
 
                        const uint16_t *ubuf1, const uint16_t *vbuf0,
453
 
                        const uint16_t *vbuf1, const uint16_t *abuf0,
454
 
                        const uint16_t *abuf1, uint8_t *dest, int dstW,
 
373
yuv2gray16_2_c_template(SwsContext *c, const int32_t *buf[2],
 
374
                        const int32_t *ubuf[2], const int32_t *vbuf[2],
 
375
                        const int32_t *abuf[2], uint16_t *dest, int dstW,
455
376
                        int yalpha, int uvalpha, int y,
456
377
                        enum PixelFormat target)
457
378
{
458
 
    int  yalpha1 = 4095 - yalpha; \
 
379
    int  yalpha1 = 4095 - yalpha;
459
380
    int i;
 
381
    const int32_t *buf0 = buf[0], *buf1 = buf[1];
460
382
 
461
383
    for (i = 0; i < (dstW >> 1); i++) {
462
 
        const int i2 = 2 * i;
463
 
        int Y1 = (buf0[i2  ] * yalpha1 + buf1[i2  ] * yalpha) >> 11;
464
 
        int Y2 = (buf0[i2+1] * yalpha1 + buf1[i2+1] * yalpha) >> 11;
 
384
        int Y1 = (buf0[i * 2    ] * yalpha1 + buf1[i * 2    ] * yalpha) >> 15;
 
385
        int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 15;
465
386
 
466
 
        output_pixel(&dest[2 * i2 + 0], Y1);
467
 
        output_pixel(&dest[2 * i2 + 2], Y2);
 
387
        output_pixel(&dest[i * 2 + 0], Y1);
 
388
        output_pixel(&dest[i * 2 + 1], Y2);
468
389
    }
469
390
}
470
391
 
471
392
static av_always_inline void
472
 
yuv2gray16_1_c_template(SwsContext *c, const uint16_t *buf0,
473
 
                        const uint16_t *ubuf0, const uint16_t *ubuf1,
474
 
                        const uint16_t *vbuf0, const uint16_t *vbuf1,
475
 
                        const uint16_t *abuf0, uint8_t *dest, int dstW,
476
 
                        int uvalpha, enum PixelFormat dstFormat,
477
 
                        int flags, int y, enum PixelFormat target)
 
393
yuv2gray16_1_c_template(SwsContext *c, const int32_t *buf0,
 
394
                        const int32_t *ubuf[2], const int32_t *vbuf[2],
 
395
                        const int32_t *abuf0, uint16_t *dest, int dstW,
 
396
                        int uvalpha, int y, enum PixelFormat target)
478
397
{
479
398
    int i;
480
399
 
481
400
    for (i = 0; i < (dstW >> 1); i++) {
482
 
        const int i2 = 2 * i;
483
 
        int Y1 = buf0[i2  ] << 1;
484
 
        int Y2 = buf0[i2+1] << 1;
 
401
        int Y1 = buf0[i * 2    ] << 1;
 
402
        int Y2 = buf0[i * 2 + 1] << 1;
485
403
 
486
 
        output_pixel(&dest[2 * i2 + 0], Y1);
487
 
        output_pixel(&dest[2 * i2 + 2], Y2);
 
404
        output_pixel(&dest[i * 2 + 0], Y1);
 
405
        output_pixel(&dest[i * 2 + 1], Y2);
488
406
    }
489
407
}
490
408
 
491
409
#undef output_pixel
492
410
 
493
 
#define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
 
411
#define YUV2PACKED16WRAPPER(name, base, ext, fmt) \
494
412
static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
495
 
                        const int16_t **lumSrc, int lumFilterSize, \
496
 
                        const int16_t *chrFilter, const int16_t **chrUSrc, \
497
 
                        const int16_t **chrVSrc, int chrFilterSize, \
498
 
                        const int16_t **alpSrc, uint8_t *dest, int dstW, \
 
413
                        const int16_t **_lumSrc, int lumFilterSize, \
 
414
                        const int16_t *chrFilter, const int16_t **_chrUSrc, \
 
415
                        const int16_t **_chrVSrc, int chrFilterSize, \
 
416
                        const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
499
417
                        int y) \
500
418
{ \
 
419
    const int32_t **lumSrc  = (const int32_t **) _lumSrc, \
 
420
                  **chrUSrc = (const int32_t **) _chrUSrc, \
 
421
                  **chrVSrc = (const int32_t **) _chrVSrc, \
 
422
                  **alpSrc  = (const int32_t **) _alpSrc; \
 
423
    uint16_t *dest = (uint16_t *) _dest; \
501
424
    name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
502
425
                          chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
503
426
                          alpSrc, dest, dstW, y, fmt); \
504
427
} \
505
428
 \
506
 
static void name ## ext ## _2_c(SwsContext *c, const uint16_t *buf0, \
507
 
                        const uint16_t *buf1, const uint16_t *ubuf0, \
508
 
                        const uint16_t *ubuf1, const uint16_t *vbuf0, \
509
 
                        const uint16_t *vbuf1, const uint16_t *abuf0, \
510
 
                        const uint16_t *abuf1, uint8_t *dest, int dstW, \
 
429
static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
 
430
                        const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
 
431
                        const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
511
432
                        int yalpha, int uvalpha, int y) \
512
433
{ \
513
 
    name ## base ## _2_c_template(c, buf0, buf1, ubuf0, ubuf1, \
514
 
                          vbuf0, vbuf1, abuf0, abuf1, \
 
434
    const int32_t **buf  = (const int32_t **) _buf, \
 
435
                  **ubuf = (const int32_t **) _ubuf, \
 
436
                  **vbuf = (const int32_t **) _vbuf, \
 
437
                  **abuf = (const int32_t **) _abuf; \
 
438
    uint16_t *dest = (uint16_t *) _dest; \
 
439
    name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
515
440
                          dest, dstW, yalpha, uvalpha, y, fmt); \
516
441
} \
517
442
 \
518
 
static void name ## ext ## _1_c(SwsContext *c, const uint16_t *buf0, \
519
 
                        const uint16_t *ubuf0, const uint16_t *ubuf1, \
520
 
                        const uint16_t *vbuf0, const uint16_t *vbuf1, \
521
 
                        const uint16_t *abuf0, uint8_t *dest, int dstW, \
522
 
                        int uvalpha, enum PixelFormat dstFormat, \
523
 
                        int flags, int y) \
 
443
static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
 
444
                        const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
 
445
                        const int16_t *_abuf0, uint8_t *_dest, int dstW, \
 
446
                        int uvalpha, int y) \
524
447
{ \
525
 
    name ## base ## _1_c_template(c, buf0, ubuf0, ubuf1, vbuf0, \
526
 
                          vbuf1, abuf0, dest, dstW, uvalpha, \
527
 
                          dstFormat, flags, y, fmt); \
 
448
    const int32_t *buf0  = (const int32_t *)  _buf0, \
 
449
                 **ubuf  = (const int32_t **) _ubuf, \
 
450
                 **vbuf  = (const int32_t **) _vbuf, \
 
451
                  *abuf0 = (const int32_t *)  _abuf0; \
 
452
    uint16_t *dest = (uint16_t *) _dest; \
 
453
    name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
 
454
                                  dstW, uvalpha, y, fmt); \
528
455
}
529
456
 
530
 
YUV2PACKEDWRAPPER(yuv2gray16,, LE, PIX_FMT_GRAY16LE);
531
 
YUV2PACKEDWRAPPER(yuv2gray16,, BE, PIX_FMT_GRAY16BE);
 
457
YUV2PACKED16WRAPPER(yuv2gray16,, LE, PIX_FMT_GRAY16LE)
 
458
YUV2PACKED16WRAPPER(yuv2gray16,, BE, PIX_FMT_GRAY16BE)
532
459
 
533
460
#define output_pixel(pos, acc) \
534
461
    if (target == PIX_FMT_MONOBLACK) { \
548
475
    const uint8_t * const d128=dither_8x8_220[y&7];
549
476
    uint8_t *g = c->table_gU[128] + c->table_gV[128];
550
477
    int i;
551
 
    int acc = 0;
 
478
    unsigned acc = 0;
552
479
 
553
480
    for (i = 0; i < dstW - 1; i += 2) {
554
481
        int j;
574
501
}
575
502
 
576
503
static av_always_inline void
577
 
yuv2mono_2_c_template(SwsContext *c, const uint16_t *buf0,
578
 
                      const uint16_t *buf1, const uint16_t *ubuf0,
579
 
                      const uint16_t *ubuf1, const uint16_t *vbuf0,
580
 
                      const uint16_t *vbuf1, const uint16_t *abuf0,
581
 
                      const uint16_t *abuf1, uint8_t *dest, int dstW,
 
504
yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
 
505
                      const int16_t *ubuf[2], const int16_t *vbuf[2],
 
506
                      const int16_t *abuf[2], uint8_t *dest, int dstW,
582
507
                      int yalpha, int uvalpha, int y,
583
508
                      enum PixelFormat target)
584
509
{
 
510
    const int16_t *buf0  = buf[0],  *buf1  = buf[1];
585
511
    const uint8_t * const d128 = dither_8x8_220[y & 7];
586
512
    uint8_t *g = c->table_gU[128] + c->table_gV[128];
587
513
    int  yalpha1 = 4095 - yalpha;
601
527
}
602
528
 
603
529
static av_always_inline void
604
 
yuv2mono_1_c_template(SwsContext *c, const uint16_t *buf0,
605
 
                      const uint16_t *ubuf0, const uint16_t *ubuf1,
606
 
                      const uint16_t *vbuf0, const uint16_t *vbuf1,
607
 
                      const uint16_t *abuf0, uint8_t *dest, int dstW,
608
 
                      int uvalpha, enum PixelFormat dstFormat,
609
 
                      int flags, int y, enum PixelFormat target)
 
530
yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
 
531
                      const int16_t *ubuf[2], const int16_t *vbuf[2],
 
532
                      const int16_t *abuf0, uint8_t *dest, int dstW,
 
533
                      int uvalpha, int y, enum PixelFormat target)
610
534
{
611
535
    const uint8_t * const d128 = dither_8x8_220[y & 7];
612
536
    uint8_t *g = c->table_gU[128] + c->table_gV[128];
627
551
 
628
552
#undef output_pixel
629
553
 
630
 
YUV2PACKEDWRAPPER(yuv2mono,, white, PIX_FMT_MONOWHITE);
631
 
YUV2PACKEDWRAPPER(yuv2mono,, black, PIX_FMT_MONOBLACK);
 
554
#define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
 
555
static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
 
556
                                const int16_t **lumSrc, int lumFilterSize, \
 
557
                                const int16_t *chrFilter, const int16_t **chrUSrc, \
 
558
                                const int16_t **chrVSrc, int chrFilterSize, \
 
559
                                const int16_t **alpSrc, uint8_t *dest, int dstW, \
 
560
                                int y) \
 
561
{ \
 
562
    name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
 
563
                                  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
 
564
                                  alpSrc, dest, dstW, y, fmt); \
 
565
} \
 
566
 \
 
567
static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
 
568
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
 
569
                                const int16_t *abuf[2], uint8_t *dest, int dstW, \
 
570
                                int yalpha, int uvalpha, int y) \
 
571
{ \
 
572
    name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
 
573
                                  dest, dstW, yalpha, uvalpha, y, fmt); \
 
574
} \
 
575
 \
 
576
static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
 
577
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
 
578
                                const int16_t *abuf0, uint8_t *dest, int dstW, \
 
579
                                int uvalpha, int y) \
 
580
{ \
 
581
    name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
 
582
                                  abuf0, dest, dstW, uvalpha, \
 
583
                                  y, fmt); \
 
584
}
 
585
 
 
586
YUV2PACKEDWRAPPER(yuv2mono,, white, PIX_FMT_MONOWHITE)
 
587
YUV2PACKEDWRAPPER(yuv2mono,, black, PIX_FMT_MONOBLACK)
632
588
 
633
589
#define output_pixels(pos, Y1, U, Y2, V) \
634
590
    if (target == PIX_FMT_YUYV422) { \
683
639
}
684
640
 
685
641
static av_always_inline void
686
 
yuv2422_2_c_template(SwsContext *c, const uint16_t *buf0,
687
 
                     const uint16_t *buf1, const uint16_t *ubuf0,
688
 
                     const uint16_t *ubuf1, const uint16_t *vbuf0,
689
 
                     const uint16_t *vbuf1, const uint16_t *abuf0,
690
 
                     const uint16_t *abuf1, uint8_t *dest, int dstW,
 
642
yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
 
643
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
 
644
                     const int16_t *abuf[2], uint8_t *dest, int dstW,
691
645
                     int yalpha, int uvalpha, int y,
692
646
                     enum PixelFormat target)
693
647
{
 
648
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
 
649
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
 
650
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
694
651
    int  yalpha1 = 4095 - yalpha;
695
652
    int uvalpha1 = 4095 - uvalpha;
696
653
    int i;
706
663
}
707
664
 
708
665
static av_always_inline void
709
 
yuv2422_1_c_template(SwsContext *c, const uint16_t *buf0,
710
 
                     const uint16_t *ubuf0, const uint16_t *ubuf1,
711
 
                     const uint16_t *vbuf0, const uint16_t *vbuf1,
712
 
                     const uint16_t *abuf0, uint8_t *dest, int dstW,
713
 
                     int uvalpha, enum PixelFormat dstFormat,
714
 
                     int flags, int y, enum PixelFormat target)
 
666
yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
 
667
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
 
668
                     const int16_t *abuf0, uint8_t *dest, int dstW,
 
669
                     int uvalpha, int y, enum PixelFormat target)
715
670
{
 
671
    const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
 
672
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
716
673
    int i;
717
674
 
718
675
    if (uvalpha < 2048) {
738
695
 
739
696
#undef output_pixels
740
697
 
741
 
YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, PIX_FMT_YUYV422);
742
 
YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, PIX_FMT_UYVY422);
 
698
YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, PIX_FMT_YUYV422)
 
699
YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, PIX_FMT_UYVY422)
743
700
 
744
 
#define r_b ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? r : b)
745
 
#define b_r ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? b : r)
 
701
#define R_B ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? R : B)
 
702
#define B_R ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? B : R)
 
703
#define output_pixel(pos, val) \
 
704
    if (isBE(target)) { \
 
705
        AV_WB16(pos, val); \
 
706
    } else { \
 
707
        AV_WL16(pos, val); \
 
708
    }
746
709
 
747
710
static av_always_inline void
748
711
yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
749
 
                       const int16_t **lumSrc, int lumFilterSize,
750
 
                       const int16_t *chrFilter, const int16_t **chrUSrc,
751
 
                       const int16_t **chrVSrc, int chrFilterSize,
752
 
                       const int16_t **alpSrc, uint8_t *dest, int dstW,
 
712
                       const int32_t **lumSrc, int lumFilterSize,
 
713
                       const int16_t *chrFilter, const int32_t **chrUSrc,
 
714
                       const int32_t **chrVSrc, int chrFilterSize,
 
715
                       const int32_t **alpSrc, uint16_t *dest, int dstW,
753
716
                       int y, enum PixelFormat target)
754
717
{
755
718
    int i;
756
719
 
757
720
    for (i = 0; i < (dstW >> 1); i++) {
758
721
        int j;
759
 
        int Y1 = 1 << 18;
760
 
        int Y2 = 1 << 18;
761
 
        int U  = 1 << 18;
762
 
        int V  = 1 << 18;
763
 
        const uint8_t *r, *g, *b;
 
722
        int Y1 = -0x40000000;
 
723
        int Y2 = -0x40000000;
 
724
        int U  = -128 << 23; // 19
 
725
        int V  = -128 << 23;
 
726
        int R, G, B;
764
727
 
765
728
        for (j = 0; j < lumFilterSize; j++) {
766
729
            Y1 += lumSrc[j][i * 2]     * lumFilter[j];
770
733
            U += chrUSrc[j][i] * chrFilter[j];
771
734
            V += chrVSrc[j][i] * chrFilter[j];
772
735
        }
773
 
        Y1 >>= 19;
774
 
        Y2 >>= 19;
775
 
        U  >>= 19;
776
 
        V  >>= 19;
777
 
        if ((Y1 | Y2 | U | V) & 0x100) {
778
 
            Y1 = av_clip_uint8(Y1);
779
 
            Y2 = av_clip_uint8(Y2);
780
 
            U  = av_clip_uint8(U);
781
 
            V  = av_clip_uint8(V);
782
 
        }
783
 
 
784
 
        /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/
785
 
        r = (const uint8_t *) c->table_rV[V];
786
 
        g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]);
787
 
        b = (const uint8_t *) c->table_bU[U];
788
 
 
789
 
        dest[ 0] = dest[ 1] = r_b[Y1];
790
 
        dest[ 2] = dest[ 3] =   g[Y1];
791
 
        dest[ 4] = dest[ 5] = b_r[Y1];
792
 
        dest[ 6] = dest[ 7] = r_b[Y2];
793
 
        dest[ 8] = dest[ 9] =   g[Y2];
794
 
        dest[10] = dest[11] = b_r[Y2];
795
 
        dest += 12;
 
736
 
 
737
        // 8bit: 12+15=27; 16-bit: 12+19=31
 
738
        Y1 >>= 14; // 10
 
739
        Y1 += 0x10000;
 
740
        Y2 >>= 14;
 
741
        Y2 += 0x10000;
 
742
        U  >>= 14;
 
743
        V  >>= 14;
 
744
 
 
745
        // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
 
746
        Y1 -= c->yuv2rgb_y_offset;
 
747
        Y2 -= c->yuv2rgb_y_offset;
 
748
        Y1 *= c->yuv2rgb_y_coeff;
 
749
        Y2 *= c->yuv2rgb_y_coeff;
 
750
        Y1 += 1 << 13; // 21
 
751
        Y2 += 1 << 13;
 
752
        // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
 
753
 
 
754
        R = V * c->yuv2rgb_v2r_coeff;
 
755
        G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
 
756
        B =                            U * c->yuv2rgb_u2b_coeff;
 
757
 
 
758
        // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
 
759
        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
 
760
        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
 
761
        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
 
762
        output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
 
763
        output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
 
764
        output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
 
765
        dest += 6;
796
766
    }
797
767
}
798
768
 
799
769
static av_always_inline void
800
 
yuv2rgb48_2_c_template(SwsContext *c, const uint16_t *buf0,
801
 
                       const uint16_t *buf1, const uint16_t *ubuf0,
802
 
                       const uint16_t *ubuf1, const uint16_t *vbuf0,
803
 
                       const uint16_t *vbuf1, const uint16_t *abuf0,
804
 
                       const uint16_t *abuf1, uint8_t *dest, int dstW,
 
770
yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
 
771
                       const int32_t *ubuf[2], const int32_t *vbuf[2],
 
772
                       const int32_t *abuf[2], uint16_t *dest, int dstW,
805
773
                       int yalpha, int uvalpha, int y,
806
774
                       enum PixelFormat target)
807
775
{
 
776
    const int32_t *buf0  = buf[0],  *buf1  = buf[1],
 
777
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
 
778
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
 
779
    int  yalpha1 = 4095 - yalpha;
 
780
    int uvalpha1 = 4095 - uvalpha;
 
781
    int i;
 
782
 
 
783
    for (i = 0; i < (dstW >> 1); i++) {
 
784
        int Y1 = (buf0[i * 2]     * yalpha1  + buf1[i * 2]     * yalpha) >> 14;
 
785
        int Y2 = (buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha) >> 14;
 
786
        int U  = (ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha + (-128 << 23)) >> 14;
 
787
        int V  = (vbuf0[i]        * uvalpha1 + vbuf1[i]        * uvalpha + (-128 << 23)) >> 14;
 
788
        int R, G, B;
 
789
 
 
790
        Y1 -= c->yuv2rgb_y_offset;
 
791
        Y2 -= c->yuv2rgb_y_offset;
 
792
        Y1 *= c->yuv2rgb_y_coeff;
 
793
        Y2 *= c->yuv2rgb_y_coeff;
 
794
        Y1 += 1 << 13;
 
795
        Y2 += 1 << 13;
 
796
 
 
797
        R = V * c->yuv2rgb_v2r_coeff;
 
798
        G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
 
799
        B =                            U * c->yuv2rgb_u2b_coeff;
 
800
 
 
801
        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
 
802
        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
 
803
        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
 
804
        output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
 
805
        output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
 
806
        output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
 
807
        dest += 6;
 
808
    }
 
809
}
 
810
 
 
811
static av_always_inline void
 
812
yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
 
813
                       const int32_t *ubuf[2], const int32_t *vbuf[2],
 
814
                       const int32_t *abuf0, uint16_t *dest, int dstW,
 
815
                       int uvalpha, int y, enum PixelFormat target)
 
816
{
 
817
    const int32_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
 
818
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
 
819
    int i;
 
820
 
 
821
    if (uvalpha < 2048) {
 
822
        for (i = 0; i < (dstW >> 1); i++) {
 
823
            int Y1 = (buf0[i * 2]    ) >> 2;
 
824
            int Y2 = (buf0[i * 2 + 1]) >> 2;
 
825
            int U  = (ubuf0[i] + (-128 << 11)) >> 2;
 
826
            int V  = (vbuf0[i] + (-128 << 11)) >> 2;
 
827
            int R, G, B;
 
828
 
 
829
            Y1 -= c->yuv2rgb_y_offset;
 
830
            Y2 -= c->yuv2rgb_y_offset;
 
831
            Y1 *= c->yuv2rgb_y_coeff;
 
832
            Y2 *= c->yuv2rgb_y_coeff;
 
833
            Y1 += 1 << 13;
 
834
            Y2 += 1 << 13;
 
835
 
 
836
            R = V * c->yuv2rgb_v2r_coeff;
 
837
            G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
 
838
            B =                            U * c->yuv2rgb_u2b_coeff;
 
839
 
 
840
            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
 
841
            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
 
842
            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
 
843
            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
 
844
            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
 
845
            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
 
846
            dest += 6;
 
847
        }
 
848
    } else {
 
849
        for (i = 0; i < (dstW >> 1); i++) {
 
850
            int Y1 = (buf0[i * 2]    ) >> 2;
 
851
            int Y2 = (buf0[i * 2 + 1]) >> 2;
 
852
            int U  = (ubuf0[i] + ubuf1[i] + (-128 << 11)) >> 3;
 
853
            int V  = (vbuf0[i] + vbuf1[i] + (-128 << 11)) >> 3;
 
854
            int R, G, B;
 
855
 
 
856
            Y1 -= c->yuv2rgb_y_offset;
 
857
            Y2 -= c->yuv2rgb_y_offset;
 
858
            Y1 *= c->yuv2rgb_y_coeff;
 
859
            Y2 *= c->yuv2rgb_y_coeff;
 
860
            Y1 += 1 << 13;
 
861
            Y2 += 1 << 13;
 
862
 
 
863
            R = V * c->yuv2rgb_v2r_coeff;
 
864
            G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
 
865
            B =                            U * c->yuv2rgb_u2b_coeff;
 
866
 
 
867
            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
 
868
            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
 
869
            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
 
870
            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
 
871
            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
 
872
            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
 
873
            dest += 6;
 
874
        }
 
875
    }
 
876
}
 
877
 
 
878
#undef output_pixel
 
879
#undef r_b
 
880
#undef b_r
 
881
 
 
882
YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE)
 
883
YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE)
 
884
YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE)
 
885
YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, PIX_FMT_BGR48LE)
 
886
 
 
887
/*
 
888
 * Write out 2 RGB pixels in the target pixel format. This function takes a
 
889
 * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
 
890
 * things like endianness conversion and shifting. The caller takes care of
 
891
 * setting the correct offset in these tables from the chroma (U/V) values.
 
892
 * This function then uses the luminance (Y1/Y2) values to write out the
 
893
 * correct RGB values into the destination buffer.
 
894
 */
 
895
static av_always_inline void
 
896
yuv2rgb_write(uint8_t *_dest, int i, unsigned Y1, unsigned Y2,
 
897
              unsigned A1, unsigned A2,
 
898
              const void *_r, const void *_g, const void *_b, int y,
 
899
              enum PixelFormat target, int hasAlpha)
 
900
{
 
901
    if (target == PIX_FMT_ARGB || target == PIX_FMT_RGBA ||
 
902
        target == PIX_FMT_ABGR || target == PIX_FMT_BGRA) {
 
903
        uint32_t *dest = (uint32_t *) _dest;
 
904
        const uint32_t *r = (const uint32_t *) _r;
 
905
        const uint32_t *g = (const uint32_t *) _g;
 
906
        const uint32_t *b = (const uint32_t *) _b;
 
907
 
 
908
#if CONFIG_SMALL
 
909
        int sh = hasAlpha ? ((target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24) : 0;
 
910
 
 
911
        dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
 
912
        dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
 
913
#else
 
914
        if (hasAlpha) {
 
915
            int sh = (target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24;
 
916
 
 
917
            dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
 
918
            dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
 
919
        } else {
 
920
            dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
 
921
            dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
 
922
        }
 
923
#endif
 
924
    } else if (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) {
 
925
        uint8_t *dest = (uint8_t *) _dest;
 
926
        const uint8_t *r = (const uint8_t *) _r;
 
927
        const uint8_t *g = (const uint8_t *) _g;
 
928
        const uint8_t *b = (const uint8_t *) _b;
 
929
 
 
930
#define r_b ((target == PIX_FMT_RGB24) ? r : b)
 
931
#define b_r ((target == PIX_FMT_RGB24) ? b : r)
 
932
        dest[i * 6 + 0] = r_b[Y1];
 
933
        dest[i * 6 + 1] =   g[Y1];
 
934
        dest[i * 6 + 2] = b_r[Y1];
 
935
        dest[i * 6 + 3] = r_b[Y2];
 
936
        dest[i * 6 + 4] =   g[Y2];
 
937
        dest[i * 6 + 5] = b_r[Y2];
 
938
#undef r_b
 
939
#undef b_r
 
940
    } else if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565 ||
 
941
               target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555 ||
 
942
               target == PIX_FMT_RGB444 || target == PIX_FMT_BGR444) {
 
943
        uint16_t *dest = (uint16_t *) _dest;
 
944
        const uint16_t *r = (const uint16_t *) _r;
 
945
        const uint16_t *g = (const uint16_t *) _g;
 
946
        const uint16_t *b = (const uint16_t *) _b;
 
947
        int dr1, dg1, db1, dr2, dg2, db2;
 
948
 
 
949
        if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565) {
 
950
            dr1 = dither_2x2_8[ y & 1     ][0];
 
951
            dg1 = dither_2x2_4[ y & 1     ][0];
 
952
            db1 = dither_2x2_8[(y & 1) ^ 1][0];
 
953
            dr2 = dither_2x2_8[ y & 1     ][1];
 
954
            dg2 = dither_2x2_4[ y & 1     ][1];
 
955
            db2 = dither_2x2_8[(y & 1) ^ 1][1];
 
956
        } else if (target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555) {
 
957
            dr1 = dither_2x2_8[ y & 1     ][0];
 
958
            dg1 = dither_2x2_8[ y & 1     ][1];
 
959
            db1 = dither_2x2_8[(y & 1) ^ 1][0];
 
960
            dr2 = dither_2x2_8[ y & 1     ][1];
 
961
            dg2 = dither_2x2_8[ y & 1     ][0];
 
962
            db2 = dither_2x2_8[(y & 1) ^ 1][1];
 
963
        } else {
 
964
            dr1 = dither_4x4_16[ y & 3     ][0];
 
965
            dg1 = dither_4x4_16[ y & 3     ][1];
 
966
            db1 = dither_4x4_16[(y & 3) ^ 3][0];
 
967
            dr2 = dither_4x4_16[ y & 3     ][1];
 
968
            dg2 = dither_4x4_16[ y & 3     ][0];
 
969
            db2 = dither_4x4_16[(y & 3) ^ 3][1];
 
970
        }
 
971
 
 
972
        dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
 
973
        dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
 
974
    } else /* 8/4-bit */ {
 
975
        uint8_t *dest = (uint8_t *) _dest;
 
976
        const uint8_t *r = (const uint8_t *) _r;
 
977
        const uint8_t *g = (const uint8_t *) _g;
 
978
        const uint8_t *b = (const uint8_t *) _b;
 
979
        int dr1, dg1, db1, dr2, dg2, db2;
 
980
 
 
981
        if (target == PIX_FMT_RGB8 || target == PIX_FMT_BGR8) {
 
982
            const uint8_t * const d64 = dither_8x8_73[y & 7];
 
983
            const uint8_t * const d32 = dither_8x8_32[y & 7];
 
984
            dr1 = dg1 = d32[(i * 2 + 0) & 7];
 
985
            db1 =       d64[(i * 2 + 0) & 7];
 
986
            dr2 = dg2 = d32[(i * 2 + 1) & 7];
 
987
            db2 =       d64[(i * 2 + 1) & 7];
 
988
        } else {
 
989
            const uint8_t * const d64  = dither_8x8_73 [y & 7];
 
990
            const uint8_t * const d128 = dither_8x8_220[y & 7];
 
991
            dr1 = db1 = d128[(i * 2 + 0) & 7];
 
992
            dg1 =        d64[(i * 2 + 0) & 7];
 
993
            dr2 = db2 = d128[(i * 2 + 1) & 7];
 
994
            dg2 =        d64[(i * 2 + 1) & 7];
 
995
        }
 
996
 
 
997
        if (target == PIX_FMT_RGB4 || target == PIX_FMT_BGR4) {
 
998
            dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
 
999
                    ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
 
1000
        } else {
 
1001
            dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
 
1002
            dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
 
1003
        }
 
1004
    }
 
1005
}
 
1006
 
 
1007
static av_always_inline void
 
1008
yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
 
1009
                     const int16_t **lumSrc, int lumFilterSize,
 
1010
                     const int16_t *chrFilter, const int16_t **chrUSrc,
 
1011
                     const int16_t **chrVSrc, int chrFilterSize,
 
1012
                     const int16_t **alpSrc, uint8_t *dest, int dstW,
 
1013
                     int y, enum PixelFormat target, int hasAlpha)
 
1014
{
 
1015
    int i;
 
1016
 
 
1017
    for (i = 0; i < (dstW >> 1); i++) {
 
1018
        int j;
 
1019
        int Y1 = 1 << 18;
 
1020
        int Y2 = 1 << 18;
 
1021
        int U  = 1 << 18;
 
1022
        int V  = 1 << 18;
 
1023
        int av_unused A1, A2;
 
1024
        const void *r, *g, *b;
 
1025
 
 
1026
        for (j = 0; j < lumFilterSize; j++) {
 
1027
            Y1 += lumSrc[j][i * 2]     * lumFilter[j];
 
1028
            Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
 
1029
        }
 
1030
        for (j = 0; j < chrFilterSize; j++) {
 
1031
            U += chrUSrc[j][i] * chrFilter[j];
 
1032
            V += chrVSrc[j][i] * chrFilter[j];
 
1033
        }
 
1034
        Y1 >>= 19;
 
1035
        Y2 >>= 19;
 
1036
        U  >>= 19;
 
1037
        V  >>= 19;
 
1038
        if ((Y1 | Y2 | U | V) & 0x100) {
 
1039
            Y1 = av_clip_uint8(Y1);
 
1040
            Y2 = av_clip_uint8(Y2);
 
1041
            U  = av_clip_uint8(U);
 
1042
            V  = av_clip_uint8(V);
 
1043
        }
 
1044
        if (hasAlpha) {
 
1045
            A1 = 1 << 18;
 
1046
            A2 = 1 << 18;
 
1047
            for (j = 0; j < lumFilterSize; j++) {
 
1048
                A1 += alpSrc[j][i * 2    ] * lumFilter[j];
 
1049
                A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
 
1050
            }
 
1051
            A1 >>= 19;
 
1052
            A2 >>= 19;
 
1053
            if ((A1 | A2) & 0x100) {
 
1054
                A1 = av_clip_uint8(A1);
 
1055
                A2 = av_clip_uint8(A2);
 
1056
            }
 
1057
        }
 
1058
 
 
1059
        /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/
 
1060
        r =  c->table_rV[V];
 
1061
        g = (c->table_gU[U] + c->table_gV[V]);
 
1062
        b =  c->table_bU[U];
 
1063
 
 
1064
        yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
 
1065
                      r, g, b, y, target, hasAlpha);
 
1066
    }
 
1067
}
 
1068
 
 
1069
static av_always_inline void
 
1070
yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
 
1071
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
 
1072
                     const int16_t *abuf[2], uint8_t *dest, int dstW,
 
1073
                     int yalpha, int uvalpha, int y,
 
1074
                     enum PixelFormat target, int hasAlpha)
 
1075
{
 
1076
    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
 
1077
                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
 
1078
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
 
1079
                  *abuf0 = hasAlpha ? abuf[0] : NULL,
 
1080
                  *abuf1 = hasAlpha ? abuf[1] : NULL;
808
1081
    int  yalpha1 = 4095 - yalpha;
809
1082
    int uvalpha1 = 4095 - uvalpha;
810
1083
    int i;
814
1087
        int Y2 = (buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha)  >> 19;
815
1088
        int U  = (ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha) >> 19;
816
1089
        int V  = (vbuf0[i]        * uvalpha1 + vbuf1[i]        * uvalpha) >> 19;
817
 
        const uint8_t *r = (const uint8_t *) c->table_rV[V],
818
 
                      *g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]),
819
 
                      *b = (const uint8_t *) c->table_bU[U];
820
 
 
821
 
        dest[ 0] = dest[ 1] = r_b[Y1];
822
 
        dest[ 2] = dest[ 3] =   g[Y1];
823
 
        dest[ 4] = dest[ 5] = b_r[Y1];
824
 
        dest[ 6] = dest[ 7] = r_b[Y2];
825
 
        dest[ 8] = dest[ 9] =   g[Y2];
826
 
        dest[10] = dest[11] = b_r[Y2];
827
 
        dest += 12;
 
1090
        int A1, A2;
 
1091
        const void *r =  c->table_rV[V],
 
1092
                   *g = (c->table_gU[U] + c->table_gV[V]),
 
1093
                   *b =  c->table_bU[U];
 
1094
 
 
1095
        if (hasAlpha) {
 
1096
            A1 = (abuf0[i * 2    ] * yalpha1 + abuf1[i * 2    ] * yalpha) >> 19;
 
1097
            A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
 
1098
        }
 
1099
 
 
1100
        yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
 
1101
                      r, g, b, y, target, hasAlpha);
828
1102
    }
829
1103
}
830
1104
 
831
1105
static av_always_inline void
832
 
yuv2rgb48_1_c_template(SwsContext *c, const uint16_t *buf0,
833
 
                       const uint16_t *ubuf0, const uint16_t *ubuf1,
834
 
                       const uint16_t *vbuf0, const uint16_t *vbuf1,
835
 
                       const uint16_t *abuf0, uint8_t *dest, int dstW,
836
 
                       int uvalpha, enum PixelFormat dstFormat,
837
 
                       int flags, int y, enum PixelFormat target)
 
1106
yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
 
1107
                     const int16_t *ubuf[2], const int16_t *vbuf[2],
 
1108
                     const int16_t *abuf0, uint8_t *dest, int dstW,
 
1109
                     int uvalpha, int y, enum PixelFormat target,
 
1110
                     int hasAlpha)
838
1111
{
 
1112
    const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
 
1113
                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
839
1114
    int i;
840
1115
 
841
1116
    if (uvalpha < 2048) {
844
1119
            int Y2 = buf0[i * 2 + 1] >> 7;
845
1120
            int U  = ubuf1[i]        >> 7;
846
1121
            int V  = vbuf1[i]        >> 7;
847
 
            const uint8_t *r = (const uint8_t *) c->table_rV[V],
848
 
                          *g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]),
849
 
                          *b = (const uint8_t *) c->table_bU[U];
850
 
 
851
 
            dest[ 0] = dest[ 1] = r_b[Y1];
852
 
            dest[ 2] = dest[ 3] =   g[Y1];
853
 
            dest[ 4] = dest[ 5] = b_r[Y1];
854
 
            dest[ 6] = dest[ 7] = r_b[Y2];
855
 
            dest[ 8] = dest[ 9] =   g[Y2];
856
 
            dest[10] = dest[11] = b_r[Y2];
857
 
            dest += 12;
 
1122
            int A1, A2;
 
1123
            const void *r =  c->table_rV[V],
 
1124
                       *g = (c->table_gU[U] + c->table_gV[V]),
 
1125
                       *b =  c->table_bU[U];
 
1126
 
 
1127
            if (hasAlpha) {
 
1128
                A1 = abuf0[i * 2    ] >> 7;
 
1129
                A2 = abuf0[i * 2 + 1] >> 7;
 
1130
            }
 
1131
 
 
1132
            yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
 
1133
                          r, g, b, y, target, hasAlpha);
858
1134
        }
859
1135
    } else {
860
1136
        for (i = 0; i < (dstW >> 1); i++) {
862
1138
            int Y2 =  buf0[i * 2 + 1]      >> 7;
863
1139
            int U  = (ubuf0[i] + ubuf1[i]) >> 8;
864
1140
            int V  = (vbuf0[i] + vbuf1[i]) >> 8;
865
 
            const uint8_t *r = (const uint8_t *) c->table_rV[V],
866
 
                          *g = (const uint8_t *)(c->table_gU[U] + c->table_gV[V]),
867
 
                          *b = (const uint8_t *) c->table_bU[U];
868
 
 
869
 
            dest[ 0] = dest[ 1] = r_b[Y1];
870
 
            dest[ 2] = dest[ 3] =   g[Y1];
871
 
            dest[ 4] = dest[ 5] = b_r[Y1];
872
 
            dest[ 6] = dest[ 7] = r_b[Y2];
873
 
            dest[ 8] = dest[ 9] =   g[Y2];
874
 
            dest[10] = dest[11] = b_r[Y2];
875
 
            dest += 12;
876
 
        }
877
 
    }
878
 
}
879
 
 
880
 
#undef r_b
881
 
#undef b_r
882
 
 
883
 
YUV2PACKEDWRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE);
884
 
//YUV2PACKEDWRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE);
885
 
YUV2PACKEDWRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE);
886
 
//YUV2PACKEDWRAPPER(yuv2, rgb48, bgr48le, PIX_FMT_BGR48LE);
887
 
 
888
 
#define YSCALE_YUV_2_RGBX_C(type,alpha) \
889
 
    for (i=0; i<(dstW>>1); i++) {\
890
 
        int j;\
891
 
        int Y1 = 1<<18;\
892
 
        int Y2 = 1<<18;\
893
 
        int U  = 1<<18;\
894
 
        int V  = 1<<18;\
895
 
        int av_unused A1, A2;\
896
 
        type av_unused *r, *b, *g;\
897
 
        const int i2= 2*i;\
898
 
        \
899
 
        for (j=0; j<lumFilterSize; j++) {\
900
 
            Y1 += lumSrc[j][i2] * lumFilter[j];\
901
 
            Y2 += lumSrc[j][i2+1] * lumFilter[j];\
902
 
        }\
903
 
        for (j=0; j<chrFilterSize; j++) {\
904
 
            U += chrUSrc[j][i] * chrFilter[j];\
905
 
            V += chrVSrc[j][i] * chrFilter[j];\
906
 
        }\
907
 
        Y1>>=19;\
908
 
        Y2>>=19;\
909
 
        U >>=19;\
910
 
        V >>=19;\
911
 
        if ((Y1|Y2|U|V)&0x100) {\
912
 
            Y1 = av_clip_uint8(Y1); \
913
 
            Y2 = av_clip_uint8(Y2); \
914
 
            U  = av_clip_uint8(U); \
915
 
            V  = av_clip_uint8(V); \
916
 
        }\
917
 
        if (alpha) {\
918
 
            A1 = 1<<18;\
919
 
            A2 = 1<<18;\
920
 
            for (j=0; j<lumFilterSize; j++) {\
921
 
                A1 += alpSrc[j][i2  ] * lumFilter[j];\
922
 
                A2 += alpSrc[j][i2+1] * lumFilter[j];\
923
 
            }\
924
 
            A1>>=19;\
925
 
            A2>>=19;\
926
 
            if ((A1|A2)&0x100) {\
927
 
                A1 = av_clip_uint8(A1); \
928
 
                A2 = av_clip_uint8(A2); \
929
 
            }\
930
 
        }\
931
 
        /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/\
932
 
    r = (type *)c->table_rV[V];   \
933
 
    g = (type *)(c->table_gU[U] + c->table_gV[V]); \
934
 
    b = (type *)c->table_bU[U];
935
 
 
936
 
#define YSCALE_YUV_2_RGBX_FULL_C(rnd,alpha) \
937
 
    for (i=0; i<dstW; i++) {\
938
 
        int j;\
939
 
        int Y = 0;\
940
 
        int U = -128<<19;\
941
 
        int V = -128<<19;\
942
 
        int av_unused A;\
943
 
        int R,G,B;\
944
 
        \
945
 
        for (j=0; j<lumFilterSize; j++) {\
946
 
            Y += lumSrc[j][i     ] * lumFilter[j];\
947
 
        }\
948
 
        for (j=0; j<chrFilterSize; j++) {\
949
 
            U += chrUSrc[j][i] * chrFilter[j];\
950
 
            V += chrVSrc[j][i] * chrFilter[j];\
951
 
        }\
952
 
        Y >>=10;\
953
 
        U >>=10;\
954
 
        V >>=10;\
955
 
        if (alpha) {\
956
 
            A = rnd;\
957
 
            for (j=0; j<lumFilterSize; j++)\
958
 
                A += alpSrc[j][i     ] * lumFilter[j];\
959
 
            A >>=19;\
960
 
            if (A&0x100)\
961
 
                A = av_clip_uint8(A);\
962
 
        }\
963
 
        Y-= c->yuv2rgb_y_offset;\
964
 
        Y*= c->yuv2rgb_y_coeff;\
965
 
        Y+= rnd;\
966
 
        R= Y + V*c->yuv2rgb_v2r_coeff;\
967
 
        G= Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;\
968
 
        B= Y +                          U*c->yuv2rgb_u2b_coeff;\
969
 
        if ((R|G|B)&(0xC0000000)) {\
970
 
            R = av_clip_uintp2(R, 30); \
971
 
            G = av_clip_uintp2(G, 30); \
972
 
            B = av_clip_uintp2(B, 30); \
973
 
        }
974
 
 
975
 
#define YSCALE_YUV_2_RGB2_C(type,alpha) \
976
 
    for (i=0; i<(dstW>>1); i++) { \
977
 
        const int i2= 2*i;       \
978
 
        int Y1= (buf0[i2  ]*yalpha1+buf1[i2  ]*yalpha)>>19;           \
979
 
        int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19;           \
980
 
        int U= (ubuf0[i]*uvalpha1+ubuf1[i]*uvalpha)>>19;              \
981
 
        int V= (vbuf0[i]*uvalpha1+vbuf1[i]*uvalpha)>>19;              \
982
 
        type av_unused *r, *b, *g;                                    \
983
 
        int av_unused A1, A2;                                         \
984
 
        if (alpha) {\
985
 
            A1= (abuf0[i2  ]*yalpha1+abuf1[i2  ]*yalpha)>>19;         \
986
 
            A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19;         \
987
 
        }\
988
 
    r = (type *)c->table_rV[V];\
989
 
    g = (type *)(c->table_gU[U] + c->table_gV[V]);\
990
 
    b = (type *)c->table_bU[U];
991
 
 
992
 
#define YSCALE_YUV_2_RGB1_C(type,alpha) \
993
 
    for (i=0; i<(dstW>>1); i++) {\
994
 
        const int i2= 2*i;\
995
 
        int Y1= buf0[i2  ]>>7;\
996
 
        int Y2= buf0[i2+1]>>7;\
997
 
        int U= (ubuf1[i])>>7;\
998
 
        int V= (vbuf1[i])>>7;\
999
 
        type av_unused *r, *b, *g;\
1000
 
        int av_unused A1, A2;\
1001
 
        if (alpha) {\
1002
 
            A1= abuf0[i2  ]>>7;\
1003
 
            A2= abuf0[i2+1]>>7;\
1004
 
        }\
1005
 
    r = (type *)c->table_rV[V];\
1006
 
    g = (type *)(c->table_gU[U] + c->table_gV[V]);\
1007
 
    b = (type *)c->table_bU[U];
1008
 
 
1009
 
#define YSCALE_YUV_2_RGB1B_C(type,alpha) \
1010
 
    for (i=0; i<(dstW>>1); i++) {\
1011
 
        const int i2= 2*i;\
1012
 
        int Y1= buf0[i2  ]>>7;\
1013
 
        int Y2= buf0[i2+1]>>7;\
1014
 
        int U= (ubuf0[i] + ubuf1[i])>>8;\
1015
 
        int V= (vbuf0[i] + vbuf1[i])>>8;\
1016
 
        type av_unused *r, *b, *g;\
1017
 
        int av_unused A1, A2;\
1018
 
        if (alpha) {\
1019
 
            A1= abuf0[i2  ]>>7;\
1020
 
            A2= abuf0[i2+1]>>7;\
1021
 
        }\
1022
 
    r = (type *)c->table_rV[V];\
1023
 
    g = (type *)(c->table_gU[U] + c->table_gV[V]);\
1024
 
    b = (type *)c->table_bU[U];
1025
 
 
1026
 
#define YSCALE_YUV_2_ANYRGB_C(func)\
1027
 
    switch(c->dstFormat) {\
1028
 
    case PIX_FMT_RGBA:\
1029
 
    case PIX_FMT_BGRA:\
1030
 
        if (CONFIG_SMALL) {\
1031
 
            int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\
1032
 
            func(uint32_t,needAlpha)\
1033
 
                ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? (A1<<24) : 0);\
1034
 
                ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? (A2<<24) : 0);\
1035
 
            }\
1036
 
        } else {\
1037
 
            if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\
1038
 
                func(uint32_t,1)\
1039
 
                    ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (A1<<24);\
1040
 
                    ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (A2<<24);\
1041
 
                }\
1042
 
            } else {\
1043
 
                func(uint32_t,0)\
1044
 
                    ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\
1045
 
                    ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\
1046
 
                }\
1047
 
            }\
1048
 
        }\
1049
 
        break;\
1050
 
    case PIX_FMT_ARGB:\
1051
 
    case PIX_FMT_ABGR:\
1052
 
        if (CONFIG_SMALL) {\
1053
 
            int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\
1054
 
            func(uint32_t,needAlpha)\
1055
 
                ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? A1 : 0);\
1056
 
                ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? A2 : 0);\
1057
 
            }\
1058
 
        } else {\
1059
 
            if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\
1060
 
                func(uint32_t,1)\
1061
 
                    ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + A1;\
1062
 
                    ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + A2;\
1063
 
                }\
1064
 
            } else {\
1065
 
                func(uint32_t,0)\
1066
 
                    ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\
1067
 
                    ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\
1068
 
                }\
1069
 
            }\
1070
 
        }                \
1071
 
        break;\
1072
 
    case PIX_FMT_RGB24:\
1073
 
        func(uint8_t,0)\
1074
 
            ((uint8_t*)dest)[0]= r[Y1];\
1075
 
            ((uint8_t*)dest)[1]= g[Y1];\
1076
 
            ((uint8_t*)dest)[2]= b[Y1];\
1077
 
            ((uint8_t*)dest)[3]= r[Y2];\
1078
 
            ((uint8_t*)dest)[4]= g[Y2];\
1079
 
            ((uint8_t*)dest)[5]= b[Y2];\
1080
 
            dest+=6;\
1081
 
        }\
1082
 
        break;\
1083
 
    case PIX_FMT_BGR24:\
1084
 
        func(uint8_t,0)\
1085
 
            ((uint8_t*)dest)[0]= b[Y1];\
1086
 
            ((uint8_t*)dest)[1]= g[Y1];\
1087
 
            ((uint8_t*)dest)[2]= r[Y1];\
1088
 
            ((uint8_t*)dest)[3]= b[Y2];\
1089
 
            ((uint8_t*)dest)[4]= g[Y2];\
1090
 
            ((uint8_t*)dest)[5]= r[Y2];\
1091
 
            dest+=6;\
1092
 
        }\
1093
 
        break;\
1094
 
    case PIX_FMT_RGB565:\
1095
 
    case PIX_FMT_BGR565:\
1096
 
        {\
1097
 
            const int dr1= dither_2x2_8[y&1    ][0];\
1098
 
            const int dg1= dither_2x2_4[y&1    ][0];\
1099
 
            const int db1= dither_2x2_8[(y&1)^1][0];\
1100
 
            const int dr2= dither_2x2_8[y&1    ][1];\
1101
 
            const int dg2= dither_2x2_4[y&1    ][1];\
1102
 
            const int db2= dither_2x2_8[(y&1)^1][1];\
1103
 
            func(uint16_t,0)\
1104
 
                ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\
1105
 
                ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\
1106
 
            }\
1107
 
        }\
1108
 
        break;\
1109
 
    case PIX_FMT_RGB555:\
1110
 
    case PIX_FMT_BGR555:\
1111
 
        {\
1112
 
            const int dr1= dither_2x2_8[y&1    ][0];\
1113
 
            const int dg1= dither_2x2_8[y&1    ][1];\
1114
 
            const int db1= dither_2x2_8[(y&1)^1][0];\
1115
 
            const int dr2= dither_2x2_8[y&1    ][1];\
1116
 
            const int dg2= dither_2x2_8[y&1    ][0];\
1117
 
            const int db2= dither_2x2_8[(y&1)^1][1];\
1118
 
            func(uint16_t,0)\
1119
 
                ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\
1120
 
                ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\
1121
 
            }\
1122
 
        }\
1123
 
        break;\
1124
 
    case PIX_FMT_RGB444:\
1125
 
    case PIX_FMT_BGR444:\
1126
 
        {\
1127
 
            const int dr1= dither_4x4_16[y&3    ][0];\
1128
 
            const int dg1= dither_4x4_16[y&3    ][1];\
1129
 
            const int db1= dither_4x4_16[(y&3)^3][0];\
1130
 
            const int dr2= dither_4x4_16[y&3    ][1];\
1131
 
            const int dg2= dither_4x4_16[y&3    ][0];\
1132
 
            const int db2= dither_4x4_16[(y&3)^3][1];\
1133
 
            func(uint16_t,0)\
1134
 
                ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\
1135
 
                ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\
1136
 
            }\
1137
 
        }\
1138
 
        break;\
1139
 
    case PIX_FMT_RGB8:\
1140
 
    case PIX_FMT_BGR8:\
1141
 
        {\
1142
 
            const uint8_t * const d64= dither_8x8_73[y&7];\
1143
 
            const uint8_t * const d32= dither_8x8_32[y&7];\
1144
 
            func(uint8_t,0)\
1145
 
                ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];\
1146
 
                ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];\
1147
 
            }\
1148
 
        }\
1149
 
        break;\
1150
 
    case PIX_FMT_RGB4:\
1151
 
    case PIX_FMT_BGR4:\
1152
 
        {\
1153
 
            const uint8_t * const d64= dither_8x8_73 [y&7];\
1154
 
            const uint8_t * const d128=dither_8x8_220[y&7];\
1155
 
            func(uint8_t,0)\
1156
 
                ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]\
1157
 
                                 + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\
1158
 
            }\
1159
 
        }\
1160
 
        break;\
1161
 
    case PIX_FMT_RGB4_BYTE:\
1162
 
    case PIX_FMT_BGR4_BYTE:\
1163
 
        {\
1164
 
            const uint8_t * const d64= dither_8x8_73 [y&7];\
1165
 
            const uint8_t * const d128=dither_8x8_220[y&7];\
1166
 
            func(uint8_t,0)\
1167
 
                ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\
1168
 
                ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\
1169
 
            }\
1170
 
        }\
1171
 
        break;\
1172
 
    }
1173
 
 
1174
 
static void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter,
 
1141
            int A1, A2;
 
1142
            const void *r =  c->table_rV[V],
 
1143
                       *g = (c->table_gU[U] + c->table_gV[V]),
 
1144
                       *b =  c->table_bU[U];
 
1145
 
 
1146
            if (hasAlpha) {
 
1147
                A1 = abuf0[i * 2    ] >> 7;
 
1148
                A2 = abuf0[i * 2 + 1] >> 7;
 
1149
            }
 
1150
 
 
1151
            yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
 
1152
                          r, g, b, y, target, hasAlpha);
 
1153
        }
 
1154
    }
 
1155
}
 
1156
 
 
1157
#define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
 
1158
static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
 
1159
                                const int16_t **lumSrc, int lumFilterSize, \
 
1160
                                const int16_t *chrFilter, const int16_t **chrUSrc, \
 
1161
                                const int16_t **chrVSrc, int chrFilterSize, \
 
1162
                                const int16_t **alpSrc, uint8_t *dest, int dstW, \
 
1163
                                int y) \
 
1164
{ \
 
1165
    name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
 
1166
                                  chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
 
1167
                                  alpSrc, dest, dstW, y, fmt, hasAlpha); \
 
1168
}
 
1169
#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
 
1170
YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
 
1171
static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
 
1172
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
 
1173
                                const int16_t *abuf[2], uint8_t *dest, int dstW, \
 
1174
                                int yalpha, int uvalpha, int y) \
 
1175
{ \
 
1176
    name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
 
1177
                                  dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
 
1178
} \
 
1179
 \
 
1180
static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
 
1181
                                const int16_t *ubuf[2], const int16_t *vbuf[2], \
 
1182
                                const int16_t *abuf0, uint8_t *dest, int dstW, \
 
1183
                                int uvalpha, int y) \
 
1184
{ \
 
1185
    name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
 
1186
                                  dstW, uvalpha, y, fmt, hasAlpha); \
 
1187
}
 
1188
 
 
1189
#if CONFIG_SMALL
 
1190
YUV2RGBWRAPPER(yuv2rgb,,  32_1,  PIX_FMT_RGB32_1,   CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
 
1191
YUV2RGBWRAPPER(yuv2rgb,,  32,    PIX_FMT_RGB32,     CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
 
1192
#else
 
1193
#if CONFIG_SWSCALE_ALPHA
 
1194
YUV2RGBWRAPPER(yuv2rgb,, a32_1,  PIX_FMT_RGB32_1,   1)
 
1195
YUV2RGBWRAPPER(yuv2rgb,, a32,    PIX_FMT_RGB32,     1)
 
1196
#endif
 
1197
YUV2RGBWRAPPER(yuv2rgb,, x32_1,  PIX_FMT_RGB32_1,   0)
 
1198
YUV2RGBWRAPPER(yuv2rgb,, x32,    PIX_FMT_RGB32,     0)
 
1199
#endif
 
1200
YUV2RGBWRAPPER(yuv2, rgb, rgb24, PIX_FMT_RGB24,   0)
 
1201
YUV2RGBWRAPPER(yuv2, rgb, bgr24, PIX_FMT_BGR24,   0)
 
1202
YUV2RGBWRAPPER(yuv2rgb,,  16,    PIX_FMT_RGB565,    0)
 
1203
YUV2RGBWRAPPER(yuv2rgb,,  15,    PIX_FMT_RGB555,    0)
 
1204
YUV2RGBWRAPPER(yuv2rgb,,  12,    PIX_FMT_RGB444,    0)
 
1205
YUV2RGBWRAPPER(yuv2rgb,,   8,    PIX_FMT_RGB8,      0)
 
1206
YUV2RGBWRAPPER(yuv2rgb,,   4,    PIX_FMT_RGB4,      0)
 
1207
YUV2RGBWRAPPER(yuv2rgb,,   4b,   PIX_FMT_RGB4_BYTE, 0)
 
1208
 
 
1209
static av_always_inline void
 
1210
yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
1175
1211
                          const int16_t **lumSrc, int lumFilterSize,
1176
1212
                          const int16_t *chrFilter, const int16_t **chrUSrc,
1177
1213
                          const int16_t **chrVSrc, int chrFilterSize,
1178
 
                          const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
1179
 
{
1180
 
    int i;
1181
 
    YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGBX_C)
1182
 
}
1183
 
 
1184
 
static void yuv2rgbX_c_full(SwsContext *c, const int16_t *lumFilter,
1185
 
                            const int16_t **lumSrc, int lumFilterSize,
1186
 
                            const int16_t *chrFilter, const int16_t **chrUSrc,
1187
 
                            const int16_t **chrVSrc, int chrFilterSize,
1188
 
                            const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
1189
 
{
1190
 
    int i;
1191
 
    int step= c->dstFormatBpp/8;
1192
 
    int aidx= 3;
1193
 
 
1194
 
    switch(c->dstFormat) {
1195
 
    case PIX_FMT_ARGB:
1196
 
        dest++;
1197
 
        aidx= 0;
1198
 
    case PIX_FMT_RGB24:
1199
 
        aidx--;
1200
 
    case PIX_FMT_RGBA:
1201
 
        if (CONFIG_SMALL) {
1202
 
            int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;
1203
 
            YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha)
1204
 
                dest[aidx]= needAlpha ? A : 255;
1205
 
                dest[0]= R>>22;
1206
 
                dest[1]= G>>22;
1207
 
                dest[2]= B>>22;
1208
 
                dest+= step;
1209
 
            }
1210
 
        } else {
1211
 
            if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1212
 
                YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1)
1213
 
                    dest[aidx]= A;
1214
 
                    dest[0]= R>>22;
1215
 
                    dest[1]= G>>22;
1216
 
                    dest[2]= B>>22;
1217
 
                    dest+= step;
1218
 
                }
1219
 
            } else {
1220
 
                YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0)
1221
 
                    dest[aidx]= 255;
1222
 
                    dest[0]= R>>22;
1223
 
                    dest[1]= G>>22;
1224
 
                    dest[2]= B>>22;
1225
 
                    dest+= step;
1226
 
                }
1227
 
            }
1228
 
        }
1229
 
        break;
1230
 
    case PIX_FMT_ABGR:
1231
 
        dest++;
1232
 
        aidx= 0;
1233
 
    case PIX_FMT_BGR24:
1234
 
        aidx--;
1235
 
    case PIX_FMT_BGRA:
1236
 
        if (CONFIG_SMALL) {
1237
 
            int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;
1238
 
            YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha)
1239
 
                dest[aidx]= needAlpha ? A : 255;
1240
 
                dest[0]= B>>22;
1241
 
                dest[1]= G>>22;
1242
 
                dest[2]= R>>22;
1243
 
                dest+= step;
1244
 
            }
1245
 
        } else {
1246
 
            if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1247
 
                YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1)
1248
 
                    dest[aidx]= A;
1249
 
                    dest[0]= B>>22;
1250
 
                    dest[1]= G>>22;
1251
 
                    dest[2]= R>>22;
1252
 
                    dest+= step;
1253
 
                }
1254
 
            } else {
1255
 
                YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0)
1256
 
                    dest[aidx]= 255;
1257
 
                    dest[0]= B>>22;
1258
 
                    dest[1]= G>>22;
1259
 
                    dest[2]= R>>22;
1260
 
                    dest+= step;
1261
 
                }
1262
 
            }
1263
 
        }
1264
 
        break;
1265
 
    default:
1266
 
        assert(0);
1267
 
    }
1268
 
}
1269
 
 
1270
 
/**
1271
 
 * vertical bilinear scale YV12 to RGB
1272
 
 */
1273
 
static void yuv2packed2_c(SwsContext *c, const uint16_t *buf0,
1274
 
                          const uint16_t *buf1, const uint16_t *ubuf0,
1275
 
                          const uint16_t *ubuf1, const uint16_t *vbuf0,
1276
 
                          const uint16_t *vbuf1, const uint16_t *abuf0,
1277
 
                          const uint16_t *abuf1, uint8_t *dest, int dstW,
1278
 
                          int yalpha, int uvalpha, int y)
1279
 
{
1280
 
    int  yalpha1=4095- yalpha;
1281
 
    int uvalpha1=4095-uvalpha;
1282
 
    int i;
1283
 
 
1284
 
    YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C)
1285
 
}
1286
 
 
1287
 
/**
1288
 
 * YV12 to RGB without scaling or interpolating
1289
 
 */
1290
 
static void yuv2packed1_c(SwsContext *c, const uint16_t *buf0,
1291
 
                          const uint16_t *ubuf0, const uint16_t *ubuf1,
1292
 
                          const uint16_t *vbuf0, const uint16_t *vbuf1,
1293
 
                          const uint16_t *abuf0, uint8_t *dest, int dstW,
1294
 
                          int uvalpha, enum PixelFormat dstFormat,
1295
 
                          int flags, int y)
1296
 
{
1297
 
    int i;
1298
 
 
1299
 
    if (uvalpha < 2048) {
1300
 
        YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C)
1301
 
    } else {
1302
 
        YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C)
1303
 
    }
1304
 
}
 
1214
                          const int16_t **alpSrc, uint8_t *dest,
 
1215
                          int dstW, int y, enum PixelFormat target, int hasAlpha)
 
1216
{
 
1217
    int i;
 
1218
    int step = (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) ? 3 : 4;
 
1219
 
 
1220
    for (i = 0; i < dstW; i++) {
 
1221
        int j;
 
1222
        int Y = 0;
 
1223
        int U = -128 << 19;
 
1224
        int V = -128 << 19;
 
1225
        int av_unused A;
 
1226
        int R, G, B;
 
1227
 
 
1228
        for (j = 0; j < lumFilterSize; j++) {
 
1229
            Y += lumSrc[j][i] * lumFilter[j];
 
1230
        }
 
1231
        for (j = 0; j < chrFilterSize; j++) {
 
1232
            U += chrUSrc[j][i] * chrFilter[j];
 
1233
            V += chrVSrc[j][i] * chrFilter[j];
 
1234
        }
 
1235
        Y >>= 10;
 
1236
        U >>= 10;
 
1237
        V >>= 10;
 
1238
        if (hasAlpha) {
 
1239
            A = 1 << 21;
 
1240
            for (j = 0; j < lumFilterSize; j++) {
 
1241
                A += alpSrc[j][i] * lumFilter[j];
 
1242
            }
 
1243
            A >>= 19;
 
1244
            if (A & 0x100)
 
1245
                A = av_clip_uint8(A);
 
1246
        }
 
1247
        Y -= c->yuv2rgb_y_offset;
 
1248
        Y *= c->yuv2rgb_y_coeff;
 
1249
        Y += 1 << 21;
 
1250
        R = Y + V*c->yuv2rgb_v2r_coeff;
 
1251
        G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
 
1252
        B = Y +                          U*c->yuv2rgb_u2b_coeff;
 
1253
        if ((R | G | B) & 0xC0000000) {
 
1254
            R = av_clip_uintp2(R, 30);
 
1255
            G = av_clip_uintp2(G, 30);
 
1256
            B = av_clip_uintp2(B, 30);
 
1257
        }
 
1258
 
 
1259
        switch(target) {
 
1260
        case PIX_FMT_ARGB:
 
1261
            dest[0] = hasAlpha ? A : 255;
 
1262
            dest[1] = R >> 22;
 
1263
            dest[2] = G >> 22;
 
1264
            dest[3] = B >> 22;
 
1265
            break;
 
1266
        case PIX_FMT_RGB24:
 
1267
            dest[0] = R >> 22;
 
1268
            dest[1] = G >> 22;
 
1269
            dest[2] = B >> 22;
 
1270
            break;
 
1271
        case PIX_FMT_RGBA:
 
1272
            dest[0] = R >> 22;
 
1273
            dest[1] = G >> 22;
 
1274
            dest[2] = B >> 22;
 
1275
            dest[3] = hasAlpha ? A : 255;
 
1276
            break;
 
1277
        case PIX_FMT_ABGR:
 
1278
            dest[0] = hasAlpha ? A : 255;
 
1279
            dest[1] = B >> 22;
 
1280
            dest[2] = G >> 22;
 
1281
            dest[3] = R >> 22;
 
1282
            dest += 4;
 
1283
            break;
 
1284
        case PIX_FMT_BGR24:
 
1285
            dest[0] = B >> 22;
 
1286
            dest[1] = G >> 22;
 
1287
            dest[2] = R >> 22;
 
1288
            break;
 
1289
        case PIX_FMT_BGRA:
 
1290
            dest[0] = B >> 22;
 
1291
            dest[1] = G >> 22;
 
1292
            dest[2] = R >> 22;
 
1293
            dest[3] = hasAlpha ? A : 255;
 
1294
            break;
 
1295
        }
 
1296
        dest += step;
 
1297
    }
 
1298
}
 
1299
 
 
1300
#if CONFIG_SMALL
 
1301
YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA,  CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
 
1302
YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR,  CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
 
1303
YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA,  CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
 
1304
YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB,  CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
 
1305
#else
 
1306
#if CONFIG_SWSCALE_ALPHA
 
1307
YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA,  1)
 
1308
YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR,  1)
 
1309
YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA,  1)
 
1310
YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB,  1)
 
1311
#endif
 
1312
YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, PIX_FMT_BGRA,  0)
 
1313
YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, PIX_FMT_ABGR,  0)
 
1314
YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, PIX_FMT_RGBA,  0)
 
1315
YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, PIX_FMT_ARGB,  0)
 
1316
#endif
 
1317
YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full,  PIX_FMT_BGR24, 0)
 
1318
YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full,  PIX_FMT_RGB24, 0)
1305
1319
 
1306
1320
static av_always_inline void fillPlane(uint8_t* plane, int stride,
1307
1321
                                       int width, int height,
1321
1335
#define b ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? r_b : b_r)
1322
1336
 
1323
1337
static av_always_inline void
1324
 
rgb48ToY_c_template(uint8_t *dst, const uint8_t *src, int width,
 
1338
rgb48ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
1325
1339
                    enum PixelFormat origin)
1326
1340
{
1327
1341
    int i;
1328
1342
    for (i = 0; i < width; i++) {
1329
 
        int r_b = input_pixel(&src[i*6+0]) >> 8;
1330
 
        int   g = input_pixel(&src[i*6+2]) >> 8;
1331
 
        int b_r = input_pixel(&src[i*6+4]) >> 8;
 
1343
        unsigned int r_b = input_pixel(&src[i*3+0]);
 
1344
        unsigned int   g = input_pixel(&src[i*3+1]);
 
1345
        unsigned int b_r = input_pixel(&src[i*3+2]);
1332
1346
 
1333
 
        dst[i] = (RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 
1347
        dst[i] = (RY*r + GY*g + BY*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
1334
1348
    }
1335
1349
}
1336
1350
 
1337
1351
static av_always_inline void
1338
 
rgb48ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
1339
 
                    const uint8_t *src1, const uint8_t *src2,
 
1352
rgb48ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
 
1353
                    const uint16_t *src1, const uint16_t *src2,
1340
1354
                    int width, enum PixelFormat origin)
1341
1355
{
1342
1356
    int i;
1343
1357
    assert(src1==src2);
1344
1358
    for (i = 0; i < width; i++) {
1345
 
        int r_b = input_pixel(&src1[i*6+0]) >> 8;
1346
 
        int   g = input_pixel(&src1[i*6+2]) >> 8;
1347
 
        int b_r = input_pixel(&src1[i*6+4]) >> 8;
 
1359
        int r_b = input_pixel(&src1[i*3+0]);
 
1360
        int   g = input_pixel(&src1[i*3+1]);
 
1361
        int b_r = input_pixel(&src1[i*3+2]);
1348
1362
 
1349
 
        dstU[i] = (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
1350
 
        dstV[i] = (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 
1363
        dstU[i] = (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 
1364
        dstV[i] = (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
1351
1365
    }
1352
1366
}
1353
1367
 
1354
1368
static av_always_inline void
1355
 
rgb48ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV,
1356
 
                          const uint8_t *src1, const uint8_t *src2,
 
1369
rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
 
1370
                          const uint16_t *src1, const uint16_t *src2,
1357
1371
                          int width, enum PixelFormat origin)
1358
1372
{
1359
1373
    int i;
1360
1374
    assert(src1==src2);
1361
1375
    for (i = 0; i < width; i++) {
1362
 
        int r_b = (input_pixel(&src1[12*i + 0]) >> 8) + (input_pixel(&src1[12*i + 6]) >> 8);
1363
 
        int   g = (input_pixel(&src1[12*i + 2]) >> 8) + (input_pixel(&src1[12*i + 8]) >> 8);
1364
 
        int b_r = (input_pixel(&src1[12*i + 4]) >> 8) + (input_pixel(&src1[12*i + 10]) >> 8);
 
1376
        int r_b = (input_pixel(&src1[6 * i + 0]) + input_pixel(&src1[6 * i + 3]) + 1) >> 1;
 
1377
        int   g = (input_pixel(&src1[6 * i + 1]) + input_pixel(&src1[6 * i + 4]) + 1) >> 1;
 
1378
        int b_r = (input_pixel(&src1[6 * i + 2]) + input_pixel(&src1[6 * i + 5]) + 1) >> 1;
1365
1379
 
1366
 
        dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
1367
 
        dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT+1);
 
1380
        dstU[i]= (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
 
1381
        dstV[i]= (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT;
1368
1382
    }
1369
1383
}
1370
1384
 
1373
1387
#undef input_pixel
1374
1388
 
1375
1389
#define rgb48funcs(pattern, BE_LE, origin) \
1376
 
static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *dst, const uint8_t *src, \
 
1390
static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, \
1377
1391
                                    int width, uint32_t *unused) \
1378
1392
{ \
 
1393
    const uint16_t *src = (const uint16_t *) _src; \
 
1394
    uint16_t *dst = (uint16_t *) _dst; \
1379
1395
    rgb48ToY_c_template(dst, src, width, origin); \
1380
1396
} \
1381
1397
 \
1382
 
static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
1383
 
                                    const uint8_t *src1, const uint8_t *src2, \
 
1398
static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
 
1399
                                    const uint8_t *_src1, const uint8_t *_src2, \
1384
1400
                                    int width, uint32_t *unused) \
1385
1401
{ \
 
1402
    const uint16_t *src1 = (const uint16_t *) _src1, \
 
1403
                   *src2 = (const uint16_t *) _src2; \
 
1404
    uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
1386
1405
    rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
1387
1406
} \
1388
1407
 \
1389
 
static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \
1390
 
                                    const uint8_t *src1, const uint8_t *src2, \
 
1408
static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \
 
1409
                                    const uint8_t *_src1, const uint8_t *_src2, \
1391
1410
                                    int width, uint32_t *unused) \
1392
1411
{ \
 
1412
    const uint16_t *src1 = (const uint16_t *) _src1, \
 
1413
                   *src2 = (const uint16_t *) _src2; \
 
1414
    uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
1393
1415
    rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \
1394
1416
}
1395
1417
 
1396
 
rgb48funcs(rgb, LE, PIX_FMT_RGB48LE);
1397
 
rgb48funcs(rgb, BE, PIX_FMT_RGB48BE);
1398
 
rgb48funcs(bgr, LE, PIX_FMT_BGR48LE);
1399
 
rgb48funcs(bgr, BE, PIX_FMT_BGR48BE);
 
1418
rgb48funcs(rgb, LE, PIX_FMT_RGB48LE)
 
1419
rgb48funcs(rgb, BE, PIX_FMT_RGB48BE)
 
1420
rgb48funcs(bgr, LE, PIX_FMT_BGR48LE)
 
1421
rgb48funcs(bgr, BE, PIX_FMT_BGR48BE)
1400
1422
 
1401
1423
#define input_pixel(i) ((origin == PIX_FMT_RGBA || origin == PIX_FMT_BGRA || \
1402
1424
                         origin == PIX_FMT_ARGB || origin == PIX_FMT_ABGR) ? AV_RN32A(&src[(i)*4]) : \
1409
1431
                       int maskr, int maskg, int maskb,
1410
1432
                       int rsh,   int gsh,   int bsh, int S)
1411
1433
{
1412
 
    const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh,
1413
 
              rnd = 33 << (S - 1);
 
1434
    const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh;
 
1435
    const unsigned rnd = 33u << (S - 1);
1414
1436
    int i;
1415
1437
 
1416
1438
    for (i = 0; i < width; i++) {
1432
1454
                        int rsh,   int gsh,   int bsh, int S)
1433
1455
{
1434
1456
    const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
1435
 
              rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
1436
 
              rnd = 257 << (S - 1);
 
1457
              rv = RV << rsh, gv = GV << gsh, bv = BV << bsh;
 
1458
    const unsigned rnd = 257u << (S - 1);
1437
1459
    int i;
1438
1460
 
1439
1461
    for (i = 0; i < width; i++) {
1457
1479
{
1458
1480
    const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh,
1459
1481
              rv = RV << rsh, gv = GV << gsh, bv = BV << bsh,
1460
 
              rnd = 257 << S, maskgx = ~(maskr | maskb);
 
1482
              maskgx = ~(maskr | maskb);
 
1483
    const unsigned rnd = 257u << S;
1461
1484
    int i;
1462
1485
 
1463
1486
    maskr |= maskr << 1; maskb |= maskb << 1; maskg |= maskg << 1;
1508
1531
                                 maskr, maskg, maskb, rsh, gsh, bsh, S); \
1509
1532
}
1510
1533
 
1511
 
rgb16_32_wrapper(PIX_FMT_BGR32,    bgr32,  16, 0,  0, 0, 0xFF0000, 0xFF00,   0x00FF,  8, 0,  8, RGB2YUV_SHIFT+8);
1512
 
rgb16_32_wrapper(PIX_FMT_BGR32_1,  bgr321, 16, 0,  0, 8, 0xFF0000, 0xFF00,   0x00FF,  8, 0,  8, RGB2YUV_SHIFT+8);
1513
 
rgb16_32_wrapper(PIX_FMT_RGB32,    rgb32,   0, 0, 16, 0,   0x00FF, 0xFF00, 0xFF0000,  8, 0,  8, RGB2YUV_SHIFT+8);
1514
 
rgb16_32_wrapper(PIX_FMT_RGB32_1,  rgb321,  0, 0, 16, 8,   0x00FF, 0xFF00, 0xFF0000,  8, 0,  8, RGB2YUV_SHIFT+8);
1515
 
rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0,  0, 0,   0x001F, 0x07E0,   0xF800, 11, 5,  0, RGB2YUV_SHIFT+8);
1516
 
rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0,  0, 0,   0x001F, 0x03E0,   0x7C00, 10, 5,  0, RGB2YUV_SHIFT+7);
1517
 
rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0,  0, 0,   0xF800, 0x07E0,   0x001F,  0, 5, 11, RGB2YUV_SHIFT+8);
1518
 
rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0,  0, 0,   0x7C00, 0x03E0,   0x001F,  0, 5, 10, RGB2YUV_SHIFT+7);
1519
 
rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0,  0, 0,   0x001F, 0x07E0,   0xF800, 11, 5,  0, RGB2YUV_SHIFT+8);
1520
 
rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0,  0, 0,   0x001F, 0x03E0,   0x7C00, 10, 5,  0, RGB2YUV_SHIFT+7);
1521
 
rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0,  0, 0,   0xF800, 0x07E0,   0x001F,  0, 5, 11, RGB2YUV_SHIFT+8);
1522
 
rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0,  0, 0,   0x7C00, 0x03E0,   0x001F,  0, 5, 10, RGB2YUV_SHIFT+7);
 
1534
rgb16_32_wrapper(PIX_FMT_BGR32,    bgr32,  16, 0,  0, 0, 0xFF0000, 0xFF00,   0x00FF,  8, 0,  8, RGB2YUV_SHIFT+8)
 
1535
rgb16_32_wrapper(PIX_FMT_BGR32_1,  bgr321, 16, 0,  0, 8, 0xFF0000, 0xFF00,   0x00FF,  8, 0,  8, RGB2YUV_SHIFT+8)
 
1536
rgb16_32_wrapper(PIX_FMT_RGB32,    rgb32,   0, 0, 16, 0,   0x00FF, 0xFF00, 0xFF0000,  8, 0,  8, RGB2YUV_SHIFT+8)
 
1537
rgb16_32_wrapper(PIX_FMT_RGB32_1,  rgb321,  0, 0, 16, 8,   0x00FF, 0xFF00, 0xFF0000,  8, 0,  8, RGB2YUV_SHIFT+8)
 
1538
rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0,  0, 0,   0x001F, 0x07E0,   0xF800, 11, 5,  0, RGB2YUV_SHIFT+8)
 
1539
rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0,  0, 0,   0x001F, 0x03E0,   0x7C00, 10, 5,  0, RGB2YUV_SHIFT+7)
 
1540
rgb16_32_wrapper(PIX_FMT_BGR444LE, bgr12le, 0, 0,  0, 0,   0x000F, 0x00F0,   0x0F00,  8, 4,  0, RGB2YUV_SHIFT+4)
 
1541
rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0,  0, 0,   0xF800, 0x07E0,   0x001F,  0, 5, 11, RGB2YUV_SHIFT+8)
 
1542
rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0,  0, 0,   0x7C00, 0x03E0,   0x001F,  0, 5, 10, RGB2YUV_SHIFT+7)
 
1543
rgb16_32_wrapper(PIX_FMT_RGB444LE, rgb12le, 0, 0,  0, 0,   0x0F00, 0x00F0,   0x000F,  0, 4,  8, RGB2YUV_SHIFT+4)
 
1544
rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0,  0, 0,   0x001F, 0x07E0,   0xF800, 11, 5,  0, RGB2YUV_SHIFT+8)
 
1545
rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0,  0, 0,   0x001F, 0x03E0,   0x7C00, 10, 5,  0, RGB2YUV_SHIFT+7)
 
1546
rgb16_32_wrapper(PIX_FMT_BGR444BE, bgr12be, 0, 0,  0, 0,   0x000F, 0x00F0,   0x0F00,  8, 4,  0, RGB2YUV_SHIFT+4)
 
1547
rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0,  0, 0,   0xF800, 0x07E0,   0x001F,  0, 5, 11, RGB2YUV_SHIFT+8)
 
1548
rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0,  0, 0,   0x7C00, 0x03E0,   0x001F,  0, 5, 10, RGB2YUV_SHIFT+7)
 
1549
rgb16_32_wrapper(PIX_FMT_RGB444BE, rgb12be, 0, 0,  0, 0,   0x0F00, 0x00F0,   0x000F,  0, 4,  8, RGB2YUV_SHIFT+4)
1523
1550
 
1524
1551
static void abgrToA_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused)
1525
1552
{
1604
1631
    assert(src1 == src2);
1605
1632
}
1606
1633
 
1607
 
static void LEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
1608
 
                     const uint8_t *src2, int width, uint32_t *unused)
1609
 
{
1610
 
    int i;
1611
 
    for (i=0; i<width; i++) {
1612
 
        dstU[i]= src1[2*i + 1];
1613
 
        dstV[i]= src2[2*i + 1];
 
1634
static void bswap16Y_c(uint8_t *_dst, const uint8_t *_src, int width, uint32_t *unused)
 
1635
{
 
1636
    int i;
 
1637
    const uint16_t *src = (const uint16_t *) _src;
 
1638
    uint16_t *dst = (uint16_t *) _dst;
 
1639
    for (i=0; i<width; i++) {
 
1640
        dst[i] = av_bswap16(src[i]);
 
1641
    }
 
1642
}
 
1643
 
 
1644
static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src1,
 
1645
                        const uint8_t *_src2, int width, uint32_t *unused)
 
1646
{
 
1647
    int i;
 
1648
    const uint16_t *src1 = (const uint16_t *) _src1,
 
1649
                   *src2 = (const uint16_t *) _src2;
 
1650
    uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV;
 
1651
    for (i=0; i<width; i++) {
 
1652
        dstU[i] = av_bswap16(src1[i]);
 
1653
        dstV[i] = av_bswap16(src2[i]);
1614
1654
    }
1615
1655
}
1616
1656
 
1635
1675
    assert(src1 == src2);
1636
1676
}
1637
1677
 
1638
 
static void BEToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1,
1639
 
                     const uint8_t *src2, int width, uint32_t *unused)
1640
 
{
1641
 
    int i;
1642
 
    for (i=0; i<width; i++) {
1643
 
        dstU[i]= src1[2*i];
1644
 
        dstV[i]= src2[2*i];
1645
 
    }
1646
 
}
1647
 
 
1648
1678
static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
1649
1679
                                        const uint8_t *src, int width)
1650
1680
{
1671
1701
 
1672
1702
#define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
1673
1703
 
1674
 
// FIXME Maybe dither instead.
1675
 
static av_always_inline void
1676
 
yuv9_OR_10ToUV_c_template(uint8_t *dstU, uint8_t *dstV,
1677
 
                          const uint8_t *_srcU, const uint8_t *_srcV,
1678
 
                          int width, enum PixelFormat origin, int depth)
1679
 
{
1680
 
    int i;
1681
 
    const uint16_t *srcU = (const uint16_t *) _srcU;
1682
 
    const uint16_t *srcV = (const uint16_t *) _srcV;
1683
 
 
1684
 
    for (i = 0; i < width; i++) {
1685
 
        dstU[i] = input_pixel(&srcU[i]) >> (depth - 8);
1686
 
        dstV[i] = input_pixel(&srcV[i]) >> (depth - 8);
1687
 
    }
1688
 
}
1689
 
 
1690
 
static av_always_inline void
1691
 
yuv9_or_10ToY_c_template(uint8_t *dstY, const uint8_t *_srcY,
1692
 
                         int width, enum PixelFormat origin, int depth)
1693
 
{
1694
 
    int i;
1695
 
    const uint16_t *srcY = (const uint16_t*)_srcY;
1696
 
 
1697
 
    for (i = 0; i < width; i++)
1698
 
        dstY[i] = input_pixel(&srcY[i]) >> (depth - 8);
1699
 
}
1700
 
 
1701
 
#undef input_pixel
1702
 
 
1703
 
#define YUV_NBPS(depth, BE_LE, origin) \
1704
 
static void BE_LE ## depth ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \
1705
 
                                     const uint8_t *srcU, const uint8_t *srcV, \
1706
 
                                     int width, uint32_t *unused) \
1707
 
{ \
1708
 
    yuv9_OR_10ToUV_c_template(dstU, dstV, srcU, srcV, width, origin, depth); \
1709
 
} \
1710
 
static void BE_LE ## depth ## ToY_c(uint8_t *dstY, const uint8_t *srcY, \
1711
 
                                    int width, uint32_t *unused) \
1712
 
{ \
1713
 
    yuv9_or_10ToY_c_template(dstY, srcY, width, origin, depth); \
1714
 
}
1715
 
 
1716
 
YUV_NBPS( 9, LE, PIX_FMT_YUV420P9LE);
1717
 
YUV_NBPS( 9, BE, PIX_FMT_YUV420P9BE);
1718
 
YUV_NBPS(10, LE, PIX_FMT_YUV420P10LE);
1719
 
YUV_NBPS(10, BE, PIX_FMT_YUV420P10BE);
1720
 
 
1721
1704
static void bgr24ToY_c(uint8_t *dst, const uint8_t *src,
1722
1705
                       int width, uint32_t *unused)
1723
1706
{
1804
1787
    }
1805
1788
}
1806
1789
 
 
1790
static void planar_rgb_to_y(uint8_t *dst, const uint8_t *src[4], int width)
 
1791
{
 
1792
    int i;
 
1793
    for (i = 0; i < width; i++) {
 
1794
        int g = src[0][i];
 
1795
        int b = src[1][i];
 
1796
        int r = src[2][i];
 
1797
 
 
1798
        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
 
1799
    }
 
1800
}
 
1801
 
 
1802
static void planar_rgb16le_to_y(uint8_t *_dst, const uint8_t *_src[4], int width)
 
1803
{
 
1804
    int i;
 
1805
    const uint16_t **src = (const uint16_t **) _src;
 
1806
    uint16_t *dst = (uint16_t *) _dst;
 
1807
    for (i = 0; i < width; i++) {
 
1808
        int g = AV_RL16(src[0] + i);
 
1809
        int b = AV_RL16(src[1] + i);
 
1810
        int r = AV_RL16(src[2] + i);
 
1811
 
 
1812
        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
 
1813
    }
 
1814
}
 
1815
 
 
1816
static void planar_rgb16be_to_y(uint8_t *_dst, const uint8_t *_src[4], int width)
 
1817
{
 
1818
    int i;
 
1819
    const uint16_t **src = (const uint16_t **) _src;
 
1820
    uint16_t *dst = (uint16_t *) _dst;
 
1821
    for (i = 0; i < width; i++) {
 
1822
        int g = AV_RB16(src[0] + i);
 
1823
        int b = AV_RB16(src[1] + i);
 
1824
        int r = AV_RB16(src[2] + i);
 
1825
 
 
1826
        dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
 
1827
    }
 
1828
}
 
1829
 
 
1830
static void planar_rgb_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int width)
 
1831
{
 
1832
    int i;
 
1833
    for (i = 0; i < width; i++) {
 
1834
        int g = src[0][i];
 
1835
        int b = src[1][i];
 
1836
        int r = src[2][i];
 
1837
 
 
1838
        dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
 
1839
        dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
 
1840
    }
 
1841
}
 
1842
 
 
1843
static void planar_rgb16le_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width)
 
1844
{
 
1845
    int i;
 
1846
    const uint16_t **src = (const uint16_t **) _src;
 
1847
    uint16_t *dstU = (uint16_t *) _dstU;
 
1848
    uint16_t *dstV = (uint16_t *) _dstV;
 
1849
    for (i = 0; i < width; i++) {
 
1850
        int g = AV_RL16(src[0] + i);
 
1851
        int b = AV_RL16(src[1] + i);
 
1852
        int r = AV_RL16(src[2] + i);
 
1853
 
 
1854
        dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
 
1855
        dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
 
1856
    }
 
1857
}
 
1858
 
 
1859
static void planar_rgb16be_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width)
 
1860
{
 
1861
    int i;
 
1862
    const uint16_t **src = (const uint16_t **) _src;
 
1863
    uint16_t *dstU = (uint16_t *) _dstU;
 
1864
    uint16_t *dstV = (uint16_t *) _dstV;
 
1865
    for (i = 0; i < width; i++) {
 
1866
        int g = AV_RB16(src[0] + i);
 
1867
        int b = AV_RB16(src[1] + i);
 
1868
        int r = AV_RB16(src[2] + i);
 
1869
 
 
1870
        dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
 
1871
        dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1);
 
1872
    }
 
1873
}
 
1874
 
 
1875
static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *_src,
 
1876
                           const int16_t *filter,
 
1877
                           const int16_t *filterPos, int filterSize)
 
1878
{
 
1879
    int i;
 
1880
    int32_t *dst = (int32_t *) _dst;
 
1881
    const uint16_t *src = (const uint16_t *) _src;
 
1882
    int bits = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
 
1883
    int sh = bits - 4;
 
1884
 
 
1885
    for (i = 0; i < dstW; i++) {
 
1886
        int j;
 
1887
        int srcPos = filterPos[i];
 
1888
        int val = 0;
 
1889
 
 
1890
        for (j = 0; j < filterSize; j++) {
 
1891
            val += src[srcPos + j] * filter[filterSize * i + j];
 
1892
        }
 
1893
        // filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit
 
1894
        dst[i] = FFMIN(val >> sh, (1 << 19) - 1);
 
1895
    }
 
1896
}
 
1897
 
 
1898
static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *_src,
 
1899
                           const int16_t *filter,
 
1900
                           const int16_t *filterPos, int filterSize)
 
1901
{
 
1902
    int i;
 
1903
    const uint16_t *src = (const uint16_t *) _src;
 
1904
    int sh = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1;
 
1905
 
 
1906
    for (i = 0; i < dstW; i++) {
 
1907
        int j;
 
1908
        int srcPos = filterPos[i];
 
1909
        int val = 0;
 
1910
 
 
1911
        for (j = 0; j < filterSize; j++) {
 
1912
            val += src[srcPos + j] * filter[filterSize * i + j];
 
1913
        }
 
1914
        // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit
 
1915
        dst[i] = FFMIN(val >> sh, (1 << 15) - 1);
 
1916
    }
 
1917
}
1807
1918
 
1808
1919
// bilinear / bicubic scaling
1809
 
static void hScale_c(int16_t *dst, int dstW, const uint8_t *src,
1810
 
                     int srcW, int xInc,
1811
 
                     const int16_t *filter, const int16_t *filterPos,
1812
 
                     int filterSize)
 
1920
static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
 
1921
                          const int16_t *filter, const int16_t *filterPos,
 
1922
                          int filterSize)
1813
1923
{
1814
1924
    int i;
1815
1925
    for (i=0; i<dstW; i++) {
1825
1935
    }
1826
1936
}
1827
1937
 
 
1938
static void hScale8To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *src,
 
1939
                          const int16_t *filter, const int16_t *filterPos,
 
1940
                          int filterSize)
 
1941
{
 
1942
    int i;
 
1943
    int32_t *dst = (int32_t *) _dst;
 
1944
    for (i=0; i<dstW; i++) {
 
1945
        int j;
 
1946
        int srcPos= filterPos[i];
 
1947
        int val=0;
 
1948
        for (j=0; j<filterSize; j++) {
 
1949
            val += ((int)src[srcPos + j])*filter[filterSize*i + j];
 
1950
        }
 
1951
        //filter += hFilterSize;
 
1952
        dst[i] = FFMIN(val>>3, (1<<19)-1); // the cubic equation does overflow ...
 
1953
        //dst[i] = val>>7;
 
1954
    }
 
1955
}
 
1956
 
1828
1957
//FIXME all pal and rgb srcFormats could do this convertion as well
1829
1958
//FIXME all scalers more complex than bilinear could do half of this transform
1830
1959
static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width)
1856
1985
        dst[i] = (dst[i]*14071 + 33561947)>>14;
1857
1986
}
1858
1987
 
 
1988
static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
 
1989
{
 
1990
    int i;
 
1991
    int32_t *dstU = (int32_t *) _dstU;
 
1992
    int32_t *dstV = (int32_t *) _dstV;
 
1993
    for (i = 0; i < width; i++) {
 
1994
        dstU[i] = (FFMIN(dstU[i],30775<<4)*4663 - (9289992<<4))>>12; //-264
 
1995
        dstV[i] = (FFMIN(dstV[i],30775<<4)*4663 - (9289992<<4))>>12; //-264
 
1996
    }
 
1997
}
 
1998
static void chrRangeFromJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
 
1999
{
 
2000
    int i;
 
2001
    int32_t *dstU = (int32_t *) _dstU;
 
2002
    int32_t *dstV = (int32_t *) _dstV;
 
2003
    for (i = 0; i < width; i++) {
 
2004
        dstU[i] = (dstU[i]*1799 + (4081085<<4))>>11; //1469
 
2005
        dstV[i] = (dstV[i]*1799 + (4081085<<4))>>11; //1469
 
2006
    }
 
2007
}
 
2008
static void lumRangeToJpeg16_c(int16_t *_dst, int width)
 
2009
{
 
2010
    int i;
 
2011
    int32_t *dst = (int32_t *) _dst;
 
2012
    for (i = 0; i < width; i++)
 
2013
        dst[i] = (FFMIN(dst[i],30189<<4)*4769 - (39057361<<2))>>12;
 
2014
}
 
2015
static void lumRangeFromJpeg16_c(int16_t *_dst, int width)
 
2016
{
 
2017
    int i;
 
2018
    int32_t *dst = (int32_t *) _dst;
 
2019
    for (i = 0; i < width; i++)
 
2020
        dst[i] = (dst[i]*14071 + (33561947<<4))>>14;
 
2021
}
 
2022
 
1859
2023
static void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
1860
2024
                           const uint8_t *src, int srcW, int xInc)
1861
2025
{
1870
2034
}
1871
2035
 
1872
2036
// *** horizontal scale Y line to temp buffer
1873
 
static av_always_inline void hyscale(SwsContext *c, uint16_t *dst, int dstWidth,
1874
 
                                     const uint8_t *src, int srcW, int xInc,
 
2037
static av_always_inline void hyscale(SwsContext *c, int16_t *dst, int dstWidth,
 
2038
                                     const uint8_t *src_in[4], int srcW, int xInc,
1875
2039
                                     const int16_t *hLumFilter,
1876
2040
                                     const int16_t *hLumFilterPos, int hLumFilterSize,
1877
2041
                                     uint8_t *formatConvBuffer,
1879
2043
{
1880
2044
    void (*toYV12)(uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12;
1881
2045
    void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
 
2046
    const uint8_t *src = src_in[isAlpha ? 3 : 0];
1882
2047
 
1883
2048
    if (toYV12) {
1884
2049
        toYV12(formatConvBuffer, src, srcW, pal);
1885
2050
        src= formatConvBuffer;
 
2051
    } else if (c->readLumPlanar && !isAlpha) {
 
2052
        c->readLumPlanar(formatConvBuffer, src_in, srcW);
 
2053
        src = formatConvBuffer;
1886
2054
    }
1887
2055
 
1888
2056
    if (!c->hyscale_fast) {
1889
 
        c->hScale(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize);
 
2057
        c->hyScale(c, dst, dstWidth, src, hLumFilter, hLumFilterPos, hLumFilterSize);
1890
2058
    } else { // fast bilinear upscale / crap downscale
1891
2059
        c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc);
1892
2060
    }
1910
2078
    }
1911
2079
}
1912
2080
 
1913
 
static av_always_inline void hcscale(SwsContext *c, uint16_t *dst1, uint16_t *dst2, int dstWidth,
1914
 
                                     const uint8_t *src1, const uint8_t *src2,
 
2081
static av_always_inline void hcscale(SwsContext *c, int16_t *dst1, int16_t *dst2, int dstWidth,
 
2082
                                     const uint8_t *src_in[4],
1915
2083
                                     int srcW, int xInc, const int16_t *hChrFilter,
1916
2084
                                     const int16_t *hChrFilterPos, int hChrFilterSize,
1917
2085
                                     uint8_t *formatConvBuffer, uint32_t *pal)
1918
2086
{
 
2087
    const uint8_t *src1 = src_in[1], *src2 = src_in[2];
1919
2088
    if (c->chrToYV12) {
1920
 
        uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW, 16);
 
2089
        uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW * FFALIGN(c->srcBpc, 8) >> 3, 16);
1921
2090
        c->chrToYV12(formatConvBuffer, buf2, src1, src2, srcW, pal);
1922
2091
        src1= formatConvBuffer;
1923
2092
        src2= buf2;
 
2093
    } else if (c->readChrPlanar) {
 
2094
        uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW * FFALIGN(c->srcBpc, 8) >> 3, 16);
 
2095
        c->readChrPlanar(formatConvBuffer, buf2, src_in, srcW);
 
2096
        src1= formatConvBuffer;
 
2097
        src2= buf2;
1924
2098
    }
1925
2099
 
1926
2100
    if (!c->hcscale_fast) {
1927
 
        c->hScale(dst1, dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
1928
 
        c->hScale(dst2, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize);
 
2101
        c->hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
 
2102
        c->hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
1929
2103
    } else { // fast bilinear upscale / crap downscale
1930
2104
        c->hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
1931
2105
    }
1936
2110
 
1937
2111
static av_always_inline void
1938
2112
find_c_packed_planar_out_funcs(SwsContext *c,
1939
 
                               yuv2planar1_fn *yuv2yuv1,    yuv2planarX_fn *yuv2yuvX,
 
2113
                               yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX,
 
2114
                               yuv2interleavedX_fn *yuv2nv12cX,
1940
2115
                               yuv2packed1_fn *yuv2packed1, yuv2packed2_fn *yuv2packed2,
1941
2116
                               yuv2packedX_fn *yuv2packedX)
1942
2117
{
1943
2118
    enum PixelFormat dstFormat = c->dstFormat;
1944
2119
 
1945
 
    if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) {
1946
 
        *yuv2yuvX     = yuv2nv12X_c;
1947
 
    } else if (is16BPS(dstFormat)) {
1948
 
        *yuv2yuvX     = isBE(dstFormat) ? yuv2yuvX16BE_c  : yuv2yuvX16LE_c;
 
2120
    if (is16BPS(dstFormat)) {
 
2121
        *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c  : yuv2planeX_16LE_c;
 
2122
        *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c  : yuv2plane1_16LE_c;
1949
2123
    } else if (is9_OR_10BPS(dstFormat)) {
1950
2124
        if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 8) {
1951
 
            *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX9BE_c :  yuv2yuvX9LE_c;
 
2125
            *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c  : yuv2planeX_9LE_c;
 
2126
            *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c  : yuv2plane1_9LE_c;
1952
2127
        } else {
1953
 
            *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX10BE_c : yuv2yuvX10LE_c;
 
2128
            *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c  : yuv2planeX_10LE_c;
 
2129
            *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c  : yuv2plane1_10LE_c;
1954
2130
        }
1955
2131
    } else {
1956
 
        *yuv2yuv1     = yuv2yuv1_c;
1957
 
        *yuv2yuvX     = yuv2yuvX_c;
 
2132
        *yuv2plane1 = yuv2plane1_8_c;
 
2133
        *yuv2planeX = yuv2planeX_8_c;
 
2134
        if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)
 
2135
            *yuv2nv12cX = yuv2nv12cX_c;
1958
2136
    }
 
2137
 
1959
2138
    if(c->flags & SWS_FULL_CHR_H_INT) {
1960
 
        *yuv2packedX = yuv2rgbX_c_full;
 
2139
        switch (dstFormat) {
 
2140
            case PIX_FMT_RGBA:
 
2141
#if CONFIG_SMALL
 
2142
                *yuv2packedX = yuv2rgba32_full_X_c;
 
2143
#else
 
2144
#if CONFIG_SWSCALE_ALPHA
 
2145
                if (c->alpPixBuf) {
 
2146
                    *yuv2packedX = yuv2rgba32_full_X_c;
 
2147
                } else
 
2148
#endif /* CONFIG_SWSCALE_ALPHA */
 
2149
                {
 
2150
                    *yuv2packedX = yuv2rgbx32_full_X_c;
 
2151
                }
 
2152
#endif /* !CONFIG_SMALL */
 
2153
                break;
 
2154
            case PIX_FMT_ARGB:
 
2155
#if CONFIG_SMALL
 
2156
                *yuv2packedX = yuv2argb32_full_X_c;
 
2157
#else
 
2158
#if CONFIG_SWSCALE_ALPHA
 
2159
                if (c->alpPixBuf) {
 
2160
                    *yuv2packedX = yuv2argb32_full_X_c;
 
2161
                } else
 
2162
#endif /* CONFIG_SWSCALE_ALPHA */
 
2163
                {
 
2164
                    *yuv2packedX = yuv2xrgb32_full_X_c;
 
2165
                }
 
2166
#endif /* !CONFIG_SMALL */
 
2167
                break;
 
2168
            case PIX_FMT_BGRA:
 
2169
#if CONFIG_SMALL
 
2170
                *yuv2packedX = yuv2bgra32_full_X_c;
 
2171
#else
 
2172
#if CONFIG_SWSCALE_ALPHA
 
2173
                if (c->alpPixBuf) {
 
2174
                    *yuv2packedX = yuv2bgra32_full_X_c;
 
2175
                } else
 
2176
#endif /* CONFIG_SWSCALE_ALPHA */
 
2177
                {
 
2178
                    *yuv2packedX = yuv2bgrx32_full_X_c;
 
2179
                }
 
2180
#endif /* !CONFIG_SMALL */
 
2181
                break;
 
2182
            case PIX_FMT_ABGR:
 
2183
#if CONFIG_SMALL
 
2184
                *yuv2packedX = yuv2abgr32_full_X_c;
 
2185
#else
 
2186
#if CONFIG_SWSCALE_ALPHA
 
2187
                if (c->alpPixBuf) {
 
2188
                    *yuv2packedX = yuv2abgr32_full_X_c;
 
2189
                } else
 
2190
#endif /* CONFIG_SWSCALE_ALPHA */
 
2191
                {
 
2192
                    *yuv2packedX = yuv2xbgr32_full_X_c;
 
2193
                }
 
2194
#endif /* !CONFIG_SMALL */
 
2195
                break;
 
2196
            case PIX_FMT_RGB24:
 
2197
            *yuv2packedX = yuv2rgb24_full_X_c;
 
2198
            break;
 
2199
        case PIX_FMT_BGR24:
 
2200
            *yuv2packedX = yuv2bgr24_full_X_c;
 
2201
            break;
 
2202
        }
1961
2203
    } else {
1962
2204
        switch (dstFormat) {
1963
 
        case PIX_FMT_GRAY16BE:
1964
 
            *yuv2packed1 = yuv2gray16BE_1_c;
1965
 
            *yuv2packed2 = yuv2gray16BE_2_c;
1966
 
            *yuv2packedX = yuv2gray16BE_X_c;
1967
 
            break;
1968
 
        case PIX_FMT_GRAY16LE:
1969
 
            *yuv2packed1 = yuv2gray16LE_1_c;
1970
 
            *yuv2packed2 = yuv2gray16LE_2_c;
1971
 
            *yuv2packedX = yuv2gray16LE_X_c;
1972
 
            break;
1973
 
        case PIX_FMT_MONOWHITE:
1974
 
            *yuv2packed1 = yuv2monowhite_1_c;
1975
 
            *yuv2packed2 = yuv2monowhite_2_c;
1976
 
            *yuv2packedX = yuv2monowhite_X_c;
1977
 
            break;
1978
 
        case PIX_FMT_MONOBLACK:
1979
 
            *yuv2packed1 = yuv2monoblack_1_c;
1980
 
            *yuv2packed2 = yuv2monoblack_2_c;
1981
 
            *yuv2packedX = yuv2monoblack_X_c;
1982
 
            break;
1983
 
        case PIX_FMT_YUYV422:
1984
 
            *yuv2packed1 = yuv2yuyv422_1_c;
1985
 
            *yuv2packed2 = yuv2yuyv422_2_c;
1986
 
            *yuv2packedX = yuv2yuyv422_X_c;
1987
 
            break;
1988
 
        case PIX_FMT_UYVY422:
1989
 
            *yuv2packed1 = yuv2uyvy422_1_c;
1990
 
            *yuv2packed2 = yuv2uyvy422_2_c;
1991
 
            *yuv2packedX = yuv2uyvy422_X_c;
1992
 
            break;
1993
2205
        case PIX_FMT_RGB48LE:
1994
 
            //*yuv2packed1 = yuv2rgb48le_1_c;
1995
 
            //*yuv2packed2 = yuv2rgb48le_2_c;
1996
 
            //*yuv2packedX = yuv2rgb48le_X_c;
1997
 
            //break;
 
2206
            *yuv2packed1 = yuv2rgb48le_1_c;
 
2207
            *yuv2packed2 = yuv2rgb48le_2_c;
 
2208
            *yuv2packedX = yuv2rgb48le_X_c;
 
2209
            break;
1998
2210
        case PIX_FMT_RGB48BE:
1999
2211
            *yuv2packed1 = yuv2rgb48be_1_c;
2000
2212
            *yuv2packed2 = yuv2rgb48be_2_c;
2001
2213
            *yuv2packedX = yuv2rgb48be_X_c;
2002
2214
            break;
2003
2215
        case PIX_FMT_BGR48LE:
2004
 
            //*yuv2packed1 = yuv2bgr48le_1_c;
2005
 
            //*yuv2packed2 = yuv2bgr48le_2_c;
2006
 
            //*yuv2packedX = yuv2bgr48le_X_c;
2007
 
            //break;
 
2216
            *yuv2packed1 = yuv2bgr48le_1_c;
 
2217
            *yuv2packed2 = yuv2bgr48le_2_c;
 
2218
            *yuv2packedX = yuv2bgr48le_X_c;
 
2219
            break;
2008
2220
        case PIX_FMT_BGR48BE:
2009
2221
            *yuv2packed1 = yuv2bgr48be_1_c;
2010
2222
            *yuv2packed2 = yuv2bgr48be_2_c;
2011
2223
            *yuv2packedX = yuv2bgr48be_X_c;
2012
2224
            break;
2013
 
        default:
2014
 
            *yuv2packed1 = yuv2packed1_c;
2015
 
            *yuv2packed2 = yuv2packed2_c;
2016
 
            *yuv2packedX = yuv2packedX_c;
 
2225
        case PIX_FMT_RGB32:
 
2226
        case PIX_FMT_BGR32:
 
2227
#if CONFIG_SMALL
 
2228
            *yuv2packed1 = yuv2rgb32_1_c;
 
2229
            *yuv2packed2 = yuv2rgb32_2_c;
 
2230
            *yuv2packedX = yuv2rgb32_X_c;
 
2231
#else
 
2232
#if CONFIG_SWSCALE_ALPHA
 
2233
                if (c->alpPixBuf) {
 
2234
                    *yuv2packed1 = yuv2rgba32_1_c;
 
2235
                    *yuv2packed2 = yuv2rgba32_2_c;
 
2236
                    *yuv2packedX = yuv2rgba32_X_c;
 
2237
                } else
 
2238
#endif /* CONFIG_SWSCALE_ALPHA */
 
2239
                {
 
2240
                    *yuv2packed1 = yuv2rgbx32_1_c;
 
2241
                    *yuv2packed2 = yuv2rgbx32_2_c;
 
2242
                    *yuv2packedX = yuv2rgbx32_X_c;
 
2243
                }
 
2244
#endif /* !CONFIG_SMALL */
 
2245
            break;
 
2246
        case PIX_FMT_RGB32_1:
 
2247
        case PIX_FMT_BGR32_1:
 
2248
#if CONFIG_SMALL
 
2249
                *yuv2packed1 = yuv2rgb32_1_1_c;
 
2250
                *yuv2packed2 = yuv2rgb32_1_2_c;
 
2251
                *yuv2packedX = yuv2rgb32_1_X_c;
 
2252
#else
 
2253
#if CONFIG_SWSCALE_ALPHA
 
2254
                if (c->alpPixBuf) {
 
2255
                    *yuv2packed1 = yuv2rgba32_1_1_c;
 
2256
                    *yuv2packed2 = yuv2rgba32_1_2_c;
 
2257
                    *yuv2packedX = yuv2rgba32_1_X_c;
 
2258
                } else
 
2259
#endif /* CONFIG_SWSCALE_ALPHA */
 
2260
                {
 
2261
                    *yuv2packed1 = yuv2rgbx32_1_1_c;
 
2262
                    *yuv2packed2 = yuv2rgbx32_1_2_c;
 
2263
                    *yuv2packedX = yuv2rgbx32_1_X_c;
 
2264
                }
 
2265
#endif /* !CONFIG_SMALL */
 
2266
                break;
 
2267
        case PIX_FMT_RGB24:
 
2268
            *yuv2packed1 = yuv2rgb24_1_c;
 
2269
            *yuv2packed2 = yuv2rgb24_2_c;
 
2270
            *yuv2packedX = yuv2rgb24_X_c;
 
2271
            break;
 
2272
        case PIX_FMT_BGR24:
 
2273
            *yuv2packed1 = yuv2bgr24_1_c;
 
2274
            *yuv2packed2 = yuv2bgr24_2_c;
 
2275
            *yuv2packedX = yuv2bgr24_X_c;
 
2276
            break;
 
2277
        case PIX_FMT_RGB565LE:
 
2278
        case PIX_FMT_RGB565BE:
 
2279
        case PIX_FMT_BGR565LE:
 
2280
        case PIX_FMT_BGR565BE:
 
2281
            *yuv2packed1 = yuv2rgb16_1_c;
 
2282
            *yuv2packed2 = yuv2rgb16_2_c;
 
2283
            *yuv2packedX = yuv2rgb16_X_c;
 
2284
            break;
 
2285
        case PIX_FMT_RGB555LE:
 
2286
        case PIX_FMT_RGB555BE:
 
2287
        case PIX_FMT_BGR555LE:
 
2288
        case PIX_FMT_BGR555BE:
 
2289
            *yuv2packed1 = yuv2rgb15_1_c;
 
2290
            *yuv2packed2 = yuv2rgb15_2_c;
 
2291
            *yuv2packedX = yuv2rgb15_X_c;
 
2292
            break;
 
2293
        case PIX_FMT_RGB444LE:
 
2294
        case PIX_FMT_RGB444BE:
 
2295
        case PIX_FMT_BGR444LE:
 
2296
        case PIX_FMT_BGR444BE:
 
2297
            *yuv2packed1 = yuv2rgb12_1_c;
 
2298
            *yuv2packed2 = yuv2rgb12_2_c;
 
2299
            *yuv2packedX = yuv2rgb12_X_c;
 
2300
            break;
 
2301
        case PIX_FMT_RGB8:
 
2302
        case PIX_FMT_BGR8:
 
2303
            *yuv2packed1 = yuv2rgb8_1_c;
 
2304
            *yuv2packed2 = yuv2rgb8_2_c;
 
2305
            *yuv2packedX = yuv2rgb8_X_c;
 
2306
            break;
 
2307
        case PIX_FMT_RGB4:
 
2308
        case PIX_FMT_BGR4:
 
2309
            *yuv2packed1 = yuv2rgb4_1_c;
 
2310
            *yuv2packed2 = yuv2rgb4_2_c;
 
2311
            *yuv2packedX = yuv2rgb4_X_c;
 
2312
            break;
 
2313
        case PIX_FMT_RGB4_BYTE:
 
2314
        case PIX_FMT_BGR4_BYTE:
 
2315
            *yuv2packed1 = yuv2rgb4b_1_c;
 
2316
            *yuv2packed2 = yuv2rgb4b_2_c;
 
2317
            *yuv2packedX = yuv2rgb4b_X_c;
2017
2318
            break;
2018
2319
        }
2019
2320
    }
 
2321
    switch (dstFormat) {
 
2322
    case PIX_FMT_GRAY16BE:
 
2323
        *yuv2packed1 = yuv2gray16BE_1_c;
 
2324
        *yuv2packed2 = yuv2gray16BE_2_c;
 
2325
        *yuv2packedX = yuv2gray16BE_X_c;
 
2326
        break;
 
2327
    case PIX_FMT_GRAY16LE:
 
2328
        *yuv2packed1 = yuv2gray16LE_1_c;
 
2329
        *yuv2packed2 = yuv2gray16LE_2_c;
 
2330
        *yuv2packedX = yuv2gray16LE_X_c;
 
2331
        break;
 
2332
    case PIX_FMT_MONOWHITE:
 
2333
        *yuv2packed1 = yuv2monowhite_1_c;
 
2334
        *yuv2packed2 = yuv2monowhite_2_c;
 
2335
        *yuv2packedX = yuv2monowhite_X_c;
 
2336
        break;
 
2337
    case PIX_FMT_MONOBLACK:
 
2338
        *yuv2packed1 = yuv2monoblack_1_c;
 
2339
        *yuv2packed2 = yuv2monoblack_2_c;
 
2340
        *yuv2packedX = yuv2monoblack_X_c;
 
2341
        break;
 
2342
    case PIX_FMT_YUYV422:
 
2343
        *yuv2packed1 = yuv2yuyv422_1_c;
 
2344
        *yuv2packed2 = yuv2yuyv422_2_c;
 
2345
        *yuv2packedX = yuv2yuyv422_X_c;
 
2346
        break;
 
2347
    case PIX_FMT_UYVY422:
 
2348
        *yuv2packed1 = yuv2uyvy422_1_c;
 
2349
        *yuv2packed2 = yuv2uyvy422_2_c;
 
2350
        *yuv2packedX = yuv2uyvy422_X_c;
 
2351
        break;
 
2352
    }
2020
2353
}
2021
2354
 
2022
2355
#define DEBUG_SWSCALE_BUFFERS 0
2062
2395
    const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);
2063
2396
    int lastDstY;
2064
2397
    uint32_t *pal=c->pal_yuv;
2065
 
    yuv2planar1_fn yuv2yuv1 = c->yuv2yuv1;
2066
 
    yuv2planarX_fn yuv2yuvX = c->yuv2yuvX;
 
2398
    yuv2planar1_fn yuv2plane1 = c->yuv2plane1;
 
2399
    yuv2planarX_fn yuv2planeX = c->yuv2planeX;
 
2400
    yuv2interleavedX_fn yuv2nv12cX = c->yuv2nv12cX;
2067
2401
    yuv2packed1_fn yuv2packed1 = c->yuv2packed1;
2068
2402
    yuv2packed2_fn yuv2packed2 = c->yuv2packed2;
2069
2403
    yuv2packedX_fn yuv2packedX = c->yuv2packedX;
 
2404
    int should_dither = is9_OR_10BPS(c->srcFormat) || is16BPS(c->srcFormat);
2070
2405
 
2071
2406
    /* vars which will change and which we need to store back in the context */
2072
2407
    int dstY= c->dstY;
2116
2451
        lastInChrBuf= -1;
2117
2452
    }
2118
2453
 
 
2454
    if (!should_dither) {
 
2455
        c->chrDither8 = c->lumDither8 = ff_sws_pb_64;
 
2456
    }
2119
2457
    lastDstY= dstY;
2120
2458
 
2121
2459
    for (;dstY < dstH; dstY++) {
2122
 
        unsigned char *dest =dst[0]+dstStride[0]*dstY;
2123
2460
        const int chrDstY= dstY>>c->chrDstVSubSample;
2124
 
        unsigned char *uDest=dst[1]+dstStride[1]*chrDstY;
2125
 
        unsigned char *vDest=dst[2]+dstStride[2]*chrDstY;
2126
 
        unsigned char *aDest=(CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3]+dstStride[3]*dstY : NULL;
 
2461
        uint8_t *dest[4] = {
 
2462
            dst[0] + dstStride[0] * dstY,
 
2463
            dst[1] + dstStride[1] * chrDstY,
 
2464
            dst[2] + dstStride[2] * chrDstY,
 
2465
            (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,
 
2466
        };
2127
2467
 
2128
2468
        const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
2129
2469
        const int firstLumSrcY2= vLumFilterPos[FFMIN(dstY | ((1<<c->chrDstVSubSample) - 1), dstH-1)];
2130
2470
        const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
2131
 
        int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input
2132
 
        int lastLumSrcY2=firstLumSrcY2+ vLumFilterSize -1; // Last line needed as input
2133
 
        int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input
 
2471
 
 
2472
        // Last line needed as input
 
2473
        int lastLumSrcY  = FFMIN(c->srcH,    firstLumSrcY  + vLumFilterSize) - 1;
 
2474
        int lastLumSrcY2 = FFMIN(c->srcH,    firstLumSrcY2 + vLumFilterSize) - 1;
 
2475
        int lastChrSrcY  = FFMIN(c->chrSrcH, firstChrSrcY  + vChrFilterSize) - 1;
2134
2476
        int enough_lines;
2135
2477
 
2136
2478
        //handle holes (FAST_BILINEAR & weird filters)
2157
2499
 
2158
2500
        //Do horizontal scaling
2159
2501
        while(lastInLumBuf < lastLumSrcY) {
2160
 
            const uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0];
2161
 
            const uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3];
 
2502
            const uint8_t *src1[4] = {
 
2503
                src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],
 
2504
                src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],
 
2505
                src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],
 
2506
                src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],
 
2507
            };
2162
2508
            lumBufIndex++;
2163
2509
            assert(lumBufIndex < 2*vLumBufSize);
2164
2510
            assert(lastInLumBuf + 1 - srcSliceY < srcSliceH);
2168
2514
                    formatConvBuffer,
2169
2515
                    pal, 0);
2170
2516
            if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
2171
 
                hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src2, srcW,
 
2517
                hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src1, srcW,
2172
2518
                        lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
2173
2519
                        formatConvBuffer,
2174
2520
                        pal, 1);
2177
2523
                               lumBufIndex,    lastInLumBuf);
2178
2524
        }
2179
2525
        while(lastInChrBuf < lastChrSrcY) {
2180
 
            const uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1];
2181
 
            const uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2];
 
2526
            const uint8_t *src1[4] = {
 
2527
                src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],
 
2528
                src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],
 
2529
                src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],
 
2530
                src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],
 
2531
            };
2182
2532
            chrBufIndex++;
2183
2533
            assert(chrBufIndex < 2*vChrBufSize);
2184
2534
            assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
2187
2537
 
2188
2538
            if (c->needs_hcscale)
2189
2539
                hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
2190
 
                          chrDstW, src1, src2, chrSrcW, chrXInc,
 
2540
                          chrDstW, src1, chrSrcW, chrXInc,
2191
2541
                          hChrFilter, hChrFilterPos, hChrFilterSize,
2192
2542
                          formatConvBuffer, pal);
2193
2543
            lastInChrBuf++;
2203
2553
#if HAVE_MMX
2204
2554
        updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf);
2205
2555
#endif
 
2556
        if (should_dither) {
 
2557
            c->chrDither8 = dither_8x8_128[chrDstY & 7];
 
2558
            c->lumDither8 = dither_8x8_128[dstY & 7];
 
2559
        }
2206
2560
        if (dstY >= dstH-2) {
2207
2561
            // hmm looks like we can't use MMX here without overwriting this array's tail
2208
 
            find_c_packed_planar_out_funcs(c, &yuv2yuv1, &yuv2yuvX,
2209
 
                                           &yuv2packed1, &yuv2packed2,
2210
 
                                           &yuv2packedX);
 
2562
            find_c_packed_planar_out_funcs(c, &yuv2plane1, &yuv2planeX,  &yuv2nv12cX,
 
2563
                                           &yuv2packed1, &yuv2packed2, &yuv2packedX);
2211
2564
        }
2212
2565
 
2213
2566
        {
2215
2568
            const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
2216
2569
            const int16_t **chrVSrcPtr= (const int16_t **) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
2217
2570
            const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
 
2571
 
 
2572
            if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {
 
2573
                const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize;
 
2574
                int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);
 
2575
                for (i = 0; i < neg;            i++)
 
2576
                    tmpY[i] = lumSrcPtr[neg];
 
2577
                for (     ; i < end;            i++)
 
2578
                    tmpY[i] = lumSrcPtr[i];
 
2579
                for (     ; i < vLumFilterSize; i++)
 
2580
                    tmpY[i] = tmpY[i-1];
 
2581
                lumSrcPtr = tmpY;
 
2582
 
 
2583
                if (alpSrcPtr) {
 
2584
                    const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize;
 
2585
                    for (i = 0; i < neg;            i++)
 
2586
                        tmpA[i] = alpSrcPtr[neg];
 
2587
                    for (     ; i < end;            i++)
 
2588
                        tmpA[i] = alpSrcPtr[i];
 
2589
                    for (     ; i < vLumFilterSize; i++)
 
2590
                        tmpA[i] = tmpA[i - 1];
 
2591
                    alpSrcPtr = tmpA;
 
2592
                }
 
2593
            }
 
2594
            if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {
 
2595
                const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize,
 
2596
                              **tmpV = (const int16_t **) chrVPixBuf + 2 * vChrBufSize;
 
2597
                int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);
 
2598
                for (i = 0; i < neg;            i++) {
 
2599
                    tmpU[i] = chrUSrcPtr[neg];
 
2600
                    tmpV[i] = chrVSrcPtr[neg];
 
2601
                }
 
2602
                for (     ; i < end;            i++) {
 
2603
                    tmpU[i] = chrUSrcPtr[i];
 
2604
                    tmpV[i] = chrVSrcPtr[i];
 
2605
                }
 
2606
                for (     ; i < vChrFilterSize; i++) {
 
2607
                    tmpU[i] = tmpU[i - 1];
 
2608
                    tmpV[i] = tmpV[i - 1];
 
2609
                }
 
2610
                chrUSrcPtr = tmpU;
 
2611
                chrVSrcPtr = tmpV;
 
2612
            }
 
2613
 
2218
2614
            if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 like
2219
2615
                const int chrSkipMask= (1<<c->chrDstVSubSample)-1;
2220
 
                if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi
2221
 
                if (c->yuv2yuv1 && vLumFilterSize == 1 && vChrFilterSize == 1) { // unscaled YV12
2222
 
                    const int16_t *lumBuf = lumSrcPtr[0];
2223
 
                    const int16_t *chrUBuf= chrUSrcPtr[0];
2224
 
                    const int16_t *chrVBuf= chrVSrcPtr[0];
2225
 
                    const int16_t *alpBuf= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? alpSrcPtr[0] : NULL;
2226
 
                    yuv2yuv1(c, lumBuf, chrUBuf, chrVBuf, alpBuf, dest,
2227
 
                                uDest, vDest, aDest, dstW, chrDstW);
2228
 
                } else { //General YV12
2229
 
                    yuv2yuvX(c,
2230
 
                                vLumFilter+dstY*vLumFilterSize   , lumSrcPtr, vLumFilterSize,
2231
 
                                vChrFilter+chrDstY*vChrFilterSize, chrUSrcPtr,
2232
 
                                chrVSrcPtr, vChrFilterSize,
2233
 
                                alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW);
 
2616
 
 
2617
                if (vLumFilterSize == 1) {
 
2618
                    yuv2plane1(lumSrcPtr[0], dest[0], dstW, c->lumDither8, 0);
 
2619
                } else {
 
2620
                    yuv2planeX(vLumFilter + dstY * vLumFilterSize, vLumFilterSize,
 
2621
                               lumSrcPtr, dest[0], dstW, c->lumDither8, 0);
 
2622
                }
 
2623
 
 
2624
                if (!((dstY&chrSkipMask) || isGray(dstFormat))) {
 
2625
                    if (yuv2nv12cX) {
 
2626
                        yuv2nv12cX(c, vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize, chrUSrcPtr, chrVSrcPtr, dest[1], chrDstW);
 
2627
                    } else if (vChrFilterSize == 1) {
 
2628
                        yuv2plane1(chrUSrcPtr[0], dest[1], chrDstW, c->chrDither8, 0);
 
2629
                        yuv2plane1(chrVSrcPtr[0], dest[2], chrDstW, c->chrDither8, 3);
 
2630
                    } else {
 
2631
                        yuv2planeX(vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize,
 
2632
                                   chrUSrcPtr, dest[1], chrDstW, c->chrDither8, 0);
 
2633
                        yuv2planeX(vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize,
 
2634
                                   chrVSrcPtr, dest[2], chrDstW, c->chrDither8, 3);
 
2635
                    }
 
2636
                }
 
2637
 
 
2638
                if (CONFIG_SWSCALE_ALPHA && alpPixBuf){
 
2639
                    if (vLumFilterSize == 1) {
 
2640
                        yuv2plane1(alpSrcPtr[0], dest[3], dstW, c->lumDither8, 0);
 
2641
                    } else {
 
2642
                        yuv2planeX(vLumFilter + dstY * vLumFilterSize, vLumFilterSize,
 
2643
                                   alpSrcPtr, dest[3], dstW, c->lumDither8, 0);
 
2644
                    }
2234
2645
                }
2235
2646
            } else {
2236
2647
                assert(lumSrcPtr  + vLumFilterSize - 1 < lumPixBuf  + vLumBufSize*2);
2237
2648
                assert(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize*2);
2238
2649
                if (c->yuv2packed1 && vLumFilterSize == 1 && vChrFilterSize == 2) { //unscaled RGB
2239
 
                    int chrAlpha= vChrFilter[2*dstY+1];
2240
 
                    yuv2packed1(c, *lumSrcPtr, *chrUSrcPtr, *(chrUSrcPtr+1),
2241
 
                                   *chrVSrcPtr, *(chrVSrcPtr+1),
2242
 
                                   alpPixBuf ? *alpSrcPtr : NULL,
2243
 
                                   dest, dstW, chrAlpha, dstFormat, flags, dstY);
 
2650
                    int chrAlpha = vChrFilter[2 * dstY + 1];
 
2651
                    yuv2packed1(c, *lumSrcPtr, chrUSrcPtr, chrVSrcPtr,
 
2652
                                alpPixBuf ? *alpSrcPtr : NULL,
 
2653
                                dest[0], dstW, chrAlpha, dstY);
2244
2654
                } else if (c->yuv2packed2 && vLumFilterSize == 2 && vChrFilterSize == 2) { //bilinear upscale RGB
2245
 
                    int lumAlpha= vLumFilter[2*dstY+1];
2246
 
                    int chrAlpha= vChrFilter[2*dstY+1];
2247
 
                    lumMmxFilter[2]=
2248
 
                    lumMmxFilter[3]= vLumFilter[2*dstY   ]*0x10001;
2249
 
                    chrMmxFilter[2]=
2250
 
                    chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001;
2251
 
                    yuv2packed2(c, *lumSrcPtr, *(lumSrcPtr+1), *chrUSrcPtr, *(chrUSrcPtr+1),
2252
 
                                   *chrVSrcPtr, *(chrVSrcPtr+1),
2253
 
                                   alpPixBuf ? *alpSrcPtr : NULL, alpPixBuf ? *(alpSrcPtr+1) : NULL,
2254
 
                                   dest, dstW, lumAlpha, chrAlpha, dstY);
 
2655
                    int lumAlpha = vLumFilter[2 * dstY + 1];
 
2656
                    int chrAlpha = vChrFilter[2 * dstY + 1];
 
2657
                    lumMmxFilter[2] =
 
2658
                    lumMmxFilter[3] = vLumFilter[2 * dstY   ] * 0x10001;
 
2659
                    chrMmxFilter[2] =
 
2660
                    chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;
 
2661
                    yuv2packed2(c, lumSrcPtr, chrUSrcPtr, chrVSrcPtr,
 
2662
                                alpPixBuf ? alpSrcPtr : NULL,
 
2663
                                dest[0], dstW, lumAlpha, chrAlpha, dstY);
2255
2664
                } else { //general RGB
2256
 
                    yuv2packedX(c,
2257
 
                                   vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize,
2258
 
                                   vChrFilter+dstY*vChrFilterSize, chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
2259
 
                                   alpSrcPtr, dest, dstW, dstY);
 
2665
                    yuv2packedX(c, vLumFilter + dstY * vLumFilterSize,
 
2666
                                lumSrcPtr, vLumFilterSize,
 
2667
                                vChrFilter + dstY * vChrFilterSize,
 
2668
                                chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
 
2669
                                alpSrcPtr, dest[0], dstW, dstY);
2260
2670
                }
2261
2671
            }
2262
2672
        }
2285
2695
{
2286
2696
    enum PixelFormat srcFormat = c->srcFormat;
2287
2697
 
2288
 
    find_c_packed_planar_out_funcs(c, &c->yuv2yuv1, &c->yuv2yuvX,
2289
 
                                   &c->yuv2packed1, &c->yuv2packed2,
 
2698
    find_c_packed_planar_out_funcs(c, &c->yuv2plane1, &c->yuv2planeX,
 
2699
                                   &c->yuv2nv12cX, &c->yuv2packed1, &c->yuv2packed2,
2290
2700
                                   &c->yuv2packedX);
2291
2701
 
2292
 
    c->hScale       = hScale_c;
2293
 
 
2294
 
    if (c->flags & SWS_FAST_BILINEAR) {
2295
 
        c->hyscale_fast = hyscale_fast_c;
2296
 
        c->hcscale_fast = hcscale_fast_c;
2297
 
    }
2298
 
 
2299
2702
    c->chrToYV12 = NULL;
2300
2703
    switch(srcFormat) {
2301
2704
        case PIX_FMT_YUYV422  : c->chrToYV12 = yuy2ToUV_c; break;
2307
2710
        case PIX_FMT_PAL8     :
2308
2711
        case PIX_FMT_BGR4_BYTE:
2309
2712
        case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV_c; break;
 
2713
        case PIX_FMT_GBRP9LE:
 
2714
        case PIX_FMT_GBRP10LE:
 
2715
        case PIX_FMT_GBRP16LE:  c->readChrPlanar = planar_rgb16le_to_uv; break;
 
2716
        case PIX_FMT_GBRP9BE:
 
2717
        case PIX_FMT_GBRP10BE:
 
2718
        case PIX_FMT_GBRP16BE:  c->readChrPlanar = planar_rgb16be_to_uv; break;
 
2719
        case PIX_FMT_GBRP:      c->readChrPlanar = planar_rgb_to_uv; break;
 
2720
#if HAVE_BIGENDIAN
 
2721
        case PIX_FMT_YUV444P9LE:
 
2722
        case PIX_FMT_YUV422P9LE:
 
2723
        case PIX_FMT_YUV420P9LE:
 
2724
        case PIX_FMT_YUV422P10LE:
 
2725
        case PIX_FMT_YUV444P10LE:
 
2726
        case PIX_FMT_YUV420P10LE:
 
2727
        case PIX_FMT_YUV420P16LE:
 
2728
        case PIX_FMT_YUV422P16LE:
 
2729
        case PIX_FMT_YUV444P16LE: c->chrToYV12 = bswap16UV_c; break;
 
2730
#else
2310
2731
        case PIX_FMT_YUV444P9BE:
2311
 
        case PIX_FMT_YUV420P9BE: c->chrToYV12 = BE9ToUV_c; break;
2312
 
        case PIX_FMT_YUV444P9LE:
2313
 
        case PIX_FMT_YUV420P9LE: c->chrToYV12 = LE9ToUV_c; break;
 
2732
        case PIX_FMT_YUV422P9BE:
 
2733
        case PIX_FMT_YUV420P9BE:
2314
2734
        case PIX_FMT_YUV444P10BE:
2315
2735
        case PIX_FMT_YUV422P10BE:
2316
 
        case PIX_FMT_YUV420P10BE: c->chrToYV12 = BE10ToUV_c; break;
2317
 
        case PIX_FMT_YUV422P10LE:
2318
 
        case PIX_FMT_YUV444P10LE:
2319
 
        case PIX_FMT_YUV420P10LE: c->chrToYV12 = LE10ToUV_c; break;
 
2736
        case PIX_FMT_YUV420P10BE:
2320
2737
        case PIX_FMT_YUV420P16BE:
2321
2738
        case PIX_FMT_YUV422P16BE:
2322
 
        case PIX_FMT_YUV444P16BE: c->chrToYV12 = BEToUV_c; break;
2323
 
        case PIX_FMT_YUV420P16LE:
2324
 
        case PIX_FMT_YUV422P16LE:
2325
 
        case PIX_FMT_YUV444P16LE: c->chrToYV12 = LEToUV_c; break;
 
2739
        case PIX_FMT_YUV444P16BE: c->chrToYV12 = bswap16UV_c; break;
 
2740
#endif
2326
2741
    }
2327
2742
    if (c->chrSrcHSubSample) {
2328
2743
        switch(srcFormat) {
2337
2752
        case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_half_c; break;
2338
2753
        case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_half_c; break;
2339
2754
        case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_half_c; break;
 
2755
        case PIX_FMT_BGR444LE: c->chrToYV12 = bgr12leToUV_half_c; break;
 
2756
        case PIX_FMT_BGR444BE: c->chrToYV12 = bgr12beToUV_half_c; break;
2340
2757
        case PIX_FMT_BGR32   : c->chrToYV12 = rgb32ToUV_half_c;   break;
2341
2758
        case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_half_c;  break;
2342
2759
        case PIX_FMT_RGB24   : c->chrToYV12 = rgb24ToUV_half_c;   break;
2344
2761
        case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_half_c; break;
2345
2762
        case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_half_c; break;
2346
2763
        case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_half_c; break;
 
2764
        case PIX_FMT_RGB444LE: c->chrToYV12 = rgb12leToUV_half_c; break;
 
2765
        case PIX_FMT_RGB444BE: c->chrToYV12 = rgb12beToUV_half_c; break;
2347
2766
        }
2348
2767
    } else {
2349
2768
        switch(srcFormat) {
2358
2777
        case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_c; break;
2359
2778
        case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_c; break;
2360
2779
        case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_c; break;
 
2780
        case PIX_FMT_BGR444LE: c->chrToYV12 = bgr12leToUV_c; break;
 
2781
        case PIX_FMT_BGR444BE: c->chrToYV12 = bgr12beToUV_c; break;
2361
2782
        case PIX_FMT_BGR32   : c->chrToYV12 = rgb32ToUV_c;   break;
2362
2783
        case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_c;  break;
2363
2784
        case PIX_FMT_RGB24   : c->chrToYV12 = rgb24ToUV_c;   break;
2365
2786
        case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_c; break;
2366
2787
        case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_c; break;
2367
2788
        case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_c; break;
 
2789
        case PIX_FMT_RGB444LE: c->chrToYV12 = rgb12leToUV_c; break;
 
2790
        case PIX_FMT_RGB444BE: c->chrToYV12 = rgb12beToUV_c; break;
2368
2791
        }
2369
2792
    }
2370
2793
 
2371
2794
    c->lumToYV12 = NULL;
2372
2795
    c->alpToYV12 = NULL;
2373
2796
    switch (srcFormat) {
 
2797
    case PIX_FMT_GBRP9LE:
 
2798
    case PIX_FMT_GBRP10LE:
 
2799
    case PIX_FMT_GBRP16LE: c->readLumPlanar = planar_rgb16le_to_y; break;
 
2800
    case PIX_FMT_GBRP9BE:
 
2801
    case PIX_FMT_GBRP10BE:
 
2802
    case PIX_FMT_GBRP16BE: c->readLumPlanar = planar_rgb16be_to_y; break;
 
2803
    case PIX_FMT_GBRP:     c->readLumPlanar = planar_rgb_to_y; break;
 
2804
#if HAVE_BIGENDIAN
 
2805
    case PIX_FMT_YUV444P9LE:
 
2806
    case PIX_FMT_YUV422P9LE:
 
2807
    case PIX_FMT_YUV420P9LE:
 
2808
    case PIX_FMT_YUV444P10LE:
 
2809
    case PIX_FMT_YUV422P10LE:
 
2810
    case PIX_FMT_YUV420P10LE:
 
2811
    case PIX_FMT_YUV420P16LE:
 
2812
    case PIX_FMT_YUV422P16LE:
 
2813
    case PIX_FMT_YUV444P16LE:
 
2814
    case PIX_FMT_GRAY16LE: c->lumToYV12 = bswap16Y_c; break;
 
2815
#else
2374
2816
    case PIX_FMT_YUV444P9BE:
2375
 
    case PIX_FMT_YUV420P9BE: c->lumToYV12 = BE9ToY_c; break;
2376
 
    case PIX_FMT_YUV444P9LE:
2377
 
    case PIX_FMT_YUV420P9LE: c->lumToYV12 = LE9ToY_c; break;
 
2817
    case PIX_FMT_YUV422P9BE:
 
2818
    case PIX_FMT_YUV420P9BE:
2378
2819
    case PIX_FMT_YUV444P10BE:
2379
2820
    case PIX_FMT_YUV422P10BE:
2380
 
    case PIX_FMT_YUV420P10BE: c->lumToYV12 = BE10ToY_c; break;
2381
 
    case PIX_FMT_YUV444P10LE:
2382
 
    case PIX_FMT_YUV422P10LE:
2383
 
    case PIX_FMT_YUV420P10LE: c->lumToYV12 = LE10ToY_c; break;
2384
 
    case PIX_FMT_YUYV422  :
 
2821
    case PIX_FMT_YUV420P10BE:
2385
2822
    case PIX_FMT_YUV420P16BE:
2386
2823
    case PIX_FMT_YUV422P16BE:
2387
2824
    case PIX_FMT_YUV444P16BE:
2388
 
    case PIX_FMT_Y400A    :
2389
 
    case PIX_FMT_GRAY16BE : c->lumToYV12 = yuy2ToY_c; break;
2390
 
    case PIX_FMT_UYVY422  :
2391
 
    case PIX_FMT_YUV420P16LE:
2392
 
    case PIX_FMT_YUV422P16LE:
2393
 
    case PIX_FMT_YUV444P16LE:
2394
 
    case PIX_FMT_GRAY16LE : c->lumToYV12 = uyvyToY_c;    break;
 
2825
    case PIX_FMT_GRAY16BE: c->lumToYV12 = bswap16Y_c; break;
 
2826
#endif
 
2827
    case PIX_FMT_YUYV422  :
 
2828
    case PIX_FMT_Y400A    : c->lumToYV12 = yuy2ToY_c; break;
 
2829
    case PIX_FMT_UYVY422  : c->lumToYV12 = uyvyToY_c;    break;
2395
2830
    case PIX_FMT_BGR24    : c->lumToYV12 = bgr24ToY_c;   break;
2396
2831
    case PIX_FMT_BGR565LE : c->lumToYV12 = bgr16leToY_c; break;
2397
2832
    case PIX_FMT_BGR565BE : c->lumToYV12 = bgr16beToY_c; break;
2398
2833
    case PIX_FMT_BGR555LE : c->lumToYV12 = bgr15leToY_c; break;
2399
2834
    case PIX_FMT_BGR555BE : c->lumToYV12 = bgr15beToY_c; break;
 
2835
    case PIX_FMT_BGR444LE : c->lumToYV12 = bgr12leToY_c; break;
 
2836
    case PIX_FMT_BGR444BE : c->lumToYV12 = bgr12beToY_c; break;
2400
2837
    case PIX_FMT_RGB24    : c->lumToYV12 = rgb24ToY_c;   break;
2401
2838
    case PIX_FMT_RGB565LE : c->lumToYV12 = rgb16leToY_c; break;
2402
2839
    case PIX_FMT_RGB565BE : c->lumToYV12 = rgb16beToY_c; break;
2403
2840
    case PIX_FMT_RGB555LE : c->lumToYV12 = rgb15leToY_c; break;
2404
2841
    case PIX_FMT_RGB555BE : c->lumToYV12 = rgb15beToY_c; break;
 
2842
    case PIX_FMT_RGB444LE : c->lumToYV12 = rgb12leToY_c; break;
 
2843
    case PIX_FMT_RGB444BE : c->lumToYV12 = rgb12beToY_c; break;
2405
2844
    case PIX_FMT_RGB8     :
2406
2845
    case PIX_FMT_BGR8     :
2407
2846
    case PIX_FMT_PAL8     :
2428
2867
        }
2429
2868
    }
2430
2869
 
 
2870
    if (c->srcBpc == 8) {
 
2871
        if (c->dstBpc <= 10) {
 
2872
            c->hyScale = c->hcScale = hScale8To15_c;
 
2873
            if (c->flags & SWS_FAST_BILINEAR) {
 
2874
                c->hyscale_fast = hyscale_fast_c;
 
2875
                c->hcscale_fast = hcscale_fast_c;
 
2876
            }
 
2877
        } else {
 
2878
            c->hyScale = c->hcScale = hScale8To19_c;
 
2879
        }
 
2880
    } else {
 
2881
        c->hyScale = c->hcScale = c->dstBpc > 10 ? hScale16To19_c : hScale16To15_c;
 
2882
    }
 
2883
 
2431
2884
    if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
2432
 
        if (c->srcRange) {
2433
 
            c->lumConvertRange = lumRangeFromJpeg_c;
2434
 
            c->chrConvertRange = chrRangeFromJpeg_c;
 
2885
        if (c->dstBpc <= 10) {
 
2886
            if (c->srcRange) {
 
2887
                c->lumConvertRange = lumRangeFromJpeg_c;
 
2888
                c->chrConvertRange = chrRangeFromJpeg_c;
 
2889
            } else {
 
2890
                c->lumConvertRange = lumRangeToJpeg_c;
 
2891
                c->chrConvertRange = chrRangeToJpeg_c;
 
2892
            }
2435
2893
        } else {
2436
 
            c->lumConvertRange = lumRangeToJpeg_c;
2437
 
            c->chrConvertRange = chrRangeToJpeg_c;
 
2894
            if (c->srcRange) {
 
2895
                c->lumConvertRange = lumRangeFromJpeg16_c;
 
2896
                c->chrConvertRange = chrRangeFromJpeg16_c;
 
2897
            } else {
 
2898
                c->lumConvertRange = lumRangeToJpeg16_c;
 
2899
                c->chrConvertRange = chrRangeToJpeg16_c;
 
2900
            }
2438
2901
        }
2439
2902
    }
2440
2903