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.

347 lines
11KB

  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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_H
  21. #define SWSCALE_SWSCALE_H
  22. /**
  23. * @file
  24. * @brief
  25. * external api for the swscale stuff
  26. */
  27. #include <stdint.h>
  28. #include "libavutil/avutil.h"
  29. #include "libavutil/log.h"
  30. #include "libavutil/pixfmt.h"
  31. #include "version.h"
  32. /**
  33. * Return the LIBSWSCALE_VERSION_INT constant.
  34. */
  35. unsigned swscale_version(void);
  36. /**
  37. * Return the libswscale build-time configuration.
  38. */
  39. const char *swscale_configuration(void);
  40. /**
  41. * Return the libswscale license.
  42. */
  43. const char *swscale_license(void);
  44. /* values for the flags, the stuff on the command line is different */
  45. #define SWS_FAST_BILINEAR 1
  46. #define SWS_BILINEAR 2
  47. #define SWS_BICUBIC 4
  48. #define SWS_X 8
  49. #define SWS_POINT 0x10
  50. #define SWS_AREA 0x20
  51. #define SWS_BICUBLIN 0x40
  52. #define SWS_GAUSS 0x80
  53. #define SWS_SINC 0x100
  54. #define SWS_LANCZOS 0x200
  55. #define SWS_SPLINE 0x400
  56. #define SWS_SRC_V_CHR_DROP_MASK 0x30000
  57. #define SWS_SRC_V_CHR_DROP_SHIFT 16
  58. #define SWS_PARAM_DEFAULT 123456
  59. #define SWS_PRINT_INFO 0x1000
  60. //the following 3 flags are not completely implemented
  61. //internal chrominace subsampling info
  62. #define SWS_FULL_CHR_H_INT 0x2000
  63. //input subsampling info
  64. #define SWS_FULL_CHR_H_INP 0x4000
  65. #define SWS_DIRECT_BGR 0x8000
  66. #define SWS_ACCURATE_RND 0x40000
  67. #define SWS_BITEXACT 0x80000
  68. #if FF_API_SWS_CPU_CAPS
  69. /**
  70. * CPU caps are autodetected now, those flags
  71. * are only provided for API compatibility.
  72. */
  73. #define SWS_CPU_CAPS_MMX 0x80000000
  74. #define SWS_CPU_CAPS_MMXEXT 0x20000000
  75. #define SWS_CPU_CAPS_MMX2 0x20000000
  76. #define SWS_CPU_CAPS_3DNOW 0x40000000
  77. #define SWS_CPU_CAPS_ALTIVEC 0x10000000
  78. #define SWS_CPU_CAPS_BFIN 0x01000000
  79. #define SWS_CPU_CAPS_SSE2 0x02000000
  80. #endif
  81. #define SWS_MAX_REDUCE_CUTOFF 0.002
  82. #define SWS_CS_ITU709 1
  83. #define SWS_CS_FCC 4
  84. #define SWS_CS_ITU601 5
  85. #define SWS_CS_ITU624 5
  86. #define SWS_CS_SMPTE170M 5
  87. #define SWS_CS_SMPTE240M 7
  88. #define SWS_CS_DEFAULT 5
  89. /**
  90. * Return a pointer to yuv<->rgb coefficients for the given colorspace
  91. * suitable for sws_setColorspaceDetails().
  92. *
  93. * @param colorspace One of the SWS_CS_* macros. If invalid,
  94. * SWS_CS_DEFAULT is used.
  95. */
  96. const int *sws_getCoefficients(int colorspace);
  97. // when used for filters they must have an odd number of elements
  98. // coeffs cannot be shared between vectors
  99. typedef struct SwsVector {
  100. double *coeff; ///< pointer to the list of coefficients
  101. int length; ///< number of coefficients in the vector
  102. } SwsVector;
  103. // vectors can be shared
  104. typedef struct SwsFilter {
  105. SwsVector *lumH;
  106. SwsVector *lumV;
  107. SwsVector *chrH;
  108. SwsVector *chrV;
  109. } SwsFilter;
  110. struct SwsContext;
  111. /**
  112. * Return a positive value if pix_fmt is a supported input format, 0
  113. * otherwise.
  114. */
  115. int sws_isSupportedInput(enum AVPixelFormat pix_fmt);
  116. /**
  117. * Return a positive value if pix_fmt is a supported output format, 0
  118. * otherwise.
  119. */
  120. int sws_isSupportedOutput(enum AVPixelFormat pix_fmt);
  121. /**
  122. * @param[in] pix_fmt the pixel format
  123. * @return a positive value if an endianness conversion for pix_fmt is
  124. * supported, 0 otherwise.
  125. */
  126. int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt);
  127. /**
  128. * Allocate an empty SwsContext. This must be filled and passed to
  129. * sws_init_context(). For filling see AVOptions, options.c and
  130. * sws_setColorspaceDetails().
  131. */
  132. struct SwsContext *sws_alloc_context(void);
  133. /**
  134. * Initialize the swscaler context sws_context.
  135. *
  136. * @return zero or positive value on success, a negative value on
  137. * error
  138. */
  139. int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter);
  140. /**
  141. * Free the swscaler context swsContext.
  142. * If swsContext is NULL, then does nothing.
  143. */
  144. void sws_freeContext(struct SwsContext *swsContext);
  145. #if FF_API_SWS_GETCONTEXT
  146. /**
  147. * Allocate and return an SwsContext. You need it to perform
  148. * scaling/conversion operations using sws_scale().
  149. *
  150. * @param srcW the width of the source image
  151. * @param srcH the height of the source image
  152. * @param srcFormat the source image format
  153. * @param dstW the width of the destination image
  154. * @param dstH the height of the destination image
  155. * @param dstFormat the destination image format
  156. * @param flags specify which algorithm and options to use for rescaling
  157. * @return a pointer to an allocated context, or NULL in case of error
  158. * @note this function is to be removed after a saner alternative is
  159. * written
  160. * @deprecated Use sws_getCachedContext() instead.
  161. */
  162. struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,
  163. int dstW, int dstH, enum AVPixelFormat dstFormat,
  164. int flags, SwsFilter *srcFilter,
  165. SwsFilter *dstFilter, const double *param);
  166. #endif
  167. /**
  168. * Scale the image slice in srcSlice and put the resulting scaled
  169. * slice in the image in dst. A slice is a sequence of consecutive
  170. * rows in an image.
  171. *
  172. * Slices have to be provided in sequential order, either in
  173. * top-bottom or bottom-top order. If slices are provided in
  174. * non-sequential order the behavior of the function is undefined.
  175. *
  176. * @param c the scaling context previously created with
  177. * sws_getContext()
  178. * @param srcSlice the array containing the pointers to the planes of
  179. * the source slice
  180. * @param srcStride the array containing the strides for each plane of
  181. * the source image
  182. * @param srcSliceY the position in the source image of the slice to
  183. * process, that is the number (counted starting from
  184. * zero) in the image of the first row of the slice
  185. * @param srcSliceH the height of the source slice, that is the number
  186. * of rows in the slice
  187. * @param dst the array containing the pointers to the planes of
  188. * the destination image
  189. * @param dstStride the array containing the strides for each plane of
  190. * the destination image
  191. * @return the height of the output slice
  192. */
  193. int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],
  194. const int srcStride[], int srcSliceY, int srcSliceH,
  195. uint8_t *const dst[], const int dstStride[]);
  196. /**
  197. * @param inv_table the yuv2rgb coefficients, normally ff_yuv2rgb_coeffs[x]
  198. * @return -1 if not supported
  199. */
  200. int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
  201. int srcRange, const int table[4], int dstRange,
  202. int brightness, int contrast, int saturation);
  203. /**
  204. * @return -1 if not supported
  205. */
  206. int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
  207. int *srcRange, int **table, int *dstRange,
  208. int *brightness, int *contrast, int *saturation);
  209. /**
  210. * Allocate and return an uninitialized vector with length coefficients.
  211. */
  212. SwsVector *sws_allocVec(int length);
  213. /**
  214. * Return a normalized Gaussian curve used to filter stuff
  215. * quality = 3 is high quality, lower is lower quality.
  216. */
  217. SwsVector *sws_getGaussianVec(double variance, double quality);
  218. /**
  219. * Allocate and return a vector with length coefficients, all
  220. * with the same value c.
  221. */
  222. SwsVector *sws_getConstVec(double c, int length);
  223. /**
  224. * Allocate and return a vector with just one coefficient, with
  225. * value 1.0.
  226. */
  227. SwsVector *sws_getIdentityVec(void);
  228. /**
  229. * Scale all the coefficients of a by the scalar value.
  230. */
  231. void sws_scaleVec(SwsVector *a, double scalar);
  232. /**
  233. * Scale all the coefficients of a so that their sum equals height.
  234. */
  235. void sws_normalizeVec(SwsVector *a, double height);
  236. void sws_convVec(SwsVector *a, SwsVector *b);
  237. void sws_addVec(SwsVector *a, SwsVector *b);
  238. void sws_subVec(SwsVector *a, SwsVector *b);
  239. void sws_shiftVec(SwsVector *a, int shift);
  240. /**
  241. * Allocate and return a clone of the vector a, that is a vector
  242. * with the same coefficients as a.
  243. */
  244. SwsVector *sws_cloneVec(SwsVector *a);
  245. /**
  246. * Print with av_log() a textual representation of the vector a
  247. * if log_level <= av_log_level.
  248. */
  249. void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level);
  250. void sws_freeVec(SwsVector *a);
  251. SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
  252. float lumaSharpen, float chromaSharpen,
  253. float chromaHShift, float chromaVShift,
  254. int verbose);
  255. void sws_freeFilter(SwsFilter *filter);
  256. /**
  257. * Check if context can be reused, otherwise reallocate a new one.
  258. *
  259. * If context is NULL, just calls sws_getContext() to get a new
  260. * context. Otherwise, checks if the parameters are the ones already
  261. * saved in context. If that is the case, returns the current
  262. * context. Otherwise, frees context and gets a new context with
  263. * the new parameters.
  264. *
  265. * Be warned that srcFilter and dstFilter are not checked, they
  266. * are assumed to remain the same.
  267. */
  268. struct SwsContext *sws_getCachedContext(struct SwsContext *context,
  269. int srcW, int srcH, enum AVPixelFormat srcFormat,
  270. int dstW, int dstH, enum AVPixelFormat dstFormat,
  271. int flags, SwsFilter *srcFilter,
  272. SwsFilter *dstFilter, const double *param);
  273. /**
  274. * Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
  275. *
  276. * The output frame will have the same packed format as the palette.
  277. *
  278. * @param src source frame buffer
  279. * @param dst destination frame buffer
  280. * @param num_pixels number of pixels to convert
  281. * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
  282. */
  283. void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
  284. /**
  285. * Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.
  286. *
  287. * With the palette format "ABCD", the destination frame ends up with the format "ABC".
  288. *
  289. * @param src source frame buffer
  290. * @param dst destination frame buffer
  291. * @param num_pixels number of pixels to convert
  292. * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
  293. */
  294. void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette);
  295. /**
  296. * Get the AVClass for swsContext. It can be used in combination with
  297. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  298. *
  299. * @see av_opt_find().
  300. */
  301. const AVClass *sws_get_class(void);
  302. #endif /* SWSCALE_SWSCALE_H */