swscale_internal.h 44 KB

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