File: videooptions.c

package info (click to toggle)
gavl 1.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 14,912 kB
  • sloc: ansic: 437,319; sh: 10,487; makefile: 238
file content (306 lines) | stat: -rw-r--r-- 8,557 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*****************************************************************
 * gavl - a general purpose audio/video processing library
 *
 * Copyright (c) 2001 - 2011 Members of the Gmerlin project
 * gmerlin-general@lists.sourceforge.net
 * http://gmerlin.sourceforge.net
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * *****************************************************************/

#include <stdlib.h> /* calloc, free */
#include <string.h> /* calloc, free */

#ifdef DEBUG
#include <stdio.h>  
#endif

#include <gavl.h>
#include <config.h>
#include <video.h>
#include <accel.h>

/***************************************************
 * Default Options
 ***************************************************/

static void run_func_default(void (*func)(void*, int, int),
                             void * gavl_data,
                             int start, int len,
                             void * client_data, int thread)
  {
  func(gavl_data, start, len);
  }

static void stop_func_default(void * client_data, int thread)
  {
  }

void gavl_video_options_set_defaults(gavl_video_options_t * opt)
  {
  memset(opt, 0, sizeof(*opt));
  opt->accel_flags = gavl_accel_supported();
  opt->scale_order = 4;
  opt->quality = GAVL_QUALITY_DEFAULT;
  opt->downscale_blur = 1.0;
  opt->downscale_filter = GAVL_DOWNSCALE_FILTER_WIDE;

  opt->num_threads = 1;
  opt->run_func = run_func_default;
  opt->stop_func = stop_func_default;
  
  gavl_init_memcpy();
  }

int gavl_video_options_get_num_threads(gavl_video_options_t * opt)
  {
  return opt->num_threads;
  }

void gavl_video_options_set_num_threads(gavl_video_options_t * opt, int n)
  {
  opt->num_threads = n;
  }

void gavl_video_options_set_run_func(gavl_video_options_t * opt,
                                     void (*run)(void (*func)(void*, int start, int num),
                                                 void * gavl_data,
                                                 int start, int num,
                                                 void * client_data, int thread), 
                                     void * client_data)
  {
  opt->run_func = run;
  opt->run_data = client_data;
  }

gavl_video_run_func gavl_video_options_get_run_func(gavl_video_options_t * opt,
                                                    void ** client_data)
  {
  *client_data = opt->run_data;
  return opt->run_func;
  }


void gavl_video_options_set_stop_func(gavl_video_options_t * opt,
                                      void (*stop)(void * client_data, int thread), 
                                      void * client_data)
  {
  opt->stop_func = stop;
  opt->stop_data = client_data;
  }

gavl_video_stop_func gavl_video_options_get_stop_func(gavl_video_options_t * opt,
                                                      void ** client_data)
  {
  *client_data = opt->stop_data;
  return opt->stop_func;
  }

void gavl_video_options_set_rectangles(gavl_video_options_t * opt,
                                       const gavl_rectangle_f_t * src_rect,
                                       const gavl_rectangle_i_t * dst_rect)
  {
  if(!src_rect || !dst_rect)
    {
    opt->have_rectangles = 0;
    return;
    }
  gavl_rectangle_f_copy(&opt->src_rect, src_rect);
  gavl_rectangle_i_copy(&opt->dst_rect, dst_rect);
  opt->have_rectangles = 1;
  }

void gavl_video_options_get_rectangles(gavl_video_options_t * opt,
                                       gavl_rectangle_f_t * src_rect,
                                       gavl_rectangle_i_t * dst_rect)
  {
  gavl_rectangle_f_copy(src_rect, &opt->src_rect);
  gavl_rectangle_i_copy(dst_rect, &opt->dst_rect);
  }

#define SET_INT(p) opt->p = p


void gavl_video_options_set_quality(gavl_video_options_t * opt, int quality)
  {
  SET_INT(quality);
  }

int gavl_video_options_get_quality(gavl_video_options_t * opt)
  {
  return opt->quality;
  }

void gavl_video_options_set_accel_flags(gavl_video_options_t * opt,
                                        int accel_flags)
  {
  SET_INT(accel_flags);
  }

int gavl_video_options_get_accel_flags(gavl_video_options_t * opt)
  {
  return opt->accel_flags;
  }

