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.

1060 lines
45KB

  1. /*
  2. * Copyright (C) 2001-2011 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. #if HAVE_ALTIVEC_H
  24. #include <altivec.h>
  25. #endif
  26. #include "version.h"
  27. #include "libavutil/avassert.h"
  28. #include "libavutil/avutil.h"
  29. #include "libavutil/common.h"
  30. #include "libavutil/intreadwrite.h"
  31. #include "libavutil/log.h"
  32. #include "libavutil/pixfmt.h"
  33. #include "libavutil/pixdesc.h"
  34. #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long
  35. #define YUVRGB_TABLE_HEADROOM 256
  36. #define MAX_FILTER_SIZE SWS_MAX_FILTER_SIZE
  37. #define DITHER1XBPP
  38. #if HAVE_BIGENDIAN
  39. #define ALT32_CORR (-1)
  40. #else
  41. #define ALT32_CORR 1
  42. #endif
  43. #if ARCH_X86_64
  44. # define APCK_PTR2 8
  45. # define APCK_COEF 16
  46. # define APCK_SIZE 24
  47. #else
  48. # define APCK_PTR2 4
  49. # define APCK_COEF 8
  50. # define APCK_SIZE 16
  51. #endif
  52. #define RETCODE_USE_CASCADE -12345
  53. struct SwsContext;
  54. typedef enum SwsDither {
  55. SWS_DITHER_NONE = 0,
  56. SWS_DITHER_AUTO,
  57. SWS_DITHER_BAYER,
  58. SWS_DITHER_ED,
  59. SWS_DITHER_A_DITHER,
  60. SWS_DITHER_X_DITHER,
  61. NB_SWS_DITHER,
  62. } SwsDither;
  63. typedef enum SwsAlphaBlend {
  64. SWS_ALPHA_BLEND_NONE = 0,
  65. SWS_ALPHA_BLEND_UNIFORM,
  66. SWS_ALPHA_BLEND_CHECKERBOARD,
  67. SWS_ALPHA_BLEND_NB,
  68. } SwsAlphaBlend;
  69. typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[],
  70. int srcStride[], int srcSliceY, int srcSliceH,
  71. uint8_t *dst[], int dstStride[]);
  72. /**
  73. * Write one line of horizontally scaled data to planar output
  74. * without any additional vertical scaling (or point-scaling).
  75. *
  76. * @param src scaled source data, 15bit for 8-10bit output,
  77. * 19-bit for 16bit output (in int32_t)
  78. * @param dest pointer to the output plane. For >8bit
  79. * output, this is in uint16_t
  80. * @param dstW width of destination in pixels
  81. * @param dither ordered dither array of type int16_t and size 8
  82. * @param offset Dither offset
  83. */
  84. typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW,
  85. const uint8_t *dither, int offset);
  86. /**
  87. * Write one line of horizontally scaled data to planar output
  88. * with multi-point vertical scaling between input pixels.
  89. *
  90. * @param filter vertical luma/alpha scaling coefficients, 12bit [0,4096]
  91. * @param src scaled luma (Y) or alpha (A) source data, 15bit for 8-10bit output,
  92. * 19-bit for 16bit output (in int32_t)
  93. * @param filterSize number of vertical input lines to scale
  94. * @param dest pointer to output plane. For >8bit
  95. * output, this is in uint16_t
  96. * @param dstW width of destination pixels
  97. * @param offset Dither offset
  98. */
  99. typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize,
  100. const int16_t **src, uint8_t *dest, int dstW,
  101. const uint8_t *dither, int offset);
  102. /**
  103. * Write one line of horizontally scaled chroma to interleaved output
  104. * with multi-point vertical scaling between input pixels.
  105. *
  106. * @param c SWS scaling context
  107. * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
  108. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  109. * 19-bit for 16bit output (in int32_t)
  110. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  111. * 19-bit for 16bit output (in int32_t)
  112. * @param chrFilterSize number of vertical chroma input lines to scale
  113. * @param dest pointer to the output plane. For >8bit
  114. * output, this is in uint16_t
  115. * @param dstW width of chroma planes
  116. */
  117. typedef void (*yuv2interleavedX_fn)(struct SwsContext *c,
  118. const int16_t *chrFilter,
  119. int chrFilterSize,
  120. const int16_t **chrUSrc,
  121. const int16_t **chrVSrc,
  122. uint8_t *dest, int dstW);
  123. /**
  124. * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
  125. * output without any additional vertical scaling (or point-scaling). Note
  126. * that this function may do chroma scaling, see the "uvalpha" argument.
  127. *
  128. * @param c SWS scaling context
  129. * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
  130. * 19-bit for 16bit output (in int32_t)
  131. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  132. * 19-bit for 16bit output (in int32_t)
  133. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  134. * 19-bit for 16bit output (in int32_t)
  135. * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
  136. * 19-bit for 16bit output (in int32_t)
  137. * @param dest pointer to the output plane. For 16bit output, this is
  138. * uint16_t
  139. * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
  140. * to write into dest[]
  141. * @param uvalpha chroma scaling coefficient for the second line of chroma
  142. * pixels, either 2048 or 0. If 0, one chroma input is used
  143. * for 2 output pixels (or if the SWS_FLAG_FULL_CHR_INT flag
  144. * is set, it generates 1 output pixel). If 2048, two chroma
  145. * input pixels should be averaged for 2 output pixels (this
  146. * only happens if SWS_FLAG_FULL_CHR_INT is not set)
  147. * @param y vertical line number for this output. This does not need
  148. * to be used to calculate the offset in the destination,
  149. * but can be used to generate comfort noise using dithering
  150. * for some output formats.
  151. */
  152. typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc,
  153. const int16_t *chrUSrc[2],
  154. const int16_t *chrVSrc[2],
  155. const int16_t *alpSrc, uint8_t *dest,
  156. int dstW, int uvalpha, int y);
  157. /**
  158. * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
  159. * output by doing bilinear scaling between two input lines.
  160. *
  161. * @param c SWS scaling context
  162. * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
  163. * 19-bit for 16bit output (in int32_t)
  164. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  165. * 19-bit for 16bit output (in int32_t)
  166. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  167. * 19-bit for 16bit output (in int32_t)
  168. * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
  169. * 19-bit for 16bit output (in int32_t)
  170. * @param dest pointer to the output plane. For 16bit output, this is
  171. * uint16_t
  172. * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
  173. * to write into dest[]
  174. * @param yalpha luma/alpha scaling coefficients for the second input line.
  175. * The first line's coefficients can be calculated by using
  176. * 4096 - yalpha
  177. * @param uvalpha chroma scaling coefficient for the second input line. The
  178. * first line's coefficients can be calculated by using
  179. * 4096 - uvalpha
  180. * @param y vertical line number for this output. This does not need
  181. * to be used to calculate the offset in the destination,
  182. * but can be used to generate comfort noise using dithering
  183. * for some output formats.
  184. */
  185. typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2],
  186. const int16_t *chrUSrc[2],
  187. const int16_t *chrVSrc[2],
  188. const int16_t *alpSrc[2],
  189. uint8_t *dest,
  190. int dstW, int yalpha, int uvalpha, int y);
  191. /**
  192. * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
  193. * output by doing multi-point vertical scaling between input pixels.
  194. *
  195. * @param c SWS scaling context
  196. * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096]
  197. * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
  198. * 19-bit for 16bit output (in int32_t)
  199. * @param lumFilterSize number of vertical luma/alpha input lines to scale
  200. * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
  201. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  202. * 19-bit for 16bit output (in int32_t)
  203. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  204. * 19-bit for 16bit output (in int32_t)
  205. * @param chrFilterSize number of vertical chroma input lines to scale
  206. * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
  207. * 19-bit for 16bit output (in int32_t)
  208. * @param dest pointer to the output plane. For 16bit output, this is
  209. * uint16_t
  210. * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
  211. * to write into dest[]
  212. * @param y vertical line number for this output. This does not need
  213. * to be used to calculate the offset in the destination,
  214. * but can be used to generate comfort noise using dithering
  215. * or some output formats.
  216. */
  217. typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
  218. const int16_t **lumSrc, int lumFilterSize,
  219. const int16_t *chrFilter,
  220. const int16_t **chrUSrc,
  221. const int16_t **chrVSrc, int chrFilterSize,
  222. const int16_t **alpSrc, uint8_t *dest,
  223. int dstW, int y);
  224. /**
  225. * Write one line of horizontally scaled Y/U/V/A to YUV/RGB
  226. * output by doing multi-point vertical scaling between input pixels.
  227. *
  228. * @param c SWS scaling context
  229. * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096]
  230. * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
  231. * 19-bit for 16bit output (in int32_t)
  232. * @param lumFilterSize number of vertical luma/alpha input lines to scale
  233. * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
  234. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  235. * 19-bit for 16bit output (in int32_t)
  236. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  237. * 19-bit for 16bit output (in int32_t)
  238. * @param chrFilterSize number of vertical chroma input lines to scale
  239. * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
  240. * 19-bit for 16bit output (in int32_t)
  241. * @param dest pointer to the output planes. For 16bit output, this is
  242. * uint16_t
  243. * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
  244. * to write into dest[]
  245. * @param y vertical line number for this output. This does not need
  246. * to be used to calculate the offset in the destination,
  247. * but can be used to generate comfort noise using dithering
  248. * or some output formats.
  249. */
  250. typedef void (*yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter,
  251. const int16_t **lumSrc, int lumFilterSize,
  252. const int16_t *chrFilter,
  253. const int16_t **chrUSrc,
  254. const int16_t **chrVSrc, int chrFilterSize,
  255. const int16_t **alpSrc, uint8_t **dest,
  256. int dstW, int y);
  257. struct SwsSlice;
  258. struct SwsFilterDescriptor;
  259. /* This struct should be aligned on at least a 32-byte boundary. */
  260. typedef struct SwsContext {
  261. /**
  262. * info on struct for av_log
  263. */
  264. const AVClass *av_class;
  265. /**
  266. * Note that src, dst, srcStride, dstStride will be copied in the
  267. * sws_scale() wrapper so they can be freely modified here.
  268. */
  269. SwsFunc swscale;
  270. int srcW; ///< Width of source luma/alpha planes.
  271. int srcH; ///< Height of source luma/alpha planes.
  272. int dstH; ///< Height of destination luma/alpha planes.
  273. int chrSrcW; ///< Width of source chroma planes.
  274. int chrSrcH; ///< Height of source chroma planes.
  275. int chrDstW; ///< Width of destination chroma planes.
  276. int chrDstH; ///< Height of destination chroma planes.
  277. int lumXInc, chrXInc;
  278. int lumYInc, chrYInc;
  279. enum AVPixelFormat dstFormat; ///< Destination pixel format.
  280. enum AVPixelFormat srcFormat; ///< Source pixel format.
  281. int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format.
  282. int srcFormatBpp; ///< Number of bits per pixel of the source pixel format.
  283. int dstBpc, srcBpc;
  284. int chrSrcHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source image.
  285. int chrSrcVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image.
  286. int chrDstHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image.
  287. int chrDstVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination image.
  288. int vChrDrop; ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user.
  289. int sliceDir; ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
  290. double param[2]; ///< Input parameters for scaling algorithms that need them.
  291. /* The cascaded_* fields allow spliting a scaler task into multiple
  292. * sequential steps, this is for example used to limit the maximum
  293. * downscaling factor that needs to be supported in one scaler.
  294. */
  295. struct SwsContext *cascaded_context[3];
  296. int cascaded_tmpStride[4];
  297. uint8_t *cascaded_tmp[4];
  298. int cascaded1_tmpStride[4];
  299. uint8_t *cascaded1_tmp[4];
  300. double gamma_value;
  301. int gamma_flag;
  302. int is_internal_gamma;
  303. uint16_t *gamma;
  304. uint16_t *inv_gamma;
  305. int numDesc;
  306. int descIndex[2];
  307. int numSlice;
  308. struct SwsSlice *slice;
  309. struct SwsFilterDescriptor *desc;
  310. uint32_t pal_yuv[256];
  311. uint32_t pal_rgb[256];
  312. /**
  313. * @name Scaled horizontal lines ring buffer.
  314. * The horizontal scaler keeps just enough scaled lines in a ring buffer
  315. * so they may be passed to the vertical scaler. The pointers to the
  316. * allocated buffers for each line are duplicated in sequence in the ring
  317. * buffer to simplify indexing and avoid wrapping around between lines
  318. * inside the vertical scaler code. The wrapping is done before the
  319. * vertical scaler is called.
  320. */
  321. //@{
  322. int16_t **lumPixBuf; ///< Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler.
  323. int16_t **chrUPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
  324. int16_t **chrVPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
  325. int16_t **alpPixBuf; ///< Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler.
  326. int vLumBufSize; ///< Number of vertical luma/alpha lines allocated in the ring buffer.
  327. int vChrBufSize; ///< Number of vertical chroma lines allocated in the ring buffer.
  328. int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer.
  329. int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer.
  330. int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source.
  331. int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source.
  332. //@}
  333. uint8_t *formatConvBuffer;
  334. /**
  335. * @name Horizontal and vertical filters.
  336. * To better understand the following fields, here is a pseudo-code of
  337. * their usage in filtering a horizontal line:
  338. * @code
  339. * for (i = 0; i < width; i++) {
  340. * dst[i] = 0;
  341. * for (j = 0; j < filterSize; j++)
  342. * dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ];
  343. * dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point.
  344. * }
  345. * @endcode
  346. */
  347. //@{
  348. int16_t *hLumFilter; ///< Array of horizontal filter coefficients for luma/alpha planes.
  349. int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes.
  350. int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes.
  351. int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes.
  352. int32_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
  353. int32_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes.
  354. int32_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes.
  355. int32_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes.
  356. int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels.
  357. int hChrFilterSize; ///< Horizontal filter size for chroma pixels.
  358. int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels.
  359. int vChrFilterSize; ///< Vertical filter size for chroma pixels.
  360. //@}
  361. int lumMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for luma/alpha planes.
  362. int chrMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for chroma planes.
  363. uint8_t *lumMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for luma/alpha planes.
  364. uint8_t *chrMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for chroma planes.
  365. int canMMXEXTBeUsed;
  366. int dstY; ///< Last destination vertical line output from last slice.
  367. int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
  368. void *yuvTable; // pointer to the yuv->rgb table start so it can be freed()
  369. // alignment ensures the offset can be added in a single
  370. // instruction on e.g. ARM
  371. DECLARE_ALIGNED(16, int, table_gV)[256 + 2*YUVRGB_TABLE_HEADROOM];
  372. uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM];
  373. uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM];
  374. uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM];
  375. DECLARE_ALIGNED(16, int32_t, input_rgb2yuv_table)[16+40*4]; // This table can contain both C and SIMD formatted values, the C vales are always at the XY_IDX points
  376. #define RY_IDX 0
  377. #define GY_IDX 1
  378. #define BY_IDX 2
  379. #define RU_IDX 3
  380. #define GU_IDX 4
  381. #define BU_IDX 5
  382. #define RV_IDX 6
  383. #define GV_IDX 7
  384. #define BV_IDX 8
  385. #define RGB2YUV_SHIFT 15
  386. int *dither_error[4];
  387. //Colorspace stuff
  388. int contrast, brightness, saturation; // for sws_getColorspaceDetails
  389. int srcColorspaceTable[4];
  390. int dstColorspaceTable[4];
  391. int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image).
  392. int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image).
  393. int src0Alpha;
  394. int dst0Alpha;
  395. int srcXYZ;
  396. int dstXYZ;
  397. int src_h_chr_pos;
  398. int dst_h_chr_pos;
  399. int src_v_chr_pos;
  400. int dst_v_chr_pos;
  401. int yuv2rgb_y_offset;
  402. int yuv2rgb_y_coeff;
  403. int yuv2rgb_v2r_coeff;
  404. int yuv2rgb_v2g_coeff;
  405. int yuv2rgb_u2g_coeff;
  406. int yuv2rgb_u2b_coeff;
  407. #define RED_DITHER "0*8"
  408. #define GREEN_DITHER "1*8"
  409. #define BLUE_DITHER "2*8"
  410. #define Y_COEFF "3*8"
  411. #define VR_COEFF "4*8"
  412. #define UB_COEFF "5*8"
  413. #define VG_COEFF "6*8"
  414. #define UG_COEFF "7*8"
  415. #define Y_OFFSET "8*8"
  416. #define U_OFFSET "9*8"
  417. #define V_OFFSET "10*8"
  418. #define LUM_MMX_FILTER_OFFSET "11*8"
  419. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)
  420. #define DSTW_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2"
  421. #define ESP_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+8"
  422. #define VROUNDER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+16"
  423. #define U_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+24"
  424. #define V_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+32"
  425. #define Y_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+40"
  426. #define ALP_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+48"
  427. #define UV_OFF_PX "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+48"
  428. #define UV_OFF_BYTE "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+56"
  429. #define DITHER16 "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+64"
  430. #define DITHER32 "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+80"
  431. #define DITHER32_INT (11*8+4*4*MAX_FILTER_SIZE*3+80) // value equal to above, used for checking that the struct hasn't been changed by mistake
  432. DECLARE_ALIGNED(8, uint64_t, redDither);
  433. DECLARE_ALIGNED(8, uint64_t, greenDither);
  434. DECLARE_ALIGNED(8, uint64_t, blueDither);
  435. DECLARE_ALIGNED(8, uint64_t, yCoeff);
  436. DECLARE_ALIGNED(8, uint64_t, vrCoeff);
  437. DECLARE_ALIGNED(8, uint64_t, ubCoeff);
  438. DECLARE_ALIGNED(8, uint64_t, vgCoeff);
  439. DECLARE_ALIGNED(8, uint64_t, ugCoeff);
  440. DECLARE_ALIGNED(8, uint64_t, yOffset);
  441. DECLARE_ALIGNED(8, uint64_t, uOffset);
  442. DECLARE_ALIGNED(8, uint64_t, vOffset);
  443. int32_t lumMmxFilter[4 * MAX_FILTER_SIZE];
  444. int32_t chrMmxFilter[4 * MAX_FILTER_SIZE];
  445. int dstW; ///< Width of destination luma/alpha planes.
  446. DECLARE_ALIGNED(8, uint64_t, esp);
  447. DECLARE_ALIGNED(8, uint64_t, vRounder);
  448. DECLARE_ALIGNED(8, uint64_t, u_temp);
  449. DECLARE_ALIGNED(8, uint64_t, v_temp);
  450. DECLARE_ALIGNED(8, uint64_t, y_temp);
  451. int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
  452. // alignment of these values is not necessary, but merely here
  453. // to maintain the same offset across x8632 and x86-64. Once we
  454. // use proper offset macros in the asm, they can be removed.
  455. DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes
  456. DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes
  457. DECLARE_ALIGNED(8, uint16_t, dither16)[8];
  458. DECLARE_ALIGNED(8, uint32_t, dither32)[8];
  459. const uint8_t *chrDither8, *lumDither8;
  460. #if HAVE_ALTIVEC
  461. vector signed short CY;
  462. vector signed short CRV;
  463. vector signed short CBU;
  464. vector signed short CGU;
  465. vector signed short CGV;
  466. vector signed short OY;
  467. vector unsigned short CSHIFT;
  468. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  469. #endif
  470. int use_mmx_vfilter;
  471. /* pre defined color-spaces gamma */
  472. #define XYZ_GAMMA (2.6f)
  473. #define RGB_GAMMA (2.2f)
  474. int16_t *xyzgamma;
  475. int16_t *rgbgamma;
  476. int16_t *xyzgammainv;
  477. int16_t *rgbgammainv;
  478. int16_t xyz2rgb_matrix[3][4];
  479. int16_t rgb2xyz_matrix[3][4];
  480. /* function pointers for swscale() */
  481. yuv2planar1_fn yuv2plane1;
  482. yuv2planarX_fn yuv2planeX;
  483. yuv2interleavedX_fn yuv2nv12cX;
  484. yuv2packed1_fn yuv2packed1;
  485. yuv2packed2_fn yuv2packed2;
  486. yuv2packedX_fn yuv2packedX;
  487. yuv2anyX_fn yuv2anyX;
  488. /// Unscaled conversion of luma plane to YV12 for horizontal scaler.
  489. void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
  490. int width, uint32_t *pal);
  491. /// Unscaled conversion of alpha plane to YV12 for horizontal scaler.
  492. void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
  493. int width, uint32_t *pal);
  494. /// Unscaled conversion of chroma planes to YV12 for horizontal scaler.
  495. void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
  496. const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  497. int width, uint32_t *pal);
  498. /**
  499. * Functions to read planar input, such as planar RGB, and convert
  500. * internally to Y/UV/A.
  501. */
  502. /** @{ */
  503. void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv);
  504. void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
  505. int width, int32_t *rgb2yuv);
  506. void (*readAlpPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv);
  507. /** @} */
  508. /**
  509. * Scale one horizontal line of input data using a bilinear filter
  510. * to produce one line of output data. Compared to SwsContext->hScale(),
  511. * please take note of the following caveats when using these:
  512. * - Scaling is done using only 7bit instead of 14bit coefficients.
  513. * - You can use no more than 5 input pixels to produce 4 output
  514. * pixels. Therefore, this filter should not be used for downscaling
  515. * by more than ~20% in width (because that equals more than 5/4th
  516. * downscaling and thus more than 5 pixels input per 4 pixels output).
  517. * - In general, bilinear filters create artifacts during downscaling
  518. * (even when <20%), because one output pixel will span more than one
  519. * input pixel, and thus some pixels will need edges of both neighbor
  520. * pixels to interpolate the output pixel. Since you can use at most
  521. * two input pixels per output pixel in bilinear scaling, this is
  522. * impossible and thus downscaling by any size will create artifacts.
  523. * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR
  524. * in SwsContext->flags.
  525. */
  526. /** @{ */
  527. void (*hyscale_fast)(struct SwsContext *c,
  528. int16_t *dst, int dstWidth,
  529. const uint8_t *src, int srcW, int xInc);
  530. void (*hcscale_fast)(struct SwsContext *c,
  531. int16_t *dst1, int16_t *dst2, int dstWidth,
  532. const uint8_t *src1, const uint8_t *src2,
  533. int srcW, int xInc);
  534. /** @} */
  535. /**
  536. * Scale one horizontal line of input data using a filter over the input
  537. * lines, to produce one (differently sized) line of output data.
  538. *
  539. * @param dst pointer to destination buffer for horizontally scaled
  540. * data. If the number of bits per component of one
  541. * destination pixel (SwsContext->dstBpc) is <= 10, data
  542. * will be 15bpc in 16bits (int16_t) width. Else (i.e.
  543. * SwsContext->dstBpc == 16), data will be 19bpc in
  544. * 32bits (int32_t) width.
  545. * @param dstW width of destination image
  546. * @param src pointer to source data to be scaled. If the number of
  547. * bits per component of a source pixel (SwsContext->srcBpc)
  548. * is 8, this is 8bpc in 8bits (uint8_t) width. Else
  549. * (i.e. SwsContext->dstBpc > 8), this is native depth
  550. * in 16bits (uint16_t) width. In other words, for 9-bit
  551. * YUV input, this is 9bpc, for 10-bit YUV input, this is
  552. * 10bpc, and for 16-bit RGB or YUV, this is 16bpc.
  553. * @param filter filter coefficients to be used per output pixel for
  554. * scaling. This contains 14bpp filtering coefficients.
  555. * Guaranteed to contain dstW * filterSize entries.
  556. * @param filterPos position of the first input pixel to be used for
  557. * each output pixel during scaling. Guaranteed to
  558. * contain dstW entries.
  559. * @param filterSize the number of input coefficients to be used (and
  560. * thus the number of input pixels to be used) for
  561. * creating a single output pixel. Is aligned to 4
  562. * (and input coefficients thus padded with zeroes)
  563. * to simplify creating SIMD code.
  564. */
  565. /** @{ */
  566. void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
  567. const uint8_t *src, const int16_t *filter,
  568. const int32_t *filterPos, int filterSize);
  569. void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
  570. const uint8_t *src, const int16_t *filter,
  571. const int32_t *filterPos, int filterSize);
  572. /** @} */
  573. /// Color range conversion function for luma plane if needed.
  574. void (*lumConvertRange)(int16_t *dst, int width);
  575. /// Color range conversion function for chroma planes if needed.
  576. void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
  577. int needs_hcscale; ///< Set if there are chroma planes to be converted.
  578. SwsDither dither;
  579. SwsAlphaBlend alphablend;
  580. } SwsContext;
  581. //FIXME check init (where 0)
  582. SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
  583. int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
  584. int fullRange, int brightness,
  585. int contrast, int saturation);
  586. void ff_yuv2rgb_init_tables_ppc(SwsContext *c, const int inv_table[4],
  587. int brightness, int contrast, int saturation);
  588. void ff_updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
  589. int lastInLumBuf, int lastInChrBuf);
  590. av_cold void ff_sws_init_range_convert(SwsContext *c);
  591. SwsFunc ff_yuv2rgb_init_x86(SwsContext *c);
  592. SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c);
  593. static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
  594. {
  595. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  596. av_assert0(desc);
  597. return desc->comp[0].depth_minus1 == 15;
  598. }
  599. static av_always_inline int is9_OR_10BPS(enum AVPixelFormat pix_fmt)
  600. {
  601. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  602. av_assert0(desc);
  603. return desc->comp[0].depth_minus1 >= 8 && desc->comp[0].depth_minus1 <= 13;
  604. }
  605. #define isNBPS(x) is9_OR_10BPS(x)
  606. static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
  607. {
  608. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  609. av_assert0(desc);
  610. return desc->flags & AV_PIX_FMT_FLAG_BE;
  611. }
  612. static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
  613. {
  614. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  615. av_assert0(desc);
  616. return !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
  617. }
  618. static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
  619. {
  620. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  621. av_assert0(desc);
  622. return ((desc->flags & AV_PIX_FMT_FLAG_PLANAR) && isYUV(pix_fmt));
  623. }
  624. static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
  625. {
  626. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  627. av_assert0(desc);
  628. return (desc->flags & AV_PIX_FMT_FLAG_RGB);
  629. }
  630. #if 0 // FIXME
  631. #define isGray(x) \
  632. (!(av_pix_fmt_desc_get(x)->flags & AV_PIX_FMT_FLAG_PAL) && \
  633. av_pix_fmt_desc_get(x)->nb_components <= 2)
  634. #else
  635. #define isGray(x) \
  636. ((x) == AV_PIX_FMT_GRAY8 || \
  637. (x) == AV_PIX_FMT_YA8 || \
  638. (x) == AV_PIX_FMT_GRAY16BE || \
  639. (x) == AV_PIX_FMT_GRAY16LE || \
  640. (x) == AV_PIX_FMT_YA16BE || \
  641. (x) == AV_PIX_FMT_YA16LE)
  642. #endif
  643. #define isRGBinInt(x) \
  644. ( \
  645. (x) == AV_PIX_FMT_RGB48BE || \
  646. (x) == AV_PIX_FMT_RGB48LE || \
  647. (x) == AV_PIX_FMT_RGB32 || \
  648. (x) == AV_PIX_FMT_RGB32_1 || \
  649. (x) == AV_PIX_FMT_RGB24 || \
  650. (x) == AV_PIX_FMT_RGB565BE || \
  651. (x) == AV_PIX_FMT_RGB565LE || \
  652. (x) == AV_PIX_FMT_RGB555BE || \
  653. (x) == AV_PIX_FMT_RGB555LE || \
  654. (x) == AV_PIX_FMT_RGB444BE || \
  655. (x) == AV_PIX_FMT_RGB444LE || \
  656. (x) == AV_PIX_FMT_RGB8 || \
  657. (x) == AV_PIX_FMT_RGB4 || \
  658. (x) == AV_PIX_FMT_RGB4_BYTE || \
  659. (x) == AV_PIX_FMT_RGBA64BE || \
  660. (x) == AV_PIX_FMT_RGBA64LE || \
  661. (x) == AV_PIX_FMT_MONOBLACK || \
  662. (x) == AV_PIX_FMT_MONOWHITE \
  663. )
  664. #define isBGRinInt(x) \
  665. ( \
  666. (x) == AV_PIX_FMT_BGR48BE || \
  667. (x) == AV_PIX_FMT_BGR48LE || \
  668. (x) == AV_PIX_FMT_BGR32 || \
  669. (x) == AV_PIX_FMT_BGR32_1 || \
  670. (x) == AV_PIX_FMT_BGR24 || \
  671. (x) == AV_PIX_FMT_BGR565BE || \
  672. (x) == AV_PIX_FMT_BGR565LE || \
  673. (x) == AV_PIX_FMT_BGR555BE || \
  674. (x) == AV_PIX_FMT_BGR555LE || \
  675. (x) == AV_PIX_FMT_BGR444BE || \
  676. (x) == AV_PIX_FMT_BGR444LE || \
  677. (x) == AV_PIX_FMT_BGR8 || \
  678. (x) == AV_PIX_FMT_BGR4 || \
  679. (x) == AV_PIX_FMT_BGR4_BYTE || \
  680. (x) == AV_PIX_FMT_BGRA64BE || \
  681. (x) == AV_PIX_FMT_BGRA64LE || \
  682. (x) == AV_PIX_FMT_MONOBLACK || \
  683. (x) == AV_PIX_FMT_MONOWHITE \
  684. )
  685. #define isRGBinBytes(x) ( \
  686. (x) == AV_PIX_FMT_RGB48BE \
  687. || (x) == AV_PIX_FMT_RGB48LE \
  688. || (x) == AV_PIX_FMT_RGBA64BE \
  689. || (x) == AV_PIX_FMT_RGBA64LE \
  690. || (x) == AV_PIX_FMT_RGBA \
  691. || (x) == AV_PIX_FMT_ARGB \
  692. || (x) == AV_PIX_FMT_RGB24 \
  693. )
  694. #define isBGRinBytes(x) ( \
  695. (x) == AV_PIX_FMT_BGR48BE \
  696. || (x) == AV_PIX_FMT_BGR48LE \
  697. || (x) == AV_PIX_FMT_BGRA64BE \
  698. || (x) == AV_PIX_FMT_BGRA64LE \
  699. || (x) == AV_PIX_FMT_BGRA \
  700. || (x) == AV_PIX_FMT_ABGR \
  701. || (x) == AV_PIX_FMT_BGR24 \
  702. )
  703. #define isBayer(x) ( \
  704. (x)==AV_PIX_FMT_BAYER_BGGR8 \
  705. || (x)==AV_PIX_FMT_BAYER_BGGR16LE \
  706. || (x)==AV_PIX_FMT_BAYER_BGGR16BE \
  707. || (x)==AV_PIX_FMT_BAYER_RGGB8 \
  708. || (x)==AV_PIX_FMT_BAYER_RGGB16LE \
  709. || (x)==AV_PIX_FMT_BAYER_RGGB16BE \
  710. || (x)==AV_PIX_FMT_BAYER_GBRG8 \
  711. || (x)==AV_PIX_FMT_BAYER_GBRG16LE \
  712. || (x)==AV_PIX_FMT_BAYER_GBRG16BE \
  713. || (x)==AV_PIX_FMT_BAYER_GRBG8 \
  714. || (x)==AV_PIX_FMT_BAYER_GRBG16LE \
  715. || (x)==AV_PIX_FMT_BAYER_GRBG16BE \
  716. )
  717. #define isAnyRGB(x) \
  718. ( \
  719. isBayer(x) || \
  720. isRGBinInt(x) || \
  721. isBGRinInt(x) || \
  722. isRGB(x) \
  723. )
  724. static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
  725. {
  726. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  727. av_assert0(desc);
  728. if (pix_fmt == AV_PIX_FMT_PAL8)
  729. return 1;
  730. return desc->flags & AV_PIX_FMT_FLAG_ALPHA;
  731. }
  732. #if 1
  733. #define isPacked(x) ( \
  734. (x)==AV_PIX_FMT_PAL8 \
  735. || (x)==AV_PIX_FMT_YUYV422 \
  736. || (x)==AV_PIX_FMT_YVYU422 \
  737. || (x)==AV_PIX_FMT_UYVY422 \
  738. || (x)==AV_PIX_FMT_YA8 \
  739. || (x)==AV_PIX_FMT_YA16LE \
  740. || (x)==AV_PIX_FMT_YA16BE \
  741. || (x)==AV_PIX_FMT_AYUV64LE \
  742. || (x)==AV_PIX_FMT_AYUV64BE \
  743. || isRGBinInt(x) \
  744. || isBGRinInt(x) \
  745. )
  746. #else
  747. static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
  748. {
  749. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  750. av_assert0(desc);
  751. return ((desc->nb_components >= 2 && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) ||
  752. pix_fmt == AV_PIX_FMT_PAL8);
  753. }
  754. #endif
  755. static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
  756. {
  757. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  758. av_assert0(desc);
  759. return (desc->nb_components >= 2 && (desc->flags & AV_PIX_FMT_FLAG_PLANAR));
  760. }
  761. static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
  762. {
  763. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  764. av_assert0(desc);
  765. return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) == AV_PIX_FMT_FLAG_RGB);
  766. }
  767. static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
  768. {
  769. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  770. av_assert0(desc);
  771. return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) ==
  772. (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB));
  773. }
  774. static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
  775. {
  776. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  777. av_assert0(desc);
  778. return (desc->flags & AV_PIX_FMT_FLAG_PAL) || (desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL);
  779. }
  780. extern const uint64_t ff_dither4[2];
  781. extern const uint64_t ff_dither8[2];
  782. extern const uint8_t ff_dither_2x2_4[3][8];
  783. extern const uint8_t ff_dither_2x2_8[3][8];
  784. extern const uint8_t ff_dither_4x4_16[5][8];
  785. extern const uint8_t ff_dither_8x8_32[9][8];
  786. extern const uint8_t ff_dither_8x8_73[9][8];
  787. extern const uint8_t ff_dither_8x8_128[9][8];
  788. extern const uint8_t ff_dither_8x8_220[9][8];
  789. extern const int32_t ff_yuv2rgb_coeffs[8][4];
  790. extern const AVClass sws_context_class;
  791. /**
  792. * Set c->swscale to an unscaled converter if one exists for the specific
  793. * source and destination formats, bit depths, flags, etc.
  794. */
  795. void ff_get_unscaled_swscale(SwsContext *c);
  796. void ff_get_unscaled_swscale_ppc(SwsContext *c);
  797. void ff_get_unscaled_swscale_arm(SwsContext *c);
  798. /**
  799. * Return function pointer to fastest main scaler path function depending
  800. * on architecture and available optimizations.
  801. */
  802. SwsFunc ff_getSwsFunc(SwsContext *c);
  803. void ff_sws_init_input_funcs(SwsContext *c);
  804. void ff_sws_init_output_funcs(SwsContext *c,
  805. yuv2planar1_fn *yuv2plane1,
  806. yuv2planarX_fn *yuv2planeX,
  807. yuv2interleavedX_fn *yuv2nv12cX,
  808. yuv2packed1_fn *yuv2packed1,
  809. yuv2packed2_fn *yuv2packed2,
  810. yuv2packedX_fn *yuv2packedX,
  811. yuv2anyX_fn *yuv2anyX);
  812. void ff_sws_init_swscale_ppc(SwsContext *c);
  813. void ff_sws_init_swscale_x86(SwsContext *c);
  814. void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
  815. const uint8_t *src, int srcW, int xInc);
  816. void ff_hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
  817. int dstWidth, const uint8_t *src1,
  818. const uint8_t *src2, int srcW, int xInc);
  819. int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode,
  820. int16_t *filter, int32_t *filterPos,
  821. int numSplits);
  822. void ff_hyscale_fast_mmxext(SwsContext *c, int16_t *dst,
  823. int dstWidth, const uint8_t *src,
  824. int srcW, int xInc);
  825. void ff_hcscale_fast_mmxext(SwsContext *c, int16_t *dst1, int16_t *dst2,
  826. int dstWidth, const uint8_t *src1,
  827. const uint8_t *src2, int srcW, int xInc);
  828. /**
  829. * Allocate and return an SwsContext.
  830. * This is like sws_getContext() but does not perform the init step, allowing
  831. * the user to set additional AVOptions.
  832. *
  833. * @see sws_getContext()
  834. */
  835. struct SwsContext *sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
  836. int dstW, int dstH, enum AVPixelFormat dstFormat,
  837. int flags, const double *param);
  838. int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
  839. int srcStride[], int srcSliceY, int srcSliceH,
  840. uint8_t *dst[], int dstStride[]);
  841. static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y,
  842. int alpha, int bits, const int big_endian)
  843. {
  844. int i, j;
  845. uint8_t *ptr = plane + stride * y;
  846. int v = alpha ? 0xFFFF>>(15-bits) : (1<<bits);
  847. for (i = 0; i < height; i++) {
  848. #define FILL(wfunc) \
  849. for (j = 0; j < width; j++) {\
  850. wfunc(ptr+2*j, v);\
  851. }
  852. if (big_endian) {
  853. FILL(AV_WB16);
  854. } else {
  855. FILL(AV_WL16);
  856. }
  857. ptr += stride;
  858. }
  859. }
  860. #define MAX_SLICE_PLANES 4
  861. /// Slice plane
  862. typedef struct SwsPlane
  863. {
  864. int available_lines; ///< max number of lines that can be hold by this plane
  865. int sliceY; ///< index of first line
  866. int sliceH; ///< number of lines
  867. uint8_t **line; ///< line buffer
  868. uint8_t **tmp; ///< Tmp line buffer used by mmx code
  869. } SwsPlane;
  870. /**
  871. * Struct which defines a slice of an image to be scaled or a output for
  872. * a scaled slice.
  873. * A slice can also be used as intermediate ring buffer for scaling steps.
  874. */
  875. typedef struct SwsSlice
  876. {
  877. int width; ///< Slice line width
  878. int h_chr_sub_sample; ///< horizontal chroma subsampling factor
  879. int v_chr_sub_sample; ///< vertical chroma subsampling factor
  880. int is_ring; ///< flag to identify if this slice is a ring buffer
  881. int should_free_lines; ///< flag to identify if there are dynamic allocated lines
  882. enum AVPixelFormat fmt; ///< planes pixel format
  883. SwsPlane plane[MAX_SLICE_PLANES]; ///< color planes
  884. } SwsSlice;
  885. /**
  886. * Struct which holds all necessary data for processing a slice.
  887. * A processing step can be a color conversion or horizontal/vertical scaling.
  888. */
  889. typedef struct SwsFilterDescriptor
  890. {
  891. SwsSlice *src; ///< Source slice
  892. SwsSlice *dst; ///< Output slice
  893. int alpha; ///< Flag for processing alpha channel
  894. void *instance; ///< Filter instance data
  895. /// Function for processing input slice sliceH lines starting from line sliceY
  896. int (*process)(SwsContext *c, struct SwsFilterDescriptor *desc, int sliceY, int sliceH);
  897. } SwsFilterDescriptor;
  898. /// Color conversion instance data
  899. typedef struct ColorContext
  900. {
  901. uint32_t *pal;
  902. } ColorContext;
  903. /// Scaler instance data
  904. typedef struct FilterContext
  905. {
  906. uint16_t *filter;
  907. int *filter_pos;
  908. int filter_size;
  909. int xInc;
  910. } FilterContext;
  911. typedef struct VScalerContext
  912. {
  913. uint16_t *filter[2];
  914. int32_t *filter_pos;
  915. int filter_size;
  916. int isMMX;
  917. void *pfn;
  918. } VScalerContext;
  919. // warp input lines in the form (src + width*i + j) to slice format (line[i][j])
  920. int ff_init_slice_from_src(SwsSlice * s, uint8_t *src[4], int stride[4], int srcW, int lumY, int lumH, int chrY, int chrH);
  921. // Initialize scaler filter descriptor chain
  922. int ff_init_filters(SwsContext *c);
  923. // Free all filter data
  924. int ff_free_filters(SwsContext *c);
  925. /*
  926. function for applying ring buffer logic into slice s
  927. It checks if the slice can hold more @lum lines, if yes
  928. do nothing otherwise remove @lum least used lines.
  929. It applies the same procedure for @chr lines.
  930. */
  931. int ff_rotate_slice(SwsSlice *s, int lum, int chr);
  932. /// initializes lum pixel format conversion descriptor
  933. int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
  934. /// initializes lum horizontal scaling descriptor
  935. int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
  936. /// initializes chr pixel format conversion descriptor
  937. int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
  938. /// initializes chr horizontal scaling descriptor
  939. int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
  940. int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst);
  941. /// initializes vertical scaling descriptors
  942. int ff_init_vscale(SwsContext *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst);
  943. /// setup vertical scaler functions
  944. void ff_init_vscale_pfn(SwsContext *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX,
  945. yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2,
  946. yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx);
  947. //number of extra lines to process
  948. #define MAX_LINES_AHEAD 4
  949. // enable use of refactored scaler code
  950. #define NEW_FILTER
  951. #endif /* SWSCALE_SWSCALE_INTERNAL_H */