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