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 
21 module ffmpeg.libswscale.swscale;
22 
23 extern (C):
24 import ffmpeg; @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 (
154     SwsContext* sws_context,
155     SwsFilter* srcFilter,
156     SwsFilter* dstFilter);
157 
158 /**
159  * Free the swscaler context swsContext.
160  * If swsContext is NULL, then does nothing.
161  */
162 void sws_freeContext (SwsContext* swsContext);
163 
164 /**
165  * Allocate and return an SwsContext. You need it to perform
166  * scaling/conversion operations using sws_scale().
167  *
168  * @param srcW the width of the source image
169  * @param srcH the height of the source image
170  * @param srcFormat the source image format
171  * @param dstW the width of the destination image
172  * @param dstH the height of the destination image
173  * @param dstFormat the destination image format
174  * @param flags specify which algorithm and options to use for rescaling
175  * @param param extra parameters to tune the used scaler
176  *              For SWS_BICUBIC param[0] and [1] tune the shape of the basis
177  *              function, param[0] tunes f(1) and param[1] f´(1)
178  *              For SWS_GAUSS param[0] tunes the exponent and thus cutoff
179  *              frequency
180  *              For SWS_LANCZOS param[0] tunes the width of the window function
181  * @return a pointer to an allocated context, or NULL in case of error
182  * @note this function is to be removed after a saner alternative is
183  *       written
184  */
185 SwsContext* sws_getContext (
186     int srcW,
187     int srcH,
188     AVPixelFormat srcFormat,
189     int dstW,
190     int dstH,
191     AVPixelFormat dstFormat,
192     int flags,
193     SwsFilter* srcFilter,
194     SwsFilter* dstFilter,
195     const(double)* param);
196 
197 /**
198  * Scale the image slice in srcSlice and put the resulting scaled
199  * slice in the image in dst. A slice is a sequence of consecutive
200  * rows in an image.
201  *
202  * Slices have to be provided in sequential order, either in
203  * top-bottom or bottom-top order. If slices are provided in
204  * non-sequential order the behavior of the function is undefined.
205  *
206  * @param c         the scaling context previously created with
207  *                  sws_getContext()
208  * @param srcSlice  the array containing the pointers to the planes of
209  *                  the source slice
210  * @param srcStride the array containing the strides for each plane of
211  *                  the source image
212  * @param srcSliceY the position in the source image of the slice to
213  *                  process, that is the number (counted starting from
214  *                  zero) in the image of the first row of the slice
215  * @param srcSliceH the height of the source slice, that is the number
216  *                  of rows in the slice
217  * @param dst       the array containing the pointers to the planes of
218  *                  the destination image
219  * @param dstStride the array containing the strides for each plane of
220  *                  the destination image
221  * @return          the height of the output slice
222  */
223 int sws_scale (
224     SwsContext* c,
225     const(ubyte*)* srcSlice,
226     const(int)* srcStride,
227     int srcSliceY,
228     int srcSliceH,
229     const(ubyte*)* dst,
230     const(int)* dstStride);
231 
232 /**
233  * @param dstRange flag indicating the while-black range of the output (1=jpeg / 0=mpeg)
234  * @param srcRange flag indicating the while-black range of the input (1=jpeg / 0=mpeg)
235  * @param table the yuv2rgb coefficients describing the output yuv space, normally ff_yuv2rgb_coeffs[x]
236  * @param inv_table the yuv2rgb coefficients describing the input yuv space, normally ff_yuv2rgb_coeffs[x]
237  * @param brightness 16.16 fixed point brightness correction
238  * @param contrast 16.16 fixed point contrast correction
239  * @param saturation 16.16 fixed point saturation correction
240  * @return -1 if not supported
241  */
242 int sws_setColorspaceDetails (
243     SwsContext* c,
244     ref const(int)[4] inv_table,
245     int srcRange,
246     ref const(int)[4] table,
247     int dstRange,
248     int brightness,
249     int contrast,
250     int saturation);
251 
252 /**
253  * @return -1 if not supported
254  */
255 int sws_getColorspaceDetails (
256     SwsContext* c,
257     int** inv_table,
258     int* srcRange,
259     int** table,
260     int* dstRange,
261     int* brightness,
262     int* contrast,
263     int* saturation);
264 
265 /**
266  * Allocate and return an uninitialized vector with length coefficients.
267  */
268 SwsVector* sws_allocVec (int length);
269 
270 /**
271  * Return a normalized Gaussian curve used to filter stuff
272  * quality = 3 is high quality, lower is lower quality.
273  */
274 SwsVector* sws_getGaussianVec (double variance, double quality);
275 
276 /**
277  * Scale all the coefficients of a by the scalar value.
278  */
279 void sws_scaleVec (SwsVector* a, double scalar);
280 
281 /**
282  * Scale all the coefficients of a so that their sum equals height.
283  */
284 void sws_normalizeVec (SwsVector* a, double height);
285 
286 SwsVector* sws_getConstVec (double c, int length);
287 SwsVector* sws_getIdentityVec ();
288 void sws_convVec (SwsVector* a, SwsVector* b);
289 void sws_addVec (SwsVector* a, SwsVector* b);
290 void sws_subVec (SwsVector* a, SwsVector* b);
291 void sws_shiftVec (SwsVector* a, int shift);
292 SwsVector* sws_cloneVec (SwsVector* a);
293 void sws_printVec2 (SwsVector* a, AVClass* log_ctx, int log_level);
294 
295 void sws_freeVec (SwsVector* a);
296 
297 SwsFilter* sws_getDefaultFilter (
298     float lumaGBlur,
299     float chromaGBlur,
300     float lumaSharpen,
301     float chromaSharpen,
302     float chromaHShift,
303     float chromaVShift,
304     int verbose);
305 void sws_freeFilter (SwsFilter* filter);
306 
307 /**
308  * Check if context can be reused, otherwise reallocate a new one.
309  *
310  * If context is NULL, just calls sws_getContext() to get a new
311  * context. Otherwise, checks if the parameters are the ones already
312  * saved in context. If that is the case, returns the current
313  * context. Otherwise, frees context and gets a new context with
314  * the new parameters.
315  *
316  * Be warned that srcFilter and dstFilter are not checked, they
317  * are assumed to remain the same.
318  */
319 SwsContext* sws_getCachedContext (
320     SwsContext* context,
321     int srcW,
322     int srcH,
323     AVPixelFormat srcFormat,
324     int dstW,
325     int dstH,
326     AVPixelFormat dstFormat,
327     int flags,
328     SwsFilter* srcFilter,
329     SwsFilter* dstFilter,
330     const(double)* param);
331 
332 /**
333  * Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
334  *
335  * The output frame will have the same packed format as the palette.
336  *
337  * @param src        source frame buffer
338  * @param dst        destination frame buffer
339  * @param num_pixels number of pixels to convert
340  * @param palette    array with [256] entries, which must match color arrangement (RGB or BGR) of src
341  */
342 void sws_convertPalette8ToPacked32 (const(ubyte)* src, ubyte* dst, int num_pixels, const(ubyte)* palette);
343 
344 /**
345  * Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.
346  *
347  * With the palette format "ABCD", the destination frame ends up with the format "ABC".
348  *
349  * @param src        source frame buffer
350  * @param dst        destination frame buffer
351  * @param num_pixels number of pixels to convert
352  * @param palette    array with [256] entries, which must match color arrangement (RGB or BGR) of src
353  */
354 void sws_convertPalette8ToPacked24 (const(ubyte)* src, ubyte* dst, int num_pixels, const(ubyte)* palette);
355 
356 /**
357  * Get the AVClass for swsContext. It can be used in combination with
358  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
359  *
360  * @see av_opt_find().
361  */
362 const(AVClass)* sws_get_class ();
363 
364 /**
365  * @}
366  */
367 
368 /* SWSCALE_SWSCALE_H */