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 #include "libavutil/log.h"
00032 #include "libavutil/pixfmt.h"
00033 #include "libavutil/pixdesc.h"
00034
00035 #define STR(s) AV_TOSTRING(s) //AV_STRINGIFY is too long
00036
00037 #define FAST_BGR2YV12 //use 7-bit instead of 15-bit coefficients
00038
00039 #define MAX_FILTER_SIZE 256
00040
00041 #define DITHER1XBPP
00042
00043 #if HAVE_BIGENDIAN
00044 #define ALT32_CORR (-1)
00045 #else
00046 #define ALT32_CORR 1
00047 #endif
00048
00049 #if ARCH_X86_64
00050 # define APCK_PTR2 8
00051 # define APCK_COEF 16
00052 # define APCK_SIZE 24
00053 #else
00054 # define APCK_PTR2 4
00055 # define APCK_COEF 8
00056 # define APCK_SIZE 16
00057 #endif
00058
00059 struct SwsContext;
00060
00061 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[],
00062 int srcStride[], int srcSliceY, int srcSliceH,
00063 uint8_t* dst[], int dstStride[]);
00064
00065
00078 typedef void (*yuv2planar1_fn) (const int16_t *src, uint8_t *dest, int dstW,
00079 const uint8_t *dither, int offset);
00080
00094 typedef void (*yuv2planarX_fn) (const int16_t *filter, int filterSize,
00095 const int16_t **src, uint8_t *dest, int dstW,
00096 const uint8_t *dither, int offset);
00097
00113 typedef void (*yuv2interleavedX_fn) (struct SwsContext *c, const int16_t *chrFilter, int chrFilterSize,
00114 const int16_t **chrUSrc, const int16_t **chrVSrc,
00115 uint8_t *dest, int dstW);
00116
00146 typedef void (*yuv2packed1_fn) (struct SwsContext *c, const int16_t *lumSrc,
00147 const int16_t *chrUSrc[2], const int16_t *chrVSrc[2],
00148 const int16_t *alpSrc, uint8_t *dest,
00149 int dstW, int uvalpha, int y);
00178 typedef void (*yuv2packed2_fn) (struct SwsContext *c, const int16_t *lumSrc[2],
00179 const int16_t *chrUSrc[2], const int16_t *chrVSrc[2],
00180 const int16_t *alpSrc[2], uint8_t *dest,
00181 int dstW, int yalpha, int uvalpha, int y);
00208 typedef void (*yuv2packedX_fn) (struct SwsContext *c, const int16_t *lumFilter,
00209 const int16_t **lumSrc, int lumFilterSize,
00210 const int16_t *chrFilter, const int16_t **chrUSrc,
00211 const int16_t **chrVSrc, int chrFilterSize,
00212 const int16_t **alpSrc, uint8_t *dest,
00213 int dstW, int y);
00214
00215
00216 typedef struct SwsContext {
00220 const AVClass *av_class;
00221
00226 SwsFunc swScale;
00227 int srcW;
00228 int srcH;
00229 int dstH;
00230 int chrSrcW;
00231 int chrSrcH;
00232 int chrDstW;
00233 int chrDstH;
00234 int lumXInc, chrXInc;
00235 int lumYInc, chrYInc;
00236 enum PixelFormat dstFormat;
00237 enum PixelFormat srcFormat;
00238 int dstFormatBpp;
00239 int srcFormatBpp;
00240 int dstBpc, srcBpc;
00241 int chrSrcHSubSample;
00242 int chrSrcVSubSample;
00243 int chrDstHSubSample;
00244 int chrDstVSubSample;
00245 int vChrDrop;
00246 int sliceDir;
00247 double param[2];
00248
00249 uint32_t pal_yuv[256];
00250 uint32_t pal_rgb[256];
00251
00262 int16_t **lumPixBuf;
00263 int16_t **chrUPixBuf;
00264 int16_t **chrVPixBuf;
00265 int16_t **alpPixBuf;
00266 int vLumBufSize;
00267 int vChrBufSize;
00268 int lastInLumBuf;
00269 int lastInChrBuf;
00270 int lumBufIndex;
00271 int chrBufIndex;
00272
00273
00274 uint8_t *formatConvBuffer;
00275
00290 int16_t *hLumFilter;
00291 int16_t *hChrFilter;
00292 int16_t *vLumFilter;
00293 int16_t *vChrFilter;
00294 int16_t *hLumFilterPos;
00295 int16_t *hChrFilterPos;
00296 int16_t *vLumFilterPos;
00297 int16_t *vChrFilterPos;
00298 int hLumFilterSize;
00299 int hChrFilterSize;
00300 int vLumFilterSize;
00301 int vChrFilterSize;
00302
00303
00304 int lumMmx2FilterCodeSize;
00305 int chrMmx2FilterCodeSize;
00306 uint8_t *lumMmx2FilterCode;
00307 uint8_t *chrMmx2FilterCode;
00308
00309 int canMMX2BeUsed;
00310
00311 int dstY;
00312 int flags;
00313 void * yuvTable;
00314 uint8_t * table_rV[256];
00315 uint8_t * table_gU[256];
00316 int table_gV[256];
00317 uint8_t * table_bU[256];
00318
00319
00320 int contrast, brightness, saturation;
00321 int srcColorspaceTable[4];
00322 int dstColorspaceTable[4];
00323 int srcRange;
00324 int dstRange;
00325 int yuv2rgb_y_offset;
00326 int yuv2rgb_y_coeff;
00327 int yuv2rgb_v2r_coeff;
00328 int yuv2rgb_v2g_coeff;
00329 int yuv2rgb_u2g_coeff;
00330 int yuv2rgb_u2b_coeff;
00331
00332 #define RED_DITHER "0*8"
00333 #define GREEN_DITHER "1*8"
00334 #define BLUE_DITHER "2*8"
00335 #define Y_COEFF "3*8"
00336 #define VR_COEFF "4*8"
00337 #define UB_COEFF "5*8"
00338 #define VG_COEFF "6*8"
00339 #define UG_COEFF "7*8"
00340 #define Y_OFFSET "8*8"
00341 #define U_OFFSET "9*8"
00342 #define V_OFFSET "10*8"
00343 #define LUM_MMX_FILTER_OFFSET "11*8"
00344 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
00345 #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
00346 #define ESP_OFFSET "11*8+4*4*256*2+8"
00347 #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
00348 #define U_TEMP "11*8+4*4*256*2+24"
00349 #define V_TEMP "11*8+4*4*256*2+32"
00350 #define Y_TEMP "11*8+4*4*256*2+40"
00351 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
00352 #define UV_OFF "11*8+4*4*256*3+48"
00353 #define UV_OFFx2 "11*8+4*4*256*3+56"
00354 #define DITHER16 "11*8+4*4*256*3+64"
00355 #define DITHER32 "11*8+4*4*256*3+80"
00356
00357 DECLARE_ALIGNED(8, uint64_t, redDither);
00358 DECLARE_ALIGNED(8, uint64_t, greenDither);
00359 DECLARE_ALIGNED(8, uint64_t, blueDither);
00360
00361 DECLARE_ALIGNED(8, uint64_t, yCoeff);
00362 DECLARE_ALIGNED(8, uint64_t, vrCoeff);
00363 DECLARE_ALIGNED(8, uint64_t, ubCoeff);
00364 DECLARE_ALIGNED(8, uint64_t, vgCoeff);
00365 DECLARE_ALIGNED(8, uint64_t, ugCoeff);
00366 DECLARE_ALIGNED(8, uint64_t, yOffset);
00367 DECLARE_ALIGNED(8, uint64_t, uOffset);
00368 DECLARE_ALIGNED(8, uint64_t, vOffset);
00369 int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
00370 int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
00371 int dstW;
00372 DECLARE_ALIGNED(8, uint64_t, esp);
00373 DECLARE_ALIGNED(8, uint64_t, vRounder);
00374 DECLARE_ALIGNED(8, uint64_t, u_temp);
00375 DECLARE_ALIGNED(8, uint64_t, v_temp);
00376 DECLARE_ALIGNED(8, uint64_t, y_temp);
00377 int32_t alpMmxFilter[4*MAX_FILTER_SIZE];
00378
00379
00380
00381 DECLARE_ALIGNED(8, ptrdiff_t, uv_off);
00382 DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2);
00383 DECLARE_ALIGNED(8, uint16_t, dither16)[8];
00384 DECLARE_ALIGNED(8, uint32_t, dither32)[8];
00385
00386 const uint8_t *chrDither8, *lumDither8;
00387
00388 #if HAVE_ALTIVEC
00389 vector signed short CY;
00390 vector signed short CRV;
00391 vector signed short CBU;
00392 vector signed short CGU;
00393 vector signed short CGV;
00394 vector signed short OY;
00395 vector unsigned short CSHIFT;
00396 vector signed short *vYCoeffsBank, *vCCoeffsBank;
00397 #endif
00398
00399 #if ARCH_BFIN
00400 DECLARE_ALIGNED(4, uint32_t, oy);
00401 DECLARE_ALIGNED(4, uint32_t, oc);
00402 DECLARE_ALIGNED(4, uint32_t, zero);
00403 DECLARE_ALIGNED(4, uint32_t, cy);
00404 DECLARE_ALIGNED(4, uint32_t, crv);
00405 DECLARE_ALIGNED(4, uint32_t, rmask);
00406 DECLARE_ALIGNED(4, uint32_t, cbu);
00407 DECLARE_ALIGNED(4, uint32_t, bmask);
00408 DECLARE_ALIGNED(4, uint32_t, cgu);
00409 DECLARE_ALIGNED(4, uint32_t, cgv);
00410 DECLARE_ALIGNED(4, uint32_t, gmask);
00411 #endif
00412
00413 #if HAVE_VIS
00414 DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
00415 #endif
00416 int use_mmx_vfilter;
00417
00418
00419 yuv2planar1_fn yuv2plane1;
00420 yuv2planarX_fn yuv2planeX;
00421 yuv2interleavedX_fn yuv2nv12cX;
00422 yuv2packed1_fn yuv2packed1;
00423 yuv2packed2_fn yuv2packed2;
00424 yuv2packedX_fn yuv2packedX;
00425
00426 void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
00427 int width, uint32_t *pal);
00428 void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
00429 int width, uint32_t *pal);
00430 void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
00431 const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
00432 int width, uint32_t *pal);
00433
00439 void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width);
00440 void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int width);
00462 void (*hyscale_fast)(struct SwsContext *c,
00463 int16_t *dst, int dstWidth,
00464 const uint8_t *src, int srcW, int xInc);
00465 void (*hcscale_fast)(struct SwsContext *c,
00466 int16_t *dst1, int16_t *dst2, int dstWidth,
00467 const uint8_t *src1, const uint8_t *src2,
00468 int srcW, int xInc);
00502 void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
00503 const int16_t *filter, const int16_t *filterPos,
00504 int filterSize);
00505 void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src,
00506 const int16_t *filter, const int16_t *filterPos,
00507 int filterSize);
00510 void (*lumConvertRange)(int16_t *dst, int width);
00511 void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
00512
00513 int needs_hcscale;
00514
00515 } SwsContext;
00516
00517
00518 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
00519 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
00520 int fullRange, int brightness,
00521 int contrast, int saturation);
00522
00523 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
00524 int brightness, int contrast, int saturation);
00525 void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
00526 int lastInLumBuf, int lastInChrBuf);
00527
00528 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
00529 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
00530 SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
00531 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
00532 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
00533 void ff_bfin_get_unscaled_swscale(SwsContext *c);
00534
00535 #if FF_API_SWS_FORMAT_NAME
00536
00539 attribute_deprecated
00540 const char *sws_format_name(enum PixelFormat format);
00541 #endif
00542
00543 #define is16BPS(x) \
00544 (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 15)
00545
00546 #define is9_OR_10BPS(x) \
00547 (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 8 || \
00548 av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 9)
00549
00550 #define isNBPS(x) is9_OR_10BPS(x)
00551
00552 #define isBE(x) \
00553 (av_pix_fmt_descriptors[x].flags & PIX_FMT_BE)
00554
00555 #define isYUV(x) \
00556 (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB) && \
00557 av_pix_fmt_descriptors[x].nb_components >= 2)
00558
00559 #define isPlanarYUV(x) \
00560 ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR) && \
00561 isYUV(x))
00562
00563 #define isRGB(x) \
00564 (av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB)
00565 #if 0 // FIXME
00566 #define isGray(x) \
00567 (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) && \
00568 av_pix_fmt_descriptors[x].nb_components <= 2)
00569 #else
00570 #define isGray(x) ( \
00571 (x)==PIX_FMT_GRAY8 \
00572 || (x)==PIX_FMT_GRAY8A \
00573 || (x)==PIX_FMT_GRAY16BE \
00574 || (x)==PIX_FMT_GRAY16LE \
00575 )
00576 #endif
00577
00578 #define isRGBinInt(x) ( \
00579 (x)==PIX_FMT_RGB48BE \
00580 || (x)==PIX_FMT_RGB48LE \
00581 || (x)==PIX_FMT_RGBA64BE \
00582 || (x)==PIX_FMT_RGBA64LE \
00583 || (x)==PIX_FMT_RGB32 \
00584 || (x)==PIX_FMT_RGB32_1 \
00585 || (x)==PIX_FMT_RGB24 \
00586 || (x)==PIX_FMT_RGB565BE \
00587 || (x)==PIX_FMT_RGB565LE \
00588 || (x)==PIX_FMT_RGB555BE \
00589 || (x)==PIX_FMT_RGB555LE \
00590 || (x)==PIX_FMT_RGB444BE \
00591 || (x)==PIX_FMT_RGB444LE \
00592 || (x)==PIX_FMT_RGB8 \
00593 || (x)==PIX_FMT_RGB4 \
00594 || (x)==PIX_FMT_RGB4_BYTE \
00595 || (x)==PIX_FMT_MONOBLACK \
00596 || (x)==PIX_FMT_MONOWHITE \
00597 )
00598 #define isBGRinInt(x) ( \
00599 (x)==PIX_FMT_BGR48BE \
00600 || (x)==PIX_FMT_BGR48LE \
00601 || (x)==PIX_FMT_BGRA64BE \
00602 || (x)==PIX_FMT_BGRA64LE \
00603 || (x)==PIX_FMT_BGR32 \
00604 || (x)==PIX_FMT_BGR32_1 \
00605 || (x)==PIX_FMT_BGR24 \
00606 || (x)==PIX_FMT_BGR565BE \
00607 || (x)==PIX_FMT_BGR565LE \
00608 || (x)==PIX_FMT_BGR555BE \
00609 || (x)==PIX_FMT_BGR555LE \
00610 || (x)==PIX_FMT_BGR444BE \
00611 || (x)==PIX_FMT_BGR444LE \
00612 || (x)==PIX_FMT_BGR8 \
00613 || (x)==PIX_FMT_BGR4 \
00614 || (x)==PIX_FMT_BGR4_BYTE \
00615 || (x)==PIX_FMT_MONOBLACK \
00616 || (x)==PIX_FMT_MONOWHITE \
00617 )
00618
00619 #define isRGBinBytes(x) ( \
00620 (x)==PIX_FMT_RGB48BE \
00621 || (x)==PIX_FMT_RGB48LE \
00622 || (x)==PIX_FMT_RGBA64BE \
00623 || (x)==PIX_FMT_RGBA64LE \
00624 || (x)==PIX_FMT_RGBA \
00625 || (x)==PIX_FMT_ARGB \
00626 || (x)==PIX_FMT_RGB24 \
00627 )
00628 #define isBGRinBytes(x) ( \
00629 (x)==PIX_FMT_BGR48BE \
00630 || (x)==PIX_FMT_BGR48LE \
00631 || (x)==PIX_FMT_BGRA64BE \
00632 || (x)==PIX_FMT_BGRA64LE \
00633 || (x)==PIX_FMT_BGRA \
00634 || (x)==PIX_FMT_ABGR \
00635 || (x)==PIX_FMT_BGR24 \
00636 )
00637
00638 #define isAnyRGB(x) ( \
00639 isRGBinInt(x) \
00640 || isBGRinInt(x) \
00641 || (x)==PIX_FMT_GBR24P \
00642 )
00643
00644 #define isALPHA(x) \
00645 (av_pix_fmt_descriptors[x].nb_components == 2 || \
00646 av_pix_fmt_descriptors[x].nb_components == 4)
00647
00648 #if 1
00649 #define isPacked(x) ( \
00650 (x)==PIX_FMT_PAL8 \
00651 || (x)==PIX_FMT_YUYV422 \
00652 || (x)==PIX_FMT_UYVY422 \
00653 || (x)==PIX_FMT_Y400A \
00654 || isRGBinInt(x) \
00655 || isBGRinInt(x) \
00656 )
00657 #else
00658 #define isPacked(x) \
00659 (av_pix_fmt_descriptors[x].nb_components >= 2 && \
00660 !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
00661
00662 #endif
00663 #define isPlanar(x) \
00664 (av_pix_fmt_descriptors[x].nb_components >= 2 && \
00665 (av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
00666
00667 #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A)
00668
00669 extern const uint64_t ff_dither4[2];
00670 extern const uint64_t ff_dither8[2];
00671 extern const uint8_t dithers[8][8][8];
00672 extern const uint16_t dither_scale[15][16];
00673
00674
00675 extern const AVClass sws_context_class;
00676
00681 void ff_get_unscaled_swscale(SwsContext *c);
00682
00683 void ff_swscale_get_unscaled_altivec(SwsContext *c);
00684
00689 SwsFunc ff_getSwsFunc(SwsContext *c);
00690
00691 void ff_sws_init_swScale_altivec(SwsContext *c);
00692 void ff_sws_init_swScale_mmx(SwsContext *c);
00693
00694 #endif