swscale_internal.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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, 15 bits for 8-10-bit output,
  78. * 19 bits for 16-bit output (in int32_t)
  79. * @param dest pointer to the output plane. For >8-bit
  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, 12 bits [0,4096]
  92. * @param src scaled luma (Y) or alpha (A) source data, 15 bits for
  93. * 8-10-bit output, 19 bits for 16-bit output (in int32_t)
  94. * @param filterSize number of vertical input lines to scale
  95. * @param dest pointer to output plane. For >8-bit
  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, 12 bits [0,4096]
  109. * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit
  110. * output, 19 bits for 16-bit output (in int32_t)
  111. * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit
  112. * output, 19 bits for 16-bit output (in int32_t)
  113. * @param chrFilterSize number of vertical chroma input lines to scale
  114. * @param dest pointer to the output plane. For >8-bit
  115. * output, this is in uint16_t
  116. * @param dstW width of chroma planes
  117. */
  118. typedef void (*yuv2interleavedX_fn)(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, 15 bits for 8-10-bit output,
  131. * 19 bits for 16-bit output (in int32_t)
  132. * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output,
  133. * 19 bits for 16-bit output (in int32_t)
  134. * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output,
  135. * 19 bits for 16-bit output (in int32_t)
  136. * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output,
  137. * 19 bits for 16-bit output (in int32_t)
  138. * @param dest pointer to the output plane. For 16-bit 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, 15 bits for 8-10-bit output,
  164. * 19 bits for 16-bit output (in int32_t)
  165. * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output,
  166. * 19 bits for 16-bit output (in int32_t)
  167. * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output,
  168. * 19 bits for 16-bit output (in int32_t)
  169. * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output,
  170. * 19 bits for 16-bit output (in int32_t)
  171. * @param dest pointer to the output plane. For 16-bit 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, 12 bits [0,4096]
  198. * @param lumSrc scaled luma (Y) source data, 15 bits for 8-10-bit output,
  199. * 19 bits for 16-bit output (in int32_t)
  200. * @param lumFilterSize number of vertical luma/alpha input lines to scale
  201. * @param chrFilter vertical chroma scaling coefficients, 12 bits [0,4096]
  202. * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output,
  203. * 19 bits for 16-bit output (in int32_t)
  204. * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output,
  205. * 19 bits for 16-bit output (in int32_t)
  206. * @param chrFilterSize number of vertical chroma input lines to scale
  207. * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output,
  208. * 19 bits for 16-bit output (in int32_t)
  209. * @param dest pointer to the output plane. For 16-bit 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, 12 bits [0,4096]
  231. * @param lumSrc scaled luma (Y) source data, 15 bits for 8-10-bit output,
  232. * 19 bits for 16-bit output (in int32_t)
  233. * @param lumFilterSize number of vertical luma/alpha input lines to scale
  234. * @param chrFilter vertical chroma scaling coefficients, 12 bits [0,4096]
  235. * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output,
  236. * 19 bits for 16-bit output (in int32_t)
  237. * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output,
  238. * 19 bits for 16-bit output (in int32_t)
  239. * @param chrFilterSize number of vertical chroma input lines to scale
  240. * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output,
  241. * 19 bits for 16-bit output (in int32_t)
  242. * @param dest pointer to the output planes. For 16-bit 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. int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer.
  325. int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer.
  326. int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source.
  327. int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source.
  328. //@}
  329. uint8_t *formatConvBuffer;
  330. int needAlpha;
  331. /**
  332. * @name Horizontal and vertical filters.
  333. * To better understand the following fields, here is a pseudo-code of
  334. * their usage in filtering a horizontal line:
  335. * @code
  336. * for (i = 0; i < width; i++) {
  337. * dst[i] = 0;
  338. * for (j = 0; j < filterSize; j++)
  339. * dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ];
  340. * dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point.
  341. * }
  342. * @endcode
  343. */
  344. //@{
  345. int16_t *hLumFilter; ///< Array of horizontal filter coefficients for luma/alpha planes.
  346. int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes.
  347. int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes.
  348. int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes.
  349. int32_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
  350. int32_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes.
  351. int32_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes.
  352. int32_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes.
  353. int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels.
  354. int hChrFilterSize; ///< Horizontal filter size for chroma pixels.
  355. int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels.
  356. int vChrFilterSize; ///< Vertical filter size for chroma pixels.
  357. //@}
  358. int lumMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for luma/alpha planes.
  359. int chrMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for chroma planes.
  360. uint8_t *lumMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for luma/alpha planes.
  361. uint8_t *chrMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for chroma planes.
  362. int canMMXEXTBeUsed;
  363. int warned_unuseable_bilinear;
  364. int dstY; ///< Last destination vertical line output from last slice.
  365. int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
  366. void *yuvTable; // pointer to the yuv->rgb table start so it can be freed()
  367. // alignment ensures the offset can be added in a single
  368. // instruction on e.g. ARM
  369. DECLARE_ALIGNED(16, int, table_gV)[256 + 2*YUVRGB_TABLE_HEADROOM];
  370. uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM];
  371. uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM];
  372. uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM];
  373. DECLARE_ALIGNED(16, int32_t, input_rgb2yuv_table)[16+40*4]; // This table can contain both C and SIMD formatted values, the C vales are always at the XY_IDX points
  374. #define RY_IDX 0
  375. #define GY_IDX 1
  376. #define BY_IDX 2
  377. #define RU_IDX 3
  378. #define GU_IDX 4
  379. #define BU_IDX 5
  380. #define RV_IDX 6
  381. #define GV_IDX 7
  382. #define BV_IDX 8
  383. #define RGB2YUV_SHIFT 15
  384. int *dither_error[4];
  385. //Colorspace stuff
  386. int contrast, brightness, saturation; // for sws_getColorspaceDetails
  387. int srcColorspaceTable[4];
  388. int dstColorspaceTable[4];
  389. int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image).
  390. int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image).
  391. int src0Alpha;
  392. int dst0Alpha;
  393. int srcXYZ;
  394. int dstXYZ;
  395. int src_h_chr_pos;
  396. int dst_h_chr_pos;
  397. int src_v_chr_pos;
  398. int dst_v_chr_pos;
  399. int yuv2rgb_y_offset;
  400. int yuv2rgb_y_coeff;
  401. int yuv2rgb_v2r_coeff;
  402. int yuv2rgb_v2g_coeff;
  403. int yuv2rgb_u2g_coeff;
  404. int yuv2rgb_u2b_coeff;
  405. #define RED_DITHER "0*8"
  406. #define GREEN_DITHER "1*8"
  407. #define BLUE_DITHER "2*8"
  408. #define Y_COEFF "3*8"
  409. #define VR_COEFF "4*8"
  410. #define UB_COEFF "5*8"
  411. #define VG_COEFF "6*8"
  412. #define UG_COEFF "7*8"
  413. #define Y_OFFSET "8*8"
  414. #define U_OFFSET "9*8"
  415. #define V_OFFSET "10*8"
  416. #define LUM_MMX_FILTER_OFFSET "11*8"
  417. #define CHR_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)
  418. #define DSTW_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2"
  419. #define ESP_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+8"
  420. #define VROUNDER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+16"
  421. #define U_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+24"
  422. #define V_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+32"
  423. #define Y_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+40"
  424. #define ALP_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+48"
  425. #define UV_OFF_PX "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+48"
  426. #define UV_OFF_BYTE "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+56"
  427. #define DITHER16 "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+64"
  428. #define DITHER32 "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+80"
  429. #define DITHER32_INT (11*8+4*4*MAX_FILTER_SIZE*3+80) // value equal to above, used for checking that the struct hasn't been changed by mistake
  430. DECLARE_ALIGNED(8, uint64_t, redDither);
  431. DECLARE_ALIGNED(8, uint64_t, greenDither);
  432. DECLARE_ALIGNED(8, uint64_t, blueDither);
  433. DECLARE_ALIGNED(8, uint64_t, yCoeff);
  434. DECLARE_ALIGNED(8, uint64_t, vrCoeff);
  435. DECLARE_ALIGNED(8, uint64_t, ubCoeff);
  436. DECLARE_ALIGNED(8, uint64_t, vgCoeff);
  437. DECLARE_ALIGNED(8, uint64_t, ugCoeff);
  438. DECLARE_ALIGNED(8, uint64_t, yOffset);
  439. DECLARE_ALIGNED(8, uint64_t, uOffset);
  440. DECLARE_ALIGNED(8, uint64_t, vOffset);
  441. int32_t lumMmxFilter[4 * MAX_FILTER_SIZE];
  442. int32_t chrMmxFilter[4 * MAX_FILTER_SIZE];
  443. int dstW; ///< Width of destination luma/alpha planes.
  444. DECLARE_ALIGNED(8, uint64_t, esp);
  445. DECLARE_ALIGNED(8, uint64_t, vRounder);
  446. DECLARE_ALIGNED(8, uint64_t, u_temp);
  447. DECLARE_ALIGNED(8, uint64_t, v_temp);
  448. DECLARE_ALIGNED(8, uint64_t, y_temp);
  449. int32_t alpMmxFilter[4 * MAX_FILTER_SIZE];
  450. // alignment of these values is not necessary, but merely here
  451. // to maintain the same offset across x8632 and x86-64. Once we
  452. // use proper offset macros in the asm, they can be removed.
  453. DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes
  454. DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes
  455. DECLARE_ALIGNED(8, uint16_t, dither16)[8];
  456. DECLARE_ALIGNED(8, uint32_t, dither32)[8];
  457. const uint8_t *chrDither8, *lumDither8;
  458. #if HAVE_ALTIVEC
  459. vector signed short CY;
  460. vector signed short CRV;
  461. vector signed short CBU;
  462. vector signed short CGU;
  463. vector signed short CGV;
  464. vector signed short OY;
  465. vector unsigned short CSHIFT;
  466. vector signed short *vYCoeffsBank, *vCCoeffsBank;
  467. #endif
  468. int use_mmx_vfilter;
  469. /* pre defined color-spaces gamma */
  470. #define XYZ_GAMMA (2.6f)
  471. #define RGB_GAMMA (2.2f)
  472. int16_t *xyzgamma;
  473. int16_t *rgbgamma;
  474. int16_t *xyzgammainv;
  475. int16_t *rgbgammainv;
  476. int16_t xyz2rgb_matrix[3][4];
  477. int16_t rgb2xyz_matrix[3][4];
  478. /* function pointers for swscale() */
  479. yuv2planar1_fn yuv2plane1;
  480. yuv2planarX_fn yuv2planeX;
  481. yuv2interleavedX_fn yuv2nv12cX;
  482. yuv2packed1_fn yuv2packed1;
  483. yuv2packed2_fn yuv2packed2;
  484. yuv2packedX_fn yuv2packedX;
  485. yuv2anyX_fn yuv2anyX;
  486. /// Unscaled conversion of luma plane to YV12 for horizontal scaler.
  487. void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
  488. int width, uint32_t *pal);
  489. /// Unscaled conversion of alpha plane to YV12 for horizontal scaler.
  490. void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3,
  491. int width, uint32_t *pal);
  492. /// Unscaled conversion of chroma planes to YV12 for horizontal scaler.
  493. void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
  494. const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  495. int width, uint32_t *pal);
  496. /**
  497. * Functions to read planar input, such as planar RGB, and convert
  498. * internally to Y/UV/A.
  499. */
  500. /** @{ */
  501. void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv);
  502. void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
  503. int width, int32_t *rgb2yuv);
  504. void (*readAlpPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv);
  505. /** @} */
  506. /**
  507. * Scale one horizontal line of input data using a bilinear filter
  508. * to produce one line of output data. Compared to SwsContext->hScale(),
  509. * please take note of the following caveats when using these:
  510. * - Scaling is done using only 7 bits instead of 14-bit coefficients.
  511. * - You can use no more than 5 input pixels to produce 4 output
  512. * pixels. Therefore, this filter should not be used for downscaling
  513. * by more than ~20% in width (because that equals more than 5/4th
  514. * downscaling and thus more than 5 pixels input per 4 pixels output).
  515. * - In general, bilinear filters create artifacts during downscaling
  516. * (even when <20%), because one output pixel will span more than one
  517. * input pixel, and thus some pixels will need edges of both neighbor
  518. * pixels to interpolate the output pixel. Since you can use at most
  519. * two input pixels per output pixel in bilinear scaling, this is
  520. * impossible and thus downscaling by any size will create artifacts.
  521. * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR
  522. * in SwsContext->flags.
  523. */
  524. /** @{ */
  525. void (*hyscale_fast)(struct SwsContext *c,
  526. int16_t *dst, int dstWidth,
  527. const uint8_t *src, int srcW, int xInc);
  528. void (*hcscale_fast)(struct SwsContext *c,
  529. int16_t *dst1, int16_t *dst2, int dstWidth,
  530. const uint8_t *src1, const uint8_t *src2,
  531. int srcW, int xInc);
  532. /** @} */
  533. /**
  534. * Scale one horizontal line of input data using a filter over the input
  535. * lines, to produce one (differently sized) line of output data.
  536. *
  537. * @param dst pointer to destination buffer for horizontally scaled
  538. * data. If the number of bits per component of one
  539. * destination pixel (SwsContext->dstBpc) is <= 10, data
  540. * will be 15 bpc in 16 bits (int16_t) width. Else (i.e.
  541. * SwsContext->dstBpc == 16), data will be 19bpc in
  542. * 32 bits (int32_t) width.
  543. * @param dstW width of destination image
  544. * @param src pointer to source data to be scaled. If the number of
  545. * bits per component of a source pixel (SwsContext->srcBpc)
  546. * is 8, this is 8bpc in 8 bits (uint8_t) width. Else
  547. * (i.e. SwsContext->dstBpc > 8), this is native depth
  548. * in 16 bits (uint16_t) width. In other words, for 9-bit
  549. * YUV input, this is 9bpc, for 10-bit YUV input, this is
  550. * 10bpc, and for 16-bit RGB or YUV, this is 16bpc.
  551. * @param filter filter coefficients to be used per output pixel for
  552. * scaling. This contains 14bpp filtering coefficients.
  553. * Guaranteed to contain dstW * filterSize entries.
  554. * @param filterPos position of the first input pixel to be used for
  555. * each output pixel during scaling. Guaranteed to
  556. * contain dstW entries.
  557. * @param filterSize the number of input coefficients to be used (and
  558. * thus the number of input pixels to be used) for
  559. * creating a single output pixel. Is aligned to 4
  560. * (and input coefficients thus padded with zeroes)
  561. * to simplify creating SIMD code.
  562. */
  563. /** @{ */
  564. void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
  565. const uint8_t *src, const int16_t *filter,
  566. const int32_t *filterPos, int filterSize);
  567. void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
  568. const uint8_t *src, const int16_t *filter,
  569. const int32_t *filterPos, int filterSize);
  570. /** @} */
  571. /// Color range conversion function for luma plane if needed.
  572. void (*lumConvertRange)(int16_t *dst, int width);
  573. /// Color range conversion function for chroma planes if needed.
  574. void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
  575. int needs_hcscale; ///< Set if there are chroma planes to be converted.
  576. SwsDither dither;
  577. SwsAlphaBlend alphablend;
  578. } SwsContext;
  579. //FIXME check init (where 0)
  580. SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c);
  581. int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
  582. int fullRange, int brightness,
  583. int contrast, int saturation);
  584. void ff_yuv2rgb_init_tables_ppc(SwsContext *c, const int inv_table[4],
  585. int brightness, int contrast, int saturation);
  586. void ff_updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
  587. int lastInLumBuf, int lastInChrBuf);
  588. av_cold void ff_sws_init_range_convert(SwsContext *c);
  589. SwsFunc ff_yuv2rgb_init_x86(SwsContext *c);
  590. SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c);
  591. static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
  592. {
  593. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  594. av_assert0(desc);
  595. return desc->comp[0].depth == 16;
  596. }
  597. static av_always_inline int is9_OR_10BPS(enum AVPixelFormat pix_fmt)
  598. {
  599. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  600. av_assert0(desc);
  601. return desc->comp[0].depth >= 9 && desc->comp[0].depth <= 14;
  602. }
  603. #define isNBPS(x) is9_OR_10BPS(x)
  604. static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
  605. {
  606. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  607. av_assert0(desc);
  608. return desc->flags & AV_PIX_FMT_FLAG_BE;
  609. }
  610. static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
  611. {
  612. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  613. av_assert0(desc);
  614. return !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
  615. }
  616. static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
  617. {
  618. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  619. av_assert0(desc);
  620. return ((desc->flags & AV_PIX_FMT_FLAG_PLANAR) && isYUV(pix_fmt));
  621. }
  622. static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
  623. {
  624. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  625. av_assert0(desc);
  626. return (desc->flags & AV_PIX_FMT_FLAG_RGB);
  627. }
  628. #if 0 // FIXME
  629. #define isGray(x) \
  630. (!(av_pix_fmt_desc_get(x)->flags & AV_PIX_FMT_FLAG_PAL) && \
  631. av_pix_fmt_desc_get(x)->nb_components <= 2)
  632. #else
  633. #define isGray(x) \
  634. ((x) == AV_PIX_FMT_GRAY8 || \
  635. (x) == AV_PIX_FMT_YA8 || \
  636. (x) == AV_PIX_FMT_GRAY16BE || \
  637. (x) == AV_PIX_FMT_GRAY16LE || \
  638. (x) == AV_PIX_FMT_YA16BE || \
  639. (x) == AV_PIX_FMT_YA16LE)
  640. #endif
  641. #define isRGBinInt(x) \
  642. ( \
  643. (x) == AV_PIX_FMT_RGB48BE || \
  644. (x) == AV_PIX_FMT_RGB48LE || \
  645. (x) == AV_PIX_FMT_RGB32 || \
  646. (x) == AV_PIX_FMT_RGB32_1 || \
  647. (x) == AV_PIX_FMT_RGB24 || \
  648. (x) == AV_PIX_FMT_RGB565BE || \
  649. (x) == AV_PIX_FMT_RGB565LE || \
  650. (x) == AV_PIX_FMT_RGB555BE || \
  651. (x) == AV_PIX_FMT_RGB555LE || \
  652. (x) == AV_PIX_FMT_RGB444BE || \
  653. (x) == AV_PIX_FMT_RGB444LE || \
  654. (x) == AV_PIX_FMT_RGB8 || \
  655. (x) == AV_PIX_FMT_RGB4 || \
  656. (x) == AV_PIX_FMT_RGB4_BYTE || \
  657. (x) == AV_PIX_FMT_RGBA64BE || \
  658. (x) == AV_PIX_FMT_RGBA64LE || \
  659. (x) == AV_PIX_FMT_MONOBLACK || \
  660. (x) == AV_PIX_FMT_MONOWHITE \
  661. )
  662. #define isBGRinInt(x) \
  663. ( \
  664. (x) == AV_PIX_FMT_BGR48BE || \
  665. (x) == AV_PIX_FMT_BGR48LE || \
  666. (x) == AV_PIX_FMT_BGR32 || \
  667. (x) == AV_PIX_FMT_BGR32_1 || \
  668. (x) == AV_PIX_FMT_BGR24 || \
  669. (x) == AV_PIX_FMT_BGR565BE || \
  670. (x) == AV_PIX_FMT_BGR565LE || \
  671. (x) == AV_PIX_FMT_BGR555BE || \
  672. (x) == AV_PIX_FMT_BGR555LE || \
  673. (x) == AV_PIX_FMT_BGR444BE || \
  674. (x) == AV_PIX_FMT_BGR444LE || \
  675. (x) == AV_PIX_FMT_BGR8 || \
  676. (x) == AV_PIX_FMT_BGR4 || \
  677. (x) == AV_PIX_FMT_BGR4_BYTE || \
  678. (x) == AV_PIX_FMT_BGRA64BE || \
  679. (x) == AV_PIX_FMT_BGRA64LE || \
  680. (x) == AV_PIX_FMT_MONOBLACK || \
  681. (x) == AV_PIX_FMT_MONOWHITE \
  682. )
  683. #define isRGBinBytes(x) ( \
  684. (x) == AV_PIX_FMT_RGB48BE \
  685. || (x) == AV_PIX_FMT_RGB48LE \
  686. || (x) == AV_PIX_FMT_RGBA64BE \
  687. || (x) == AV_PIX_FMT_RGBA64LE \
  688. || (x) == AV_PIX_FMT_RGBA \
  689. || (x) == AV_PIX_FMT_ARGB \
  690. || (x) == AV_PIX_FMT_RGB24 \
  691. )
  692. #define isBGRinBytes(x) ( \
  693. (x) == AV_PIX_FMT_BGR48BE \
  694. || (x) == AV_PIX_FMT_BGR48LE \
  695. || (x) == AV_PIX_FMT_BGRA64BE \
  696. || (x) == AV_PIX_FMT_BGRA64LE \
  697. || (x) == AV_PIX_FMT_BGRA \
  698. || (x) == AV_PIX_FMT_ABGR \
  699. || (x) == AV_PIX_FMT_BGR24 \
  700. )
  701. #define isBayer(x) ( \
  702. (x)==AV_PIX_FMT_BAYER_BGGR8 \
  703. || (x)==AV_PIX_FMT_BAYER_BGGR16LE \
  704. || (x)==AV_PIX_FMT_BAYER_BGGR16BE \
  705. || (x)==AV_PIX_FMT_BAYER_RGGB8 \
  706. || (x)==AV_PIX_FMT_BAYER_RGGB16LE \
  707. || (x)==AV_PIX_FMT_BAYER_RGGB16BE \
  708. || (x)==AV_PIX_FMT_BAYER_GBRG8 \
  709. || (x)==AV_PIX_FMT_BAYER_GBRG16LE \
  710. || (x)==AV_PIX_FMT_BAYER_GBRG16BE \
  711. || (x)==AV_PIX_FMT_BAYER_GRBG8 \
  712. || (x)==AV_PIX_FMT_BAYER_GRBG16LE \
  713. || (x)==AV_PIX_FMT_BAYER_GRBG16BE \
  714. )
  715. #define isAnyRGB(x) \
  716. ( \
  717. isBayer(x) || \
  718. isRGBinInt(x) || \
  719. isBGRinInt(x) || \
  720. isRGB(x) \
  721. )
  722. static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
  723. {
  724. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  725. av_assert0(desc);
  726. if (pix_fmt == AV_PIX_FMT_PAL8)
  727. return 1;
  728. return desc->flags & AV_PIX_FMT_FLAG_ALPHA;
  729. }
  730. #if 1
  731. #define isPacked(x) ( \
  732. (x)==AV_PIX_FMT_PAL8 \
  733. || (x)==AV_PIX_FMT_YUYV422 \
  734. || (x)==AV_PIX_FMT_YVYU422 \
  735. || (x)==AV_PIX_FMT_UYVY422 \
  736. || (x)==AV_PIX_FMT_YA8 \
  737. || (x)==AV_PIX_FMT_YA16LE \
  738. || (x)==AV_PIX_FMT_YA16BE \
  739. || (x)==AV_PIX_FMT_AYUV64LE \
  740. || (x)==AV_PIX_FMT_AYUV64BE \
  741. || isRGBinInt(x) \
  742. || isBGRinInt(x) \
  743. )
  744. #else
  745. static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
  746. {
  747. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  748. av_assert0(desc);
  749. return ((desc->nb_components >= 2 && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) ||
  750. pix_fmt == AV_PIX_FMT_PAL8);
  751. }
  752. #endif
  753. static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
  754. {
  755. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  756. av_assert0(desc);
  757. return (desc->nb_components >= 2 && (desc->flags & AV_PIX_FMT_FLAG_PLANAR));
  758. }
  759. static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
  760. {
  761. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  762. av_assert0(desc);
  763. return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) == AV_PIX_FMT_FLAG_RGB);
  764. }
  765. static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
  766. {
  767. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  768. av_assert0(desc);
  769. return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) ==
  770. (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB));
  771. }
  772. static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
  773. {
  774. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  775. av_assert0(desc);
  776. return (desc->flags & AV_PIX_FMT_FLAG_PAL) || (desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL);
  777. }
  778. extern const uint64_t ff_dither4[2];
  779. extern const uint64_t ff_dither8[2];
  780. extern const uint8_t ff_dither_2x2_4[3][8];
  781. extern const uint8_t ff_dither_2x2_8[3][8];
  782. extern const uint8_t ff_dither_4x4_16[5][8];
  783. extern const uint8_t ff_dither_8x8_32[9][8];
  784. extern const uint8_t ff_dither_8x8_73[9][8];
  785. extern const uint8_t ff_dither_8x8_128[9][8];
  786. extern const uint8_t ff_dither_8x8_220[9][8];
  787. extern const int32_t ff_yuv2rgb_coeffs[11][4];
  788. extern const AVClass ff_sws_context_class;
  789. /**
  790. * Set c->swscale to an unscaled converter if one exists for the specific
  791. * source and destination formats, bit depths, flags, etc.
  792. */
  793. void ff_get_unscaled_swscale(SwsContext *c);
  794. void ff_get_unscaled_swscale_ppc(SwsContext *c);
  795. void ff_get_unscaled_swscale_arm(SwsContext *c);
  796. void ff_get_unscaled_swscale_aarch64(SwsContext *c);
  797. /**
  798. * Return function pointer to fastest main scaler path function depending
  799. * on architecture and available optimizations.
  800. */
  801. SwsFunc ff_getSwsFunc(SwsContext *c);
  802. void ff_sws_init_input_funcs(SwsContext *c);
  803. void ff_sws_init_output_funcs(SwsContext *c,
  804. yuv2planar1_fn *yuv2plane1,
  805. yuv2planarX_fn *yuv2planeX,
  806. yuv2interleavedX_fn *yuv2nv12cX,
  807. yuv2packed1_fn *yuv2packed1,
  808. yuv2packed2_fn *yuv2packed2,
  809. yuv2packedX_fn *yuv2packedX,
  810. yuv2anyX_fn *yuv2anyX);
  811. void ff_sws_init_swscale_ppc(SwsContext *c);
  812. void ff_sws_init_swscale_x86(SwsContext *c);
  813. void ff_sws_init_swscale_aarch64(SwsContext *c);
  814. void ff_sws_init_swscale_arm(SwsContext *c);
  815. void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
  816. const uint8_t *src, int srcW, int xInc);
  817. void ff_hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
  818. int dstWidth, const uint8_t *src1,
  819. const uint8_t *src2, int srcW, int xInc);
  820. int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode,
  821. int16_t *filter, int32_t *filterPos,
  822. int numSplits);
  823. void ff_hyscale_fast_mmxext(SwsContext *c, int16_t *dst,
  824. int dstWidth, const uint8_t *src,
  825. int srcW, int xInc);
  826. void ff_hcscale_fast_mmxext(SwsContext *c, int16_t *dst1, int16_t *dst2,
  827. int dstWidth, const uint8_t *src1,
  828. const uint8_t *src2, int srcW, int xInc);
  829. /**
  830. * Allocate and return an SwsContext.
  831. * This is like sws_getContext() but does not perform the init step, allowing
  832. * the user to set additional AVOptions.
  833. *
  834. * @see sws_getContext()
  835. */
  836. struct SwsContext *sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
  837. int dstW, int dstH, enum AVPixelFormat dstFormat,
  838. int flags, const double *param);
  839. int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
  840. int srcStride[], int srcSliceY, int srcSliceH,
  841. uint8_t *dst[], int dstStride[]);
  842. static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y,
  843. int alpha, int bits, const int big_endian)
  844. {
  845. int i, j;
  846. uint8_t *ptr = plane + stride * y;
  847. int v = alpha ? 0xFFFF>>(16-bits) : (1<<(bits-1));
  848. for (i = 0; i < height; i++) {
  849. #define FILL(wfunc) \
  850. for (j = 0; j < width; j++) {\
  851. wfunc(ptr+2*j, v);\
  852. }
  853. if (big_endian) {
  854. FILL(AV_WB16);
  855. } else {
  856. FILL(AV_WL16);
  857. }
  858. ptr += stride;
  859. }
  860. }
  861. #define MAX_SLICE_PLANES 4
  862. /// Slice plane
  863. typedef struct SwsPlane
  864. {
  865. int available_lines; ///< max number of lines that can be hold by this plane
  866. int sliceY; ///< index of first line
  867. int sliceH; ///< number of lines
  868. uint8_t **line; ///< line buffer
  869. uint8_t **tmp; ///< Tmp line buffer used by mmx code
  870. } SwsPlane;
  871. /**
  872. * Struct which defines a slice of an image to be scaled or an output for
  873. * a scaled slice.
  874. * A slice can also be used as intermediate ring buffer for scaling steps.
  875. */
  876. typedef struct SwsSlice
  877. {
  878. int width; ///< Slice line width
  879. int h_chr_sub_sample; ///< horizontal chroma subsampling factor
  880. int v_chr_sub_sample; ///< vertical chroma subsampling factor
  881. int is_ring; ///< flag to identify if this slice is a ring buffer
  882. int should_free_lines; ///< flag to identify if there are dynamic allocated lines
  883. enum AVPixelFormat fmt; ///< planes pixel format
  884. SwsPlane plane[MAX_SLICE_PLANES]; ///< color planes
  885. } SwsSlice;
  886. /**
  887. * Struct which holds all necessary data for processing a slice.
  888. * A processing step can be a color conversion or horizontal/vertical scaling.
  889. */
  890. typedef struct SwsFilterDescriptor
  891. {
  892. SwsSlice *src; ///< Source slice
  893. SwsSlice *dst; ///< Output slice
  894. int alpha; ///< Flag for processing alpha channel
  895. void *instance; ///< Filter instance data
  896. /// Function for processing input slice sliceH lines starting from line sliceY
  897. int (*process)(SwsContext *c, struct SwsFilterDescriptor *desc, int sliceY, int sliceH);
  898. } SwsFilterDescriptor;
  899. // warp input lines in the form (src + width*i + j) to slice format (line[i][j])
  900. // relative=true means first line src[x][0] otherwise first line is src[x][lum/crh Y]
  901. 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);
  902. // Initialize scaler filter descriptor chain
  903. int ff_init_filters(SwsContext *c);
  904. // Free all filter data
  905. int ff_free_filters(SwsContext *c);
  906. /*
  907. function for applying ring buffer logic into slice s
  908. It checks if the slice can hold more @lum lines, if yes
  909. do nothing otherwise remove @lum least used lines.
  910. It applies the same procedure for @chr lines.
  911. */
  912. int ff_rotate_slice(SwsSlice *s, int lum, int chr);
  913. /// initializes gamma conversion descriptor
  914. int ff_init_gamma_convert(SwsFilterDescriptor *desc, SwsSlice * src, uint16_t *table);
  915. /// initializes lum pixel format conversion descriptor
  916. int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
  917. /// initializes lum horizontal scaling descriptor
  918. int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
  919. /// initializes chr pixel format conversion descriptor
  920. int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
  921. /// initializes chr horizontal scaling descriptor
  922. int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
  923. int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst);
  924. /// initializes vertical scaling descriptors
  925. int ff_init_vscale(SwsContext *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst);
  926. /// setup vertical scaler functions
  927. void ff_init_vscale_pfn(SwsContext *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX,
  928. yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2,
  929. yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx);
  930. //number of extra lines to process
  931. #define MAX_LINES_AHEAD 4
  932. #endif /* SWSCALE_SWSCALE_INTERNAL_H */