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