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.

227 lines
6.8KB

  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 modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * the C code (not assembly, mmx, ...) of the swscaler which has been written
  21. * by Michael Niedermayer can be used under the LGPL license too
  22. */
  23. #ifndef SWSCALE_INTERNAL_H
  24. #define SWSCALE_INTERNAL_H
  25. #ifdef HAVE_ALTIVEC_H
  26. #include <altivec.h>
  27. #endif
  28. #include "avutil.h"
  29. #ifdef CONFIG_DARWIN
  30. #define AVV(x...) (x)
  31. #else
  32. #define AVV(x...) {x}
  33. #endif
  34. #define MSG_WARN(args...) av_log(NULL, AV_LOG_DEBUG, ##args )
  35. #define MSG_FATAL(args...) av_log(NULL, AV_LOG_ERROR, ##args )
  36. #define MSG_ERR(args...) av_log(NULL, AV_LOG_ERROR, ##args )
  37. #define MSG_V(args...) av_log(NULL, AV_LOG_INFO, ##args )
  38. #define MSG_DBG2(args...) av_log(NULL, AV_LOG_DEBUG, ##args )
  39. #define MSG_INFO(args...) av_log(NULL, AV_LOG_INFO, ##args )
  40. #define MAX_FILTER_SIZE 256
  41. typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
  42. int srcSliceH, uint8_t* dst[], int dstStride[]);
  43. /* this struct should be aligned on at least 32-byte boundary */
  44. typedef struct SwsContext{
  45. /**
  46. *
  47. * Note the src,dst,srcStride,dstStride will be copied, in the sws_scale() warper so they can freely be modified here
  48. */
  49. SwsFunc swScale;
  50. int srcW, srcH, dstH;
  51. int chrSrcW, chrSrcH, chrDstW, chrDstH;
  52. int lumXInc, chrXInc;
  53. int lumYInc, chrYInc;
  54. int dstFormat, srcFormat; ///< format 4:2:0 type is allways YV12
  55. int origDstFormat, origSrcFormat; ///< format
  56. int chrSrcHSubSample, chrSrcVSubSample;
  57. int chrIntHSubSample, chrIntVSubSample;
  58. int chrDstHSubSample, chrDstVSubSample;
  59. int vChrDrop;
  60. int sliceDir;
  61. double param[2];
  62. int16_t **lumPixBuf;
  63. int16_t **chrPixBuf;
  64. int16_t *hLumFilter;
  65. int16_t *hLumFilterPos;
  66. int16_t *hChrFilter;
  67. int16_t *hChrFilterPos;
  68. int16_t *vLumFilter;
  69. int16_t *vLumFilterPos;
  70. int16_t *vChrFilter;
  71. int16_t *vChrFilterPos;
  72. uint8_t formatConvBuffer[4000]; //FIXME dynamic alloc, but we have to change alot of code for this to be usefull
  73. int hLumFilterSize;
  74. int hChrFilterSize;
  75. int vLumFilterSize;
  76. int vChrFilterSize;
  77. int vLumBufSize;
  78. int vChrBufSize;
  79. uint8_t *funnyYCode;
  80. uint8_t *funnyUVCode;
  81. int32_t *lumMmx2FilterPos;
  82. int32_t *chrMmx2FilterPos;
  83. int16_t *lumMmx2Filter;
  84. int16_t *chrMmx2Filter;
  85. int canMMX2BeUsed;
  86. int lastInLumBuf;
  87. int lastInChrBuf;
  88. int lumBufIndex;
  89. int chrBufIndex;
  90. int dstY;
  91. int flags;
  92. void * yuvTable; // pointer to the yuv->rgb table start so it can be freed()
  93. void * table_rV[256];
  94. void * table_gU[256];
  95. int table_gV[256];
  96. void * table_bU[256];
  97. //Colorspace stuff
  98. int contrast, brightness, saturation; // for sws_getColorspaceDetails
  99. int srcColorspaceTable[4];
  100. int dstColorspaceTable[4];
  101. int srcRange, dstRange;
  102. #define RED_DITHER "0*8"
  103. #define GREEN_DITHER "1*8"
  104. #define BLUE_DITHER "2*8"
  105. #define Y_COEFF "3*8"
  106. #define VR_COEFF "4*8"
  107. #define UB_COEFF "5*8"
  108. #define VG_COEFF "6*8"
  109. #define UG_COEFF "7*8"
  110. #define Y_OFFSET "8*8"
  111. #define U_OFFSET "9*8"
  112. #define V_OFFSET "10*8"
  113. #define LUM_MMX_FILTER_OFFSET "11*8"
  114. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
  115. #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, its hardcoded in the asm
  116. #define ESP_OFFSET "11*8+4*4*256*2+8"
  117. #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
  118. #define U_TEMP "11*8+4*4*256*2+24"
  119. #define V_TEMP "11*8+4*4*256*2+32"
  120. uint64_t redDither __attribute__((aligned(8)));
  121. uint64_t greenDither __attribute__((aligned(8)));
  122. uint64_t blueDither __attribute__((aligned(8)));
  123. uint64_t yCoeff __attribute__((aligned(8)));
  124. uint64_t vrCoeff __attribute__((aligned(8)));
  125. uint64_t ubCoeff __attribute__((aligned(8)));
  126. uint64_t vgCoeff __attribute__((aligned(8)));
  127. uint64_t ugCoeff __attribute__((aligned(8)));
  128. uint64_t yOffset __attribute__((aligned(8)));
  129. uint64_t uOffset __attribute__((aligned(8)));
  130. uint64_t vOffset __attribute__((aligned(8)));
  131. int32_t lumMmxFilter[4*MAX_FILTER_SIZE];
  132. int32_t chrMmxFilter[4*MAX_FILTER_SIZE];
  133. int dstW;
  134. uint64_t esp __attribute__((aligned(8)));
  135. uint64_t vRounder __attribute__((aligned(8)));
  136. uint64_t u_temp __attribute__((aligned(8)));
  137. uint64_t v_temp __attribute__((aligned(8)));
  138. #ifdef HAVE_ALTIVEC
  139. vector signed short CY;
  140. vector signed short CRV;
  141. vector signed short CBU;
  142. vector signed short CGU;
  143. vector signed short CGV;
  144. vector signed short OY;
  145. vector unsigned short CSHIFT;
  146. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  147. #endif
  148. } SwsContext;
  149. //FIXME check init (where 0)
  150. SwsFunc yuv2rgb_get_func_ptr (SwsContext *c);
  151. int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation);
  152. char *sws_format_name(int format);
  153. //FIXME replace this with something faster
  154. #define isPlanarYUV(x) ((x)==PIX_FMT_YUV410P || (x)==PIX_FMT_YUV420P \
  155. || (x)==PIX_FMT_YUV411P || (x)==PIX_FMT_YUV422P \
  156. || (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_NV12 \
  157. || (x)==PIX_FMT_NV21)
  158. #define isYUV(x) ((x)==PIX_FMT_UYVY422 || (x)==PIX_FMT_YUYV422 || isPlanarYUV(x))
  159. #define isGray(x) ((x)==PIX_FMT_GRAY8)
  160. #define isRGB(x) ((x)==PIX_FMT_BGR32 || (x)==PIX_FMT_RGB24 \
  161. || (x)==PIX_FMT_RGB565 || (x)==PIX_FMT_RGB555 \
  162. || (x)==PIX_FMT_RGB8 || (x)==PIX_FMT_RGB4 \
  163. || (x)==PIX_FMT_MONOBLACK)
  164. #define isBGR(x) ((x)==PIX_FMT_RGB32 || (x)==PIX_FMT_BGR24 \
  165. || (x)==PIX_FMT_BGR565 || (x)==PIX_FMT_BGR555 \
  166. || (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_BGR4 \
  167. || (x)==PIX_FMT_MONOBLACK)
  168. static inline int fmt_depth(int fmt)
  169. {
  170. switch(fmt) {
  171. case PIX_FMT_BGRA:
  172. case PIX_FMT_ABGR:
  173. case PIX_FMT_RGBA:
  174. case PIX_FMT_ARGB:
  175. return 32;
  176. case PIX_FMT_BGR24:
  177. case PIX_FMT_RGB24:
  178. return 24;
  179. case PIX_FMT_BGR565:
  180. case PIX_FMT_RGB565:
  181. return 16;
  182. case PIX_FMT_BGR555:
  183. case PIX_FMT_RGB555:
  184. return 15;
  185. case PIX_FMT_BGR8:
  186. case PIX_FMT_RGB8:
  187. return 8;
  188. case PIX_FMT_BGR4:
  189. case PIX_FMT_RGB4:
  190. case PIX_FMT_BGR4_BYTE:
  191. case PIX_FMT_RGB4_BYTE:
  192. return 4;
  193. case PIX_FMT_MONOBLACK:
  194. return 1;
  195. default:
  196. return 0;
  197. }
  198. }
  199. #endif