swscale_internal.h 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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 dstFormat destination pixel format
  106. * @param chrDither ordered dither array of type uint8_t and size 8
  107. * @param chrFilter vertical chroma scaling coefficients, 12 bits [0,4096]
  108. * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit
  109. * output, 19 bits for 16-bit output (in int32_t)
  110. * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit
  111. * output, 19 bits for 16-bit output (in int32_t)
  112. * @param chrFilterSize number of vertical chroma input lines to scale
  113. * @param dest pointer to the output plane. For >8-bit
  114. * output, this is in uint16_t
  115. * @param dstW width of chroma planes
  116. */
  117. typedef void (*yuv2interleavedX_fn)(enum AVPixelFormat dstFormat,
  118. const uint8_t *chrDither,
  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. float uint2float_lut[256];
  315. /**
  316. * @name Scaled horizontal lines ring buffer.
  317. * The horizontal scaler keeps just enough scaled lines in a ring buffer
  318. * so they may be passed to the vertical scaler. The pointers to the
  319. * allocated buffers for each line are duplicated in sequence in the ring
  320. * buffer to simplify indexing and avoid wrapping around between lines
  321. * inside the vertical scaler code. The wrapping is done before the
  322. * vertical scaler is called.
  323. */
  324. //@{
  325. int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer.
  326. int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer.
  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);
  586. av_cold void ff_sws_init_range_convert(SwsContext *c);
  587. SwsFunc ff_yuv2rgb_init_x86(SwsContext *c);
  588. SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c);
  589. static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
  590. {
  591. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  592. av_assert0(desc);
  593. return desc->comp[0].depth == 16;
  594. }
  595. static av_always_inline int is32BPS(enum AVPixelFormat pix_fmt)
  596. {
  597. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  598. av_assert0(desc);
  599. return desc->comp[0].depth == 32;
  600. }
  601. static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
  602. {
  603. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  604. av_assert0(desc);
  605. return desc->comp[0].depth >= 9 && desc->comp[0].depth <= 14;
  606. }
  607. static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
  608. {
  609. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  610. av_assert0(desc);
  611. return desc->flags & AV_PIX_FMT_FLAG_BE;
  612. }
  613. static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
  614. {
  615. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  616. av_assert0(desc);
  617. return !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
  618. }
  619. static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
  620. {
  621. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  622. av_assert0(desc);
  623. return ((desc->flags & AV_PIX_FMT_FLAG_PLANAR) && isYUV(pix_fmt));
  624. }
  625. /*
  626. * Identity semi-planar YUV formats. Specifically, those are YUV formats
  627. * where the second and third components (U & V) are on the same plane.
  628. */
  629. static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
  630. {
  631. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  632. av_assert0(desc);
  633. return (isPlanarYUV(pix_fmt) && desc->comp[1].plane == desc->comp[2].plane);
  634. }
  635. static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
  636. {
  637. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  638. av_assert0(desc);
  639. return (desc->flags & AV_PIX_FMT_FLAG_RGB);
  640. }
  641. static av_always_inline int isGray(enum AVPixelFormat pix_fmt)
  642. {
  643. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  644. av_assert0(desc);
  645. return !(desc->flags & AV_PIX_FMT_FLAG_PAL) &&
  646. !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
  647. desc->nb_components <= 2 &&
  648. pix_fmt != AV_PIX_FMT_MONOBLACK &&
  649. pix_fmt != AV_PIX_FMT_MONOWHITE;
  650. }
  651. static av_always_inline int isRGBinInt(enum AVPixelFormat pix_fmt)
  652. {
  653. return pix_fmt == AV_PIX_FMT_RGB48BE ||
  654. pix_fmt == AV_PIX_FMT_RGB48LE ||
  655. pix_fmt == AV_PIX_FMT_RGB32 ||
  656. pix_fmt == AV_PIX_FMT_RGB32_1 ||
  657. pix_fmt == AV_PIX_FMT_RGB24 ||
  658. pix_fmt == AV_PIX_FMT_RGB565BE ||
  659. pix_fmt == AV_PIX_FMT_RGB565LE ||
  660. pix_fmt == AV_PIX_FMT_RGB555BE ||
  661. pix_fmt == AV_PIX_FMT_RGB555LE ||
  662. pix_fmt == AV_PIX_FMT_RGB444BE ||
  663. pix_fmt == AV_PIX_FMT_RGB444LE ||
  664. pix_fmt == AV_PIX_FMT_RGB8 ||
  665. pix_fmt == AV_PIX_FMT_RGB4 ||
  666. pix_fmt == AV_PIX_FMT_RGB4_BYTE ||
  667. pix_fmt == AV_PIX_FMT_RGBA64BE ||
  668. pix_fmt == AV_PIX_FMT_RGBA64LE ||
  669. pix_fmt == AV_PIX_FMT_MONOBLACK ||
  670. pix_fmt == AV_PIX_FMT_MONOWHITE;
  671. }
  672. static av_always_inline int isBGRinInt(enum AVPixelFormat pix_fmt)
  673. {
  674. return pix_fmt == AV_PIX_FMT_BGR48BE ||
  675. pix_fmt == AV_PIX_FMT_BGR48LE ||
  676. pix_fmt == AV_PIX_FMT_BGR32 ||
  677. pix_fmt == AV_PIX_FMT_BGR32_1 ||
  678. pix_fmt == AV_PIX_FMT_BGR24 ||
  679. pix_fmt == AV_PIX_FMT_BGR565BE ||
  680. pix_fmt == AV_PIX_FMT_BGR565LE ||
  681. pix_fmt == AV_PIX_FMT_BGR555BE ||
  682. pix_fmt == AV_PIX_FMT_BGR555LE ||
  683. pix_fmt == AV_PIX_FMT_BGR444BE ||
  684. pix_fmt == AV_PIX_FMT_BGR444LE ||
  685. pix_fmt == AV_PIX_FMT_BGR8 ||
  686. pix_fmt == AV_PIX_FMT_BGR4 ||
  687. pix_fmt == AV_PIX_FMT_BGR4_BYTE ||
  688. pix_fmt == AV_PIX_FMT_BGRA64BE ||
  689. pix_fmt == AV_PIX_FMT_BGRA64LE ||
  690. pix_fmt == AV_PIX_FMT_MONOBLACK ||
  691. pix_fmt == AV_PIX_FMT_MONOWHITE;
  692. }
  693. static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
  694. {
  695. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  696. av_assert0(desc);
  697. return !!(desc->flags & AV_PIX_FMT_FLAG_BAYER);
  698. }
  699. static av_always_inline int isBayer16BPS(enum AVPixelFormat pix_fmt)
  700. {
  701. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  702. av_assert0(desc);
  703. return desc->comp[1].depth == 8;
  704. }
  705. static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
  706. {
  707. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  708. av_assert0(desc);
  709. return (desc->flags & AV_PIX_FMT_FLAG_RGB) ||
  710. pix_fmt == AV_PIX_FMT_MONOBLACK || pix_fmt == AV_PIX_FMT_MONOWHITE;
  711. }
  712. static av_always_inline int isFloat(enum AVPixelFormat pix_fmt)
  713. {
  714. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  715. av_assert0(desc);
  716. return desc->flags & AV_PIX_FMT_FLAG_FLOAT;
  717. }
  718. static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
  719. {
  720. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  721. av_assert0(desc);
  722. if (pix_fmt == AV_PIX_FMT_PAL8)
  723. return 1;
  724. return desc->flags & AV_PIX_FMT_FLAG_ALPHA;
  725. }
  726. static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
  727. {
  728. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  729. av_assert0(desc);
  730. return (desc->nb_components >= 2 && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) ||
  731. pix_fmt == AV_PIX_FMT_PAL8 ||
  732. pix_fmt == AV_PIX_FMT_MONOBLACK || pix_fmt == AV_PIX_FMT_MONOWHITE;
  733. }
  734. static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
  735. {
  736. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  737. av_assert0(desc);
  738. return (desc->nb_components >= 2 && (desc->flags & AV_PIX_FMT_FLAG_PLANAR));
  739. }
  740. static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
  741. {
  742. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  743. av_assert0(desc);
  744. return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) == AV_PIX_FMT_FLAG_RGB);
  745. }
  746. static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
  747. {
  748. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
  749. av_assert0(desc);
  750. return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) ==
  751. (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB));
  752. }
  753. static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
  754. {
  755. switch (pix_fmt) {
  756. case AV_PIX_FMT_PAL8:
  757. case AV_PIX_FMT_BGR4_BYTE:
  758. case AV_PIX_FMT_BGR8:
  759. case AV_PIX_FMT_GRAY8:
  760. case AV_PIX_FMT_RGB4_BYTE:
  761. case AV_PIX_FMT_RGB8:
  762. return 1;
  763. default:
  764. return 0;
  765. }
  766. }
  767. extern const uint64_t ff_dither4[2];
  768. extern const uint64_t ff_dither8[2];
  769. extern const uint8_t ff_dither_2x2_4[3][8];
  770. extern const uint8_t ff_dither_2x2_8[3][8];
  771. extern const uint8_t ff_dither_4x4_16[5][8];
  772. extern const uint8_t ff_dither_8x8_32[9][8];
  773. extern const uint8_t ff_dither_8x8_73[9][8];
  774. extern const uint8_t ff_dither_8x8_128[9][8];
  775. extern const uint8_t ff_dither_8x8_220[9][8];
  776. extern const int32_t ff_yuv2rgb_coeffs[11][4];
  777. extern const AVClass ff_sws_context_class;
  778. /**
  779. * Set c->swscale to an unscaled converter if one exists for the specific
  780. * source and destination formats, bit depths, flags, etc.
  781. */
  782. void ff_get_unscaled_swscale(SwsContext *c);
  783. void ff_get_unscaled_swscale_ppc(SwsContext *c);
  784. void ff_get_unscaled_swscale_arm(SwsContext *c);
  785. void ff_get_unscaled_swscale_aarch64(SwsContext *c);
  786. /**
  787. * Return function pointer to fastest main scaler path function depending
  788. * on architecture and available optimizations.
  789. */
  790. SwsFunc ff_getSwsFunc(SwsContext *c);
  791. void ff_sws_init_input_funcs(SwsContext *c);
  792. void ff_sws_init_output_funcs(SwsContext *c,
  793. yuv2planar1_fn *yuv2plane1,
  794. yuv2planarX_fn *yuv2planeX,
  795. yuv2interleavedX_fn *yuv2nv12cX,
  796. yuv2packed1_fn *yuv2packed1,
  797. yuv2packed2_fn *yuv2packed2,
  798. yuv2packedX_fn *yuv2packedX,
  799. yuv2anyX_fn *yuv2anyX);
  800. void ff_sws_init_swscale_ppc(SwsContext *c);
  801. void ff_sws_init_swscale_vsx(SwsContext *c);
  802. void ff_sws_init_swscale_x86(SwsContext *c);
  803. void ff_sws_init_swscale_aarch64(SwsContext *c);
  804. void ff_sws_init_swscale_arm(SwsContext *c);
  805. void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth,
  806. const uint8_t *src, int srcW, int xInc);
  807. void ff_hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2,
  808. int dstWidth, const uint8_t *src1,
  809. const uint8_t *src2, int srcW, int xInc);
  810. int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode,
  811. int16_t *filter, int32_t *filterPos,
  812. int numSplits);
  813. void ff_hyscale_fast_mmxext(SwsContext *c, int16_t *dst,
  814. int dstWidth, const uint8_t *src,
  815. int srcW, int xInc);
  816. void ff_hcscale_fast_mmxext(SwsContext *c, int16_t *dst1, int16_t *dst2,
  817. int dstWidth, const uint8_t *src1,
  818. const uint8_t *src2, int srcW, int xInc);
  819. /**
  820. * Allocate and return an SwsContext.
  821. * This is like sws_getContext() but does not perform the init step, allowing
  822. * the user to set additional AVOptions.
  823. *
  824. * @see sws_getContext()
  825. */
  826. struct SwsContext *sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
  827. int dstW, int dstH, enum AVPixelFormat dstFormat,
  828. int flags, const double *param);
  829. int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
  830. int srcStride[], int srcSliceY, int srcSliceH,
  831. uint8_t *dst[], int dstStride[]);
  832. static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y,
  833. int alpha, int bits, const int big_endian)
  834. {
  835. int i, j;
  836. uint8_t *ptr = plane + stride * y;
  837. int v = alpha ? 0xFFFF>>(16-bits) : (1<<(bits-1));
  838. for (i = 0; i < height; i++) {
  839. #define FILL(wfunc) \
  840. for (j = 0; j < width; j++) {\
  841. wfunc(ptr+2*j, v);\
  842. }
  843. if (big_endian) {
  844. FILL(AV_WB16);
  845. } else {
  846. FILL(AV_WL16);
  847. }
  848. ptr += stride;
  849. }
  850. #undef FILL
  851. }
  852. static inline void fillPlane32(uint8_t *plane, int stride, int width, int height, int y,
  853. int alpha, int bits, const int big_endian, int is_float)
  854. {
  855. int i, j;
  856. uint8_t *ptr = plane + stride * y;
  857. uint32_t v;
  858. uint32_t onef32 = 0x3f800000;
  859. if (is_float)
  860. v = alpha ? onef32 : 0;
  861. else
  862. v = alpha ? 0xFFFFFFFF>>(32-bits) : (1<<(bits-1));
  863. for (i = 0; i < height; i++) {
  864. #define FILL(wfunc) \
  865. for (j = 0; j < width; j++) {\
  866. wfunc(ptr+4*j, v);\
  867. }
  868. if (big_endian) {
  869. FILL(AV_WB32);
  870. } else {
  871. FILL(AV_WL32);
  872. }
  873. ptr += stride;
  874. }
  875. #undef FILL
  876. }
  877. #define MAX_SLICE_PLANES 4
  878. /// Slice plane
  879. typedef struct SwsPlane
  880. {
  881. int available_lines; ///< max number of lines that can be hold by this plane
  882. int sliceY; ///< index of first line
  883. int sliceH; ///< number of lines
  884. uint8_t **line; ///< line buffer
  885. uint8_t **tmp; ///< Tmp line buffer used by mmx code
  886. } SwsPlane;
  887. /**
  888. * Struct which defines a slice of an image to be scaled or an output for
  889. * a scaled slice.
  890. * A slice can also be used as intermediate ring buffer for scaling steps.
  891. */
  892. typedef struct SwsSlice
  893. {
  894. int width; ///< Slice line width
  895. int h_chr_sub_sample; ///< horizontal chroma subsampling factor
  896. int v_chr_sub_sample; ///< vertical chroma subsampling factor
  897. int is_ring; ///< flag to identify if this slice is a ring buffer
  898. int should_free_lines; ///< flag to identify if there are dynamic allocated lines
  899. enum AVPixelFormat fmt; ///< planes pixel format
  900. SwsPlane plane[MAX_SLICE_PLANES]; ///< color planes
  901. } SwsSlice;
  902. /**
  903. * Struct which holds all necessary data for processing a slice.
  904. * A processing step can be a color conversion or horizontal/vertical scaling.
  905. */
  906. typedef struct SwsFilterDescriptor
  907. {
  908. SwsSlice *src; ///< Source slice
  909. SwsSlice *dst; ///< Output slice
  910. int alpha; ///< Flag for processing alpha channel
  911. void *instance; ///< Filter instance data
  912. /// Function for processing input slice sliceH lines starting from line sliceY
  913. int (*process)(SwsContext *c, struct SwsFilterDescriptor *desc, int sliceY, int sliceH);
  914. } SwsFilterDescriptor;
  915. // warp input lines in the form (src + width*i + j) to slice format (line[i][j])
  916. // relative=true means first line src[x][0] otherwise first line is src[x][lum/crh Y]
  917. 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);
  918. // Initialize scaler filter descriptor chain
  919. int ff_init_filters(SwsContext *c);
  920. // Free all filter data
  921. int ff_free_filters(SwsContext *c);
  922. /*
  923. function for applying ring buffer logic into slice s
  924. It checks if the slice can hold more @lum lines, if yes
  925. do nothing otherwise remove @lum least used lines.
  926. It applies the same procedure for @chr lines.
  927. */
  928. int ff_rotate_slice(SwsSlice *s, int lum, int chr);
  929. /// initializes gamma conversion descriptor
  930. int ff_init_gamma_convert(SwsFilterDescriptor *desc, SwsSlice * src, uint16_t *table);
  931. /// initializes lum pixel format conversion descriptor
  932. int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
  933. /// initializes lum horizontal scaling descriptor
  934. int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
  935. /// initializes chr pixel format conversion descriptor
  936. int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal);
  937. /// initializes chr horizontal scaling descriptor
  938. int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc);
  939. int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst);
  940. /// initializes vertical scaling descriptors
  941. int ff_init_vscale(SwsContext *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst);
  942. /// setup vertical scaler functions
  943. void ff_init_vscale_pfn(SwsContext *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX,
  944. yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2,
  945. yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx);
  946. //number of extra lines to process
  947. #define MAX_LINES_AHEAD 4
  948. #endif /* SWSCALE_SWSCALE_INTERNAL_H */