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.

673 lines
31KB

  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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 "libavutil/avutil.h"
  27. #include "libavutil/log.h"
  28. #include "libavutil/pixfmt.h"
  29. #include "libavutil/pixdesc.h"
  30. #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long
  31. #define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients
  32. #define MAX_FILTER_SIZE 256
  33. #if HAVE_BIGENDIAN
  34. #define ALT32_CORR (-1)
  35. #else
  36. #define ALT32_CORR 1
  37. #endif
  38. #if ARCH_X86_64
  39. # define APCK_PTR2 8
  40. # define APCK_COEF 16
  41. # define APCK_SIZE 24
  42. #else
  43. # define APCK_PTR2 4
  44. # define APCK_COEF 8
  45. # define APCK_SIZE 16
  46. #endif
  47. struct SwsContext;
  48. typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[],
  49. int srcStride[], int srcSliceY, int srcSliceH,
  50. uint8_t *dst[], int dstStride[]);
  51. /**
  52. * Write one line of horizontally scaled data to planar output
  53. * without any additional vertical scaling (or point-scaling).
  54. *
  55. * @param src scaled source data, 15bit for 8-10bit output,
  56. * 19-bit for 16bit output (in int32_t)
  57. * @param dest pointer to the output plane. For >8bit
  58. * output, this is in uint16_t
  59. * @param dstW width of destination in pixels
  60. * @param dither ordered dither array of type int16_t and size 8
  61. * @param offset Dither offset
  62. */
  63. typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW,
  64. const uint8_t *dither, int offset);
  65. /**
  66. * Write one line of horizontally scaled data to planar output
  67. * with multi-point vertical scaling between input pixels.
  68. *
  69. * @param filter vertical luma/alpha scaling coefficients, 12bit [0,4096]
  70. * @param src scaled luma (Y) or alpha (A) source data, 15bit for 8-10bit output,
  71. * 19-bit for 16bit output (in int32_t)
  72. * @param filterSize number of vertical input lines to scale
  73. * @param dest pointer to output plane. For >8bit
  74. * output, this is in uint16_t
  75. * @param dstW width of destination pixels
  76. * @param offset Dither offset
  77. */
  78. typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize,
  79. const int16_t **src, uint8_t *dest, int dstW,
  80. const uint8_t *dither, int offset);
  81. /**
  82. * Write one line of horizontally scaled chroma to interleaved output
  83. * with multi-point vertical scaling between input pixels.
  84. *
  85. * @param c SWS scaling context
  86. * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
  87. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  88. * 19-bit for 16bit output (in int32_t)
  89. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  90. * 19-bit for 16bit output (in int32_t)
  91. * @param chrFilterSize number of vertical chroma input lines to scale
  92. * @param dest pointer to the output plane. For >8bit
  93. * output, this is in uint16_t
  94. * @param dstW width of chroma planes
  95. */
  96. typedef void (*yuv2interleavedX_fn)(struct SwsContext *c,
  97. const int16_t *chrFilter,
  98. int chrFilterSize,
  99. const int16_t **chrUSrc,
  100. const int16_t **chrVSrc,
  101. uint8_t *dest, int dstW);
  102. /**
  103. * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
  104. * output without any additional vertical scaling (or point-scaling). Note
  105. * that this function may do chroma scaling, see the "uvalpha" argument.
  106. *
  107. * @param c SWS scaling context
  108. * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
  109. * 19-bit for 16bit output (in int32_t)
  110. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  111. * 19-bit for 16bit output (in int32_t)
  112. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  113. * 19-bit for 16bit output (in int32_t)
  114. * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
  115. * 19-bit for 16bit output (in int32_t)
  116. * @param dest pointer to the output plane. For 16bit output, this is
  117. * uint16_t
  118. * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
  119. * to write into dest[]
  120. * @param uvalpha chroma scaling coefficient for the second line of chroma
  121. * pixels, either 2048 or 0. If 0, one chroma input is used
  122. * for 2 output pixels (or if the SWS_FLAG_FULL_CHR_INT flag
  123. * is set, it generates 1 output pixel). If 2048, two chroma
  124. * input pixels should be averaged for 2 output pixels (this
  125. * only happens if SWS_FLAG_FULL_CHR_INT is not set)
  126. * @param y vertical line number for this output. This does not need
  127. * to be used to calculate the offset in the destination,
  128. * but can be used to generate comfort noise using dithering
  129. * for some output formats.
  130. */
  131. typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc,
  132. const int16_t *chrUSrc[2],
  133. const int16_t *chrVSrc[2],
  134. const int16_t *alpSrc, uint8_t *dest,
  135. int dstW, int uvalpha, int y);
  136. /**
  137. * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
  138. * output by doing bilinear scaling between two input lines.
  139. *
  140. * @param c SWS scaling context
  141. * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
  142. * 19-bit for 16bit output (in int32_t)
  143. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  144. * 19-bit for 16bit output (in int32_t)
  145. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  146. * 19-bit for 16bit output (in int32_t)
  147. * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
  148. * 19-bit for 16bit output (in int32_t)
  149. * @param dest pointer to the output plane. For 16bit output, this is
  150. * uint16_t
  151. * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
  152. * to write into dest[]
  153. * @param yalpha luma/alpha scaling coefficients for the second input line.
  154. * The first line's coefficients can be calculated by using
  155. * 4096 - yalpha
  156. * @param uvalpha chroma scaling coefficient for the second input line. The
  157. * first line's coefficients can be calculated by using
  158. * 4096 - uvalpha
  159. * @param y vertical line number for this output. This does not need
  160. * to be used to calculate the offset in the destination,
  161. * but can be used to generate comfort noise using dithering
  162. * for some output formats.
  163. */
  164. typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2],
  165. const int16_t *chrUSrc[2],
  166. const int16_t *chrVSrc[2],
  167. const int16_t *alpSrc[2],
  168. uint8_t *dest,
  169. int dstW, int yalpha, int uvalpha, int y);
  170. /**
  171. * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB
  172. * output by doing multi-point vertical scaling between input pixels.
  173. *
  174. * @param c SWS scaling context
  175. * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096]
  176. * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output,
  177. * 19-bit for 16bit output (in int32_t)
  178. * @param lumFilterSize number of vertical luma/alpha input lines to scale
  179. * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096]
  180. * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output,
  181. * 19-bit for 16bit output (in int32_t)
  182. * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output,
  183. * 19-bit for 16bit output (in int32_t)
  184. * @param chrFilterSize number of vertical chroma input lines to scale
  185. * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output,
  186. * 19-bit for 16bit output (in int32_t)
  187. * @param dest pointer to the output plane. For 16bit output, this is
  188. * uint16_t
  189. * @param dstW width of lumSrc and alpSrc in pixels, number of pixels
  190. * to write into dest[]
  191. * @param y vertical line number for this output. This does not need
  192. * to be used to calculate the offset in the destination,
  193. * but can be used to generate comfort noise using dithering
  194. * or some output formats.
  195. */
  196. typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
  197. const int16_t **lumSrc, int lumFilterSize,
  198. const int16_t *chrFilter,
  199. const int16_t **chrUSrc,
  200. const int16_t **chrVSrc, int chrFilterSize,
  201. const int16_t **alpSrc, uint8_t *dest,
  202. int dstW, int y);
  203. /* This struct should be aligned on at least a 32-byte boundary. */
  204. typedef struct SwsContext {
  205. /**
  206. * info on struct for av_log
  207. */
  208. const AVClass *av_class;
  209. /**
  210. * Note that src, dst, srcStride, dstStride will be copied in the
  211. * sws_scale() wrapper so they can be freely modified here.
  212. */
  213. SwsFunc swScale;
  214. int srcW; ///< Width of source luma/alpha planes.
  215. int srcH; ///< Height of source luma/alpha planes.
  216. int dstH; ///< Height of destination luma/alpha planes.
  217. int chrSrcW; ///< Width of source chroma planes.
  218. int chrSrcH; ///< Height of source chroma planes.
  219. int chrDstW; ///< Width of destination chroma planes.
  220. int chrDstH; ///< Height of destination chroma planes.
  221. int lumXInc, chrXInc;
  222. int lumYInc, chrYInc;
  223. enum PixelFormat dstFormat; ///< Destination pixel format.
  224. enum PixelFormat srcFormat; ///< Source pixel format.
  225. int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format.
  226. int srcFormatBpp; ///< Number of bits per pixel of the source pixel format.
  227. int dstBpc, srcBpc;
  228. int chrSrcHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source image.
  229. int chrSrcVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image.
  230. int chrDstHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image.
  231. int chrDstVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination image.
  232. int vChrDrop; ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user.
  233. int sliceDir; ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
  234. double param[2]; ///< Input parameters for scaling algorithms that need them.
  235. uint32_t pal_yuv[256];
  236. uint32_t pal_rgb[256];
  237. /**
  238. * @name Scaled horizontal lines ring buffer.
  239. * The horizontal scaler keeps just enough scaled lines in a ring buffer
  240. * so they may be passed to the vertical scaler. The pointers to the
  241. * allocated buffers for each line are duplicated in sequence in the ring
  242. * buffer to simplify indexing and avoid wrapping around between lines
  243. * inside the vertical scaler code. The wrapping is done before the
  244. * vertical scaler is called.
  245. */
  246. //@{
  247. int16_t **lumPixBuf; ///< Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler.
  248. int16_t **chrUPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
  249. int16_t **chrVPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
  250. int16_t **alpPixBuf; ///< Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler.
  251. int vLumBufSize; ///< Number of vertical luma/alpha lines allocated in the ring buffer.
  252. int vChrBufSize; ///< Number of vertical chroma lines allocated in the ring buffer.
  253. int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer.
  254. int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer.
  255. int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source.
  256. int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source.
  257. //@}
  258. uint8_t *formatConvBuffer;
  259. /**
  260. * @name Horizontal and vertical filters.
  261. * To better understand the following fields, here is a pseudo-code of
  262. * their usage in filtering a horizontal line:
  263. * @code
  264. * for (i = 0; i < width; i++) {
  265. * dst[i] = 0;
  266. * for (j = 0; j < filterSize; j++)
  267. * dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ];
  268. * dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point.
  269. * }
  270. * @endcode
  271. */
  272. //@{
  273. int16_t *hLumFilter; ///< Array of horizontal filter coefficients for luma/alpha planes.
  274. int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes.
  275. int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes.
  276. int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes.
  277. int32_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
  278. int32_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes.
  279. int32_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes.
  280. int32_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes.
  281. int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels.
  282. int hChrFilterSize; ///< Horizontal filter size for chroma pixels.
  283. int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels.
  284. int vChrFilterSize; ///< Vertical filter size for chroma pixels.
  285. //@}
  286. int lumMmx2FilterCodeSize; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code size for luma/alpha planes.
  287. int chrMmx2FilterCodeSize; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code size for chroma planes.
  288. uint8_t *lumMmx2FilterCode; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code for luma/alpha planes.
  289. uint8_t *chrMmx2FilterCode; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code for chroma planes.
  290. int canMMX2BeUsed;
  291. int dstY; ///< Last destination vertical line output from last slice.
  292. int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
  293. void *yuvTable; // pointer to the yuv->rgb table start so it can be freed()
  294. uint8_t *table_rV[256];
  295. uint8_t *table_gU[256];
  296. int table_gV[256];
  297. uint8_t *table_bU[256];
  298. //Colorspace stuff
  299. int contrast, brightness, saturation; // for sws_getColorspaceDetails
  300. int srcColorspaceTable[4];
  301. int dstColorspaceTable[4];
  302. int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image).
  303. int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image).
  304. int yuv2rgb_y_offset;
  305. int yuv2rgb_y_coeff;
  306. int yuv2rgb_v2r_coeff;
  307. int yuv2rgb_v2g_coeff;
  308. int yuv2rgb_u2g_coeff;
  309. int yuv2rgb_u2b_coeff;
  310. #define RED_DITHER "0*8"
  311. #define GREEN_DITHER "1*8"
  312. #define BLUE_DITHER "2*8"
  313. #define Y_COEFF "3*8"
  314. #define VR_COEFF "4*8"
  315. #define UB_COEFF "5*8"
  316. #define VG_COEFF "6*8"
  317. #define UG_COEFF "7*8"
  318. #define Y_OFFSET "8*8"
  319. #define U_OFFSET "9*8"
  320. #define V_OFFSET "10*8"
  321. #define LUM_MMX_FILTER_OFFSET "11*8"
  322. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
  323. #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
  324. #define ESP_OFFSET "11*8+4*4*256*2+8"
  325. #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
  326. #define U_TEMP "11*8+4*4*256*2+24"
  327. #define V_TEMP "11*8+4*4*256*2+32"
  328. #define Y_TEMP "11*8+4*4*256*2+40"
  329. #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
  330. #define UV_OFF_PX "11*8+4*4*256*3+48"
  331. #define UV_OFF_BYTE "11*8+4*4*256*3+56"
  332. #define DITHER16 "11*8+4*4*256*3+64"
  333. #define DITHER32 "11*8+4*4*256*3+80"
  334. DECLARE_ALIGNED(8, uint64_t, redDither);
  335. DECLARE_ALIGNED(8, uint64_t, greenDither);
  336. DECLARE_ALIGNED(8, uint64_t, blueDither);
  337. DECLARE_ALIGNED(8, uint64_t, yCoeff);
  338. DECLARE_ALIGNED(8, uint64_t, vrCoeff);
  339. DECLARE_ALIGNED(8, uint64_t, ubCoeff);
  340. DECLARE_ALIGNED(8, uint64_t, vgCoeff);
  341. DECLARE_ALIGNED(8, uint64_t, ugCoeff);
  342. DECLARE_ALIGNED(8, uint64_t, yOffset);
  343. DECLARE_ALIGNED(8, uint64_t, uOffset);
  344. DECLARE_ALIGNED(8, uint64_t, vOffset);
  345. int32_t lumMmxFilter[4 * MAX_FILTER_SIZE];
  346. int32_t chrMmxFilter[4 * MAX_FILTER_SIZE];
  347. int dstW; ///< Width of destination luma/alpha planes.
  348. DECLARE_ALIGNED(8, uint64_t, esp);
  349. DECLARE_ALIGNED(8, uint64_t, vRounder);
  350. DECLARE_ALIGNED(8, uint64_t, u_temp);
  351. DECLARE_ALIGNED(8, uint64_t, v_temp);
  352. DECLARE_ALIGNED(8, uint64_t, y_temp);
  353. int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
  354. // alignment of these values is not necessary, but merely here
  355. // to maintain the same offset across x8632 and x86-64. Once we
  356. // use proper offset macros in the asm, they can be removed.
  357. DECLARE_ALIGNED(8, ptrdiff_t, uv_off_px); ///< offset (in pixels) between u and v planes
  358. DECLARE_ALIGNED(8, ptrdiff_t, uv_off_byte); ///< offset (in bytes) between u and v planes
  359. DECLARE_ALIGNED(8, uint16_t, dither16)[8];
  360. DECLARE_ALIGNED(8, uint32_t, dither32)[8];
  361. const uint8_t *chrDither8, *lumDither8;
  362. #if HAVE_ALTIVEC
  363. vector signed short CY;
  364. vector signed short CRV;
  365. vector signed short CBU;
  366. vector signed short CGU;
  367. vector signed short CGV;
  368. vector signed short OY;
  369. vector unsigned short CSHIFT;
  370. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  371. #endif
  372. #if ARCH_BFIN
  373. DECLARE_ALIGNED(4, uint32_t, oy);
  374. DECLARE_ALIGNED(4, uint32_t, oc);
  375. DECLARE_ALIGNED(4, uint32_t, zero);
  376. DECLARE_ALIGNED(4, uint32_t, cy);
  377. DECLARE_ALIGNED(4, uint32_t, crv);
  378. DECLARE_ALIGNED(4, uint32_t, rmask);
  379. DECLARE_ALIGNED(4, uint32_t, cbu);
  380. DECLARE_ALIGNED(4, uint32_t, bmask);
  381. DECLARE_ALIGNED(4, uint32_t, cgu);
  382. DECLARE_ALIGNED(4, uint32_t, cgv);
  383. DECLARE_ALIGNED(4, uint32_t, gmask);
  384. #endif
  385. #if HAVE_VIS
  386. DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
  387. #endif
  388. /* function pointers for swScale() */
  389. yuv2planar1_fn yuv2plane1;
  390. yuv2planarX_fn yuv2planeX;
  391. yuv2interleavedX_fn yuv2nv12cX;
  392. yuv2packed1_fn yuv2packed1;
  393. yuv2packed2_fn yuv2packed2;
  394. yuv2packedX_fn yuv2packedX;
  395. /// Unscaled conversion of luma plane to YV12 for horizontal scaler.
  396. void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
  397. int width, uint32_t *pal);
  398. /// Unscaled conversion of alpha plane to YV12 for horizontal scaler.
  399. void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
  400. int width, uint32_t *pal);
  401. /// Unscaled conversion of chroma planes to YV12 for horizontal scaler.
  402. void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
  403. const uint8_t *src1, const uint8_t *src2,
  404. int width, uint32_t *pal);
  405. /**
  406. * Functions to read planar input, such as planar RGB, and convert
  407. * internally to Y/UV.
  408. */
  409. /** @{ */
  410. void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width);
  411. void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
  412. int width);
  413. /** @} */
  414. /**
  415. * Scale one horizontal line of input data using a bilinear filter
  416. * to produce one line of output data. Compared to SwsContext->hScale(),
  417. * please take note of the following caveats when using these:
  418. * - Scaling is done using only 7bit instead of 14bit coefficients.
  419. * - You can use no more than 5 input pixels to produce 4 output
  420. * pixels. Therefore, this filter should not be used for downscaling
  421. * by more than ~20% in width (because that equals more than 5/4th
  422. * downscaling and thus more than 5 pixels input per 4 pixels output).
  423. * - In general, bilinear filters create artifacts during downscaling
  424. * (even when <20%), because one output pixel will span more than one
  425. * input pixel, and thus some pixels will need edges of both neighbor
  426. * pixels to interpolate the output pixel. Since you can use at most
  427. * two input pixels per output pixel in bilinear scaling, this is
  428. * impossible and thus downscaling by any size will create artifacts.
  429. * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR
  430. * in SwsContext->flags.
  431. */
  432. /** @{ */
  433. void (*hyscale_fast)(struct SwsContext *c,
  434. int16_t *dst, int dstWidth,
  435. const uint8_t *src, int srcW, int xInc);
  436. void (*hcscale_fast)(struct SwsContext *c,
  437. int16_t *dst1, int16_t *dst2, int dstWidth,
  438. const uint8_t *src1, const uint8_t *src2,
  439. int srcW, int xInc);
  440. /** @} */
  441. /**
  442. * Scale one horizontal line of input data using a filter over the input
  443. * lines, to produce one (differently sized) line of output data.
  444. *
  445. * @param dst pointer to destination buffer for horizontally scaled
  446. * data. If the number of bits per component of one
  447. * destination pixel (SwsContext->dstBpc) is <= 10, data
  448. * will be 15bpc in 16bits (int16_t) width. Else (i.e.
  449. * SwsContext->dstBpc == 16), data will be 19bpc in
  450. * 32bits (int32_t) width.
  451. * @param dstW width of destination image
  452. * @param src pointer to source data to be scaled. If the number of
  453. * bits per component of a source pixel (SwsContext->srcBpc)
  454. * is 8, this is 8bpc in 8bits (uint8_t) width. Else
  455. * (i.e. SwsContext->dstBpc > 8), this is native depth
  456. * in 16bits (uint16_t) width. In other words, for 9-bit
  457. * YUV input, this is 9bpc, for 10-bit YUV input, this is
  458. * 10bpc, and for 16-bit RGB or YUV, this is 16bpc.
  459. * @param filter filter coefficients to be used per output pixel for
  460. * scaling. This contains 14bpp filtering coefficients.
  461. * Guaranteed to contain dstW * filterSize entries.
  462. * @param filterPos position of the first input pixel to be used for
  463. * each output pixel during scaling. Guaranteed to
  464. * contain dstW entries.
  465. * @param filterSize the number of input coefficients to be used (and
  466. * thus the number of input pixels to be used) for
  467. * creating a single output pixel. Is aligned to 4
  468. * (and input coefficients thus padded with zeroes)
  469. * to simplify creating SIMD code.
  470. */
  471. /** @{ */
  472. void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
  473. const uint8_t *src, const int16_t *filter,
  474. const int32_t *filterPos, int filterSize);
  475. void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
  476. const uint8_t *src, const int16_t *filter,
  477. const int32_t *filterPos, int filterSize);
  478. /** @} */
  479. /// Color range conversion function for luma plane if needed.
  480. void (*lumConvertRange)(int16_t *dst, int width);
  481. /// Color range conversion function for chroma planes if needed.
  482. void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
  483. int needs_hcscale; ///< Set if there are chroma planes to be converted.
  484. } SwsContext;
  485. //FIXME check init (where 0)
  486. SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
  487. int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
  488. int fullRange, int brightness,
  489. int contrast, int saturation);
  490. void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
  491. int brightness, int contrast, int saturation);
  492. void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
  493. int lastInLumBuf, int lastInChrBuf);
  494. SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c);
  495. SwsFunc ff_yuv2rgb_init_vis(SwsContext *c);
  496. SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c);
  497. SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c);
  498. void ff_bfin_get_unscaled_swscale(SwsContext *c);
  499. const char *sws_format_name(enum PixelFormat format);
  500. #define is16BPS(x) \
  501. (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 15)
  502. #define is9_OR_10BPS(x) \
  503. (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 8 || \
  504. av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 9)
  505. #define isBE(x) \
  506. (av_pix_fmt_descriptors[x].flags & PIX_FMT_BE)
  507. #define isYUV(x) \
  508. (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB) && \
  509. av_pix_fmt_descriptors[x].nb_components >= 2)
  510. #define isPlanarYUV(x) \
  511. ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR) && \
  512. isYUV(x))
  513. #define isRGB(x) \
  514. (av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB)
  515. #if 0 // FIXME
  516. #define isGray(x) \
  517. (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) && \
  518. av_pix_fmt_descriptors[x].nb_components <= 2)
  519. #else
  520. #define isGray(x) \
  521. ((x) == PIX_FMT_GRAY8 || \
  522. (x) == PIX_FMT_Y400A || \
  523. (x) == PIX_FMT_GRAY16BE || \
  524. (x) == PIX_FMT_GRAY16LE)
  525. #endif
  526. #define isRGBinInt(x) \
  527. ((x) == PIX_FMT_RGB48BE || \
  528. (x) == PIX_FMT_RGB48LE || \
  529. (x) == PIX_FMT_RGB32 || \
  530. (x) == PIX_FMT_RGB32_1 || \
  531. (x) == PIX_FMT_RGB24 || \
  532. (x) == PIX_FMT_RGB565BE || \
  533. (x) == PIX_FMT_RGB565LE || \
  534. (x) == PIX_FMT_RGB555BE || \
  535. (x) == PIX_FMT_RGB555LE || \
  536. (x) == PIX_FMT_RGB444BE || \
  537. (x) == PIX_FMT_RGB444LE || \
  538. (x) == PIX_FMT_RGB8 || \
  539. (x) == PIX_FMT_RGB4 || \
  540. (x) == PIX_FMT_RGB4_BYTE || \
  541. (x) == PIX_FMT_MONOBLACK || \
  542. (x) == PIX_FMT_MONOWHITE)
  543. #define isBGRinInt(x) \
  544. ((x) == PIX_FMT_BGR48BE || \
  545. (x) == PIX_FMT_BGR48LE || \
  546. (x) == PIX_FMT_BGR32 || \
  547. (x) == PIX_FMT_BGR32_1 || \
  548. (x) == PIX_FMT_BGR24 || \
  549. (x) == PIX_FMT_BGR565BE || \
  550. (x) == PIX_FMT_BGR565LE || \
  551. (x) == PIX_FMT_BGR555BE || \
  552. (x) == PIX_FMT_BGR555LE || \
  553. (x) == PIX_FMT_BGR444BE || \
  554. (x) == PIX_FMT_BGR444LE || \
  555. (x) == PIX_FMT_BGR8 || \
  556. (x) == PIX_FMT_BGR4 || \
  557. (x) == PIX_FMT_BGR4_BYTE || \
  558. (x) == PIX_FMT_MONOBLACK || \
  559. (x) == PIX_FMT_MONOWHITE)
  560. #define isAnyRGB(x) \
  561. (isRGBinInt(x) || \
  562. isBGRinInt(x))
  563. #define isALPHA(x) \
  564. (av_pix_fmt_descriptors[x].nb_components == 2 || \
  565. av_pix_fmt_descriptors[x].nb_components == 4)
  566. #define isPacked(x) \
  567. ((av_pix_fmt_descriptors[x].nb_components >= 2 && \
  568. !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) || \
  569. (x) == PIX_FMT_PAL8)
  570. #define isPlanar(x) \
  571. (av_pix_fmt_descriptors[x].nb_components >= 2 && \
  572. (av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
  573. #define isPackedRGB(x) \
  574. ((av_pix_fmt_descriptors[x].flags & \
  575. (PIX_FMT_PLANAR | PIX_FMT_RGB)) == PIX_FMT_RGB)
  576. #define isPlanarRGB(x) \
  577. ((av_pix_fmt_descriptors[x].flags & \
  578. (PIX_FMT_PLANAR | PIX_FMT_RGB)) == (PIX_FMT_PLANAR | PIX_FMT_RGB))
  579. #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || \
  580. (av_pix_fmt_descriptors[x].flags & PIX_FMT_PSEUDOPAL) || \
  581. (x) == PIX_FMT_Y400A)
  582. extern const uint64_t ff_dither4[2];
  583. extern const uint64_t ff_dither8[2];
  584. extern const AVClass sws_context_class;
  585. /**
  586. * Set c->swScale to an unscaled converter if one exists for the specific
  587. * source and destination formats, bit depths, flags, etc.
  588. */
  589. void ff_get_unscaled_swscale(SwsContext *c);
  590. void ff_swscale_get_unscaled_altivec(SwsContext *c);
  591. /**
  592. * Return function pointer to fastest main scaler path function depending
  593. * on architecture and available optimizations.
  594. */
  595. SwsFunc ff_getSwsFunc(SwsContext *c);
  596. void ff_sws_init_input_funcs(SwsContext *c);
  597. void ff_sws_init_output_funcs(SwsContext *c,
  598. yuv2planar1_fn *yuv2plane1,
  599. yuv2planarX_fn *yuv2planeX,
  600. yuv2interleavedX_fn *yuv2nv12cX,
  601. yuv2packed1_fn *yuv2packed1,
  602. yuv2packed2_fn *yuv2packed2,
  603. yuv2packedX_fn *yuv2packedX);
  604. void ff_sws_init_swScale_altivec(SwsContext *c);
  605. void ff_sws_init_swScale_mmx(SwsContext *c);
  606. #endif /* SWSCALE_SWSCALE_INTERNAL_H */