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.

313 lines
9.6KB

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