annotate ffmpeg/libswscale/output.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Copyright (C) 2001-2012 Michael Niedermayer <michaelni@gmx.at>
yading@11 3 *
yading@11 4 * This file is part of FFmpeg.
yading@11 5 *
yading@11 6 * FFmpeg is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * FFmpeg is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with FFmpeg; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 #include <assert.h>
yading@11 22 #include <math.h>
yading@11 23 #include <stdint.h>
yading@11 24 #include <stdio.h>
yading@11 25 #include <string.h>
yading@11 26
yading@11 27 #include "libavutil/attributes.h"
yading@11 28 #include "libavutil/avutil.h"
yading@11 29 #include "libavutil/avassert.h"
yading@11 30 #include "libavutil/bswap.h"
yading@11 31 #include "libavutil/cpu.h"
yading@11 32 #include "libavutil/intreadwrite.h"
yading@11 33 #include "libavutil/mathematics.h"
yading@11 34 #include "libavutil/pixdesc.h"
yading@11 35 #include "config.h"
yading@11 36 #include "rgb2rgb.h"
yading@11 37 #include "swscale.h"
yading@11 38 #include "swscale_internal.h"
yading@11 39
yading@11 40 DECLARE_ALIGNED(8, const uint8_t, dither_2x2_4)[][8]={
yading@11 41 { 1, 3, 1, 3, 1, 3, 1, 3, },
yading@11 42 { 2, 0, 2, 0, 2, 0, 2, 0, },
yading@11 43 { 1, 3, 1, 3, 1, 3, 1, 3, },
yading@11 44 };
yading@11 45
yading@11 46 DECLARE_ALIGNED(8, const uint8_t, dither_2x2_8)[][8]={
yading@11 47 { 6, 2, 6, 2, 6, 2, 6, 2, },
yading@11 48 { 0, 4, 0, 4, 0, 4, 0, 4, },
yading@11 49 { 6, 2, 6, 2, 6, 2, 6, 2, },
yading@11 50 };
yading@11 51
yading@11 52 DECLARE_ALIGNED(8, const uint8_t, dither_4x4_16)[][8]={
yading@11 53 { 8, 4, 11, 7, 8, 4, 11, 7, },
yading@11 54 { 2, 14, 1, 13, 2, 14, 1, 13, },
yading@11 55 { 10, 6, 9, 5, 10, 6, 9, 5, },
yading@11 56 { 0, 12, 3, 15, 0, 12, 3, 15, },
yading@11 57 { 8, 4, 11, 7, 8, 4, 11, 7, },
yading@11 58 };
yading@11 59
yading@11 60 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32)[][8]={
yading@11 61 { 17, 9, 23, 15, 16, 8, 22, 14, },
yading@11 62 { 5, 29, 3, 27, 4, 28, 2, 26, },
yading@11 63 { 21, 13, 19, 11, 20, 12, 18, 10, },
yading@11 64 { 0, 24, 6, 30, 1, 25, 7, 31, },
yading@11 65 { 16, 8, 22, 14, 17, 9, 23, 15, },
yading@11 66 { 4, 28, 2, 26, 5, 29, 3, 27, },
yading@11 67 { 20, 12, 18, 10, 21, 13, 19, 11, },
yading@11 68 { 1, 25, 7, 31, 0, 24, 6, 30, },
yading@11 69 { 17, 9, 23, 15, 16, 8, 22, 14, },
yading@11 70 };
yading@11 71
yading@11 72 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73)[][8]={
yading@11 73 { 0, 55, 14, 68, 3, 58, 17, 72, },
yading@11 74 { 37, 18, 50, 32, 40, 22, 54, 35, },
yading@11 75 { 9, 64, 5, 59, 13, 67, 8, 63, },
yading@11 76 { 46, 27, 41, 23, 49, 31, 44, 26, },
yading@11 77 { 2, 57, 16, 71, 1, 56, 15, 70, },
yading@11 78 { 39, 21, 52, 34, 38, 19, 51, 33, },
yading@11 79 { 11, 66, 7, 62, 10, 65, 6, 60, },
yading@11 80 { 48, 30, 43, 25, 47, 29, 42, 24, },
yading@11 81 { 0, 55, 14, 68, 3, 58, 17, 72, },
yading@11 82 };
yading@11 83
yading@11 84 #if 1
yading@11 85 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
yading@11 86 {117, 62, 158, 103, 113, 58, 155, 100, },
yading@11 87 { 34, 199, 21, 186, 31, 196, 17, 182, },
yading@11 88 {144, 89, 131, 76, 141, 86, 127, 72, },
yading@11 89 { 0, 165, 41, 206, 10, 175, 52, 217, },
yading@11 90 {110, 55, 151, 96, 120, 65, 162, 107, },
yading@11 91 { 28, 193, 14, 179, 38, 203, 24, 189, },
yading@11 92 {138, 83, 124, 69, 148, 93, 134, 79, },
yading@11 93 { 7, 172, 48, 213, 3, 168, 45, 210, },
yading@11 94 {117, 62, 158, 103, 113, 58, 155, 100, },
yading@11 95 };
yading@11 96 #elif 1
yading@11 97 // tries to correct a gamma of 1.5
yading@11 98 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
yading@11 99 { 0, 143, 18, 200, 2, 156, 25, 215, },
yading@11 100 { 78, 28, 125, 64, 89, 36, 138, 74, },
yading@11 101 { 10, 180, 3, 161, 16, 195, 8, 175, },
yading@11 102 {109, 51, 93, 38, 121, 60, 105, 47, },
yading@11 103 { 1, 152, 23, 210, 0, 147, 20, 205, },
yading@11 104 { 85, 33, 134, 71, 81, 30, 130, 67, },
yading@11 105 { 14, 190, 6, 171, 12, 185, 5, 166, },
yading@11 106 {117, 57, 101, 44, 113, 54, 97, 41, },
yading@11 107 { 0, 143, 18, 200, 2, 156, 25, 215, },
yading@11 108 };
yading@11 109 #elif 1
yading@11 110 // tries to correct a gamma of 2.0
yading@11 111 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
yading@11 112 { 0, 124, 8, 193, 0, 140, 12, 213, },
yading@11 113 { 55, 14, 104, 42, 66, 19, 119, 52, },
yading@11 114 { 3, 168, 1, 145, 6, 187, 3, 162, },
yading@11 115 { 86, 31, 70, 21, 99, 39, 82, 28, },
yading@11 116 { 0, 134, 11, 206, 0, 129, 9, 200, },
yading@11 117 { 62, 17, 114, 48, 58, 16, 109, 45, },
yading@11 118 { 5, 181, 2, 157, 4, 175, 1, 151, },
yading@11 119 { 95, 36, 78, 26, 90, 34, 74, 24, },
yading@11 120 { 0, 124, 8, 193, 0, 140, 12, 213, },
yading@11 121 };
yading@11 122 #else
yading@11 123 // tries to correct a gamma of 2.5
yading@11 124 DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[][8]={
yading@11 125 { 0, 107, 3, 187, 0, 125, 6, 212, },
yading@11 126 { 39, 7, 86, 28, 49, 11, 102, 36, },
yading@11 127 { 1, 158, 0, 131, 3, 180, 1, 151, },
yading@11 128 { 68, 19, 52, 12, 81, 25, 64, 17, },
yading@11 129 { 0, 119, 5, 203, 0, 113, 4, 195, },
yading@11 130 { 45, 9, 96, 33, 42, 8, 91, 30, },
yading@11 131 { 2, 172, 1, 144, 2, 165, 0, 137, },
yading@11 132 { 77, 23, 60, 15, 72, 21, 56, 14, },
yading@11 133 { 0, 107, 3, 187, 0, 125, 6, 212, },
yading@11 134 };
yading@11 135 #endif
yading@11 136
yading@11 137 #define output_pixel(pos, val, bias, signedness) \
yading@11 138 if (big_endian) { \
yading@11 139 AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
yading@11 140 } else { \
yading@11 141 AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
yading@11 142 }
yading@11 143
yading@11 144 static av_always_inline void
yading@11 145 yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW,
yading@11 146 int big_endian, int output_bits)
yading@11 147 {
yading@11 148 int i;
yading@11 149 int shift = 3;
yading@11 150 av_assert0(output_bits == 16);
yading@11 151
yading@11 152 for (i = 0; i < dstW; i++) {
yading@11 153 int val = src[i] + (1 << (shift - 1));
yading@11 154 output_pixel(&dest[i], val, 0, uint);
yading@11 155 }
yading@11 156 }
yading@11 157
yading@11 158 static av_always_inline void
yading@11 159 yuv2planeX_16_c_template(const int16_t *filter, int filterSize,
yading@11 160 const int32_t **src, uint16_t *dest, int dstW,
yading@11 161 int big_endian, int output_bits)
yading@11 162 {
yading@11 163 int i;
yading@11 164 int shift = 15;
yading@11 165 av_assert0(output_bits == 16);
yading@11 166
yading@11 167 for (i = 0; i < dstW; i++) {
yading@11 168 int val = 1 << (shift - 1);
yading@11 169 int j;
yading@11 170
yading@11 171 /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline
yading@11 172 * filters (or anything with negative coeffs, the range can be slightly
yading@11 173 * wider in both directions. To account for this overflow, we subtract
yading@11 174 * a constant so it always fits in the signed range (assuming a
yading@11 175 * reasonable filterSize), and re-add that at the end. */
yading@11 176 val -= 0x40000000;
yading@11 177 for (j = 0; j < filterSize; j++)
yading@11 178 val += src[j][i] * (unsigned)filter[j];
yading@11 179
yading@11 180 output_pixel(&dest[i], val, 0x8000, int);
yading@11 181 }
yading@11 182 }
yading@11 183
yading@11 184 #undef output_pixel
yading@11 185
yading@11 186 #define output_pixel(pos, val) \
yading@11 187 if (big_endian) { \
yading@11 188 AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
yading@11 189 } else { \
yading@11 190 AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
yading@11 191 }
yading@11 192
yading@11 193 static av_always_inline void
yading@11 194 yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW,
yading@11 195 int big_endian, int output_bits)
yading@11 196 {
yading@11 197 int i;
yading@11 198 int shift = 15 - output_bits;
yading@11 199
yading@11 200 for (i = 0; i < dstW; i++) {
yading@11 201 int val = src[i] + (1 << (shift - 1));
yading@11 202 output_pixel(&dest[i], val);
yading@11 203 }
yading@11 204 }
yading@11 205
yading@11 206 static av_always_inline void
yading@11 207 yuv2planeX_10_c_template(const int16_t *filter, int filterSize,
yading@11 208 const int16_t **src, uint16_t *dest, int dstW,
yading@11 209 int big_endian, int output_bits)
yading@11 210 {
yading@11 211 int i;
yading@11 212 int shift = 11 + 16 - output_bits;
yading@11 213
yading@11 214 for (i = 0; i < dstW; i++) {
yading@11 215 int val = 1 << (shift - 1);
yading@11 216 int j;
yading@11 217
yading@11 218 for (j = 0; j < filterSize; j++)
yading@11 219 val += src[j][i] * filter[j];
yading@11 220
yading@11 221 output_pixel(&dest[i], val);
yading@11 222 }
yading@11 223 }
yading@11 224
yading@11 225 #undef output_pixel
yading@11 226
yading@11 227 #define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \
yading@11 228 static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \
yading@11 229 uint8_t *dest, int dstW, \
yading@11 230 const uint8_t *dither, int offset)\
yading@11 231 { \
yading@11 232 yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \
yading@11 233 (uint16_t *) dest, dstW, is_be, bits); \
yading@11 234 }\
yading@11 235 static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \
yading@11 236 const int16_t **src, uint8_t *dest, int dstW, \
yading@11 237 const uint8_t *dither, int offset)\
yading@11 238 { \
yading@11 239 yuv2planeX_## template_size ## _c_template(filter, \
yading@11 240 filterSize, (const typeX_t **) src, \
yading@11 241 (uint16_t *) dest, dstW, is_be, bits); \
yading@11 242 }
yading@11 243 yuv2NBPS( 9, BE, 1, 10, int16_t)
yading@11 244 yuv2NBPS( 9, LE, 0, 10, int16_t)
yading@11 245 yuv2NBPS(10, BE, 1, 10, int16_t)
yading@11 246 yuv2NBPS(10, LE, 0, 10, int16_t)
yading@11 247 yuv2NBPS(12, BE, 1, 10, int16_t)
yading@11 248 yuv2NBPS(12, LE, 0, 10, int16_t)
yading@11 249 yuv2NBPS(14, BE, 1, 10, int16_t)
yading@11 250 yuv2NBPS(14, LE, 0, 10, int16_t)
yading@11 251 yuv2NBPS(16, BE, 1, 16, int32_t)
yading@11 252 yuv2NBPS(16, LE, 0, 16, int32_t)
yading@11 253
yading@11 254 static void yuv2planeX_8_c(const int16_t *filter, int filterSize,
yading@11 255 const int16_t **src, uint8_t *dest, int dstW,
yading@11 256 const uint8_t *dither, int offset)
yading@11 257 {
yading@11 258 int i;
yading@11 259 for (i=0; i<dstW; i++) {
yading@11 260 int val = dither[(i + offset) & 7] << 12;
yading@11 261 int j;
yading@11 262 for (j=0; j<filterSize; j++)
yading@11 263 val += src[j][i] * filter[j];
yading@11 264
yading@11 265 dest[i]= av_clip_uint8(val>>19);
yading@11 266 }
yading@11 267 }
yading@11 268
yading@11 269 static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW,
yading@11 270 const uint8_t *dither, int offset)
yading@11 271 {
yading@11 272 int i;
yading@11 273 for (i=0; i<dstW; i++) {
yading@11 274 int val = (src[i] + dither[(i + offset) & 7]) >> 7;
yading@11 275 dest[i]= av_clip_uint8(val);
yading@11 276 }
yading@11 277 }
yading@11 278
yading@11 279 static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
yading@11 280 const int16_t **chrUSrc, const int16_t **chrVSrc,
yading@11 281 uint8_t *dest, int chrDstW)
yading@11 282 {
yading@11 283 enum AVPixelFormat dstFormat = c->dstFormat;
yading@11 284 const uint8_t *chrDither = c->chrDither8;
yading@11 285 int i;
yading@11 286
yading@11 287 if (dstFormat == AV_PIX_FMT_NV12)
yading@11 288 for (i=0; i<chrDstW; i++) {
yading@11 289 int u = chrDither[i & 7] << 12;
yading@11 290 int v = chrDither[(i + 3) & 7] << 12;
yading@11 291 int j;
yading@11 292 for (j=0; j<chrFilterSize; j++) {
yading@11 293 u += chrUSrc[j][i] * chrFilter[j];
yading@11 294 v += chrVSrc[j][i] * chrFilter[j];
yading@11 295 }
yading@11 296
yading@11 297 dest[2*i]= av_clip_uint8(u>>19);
yading@11 298 dest[2*i+1]= av_clip_uint8(v>>19);
yading@11 299 }
yading@11 300 else
yading@11 301 for (i=0; i<chrDstW; i++) {
yading@11 302 int u = chrDither[i & 7] << 12;
yading@11 303 int v = chrDither[(i + 3) & 7] << 12;
yading@11 304 int j;
yading@11 305 for (j=0; j<chrFilterSize; j++) {
yading@11 306 u += chrUSrc[j][i] * chrFilter[j];
yading@11 307 v += chrVSrc[j][i] * chrFilter[j];
yading@11 308 }
yading@11 309
yading@11 310 dest[2*i]= av_clip_uint8(v>>19);
yading@11 311 dest[2*i+1]= av_clip_uint8(u>>19);
yading@11 312 }
yading@11 313 }
yading@11 314
yading@11 315 #define accumulate_bit(acc, val) \
yading@11 316 acc <<= 1; \
yading@11 317 acc |= (val) >= (128 + 110)
yading@11 318 #define output_pixel(pos, acc) \
yading@11 319 if (target == AV_PIX_FMT_MONOBLACK) { \
yading@11 320 pos = acc; \
yading@11 321 } else { \
yading@11 322 pos = ~acc; \
yading@11 323 }
yading@11 324
yading@11 325 static av_always_inline void
yading@11 326 yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,
yading@11 327 const int16_t **lumSrc, int lumFilterSize,
yading@11 328 const int16_t *chrFilter, const int16_t **chrUSrc,
yading@11 329 const int16_t **chrVSrc, int chrFilterSize,
yading@11 330 const int16_t **alpSrc, uint8_t *dest, int dstW,
yading@11 331 int y, enum AVPixelFormat target)
yading@11 332 {
yading@11 333 const uint8_t * const d128=dither_8x8_220[y&7];
yading@11 334 int i;
yading@11 335 unsigned acc = 0;
yading@11 336 int err = 0;
yading@11 337
yading@11 338 for (i = 0; i < dstW; i += 2) {
yading@11 339 int j;
yading@11 340 int Y1 = 1 << 18;
yading@11 341 int Y2 = 1 << 18;
yading@11 342
yading@11 343 for (j = 0; j < lumFilterSize; j++) {
yading@11 344 Y1 += lumSrc[j][i] * lumFilter[j];
yading@11 345 Y2 += lumSrc[j][i+1] * lumFilter[j];
yading@11 346 }
yading@11 347 Y1 >>= 19;
yading@11 348 Y2 >>= 19;
yading@11 349 if ((Y1 | Y2) & 0x100) {
yading@11 350 Y1 = av_clip_uint8(Y1);
yading@11 351 Y2 = av_clip_uint8(Y2);
yading@11 352 }
yading@11 353 if (c->flags & SWS_ERROR_DIFFUSION) {
yading@11 354 Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
yading@11 355 c->dither_error[0][i] = err;
yading@11 356 acc = 2*acc + (Y1 >= 128);
yading@11 357 Y1 -= 220*(acc&1);
yading@11 358
yading@11 359 err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);
yading@11 360 c->dither_error[0][i+1] = Y1;
yading@11 361 acc = 2*acc + (err >= 128);
yading@11 362 err -= 220*(acc&1);
yading@11 363 } else {
yading@11 364 accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);
yading@11 365 accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);
yading@11 366 }
yading@11 367 if ((i & 7) == 6) {
yading@11 368 output_pixel(*dest++, acc);
yading@11 369 }
yading@11 370 }
yading@11 371 c->dither_error[0][i] = err;
yading@11 372
yading@11 373 if (i & 6) {
yading@11 374 output_pixel(*dest, acc);
yading@11 375 }
yading@11 376 }
yading@11 377
yading@11 378 static av_always_inline void
yading@11 379 yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2],
yading@11 380 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 381 const int16_t *abuf[2], uint8_t *dest, int dstW,
yading@11 382 int yalpha, int uvalpha, int y,
yading@11 383 enum AVPixelFormat target)
yading@11 384 {
yading@11 385 const int16_t *buf0 = buf[0], *buf1 = buf[1];
yading@11 386 const uint8_t * const d128 = dither_8x8_220[y & 7];
yading@11 387 int yalpha1 = 4096 - yalpha;
yading@11 388 int i;
yading@11 389
yading@11 390 if (c->flags & SWS_ERROR_DIFFUSION) {
yading@11 391 int err = 0;
yading@11 392 int acc = 0;
yading@11 393 for (i = 0; i < dstW; i +=2) {
yading@11 394 int Y;
yading@11 395
yading@11 396 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
yading@11 397 Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
yading@11 398 c->dither_error[0][i] = err;
yading@11 399 acc = 2*acc + (Y >= 128);
yading@11 400 Y -= 220*(acc&1);
yading@11 401
yading@11 402 err = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
yading@11 403 err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
yading@11 404 c->dither_error[0][i+1] = Y;
yading@11 405 acc = 2*acc + (err >= 128);
yading@11 406 err -= 220*(acc&1);
yading@11 407
yading@11 408 if ((i & 7) == 6)
yading@11 409 output_pixel(*dest++, acc);
yading@11 410 }
yading@11 411 c->dither_error[0][i] = err;
yading@11 412 } else {
yading@11 413 for (i = 0; i < dstW; i += 8) {
yading@11 414 int Y, acc = 0;
yading@11 415
yading@11 416 Y = (buf0[i + 0] * yalpha1 + buf1[i + 0] * yalpha) >> 19;
yading@11 417 accumulate_bit(acc, Y + d128[0]);
yading@11 418 Y = (buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19;
yading@11 419 accumulate_bit(acc, Y + d128[1]);
yading@11 420 Y = (buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19;
yading@11 421 accumulate_bit(acc, Y + d128[2]);
yading@11 422 Y = (buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19;
yading@11 423 accumulate_bit(acc, Y + d128[3]);
yading@11 424 Y = (buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19;
yading@11 425 accumulate_bit(acc, Y + d128[4]);
yading@11 426 Y = (buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19;
yading@11 427 accumulate_bit(acc, Y + d128[5]);
yading@11 428 Y = (buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19;
yading@11 429 accumulate_bit(acc, Y + d128[6]);
yading@11 430 Y = (buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19;
yading@11 431 accumulate_bit(acc, Y + d128[7]);
yading@11 432
yading@11 433 output_pixel(*dest++, acc);
yading@11 434 }
yading@11 435 }
yading@11 436 }
yading@11 437
yading@11 438 static av_always_inline void
yading@11 439 yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0,
yading@11 440 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 441 const int16_t *abuf0, uint8_t *dest, int dstW,
yading@11 442 int uvalpha, int y, enum AVPixelFormat target)
yading@11 443 {
yading@11 444 const uint8_t * const d128 = dither_8x8_220[y & 7];
yading@11 445 int i;
yading@11 446
yading@11 447 if (c->flags & SWS_ERROR_DIFFUSION) {
yading@11 448 int err = 0;
yading@11 449 int acc = 0;
yading@11 450 for (i = 0; i < dstW; i +=2) {
yading@11 451 int Y;
yading@11 452
yading@11 453 Y = ((buf0[i + 0] + 64) >> 7);
yading@11 454 Y += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;
yading@11 455 c->dither_error[0][i] = err;
yading@11 456 acc = 2*acc + (Y >= 128);
yading@11 457 Y -= 220*(acc&1);
yading@11 458
yading@11 459 err = ((buf0[i + 1] + 64) >> 7);
yading@11 460 err += (7*Y + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4;
yading@11 461 c->dither_error[0][i+1] = Y;
yading@11 462 acc = 2*acc + (err >= 128);
yading@11 463 err -= 220*(acc&1);
yading@11 464
yading@11 465 if ((i & 7) == 6)
yading@11 466 output_pixel(*dest++, acc);
yading@11 467 }
yading@11 468 c->dither_error[0][i] = err;
yading@11 469 } else {
yading@11 470 for (i = 0; i < dstW; i += 8) {
yading@11 471 int acc = 0;
yading@11 472 accumulate_bit(acc, ((buf0[i + 0] + 64) >> 7) + d128[0]);
yading@11 473 accumulate_bit(acc, ((buf0[i + 1] + 64) >> 7) + d128[1]);
yading@11 474 accumulate_bit(acc, ((buf0[i + 2] + 64) >> 7) + d128[2]);
yading@11 475 accumulate_bit(acc, ((buf0[i + 3] + 64) >> 7) + d128[3]);
yading@11 476 accumulate_bit(acc, ((buf0[i + 4] + 64) >> 7) + d128[4]);
yading@11 477 accumulate_bit(acc, ((buf0[i + 5] + 64) >> 7) + d128[5]);
yading@11 478 accumulate_bit(acc, ((buf0[i + 6] + 64) >> 7) + d128[6]);
yading@11 479 accumulate_bit(acc, ((buf0[i + 7] + 64) >> 7) + d128[7]);
yading@11 480
yading@11 481 output_pixel(*dest++, acc);
yading@11 482 }
yading@11 483 }
yading@11 484 }
yading@11 485
yading@11 486 #undef output_pixel
yading@11 487 #undef accumulate_bit
yading@11 488
yading@11 489 #define YUV2PACKEDWRAPPER(name, base, ext, fmt) \
yading@11 490 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
yading@11 491 const int16_t **lumSrc, int lumFilterSize, \
yading@11 492 const int16_t *chrFilter, const int16_t **chrUSrc, \
yading@11 493 const int16_t **chrVSrc, int chrFilterSize, \
yading@11 494 const int16_t **alpSrc, uint8_t *dest, int dstW, \
yading@11 495 int y) \
yading@11 496 { \
yading@11 497 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
yading@11 498 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
yading@11 499 alpSrc, dest, dstW, y, fmt); \
yading@11 500 } \
yading@11 501 \
yading@11 502 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
yading@11 503 const int16_t *ubuf[2], const int16_t *vbuf[2], \
yading@11 504 const int16_t *abuf[2], uint8_t *dest, int dstW, \
yading@11 505 int yalpha, int uvalpha, int y) \
yading@11 506 { \
yading@11 507 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
yading@11 508 dest, dstW, yalpha, uvalpha, y, fmt); \
yading@11 509 } \
yading@11 510 \
yading@11 511 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
yading@11 512 const int16_t *ubuf[2], const int16_t *vbuf[2], \
yading@11 513 const int16_t *abuf0, uint8_t *dest, int dstW, \
yading@11 514 int uvalpha, int y) \
yading@11 515 { \
yading@11 516 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \
yading@11 517 abuf0, dest, dstW, uvalpha, \
yading@11 518 y, fmt); \
yading@11 519 }
yading@11 520
yading@11 521 YUV2PACKEDWRAPPER(yuv2mono,, white, AV_PIX_FMT_MONOWHITE)
yading@11 522 YUV2PACKEDWRAPPER(yuv2mono,, black, AV_PIX_FMT_MONOBLACK)
yading@11 523
yading@11 524 #define output_pixels(pos, Y1, U, Y2, V) \
yading@11 525 if (target == AV_PIX_FMT_YUYV422) { \
yading@11 526 dest[pos + 0] = Y1; \
yading@11 527 dest[pos + 1] = U; \
yading@11 528 dest[pos + 2] = Y2; \
yading@11 529 dest[pos + 3] = V; \
yading@11 530 } else { \
yading@11 531 dest[pos + 0] = U; \
yading@11 532 dest[pos + 1] = Y1; \
yading@11 533 dest[pos + 2] = V; \
yading@11 534 dest[pos + 3] = Y2; \
yading@11 535 }
yading@11 536
yading@11 537 static av_always_inline void
yading@11 538 yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
yading@11 539 const int16_t **lumSrc, int lumFilterSize,
yading@11 540 const int16_t *chrFilter, const int16_t **chrUSrc,
yading@11 541 const int16_t **chrVSrc, int chrFilterSize,
yading@11 542 const int16_t **alpSrc, uint8_t *dest, int dstW,
yading@11 543 int y, enum AVPixelFormat target)
yading@11 544 {
yading@11 545 int i;
yading@11 546
yading@11 547 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 548 int j;
yading@11 549 int Y1 = 1 << 18;
yading@11 550 int Y2 = 1 << 18;
yading@11 551 int U = 1 << 18;
yading@11 552 int V = 1 << 18;
yading@11 553
yading@11 554 for (j = 0; j < lumFilterSize; j++) {
yading@11 555 Y1 += lumSrc[j][i * 2] * lumFilter[j];
yading@11 556 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
yading@11 557 }
yading@11 558 for (j = 0; j < chrFilterSize; j++) {
yading@11 559 U += chrUSrc[j][i] * chrFilter[j];
yading@11 560 V += chrVSrc[j][i] * chrFilter[j];
yading@11 561 }
yading@11 562 Y1 >>= 19;
yading@11 563 Y2 >>= 19;
yading@11 564 U >>= 19;
yading@11 565 V >>= 19;
yading@11 566 if ((Y1 | Y2 | U | V) & 0x100) {
yading@11 567 Y1 = av_clip_uint8(Y1);
yading@11 568 Y2 = av_clip_uint8(Y2);
yading@11 569 U = av_clip_uint8(U);
yading@11 570 V = av_clip_uint8(V);
yading@11 571 }
yading@11 572 output_pixels(4*i, Y1, U, Y2, V);
yading@11 573 }
yading@11 574 }
yading@11 575
yading@11 576 static av_always_inline void
yading@11 577 yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
yading@11 578 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 579 const int16_t *abuf[2], uint8_t *dest, int dstW,
yading@11 580 int yalpha, int uvalpha, int y,
yading@11 581 enum AVPixelFormat target)
yading@11 582 {
yading@11 583 const int16_t *buf0 = buf[0], *buf1 = buf[1],
yading@11 584 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
yading@11 585 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
yading@11 586 int yalpha1 = 4096 - yalpha;
yading@11 587 int uvalpha1 = 4096 - uvalpha;
yading@11 588 int i;
yading@11 589
yading@11 590 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 591 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
yading@11 592 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
yading@11 593 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
yading@11 594 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
yading@11 595
yading@11 596 if ((Y1 | Y2 | U | V) & 0x100) {
yading@11 597 Y1 = av_clip_uint8(Y1);
yading@11 598 Y2 = av_clip_uint8(Y2);
yading@11 599 U = av_clip_uint8(U);
yading@11 600 V = av_clip_uint8(V);
yading@11 601 }
yading@11 602
yading@11 603 output_pixels(i * 4, Y1, U, Y2, V);
yading@11 604 }
yading@11 605 }
yading@11 606
yading@11 607 static av_always_inline void
yading@11 608 yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
yading@11 609 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 610 const int16_t *abuf0, uint8_t *dest, int dstW,
yading@11 611 int uvalpha, int y, enum AVPixelFormat target)
yading@11 612 {
yading@11 613 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
yading@11 614 int i;
yading@11 615
yading@11 616 if (uvalpha < 2048) {
yading@11 617 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 618 int Y1 = (buf0[i * 2 ]+64) >> 7;
yading@11 619 int Y2 = (buf0[i * 2 + 1]+64) >> 7;
yading@11 620 int U = (ubuf0[i] +64) >> 7;
yading@11 621 int V = (vbuf0[i] +64) >> 7;
yading@11 622
yading@11 623 if ((Y1 | Y2 | U | V) & 0x100) {
yading@11 624 Y1 = av_clip_uint8(Y1);
yading@11 625 Y2 = av_clip_uint8(Y2);
yading@11 626 U = av_clip_uint8(U);
yading@11 627 V = av_clip_uint8(V);
yading@11 628 }
yading@11 629
yading@11 630 Y1 = av_clip_uint8(Y1);
yading@11 631 Y2 = av_clip_uint8(Y2);
yading@11 632 U = av_clip_uint8(U);
yading@11 633 V = av_clip_uint8(V);
yading@11 634
yading@11 635 output_pixels(i * 4, Y1, U, Y2, V);
yading@11 636 }
yading@11 637 } else {
yading@11 638 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
yading@11 639 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 640 int Y1 = (buf0[i * 2 ] + 64) >> 7;
yading@11 641 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
yading@11 642 int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
yading@11 643 int V = (vbuf0[i] + vbuf1[i]+128) >> 8;
yading@11 644
yading@11 645 if ((Y1 | Y2 | U | V) & 0x100) {
yading@11 646 Y1 = av_clip_uint8(Y1);
yading@11 647 Y2 = av_clip_uint8(Y2);
yading@11 648 U = av_clip_uint8(U);
yading@11 649 V = av_clip_uint8(V);
yading@11 650 }
yading@11 651
yading@11 652 Y1 = av_clip_uint8(Y1);
yading@11 653 Y2 = av_clip_uint8(Y2);
yading@11 654 U = av_clip_uint8(U);
yading@11 655 V = av_clip_uint8(V);
yading@11 656
yading@11 657 output_pixels(i * 4, Y1, U, Y2, V);
yading@11 658 }
yading@11 659 }
yading@11 660 }
yading@11 661
yading@11 662 #undef output_pixels
yading@11 663
yading@11 664 YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, AV_PIX_FMT_YUYV422)
yading@11 665 YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
yading@11 666
yading@11 667 #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? R : B)
yading@11 668 #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE) ? B : R)
yading@11 669 #define output_pixel(pos, val) \
yading@11 670 if (isBE(target)) { \
yading@11 671 AV_WB16(pos, val); \
yading@11 672 } else { \
yading@11 673 AV_WL16(pos, val); \
yading@11 674 }
yading@11 675
yading@11 676 static av_always_inline void
yading@11 677 yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
yading@11 678 const int32_t **lumSrc, int lumFilterSize,
yading@11 679 const int16_t *chrFilter, const int32_t **chrUSrc,
yading@11 680 const int32_t **chrVSrc, int chrFilterSize,
yading@11 681 const int32_t **alpSrc, uint16_t *dest, int dstW,
yading@11 682 int y, enum AVPixelFormat target)
yading@11 683 {
yading@11 684 int i;
yading@11 685
yading@11 686 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 687 int j;
yading@11 688 int Y1 = -0x40000000;
yading@11 689 int Y2 = -0x40000000;
yading@11 690 int U = -128 << 23; // 19
yading@11 691 int V = -128 << 23;
yading@11 692 int R, G, B;
yading@11 693
yading@11 694 for (j = 0; j < lumFilterSize; j++) {
yading@11 695 Y1 += lumSrc[j][i * 2] * (unsigned)lumFilter[j];
yading@11 696 Y2 += lumSrc[j][i * 2 + 1] * (unsigned)lumFilter[j];
yading@11 697 }
yading@11 698 for (j = 0; j < chrFilterSize; j++) {;
yading@11 699 U += chrUSrc[j][i] * (unsigned)chrFilter[j];
yading@11 700 V += chrVSrc[j][i] * (unsigned)chrFilter[j];
yading@11 701 }
yading@11 702
yading@11 703 // 8bit: 12+15=27; 16-bit: 12+19=31
yading@11 704 Y1 >>= 14; // 10
yading@11 705 Y1 += 0x10000;
yading@11 706 Y2 >>= 14;
yading@11 707 Y2 += 0x10000;
yading@11 708 U >>= 14;
yading@11 709 V >>= 14;
yading@11 710
yading@11 711 // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit
yading@11 712 Y1 -= c->yuv2rgb_y_offset;
yading@11 713 Y2 -= c->yuv2rgb_y_offset;
yading@11 714 Y1 *= c->yuv2rgb_y_coeff;
yading@11 715 Y2 *= c->yuv2rgb_y_coeff;
yading@11 716 Y1 += 1 << 13; // 21
yading@11 717 Y2 += 1 << 13;
yading@11 718 // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit
yading@11 719
yading@11 720 R = V * c->yuv2rgb_v2r_coeff;
yading@11 721 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
yading@11 722 B = U * c->yuv2rgb_u2b_coeff;
yading@11 723
yading@11 724 // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
yading@11 725 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
yading@11 726 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
yading@11 727 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
yading@11 728 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
yading@11 729 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
yading@11 730 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
yading@11 731 dest += 6;
yading@11 732 }
yading@11 733 }
yading@11 734
yading@11 735 static av_always_inline void
yading@11 736 yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
yading@11 737 const int32_t *ubuf[2], const int32_t *vbuf[2],
yading@11 738 const int32_t *abuf[2], uint16_t *dest, int dstW,
yading@11 739 int yalpha, int uvalpha, int y,
yading@11 740 enum AVPixelFormat target)
yading@11 741 {
yading@11 742 const int32_t *buf0 = buf[0], *buf1 = buf[1],
yading@11 743 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
yading@11 744 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
yading@11 745 int yalpha1 = 4096 - yalpha;
yading@11 746 int uvalpha1 = 4096 - uvalpha;
yading@11 747 int i;
yading@11 748
yading@11 749 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 750 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
yading@11 751 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
yading@11 752 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14;
yading@11 753 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14;
yading@11 754 int R, G, B;
yading@11 755
yading@11 756 Y1 -= c->yuv2rgb_y_offset;
yading@11 757 Y2 -= c->yuv2rgb_y_offset;
yading@11 758 Y1 *= c->yuv2rgb_y_coeff;
yading@11 759 Y2 *= c->yuv2rgb_y_coeff;
yading@11 760 Y1 += 1 << 13;
yading@11 761 Y2 += 1 << 13;
yading@11 762
yading@11 763 R = V * c->yuv2rgb_v2r_coeff;
yading@11 764 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
yading@11 765 B = U * c->yuv2rgb_u2b_coeff;
yading@11 766
yading@11 767 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
yading@11 768 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
yading@11 769 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
yading@11 770 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
yading@11 771 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
yading@11 772 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
yading@11 773 dest += 6;
yading@11 774 }
yading@11 775 }
yading@11 776
yading@11 777 static av_always_inline void
yading@11 778 yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
yading@11 779 const int32_t *ubuf[2], const int32_t *vbuf[2],
yading@11 780 const int32_t *abuf0, uint16_t *dest, int dstW,
yading@11 781 int uvalpha, int y, enum AVPixelFormat target)
yading@11 782 {
yading@11 783 const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
yading@11 784 int i;
yading@11 785
yading@11 786 if (uvalpha < 2048) {
yading@11 787 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 788 int Y1 = (buf0[i * 2] ) >> 2;
yading@11 789 int Y2 = (buf0[i * 2 + 1]) >> 2;
yading@11 790 int U = (ubuf0[i] + (-128 << 11)) >> 2;
yading@11 791 int V = (vbuf0[i] + (-128 << 11)) >> 2;
yading@11 792 int R, G, B;
yading@11 793
yading@11 794 Y1 -= c->yuv2rgb_y_offset;
yading@11 795 Y2 -= c->yuv2rgb_y_offset;
yading@11 796 Y1 *= c->yuv2rgb_y_coeff;
yading@11 797 Y2 *= c->yuv2rgb_y_coeff;
yading@11 798 Y1 += 1 << 13;
yading@11 799 Y2 += 1 << 13;
yading@11 800
yading@11 801 R = V * c->yuv2rgb_v2r_coeff;
yading@11 802 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
yading@11 803 B = U * c->yuv2rgb_u2b_coeff;
yading@11 804
yading@11 805 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
yading@11 806 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
yading@11 807 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
yading@11 808 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
yading@11 809 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
yading@11 810 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
yading@11 811 dest += 6;
yading@11 812 }
yading@11 813 } else {
yading@11 814 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
yading@11 815 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 816 int Y1 = (buf0[i * 2] ) >> 2;
yading@11 817 int Y2 = (buf0[i * 2 + 1]) >> 2;
yading@11 818 int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
yading@11 819 int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;
yading@11 820 int R, G, B;
yading@11 821
yading@11 822 Y1 -= c->yuv2rgb_y_offset;
yading@11 823 Y2 -= c->yuv2rgb_y_offset;
yading@11 824 Y1 *= c->yuv2rgb_y_coeff;
yading@11 825 Y2 *= c->yuv2rgb_y_coeff;
yading@11 826 Y1 += 1 << 13;
yading@11 827 Y2 += 1 << 13;
yading@11 828
yading@11 829 R = V * c->yuv2rgb_v2r_coeff;
yading@11 830 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
yading@11 831 B = U * c->yuv2rgb_u2b_coeff;
yading@11 832
yading@11 833 output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
yading@11 834 output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14);
yading@11 835 output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
yading@11 836 output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
yading@11 837 output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14);
yading@11 838 output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
yading@11 839 dest += 6;
yading@11 840 }
yading@11 841 }
yading@11 842 }
yading@11 843
yading@11 844 #undef output_pixel
yading@11 845 #undef r_b
yading@11 846 #undef b_r
yading@11 847
yading@11 848 #define YUV2PACKED16WRAPPER(name, base, ext, fmt) \
yading@11 849 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
yading@11 850 const int16_t **_lumSrc, int lumFilterSize, \
yading@11 851 const int16_t *chrFilter, const int16_t **_chrUSrc, \
yading@11 852 const int16_t **_chrVSrc, int chrFilterSize, \
yading@11 853 const int16_t **_alpSrc, uint8_t *_dest, int dstW, \
yading@11 854 int y) \
yading@11 855 { \
yading@11 856 const int32_t **lumSrc = (const int32_t **) _lumSrc, \
yading@11 857 **chrUSrc = (const int32_t **) _chrUSrc, \
yading@11 858 **chrVSrc = (const int32_t **) _chrVSrc, \
yading@11 859 **alpSrc = (const int32_t **) _alpSrc; \
yading@11 860 uint16_t *dest = (uint16_t *) _dest; \
yading@11 861 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
yading@11 862 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
yading@11 863 alpSrc, dest, dstW, y, fmt); \
yading@11 864 } \
yading@11 865 \
yading@11 866 static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \
yading@11 867 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
yading@11 868 const int16_t *_abuf[2], uint8_t *_dest, int dstW, \
yading@11 869 int yalpha, int uvalpha, int y) \
yading@11 870 { \
yading@11 871 const int32_t **buf = (const int32_t **) _buf, \
yading@11 872 **ubuf = (const int32_t **) _ubuf, \
yading@11 873 **vbuf = (const int32_t **) _vbuf, \
yading@11 874 **abuf = (const int32_t **) _abuf; \
yading@11 875 uint16_t *dest = (uint16_t *) _dest; \
yading@11 876 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
yading@11 877 dest, dstW, yalpha, uvalpha, y, fmt); \
yading@11 878 } \
yading@11 879 \
yading@11 880 static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \
yading@11 881 const int16_t *_ubuf[2], const int16_t *_vbuf[2], \
yading@11 882 const int16_t *_abuf0, uint8_t *_dest, int dstW, \
yading@11 883 int uvalpha, int y) \
yading@11 884 { \
yading@11 885 const int32_t *buf0 = (const int32_t *) _buf0, \
yading@11 886 **ubuf = (const int32_t **) _ubuf, \
yading@11 887 **vbuf = (const int32_t **) _vbuf, \
yading@11 888 *abuf0 = (const int32_t *) _abuf0; \
yading@11 889 uint16_t *dest = (uint16_t *) _dest; \
yading@11 890 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
yading@11 891 dstW, uvalpha, y, fmt); \
yading@11 892 }
yading@11 893
yading@11 894 YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, AV_PIX_FMT_RGB48BE)
yading@11 895 YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, AV_PIX_FMT_RGB48LE)
yading@11 896 YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, AV_PIX_FMT_BGR48BE)
yading@11 897 YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, AV_PIX_FMT_BGR48LE)
yading@11 898
yading@11 899 /*
yading@11 900 * Write out 2 RGB pixels in the target pixel format. This function takes a
yading@11 901 * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of
yading@11 902 * things like endianness conversion and shifting. The caller takes care of
yading@11 903 * setting the correct offset in these tables from the chroma (U/V) values.
yading@11 904 * This function then uses the luminance (Y1/Y2) values to write out the
yading@11 905 * correct RGB values into the destination buffer.
yading@11 906 */
yading@11 907 static av_always_inline void
yading@11 908 yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2,
yading@11 909 unsigned A1, unsigned A2,
yading@11 910 const void *_r, const void *_g, const void *_b, int y,
yading@11 911 enum AVPixelFormat target, int hasAlpha)
yading@11 912 {
yading@11 913 if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_RGBA ||
yading@11 914 target == AV_PIX_FMT_ABGR || target == AV_PIX_FMT_BGRA) {
yading@11 915 uint32_t *dest = (uint32_t *) _dest;
yading@11 916 const uint32_t *r = (const uint32_t *) _r;
yading@11 917 const uint32_t *g = (const uint32_t *) _g;
yading@11 918 const uint32_t *b = (const uint32_t *) _b;
yading@11 919
yading@11 920 #if CONFIG_SMALL
yading@11 921 int sh = hasAlpha ? ((target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24) : 0;
yading@11 922
yading@11 923 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0);
yading@11 924 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0);
yading@11 925 #else
yading@11 926 if (hasAlpha) {
yading@11 927 int sh = (target == AV_PIX_FMT_RGB32_1 || target == AV_PIX_FMT_BGR32_1) ? 0 : 24;
yading@11 928
yading@11 929 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh);
yading@11 930 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh);
yading@11 931 } else {
yading@11 932 dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1];
yading@11 933 dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2];
yading@11 934 }
yading@11 935 #endif
yading@11 936 } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
yading@11 937 uint8_t *dest = (uint8_t *) _dest;
yading@11 938 const uint8_t *r = (const uint8_t *) _r;
yading@11 939 const uint8_t *g = (const uint8_t *) _g;
yading@11 940 const uint8_t *b = (const uint8_t *) _b;
yading@11 941
yading@11 942 #define r_b ((target == AV_PIX_FMT_RGB24) ? r : b)
yading@11 943 #define b_r ((target == AV_PIX_FMT_RGB24) ? b : r)
yading@11 944
yading@11 945 dest[i * 6 + 0] = r_b[Y1];
yading@11 946 dest[i * 6 + 1] = g[Y1];
yading@11 947 dest[i * 6 + 2] = b_r[Y1];
yading@11 948 dest[i * 6 + 3] = r_b[Y2];
yading@11 949 dest[i * 6 + 4] = g[Y2];
yading@11 950 dest[i * 6 + 5] = b_r[Y2];
yading@11 951 #undef r_b
yading@11 952 #undef b_r
yading@11 953 } else if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565 ||
yading@11 954 target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555 ||
yading@11 955 target == AV_PIX_FMT_RGB444 || target == AV_PIX_FMT_BGR444) {
yading@11 956 uint16_t *dest = (uint16_t *) _dest;
yading@11 957 const uint16_t *r = (const uint16_t *) _r;
yading@11 958 const uint16_t *g = (const uint16_t *) _g;
yading@11 959 const uint16_t *b = (const uint16_t *) _b;
yading@11 960 int dr1, dg1, db1, dr2, dg2, db2;
yading@11 961
yading@11 962 if (target == AV_PIX_FMT_RGB565 || target == AV_PIX_FMT_BGR565) {
yading@11 963 dr1 = dither_2x2_8[ y & 1 ][0];
yading@11 964 dg1 = dither_2x2_4[ y & 1 ][0];
yading@11 965 db1 = dither_2x2_8[(y & 1) ^ 1][0];
yading@11 966 dr2 = dither_2x2_8[ y & 1 ][1];
yading@11 967 dg2 = dither_2x2_4[ y & 1 ][1];
yading@11 968 db2 = dither_2x2_8[(y & 1) ^ 1][1];
yading@11 969 } else if (target == AV_PIX_FMT_RGB555 || target == AV_PIX_FMT_BGR555) {
yading@11 970 dr1 = dither_2x2_8[ y & 1 ][0];
yading@11 971 dg1 = dither_2x2_8[ y & 1 ][1];
yading@11 972 db1 = dither_2x2_8[(y & 1) ^ 1][0];
yading@11 973 dr2 = dither_2x2_8[ y & 1 ][1];
yading@11 974 dg2 = dither_2x2_8[ y & 1 ][0];
yading@11 975 db2 = dither_2x2_8[(y & 1) ^ 1][1];
yading@11 976 } else {
yading@11 977 dr1 = dither_4x4_16[ y & 3 ][0];
yading@11 978 dg1 = dither_4x4_16[ y & 3 ][1];
yading@11 979 db1 = dither_4x4_16[(y & 3) ^ 3][0];
yading@11 980 dr2 = dither_4x4_16[ y & 3 ][1];
yading@11 981 dg2 = dither_4x4_16[ y & 3 ][0];
yading@11 982 db2 = dither_4x4_16[(y & 3) ^ 3][1];
yading@11 983 }
yading@11 984
yading@11 985 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
yading@11 986 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
yading@11 987 } else /* 8/4-bit */ {
yading@11 988 uint8_t *dest = (uint8_t *) _dest;
yading@11 989 const uint8_t *r = (const uint8_t *) _r;
yading@11 990 const uint8_t *g = (const uint8_t *) _g;
yading@11 991 const uint8_t *b = (const uint8_t *) _b;
yading@11 992 int dr1, dg1, db1, dr2, dg2, db2;
yading@11 993
yading@11 994 if (target == AV_PIX_FMT_RGB8 || target == AV_PIX_FMT_BGR8) {
yading@11 995 const uint8_t * const d64 = dither_8x8_73[y & 7];
yading@11 996 const uint8_t * const d32 = dither_8x8_32[y & 7];
yading@11 997 dr1 = dg1 = d32[(i * 2 + 0) & 7];
yading@11 998 db1 = d64[(i * 2 + 0) & 7];
yading@11 999 dr2 = dg2 = d32[(i * 2 + 1) & 7];
yading@11 1000 db2 = d64[(i * 2 + 1) & 7];
yading@11 1001 } else {
yading@11 1002 const uint8_t * const d64 = dither_8x8_73 [y & 7];
yading@11 1003 const uint8_t * const d128 = dither_8x8_220[y & 7];
yading@11 1004 dr1 = db1 = d128[(i * 2 + 0) & 7];
yading@11 1005 dg1 = d64[(i * 2 + 0) & 7];
yading@11 1006 dr2 = db2 = d128[(i * 2 + 1) & 7];
yading@11 1007 dg2 = d64[(i * 2 + 1) & 7];
yading@11 1008 }
yading@11 1009
yading@11 1010 if (target == AV_PIX_FMT_RGB4 || target == AV_PIX_FMT_BGR4) {
yading@11 1011 dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] +
yading@11 1012 ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4);
yading@11 1013 } else {
yading@11 1014 dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1];
yading@11 1015 dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2];
yading@11 1016 }
yading@11 1017 }
yading@11 1018 }
yading@11 1019
yading@11 1020 static av_always_inline void
yading@11 1021 yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
yading@11 1022 const int16_t **lumSrc, int lumFilterSize,
yading@11 1023 const int16_t *chrFilter, const int16_t **chrUSrc,
yading@11 1024 const int16_t **chrVSrc, int chrFilterSize,
yading@11 1025 const int16_t **alpSrc, uint8_t *dest, int dstW,
yading@11 1026 int y, enum AVPixelFormat target, int hasAlpha)
yading@11 1027 {
yading@11 1028 int i;
yading@11 1029
yading@11 1030 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 1031 int j, A1, A2;
yading@11 1032 int Y1 = 1 << 18;
yading@11 1033 int Y2 = 1 << 18;
yading@11 1034 int U = 1 << 18;
yading@11 1035 int V = 1 << 18;
yading@11 1036 const void *r, *g, *b;
yading@11 1037
yading@11 1038 for (j = 0; j < lumFilterSize; j++) {
yading@11 1039 Y1 += lumSrc[j][i * 2] * lumFilter[j];
yading@11 1040 Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j];
yading@11 1041 }
yading@11 1042 for (j = 0; j < chrFilterSize; j++) {
yading@11 1043 U += chrUSrc[j][i] * chrFilter[j];
yading@11 1044 V += chrVSrc[j][i] * chrFilter[j];
yading@11 1045 }
yading@11 1046 Y1 >>= 19;
yading@11 1047 Y2 >>= 19;
yading@11 1048 U >>= 19;
yading@11 1049 V >>= 19;
yading@11 1050 if (hasAlpha) {
yading@11 1051 A1 = 1 << 18;
yading@11 1052 A2 = 1 << 18;
yading@11 1053 for (j = 0; j < lumFilterSize; j++) {
yading@11 1054 A1 += alpSrc[j][i * 2 ] * lumFilter[j];
yading@11 1055 A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
yading@11 1056 }
yading@11 1057 A1 >>= 19;
yading@11 1058 A2 >>= 19;
yading@11 1059 if ((A1 | A2) & 0x100) {
yading@11 1060 A1 = av_clip_uint8(A1);
yading@11 1061 A2 = av_clip_uint8(A2);
yading@11 1062 }
yading@11 1063 }
yading@11 1064
yading@11 1065 r = c->table_rV[V + YUVRGB_TABLE_HEADROOM];
yading@11 1066 g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]);
yading@11 1067 b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
yading@11 1068
yading@11 1069 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
yading@11 1070 r, g, b, y, target, hasAlpha);
yading@11 1071 }
yading@11 1072 }
yading@11 1073
yading@11 1074 static av_always_inline void
yading@11 1075 yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
yading@11 1076 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 1077 const int16_t *abuf[2], uint8_t *dest, int dstW,
yading@11 1078 int yalpha, int uvalpha, int y,
yading@11 1079 enum AVPixelFormat target, int hasAlpha)
yading@11 1080 {
yading@11 1081 const int16_t *buf0 = buf[0], *buf1 = buf[1],
yading@11 1082 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
yading@11 1083 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
yading@11 1084 *abuf0 = hasAlpha ? abuf[0] : NULL,
yading@11 1085 *abuf1 = hasAlpha ? abuf[1] : NULL;
yading@11 1086 int yalpha1 = 4096 - yalpha;
yading@11 1087 int uvalpha1 = 4096 - uvalpha;
yading@11 1088 int i;
yading@11 1089
yading@11 1090 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 1091 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
yading@11 1092 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
yading@11 1093 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
yading@11 1094 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
yading@11 1095 int A1, A2;
yading@11 1096 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
yading@11 1097 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
yading@11 1098 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
yading@11 1099
yading@11 1100 if (hasAlpha) {
yading@11 1101 A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;
yading@11 1102 A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;
yading@11 1103 A1 = av_clip_uint8(A1);
yading@11 1104 A2 = av_clip_uint8(A2);
yading@11 1105 }
yading@11 1106
yading@11 1107 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
yading@11 1108 r, g, b, y, target, hasAlpha);
yading@11 1109 }
yading@11 1110 }
yading@11 1111
yading@11 1112 static av_always_inline void
yading@11 1113 yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
yading@11 1114 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 1115 const int16_t *abuf0, uint8_t *dest, int dstW,
yading@11 1116 int uvalpha, int y, enum AVPixelFormat target,
yading@11 1117 int hasAlpha)
yading@11 1118 {
yading@11 1119 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
yading@11 1120 int i;
yading@11 1121
yading@11 1122 if (uvalpha < 2048) {
yading@11 1123 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 1124 int Y1 = (buf0[i * 2 ] + 64) >> 7;
yading@11 1125 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
yading@11 1126 int U = (ubuf0[i] + 64) >> 7;
yading@11 1127 int V = (vbuf0[i] + 64) >> 7;
yading@11 1128 int A1, A2;
yading@11 1129 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
yading@11 1130 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
yading@11 1131 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
yading@11 1132
yading@11 1133 if (hasAlpha) {
yading@11 1134 A1 = abuf0[i * 2 ] * 255 + 16384 >> 15;
yading@11 1135 A2 = abuf0[i * 2 + 1] * 255 + 16384 >> 15;
yading@11 1136 A1 = av_clip_uint8(A1);
yading@11 1137 A2 = av_clip_uint8(A2);
yading@11 1138 }
yading@11 1139
yading@11 1140 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
yading@11 1141 r, g, b, y, target, hasAlpha);
yading@11 1142 }
yading@11 1143 } else {
yading@11 1144 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
yading@11 1145 for (i = 0; i < ((dstW + 1) >> 1); i++) {
yading@11 1146 int Y1 = (buf0[i * 2 ] + 64) >> 7;
yading@11 1147 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
yading@11 1148 int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
yading@11 1149 int V = (vbuf0[i] + vbuf1[i] + 128) >> 8;
yading@11 1150 int A1, A2;
yading@11 1151 const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM],
yading@11 1152 *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]),
yading@11 1153 *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM];
yading@11 1154
yading@11 1155 if (hasAlpha) {
yading@11 1156 A1 = (abuf0[i * 2 ] + 64) >> 7;
yading@11 1157 A2 = (abuf0[i * 2 + 1] + 64) >> 7;
yading@11 1158 A1 = av_clip_uint8(A1);
yading@11 1159 A2 = av_clip_uint8(A2);
yading@11 1160 }
yading@11 1161
yading@11 1162 yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
yading@11 1163 r, g, b, y, target, hasAlpha);
yading@11 1164 }
yading@11 1165 }
yading@11 1166 }
yading@11 1167
yading@11 1168 #define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
yading@11 1169 static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \
yading@11 1170 const int16_t **lumSrc, int lumFilterSize, \
yading@11 1171 const int16_t *chrFilter, const int16_t **chrUSrc, \
yading@11 1172 const int16_t **chrVSrc, int chrFilterSize, \
yading@11 1173 const int16_t **alpSrc, uint8_t *dest, int dstW, \
yading@11 1174 int y) \
yading@11 1175 { \
yading@11 1176 name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
yading@11 1177 chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
yading@11 1178 alpSrc, dest, dstW, y, fmt, hasAlpha); \
yading@11 1179 }
yading@11 1180
yading@11 1181 #define YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
yading@11 1182 YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \
yading@11 1183 static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \
yading@11 1184 const int16_t *ubuf[2], const int16_t *vbuf[2], \
yading@11 1185 const int16_t *abuf[2], uint8_t *dest, int dstW, \
yading@11 1186 int yalpha, int uvalpha, int y) \
yading@11 1187 { \
yading@11 1188 name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \
yading@11 1189 dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \
yading@11 1190 }
yading@11 1191
yading@11 1192 #define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \
yading@11 1193 YUV2RGBWRAPPERX2(name, base, ext, fmt, hasAlpha) \
yading@11 1194 static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \
yading@11 1195 const int16_t *ubuf[2], const int16_t *vbuf[2], \
yading@11 1196 const int16_t *abuf0, uint8_t *dest, int dstW, \
yading@11 1197 int uvalpha, int y) \
yading@11 1198 { \
yading@11 1199 name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \
yading@11 1200 dstW, uvalpha, y, fmt, hasAlpha); \
yading@11 1201 }
yading@11 1202
yading@11 1203 #if CONFIG_SMALL
yading@11 1204 YUV2RGBWRAPPER(yuv2rgb,, 32_1, AV_PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
yading@11 1205 YUV2RGBWRAPPER(yuv2rgb,, 32, AV_PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
yading@11 1206 #else
yading@11 1207 #if CONFIG_SWSCALE_ALPHA
yading@11 1208 YUV2RGBWRAPPER(yuv2rgb,, a32_1, AV_PIX_FMT_RGB32_1, 1)
yading@11 1209 YUV2RGBWRAPPER(yuv2rgb,, a32, AV_PIX_FMT_RGB32, 1)
yading@11 1210 #endif
yading@11 1211 YUV2RGBWRAPPER(yuv2rgb,, x32_1, AV_PIX_FMT_RGB32_1, 0)
yading@11 1212 YUV2RGBWRAPPER(yuv2rgb,, x32, AV_PIX_FMT_RGB32, 0)
yading@11 1213 #endif
yading@11 1214 YUV2RGBWRAPPER(yuv2, rgb, rgb24, AV_PIX_FMT_RGB24, 0)
yading@11 1215 YUV2RGBWRAPPER(yuv2, rgb, bgr24, AV_PIX_FMT_BGR24, 0)
yading@11 1216 YUV2RGBWRAPPER(yuv2rgb,, 16, AV_PIX_FMT_RGB565, 0)
yading@11 1217 YUV2RGBWRAPPER(yuv2rgb,, 15, AV_PIX_FMT_RGB555, 0)
yading@11 1218 YUV2RGBWRAPPER(yuv2rgb,, 12, AV_PIX_FMT_RGB444, 0)
yading@11 1219 YUV2RGBWRAPPER(yuv2rgb,, 8, AV_PIX_FMT_RGB8, 0)
yading@11 1220 YUV2RGBWRAPPER(yuv2rgb,, 4, AV_PIX_FMT_RGB4, 0)
yading@11 1221 YUV2RGBWRAPPER(yuv2rgb,, 4b, AV_PIX_FMT_RGB4_BYTE, 0)
yading@11 1222
yading@11 1223 static av_always_inline void yuv2rgb_write_full(SwsContext *c,
yading@11 1224 uint8_t *dest, int i, int Y, int A, int U, int V,
yading@11 1225 int y, enum AVPixelFormat target, int hasAlpha, int err[4])
yading@11 1226 {
yading@11 1227 int R, G, B;
yading@11 1228 int isrgb8 = target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8;
yading@11 1229
yading@11 1230 Y -= c->yuv2rgb_y_offset;
yading@11 1231 Y *= c->yuv2rgb_y_coeff;
yading@11 1232 Y += 1 << 21;
yading@11 1233 R = Y + V*c->yuv2rgb_v2r_coeff;
yading@11 1234 G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;
yading@11 1235 B = Y + U*c->yuv2rgb_u2b_coeff;
yading@11 1236 if ((R | G | B) & 0xC0000000) {
yading@11 1237 R = av_clip_uintp2(R, 30);
yading@11 1238 G = av_clip_uintp2(G, 30);
yading@11 1239 B = av_clip_uintp2(B, 30);
yading@11 1240 }
yading@11 1241
yading@11 1242 switch(target) {
yading@11 1243 case AV_PIX_FMT_ARGB:
yading@11 1244 dest[0] = hasAlpha ? A : 255;
yading@11 1245 dest[1] = R >> 22;
yading@11 1246 dest[2] = G >> 22;
yading@11 1247 dest[3] = B >> 22;
yading@11 1248 break;
yading@11 1249 case AV_PIX_FMT_RGB24:
yading@11 1250 dest[0] = R >> 22;
yading@11 1251 dest[1] = G >> 22;
yading@11 1252 dest[2] = B >> 22;
yading@11 1253 break;
yading@11 1254 case AV_PIX_FMT_RGBA:
yading@11 1255 dest[0] = R >> 22;
yading@11 1256 dest[1] = G >> 22;
yading@11 1257 dest[2] = B >> 22;
yading@11 1258 dest[3] = hasAlpha ? A : 255;
yading@11 1259 break;
yading@11 1260 case AV_PIX_FMT_ABGR:
yading@11 1261 dest[0] = hasAlpha ? A : 255;
yading@11 1262 dest[1] = B >> 22;
yading@11 1263 dest[2] = G >> 22;
yading@11 1264 dest[3] = R >> 22;
yading@11 1265 break;
yading@11 1266 case AV_PIX_FMT_BGR24:
yading@11 1267 dest[0] = B >> 22;
yading@11 1268 dest[1] = G >> 22;
yading@11 1269 dest[2] = R >> 22;
yading@11 1270 break;
yading@11 1271 case AV_PIX_FMT_BGRA:
yading@11 1272 dest[0] = B >> 22;
yading@11 1273 dest[1] = G >> 22;
yading@11 1274 dest[2] = R >> 22;
yading@11 1275 dest[3] = hasAlpha ? A : 255;
yading@11 1276 break;
yading@11 1277 case AV_PIX_FMT_BGR4_BYTE:
yading@11 1278 case AV_PIX_FMT_RGB4_BYTE:
yading@11 1279 case AV_PIX_FMT_BGR8:
yading@11 1280 case AV_PIX_FMT_RGB8:
yading@11 1281 {
yading@11 1282 int r,g,b;
yading@11 1283 R >>= 22;
yading@11 1284 G >>= 22;
yading@11 1285 B >>= 22;
yading@11 1286 R += (7*err[0] + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2])>>4;
yading@11 1287 G += (7*err[1] + 1*c->dither_error[1][i] + 5*c->dither_error[1][i+1] + 3*c->dither_error[1][i+2])>>4;
yading@11 1288 B += (7*err[2] + 1*c->dither_error[2][i] + 5*c->dither_error[2][i+1] + 3*c->dither_error[2][i+2])>>4;
yading@11 1289 c->dither_error[0][i] = err[0];
yading@11 1290 c->dither_error[1][i] = err[1];
yading@11 1291 c->dither_error[2][i] = err[2];
yading@11 1292 r = R >> (isrgb8 ? 5 : 7);
yading@11 1293 g = G >> (isrgb8 ? 5 : 6);
yading@11 1294 b = B >> (isrgb8 ? 6 : 7);
yading@11 1295 r = av_clip(r, 0, isrgb8 ? 7 : 1);
yading@11 1296 g = av_clip(g, 0, isrgb8 ? 7 : 3);
yading@11 1297 b = av_clip(b, 0, isrgb8 ? 3 : 1);
yading@11 1298 err[0] = R - r*(isrgb8 ? 36 : 255);
yading@11 1299 err[1] = G - g*(isrgb8 ? 36 : 85);
yading@11 1300 err[2] = B - b*(isrgb8 ? 85 : 255);
yading@11 1301 if(target == AV_PIX_FMT_BGR4_BYTE) {
yading@11 1302 dest[0] = r + 2*g + 8*b;
yading@11 1303 } else if(target == AV_PIX_FMT_RGB4_BYTE) {
yading@11 1304 dest[0] = b + 2*g + 8*r;
yading@11 1305 } else if(target == AV_PIX_FMT_BGR8) {
yading@11 1306 dest[0] = r + 8*g + 64*b;
yading@11 1307 } else if(target == AV_PIX_FMT_RGB8) {
yading@11 1308 dest[0] = b + 4*g + 32*r;
yading@11 1309 } else
yading@11 1310 av_assert2(0);
yading@11 1311 break;}
yading@11 1312 }
yading@11 1313 }
yading@11 1314
yading@11 1315 static av_always_inline void
yading@11 1316 yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
yading@11 1317 const int16_t **lumSrc, int lumFilterSize,
yading@11 1318 const int16_t *chrFilter, const int16_t **chrUSrc,
yading@11 1319 const int16_t **chrVSrc, int chrFilterSize,
yading@11 1320 const int16_t **alpSrc, uint8_t *dest,
yading@11 1321 int dstW, int y, enum AVPixelFormat target, int hasAlpha)
yading@11 1322 {
yading@11 1323 int i;
yading@11 1324 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
yading@11 1325 int err[4] = {0};
yading@11 1326
yading@11 1327 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
yading@11 1328 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
yading@11 1329 step = 1;
yading@11 1330
yading@11 1331 for (i = 0; i < dstW; i++) {
yading@11 1332 int j;
yading@11 1333 int Y = 1<<9;
yading@11 1334 int U = (1<<9)-(128 << 19);
yading@11 1335 int V = (1<<9)-(128 << 19);
yading@11 1336 int A;
yading@11 1337
yading@11 1338 for (j = 0; j < lumFilterSize; j++) {
yading@11 1339 Y += lumSrc[j][i] * lumFilter[j];
yading@11 1340 }
yading@11 1341 for (j = 0; j < chrFilterSize; j++) {
yading@11 1342 U += chrUSrc[j][i] * chrFilter[j];
yading@11 1343 V += chrVSrc[j][i] * chrFilter[j];
yading@11 1344 }
yading@11 1345 Y >>= 10;
yading@11 1346 U >>= 10;
yading@11 1347 V >>= 10;
yading@11 1348 if (hasAlpha) {
yading@11 1349 A = 1 << 18;
yading@11 1350 for (j = 0; j < lumFilterSize; j++) {
yading@11 1351 A += alpSrc[j][i] * lumFilter[j];
yading@11 1352 }
yading@11 1353 A >>= 19;
yading@11 1354 if (A & 0x100)
yading@11 1355 A = av_clip_uint8(A);
yading@11 1356 }
yading@11 1357 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
yading@11 1358 dest += step;
yading@11 1359 }
yading@11 1360 c->dither_error[0][i] = err[0];
yading@11 1361 c->dither_error[1][i] = err[1];
yading@11 1362 c->dither_error[2][i] = err[2];
yading@11 1363 }
yading@11 1364
yading@11 1365 static av_always_inline void
yading@11 1366 yuv2rgb_full_2_c_template(SwsContext *c, const int16_t *buf[2],
yading@11 1367 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 1368 const int16_t *abuf[2], uint8_t *dest, int dstW,
yading@11 1369 int yalpha, int uvalpha, int y,
yading@11 1370 enum AVPixelFormat target, int hasAlpha)
yading@11 1371 {
yading@11 1372 const int16_t *buf0 = buf[0], *buf1 = buf[1],
yading@11 1373 *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
yading@11 1374 *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],
yading@11 1375 *abuf0 = hasAlpha ? abuf[0] : NULL,
yading@11 1376 *abuf1 = hasAlpha ? abuf[1] : NULL;
yading@11 1377 int yalpha1 = 4096 - yalpha;
yading@11 1378 int uvalpha1 = 4096 - uvalpha;
yading@11 1379 int i;
yading@11 1380 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
yading@11 1381 int err[4] = {0};
yading@11 1382
yading@11 1383 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
yading@11 1384 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
yading@11 1385 step = 1;
yading@11 1386
yading@11 1387 for (i = 0; i < dstW; i++) {
yading@11 1388 int Y = ( buf0[i] * yalpha1 + buf1[i] * yalpha ) >> 10; //FIXME rounding
yading@11 1389 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha-(128 << 19)) >> 10;
yading@11 1390 int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha-(128 << 19)) >> 10;
yading@11 1391 int A;
yading@11 1392
yading@11 1393 if (hasAlpha) {
yading@11 1394 A = (abuf0[i] * yalpha1 + abuf1[i] * yalpha + (1<<18)) >> 19;
yading@11 1395 if (A & 0x100)
yading@11 1396 A = av_clip_uint8(A);
yading@11 1397 }
yading@11 1398
yading@11 1399 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
yading@11 1400 dest += step;
yading@11 1401 }
yading@11 1402 c->dither_error[0][i] = err[0];
yading@11 1403 c->dither_error[1][i] = err[1];
yading@11 1404 c->dither_error[2][i] = err[2];
yading@11 1405 }
yading@11 1406
yading@11 1407 static av_always_inline void
yading@11 1408 yuv2rgb_full_1_c_template(SwsContext *c, const int16_t *buf0,
yading@11 1409 const int16_t *ubuf[2], const int16_t *vbuf[2],
yading@11 1410 const int16_t *abuf0, uint8_t *dest, int dstW,
yading@11 1411 int uvalpha, int y, enum AVPixelFormat target,
yading@11 1412 int hasAlpha)
yading@11 1413 {
yading@11 1414 const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];
yading@11 1415 int i;
yading@11 1416 int step = (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) ? 3 : 4;
yading@11 1417 int err[4] = {0};
yading@11 1418
yading@11 1419 if( target == AV_PIX_FMT_BGR4_BYTE || target == AV_PIX_FMT_RGB4_BYTE
yading@11 1420 || target == AV_PIX_FMT_BGR8 || target == AV_PIX_FMT_RGB8)
yading@11 1421 step = 1;
yading@11 1422
yading@11 1423 if (uvalpha < 2048) {
yading@11 1424 for (i = 0; i < dstW; i++) {
yading@11 1425 int Y = buf0[i] << 2;
yading@11 1426 int U = (ubuf0[i] - (128<<7)) << 2;
yading@11 1427 int V = (vbuf0[i] - (128<<7)) << 2;
yading@11 1428 int A;
yading@11 1429
yading@11 1430 if (hasAlpha) {
yading@11 1431 A = (abuf0[i] + 64) >> 7;
yading@11 1432 if (A & 0x100)
yading@11 1433 A = av_clip_uint8(A);
yading@11 1434 }
yading@11 1435
yading@11 1436 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
yading@11 1437 dest += step;
yading@11 1438 }
yading@11 1439 } else {
yading@11 1440 const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
yading@11 1441 for (i = 0; i < dstW; i++) {
yading@11 1442 int Y = buf0[i] << 2;
yading@11 1443 int U = (ubuf0[i] + ubuf1[i] - (128<<8)) << 1;
yading@11 1444 int V = (vbuf0[i] + vbuf1[i] - (128<<8)) << 1;
yading@11 1445 int A;
yading@11 1446
yading@11 1447 if (hasAlpha) {
yading@11 1448 A = (abuf0[i] + 64) >> 7;
yading@11 1449 if (A & 0x100)
yading@11 1450 A = av_clip_uint8(A);
yading@11 1451 }
yading@11 1452
yading@11 1453 yuv2rgb_write_full(c, dest, i, Y, A, U, V, y, target, hasAlpha, err);
yading@11 1454 dest += step;
yading@11 1455 }
yading@11 1456 }
yading@11 1457
yading@11 1458 c->dither_error[0][i] = err[0];
yading@11 1459 c->dither_error[1][i] = err[1];
yading@11 1460 c->dither_error[2][i] = err[2];
yading@11 1461 }
yading@11 1462
yading@11 1463 #if CONFIG_SMALL
yading@11 1464 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
yading@11 1465 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
yading@11 1466 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
yading@11 1467 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
yading@11 1468 #else
yading@11 1469 #if CONFIG_SWSCALE_ALPHA
yading@11 1470 YUV2RGBWRAPPER(yuv2, rgb_full, bgra32_full, AV_PIX_FMT_BGRA, 1)
yading@11 1471 YUV2RGBWRAPPER(yuv2, rgb_full, abgr32_full, AV_PIX_FMT_ABGR, 1)
yading@11 1472 YUV2RGBWRAPPER(yuv2, rgb_full, rgba32_full, AV_PIX_FMT_RGBA, 1)
yading@11 1473 YUV2RGBWRAPPER(yuv2, rgb_full, argb32_full, AV_PIX_FMT_ARGB, 1)
yading@11 1474 #endif
yading@11 1475 YUV2RGBWRAPPER(yuv2, rgb_full, bgrx32_full, AV_PIX_FMT_BGRA, 0)
yading@11 1476 YUV2RGBWRAPPER(yuv2, rgb_full, xbgr32_full, AV_PIX_FMT_ABGR, 0)
yading@11 1477 YUV2RGBWRAPPER(yuv2, rgb_full, rgbx32_full, AV_PIX_FMT_RGBA, 0)
yading@11 1478 YUV2RGBWRAPPER(yuv2, rgb_full, xrgb32_full, AV_PIX_FMT_ARGB, 0)
yading@11 1479 #endif
yading@11 1480 YUV2RGBWRAPPER(yuv2, rgb_full, bgr24_full, AV_PIX_FMT_BGR24, 0)
yading@11 1481 YUV2RGBWRAPPER(yuv2, rgb_full, rgb24_full, AV_PIX_FMT_RGB24, 0)
yading@11 1482
yading@11 1483 YUV2RGBWRAPPER(yuv2, rgb_full, bgr4_byte_full, AV_PIX_FMT_BGR4_BYTE, 0)
yading@11 1484 YUV2RGBWRAPPER(yuv2, rgb_full, rgb4_byte_full, AV_PIX_FMT_RGB4_BYTE, 0)
yading@11 1485 YUV2RGBWRAPPER(yuv2, rgb_full, bgr8_full, AV_PIX_FMT_BGR8, 0)
yading@11 1486 YUV2RGBWRAPPER(yuv2, rgb_full, rgb8_full, AV_PIX_FMT_RGB8, 0)
yading@11 1487
yading@11 1488 static void
yading@11 1489 yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
yading@11 1490 const int16_t **lumSrc, int lumFilterSize,
yading@11 1491 const int16_t *chrFilter, const int16_t **chrUSrc,
yading@11 1492 const int16_t **chrVSrc, int chrFilterSize,
yading@11 1493 const int16_t **alpSrc, uint8_t **dest,
yading@11 1494 int dstW, int y)
yading@11 1495 {
yading@11 1496 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
yading@11 1497 int i;
yading@11 1498 int hasAlpha = 0;
yading@11 1499 uint16_t **dest16 = (uint16_t**)dest;
yading@11 1500 int SH = 22 + 7 - desc->comp[0].depth_minus1;
yading@11 1501
yading@11 1502 for (i = 0; i < dstW; i++) {
yading@11 1503 int j;
yading@11 1504 int Y = 1 << 9;
yading@11 1505 int U = (1 << 9) - (128 << 19);
yading@11 1506 int V = (1 << 9) - (128 << 19);
yading@11 1507 int R, G, B, A;
yading@11 1508
yading@11 1509 for (j = 0; j < lumFilterSize; j++)
yading@11 1510 Y += lumSrc[j][i] * lumFilter[j];
yading@11 1511
yading@11 1512 for (j = 0; j < chrFilterSize; j++) {
yading@11 1513 U += chrUSrc[j][i] * chrFilter[j];
yading@11 1514 V += chrVSrc[j][i] * chrFilter[j];
yading@11 1515 }
yading@11 1516
yading@11 1517 Y >>= 10;
yading@11 1518 U >>= 10;
yading@11 1519 V >>= 10;
yading@11 1520
yading@11 1521 if (hasAlpha) {
yading@11 1522 A = 1 << 18;
yading@11 1523
yading@11 1524 for (j = 0; j < lumFilterSize; j++)
yading@11 1525 A += alpSrc[j][i] * lumFilter[j];
yading@11 1526
yading@11 1527 A >>= 19;
yading@11 1528
yading@11 1529 if (A & 0x100)
yading@11 1530 A = av_clip_uint8(A);
yading@11 1531 }
yading@11 1532
yading@11 1533 Y -= c->yuv2rgb_y_offset;
yading@11 1534 Y *= c->yuv2rgb_y_coeff;
yading@11 1535 Y += 1 << 21;
yading@11 1536 R = Y + V * c->yuv2rgb_v2r_coeff;
yading@11 1537 G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
yading@11 1538 B = Y + U * c->yuv2rgb_u2b_coeff;
yading@11 1539
yading@11 1540 if ((R | G | B) & 0xC0000000) {
yading@11 1541 R = av_clip_uintp2(R, 30);
yading@11 1542 G = av_clip_uintp2(G, 30);
yading@11 1543 B = av_clip_uintp2(B, 30);
yading@11 1544 }
yading@11 1545
yading@11 1546 if (SH != 22) {
yading@11 1547 dest16[0][i] = G >> SH;
yading@11 1548 dest16[1][i] = B >> SH;
yading@11 1549 dest16[2][i] = R >> SH;
yading@11 1550 } else {
yading@11 1551 dest[0][i] = G >> 22;
yading@11 1552 dest[1][i] = B >> 22;
yading@11 1553 dest[2][i] = R >> 22;
yading@11 1554 }
yading@11 1555 }
yading@11 1556 if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
yading@11 1557 for (i = 0; i < dstW; i++) {
yading@11 1558 dest16[0][i] = av_bswap16(dest16[0][i]);
yading@11 1559 dest16[1][i] = av_bswap16(dest16[1][i]);
yading@11 1560 dest16[2][i] = av_bswap16(dest16[2][i]);
yading@11 1561 }
yading@11 1562 }
yading@11 1563 }
yading@11 1564
yading@11 1565 av_cold void ff_sws_init_output_funcs(SwsContext *c,
yading@11 1566 yuv2planar1_fn *yuv2plane1,
yading@11 1567 yuv2planarX_fn *yuv2planeX,
yading@11 1568 yuv2interleavedX_fn *yuv2nv12cX,
yading@11 1569 yuv2packed1_fn *yuv2packed1,
yading@11 1570 yuv2packed2_fn *yuv2packed2,
yading@11 1571 yuv2packedX_fn *yuv2packedX,
yading@11 1572 yuv2anyX_fn *yuv2anyX)
yading@11 1573 {
yading@11 1574 enum AVPixelFormat dstFormat = c->dstFormat;
yading@11 1575 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
yading@11 1576
yading@11 1577 if (is16BPS(dstFormat)) {
yading@11 1578 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c;
yading@11 1579 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c;
yading@11 1580 } else if (is9_OR_10BPS(dstFormat)) {
yading@11 1581 if (desc->comp[0].depth_minus1 == 8) {
yading@11 1582 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c;
yading@11 1583 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c;
yading@11 1584 } else if (desc->comp[0].depth_minus1 == 9) {
yading@11 1585 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c;
yading@11 1586 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c;
yading@11 1587 } else if (desc->comp[0].depth_minus1 == 11) {
yading@11 1588 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_12BE_c : yuv2planeX_12LE_c;
yading@11 1589 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_12BE_c : yuv2plane1_12LE_c;
yading@11 1590 } else if (desc->comp[0].depth_minus1 == 13) {
yading@11 1591 *yuv2planeX = isBE(dstFormat) ? yuv2planeX_14BE_c : yuv2planeX_14LE_c;
yading@11 1592 *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_14BE_c : yuv2plane1_14LE_c;
yading@11 1593 } else
yading@11 1594 av_assert0(0);
yading@11 1595 } else {
yading@11 1596 *yuv2plane1 = yuv2plane1_8_c;
yading@11 1597 *yuv2planeX = yuv2planeX_8_c;
yading@11 1598 if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)
yading@11 1599 *yuv2nv12cX = yuv2nv12cX_c;
yading@11 1600 }
yading@11 1601
yading@11 1602 if(c->flags & SWS_FULL_CHR_H_INT) {
yading@11 1603 switch (dstFormat) {
yading@11 1604 case AV_PIX_FMT_RGBA:
yading@11 1605 #if CONFIG_SMALL
yading@11 1606 *yuv2packedX = yuv2rgba32_full_X_c;
yading@11 1607 *yuv2packed2 = yuv2rgba32_full_2_c;
yading@11 1608 *yuv2packed1 = yuv2rgba32_full_1_c;
yading@11 1609 #else
yading@11 1610 #if CONFIG_SWSCALE_ALPHA
yading@11 1611 if (c->alpPixBuf) {
yading@11 1612 *yuv2packedX = yuv2rgba32_full_X_c;
yading@11 1613 *yuv2packed2 = yuv2rgba32_full_2_c;
yading@11 1614 *yuv2packed1 = yuv2rgba32_full_1_c;
yading@11 1615 } else
yading@11 1616 #endif /* CONFIG_SWSCALE_ALPHA */
yading@11 1617 {
yading@11 1618 *yuv2packedX = yuv2rgbx32_full_X_c;
yading@11 1619 *yuv2packed2 = yuv2rgbx32_full_2_c;
yading@11 1620 *yuv2packed1 = yuv2rgbx32_full_1_c;
yading@11 1621 }
yading@11 1622 #endif /* !CONFIG_SMALL */
yading@11 1623 break;
yading@11 1624 case AV_PIX_FMT_ARGB:
yading@11 1625 #if CONFIG_SMALL
yading@11 1626 *yuv2packedX = yuv2argb32_full_X_c;
yading@11 1627 *yuv2packed2 = yuv2argb32_full_2_c;
yading@11 1628 *yuv2packed1 = yuv2argb32_full_1_c;
yading@11 1629 #else
yading@11 1630 #if CONFIG_SWSCALE_ALPHA
yading@11 1631 if (c->alpPixBuf) {
yading@11 1632 *yuv2packedX = yuv2argb32_full_X_c;
yading@11 1633 *yuv2packed2 = yuv2argb32_full_2_c;
yading@11 1634 *yuv2packed1 = yuv2argb32_full_1_c;
yading@11 1635 } else
yading@11 1636 #endif /* CONFIG_SWSCALE_ALPHA */
yading@11 1637 {
yading@11 1638 *yuv2packedX = yuv2xrgb32_full_X_c;
yading@11 1639 *yuv2packed2 = yuv2xrgb32_full_2_c;
yading@11 1640 *yuv2packed1 = yuv2xrgb32_full_1_c;
yading@11 1641 }
yading@11 1642 #endif /* !CONFIG_SMALL */
yading@11 1643 break;
yading@11 1644 case AV_PIX_FMT_BGRA:
yading@11 1645 #if CONFIG_SMALL
yading@11 1646 *yuv2packedX = yuv2bgra32_full_X_c;
yading@11 1647 *yuv2packed2 = yuv2bgra32_full_2_c;
yading@11 1648 *yuv2packed1 = yuv2bgra32_full_1_c;
yading@11 1649 #else
yading@11 1650 #if CONFIG_SWSCALE_ALPHA
yading@11 1651 if (c->alpPixBuf) {
yading@11 1652 *yuv2packedX = yuv2bgra32_full_X_c;
yading@11 1653 *yuv2packed2 = yuv2bgra32_full_2_c;
yading@11 1654 *yuv2packed1 = yuv2bgra32_full_1_c;
yading@11 1655 } else
yading@11 1656 #endif /* CONFIG_SWSCALE_ALPHA */
yading@11 1657 {
yading@11 1658 *yuv2packedX = yuv2bgrx32_full_X_c;
yading@11 1659 *yuv2packed2 = yuv2bgrx32_full_2_c;
yading@11 1660 *yuv2packed1 = yuv2bgrx32_full_1_c;
yading@11 1661 }
yading@11 1662 #endif /* !CONFIG_SMALL */
yading@11 1663 break;
yading@11 1664 case AV_PIX_FMT_ABGR:
yading@11 1665 #if CONFIG_SMALL
yading@11 1666 *yuv2packedX = yuv2abgr32_full_X_c;
yading@11 1667 *yuv2packed2 = yuv2abgr32_full_2_c;
yading@11 1668 *yuv2packed1 = yuv2abgr32_full_1_c;
yading@11 1669 #else
yading@11 1670 #if CONFIG_SWSCALE_ALPHA
yading@11 1671 if (c->alpPixBuf) {
yading@11 1672 *yuv2packedX = yuv2abgr32_full_X_c;
yading@11 1673 *yuv2packed2 = yuv2abgr32_full_2_c;
yading@11 1674 *yuv2packed1 = yuv2abgr32_full_1_c;
yading@11 1675 } else
yading@11 1676 #endif /* CONFIG_SWSCALE_ALPHA */
yading@11 1677 {
yading@11 1678 *yuv2packedX = yuv2xbgr32_full_X_c;
yading@11 1679 *yuv2packed2 = yuv2xbgr32_full_2_c;
yading@11 1680 *yuv2packed1 = yuv2xbgr32_full_1_c;
yading@11 1681 }
yading@11 1682 #endif /* !CONFIG_SMALL */
yading@11 1683 break;
yading@11 1684 case AV_PIX_FMT_RGB24:
yading@11 1685 *yuv2packedX = yuv2rgb24_full_X_c;
yading@11 1686 *yuv2packed2 = yuv2rgb24_full_2_c;
yading@11 1687 *yuv2packed1 = yuv2rgb24_full_1_c;
yading@11 1688 break;
yading@11 1689 case AV_PIX_FMT_BGR24:
yading@11 1690 *yuv2packedX = yuv2bgr24_full_X_c;
yading@11 1691 *yuv2packed2 = yuv2bgr24_full_2_c;
yading@11 1692 *yuv2packed1 = yuv2bgr24_full_1_c;
yading@11 1693 break;
yading@11 1694 case AV_PIX_FMT_BGR4_BYTE:
yading@11 1695 *yuv2packedX = yuv2bgr4_byte_full_X_c;
yading@11 1696 *yuv2packed2 = yuv2bgr4_byte_full_2_c;
yading@11 1697 *yuv2packed1 = yuv2bgr4_byte_full_1_c;
yading@11 1698 break;
yading@11 1699 case AV_PIX_FMT_RGB4_BYTE:
yading@11 1700 *yuv2packedX = yuv2rgb4_byte_full_X_c;
yading@11 1701 *yuv2packed2 = yuv2rgb4_byte_full_2_c;
yading@11 1702 *yuv2packed1 = yuv2rgb4_byte_full_1_c;
yading@11 1703 break;
yading@11 1704 case AV_PIX_FMT_BGR8:
yading@11 1705 *yuv2packedX = yuv2bgr8_full_X_c;
yading@11 1706 *yuv2packed2 = yuv2bgr8_full_2_c;
yading@11 1707 *yuv2packed1 = yuv2bgr8_full_1_c;
yading@11 1708 break;
yading@11 1709 case AV_PIX_FMT_RGB8:
yading@11 1710 *yuv2packedX = yuv2rgb8_full_X_c;
yading@11 1711 *yuv2packed2 = yuv2rgb8_full_2_c;
yading@11 1712 *yuv2packed1 = yuv2rgb8_full_1_c;
yading@11 1713 break;
yading@11 1714 case AV_PIX_FMT_GBRP:
yading@11 1715 case AV_PIX_FMT_GBRP9BE:
yading@11 1716 case AV_PIX_FMT_GBRP9LE:
yading@11 1717 case AV_PIX_FMT_GBRP10BE:
yading@11 1718 case AV_PIX_FMT_GBRP10LE:
yading@11 1719 case AV_PIX_FMT_GBRP12BE:
yading@11 1720 case AV_PIX_FMT_GBRP12LE:
yading@11 1721 case AV_PIX_FMT_GBRP14BE:
yading@11 1722 case AV_PIX_FMT_GBRP14LE:
yading@11 1723 case AV_PIX_FMT_GBRP16BE:
yading@11 1724 case AV_PIX_FMT_GBRP16LE:
yading@11 1725 *yuv2anyX = yuv2gbrp_full_X_c;
yading@11 1726 break;
yading@11 1727 }
yading@11 1728 if (!*yuv2packedX && !*yuv2anyX)
yading@11 1729 goto YUV_PACKED;
yading@11 1730 } else {
yading@11 1731 YUV_PACKED:
yading@11 1732 switch (dstFormat) {
yading@11 1733 case AV_PIX_FMT_RGB48LE:
yading@11 1734 *yuv2packed1 = yuv2rgb48le_1_c;
yading@11 1735 *yuv2packed2 = yuv2rgb48le_2_c;
yading@11 1736 *yuv2packedX = yuv2rgb48le_X_c;
yading@11 1737 break;
yading@11 1738 case AV_PIX_FMT_RGB48BE:
yading@11 1739 *yuv2packed1 = yuv2rgb48be_1_c;
yading@11 1740 *yuv2packed2 = yuv2rgb48be_2_c;
yading@11 1741 *yuv2packedX = yuv2rgb48be_X_c;
yading@11 1742 break;
yading@11 1743 case AV_PIX_FMT_BGR48LE:
yading@11 1744 *yuv2packed1 = yuv2bgr48le_1_c;
yading@11 1745 *yuv2packed2 = yuv2bgr48le_2_c;
yading@11 1746 *yuv2packedX = yuv2bgr48le_X_c;
yading@11 1747 break;
yading@11 1748 case AV_PIX_FMT_BGR48BE:
yading@11 1749 *yuv2packed1 = yuv2bgr48be_1_c;
yading@11 1750 *yuv2packed2 = yuv2bgr48be_2_c;
yading@11 1751 *yuv2packedX = yuv2bgr48be_X_c;
yading@11 1752 break;
yading@11 1753 case AV_PIX_FMT_RGB32:
yading@11 1754 case AV_PIX_FMT_BGR32:
yading@11 1755 #if CONFIG_SMALL
yading@11 1756 *yuv2packed1 = yuv2rgb32_1_c;
yading@11 1757 *yuv2packed2 = yuv2rgb32_2_c;
yading@11 1758 *yuv2packedX = yuv2rgb32_X_c;
yading@11 1759 #else
yading@11 1760 #if CONFIG_SWSCALE_ALPHA
yading@11 1761 if (c->alpPixBuf) {
yading@11 1762 *yuv2packed1 = yuv2rgba32_1_c;
yading@11 1763 *yuv2packed2 = yuv2rgba32_2_c;
yading@11 1764 *yuv2packedX = yuv2rgba32_X_c;
yading@11 1765 } else
yading@11 1766 #endif /* CONFIG_SWSCALE_ALPHA */
yading@11 1767 {
yading@11 1768 *yuv2packed1 = yuv2rgbx32_1_c;
yading@11 1769 *yuv2packed2 = yuv2rgbx32_2_c;
yading@11 1770 *yuv2packedX = yuv2rgbx32_X_c;
yading@11 1771 }
yading@11 1772 #endif /* !CONFIG_SMALL */
yading@11 1773 break;
yading@11 1774 case AV_PIX_FMT_RGB32_1:
yading@11 1775 case AV_PIX_FMT_BGR32_1:
yading@11 1776 #if CONFIG_SMALL
yading@11 1777 *yuv2packed1 = yuv2rgb32_1_1_c;
yading@11 1778 *yuv2packed2 = yuv2rgb32_1_2_c;
yading@11 1779 *yuv2packedX = yuv2rgb32_1_X_c;
yading@11 1780 #else
yading@11 1781 #if CONFIG_SWSCALE_ALPHA
yading@11 1782 if (c->alpPixBuf) {
yading@11 1783 *yuv2packed1 = yuv2rgba32_1_1_c;
yading@11 1784 *yuv2packed2 = yuv2rgba32_1_2_c;
yading@11 1785 *yuv2packedX = yuv2rgba32_1_X_c;
yading@11 1786 } else
yading@11 1787 #endif /* CONFIG_SWSCALE_ALPHA */
yading@11 1788 {
yading@11 1789 *yuv2packed1 = yuv2rgbx32_1_1_c;
yading@11 1790 *yuv2packed2 = yuv2rgbx32_1_2_c;
yading@11 1791 *yuv2packedX = yuv2rgbx32_1_X_c;
yading@11 1792 }
yading@11 1793 #endif /* !CONFIG_SMALL */
yading@11 1794 break;
yading@11 1795 case AV_PIX_FMT_RGB24:
yading@11 1796 *yuv2packed1 = yuv2rgb24_1_c;
yading@11 1797 *yuv2packed2 = yuv2rgb24_2_c;
yading@11 1798 *yuv2packedX = yuv2rgb24_X_c;
yading@11 1799 break;
yading@11 1800 case AV_PIX_FMT_BGR24:
yading@11 1801 *yuv2packed1 = yuv2bgr24_1_c;
yading@11 1802 *yuv2packed2 = yuv2bgr24_2_c;
yading@11 1803 *yuv2packedX = yuv2bgr24_X_c;
yading@11 1804 break;
yading@11 1805 case AV_PIX_FMT_RGB565LE:
yading@11 1806 case AV_PIX_FMT_RGB565BE:
yading@11 1807 case AV_PIX_FMT_BGR565LE:
yading@11 1808 case AV_PIX_FMT_BGR565BE:
yading@11 1809 *yuv2packed1 = yuv2rgb16_1_c;
yading@11 1810 *yuv2packed2 = yuv2rgb16_2_c;
yading@11 1811 *yuv2packedX = yuv2rgb16_X_c;
yading@11 1812 break;
yading@11 1813 case AV_PIX_FMT_RGB555LE:
yading@11 1814 case AV_PIX_FMT_RGB555BE:
yading@11 1815 case AV_PIX_FMT_BGR555LE:
yading@11 1816 case AV_PIX_FMT_BGR555BE:
yading@11 1817 *yuv2packed1 = yuv2rgb15_1_c;
yading@11 1818 *yuv2packed2 = yuv2rgb15_2_c;
yading@11 1819 *yuv2packedX = yuv2rgb15_X_c;
yading@11 1820 break;
yading@11 1821 case AV_PIX_FMT_RGB444LE:
yading@11 1822 case AV_PIX_FMT_RGB444BE:
yading@11 1823 case AV_PIX_FMT_BGR444LE:
yading@11 1824 case AV_PIX_FMT_BGR444BE:
yading@11 1825 *yuv2packed1 = yuv2rgb12_1_c;
yading@11 1826 *yuv2packed2 = yuv2rgb12_2_c;
yading@11 1827 *yuv2packedX = yuv2rgb12_X_c;
yading@11 1828 break;
yading@11 1829 case AV_PIX_FMT_RGB8:
yading@11 1830 case AV_PIX_FMT_BGR8:
yading@11 1831 *yuv2packed1 = yuv2rgb8_1_c;
yading@11 1832 *yuv2packed2 = yuv2rgb8_2_c;
yading@11 1833 *yuv2packedX = yuv2rgb8_X_c;
yading@11 1834 break;
yading@11 1835 case AV_PIX_FMT_RGB4:
yading@11 1836 case AV_PIX_FMT_BGR4:
yading@11 1837 *yuv2packed1 = yuv2rgb4_1_c;
yading@11 1838 *yuv2packed2 = yuv2rgb4_2_c;
yading@11 1839 *yuv2packedX = yuv2rgb4_X_c;
yading@11 1840 break;
yading@11 1841 case AV_PIX_FMT_RGB4_BYTE:
yading@11 1842 case AV_PIX_FMT_BGR4_BYTE:
yading@11 1843 *yuv2packed1 = yuv2rgb4b_1_c;
yading@11 1844 *yuv2packed2 = yuv2rgb4b_2_c;
yading@11 1845 *yuv2packedX = yuv2rgb4b_X_c;
yading@11 1846 break;
yading@11 1847 }
yading@11 1848 }
yading@11 1849 switch (dstFormat) {
yading@11 1850 case AV_PIX_FMT_MONOWHITE:
yading@11 1851 *yuv2packed1 = yuv2monowhite_1_c;
yading@11 1852 *yuv2packed2 = yuv2monowhite_2_c;
yading@11 1853 *yuv2packedX = yuv2monowhite_X_c;
yading@11 1854 break;
yading@11 1855 case AV_PIX_FMT_MONOBLACK:
yading@11 1856 *yuv2packed1 = yuv2monoblack_1_c;
yading@11 1857 *yuv2packed2 = yuv2monoblack_2_c;
yading@11 1858 *yuv2packedX = yuv2monoblack_X_c;
yading@11 1859 break;
yading@11 1860 case AV_PIX_FMT_YUYV422:
yading@11 1861 *yuv2packed1 = yuv2yuyv422_1_c;
yading@11 1862 *yuv2packed2 = yuv2yuyv422_2_c;
yading@11 1863 *yuv2packedX = yuv2yuyv422_X_c;
yading@11 1864 break;
yading@11 1865 case AV_PIX_FMT_UYVY422:
yading@11 1866 *yuv2packed1 = yuv2uyvy422_1_c;
yading@11 1867 *yuv2packed2 = yuv2uyvy422_2_c;
yading@11 1868 *yuv2packedX = yuv2uyvy422_X_c;
yading@11 1869 break;
yading@11 1870 }
yading@11 1871 }