swscale_internal.h 44 KB

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