swscale_internal.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 *hLumFilter;
  76. int16_t *hLumFilterPos;
  77. int16_t *hChrFilter;
  78. int16_t *hChrFilterPos;
  79. int16_t *vLumFilter;
  80. int16_t *vLumFilterPos;
  81. int16_t *vChrFilter;
  82. int16_t *vChrFilterPos;
  83. uint8_t formatConvBuffer[VOF]; //FIXME dynamic allocation, but we have to change a lot of code for this to be useful
  84. int hLumFilterSize;
  85. int hChrFilterSize;
  86. int vLumFilterSize;
  87. int vChrFilterSize;
  88. int vLumBufSize;
  89. int vChrBufSize;
  90. uint8_t *funnyYCode;
  91. uint8_t *funnyUVCode;
  92. int32_t *lumMmx2FilterPos;
  93. int32_t *chrMmx2FilterPos;
  94. int16_t *lumMmx2Filter;
  95. int16_t *chrMmx2Filter;
  96. int canMMX2BeUsed;
  97. int lastInLumBuf;
  98. int lastInChrBuf;
  99. int lumBufIndex;
  100. int chrBufIndex;
  101. int dstY;
  102. int flags;
  103. void * yuvTable; // pointer to the yuv->rgb table start so it can be freed()
  104. uint8_t * table_rV[256];
  105. uint8_t * table_gU[256];
  106. int table_gV[256];
  107. uint8_t * table_bU[256];
  108. //Colorspace stuff
  109. int contrast, brightness, saturation; // for sws_getColorspaceDetails
  110. int srcColorspaceTable[4];
  111. int dstColorspaceTable[4];
  112. int srcRange, dstRange;
  113. int yuv2rgb_y_offset;
  114. int yuv2rgb_y_coeff;
  115. int yuv2rgb_v2r_coeff;
  116. int yuv2rgb_v2g_coeff;
  117. int yuv2rgb_u2g_coeff;
  118. int yuv2rgb_u2b_coeff;
  119. #define RED_DITHER "0*8"
  120. #define GREEN_DITHER "1*8"
  121. #define BLUE_DITHER "2*8"
  122. #define Y_COEFF "3*8"
  123. #define VR_COEFF "4*8"
  124. #define UB_COEFF "5*8"
  125. #define VG_COEFF "6*8"
  126. #define UG_COEFF "7*8"
  127. #define Y_OFFSET "8*8"
  128. #define U_OFFSET "9*8"
  129. #define V_OFFSET "10*8"
  130. #define LUM_MMX_FILTER_OFFSET "11*8"
  131. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
  132. #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
  133. #define ESP_OFFSET "11*8+4*4*256*2+8"
  134. #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
  135. #define U_TEMP "11*8+4*4*256*2+24"
  136. #define V_TEMP "11*8+4*4*256*2+32"
  137. uint64_t redDither __attribute__((aligned(8)));
  138. uint64_t greenDither __attribute__((aligned(8)));
  139. uint64_t blueDither __attribute__((aligned(8)));
  140. uint64_t yCoeff __attribute__((aligned(8)));
  141. uint64_t vrCoeff __attribute__((aligned(8)));
  142. uint64_t ubCoeff __attribute__((aligned(8)));
  143. uint64_t vgCoeff __attribute__((aligned(8)));
  144. uint64_t ugCoeff __attribute__((aligned(8)));
  145. uint64_t yOffset __attribute__((aligned(8)));
  146. uint64_t uOffset __attribute__((aligned(8)));
  147. uint64_t vOffset __attribute__((aligned(8)));
  148. int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
  149. int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
  150. int dstW;
  151. uint64_t esp __attribute__((aligned(8)));
  152. uint64_t vRounder __attribute__((aligned(8)));
  153. uint64_t u_temp __attribute__((aligned(8)));
  154. uint64_t v_temp __attribute__((aligned(8)));
  155. #if HAVE_ALTIVEC
  156. vector signed short CY;
  157. vector signed short CRV;
  158. vector signed short CBU;
  159. vector signed short CGU;
  160. vector signed short CGV;
  161. vector signed short OY;
  162. vector unsigned short CSHIFT;
  163. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  164. #endif
  165. #if ARCH_BFIN
  166. uint32_t oy __attribute__((aligned(4)));
  167. uint32_t oc __attribute__((aligned(4)));
  168. uint32_t zero __attribute__((aligned(4)));
  169. uint32_t cy __attribute__((aligned(4)));
  170. uint32_t crv __attribute__((aligned(4)));
  171. uint32_t rmask __attribute__((aligned(4)));
  172. uint32_t cbu __attribute__((aligned(4)));
  173. uint32_t bmask __attribute__((aligned(4)));
  174. uint32_t cgu __attribute__((aligned(4)));
  175. uint32_t cgv __attribute__((aligned(4)));
  176. uint32_t gmask __attribute__((aligned(4)));
  177. #endif
  178. #if HAVE_VIS
  179. uint64_t sparc_coeffs[10] __attribute__((aligned(8)));
  180. #endif
  181. } SwsContext;
  182. //FIXME check init (where 0)
  183. SwsFunc sws_yuv2rgb_get_func_ptr (SwsContext *c);
  184. int sws_yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation);
  185. void sws_yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation);
  186. SwsFunc sws_yuv2rgb_init_altivec (SwsContext *c);
  187. void altivec_yuv2packedX (SwsContext *c,
  188. int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  189. int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
  190. uint8_t *dest, int dstW, int dstY);
  191. const char *sws_format_name(int format);
  192. //FIXME replace this with something faster
  193. #define isPlanarYUV(x) ( \
  194. (x)==PIX_FMT_YUV410P \
  195. || (x)==PIX_FMT_YUV420P \
  196. || (x)==PIX_FMT_YUV411P \
  197. || (x)==PIX_FMT_YUV422P \
  198. || (x)==PIX_FMT_YUV444P \
  199. || (x)==PIX_FMT_YUV440P \
  200. || (x)==PIX_FMT_NV12 \
  201. || (x)==PIX_FMT_NV21 \
  202. )
  203. #define isYUV(x) ( \
  204. (x)==PIX_FMT_UYVY422 \
  205. || (x)==PIX_FMT_YUYV422 \
  206. || isPlanarYUV(x) \
  207. )
  208. #define isGray(x) ( \
  209. (x)==PIX_FMT_GRAY8 \
  210. || (x)==PIX_FMT_GRAY16BE \
  211. || (x)==PIX_FMT_GRAY16LE \
  212. )
  213. #define isGray16(x) ( \
  214. (x)==PIX_FMT_GRAY16BE \
  215. || (x)==PIX_FMT_GRAY16LE \
  216. )
  217. #define isRGB(x) ( \
  218. (x)==PIX_FMT_RGB32 \
  219. || (x)==PIX_FMT_RGB32_1 \
  220. || (x)==PIX_FMT_RGB24 \
  221. || (x)==PIX_FMT_RGB565 \
  222. || (x)==PIX_FMT_RGB555 \
  223. || (x)==PIX_FMT_RGB8 \
  224. || (x)==PIX_FMT_RGB4 \
  225. || (x)==PIX_FMT_RGB4_BYTE \
  226. || (x)==PIX_FMT_MONOBLACK \
  227. || (x)==PIX_FMT_MONOWHITE \
  228. )
  229. #define isBGR(x) ( \
  230. (x)==PIX_FMT_BGR32 \
  231. || (x)==PIX_FMT_BGR32_1 \
  232. || (x)==PIX_FMT_BGR24 \
  233. || (x)==PIX_FMT_BGR565 \
  234. || (x)==PIX_FMT_BGR555 \
  235. || (x)==PIX_FMT_BGR8 \
  236. || (x)==PIX_FMT_BGR4 \
  237. || (x)==PIX_FMT_BGR4_BYTE \
  238. || (x)==PIX_FMT_MONOBLACK \
  239. || (x)==PIX_FMT_MONOWHITE \
  240. )
  241. #define isALPHA(x) ( \
  242. (x)==PIX_FMT_BGR32 \
  243. || (x)==PIX_FMT_BGR32_1 \
  244. || (x)==PIX_FMT_RGB32 \
  245. || (x)==PIX_FMT_RGB32_1 \
  246. || (x)==PIX_FMT_YUVA420P \
  247. )
  248. static inline int fmt_depth(int fmt)
  249. {
  250. switch(fmt) {
  251. case PIX_FMT_BGRA:
  252. case PIX_FMT_ABGR:
  253. case PIX_FMT_RGBA:
  254. case PIX_FMT_ARGB:
  255. return 32;
  256. case PIX_FMT_BGR24:
  257. case PIX_FMT_RGB24:
  258. return 24;
  259. case PIX_FMT_BGR565:
  260. case PIX_FMT_RGB565:
  261. case PIX_FMT_GRAY16BE:
  262. case PIX_FMT_GRAY16LE:
  263. return 16;
  264. case PIX_FMT_BGR555:
  265. case PIX_FMT_RGB555:
  266. return 15;
  267. case PIX_FMT_BGR8:
  268. case PIX_FMT_RGB8:
  269. return 8;
  270. case PIX_FMT_BGR4:
  271. case PIX_FMT_RGB4:
  272. case PIX_FMT_BGR4_BYTE:
  273. case PIX_FMT_RGB4_BYTE:
  274. return 4;
  275. case PIX_FMT_MONOBLACK:
  276. case PIX_FMT_MONOWHITE:
  277. return 1;
  278. default:
  279. return 0;
  280. }
  281. }
  282. extern const uint64_t ff_dither4[2];
  283. extern const uint64_t ff_dither8[2];
  284. extern const AVClass sws_context_class;
  285. #endif /* SWSCALE_SWSCALE_INTERNAL_H */