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