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 #if HAVE_BIGENDIAN
00042 #define ALT32_CORR (-1)
00043 #else
00044 #define ALT32_CORR 1
00045 #endif
00046
00047 #if ARCH_X86_64
00048 # define APCK_PTR2 8
00049 # define APCK_COEF 16
00050 # define APCK_SIZE 24
00051 #else
00052 # define APCK_PTR2 4
00053 # define APCK_COEF 8
00054 # define APCK_SIZE 16
00055 #endif
00056
00057 struct SwsContext;
00058
00059 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[],
00060 int srcStride[], int srcSliceY, int srcSliceH,
00061 uint8_t *dst[], int dstStride[]);
00062
00075 typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW,
00076 const uint8_t *dither, int offset);
00077
00091 typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize,
00092 const int16_t **src, uint8_t *dest, int dstW,
00093 const uint8_t *dither, int offset);
00094
00110 typedef void (*yuv2interleavedX_fn)(struct SwsContext *c,
00111 const int16_t *chrFilter,
00112 int chrFilterSize,
00113 const int16_t **chrUSrc,
00114 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],
00148 const int16_t *chrVSrc[2],
00149 const int16_t *alpSrc, uint8_t *dest,
00150 int dstW, int uvalpha, int y);
00179 typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2],
00180 const int16_t *chrUSrc[2],
00181 const int16_t *chrVSrc[2],
00182 const int16_t *alpSrc[2],
00183 uint8_t *dest,
00184 int dstW, int yalpha, int uvalpha, int y);
00211 typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
00212 const int16_t **lumSrc, int lumFilterSize,
00213 const int16_t *chrFilter,
00214 const int16_t **chrUSrc,
00215 const int16_t **chrVSrc, int chrFilterSize,
00216 const int16_t **alpSrc, uint8_t *dest,
00217 int dstW, int y);
00218
00219
00220 typedef struct SwsContext {
00224 const AVClass *av_class;
00225
00230 SwsFunc swScale;
00231 int srcW;
00232 int srcH;
00233 int dstH;
00234 int chrSrcW;
00235 int chrSrcH;
00236 int chrDstW;
00237 int chrDstH;
00238 int lumXInc, chrXInc;
00239 int lumYInc, chrYInc;
00240 enum PixelFormat dstFormat;
00241 enum PixelFormat srcFormat;
00242 int dstFormatBpp;
00243 int srcFormatBpp;
00244 int dstBpc, srcBpc;
00245 int chrSrcHSubSample;
00246 int chrSrcVSubSample;
00247 int chrDstHSubSample;
00248 int chrDstVSubSample;
00249 int vChrDrop;
00250 int sliceDir;
00251 double param[2];
00252
00253 uint32_t pal_yuv[256];
00254 uint32_t pal_rgb[256];
00255
00266 int16_t **lumPixBuf;
00267 int16_t **chrUPixBuf;
00268 int16_t **chrVPixBuf;
00269 int16_t **alpPixBuf;
00270 int vLumBufSize;
00271 int vChrBufSize;
00272 int lastInLumBuf;
00273 int lastInChrBuf;
00274 int lumBufIndex;
00275 int chrBufIndex;
00276
00277
00278 uint8_t *formatConvBuffer;
00279
00294 int16_t *hLumFilter;
00295 int16_t *hChrFilter;
00296 int16_t *vLumFilter;
00297 int16_t *vChrFilter;
00298 int16_t *hLumFilterPos;
00299 int16_t *hChrFilterPos;
00300 int16_t *vLumFilterPos;
00301 int16_t *vChrFilterPos;
00302 int hLumFilterSize;
00303 int hChrFilterSize;
00304 int vLumFilterSize;
00305 int vChrFilterSize;
00306
00307
00308 int lumMmx2FilterCodeSize;
00309 int chrMmx2FilterCodeSize;
00310 uint8_t *lumMmx2FilterCode;
00311 uint8_t *chrMmx2FilterCode;
00312
00313 int canMMX2BeUsed;
00314
00315 int dstY;
00316 int flags;
00317 void *yuvTable;
00318 uint8_t *table_rV[256];
00319 uint8_t *table_gU[256];
00320 int table_gV[256];
00321 uint8_t *table_bU[256];
00322
00323
00324 int contrast, brightness, saturation;
00325 int srcColorspaceTable[4];
00326 int dstColorspaceTable[4];
00327 int srcRange;
00328 int dstRange;
00329 int yuv2rgb_y_offset;
00330 int yuv2rgb_y_coeff;
00331 int yuv2rgb_v2r_coeff;
00332 int yuv2rgb_v2g_coeff;
00333 int yuv2rgb_u2g_coeff;
00334 int yuv2rgb_u2b_coeff;
00335
00336 #define RED_DITHER "0*8"
00337 #define GREEN_DITHER "1*8"
00338 #define BLUE_DITHER "2*8"
00339 #define Y_COEFF "3*8"
00340 #define VR_COEFF "4*8"
00341 #define UB_COEFF "5*8"
00342 #define VG_COEFF "6*8"
00343 #define UG_COEFF "7*8"
00344 #define Y_OFFSET "8*8"
00345 #define U_OFFSET "9*8"
00346 #define V_OFFSET "10*8"
00347 #define LUM_MMX_FILTER_OFFSET "11*8"
00348 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
00349 #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
00350 #define ESP_OFFSET "11*8+4*4*256*2+8"
00351 #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
00352 #define U_TEMP "11*8+4*4*256*2+24"
00353 #define V_TEMP "11*8+4*4*256*2+32"
00354 #define Y_TEMP "11*8+4*4*256*2+40"
00355 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
00356 #define UV_OFF_PX "11*8+4*4*256*3+48"
00357 #define UV_OFF_BYTE "11*8+4*4*256*3+56"
00358 #define DITHER16 "11*8+4*4*256*3+64"
00359 #define DITHER32 "11*8+4*4*256*3+80"
00360
00361 DECLARE_ALIGNED(8, uint64_t, redDither);
00362 DECLARE_ALIGNED(8, uint64_t, greenDither);
00363 DECLARE_ALIGNED(8, uint64_t, blueDither);
00364
00365 DECLARE_ALIGNED(8, uint64_t, yCoeff);
00366 DECLARE_ALIGNED(8, uint64_t, vrCoeff);
00367 DECLARE_ALIGNED(8, uint64_t, ubCoeff);
00368 DECLARE_ALIGNED(8, uint64_t, vgCoeff);
00369 DECLARE_ALIGNED(8, uint64_t, ugCoeff);
00370 DECLARE_ALIGNED(8, uint64_t, yOffset);
00371 DECLARE_ALIGNED(8, uint64_t, uOffset);
00372 DECLARE_ALIGNED(8, uint64_t, vOffset);
00373 int32_t lumMmxFilter[4 * MAX_FILTER_SIZE];
00374 int32_t chrMmxFilter[4 * MAX_FILTER_SIZE];
00375 int dstW;
00376 DECLARE_ALIGNED(8, uint64_t, esp);
00377 DECLARE_ALIGNED(8, uint64_t, vRounder);
00378 DECLARE_ALIGNED(8, uint64_t, u_temp);
00379 DECLARE_ALIGNED(8, uint64_t, v_temp);
00380 DECLARE_ALIGNED(8, uint64_t, y_temp);
00381 int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
00382
00383
00384
00385 DECLARE_ALIGNED(8, ptrdiff_t, uv_off_px);
00386 DECLARE_ALIGNED(8, ptrdiff_t, uv_off_byte);
00387 DECLARE_ALIGNED(8, uint16_t, dither16)[8];
00388 DECLARE_ALIGNED(8, uint32_t, dither32)[8];
00389
00390 const uint8_t *chrDither8, *lumDither8;
00391
00392 #if HAVE_ALTIVEC
00393 vector signed short CY;
00394 vector signed short CRV;
00395 vector signed short CBU;
00396 vector signed short CGU;
00397 vector signed short CGV;
00398 vector signed short OY;
00399 vector unsigned short CSHIFT;
00400 vector signed short *vYCoeffsBank, *vCCoeffsBank;
00401 #endif
00402
00403 #if ARCH_BFIN
00404 DECLARE_ALIGNED(4, uint32_t, oy);
00405 DECLARE_ALIGNED(4, uint32_t, oc);
00406 DECLARE_ALIGNED(4, uint32_t, zero);
00407 DECLARE_ALIGNED(4, uint32_t, cy);
00408 DECLARE_ALIGNED(4, uint32_t, crv);
00409 DECLARE_ALIGNED(4, uint32_t, rmask);
00410 DECLARE_ALIGNED(4, uint32_t, cbu);
00411 DECLARE_ALIGNED(4, uint32_t, bmask);
00412 DECLARE_ALIGNED(4, uint32_t, cgu);
00413 DECLARE_ALIGNED(4, uint32_t, cgv);
00414 DECLARE_ALIGNED(4, uint32_t, gmask);
00415 #endif
00416
00417 #if HAVE_VIS
00418 DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
00419 #endif
00420
00421
00422 yuv2planar1_fn yuv2plane1;
00423 yuv2planarX_fn yuv2planeX;
00424 yuv2interleavedX_fn yuv2nv12cX;
00425 yuv2packed1_fn yuv2packed1;
00426 yuv2packed2_fn yuv2packed2;
00427 yuv2packedX_fn yuv2packedX;
00428
00430 void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
00431 int width, uint32_t *pal);
00433 void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
00434 int width, uint32_t *pal);
00436 void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
00437 const uint8_t *src1, const uint8_t *src2,
00438 int width, uint32_t *pal);
00439
00445 void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width);
00446 void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
00447 int width);
00469 void (*hyscale_fast)(struct SwsContext *c,
00470 int16_t *dst, int dstWidth,
00471 const uint8_t *src, int srcW, int xInc);
00472 void (*hcscale_fast)(struct SwsContext *c,
00473 int16_t *dst1, int16_t *dst2, int dstWidth,
00474 const uint8_t *src1, const uint8_t *src2,
00475 int srcW, int xInc);
00509 void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
00510 const uint8_t *src, const int16_t *filter,
00511 const int16_t *filterPos, int filterSize);
00512 void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
00513 const uint8_t *src, const int16_t *filter,
00514 const int16_t *filterPos, int filterSize);
00517
00518 void (*lumConvertRange)(int16_t *dst, int width);
00520 void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
00521
00522 int needs_hcscale;
00523 } SwsContext;
00524
00525
00526 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
00527 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
00528 int fullRange, int brightness,
00529 int contrast, int saturation);
00530
00531 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
00532 int brightness, int contrast, int saturation);
00533 void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
00534 int lastInLumBuf, int lastInChrBuf);
00535
00536 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
00537 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
00538 SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
00539 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
00540 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
00541 void ff_bfin_get_unscaled_swscale(SwsContext *c);
00542
00543 const char *sws_format_name(enum PixelFormat format);
00544
00545 #define is16BPS(x) \
00546 (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 15)
00547
00548 #define is9_OR_10BPS(x) \
00549 (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 8 || \
00550 av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 9)
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
00566 #if 0 // FIXME
00567 #define isGray(x) \
00568 (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) && \
00569 av_pix_fmt_descriptors[x].nb_components <= 2)
00570 #else
00571 #define isGray(x) \
00572 ((x) == PIX_FMT_GRAY8 || \
00573 (x) == PIX_FMT_Y400A || \
00574 (x) == PIX_FMT_GRAY16BE || \
00575 (x) == PIX_FMT_GRAY16LE)
00576 #endif
00577
00578 #define isRGBinInt(x) \
00579 ((x) == PIX_FMT_RGB48BE || \
00580 (x) == PIX_FMT_RGB48LE || \
00581 (x) == PIX_FMT_RGB32 || \
00582 (x) == PIX_FMT_RGB32_1 || \
00583 (x) == PIX_FMT_RGB24 || \
00584 (x) == PIX_FMT_RGB565BE || \
00585 (x) == PIX_FMT_RGB565LE || \
00586 (x) == PIX_FMT_RGB555BE || \
00587 (x) == PIX_FMT_RGB555LE || \
00588 (x) == PIX_FMT_RGB444BE || \
00589 (x) == PIX_FMT_RGB444LE || \
00590 (x) == PIX_FMT_RGB8 || \
00591 (x) == PIX_FMT_RGB4 || \
00592 (x) == PIX_FMT_RGB4_BYTE || \
00593 (x) == PIX_FMT_MONOBLACK || \
00594 (x) == PIX_FMT_MONOWHITE)
00595
00596 #define isBGRinInt(x) \
00597 ((x) == PIX_FMT_BGR48BE || \
00598 (x) == PIX_FMT_BGR48LE || \
00599 (x) == PIX_FMT_BGR32 || \
00600 (x) == PIX_FMT_BGR32_1 || \
00601 (x) == PIX_FMT_BGR24 || \
00602 (x) == PIX_FMT_BGR565BE || \
00603 (x) == PIX_FMT_BGR565LE || \
00604 (x) == PIX_FMT_BGR555BE || \
00605 (x) == PIX_FMT_BGR555LE || \
00606 (x) == PIX_FMT_BGR444BE || \
00607 (x) == PIX_FMT_BGR444LE || \
00608 (x) == PIX_FMT_BGR8 || \
00609 (x) == PIX_FMT_BGR4 || \
00610 (x) == PIX_FMT_BGR4_BYTE || \
00611 (x) == PIX_FMT_MONOBLACK || \
00612 (x) == PIX_FMT_MONOWHITE)
00613
00614 #define isAnyRGB(x) \
00615 (isRGBinInt(x) || \
00616 isBGRinInt(x))
00617
00618 #define isALPHA(x) \
00619 (av_pix_fmt_descriptors[x].nb_components == 2 || \
00620 av_pix_fmt_descriptors[x].nb_components == 4)
00621
00622 #define isPacked(x) \
00623 ((av_pix_fmt_descriptors[x].nb_components >= 2 && \
00624 !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) || \
00625 (x) == PIX_FMT_PAL8)
00626
00627 #define isPlanar(x) \
00628 (av_pix_fmt_descriptors[x].nb_components >= 2 && \
00629 (av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
00630
00631 #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A)
00632
00633 extern const uint64_t ff_dither4[2];
00634 extern const uint64_t ff_dither8[2];
00635
00636 extern const AVClass sws_context_class;
00637
00642 void ff_get_unscaled_swscale(SwsContext *c);
00643
00644 void ff_swscale_get_unscaled_altivec(SwsContext *c);
00645
00650 SwsFunc ff_getSwsFunc(SwsContext *c);
00651
00652 void ff_sws_init_swScale_altivec(SwsContext *c);
00653 void ff_sws_init_swScale_mmx(SwsContext *c);
00654
00655 #endif