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.

424 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. #ifdef WORDS_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 chrIntHSubSample, chrIntVSubSample;
  72. int chrDstHSubSample, chrDstVSubSample;
  73. int vChrDrop;
  74. int sliceDir;
  75. double param[2];
  76. uint32_t pal_yuv[256];
  77. uint32_t pal_rgb[256];
  78. int16_t **lumPixBuf;
  79. int16_t **chrPixBuf;
  80. int16_t **alpPixBuf;
  81. int16_t *hLumFilter;
  82. int16_t *hLumFilterPos;
  83. int16_t *hChrFilter;
  84. int16_t *hChrFilterPos;
  85. int16_t *vLumFilter;
  86. int16_t *vLumFilterPos;
  87. int16_t *vChrFilter;
  88. int16_t *vChrFilterPos;
  89. uint8_t formatConvBuffer[VOF]; //FIXME dynamic allocation, but we have to change a lot of code for this to be useful
  90. int hLumFilterSize;
  91. int hChrFilterSize;
  92. int vLumFilterSize;
  93. int vChrFilterSize;
  94. int vLumBufSize;
  95. int vChrBufSize;
  96. uint8_t *funnyYCode;
  97. uint8_t *funnyUVCode;
  98. int32_t *lumMmx2FilterPos;
  99. int32_t *chrMmx2FilterPos;
  100. int16_t *lumMmx2Filter;
  101. int16_t *chrMmx2Filter;
  102. int canMMX2BeUsed;
  103. int lastInLumBuf;
  104. int lastInChrBuf;
  105. int lumBufIndex;
  106. int chrBufIndex;
  107. int dstY;
  108. int flags;
  109. void * yuvTable; // pointer to the yuv->rgb table start so it can be freed()
  110. uint8_t * table_rV[256];
  111. uint8_t * table_gU[256];
  112. int table_gV[256];
  113. uint8_t * table_bU[256];
  114. //Colorspace stuff
  115. int contrast, brightness, saturation; // for sws_getColorspaceDetails
  116. int srcColorspaceTable[4];
  117. int dstColorspaceTable[4];
  118. int srcRange, dstRange;
  119. int yuv2rgb_y_offset;
  120. int yuv2rgb_y_coeff;
  121. int yuv2rgb_v2r_coeff;
  122. int yuv2rgb_v2g_coeff;
  123. int yuv2rgb_u2g_coeff;
  124. int yuv2rgb_u2b_coeff;
  125. #define RED_DITHER "0*8"
  126. #define GREEN_DITHER "1*8"
  127. #define BLUE_DITHER "2*8"
  128. #define Y_COEFF "3*8"
  129. #define VR_COEFF "4*8"
  130. #define UB_COEFF "5*8"
  131. #define VG_COEFF "6*8"
  132. #define UG_COEFF "7*8"
  133. #define Y_OFFSET "8*8"
  134. #define U_OFFSET "9*8"
  135. #define V_OFFSET "10*8"
  136. #define LUM_MMX_FILTER_OFFSET "11*8"
  137. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
  138. #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
  139. #define ESP_OFFSET "11*8+4*4*256*2+8"
  140. #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
  141. #define U_TEMP "11*8+4*4*256*2+24"
  142. #define V_TEMP "11*8+4*4*256*2+32"
  143. #define Y_TEMP "11*8+4*4*256*2+40"
  144. #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
  145. DECLARE_ALIGNED(8, uint64_t, redDither);
  146. DECLARE_ALIGNED(8, uint64_t, greenDither);
  147. DECLARE_ALIGNED(8, uint64_t, blueDither);
  148. DECLARE_ALIGNED(8, uint64_t, yCoeff);
  149. DECLARE_ALIGNED(8, uint64_t, vrCoeff);
  150. DECLARE_ALIGNED(8, uint64_t, ubCoeff);
  151. DECLARE_ALIGNED(8, uint64_t, vgCoeff);
  152. DECLARE_ALIGNED(8, uint64_t, ugCoeff);
  153. DECLARE_ALIGNED(8, uint64_t, yOffset);
  154. DECLARE_ALIGNED(8, uint64_t, uOffset);
  155. DECLARE_ALIGNED(8, uint64_t, vOffset);
  156. int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
  157. int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
  158. int dstW;
  159. DECLARE_ALIGNED(8, uint64_t, esp);
  160. DECLARE_ALIGNED(8, uint64_t, vRounder);
  161. DECLARE_ALIGNED(8, uint64_t, u_temp);
  162. DECLARE_ALIGNED(8, uint64_t, v_temp);
  163. DECLARE_ALIGNED(8, uint64_t, y_temp);
  164. int32_t alpMmxFilter[4*MAX_FILTER_SIZE];
  165. #if HAVE_ALTIVEC
  166. vector signed short CY;
  167. vector signed short CRV;
  168. vector signed short CBU;
  169. vector signed short CGU;
  170. vector signed short CGV;
  171. vector signed short OY;
  172. vector unsigned short CSHIFT;
  173. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  174. #endif
  175. #if ARCH_BFIN
  176. DECLARE_ALIGNED(4, uint32_t, oy);
  177. DECLARE_ALIGNED(4, uint32_t, oc);
  178. DECLARE_ALIGNED(4, uint32_t, zero);
  179. DECLARE_ALIGNED(4, uint32_t, cy);
  180. DECLARE_ALIGNED(4, uint32_t, crv);
  181. DECLARE_ALIGNED(4, uint32_t, rmask);
  182. DECLARE_ALIGNED(4, uint32_t, cbu);
  183. DECLARE_ALIGNED(4, uint32_t, bmask);
  184. DECLARE_ALIGNED(4, uint32_t, cgu);
  185. DECLARE_ALIGNED(4, uint32_t, cgv);
  186. DECLARE_ALIGNED(4, uint32_t, gmask);
  187. #endif
  188. #if HAVE_VIS
  189. DECLARE_ALIGNED(8, uint64_t, sparc_coeffs[10]);
  190. #endif
  191. /* function pointers for swScale() */
  192. void (*yuv2nv12X )(struct SwsContext *c,
  193. const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
  194. const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
  195. uint8_t *dest, uint8_t *uDest,
  196. int dstW, int chrDstW, int dstFormat);
  197. void (*yuv2yuv1 )(struct SwsContext *c,
  198. const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc,
  199. uint8_t *dest,
  200. uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
  201. long dstW, long chrDstW);
  202. void (*yuv2yuvX )(struct SwsContext *c,
  203. const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
  204. const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
  205. const int16_t **alpSrc,
  206. uint8_t *dest,
  207. uint8_t *uDest, uint8_t *vDest, uint8_t *aDest,
  208. long dstW, long chrDstW);
  209. void (*yuv2packed1)(struct SwsContext *c,
  210. const uint16_t *buf0,
  211. const uint16_t *uvbuf0, const uint16_t *uvbuf1,
  212. const uint16_t *abuf0,
  213. uint8_t *dest,
  214. int dstW, int uvalpha, int dstFormat, int flags, int y);
  215. void (*yuv2packed2)(struct SwsContext *c,
  216. const uint16_t *buf0, const uint16_t *buf1,
  217. const uint16_t *uvbuf0, const uint16_t *uvbuf1,
  218. const uint16_t *abuf0, const uint16_t *abuf1,
  219. uint8_t *dest,
  220. int dstW, int yalpha, int uvalpha, int y);
  221. void (*yuv2packedX)(struct SwsContext *c,
  222. const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize,
  223. const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize,
  224. const int16_t **alpSrc, uint8_t *dest,
  225. long dstW, long dstY);
  226. void (*hyscale_internal)(uint8_t *dst, const uint8_t *src,
  227. long width, uint32_t *pal);
  228. void (*hascale_internal)(uint8_t *dst, const uint8_t *src,
  229. long width, uint32_t *pal);
  230. void (*hcscale_internal)(uint8_t *dstU, uint8_t *dstV,
  231. const uint8_t *src1, const uint8_t *src2,
  232. long width, uint32_t *pal);
  233. void (*hyscale_fast)(struct SwsContext *c,
  234. int16_t *dst, int dstWidth,
  235. const uint8_t *src, int srcW, int xInc);
  236. void (*hcscale_fast)(struct SwsContext *c,
  237. int16_t *dst, int dstWidth,
  238. const uint8_t *src1, const uint8_t *src2,
  239. int srcW, int xInc);
  240. void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW,
  241. int xInc, const int16_t *filter, const int16_t *filterPos,
  242. long filterSize);
  243. } SwsContext;
  244. //FIXME check init (where 0)
  245. SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
  246. int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
  247. int fullRange, int brightness,
  248. int contrast, int saturation);
  249. void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
  250. int brightness, int contrast, int saturation);
  251. SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
  252. SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
  253. SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
  254. SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
  255. SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
  256. void ff_bfin_get_unscaled_swscale(SwsContext *c);
  257. void ff_yuv2packedX_altivec(SwsContext *c,
  258. const int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  259. const int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
  260. uint8_t *dest, int dstW, int dstY);
  261. const char *sws_format_name(int format);
  262. //FIXME replace this with something faster
  263. #define is16BPS(x) ( \
  264. (x)==PIX_FMT_GRAY16BE \
  265. || (x)==PIX_FMT_GRAY16LE \
  266. || (x)==PIX_FMT_RGB48BE \
  267. || (x)==PIX_FMT_RGB48LE \
  268. || (x)==PIX_FMT_YUV420PLE \
  269. || (x)==PIX_FMT_YUV422PLE \
  270. || (x)==PIX_FMT_YUV444PLE \
  271. || (x)==PIX_FMT_YUV420PBE \
  272. || (x)==PIX_FMT_YUV422PBE \
  273. || (x)==PIX_FMT_YUV444PBE \
  274. )
  275. #define isBE(x) ((x)&1)
  276. #define isPlanar8YUV(x) ( \
  277. (x)==PIX_FMT_YUV410P \
  278. || (x)==PIX_FMT_YUV420P \
  279. || (x)==PIX_FMT_YUVA420P \
  280. || (x)==PIX_FMT_YUV411P \
  281. || (x)==PIX_FMT_YUV422P \
  282. || (x)==PIX_FMT_YUV444P \
  283. || (x)==PIX_FMT_YUV440P \
  284. || (x)==PIX_FMT_NV12 \
  285. || (x)==PIX_FMT_NV21 \
  286. )
  287. #define isPlanarYUV(x) ( \
  288. isPlanar8YUV(x) \
  289. || (x)==PIX_FMT_YUV420PLE \
  290. || (x)==PIX_FMT_YUV422PLE \
  291. || (x)==PIX_FMT_YUV444PLE \
  292. || (x)==PIX_FMT_YUV420PBE \
  293. || (x)==PIX_FMT_YUV422PBE \
  294. || (x)==PIX_FMT_YUV444PBE \
  295. )
  296. #define isYUV(x) ( \
  297. (x)==PIX_FMT_UYVY422 \
  298. || (x)==PIX_FMT_YUYV422 \
  299. || isPlanarYUV(x) \
  300. )
  301. #define isGray(x) ( \
  302. (x)==PIX_FMT_GRAY8 \
  303. || (x)==PIX_FMT_GRAY16BE \
  304. || (x)==PIX_FMT_GRAY16LE \
  305. )
  306. #define isGray16(x) ( \
  307. (x)==PIX_FMT_GRAY16BE \
  308. || (x)==PIX_FMT_GRAY16LE \
  309. )
  310. #define isRGB(x) ( \
  311. (x)==PIX_FMT_RGB48BE \
  312. || (x)==PIX_FMT_RGB48LE \
  313. || (x)==PIX_FMT_RGB32 \
  314. || (x)==PIX_FMT_RGB32_1 \
  315. || (x)==PIX_FMT_RGB24 \
  316. || (x)==PIX_FMT_RGB565 \
  317. || (x)==PIX_FMT_RGB555 \
  318. || (x)==PIX_FMT_RGB8 \
  319. || (x)==PIX_FMT_RGB4 \
  320. || (x)==PIX_FMT_RGB4_BYTE \
  321. || (x)==PIX_FMT_MONOBLACK \
  322. || (x)==PIX_FMT_MONOWHITE \
  323. )
  324. #define isBGR(x) ( \
  325. (x)==PIX_FMT_BGR32 \
  326. || (x)==PIX_FMT_BGR32_1 \
  327. || (x)==PIX_FMT_BGR24 \
  328. || (x)==PIX_FMT_BGR565 \
  329. || (x)==PIX_FMT_BGR555 \
  330. || (x)==PIX_FMT_BGR8 \
  331. || (x)==PIX_FMT_BGR4 \
  332. || (x)==PIX_FMT_BGR4_BYTE \
  333. || (x)==PIX_FMT_MONOBLACK \
  334. || (x)==PIX_FMT_MONOWHITE \
  335. )
  336. #define isALPHA(x) ( \
  337. (x)==PIX_FMT_BGR32 \
  338. || (x)==PIX_FMT_BGR32_1 \
  339. || (x)==PIX_FMT_RGB32 \
  340. || (x)==PIX_FMT_RGB32_1 \
  341. || (x)==PIX_FMT_YUVA420P \
  342. )
  343. static inline int fmt_depth(int fmt)
  344. {
  345. switch(fmt) {
  346. case PIX_FMT_RGB48BE:
  347. case PIX_FMT_RGB48LE:
  348. return 48;
  349. case PIX_FMT_BGRA:
  350. case PIX_FMT_ABGR:
  351. case PIX_FMT_RGBA:
  352. case PIX_FMT_ARGB:
  353. return 32;
  354. case PIX_FMT_BGR24:
  355. case PIX_FMT_RGB24:
  356. return 24;
  357. case PIX_FMT_BGR565:
  358. case PIX_FMT_RGB565:
  359. case PIX_FMT_GRAY16BE:
  360. case PIX_FMT_GRAY16LE:
  361. return 16;
  362. case PIX_FMT_BGR555:
  363. case PIX_FMT_RGB555:
  364. return 15;
  365. case PIX_FMT_BGR8:
  366. case PIX_FMT_RGB8:
  367. return 8;
  368. case PIX_FMT_BGR4:
  369. case PIX_FMT_RGB4:
  370. case PIX_FMT_BGR4_BYTE:
  371. case PIX_FMT_RGB4_BYTE:
  372. return 4;
  373. case PIX_FMT_MONOBLACK:
  374. case PIX_FMT_MONOWHITE:
  375. return 1;
  376. default:
  377. return 0;
  378. }
  379. }
  380. extern const uint64_t ff_dither4[2];
  381. extern const uint64_t ff_dither8[2];
  382. extern const AVClass sws_context_class;
  383. #endif /* SWSCALE_SWSCALE_INTERNAL_H */