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.

304 lines
9.4KB

  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. #define RED_DITHER "0*8"
  111. #define GREEN_DITHER "1*8"
  112. #define BLUE_DITHER "2*8"
  113. #define Y_COEFF "3*8"
  114. #define VR_COEFF "4*8"
  115. #define UB_COEFF "5*8"
  116. #define VG_COEFF "6*8"
  117. #define UG_COEFF "7*8"
  118. #define Y_OFFSET "8*8"
  119. #define U_OFFSET "9*8"
  120. #define V_OFFSET "10*8"
  121. #define LUM_MMX_FILTER_OFFSET "11*8"
  122. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
  123. #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
  124. #define ESP_OFFSET "11*8+4*4*256*2+8"
  125. #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
  126. #define U_TEMP "11*8+4*4*256*2+24"
  127. #define V_TEMP "11*8+4*4*256*2+32"
  128. uint64_t redDither __attribute__((aligned(8)));
  129. uint64_t greenDither __attribute__((aligned(8)));
  130. uint64_t blueDither __attribute__((aligned(8)));
  131. uint64_t yCoeff __attribute__((aligned(8)));
  132. uint64_t vrCoeff __attribute__((aligned(8)));
  133. uint64_t ubCoeff __attribute__((aligned(8)));
  134. uint64_t vgCoeff __attribute__((aligned(8)));
  135. uint64_t ugCoeff __attribute__((aligned(8)));
  136. uint64_t yOffset __attribute__((aligned(8)));
  137. uint64_t uOffset __attribute__((aligned(8)));
  138. uint64_t vOffset __attribute__((aligned(8)));
  139. int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
  140. int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
  141. int dstW;
  142. uint64_t esp __attribute__((aligned(8)));
  143. uint64_t vRounder __attribute__((aligned(8)));
  144. uint64_t u_temp __attribute__((aligned(8)));
  145. uint64_t v_temp __attribute__((aligned(8)));
  146. #ifdef HAVE_ALTIVEC
  147. vector signed short CY;
  148. vector signed short CRV;
  149. vector signed short CBU;
  150. vector signed short CGU;
  151. vector signed short CGV;
  152. vector signed short OY;
  153. vector unsigned short CSHIFT;
  154. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  155. #endif
  156. #ifdef ARCH_BFIN
  157. uint32_t oy __attribute__((aligned(4)));
  158. uint32_t oc __attribute__((aligned(4)));
  159. uint32_t zero __attribute__((aligned(4)));
  160. uint32_t cy __attribute__((aligned(4)));
  161. uint32_t crv __attribute__((aligned(4)));
  162. uint32_t rmask __attribute__((aligned(4)));
  163. uint32_t cbu __attribute__((aligned(4)));
  164. uint32_t bmask __attribute__((aligned(4)));
  165. uint32_t cgu __attribute__((aligned(4)));
  166. uint32_t cgv __attribute__((aligned(4)));
  167. uint32_t gmask __attribute__((aligned(4)));
  168. #endif
  169. #ifdef HAVE_VIS
  170. uint64_t sparc_coeffs[10] __attribute__((aligned(8)));
  171. #endif
  172. } SwsContext;
  173. //FIXME check init (where 0)
  174. SwsFunc yuv2rgb_get_func_ptr (SwsContext *c);
  175. int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation);
  176. void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation);
  177. SwsFunc yuv2rgb_init_altivec (SwsContext *c);
  178. void altivec_yuv2packedX (SwsContext *c,
  179. int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize,
  180. int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize,
  181. uint8_t *dest, int dstW, int dstY);
  182. const char *sws_format_name(int format);
  183. //FIXME replace this with something faster
  184. #define isPlanarYUV(x) ( \
  185. (x)==PIX_FMT_YUV410P \
  186. || (x)==PIX_FMT_YUV420P \
  187. || (x)==PIX_FMT_YUV411P \
  188. || (x)==PIX_FMT_YUV422P \
  189. || (x)==PIX_FMT_YUV444P \
  190. || (x)==PIX_FMT_YUV440P \
  191. || (x)==PIX_FMT_NV12 \
  192. || (x)==PIX_FMT_NV21 \
  193. )
  194. #define isYUV(x) ( \
  195. (x)==PIX_FMT_UYVY422 \
  196. || (x)==PIX_FMT_YUYV422 \
  197. || isPlanarYUV(x) \
  198. )
  199. #define isGray(x) ( \
  200. (x)==PIX_FMT_GRAY8 \
  201. || (x)==PIX_FMT_GRAY16BE \
  202. || (x)==PIX_FMT_GRAY16LE \
  203. )
  204. #define isGray16(x) ( \
  205. (x)==PIX_FMT_GRAY16BE \
  206. || (x)==PIX_FMT_GRAY16LE \
  207. )
  208. #define isRGB(x) ( \
  209. (x)==PIX_FMT_RGB32 \
  210. || (x)==PIX_FMT_RGB32_1 \
  211. || (x)==PIX_FMT_RGB24 \
  212. || (x)==PIX_FMT_RGB565 \
  213. || (x)==PIX_FMT_RGB555 \
  214. || (x)==PIX_FMT_RGB8 \
  215. || (x)==PIX_FMT_RGB4 \
  216. || (x)==PIX_FMT_RGB4_BYTE \
  217. || (x)==PIX_FMT_MONOBLACK \
  218. )
  219. #define isBGR(x) ( \
  220. (x)==PIX_FMT_BGR32 \
  221. || (x)==PIX_FMT_BGR32_1 \
  222. || (x)==PIX_FMT_BGR24 \
  223. || (x)==PIX_FMT_BGR565 \
  224. || (x)==PIX_FMT_BGR555 \
  225. || (x)==PIX_FMT_BGR8 \
  226. || (x)==PIX_FMT_BGR4 \
  227. || (x)==PIX_FMT_BGR4_BYTE \
  228. || (x)==PIX_FMT_MONOBLACK \
  229. )
  230. static inline int fmt_depth(int fmt)
  231. {
  232. switch(fmt) {
  233. case PIX_FMT_BGRA:
  234. case PIX_FMT_ABGR:
  235. case PIX_FMT_RGBA:
  236. case PIX_FMT_ARGB:
  237. return 32;
  238. case PIX_FMT_BGR24:
  239. case PIX_FMT_RGB24:
  240. return 24;
  241. case PIX_FMT_BGR565:
  242. case PIX_FMT_RGB565:
  243. case PIX_FMT_GRAY16BE:
  244. case PIX_FMT_GRAY16LE:
  245. return 16;
  246. case PIX_FMT_BGR555:
  247. case PIX_FMT_RGB555:
  248. return 15;
  249. case PIX_FMT_BGR8:
  250. case PIX_FMT_RGB8:
  251. return 8;
  252. case PIX_FMT_BGR4:
  253. case PIX_FMT_RGB4:
  254. case PIX_FMT_BGR4_BYTE:
  255. case PIX_FMT_RGB4_BYTE:
  256. return 4;
  257. case PIX_FMT_MONOBLACK:
  258. return 1;
  259. default:
  260. return 0;
  261. }
  262. }
  263. extern const DECLARE_ALIGNED(8, uint64_t, ff_dither4[2]);
  264. extern const DECLARE_ALIGNED(8, uint64_t, ff_dither8[2]);
  265. extern const AVClass sws_context_class;
  266. #endif /* SWSCALE_SWSCALE_INTERNAL_H */