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.

417 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. uint64_t redDither __attribute__((aligned(8)));
  146. uint64_t greenDither __attribute__((aligned(8)));
  147. uint64_t blueDither __attribute__((aligned(8)));
  148. uint64_t yCoeff __attribute__((aligned(8)));
  149. uint64_t vrCoeff __attribute__((aligned(8)));
  150. uint64_t ubCoeff __attribute__((aligned(8)));
  151. uint64_t vgCoeff __attribute__((aligned(8)));
  152. uint64_t ugCoeff __attribute__((aligned(8)));
  153. uint64_t yOffset __attribute__((aligned(8)));
  154. uint64_t uOffset __attribute__((aligned(8)));
  155. uint64_t vOffset __attribute__((aligned(8)));
  156. int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
  157. int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
  158. int dstW;
  159. uint64_t esp __attribute__((aligned(8)));
  160. uint64_t vRounder __attribute__((aligned(8)));
  161. uint64_t u_temp __attribute__((aligned(8)));
  162. uint64_t v_temp __attribute__((aligned(8)));
  163. uint64_t y_temp __attribute__((aligned(8)));
  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. uint32_t oy __attribute__((aligned(4)));
  177. uint32_t oc __attribute__((aligned(4)));
  178. uint32_t zero __attribute__((aligned(4)));
  179. uint32_t cy __attribute__((aligned(4)));
  180. uint32_t crv __attribute__((aligned(4)));
  181. uint32_t rmask __attribute__((aligned(4)));
  182. uint32_t cbu __attribute__((aligned(4)));
  183. uint32_t bmask __attribute__((aligned(4)));
  184. uint32_t cgu __attribute__((aligned(4)));
  185. uint32_t cgv __attribute__((aligned(4)));
  186. uint32_t gmask __attribute__((aligned(4)));
  187. #endif
  188. #if HAVE_VIS
  189. uint64_t sparc_coeffs[10] __attribute__((aligned(8)));
  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. int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  259. 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_YUV420PLE \
  267. || (x)==PIX_FMT_YUV422PLE \
  268. || (x)==PIX_FMT_YUV444PLE \
  269. || (x)==PIX_FMT_YUV420PBE \
  270. || (x)==PIX_FMT_YUV422PBE \
  271. || (x)==PIX_FMT_YUV444PBE \
  272. )
  273. #define isBE(x) ((x)&1)
  274. #define isPlanar8YUV(x) ( \
  275. (x)==PIX_FMT_YUV410P \
  276. || (x)==PIX_FMT_YUV420P \
  277. || (x)==PIX_FMT_YUVA420P \
  278. || (x)==PIX_FMT_YUV411P \
  279. || (x)==PIX_FMT_YUV422P \
  280. || (x)==PIX_FMT_YUV444P \
  281. || (x)==PIX_FMT_YUV440P \
  282. || (x)==PIX_FMT_NV12 \
  283. || (x)==PIX_FMT_NV21 \
  284. )
  285. #define isPlanarYUV(x) ( \
  286. isPlanar8YUV(x) \
  287. || (x)==PIX_FMT_YUV420PLE \
  288. || (x)==PIX_FMT_YUV422PLE \
  289. || (x)==PIX_FMT_YUV444PLE \
  290. || (x)==PIX_FMT_YUV420PBE \
  291. || (x)==PIX_FMT_YUV422PBE \
  292. || (x)==PIX_FMT_YUV444PBE \
  293. )
  294. #define isYUV(x) ( \
  295. (x)==PIX_FMT_UYVY422 \
  296. || (x)==PIX_FMT_YUYV422 \
  297. || isPlanarYUV(x) \
  298. )
  299. #define isGray(x) ( \
  300. (x)==PIX_FMT_GRAY8 \
  301. || (x)==PIX_FMT_GRAY16BE \
  302. || (x)==PIX_FMT_GRAY16LE \
  303. )
  304. #define isGray16(x) ( \
  305. (x)==PIX_FMT_GRAY16BE \
  306. || (x)==PIX_FMT_GRAY16LE \
  307. )
  308. #define isRGB(x) ( \
  309. (x)==PIX_FMT_RGB32 \
  310. || (x)==PIX_FMT_RGB32_1 \
  311. || (x)==PIX_FMT_RGB24 \
  312. || (x)==PIX_FMT_RGB565 \
  313. || (x)==PIX_FMT_RGB555 \
  314. || (x)==PIX_FMT_RGB8 \
  315. || (x)==PIX_FMT_RGB4 \
  316. || (x)==PIX_FMT_RGB4_BYTE \
  317. || (x)==PIX_FMT_MONOBLACK \
  318. || (x)==PIX_FMT_MONOWHITE \
  319. )
  320. #define isBGR(x) ( \
  321. (x)==PIX_FMT_BGR32 \
  322. || (x)==PIX_FMT_BGR32_1 \
  323. || (x)==PIX_FMT_BGR24 \
  324. || (x)==PIX_FMT_BGR565 \
  325. || (x)==PIX_FMT_BGR555 \
  326. || (x)==PIX_FMT_BGR8 \
  327. || (x)==PIX_FMT_BGR4 \
  328. || (x)==PIX_FMT_BGR4_BYTE \
  329. || (x)==PIX_FMT_MONOBLACK \
  330. || (x)==PIX_FMT_MONOWHITE \
  331. )
  332. #define isALPHA(x) ( \
  333. (x)==PIX_FMT_BGR32 \
  334. || (x)==PIX_FMT_BGR32_1 \
  335. || (x)==PIX_FMT_RGB32 \
  336. || (x)==PIX_FMT_RGB32_1 \
  337. || (x)==PIX_FMT_YUVA420P \
  338. )
  339. static inline int fmt_depth(int fmt)
  340. {
  341. switch(fmt) {
  342. case PIX_FMT_BGRA:
  343. case PIX_FMT_ABGR:
  344. case PIX_FMT_RGBA:
  345. case PIX_FMT_ARGB:
  346. return 32;
  347. case PIX_FMT_BGR24:
  348. case PIX_FMT_RGB24:
  349. return 24;
  350. case PIX_FMT_BGR565:
  351. case PIX_FMT_RGB565:
  352. case PIX_FMT_GRAY16BE:
  353. case PIX_FMT_GRAY16LE:
  354. return 16;
  355. case PIX_FMT_BGR555:
  356. case PIX_FMT_RGB555:
  357. return 15;
  358. case PIX_FMT_BGR8:
  359. case PIX_FMT_RGB8:
  360. return 8;
  361. case PIX_FMT_BGR4:
  362. case PIX_FMT_RGB4:
  363. case PIX_FMT_BGR4_BYTE:
  364. case PIX_FMT_RGB4_BYTE:
  365. return 4;
  366. case PIX_FMT_MONOBLACK:
  367. case PIX_FMT_MONOWHITE:
  368. return 1;
  369. default:
  370. return 0;
  371. }
  372. }
  373. extern const uint64_t ff_dither4[2];
  374. extern const uint64_t ff_dither8[2];
  375. extern const AVClass sws_context_class;
  376. #endif /* SWSCALE_SWSCALE_INTERNAL_H */