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.

336 lines
10KB

  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. } SwsContext;
  187. //FIXME check init (where 0)
  188. SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
  189. int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation);
  190. void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], int brightness, int contrast, int saturation);
  191. SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
  192. SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
  193. SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c);
  194. SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
  195. SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
  196. void ff_bfin_get_unscaled_swscale(SwsContext *c);
  197. void ff_yuv2packedX_altivec(SwsContext *c,
  198. int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  199. int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
  200. uint8_t *dest, int dstW, int dstY);
  201. const char *sws_format_name(int format);
  202. //FIXME replace this with something faster
  203. #define isPlanarYUV(x) ( \
  204. (x)==PIX_FMT_YUV410P \
  205. || (x)==PIX_FMT_YUV420P \
  206. || (x)==PIX_FMT_YUVA420P \
  207. || (x)==PIX_FMT_YUV411P \
  208. || (x)==PIX_FMT_YUV422P \
  209. || (x)==PIX_FMT_YUV444P \
  210. || (x)==PIX_FMT_YUV440P \
  211. || (x)==PIX_FMT_NV12 \
  212. || (x)==PIX_FMT_NV21 \
  213. )
  214. #define isYUV(x) ( \
  215. (x)==PIX_FMT_UYVY422 \
  216. || (x)==PIX_FMT_YUYV422 \
  217. || isPlanarYUV(x) \
  218. )
  219. #define isGray(x) ( \
  220. (x)==PIX_FMT_GRAY8 \
  221. || (x)==PIX_FMT_GRAY16BE \
  222. || (x)==PIX_FMT_GRAY16LE \
  223. )
  224. #define isGray16(x) ( \
  225. (x)==PIX_FMT_GRAY16BE \
  226. || (x)==PIX_FMT_GRAY16LE \
  227. )
  228. #define isRGB(x) ( \
  229. (x)==PIX_FMT_RGB32 \
  230. || (x)==PIX_FMT_RGB32_1 \
  231. || (x)==PIX_FMT_RGB24 \
  232. || (x)==PIX_FMT_RGB565 \
  233. || (x)==PIX_FMT_RGB555 \
  234. || (x)==PIX_FMT_RGB8 \
  235. || (x)==PIX_FMT_RGB4 \
  236. || (x)==PIX_FMT_RGB4_BYTE \
  237. || (x)==PIX_FMT_MONOBLACK \
  238. || (x)==PIX_FMT_MONOWHITE \
  239. )
  240. #define isBGR(x) ( \
  241. (x)==PIX_FMT_BGR32 \
  242. || (x)==PIX_FMT_BGR32_1 \
  243. || (x)==PIX_FMT_BGR24 \
  244. || (x)==PIX_FMT_BGR565 \
  245. || (x)==PIX_FMT_BGR555 \
  246. || (x)==PIX_FMT_BGR8 \
  247. || (x)==PIX_FMT_BGR4 \
  248. || (x)==PIX_FMT_BGR4_BYTE \
  249. || (x)==PIX_FMT_MONOBLACK \
  250. || (x)==PIX_FMT_MONOWHITE \
  251. )
  252. #define isALPHA(x) ( \
  253. (x)==PIX_FMT_BGR32 \
  254. || (x)==PIX_FMT_BGR32_1 \
  255. || (x)==PIX_FMT_RGB32 \
  256. || (x)==PIX_FMT_RGB32_1 \
  257. || (x)==PIX_FMT_YUVA420P \
  258. )
  259. static inline int fmt_depth(int fmt)
  260. {
  261. switch(fmt) {
  262. case PIX_FMT_BGRA:
  263. case PIX_FMT_ABGR:
  264. case PIX_FMT_RGBA:
  265. case PIX_FMT_ARGB:
  266. return 32;
  267. case PIX_FMT_BGR24:
  268. case PIX_FMT_RGB24:
  269. return 24;
  270. case PIX_FMT_BGR565:
  271. case PIX_FMT_RGB565:
  272. case PIX_FMT_GRAY16BE:
  273. case PIX_FMT_GRAY16LE:
  274. return 16;
  275. case PIX_FMT_BGR555:
  276. case PIX_FMT_RGB555:
  277. return 15;
  278. case PIX_FMT_BGR8:
  279. case PIX_FMT_RGB8:
  280. return 8;
  281. case PIX_FMT_BGR4:
  282. case PIX_FMT_RGB4:
  283. case PIX_FMT_BGR4_BYTE:
  284. case PIX_FMT_RGB4_BYTE:
  285. return 4;
  286. case PIX_FMT_MONOBLACK:
  287. case PIX_FMT_MONOWHITE:
  288. return 1;
  289. default:
  290. return 0;
  291. }
  292. }
  293. extern const uint64_t ff_dither4[2];
  294. extern const uint64_t ff_dither8[2];
  295. extern const AVClass sws_context_class;
  296. #endif /* SWSCALE_SWSCALE_INTERNAL_H */