swscale_internal.h 45 KB

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