void gavl_video_options_set_conversion_flags(gavl_video_options_t * opt,
                                             int conversion_flags)
  {
  SET_INT(conversion_flags);
  }

int gavl_video_options_get_conversion_flags(gavl_video_options_t * opt)
  {
  return opt->conversion_flags;
  }

void gavl_video_options_set_alpha_mode(gavl_video_options_t * opt,
                                       gavl_alpha_mode_t alpha_mode)
  {
  SET_INT(alpha_mode);
  }

gavl_alpha_mode_t
gavl_video_options_get_alpha_mode(gavl_video_options_t * opt)
  {
  return opt->alpha_mode;
  }

void gavl_video_options_set_scale_mode(gavl_video_options_t * opt,
                                       gavl_scale_mode_t scale_mode)
  {
  SET_INT(scale_mode);
  }

gavl_scale_mode_t  gavl_video_options_get_scale_mode(gavl_video_options_t * opt)
  {
  return opt->scale_mode;
  }



void gavl_video_options_set_scale_order(gavl_video_options_t * opt,
                                        int scale_order)
  {
  SET_INT(scale_order);
  }

int gavl_video_options_get_scale_order(gavl_video_options_t * opt)
  {
  return opt->scale_order;
  }

void
gavl_video_options_set_deinterlace_mode(gavl_video_options_t * opt,
                                        gavl_deinterlace_mode_t deinterlace_mode)
  {
  SET_INT(deinterlace_mode);
  }

gavl_deinterlace_mode_t
gavl_video_options_get_deinterlace_mode(gavl_video_options_t * opt)
  {
  return opt->deinterlace_mode;
  }



void
gavl_video_options_set_deinterlace_drop_mode(gavl_video_options_t * opt,
                                             gavl_deinterlace_drop_mode_t deinterlace_drop_mode)
  {
  SET_INT(deinterlace_drop_mode);
  }

gavl_deinterlace_drop_mode_t
gavl_video_options_get_deinterlace_drop_mode(gavl_video_options_t * opt)
  {
  return opt->deinterlace_drop_mode;
  }

#undef SET_INT

#define CLIP_FLOAT(a) if(a < 0.0) a = 0.0; if(a>1.0) a = 1.0;

void gavl_video_options_set_background_color(gavl_video_options_t * opt,
                                             const float * color)
  {
  memcpy(opt->background_float, color, 3*sizeof(*color));

  CLIP_FLOAT(opt->background_float[0]);
  CLIP_FLOAT(opt->background_float[1]);
  CLIP_FLOAT(opt->background_float[2]);
  opt->background_16[0] = (uint16_t)(opt->background_float[0] * 65535.0 + 0.5);
  opt->background_16[1] = (uint16_t)(opt->background_float[1] * 65535.0 + 0.5);
  opt->background_16[2] = (uint16_t)(opt->background_float[2] * 65535.0 + 0.5);
  
  }

void gavl_video_options_get_background_color(gavl_video_options_t * opt,
                                             float * color)
  {
  memcpy(color, opt->background_float, 3*sizeof(*color));
  }

void gavl_video_options_set_downscale_filter(gavl_video_options_t * opt,
                                             gavl_downscale_filter_t f)
  {
  opt->downscale_filter = f;
  
  }
  
gavl_downscale_filter_t
gavl_video_options_get_downscale_filter(gavl_video_options_t * opt)
  {
  return opt->downscale_filter;
  }

void gavl_video_options_set_downscale_blur(gavl_video_options_t * opt,
                                           float f)
  {
  opt->downscale_blur = f;
  }
  

/*!  \ingroup video_options
 *   \brief Get blur factor for downscaling
 *   \param opt Video options
 *   \returns Factor
 *
 *  Since 1.1.0
 */
  
float gavl_video_options_get_downscale_blur(gavl_video_options_t * opt)
  {
  return opt->downscale_blur;
  }


gavl_video_options_t * gavl_video_options_create()
  {
  gavl_video_options_t * ret = calloc(1, sizeof(*ret));
  gavl_video_options_set_defaults(ret);
  return ret;
  }

void gavl_video_options_copy(gavl_video_options_t * dst,
                             const gavl_video_options_t * src)
  {
  memcpy(dst, src, sizeof(*dst));
  }

void gavl_video_options_destroy(gavl_video_options_t * opt)
  {
  free(opt);
  }