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.

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