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.

267 lines
8.2KB

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