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