swscale_internal.h 31 KB

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