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.

387 lines
13KB

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