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.

292 lines
9.1KB

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