Libav 0.7.1
|
00001 /* 00002 * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at> 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 #if HAVE_BIGENDIAN 00039 #define ALT32_CORR (-1) 00040 #else 00041 #define ALT32_CORR 1 00042 #endif 00043 00044 #if ARCH_X86_64 00045 # define APCK_PTR2 8 00046 # define APCK_COEF 16 00047 # define APCK_SIZE 24 00048 #else 00049 # define APCK_PTR2 4 00050 # define APCK_COEF 8 00051 # define APCK_SIZE 16 00052 #endif 00053 00054 struct SwsContext; 00055 00056 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[], 00057 int srcStride[], int srcSliceY, int srcSliceH, 00058 uint8_t* dst[], int dstStride[]); 00059 00060 typedef void (*yuv2planar1_fn) (struct SwsContext *c, 00061 const int16_t *lumSrc, const int16_t *chrUSrc, 00062 const int16_t *chrVSrc, const int16_t *alpSrc, 00063 uint8_t *dest, 00064 uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, 00065 int dstW, int chrDstW); 00066 typedef void (*yuv2planarX_fn) (struct SwsContext *c, 00067 const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, 00068 const int16_t *chrFilter, const int16_t **chrUSrc, 00069 const int16_t **chrVSrc, int chrFilterSize, 00070 const int16_t **alpSrc, 00071 uint8_t *dest, 00072 uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, 00073 int dstW, int chrDstW); 00074 typedef void (*yuv2packed1_fn) (struct SwsContext *c, 00075 const uint16_t *buf0, 00076 const uint16_t *ubuf0, const uint16_t *ubuf1, 00077 const uint16_t *vbuf0, const uint16_t *vbuf1, 00078 const uint16_t *abuf0, 00079 uint8_t *dest, 00080 int dstW, int uvalpha, int dstFormat, int flags, int y); 00081 typedef void (*yuv2packed2_fn) (struct SwsContext *c, 00082 const uint16_t *buf0, const uint16_t *buf1, 00083 const uint16_t *ubuf0, const uint16_t *ubuf1, 00084 const uint16_t *vbuf0, const uint16_t *vbuf1, 00085 const uint16_t *abuf0, const uint16_t *abuf1, 00086 uint8_t *dest, 00087 int dstW, int yalpha, int uvalpha, int y); 00088 typedef void (*yuv2packedX_fn) (struct SwsContext *c, 00089 const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, 00090 const int16_t *chrFilter, const int16_t **chrUSrc, 00091 const int16_t **chrVSrc, int chrFilterSize, 00092 const int16_t **alpSrc, uint8_t *dest, 00093 int dstW, int dstY); 00094 00095 /* This struct should be aligned on at least a 32-byte boundary. */ 00096 typedef struct SwsContext { 00100 const AVClass *av_class; 00101 00106 SwsFunc swScale; 00107 int srcW; 00108 int srcH; 00109 int dstH; 00110 int chrSrcW; 00111 int chrSrcH; 00112 int chrDstW; 00113 int chrDstH; 00114 int lumXInc, chrXInc; 00115 int lumYInc, chrYInc; 00116 enum PixelFormat dstFormat; 00117 enum PixelFormat srcFormat; 00118 int dstFormatBpp; 00119 int srcFormatBpp; 00120 int chrSrcHSubSample; 00121 int chrSrcVSubSample; 00122 int chrDstHSubSample; 00123 int chrDstVSubSample; 00124 int vChrDrop; 00125 int sliceDir; 00126 double param[2]; 00127 00128 uint32_t pal_yuv[256]; 00129 uint32_t pal_rgb[256]; 00130 00141 int16_t **lumPixBuf; 00142 int16_t **chrUPixBuf; 00143 int16_t **chrVPixBuf; 00144 int16_t **alpPixBuf; 00145 int vLumBufSize; 00146 int vChrBufSize; 00147 int lastInLumBuf; 00148 int lastInChrBuf; 00149 int lumBufIndex; 00150 int chrBufIndex; 00151 00152 00153 uint8_t *formatConvBuffer; 00154 00169 int16_t *hLumFilter; 00170 int16_t *hChrFilter; 00171 int16_t *vLumFilter; 00172 int16_t *vChrFilter; 00173 int16_t *hLumFilterPos; 00174 int16_t *hChrFilterPos; 00175 int16_t *vLumFilterPos; 00176 int16_t *vChrFilterPos; 00177 int hLumFilterSize; 00178 int hChrFilterSize; 00179 int vLumFilterSize; 00180 int vChrFilterSize; 00181 00182 00183 int lumMmx2FilterCodeSize; 00184 int chrMmx2FilterCodeSize; 00185 uint8_t *lumMmx2FilterCode; 00186 uint8_t *chrMmx2FilterCode; 00187 00188 int canMMX2BeUsed; 00189 00190 int dstY; 00191 int flags; 00192 void * yuvTable; // pointer to the yuv->rgb table start so it can be freed() 00193 uint8_t * table_rV[256]; 00194 uint8_t * table_gU[256]; 00195 int table_gV[256]; 00196 uint8_t * table_bU[256]; 00197 00198 //Colorspace stuff 00199 int contrast, brightness, saturation; // for sws_getColorspaceDetails 00200 int srcColorspaceTable[4]; 00201 int dstColorspaceTable[4]; 00202 int srcRange; 00203 int dstRange; 00204 int yuv2rgb_y_offset; 00205 int yuv2rgb_y_coeff; 00206 int yuv2rgb_v2r_coeff; 00207 int yuv2rgb_v2g_coeff; 00208 int yuv2rgb_u2g_coeff; 00209 int yuv2rgb_u2b_coeff; 00210 00211 #define RED_DITHER "0*8" 00212 #define GREEN_DITHER "1*8" 00213 #define BLUE_DITHER "2*8" 00214 #define Y_COEFF "3*8" 00215 #define VR_COEFF "4*8" 00216 #define UB_COEFF "5*8" 00217 #define VG_COEFF "6*8" 00218 #define UG_COEFF "7*8" 00219 #define Y_OFFSET "8*8" 00220 #define U_OFFSET "9*8" 00221 #define V_OFFSET "10*8" 00222 #define LUM_MMX_FILTER_OFFSET "11*8" 00223 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256" 00224 #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM 00225 #define ESP_OFFSET "11*8+4*4*256*2+8" 00226 #define VROUNDER_OFFSET "11*8+4*4*256*2+16" 00227 #define U_TEMP "11*8+4*4*256*2+24" 00228 #define V_TEMP "11*8+4*4*256*2+32" 00229 #define Y_TEMP "11*8+4*4*256*2+40" 00230 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48" 00231 #define UV_OFF "11*8+4*4*256*3+48" 00232 #define UV_OFFx2 "11*8+4*4*256*3+56" 00233 00234 DECLARE_ALIGNED(8, uint64_t, redDither); 00235 DECLARE_ALIGNED(8, uint64_t, greenDither); 00236 DECLARE_ALIGNED(8, uint64_t, blueDither); 00237 00238 DECLARE_ALIGNED(8, uint64_t, yCoeff); 00239 DECLARE_ALIGNED(8, uint64_t, vrCoeff); 00240 DECLARE_ALIGNED(8, uint64_t, ubCoeff); 00241 DECLARE_ALIGNED(8, uint64_t, vgCoeff); 00242 DECLARE_ALIGNED(8, uint64_t, ugCoeff); 00243 DECLARE_ALIGNED(8, uint64_t, yOffset); 00244 DECLARE_ALIGNED(8, uint64_t, uOffset); 00245 DECLARE_ALIGNED(8, uint64_t, vOffset); 00246 int32_t lumMmxFilter[4*MAX_FILTER_SIZE]; 00247 int32_t chrMmxFilter[4*MAX_FILTER_SIZE]; 00248 int dstW; 00249 DECLARE_ALIGNED(8, uint64_t, esp); 00250 DECLARE_ALIGNED(8, uint64_t, vRounder); 00251 DECLARE_ALIGNED(8, uint64_t, u_temp); 00252 DECLARE_ALIGNED(8, uint64_t, v_temp); 00253 DECLARE_ALIGNED(8, uint64_t, y_temp); 00254 int32_t alpMmxFilter[4*MAX_FILTER_SIZE]; 00255 DECLARE_ALIGNED(8, ptrdiff_t, uv_off); 00256 DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); 00257 00258 #if HAVE_ALTIVEC 00259 vector signed short CY; 00260 vector signed short CRV; 00261 vector signed short CBU; 00262 vector signed short CGU; 00263 vector signed short CGV; 00264 vector signed short OY; 00265 vector unsigned short CSHIFT; 00266 vector signed short *vYCoeffsBank, *vCCoeffsBank; 00267 #endif 00268 00269 #if ARCH_BFIN 00270 DECLARE_ALIGNED(4, uint32_t, oy); 00271 DECLARE_ALIGNED(4, uint32_t, oc); 00272 DECLARE_ALIGNED(4, uint32_t, zero); 00273 DECLARE_ALIGNED(4, uint32_t, cy); 00274 DECLARE_ALIGNED(4, uint32_t, crv); 00275 DECLARE_ALIGNED(4, uint32_t, rmask); 00276 DECLARE_ALIGNED(4, uint32_t, cbu); 00277 DECLARE_ALIGNED(4, uint32_t, bmask); 00278 DECLARE_ALIGNED(4, uint32_t, cgu); 00279 DECLARE_ALIGNED(4, uint32_t, cgv); 00280 DECLARE_ALIGNED(4, uint32_t, gmask); 00281 #endif 00282 00283 #if HAVE_VIS 00284 DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10]; 00285 #endif 00286 00287 /* function pointers for swScale() */ 00288 yuv2planar1_fn yuv2yuv1; 00289 yuv2planarX_fn yuv2yuvX; 00290 yuv2packed1_fn yuv2packed1; 00291 yuv2packed2_fn yuv2packed2; 00292 yuv2packedX_fn yuv2packedX; 00293 00294 void (*lumToYV12)(uint8_t *dst, const uint8_t *src, 00295 int width, uint32_t *pal); 00296 void (*alpToYV12)(uint8_t *dst, const uint8_t *src, 00297 int width, uint32_t *pal); 00298 void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV, 00299 const uint8_t *src1, const uint8_t *src2, 00300 int width, uint32_t *pal); 00301 void (*hyscale_fast)(struct SwsContext *c, 00302 int16_t *dst, int dstWidth, 00303 const uint8_t *src, int srcW, int xInc); 00304 void (*hcscale_fast)(struct SwsContext *c, 00305 int16_t *dst1, int16_t *dst2, int dstWidth, 00306 const uint8_t *src1, const uint8_t *src2, 00307 int srcW, int xInc); 00308 00309 void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, 00310 int xInc, const int16_t *filter, const int16_t *filterPos, 00311 int filterSize); 00312 00313 void (*lumConvertRange)(int16_t *dst, int width); 00314 void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width); 00315 00316 int needs_hcscale; 00317 00318 } SwsContext; 00319 //FIXME check init (where 0) 00320 00321 SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c); 00322 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], 00323 int fullRange, int brightness, 00324 int contrast, int saturation); 00325 00326 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], 00327 int brightness, int contrast, int saturation); 00328 void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, 00329 int lastInLumBuf, int lastInChrBuf); 00330 00331 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c); 00332 SwsFunc ff_yuv2rgb_init_vis(SwsContext *c); 00333 SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c); 00334 SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c); 00335 SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c); 00336 void ff_bfin_get_unscaled_swscale(SwsContext *c); 00337 00338 const char *sws_format_name(enum PixelFormat format); 00339 00340 //FIXME replace this with something faster 00341 #define is16BPS(x) ( \ 00342 (x)==PIX_FMT_GRAY16BE \ 00343 || (x)==PIX_FMT_GRAY16LE \ 00344 || (x)==PIX_FMT_BGR48BE \ 00345 || (x)==PIX_FMT_BGR48LE \ 00346 || (x)==PIX_FMT_RGB48BE \ 00347 || (x)==PIX_FMT_RGB48LE \ 00348 || (x)==PIX_FMT_YUV420P16LE \ 00349 || (x)==PIX_FMT_YUV422P16LE \ 00350 || (x)==PIX_FMT_YUV444P16LE \ 00351 || (x)==PIX_FMT_YUV420P16BE \ 00352 || (x)==PIX_FMT_YUV422P16BE \ 00353 || (x)==PIX_FMT_YUV444P16BE \ 00354 ) 00355 #define is9_OR_10BPS(x) ( \ 00356 (x)==PIX_FMT_YUV420P9LE \ 00357 || (x)==PIX_FMT_YUV420P9BE \ 00358 || (x)==PIX_FMT_YUV444P9BE \ 00359 || (x)==PIX_FMT_YUV444P9LE \ 00360 || (x)==PIX_FMT_YUV422P10BE \ 00361 || (x)==PIX_FMT_YUV422P10LE \ 00362 || (x)==PIX_FMT_YUV444P10BE \ 00363 || (x)==PIX_FMT_YUV444P10LE \ 00364 || (x)==PIX_FMT_YUV420P10LE \ 00365 || (x)==PIX_FMT_YUV420P10BE \ 00366 ) 00367 #define isBE(x) ((x)&1) 00368 #define isPlanar8YUV(x) ( \ 00369 (x)==PIX_FMT_YUV410P \ 00370 || (x)==PIX_FMT_YUV420P \ 00371 || (x)==PIX_FMT_YUVA420P \ 00372 || (x)==PIX_FMT_YUV411P \ 00373 || (x)==PIX_FMT_YUV422P \ 00374 || (x)==PIX_FMT_YUV444P \ 00375 || (x)==PIX_FMT_YUV440P \ 00376 || (x)==PIX_FMT_NV12 \ 00377 || (x)==PIX_FMT_NV21 \ 00378 ) 00379 #define isPlanarYUV(x) ( \ 00380 isPlanar8YUV(x) \ 00381 || (x)==PIX_FMT_YUV420P9LE \ 00382 || (x)==PIX_FMT_YUV444P9LE \ 00383 || (x)==PIX_FMT_YUV420P10LE \ 00384 || (x)==PIX_FMT_YUV422P10LE \ 00385 || (x)==PIX_FMT_YUV444P10LE \ 00386 || (x)==PIX_FMT_YUV420P16LE \ 00387 || (x)==PIX_FMT_YUV422P16LE \ 00388 || (x)==PIX_FMT_YUV444P16LE \ 00389 || (x)==PIX_FMT_YUV420P9BE \ 00390 || (x)==PIX_FMT_YUV444P9BE \ 00391 || (x)==PIX_FMT_YUV420P10BE \ 00392 || (x)==PIX_FMT_YUV422P10BE \ 00393 || (x)==PIX_FMT_YUV444P10BE \ 00394 || (x)==PIX_FMT_YUV420P16BE \ 00395 || (x)==PIX_FMT_YUV422P16BE \ 00396 || (x)==PIX_FMT_YUV444P16BE \ 00397 ) 00398 #define isYUV(x) ( \ 00399 (x)==PIX_FMT_UYVY422 \ 00400 || (x)==PIX_FMT_YUYV422 \ 00401 || isPlanarYUV(x) \ 00402 ) 00403 #define isGray(x) ( \ 00404 (x)==PIX_FMT_GRAY8 \ 00405 || (x)==PIX_FMT_Y400A \ 00406 || (x)==PIX_FMT_GRAY16BE \ 00407 || (x)==PIX_FMT_GRAY16LE \ 00408 ) 00409 #define isGray16(x) ( \ 00410 (x)==PIX_FMT_GRAY16BE \ 00411 || (x)==PIX_FMT_GRAY16LE \ 00412 ) 00413 #define isRGBinInt(x) ( \ 00414 (x)==PIX_FMT_RGB48BE \ 00415 || (x)==PIX_FMT_RGB48LE \ 00416 || (x)==PIX_FMT_RGB32 \ 00417 || (x)==PIX_FMT_RGB32_1 \ 00418 || (x)==PIX_FMT_RGB24 \ 00419 || (x)==PIX_FMT_RGB565BE \ 00420 || (x)==PIX_FMT_RGB565LE \ 00421 || (x)==PIX_FMT_RGB555BE \ 00422 || (x)==PIX_FMT_RGB555LE \ 00423 || (x)==PIX_FMT_RGB444BE \ 00424 || (x)==PIX_FMT_RGB444LE \ 00425 || (x)==PIX_FMT_RGB8 \ 00426 || (x)==PIX_FMT_RGB4 \ 00427 || (x)==PIX_FMT_RGB4_BYTE \ 00428 || (x)==PIX_FMT_MONOBLACK \ 00429 || (x)==PIX_FMT_MONOWHITE \ 00430 ) 00431 #define isBGRinInt(x) ( \ 00432 (x)==PIX_FMT_BGR48BE \ 00433 || (x)==PIX_FMT_BGR48LE \ 00434 || (x)==PIX_FMT_BGR32 \ 00435 || (x)==PIX_FMT_BGR32_1 \ 00436 || (x)==PIX_FMT_BGR24 \ 00437 || (x)==PIX_FMT_BGR565BE \ 00438 || (x)==PIX_FMT_BGR565LE \ 00439 || (x)==PIX_FMT_BGR555BE \ 00440 || (x)==PIX_FMT_BGR555LE \ 00441 || (x)==PIX_FMT_BGR444BE \ 00442 || (x)==PIX_FMT_BGR444LE \ 00443 || (x)==PIX_FMT_BGR8 \ 00444 || (x)==PIX_FMT_BGR4 \ 00445 || (x)==PIX_FMT_BGR4_BYTE \ 00446 || (x)==PIX_FMT_MONOBLACK \ 00447 || (x)==PIX_FMT_MONOWHITE \ 00448 ) 00449 #define isRGBinBytes(x) ( \ 00450 (x)==PIX_FMT_RGB48BE \ 00451 || (x)==PIX_FMT_RGB48LE \ 00452 || (x)==PIX_FMT_RGBA \ 00453 || (x)==PIX_FMT_ARGB \ 00454 || (x)==PIX_FMT_RGB24 \ 00455 ) 00456 #define isBGRinBytes(x) ( \ 00457 (x)==PIX_FMT_BGR48BE \ 00458 || (x)==PIX_FMT_BGR48LE \ 00459 || (x)==PIX_FMT_BGRA \ 00460 || (x)==PIX_FMT_ABGR \ 00461 || (x)==PIX_FMT_BGR24 \ 00462 ) 00463 #define isAnyRGB(x) ( \ 00464 isRGBinInt(x) \ 00465 || isBGRinInt(x) \ 00466 ) 00467 #define isALPHA(x) ( \ 00468 (x)==PIX_FMT_BGR32 \ 00469 || (x)==PIX_FMT_BGR32_1 \ 00470 || (x)==PIX_FMT_RGB32 \ 00471 || (x)==PIX_FMT_RGB32_1 \ 00472 || (x)==PIX_FMT_Y400A \ 00473 || (x)==PIX_FMT_YUVA420P \ 00474 ) 00475 #define isPacked(x) ( \ 00476 (x)==PIX_FMT_PAL8 \ 00477 || (x)==PIX_FMT_YUYV422 \ 00478 || (x)==PIX_FMT_UYVY422 \ 00479 || (x)==PIX_FMT_Y400A \ 00480 || isAnyRGB(x) \ 00481 ) 00482 #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A) 00483 00484 extern const uint64_t ff_dither4[2]; 00485 extern const uint64_t ff_dither8[2]; 00486 00487 extern const AVClass sws_context_class; 00488 00493 void ff_get_unscaled_swscale(SwsContext *c); 00494 00495 void ff_swscale_get_unscaled_altivec(SwsContext *c); 00496 00501 SwsFunc ff_getSwsFunc(SwsContext *c); 00502 00503 void ff_sws_init_swScale_altivec(SwsContext *c); 00504 void ff_sws_init_swScale_mmx(SwsContext *c); 00505 00506 #endif /* SWSCALE_SWSCALE_INTERNAL_H */