You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

937 lines
41KB

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