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