00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SWSCALE_SWSCALE_INTERNAL_H
00022 #define SWSCALE_SWSCALE_INTERNAL_H
00023
00024 #include "config.h"
00025
00026 #if HAVE_ALTIVEC_H
00027 #include <altivec.h>
00028 #endif
00029
00030 #include "libavutil/avutil.h"
00031
00032 #define STR(s) AV_TOSTRING(s) //AV_STRINGIFY is too long
00033
00034 #define FAST_BGR2YV12 //use 7-bit instead of 15-bit coefficients
00035
00036 #define MAX_FILTER_SIZE 256
00037
00038 #define DITHER1XBPP
00039
00040 #if HAVE_BIGENDIAN
00041 #define ALT32_CORR (-1)
00042 #else
00043 #define ALT32_CORR 1
00044 #endif
00045
00046 #if ARCH_X86_64
00047 # define APCK_PTR2 8
00048 # define APCK_COEF 16
00049 # define APCK_SIZE 24
00050 #else
00051 # define APCK_PTR2 4
00052 # define APCK_COEF 8
00053 # define APCK_SIZE 16
00054 #endif
00055
00056 struct SwsContext;
00057
00058 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[],
00059 int srcStride[], int srcSliceY, int srcSliceH,
00060 uint8_t* dst[], int dstStride[]);
00061
00062 typedef void (*yuv2planar1_fn) (struct SwsContext *c,
00063 const int16_t *lumSrc, const int16_t *chrUSrc,
00064 const int16_t *chrVSrc, const int16_t *alpSrc,
00065 uint8_t *dest,
00066 uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
00067 int dstW, int chrDstW, const uint8_t *lumDither, const uint8_t *chrDither);
00068 typedef void (*yuv2planarX_fn) (struct SwsContext *c,
00069 const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
00070 const int16_t *chrFilter, const int16_t **chrUSrc,
00071 const int16_t **chrVSrc, int chrFilterSize,
00072 const int16_t **alpSrc,
00073 uint8_t *dest,
00074 uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
00075 int dstW, int chrDstW, const uint8_t *lumDither, const uint8_t *chrDither);
00076 typedef void (*yuv2packed1_fn) (struct SwsContext *c,
00077 const uint16_t *buf0,
00078 const uint16_t *ubuf0, const uint16_t *ubuf1,
00079 const uint16_t *vbuf0, const uint16_t *vbuf1,
00080 const uint16_t *abuf0,
00081 uint8_t *dest,
00082 int dstW, int uvalpha, int dstFormat, int flags, int y);
00083 typedef void (*yuv2packed2_fn) (struct SwsContext *c,
00084 const uint16_t *buf0, const uint16_t *buf1,
00085 const uint16_t *ubuf0, const uint16_t *ubuf1,
00086 const uint16_t *vbuf0, const uint16_t *vbuf1,
00087 const uint16_t *abuf0, const uint16_t *abuf1,
00088 uint8_t *dest,
00089 int dstW, int yalpha, int uvalpha, int y);
00090 typedef void (*yuv2packedX_fn) (struct SwsContext *c,
00091 const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
00092 const int16_t *chrFilter, const int16_t **chrUSrc,
00093 const int16_t **chrVSrc, int chrFilterSize,
00094 const int16_t **alpSrc, uint8_t *dest,
00095 int dstW, int dstY);
00096
00097
00098 typedef struct SwsContext {
00102 const AVClass *av_class;
00103
00108 SwsFunc swScale;
00109 int srcW;
00110 int srcH;
00111 int dstH;
00112 int chrSrcW;
00113 int chrSrcH;
00114 int chrDstW;
00115 int chrDstH;
00116 int lumXInc, chrXInc;
00117 int lumYInc, chrYInc;
00118 enum PixelFormat dstFormat;
00119 enum PixelFormat srcFormat;
00120 int dstFormatBpp;
00121 int srcFormatBpp;
00122 int chrSrcHSubSample;
00123 int chrSrcVSubSample;
00124 int chrDstHSubSample;
00125 int chrDstVSubSample;
00126 int vChrDrop;
00127 int sliceDir;
00128 double param[2];
00129
00130 uint32_t pal_yuv[256];
00131 uint32_t pal_rgb[256];
00132
00143 int16_t **lumPixBuf;
00144 int16_t **chrUPixBuf;
00145 int16_t **chrVPixBuf;
00146 int16_t **alpPixBuf;
00147 int vLumBufSize;
00148 int vChrBufSize;
00149 int lastInLumBuf;
00150 int lastInChrBuf;
00151 int lumBufIndex;
00152 int chrBufIndex;
00153
00154
00155 uint8_t *formatConvBuffer;
00156
00171 int16_t *hLumFilter;
00172 int16_t *hChrFilter;
00173 int16_t *vLumFilter;
00174 int16_t *vChrFilter;
00175 int16_t *hLumFilterPos;
00176 int16_t *hChrFilterPos;
00177 int16_t *vLumFilterPos;
00178 int16_t *vChrFilterPos;
00179 int hLumFilterSize;
00180 int hChrFilterSize;
00181 int vLumFilterSize;
00182 int vChrFilterSize;
00183
00184
00185 int lumMmx2FilterCodeSize;
00186 int chrMmx2FilterCodeSize;
00187 uint8_t *lumMmx2FilterCode;
00188 uint8_t *chrMmx2FilterCode;
00189
00190 int canMMX2BeUsed;
00191
00192 int dstY;
00193 int flags;
00194 void * yuvTable;
00195 uint8_t * table_rV[256];
00196 uint8_t * table_gU[256];
00197 int table_gV[256];
00198 uint8_t * table_bU[256];
00199
00200
00201 int contrast, brightness, saturation;
00202 int srcColorspaceTable[4];
00203 int dstColorspaceTable[4];
00204 int srcRange;
00205 int dstRange;
00206 int yuv2rgb_y_offset;
00207 int yuv2rgb_y_coeff;
00208 int yuv2rgb_v2r_coeff;
00209 int yuv2rgb_v2g_coeff;
00210 int yuv2rgb_u2g_coeff;
00211 int yuv2rgb_u2b_coeff;
00212
00213 #define RED_DITHER "0*8"
00214 #define GREEN_DITHER "1*8"
00215 #define BLUE_DITHER "2*8"
00216 #define Y_COEFF "3*8"
00217 #define VR_COEFF "4*8"
00218 #define UB_COEFF "5*8"
00219 #define VG_COEFF "6*8"
00220 #define UG_COEFF "7*8"
00221 #define Y_OFFSET "8*8"
00222 #define U_OFFSET "9*8"
00223 #define V_OFFSET "10*8"
00224 #define LUM_MMX_FILTER_OFFSET "11*8"
00225 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
00226 #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
00227 #define ESP_OFFSET "11*8+4*4*256*2+8"
00228 #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
00229 #define U_TEMP "11*8+4*4*256*2+24"
00230 #define V_TEMP "11*8+4*4*256*2+32"
00231 #define Y_TEMP "11*8+4*4*256*2+40"
00232 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
00233 #define UV_OFF "11*8+4*4*256*3+48"
00234 #define UV_OFFx2 "11*8+4*4*256*3+56"
00235 #define DITHER16 "11*8+4*4*256*3+64"
00236 #define DITHER32 "11*8+4*4*256*3+64+16"
00237
00238 DECLARE_ALIGNED(8, uint64_t, redDither);
00239 DECLARE_ALIGNED(8, uint64_t, greenDither);
00240 DECLARE_ALIGNED(8, uint64_t, blueDither);
00241
00242 DECLARE_ALIGNED(8, uint64_t, yCoeff);
00243 DECLARE_ALIGNED(8, uint64_t, vrCoeff);
00244 DECLARE_ALIGNED(8, uint64_t, ubCoeff);
00245 DECLARE_ALIGNED(8, uint64_t, vgCoeff);
00246 DECLARE_ALIGNED(8, uint64_t, ugCoeff);
00247 DECLARE_ALIGNED(8, uint64_t, yOffset);
00248 DECLARE_ALIGNED(8, uint64_t, uOffset);
00249 DECLARE_ALIGNED(8, uint64_t, vOffset);
00250 int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
00251 int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
00252 int dstW;
00253 DECLARE_ALIGNED(8, uint64_t, esp);
00254 DECLARE_ALIGNED(8, uint64_t, vRounder);
00255 DECLARE_ALIGNED(8, uint64_t, u_temp);
00256 DECLARE_ALIGNED(8, uint64_t, v_temp);
00257 DECLARE_ALIGNED(8, uint64_t, y_temp);
00258 int32_t alpMmxFilter[4*MAX_FILTER_SIZE];
00259 DECLARE_ALIGNED(8, ptrdiff_t, uv_off);
00260 DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2);
00261 uint16_t dither16[8];
00262 uint32_t dither32[8];
00263
00264 #if HAVE_ALTIVEC
00265 vector signed short CY;
00266 vector signed short CRV;
00267 vector signed short CBU;
00268 vector signed short CGU;
00269 vector signed short CGV;
00270 vector signed short OY;
00271 vector unsigned short CSHIFT;
00272 vector signed short *vYCoeffsBank, *vCCoeffsBank;
00273 #endif
00274
00275 #if ARCH_BFIN
00276 DECLARE_ALIGNED(4, uint32_t, oy);
00277 DECLARE_ALIGNED(4, uint32_t, oc);
00278 DECLARE_ALIGNED(4, uint32_t, zero);
00279 DECLARE_ALIGNED(4, uint32_t, cy);
00280 DECLARE_ALIGNED(4, uint32_t, crv);
00281 DECLARE_ALIGNED(4, uint32_t, rmask);
00282 DECLARE_ALIGNED(4, uint32_t, cbu);
00283 DECLARE_ALIGNED(4, uint32_t, bmask);
00284 DECLARE_ALIGNED(4, uint32_t, cgu);
00285 DECLARE_ALIGNED(4, uint32_t, cgv);
00286 DECLARE_ALIGNED(4, uint32_t, gmask);
00287 #endif
00288
00289 #if HAVE_VIS
00290 DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
00291 #endif
00292
00293
00294 yuv2planar1_fn yuv2yuv1;
00295 yuv2planarX_fn yuv2yuvX;
00296 yuv2packed1_fn yuv2packed1;
00297 yuv2packed2_fn yuv2packed2;
00298 yuv2packedX_fn yuv2packedX;
00299
00300 void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
00301 int width, uint32_t *pal);
00302 void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
00303 int width, uint32_t *pal);
00304 void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
00305 const uint8_t *src1, const uint8_t *src2,
00306 int width, uint32_t *pal);
00307 void (*hyscale_fast)(struct SwsContext *c,
00308 int16_t *dst, int dstWidth,
00309 const uint8_t *src, int srcW, int xInc);
00310 void (*hcscale_fast)(struct SwsContext *c,
00311 int16_t *dst1, int16_t *dst2, int dstWidth,
00312 const uint8_t *src1, const uint8_t *src2,
00313 int srcW, int xInc);
00314
00315 void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW,
00316 int xInc, const int16_t *filter, const int16_t *filterPos,
00317 int filterSize);
00318
00319 void (*hScale16)(int16_t *dst, int dstW, const uint16_t *src, int srcW,
00320 int xInc, const int16_t *filter, const int16_t *filterPos,
00321 long filterSize, int shift);
00322
00323 void (*lumConvertRange)(int16_t *dst, int width);
00324 void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
00325
00326 int needs_hcscale;
00327
00328 } SwsContext;
00329
00330
00331 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
00332 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
00333 int fullRange, int brightness,
00334 int contrast, int saturation);
00335
00336 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
00337 int brightness, int contrast, int saturation);
00338 void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
00339 int lastInLumBuf, int lastInChrBuf);
00340
00341 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
00342 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
00343 SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
00344 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
00345 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
00346 void ff_bfin_get_unscaled_swscale(SwsContext *c);
00347
00348 #if FF_API_SWS_FORMAT_NAME
00349
00352 attribute_deprecated
00353 const char *sws_format_name(enum PixelFormat format);
00354 #endif
00355
00356
00357 #define is16BPS(x) ( \
00358 (x)==PIX_FMT_GRAY16BE \
00359 || (x)==PIX_FMT_GRAY16LE \
00360 || (x)==PIX_FMT_BGR48BE \
00361 || (x)==PIX_FMT_BGR48LE \
00362 || (x)==PIX_FMT_RGB48BE \
00363 || (x)==PIX_FMT_RGB48LE \
00364 || (x)==PIX_FMT_YUV420P16LE \
00365 || (x)==PIX_FMT_YUV422P16LE \
00366 || (x)==PIX_FMT_YUV444P16LE \
00367 || (x)==PIX_FMT_YUV420P16BE \
00368 || (x)==PIX_FMT_YUV422P16BE \
00369 || (x)==PIX_FMT_YUV444P16BE \
00370 )
00371 #define isNBPS(x) ( \
00372 (x)==PIX_FMT_YUV420P9LE \
00373 || (x)==PIX_FMT_YUV420P9BE \
00374 || (x)==PIX_FMT_YUV444P9BE \
00375 || (x)==PIX_FMT_YUV444P9LE \
00376 || (x)==PIX_FMT_YUV422P10BE \
00377 || (x)==PIX_FMT_YUV422P10LE \
00378 || (x)==PIX_FMT_YUV444P10BE \
00379 || (x)==PIX_FMT_YUV444P10LE \
00380 || (x)==PIX_FMT_YUV420P10LE \
00381 || (x)==PIX_FMT_YUV420P10BE \
00382 || (x)==PIX_FMT_YUV422P10LE \
00383 || (x)==PIX_FMT_YUV422P10BE \
00384 )
00385 #define is9_OR_10BPS isNBPS //for ronald
00386 #define isBE(x) ((x)&1)
00387 #define isPlanar8YUV(x) ( \
00388 (x)==PIX_FMT_YUV410P \
00389 || (x)==PIX_FMT_YUV420P \
00390 || (x)==PIX_FMT_YUVA420P \
00391 || (x)==PIX_FMT_YUV411P \
00392 || (x)==PIX_FMT_YUV422P \
00393 || (x)==PIX_FMT_YUV444P \
00394 || (x)==PIX_FMT_YUV440P \
00395 || (x)==PIX_FMT_NV12 \
00396 || (x)==PIX_FMT_NV21 \
00397 )
00398 #define isPlanarYUV(x) ( \
00399 isPlanar8YUV(x) \
00400 || (x)==PIX_FMT_YUV420P9LE \
00401 || (x)==PIX_FMT_YUV444P9LE \
00402 || (x)==PIX_FMT_YUV420P10LE \
00403 || (x)==PIX_FMT_YUV422P10LE \
00404 || (x)==PIX_FMT_YUV444P10LE \
00405 || (x)==PIX_FMT_YUV420P16LE \
00406 || (x)==PIX_FMT_YUV422P10LE \
00407 || (x)==PIX_FMT_YUV422P16LE \
00408 || (x)==PIX_FMT_YUV444P16LE \
00409 || (x)==PIX_FMT_YUV420P9BE \
00410 || (x)==PIX_FMT_YUV444P9BE \
00411 || (x)==PIX_FMT_YUV420P10BE \
00412 || (x)==PIX_FMT_YUV422P10BE \
00413 || (x)==PIX_FMT_YUV444P10BE \
00414 || (x)==PIX_FMT_YUV420P16BE \
00415 || (x)==PIX_FMT_YUV422P10BE \
00416 || (x)==PIX_FMT_YUV422P16BE \
00417 || (x)==PIX_FMT_YUV444P16BE \
00418 )
00419 #define isYUV(x) ( \
00420 (x)==PIX_FMT_UYVY422 \
00421 || (x)==PIX_FMT_YUYV422 \
00422 || isPlanarYUV(x) \
00423 )
00424 #define isGray(x) ( \
00425 (x)==PIX_FMT_GRAY8 \
00426 || (x)==PIX_FMT_GRAY8A \
00427 || (x)==PIX_FMT_GRAY16BE \
00428 || (x)==PIX_FMT_GRAY16LE \
00429 )
00430 #define isGray16(x) ( \
00431 (x)==PIX_FMT_GRAY16BE \
00432 || (x)==PIX_FMT_GRAY16LE \
00433 )
00434 #define isRGBinInt(x) ( \
00435 (x)==PIX_FMT_RGB48BE \
00436 || (x)==PIX_FMT_RGB48LE \
00437 || (x)==PIX_FMT_RGB32 \
00438 || (x)==PIX_FMT_RGB32_1 \
00439 || (x)==PIX_FMT_RGB24 \
00440 || (x)==PIX_FMT_RGB565BE \
00441 || (x)==PIX_FMT_RGB565LE \
00442 || (x)==PIX_FMT_RGB555BE \
00443 || (x)==PIX_FMT_RGB555LE \
00444 || (x)==PIX_FMT_RGB444BE \
00445 || (x)==PIX_FMT_RGB444LE \
00446 || (x)==PIX_FMT_RGB8 \
00447 || (x)==PIX_FMT_RGB4 \
00448 || (x)==PIX_FMT_RGB4_BYTE \
00449 || (x)==PIX_FMT_MONOBLACK \
00450 || (x)==PIX_FMT_MONOWHITE \
00451 )
00452 #define isBGRinInt(x) ( \
00453 (x)==PIX_FMT_BGR48BE \
00454 || (x)==PIX_FMT_BGR48LE \
00455 || (x)==PIX_FMT_BGR32 \
00456 || (x)==PIX_FMT_BGR32_1 \
00457 || (x)==PIX_FMT_BGR24 \
00458 || (x)==PIX_FMT_BGR565BE \
00459 || (x)==PIX_FMT_BGR565LE \
00460 || (x)==PIX_FMT_BGR555BE \
00461 || (x)==PIX_FMT_BGR555LE \
00462 || (x)==PIX_FMT_BGR444BE \
00463 || (x)==PIX_FMT_BGR444LE \
00464 || (x)==PIX_FMT_BGR8 \
00465 || (x)==PIX_FMT_BGR4 \
00466 || (x)==PIX_FMT_BGR4_BYTE \
00467 || (x)==PIX_FMT_MONOBLACK \
00468 || (x)==PIX_FMT_MONOWHITE \
00469 )
00470 #define isRGBinBytes(x) ( \
00471 (x)==PIX_FMT_RGB48BE \
00472 || (x)==PIX_FMT_RGB48LE \
00473 || (x)==PIX_FMT_RGBA \
00474 || (x)==PIX_FMT_ARGB \
00475 || (x)==PIX_FMT_RGB24 \
00476 )
00477 #define isBGRinBytes(x) ( \
00478 (x)==PIX_FMT_BGR48BE \
00479 || (x)==PIX_FMT_BGR48LE \
00480 || (x)==PIX_FMT_BGRA \
00481 || (x)==PIX_FMT_ABGR \
00482 || (x)==PIX_FMT_BGR24 \
00483 )
00484 #define isAnyRGB(x) ( \
00485 isRGBinInt(x) \
00486 || isBGRinInt(x) \
00487 )
00488 #define isALPHA(x) ( \
00489 (x)==PIX_FMT_BGR32 \
00490 || (x)==PIX_FMT_BGR32_1 \
00491 || (x)==PIX_FMT_RGB32 \
00492 || (x)==PIX_FMT_RGB32_1 \
00493 || (x)==PIX_FMT_PAL8 \
00494 || (x)==PIX_FMT_GRAY8A \
00495 || (x)==PIX_FMT_YUVA420P \
00496 )
00497 #define isPacked(x) ( \
00498 (x)==PIX_FMT_PAL8 \
00499 || (x)==PIX_FMT_YUYV422 \
00500 || (x)==PIX_FMT_UYVY422 \
00501 || (x)==PIX_FMT_Y400A \
00502 || isAnyRGB(x) \
00503 )
00504 #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_GRAY8A)
00505
00506 extern const uint64_t ff_dither4[2];
00507 extern const uint64_t ff_dither8[2];
00508 extern const uint8_t dithers[8][8][8];
00509 extern const uint16_t dither_scale[15][16];
00510
00511
00512 extern const AVClass sws_context_class;
00513
00518 void ff_get_unscaled_swscale(SwsContext *c);
00519
00520 void ff_swscale_get_unscaled_altivec(SwsContext *c);
00521
00526 SwsFunc ff_getSwsFunc(SwsContext *c);
00527
00528 void ff_sws_init_swScale_altivec(SwsContext *c);
00529 void ff_sws_init_swScale_mmx(SwsContext *c);
00530
00531 #endif