You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

425 lines
14KB

  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef SWSCALE_SWSCALE_INTERNAL_H
  21. #define SWSCALE_SWSCALE_INTERNAL_H
  22. #include "config.h"
  23. #if HAVE_ALTIVEC_H
  24. #include <altivec.h>
  25. #endif
  26. #include "libavutil/avutil.h"
  27. #define STR(s) AV_TOSTRING(s) //AV_STRINGIFY is too long
  28. #define MAX_FILTER_SIZE 256
  29. #if ARCH_X86
  30. #define VOFW 5120
  31. #else
  32. #define VOFW 2048 // faster on PPC and not tested on others
  33. #endif
  34. #define VOF (VOFW*2)
  35. #if HAVE_BIGENDIAN
  36. #define ALT32_CORR (-1)
  37. #else
  38. #define ALT32_CORR 1
  39. #endif
  40. #if ARCH_X86_64
  41. # define APCK_PTR2 8
  42. # define APCK_COEF 16
  43. # define APCK_SIZE 24
  44. #else
  45. # define APCK_PTR2 4
  46. # define APCK_COEF 8
  47. # define APCK_SIZE 16
  48. #endif
  49. struct SwsContext;
  50. typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[],
  51. int srcStride[], int srcSliceY, int srcSliceH,
  52. uint8_t* dst[], int dstStride[]);
  53. /* This struct should be aligned on at least a 32-byte boundary. */
  54. typedef struct SwsContext {
  55. /**
  56. * info on struct for av_log
  57. */
  58. const AVClass *av_class;
  59. /**
  60. * Note that src, dst, srcStride, dstStride will be copied in the
  61. * sws_scale() wrapper so they can be freely modified here.
  62. */
  63. SwsFunc swScale;
  64. int srcW, srcH, dstH;
  65. int chrSrcW, chrSrcH, chrDstW, chrDstH;
  66. int lumXInc, chrXInc;
  67. int lumYInc, chrYInc;
  68. enum PixelFormat dstFormat, srcFormat; ///< format 4:2:0 type is always YV12
  69. int origDstFormat, origSrcFormat; ///< format
  70. int chrSrcHSubSample, chrSrcVSubSample;
  71. int chrDstHSubSample, chrDstVSubSample;
  72. int vChrDrop;
  73. int sliceDir;
  74. double param[2];
  75. uint32_t pal_yuv[256];
  76. uint32_t pal_rgb[256];
  77. int16_t **lumPixBuf;
  78. int16_t **chrPixBuf;
  79. int16_t **alpPixBuf;
  80. int16_t *hLumFilter;
  81. int16_t *hLumFilterPos;
  82. int16_t *hChrFilter;
  83. int16_t *hChrFilterPos;
  84. int16_t *vLumFilter;
  85. int16_t *vLumFilterPos;
  86. int16_t *vChrFilter;
  87. int16_t *vChrFilterPos;
  88. uint8_t formatConvBuffer[VOF]; //FIXME dynamic allocation, but we have to change a lot of code for this to be useful
  89. int hLumFilterSize;
  90. int hChrFilterSize;
  91. int vLumFilterSize;
  92. int vChrFilterSize;
  93. int vLumBufSize;
  94. int vChrBufSize;
  95. int lumMmx2FilterCodeSize;
  96. int chrMmx2FilterCodeSize;
  97. uint8_t *lumMmx2FilterCode;
  98. uint8_t *chrMmx2FilterCode;
  99. int32_t *lumMmx2FilterPos;
  100. int32_t *chrMmx2FilterPos;
  101. int16_t *lumMmx2Filter;
  102. int16_t *chrMmx2Filter;
  103. int canMMX2BeUsed;
  104. int lastInLumBuf;
  105. int lastInChrBuf;
  106. int lumBufIndex;
  107. int chrBufIndex;
  108. int dstY;
  109. int flags;
  110. void * yuvTable; // pointer to the yuv->rgb table start so it can be freed()
  111. uint8_t * table_rV[256];
  112. uint8_t * table_gU[256];
  113. int table_gV[256];
  114. uint8_t * table_bU[256];
  115. //Colorspace stuff
  116. int contrast, brightness, saturation; // for sws_getColorspaceDetails
  117. int srcColorspaceTable[4];
  118. int dstColorspaceTable[4];
  119. int srcRange, dstRange;
  120. int yuv2rgb_y_offset;
  121. int yuv2rgb_y_coeff;
  122. int yuv2rgb_v2r_coeff;
  123. int yuv2rgb_v2g_coeff;
  124. int yuv2rgb_u2g_coeff;
  125. int yuv2rgb_u2b_coeff;
  126. #define RED_DITHER "0*8"
  127. #define GREEN_DITHER "1*8"
  128. #define BLUE_DITHER "2*8"
  129. #define Y_COEFF "3*8"
  130. #define VR_COEFF "4*8"
  131. #define UB_COEFF "5*8"
  132. #define VG_COEFF "6*8"
  133. #define UG_COEFF "7*8"
  134. #define Y_OFFSET "8*8"
  135. #define U_OFFSET "9*8"
  136. #define V_OFFSET "10*8"
  137. #define LUM_MMX_FILTER_OFFSET "11*8"
  138. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
  139. #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
  140. #define ESP_OFFSET "11*8+4*4*256*2+8"
  141. #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
  142. #define U_TEMP "11*8+4*4*256*2+24"
  143. #define V_TEMP "11*8+4*4*256*2+32"
  144. #define Y_TEMP "11*8+4*4*256*2+40"
  145. #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
  146. DECLARE_ALIGNED(8, uint64_t, redDither);
  147. DECLARE_ALIGNED(8, uint64_t, greenDither);
  148. DECLARE_ALIGNED(8, uint64_t, blueDither);
  149. DECLARE_ALIGNED(8, uint64_t, yCoeff);
  150. DECLARE_ALIGNED(8, uint64_t, vrCoeff);
  151. DECLARE_ALIGNED(8, uint64_t, ubCoeff);
  152. DECLARE_ALIGNED(8, uint64_t, vgCoeff);
  153. DECLARE_ALIGNED(8, uint64_t, ugCoeff);
  154. DECLARE_ALIGNED(8, uint64_t, yOffset);
  155. DECLARE_ALIGNED(8, uint64_t, uOffset);
  156. DECLARE_ALIGNED(8, uint64_t, vOffset);
  157. int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
  158. int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
  159. int dstW;
  160. DECLARE_ALIGNED(8, uint64_t, esp);
  161. DECLARE_ALIGNED(8, uint64_t, vRounder);
  162. DECLARE_ALIGNED(8, uint64_t, u_temp);
  163. DECLARE_ALIGNED(8, uint64_t, v_temp);
  164. DECLARE_ALIGNED(8, uint64_t, y_temp);
  165. int32_t alpMmxFilter[4*MAX_FILTER_SIZE];
  166. #if HAVE_ALTIVEC
  167. vector signed short CY;
  168. vector signed short CRV;
  169. vector signed short CBU;
  170. vector signed short CGU;
  171. vector signed short CGV;
  172. vector signed short OY;
  173. vector unsigned short CSHIFT;
  174. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  175. #endif
  176. #if ARCH_BFIN
  177. DECLARE_ALIGNED(4, uint32_t, oy);
  178. DECLARE_ALIGNED(4, uint32_t, oc);
  179. DECLARE_ALIGNED(4, uint32_t, zero);
  180. DECLARE_ALIGNED(4, uint32_t, cy);
  181. DECLARE_ALIGNED(4, uint32_t, crv);
  182. DECLARE_ALIGNED(4, uint32_t, rmask);
  183. DECLARE_ALIGNED(4, uint32_t, cbu);
  184. DECLARE_ALIGNED(4, uint32_t, bmask);
  185. DECLARE_ALIGNED(4, uint32_t, cgu);
  186. DECLARE_ALIGNED(4, uint32_t, cgv);
  187. DECLARE_ALIGNED(4, uint32_t, gmask);
  188. #endif
  189. #if HAVE_VIS
  190. DECLARE_ALIGNED(8, uint64_t, sparc_coeffs[10]);
  191. #endif
  192. /* function pointers for swScale() */
  193. void (*yuv2nv12X )(struct SwsContext *c,
  194. const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
  195. const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
  196. uint8_t *dest, uint8_t *uDest,
  197. int dstW, int chrDstW, int dstFormat);
  198. void (*yuv2yuv1 )(struct SwsContext *c,
  199. const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc,
  200. uint8_t *dest,
  201. uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
  202. long dstW, long chrDstW);
  203. void (*yuv2yuvX )(struct SwsContext *c,
  204. const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
  205. const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
  206. const int16_t **alpSrc,
  207. uint8_t *dest,
  208. uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
  209. long dstW, long chrDstW);
  210. void (*yuv2packed1)(struct SwsContext *c,
  211. const uint16_t *buf0,
  212. const uint16_t *uvbuf0, const uint16_t *uvbuf1,
  213. const uint16_t *abuf0,
  214. uint8_t *dest,
  215. int dstW, int uvalpha, int dstFormat, int flags, int y);
  216. void (*yuv2packed2)(struct SwsContext *c,
  217. const uint16_t *buf0, const uint16_t *buf1,
  218. const uint16_t *uvbuf0, const uint16_t *uvbuf1,
  219. const uint16_t *abuf0, const uint16_t *abuf1,
  220. uint8_t *dest,
  221. int dstW, int yalpha, int uvalpha, int y);
  222. void (*yuv2packedX)(struct SwsContext *c,
  223. const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
  224. const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
  225. const int16_t **alpSrc, uint8_t *dest,
  226. long dstW, long dstY);
  227. void (*hyscale_internal)(uint8_t *dst, const uint8_t *src,
  228. long width, uint32_t *pal);
  229. void (*hascale_internal)(uint8_t *dst, const uint8_t *src,
  230. long width, uint32_t *pal);
  231. void (*hcscale_internal)(uint8_t *dstU, uint8_t *dstV,
  232. const uint8_t *src1, const uint8_t *src2,
  233. long width, uint32_t *pal);
  234. void (*hyscale_fast)(struct SwsContext *c,
  235. int16_t *dst, int dstWidth,
  236. const uint8_t *src, int srcW, int xInc);
  237. void (*hcscale_fast)(struct SwsContext *c,
  238. int16_t *dst, int dstWidth,
  239. const uint8_t *src1, const uint8_t *src2,
  240. int srcW, int xInc);
  241. void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW,
  242. int xInc, const int16_t *filter, const int16_t *filterPos,
  243. long filterSize);
  244. } SwsContext;
  245. //FIXME check init (where 0)
  246. SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
  247. int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
  248. int fullRange, int brightness,
  249. int contrast, int saturation);
  250. void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
  251. int brightness, int contrast, int saturation);
  252. SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
  253. SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
  254. SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
  255. SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
  256. SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
  257. void ff_bfin_get_unscaled_swscale(SwsContext *c);
  258. void ff_yuv2packedX_altivec(SwsContext *c,
  259. const int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  260. const int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
  261. uint8_t *dest, int dstW, int dstY);
  262. const char *sws_format_name(enum PixelFormat format);
  263. //FIXME replace this with something faster
  264. #define is16BPS(x) ( \
  265. (x)==PIX_FMT_GRAY16BE \
  266. || (x)==PIX_FMT_GRAY16LE \
  267. || (x)==PIX_FMT_RGB48BE \
  268. || (x)==PIX_FMT_RGB48LE \
  269. || (x)==PIX_FMT_YUV420P16LE \
  270. || (x)==PIX_FMT_YUV422P16LE \
  271. || (x)==PIX_FMT_YUV444P16LE \
  272. || (x)==PIX_FMT_YUV420P16BE \
  273. || (x)==PIX_FMT_YUV422P16BE \
  274. || (x)==PIX_FMT_YUV444P16BE \
  275. )
  276. #define isBE(x) ((x)&1)
  277. #define isPlanar8YUV(x) ( \
  278. (x)==PIX_FMT_YUV410P \
  279. || (x)==PIX_FMT_YUV420P \
  280. || (x)==PIX_FMT_YUVA420P \
  281. || (x)==PIX_FMT_YUV411P \
  282. || (x)==PIX_FMT_YUV422P \
  283. || (x)==PIX_FMT_YUV444P \
  284. || (x)==PIX_FMT_YUV440P \
  285. || (x)==PIX_FMT_NV12 \
  286. || (x)==PIX_FMT_NV21 \
  287. )
  288. #define isPlanarYUV(x) ( \
  289. isPlanar8YUV(x) \
  290. || (x)==PIX_FMT_YUV420P16LE \
  291. || (x)==PIX_FMT_YUV422P16LE \
  292. || (x)==PIX_FMT_YUV444P16LE \
  293. || (x)==PIX_FMT_YUV420P16BE \
  294. || (x)==PIX_FMT_YUV422P16BE \
  295. || (x)==PIX_FMT_YUV444P16BE \
  296. )
  297. #define isYUV(x) ( \
  298. (x)==PIX_FMT_UYVY422 \
  299. || (x)==PIX_FMT_YUYV422 \
  300. || isPlanarYUV(x) \
  301. )
  302. #define isGray(x) ( \
  303. (x)==PIX_FMT_GRAY8 \
  304. || (x)==PIX_FMT_GRAY16BE \
  305. || (x)==PIX_FMT_GRAY16LE \
  306. )
  307. #define isGray16(x) ( \
  308. (x)==PIX_FMT_GRAY16BE \
  309. || (x)==PIX_FMT_GRAY16LE \
  310. )
  311. #define isRGB(x) ( \
  312. (x)==PIX_FMT_RGB48BE \
  313. || (x)==PIX_FMT_RGB48LE \
  314. || (x)==PIX_FMT_RGB32 \
  315. || (x)==PIX_FMT_RGB32_1 \
  316. || (x)==PIX_FMT_RGB24 \
  317. || (x)==PIX_FMT_RGB565 \
  318. || (x)==PIX_FMT_RGB555 \
  319. || (x)==PIX_FMT_RGB8 \
  320. || (x)==PIX_FMT_RGB4 \
  321. || (x)==PIX_FMT_RGB4_BYTE \
  322. || (x)==PIX_FMT_MONOBLACK \
  323. || (x)==PIX_FMT_MONOWHITE \
  324. )
  325. #define isBGR(x) ( \
  326. (x)==PIX_FMT_BGR32 \
  327. || (x)==PIX_FMT_BGR32_1 \
  328. || (x)==PIX_FMT_BGR24 \
  329. || (x)==PIX_FMT_BGR565 \
  330. || (x)==PIX_FMT_BGR555 \
  331. || (x)==PIX_FMT_BGR8 \
  332. || (x)==PIX_FMT_BGR4 \
  333. || (x)==PIX_FMT_BGR4_BYTE \
  334. || (x)==PIX_FMT_MONOBLACK \
  335. || (x)==PIX_FMT_MONOWHITE \
  336. )
  337. #define isALPHA(x) ( \
  338. (x)==PIX_FMT_BGR32 \
  339. || (x)==PIX_FMT_BGR32_1 \
  340. || (x)==PIX_FMT_RGB32 \
  341. || (x)==PIX_FMT_RGB32_1 \
  342. || (x)==PIX_FMT_YUVA420P \
  343. )
  344. static inline int fmt_depth(int fmt)
  345. {
  346. switch(fmt) {
  347. case PIX_FMT_RGB48BE:
  348. case PIX_FMT_RGB48LE:
  349. return 48;
  350. case PIX_FMT_BGRA:
  351. case PIX_FMT_ABGR:
  352. case PIX_FMT_RGBA:
  353. case PIX_FMT_ARGB:
  354. return 32;
  355. case PIX_FMT_BGR24:
  356. case PIX_FMT_RGB24:
  357. return 24;
  358. case PIX_FMT_BGR565:
  359. case PIX_FMT_RGB565:
  360. case PIX_FMT_GRAY16BE:
  361. case PIX_FMT_GRAY16LE:
  362. return 16;
  363. case PIX_FMT_BGR555:
  364. case PIX_FMT_RGB555:
  365. return 15;
  366. case PIX_FMT_BGR8:
  367. case PIX_FMT_RGB8:
  368. return 8;
  369. case PIX_FMT_BGR4:
  370. case PIX_FMT_RGB4:
  371. case PIX_FMT_BGR4_BYTE:
  372. case PIX_FMT_RGB4_BYTE:
  373. return 4;
  374. case PIX_FMT_MONOBLACK:
  375. case PIX_FMT_MONOWHITE:
  376. return 1;
  377. default:
  378. return 0;
  379. }
  380. }
  381. extern const uint64_t ff_dither4[2];
  382. extern const uint64_t ff_dither8[2];
  383. extern const AVClass sws_context_class;
  384. #endif /* SWSCALE_SWSCALE_INTERNAL_H */