libvisual  0.5.0
lv_video_c.cpp
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Dennis Smit <ds@nerds-incorporated.org>
7  * Duilio J. Protti <dprotti@users.sourceforge.net>
8  * Chong Kai Xiong <kaixiong@codeleft.sg>
9  * Jean-Christophe Hoelt <jeko@ios-software.com>
10  * Jaak Randmets <jaak.ra@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License as
14  * published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  */
26 
27 #include <config.h>
28 #include "lv_video.h"
29 #include "lv_common.h"
30 
31 VisVideo *visual_video_new ()
32 {
33  auto self = LV::Video::create ();
34  if (self) {
35  LV::intrusive_ptr_add_ref (self.get ());
36  }
37 
38  return self.get ();
39 }
40 
41 VisVideo *visual_video_new_with_buffer (int width, int height, VisVideoDepth depth)
42 {
43  auto self = LV::Video::create (width, height, depth);
44  if (self) {
45  LV::intrusive_ptr_add_ref (self.get ());
46  }
47 
48  return self.get ();
49 }
50 
51 VisVideo *visual_video_new_wrap_buffer (void *buffer, int owner, int width, int height, VisVideoDepth depth, int pitch)
52 {
53  auto self = LV::Video::wrap (buffer, owner, width, height, depth, pitch);
54  if (self) {
55  LV::intrusive_ptr_add_ref (self.get ());
56  }
57 
58  return self.get ();
59 }
60 
61 VisVideo *visual_video_load_from_file (const char *path)
62 {
63  auto self = LV::Video::create_from_file (path);
64  if (self) {
65  LV::intrusive_ptr_add_ref (self.get ());
66  }
67 
68  return self.get ();
69 }
70 
71 void visual_video_free_buffer (VisVideo *self)
72 {
73  visual_return_if_fail (self != nullptr);
74 
75  self->free_buffer ();
76 }
77 
78 int visual_video_allocate_buffer (VisVideo *self)
79 {
80  visual_return_val_if_fail (self != nullptr, FALSE);
81 
82  return self->allocate_buffer ();
83 }
84 
85 int visual_video_has_allocated_buffer (VisVideo *self)
86 {
87  visual_return_val_if_fail (self != nullptr, FALSE);
88 
89  return self->has_allocated_buffer ();
90 }
91 
92 void visual_video_copy_attrs (VisVideo *self, VisVideo *src)
93 {
94  visual_return_if_fail (self != nullptr);
95  visual_return_if_fail (src != nullptr);
96 
97  self->copy_attrs (LV::VideoPtr (src));
98 }
99 
100 int visual_video_compare_attrs (VisVideo *self, VisVideo *src)
101 {
102  visual_return_val_if_fail (self != nullptr, FALSE);
103  visual_return_val_if_fail (src != nullptr, FALSE);
104 
105  return self->compare_attrs (LV::VideoPtr (src));
106 }
107 
108 int visual_video_compare_attrs_ignore_pitch (VisVideo *self, VisVideo *src)
109 {
110  visual_return_val_if_fail (self != nullptr, FALSE);
111  visual_return_val_if_fail (src != nullptr, FALSE);
112 
113  return self->compare_attrs_ignore_pitch (LV::VideoPtr (src));
114 }
115 
116 void visual_video_set_palette (VisVideo *self, VisPalette *pal)
117 {
118  visual_return_if_fail (self != nullptr);
119 
120  if (pal) {
121  self->set_palette (*pal);
122  } else {
123  self->set_palette (LV::Palette ());
124  }
125 }
126 
127 VisPalette *visual_video_get_palette (VisVideo *self)
128 {
129  visual_return_val_if_fail (self != nullptr, nullptr);
130 
131  auto& palette = self->get_palette ();
132  if (!palette.empty ()) {
133  return &palette;
134  } else {
135  return nullptr;
136  }
137 }
138 
139 int visual_video_get_width (VisVideo *self)
140 {
141  visual_return_val_if_fail (self != nullptr, 0);
142 
143  return self->get_width ();
144 }
145 
146 int visual_video_get_height (VisVideo *self)
147 {
148  visual_return_val_if_fail (self != nullptr, 0);
149 
150  return self->get_height ();
151 }
152 
153 void visual_video_set_pitch (VisVideo *self, int pitch)
154 {
155  visual_return_if_fail (self != nullptr);
156 
157  self->set_pitch (pitch);
158 }
159 
160 int visual_video_get_pitch (VisVideo *self)
161 {
162  visual_return_val_if_fail (self != nullptr, 0);
163 
164  return self->get_pitch ();
165 }
166 
167 void visual_video_set_depth (VisVideo *self, VisVideoDepth depth)
168 {
169  visual_return_if_fail (self != nullptr);
170 
171  self->set_depth (depth);
172 }
173 
174 VisVideoDepth visual_video_get_depth (VisVideo *self)
175 {
176  visual_return_val_if_fail (self != nullptr, VISUAL_VIDEO_DEPTH_NONE);
177 
178  return self->get_depth ();
179 }
180 
181 int visual_video_get_bpp (VisVideo *self)
182 {
183  visual_return_val_if_fail (self != nullptr, 0);
184 
185  return self->get_bpp ();
186 }
187 
188 void visual_video_set_attrs (VisVideo *self, int width, int height, int pitch, VisVideoDepth depth)
189 {
190  visual_return_if_fail (self != nullptr);
191 
192  self->set_attrs (width, height, pitch, depth);
193 }
194 
195 visual_size_t visual_video_get_size (VisVideo *self)
196 {
197  visual_return_val_if_fail (self != nullptr, 0);
198 
199  return self->get_size ();
200 }
201 
202 void *visual_video_get_pixels (VisVideo *self)
203 {
204  visual_return_val_if_fail (self != nullptr, nullptr);
205 
206  return self->get_pixels ();
207 }
208 
209 VisBuffer *visual_video_get_buffer (VisVideo *self)
210 {
211  visual_return_val_if_fail (self != nullptr, nullptr);
212 
213  LV::BufferPtr buffer = self->get_buffer ();
214  if (buffer) {
215  LV::intrusive_ptr_add_ref (buffer.get ());
216  }
217 
218  return buffer.get ();
219 }
220 
221 VisRectangle *visual_video_get_extents (VisVideo *self)
222 {
223  visual_return_val_if_fail (self != nullptr, nullptr);
224 
225  return new LV::Rect (self->get_extents ());
226 }
227 
228 void *visual_video_get_pixel_ptr (VisVideo *self, int x, int y)
229 {
230  visual_return_val_if_fail (self != nullptr, nullptr);
231 
232  return self->get_pixel_ptr (x, y);
233 }
234 
235 VisVideo* visual_video_new_sub (VisVideo *src, VisRectangle *area)
236 {
237  visual_return_val_if_fail (src != nullptr, nullptr);
238  visual_return_val_if_fail (area != nullptr, nullptr);
239 
240  LV::VideoPtr self = LV::Video::create_sub (LV::VideoPtr (src), *area);
241  if (self) {
242  LV::intrusive_ptr_add_ref (self.get ());
243  }
244 
245  return self.get ();
246 }
247 
248 VisVideo* visual_video_new_sub_by_values (VisVideo *src, int x, int y, int width, int height)
249 {
250  visual_return_val_if_fail (src != nullptr, nullptr);
251 
252  LV::VideoPtr self = LV::Video::create_sub (LV::VideoPtr (src), LV::Rect (x, y, width, height));
253  if (self) {
254  LV::intrusive_ptr_add_ref (self.get ());
255  }
256 
257  return self.get ();
258 }
259 
260 VisVideo* visual_video_new_sub_with_boundary (VisRectangle *drect, VisVideo *src, VisRectangle *srect)
261 {
262  visual_return_val_if_fail (src != nullptr, nullptr);
263  visual_return_val_if_fail (drect != nullptr, nullptr);
264  visual_return_val_if_fail (srect != nullptr, nullptr);
265 
266  LV::VideoPtr self = LV::Video::create_sub (*drect, LV::VideoPtr (src), *srect);
267  if (self) {
268  LV::intrusive_ptr_add_ref (self.get ());
269  }
270 
271  return self.get ();
272 }
273 
274 void visual_video_set_compose_type (VisVideo *self, VisVideoComposeType type)
275 {
276  visual_return_if_fail (self != nullptr);
277 
278  self->set_compose_type (type);
279 }
280 
281 void visual_video_set_compose_colorkey (VisVideo *self, VisColor *color)
282 {
283  visual_return_if_fail (self != nullptr);
284  visual_return_if_fail (color != nullptr);
285 
286  self->set_compose_colorkey (*color);
287 }
288 
289 void visual_video_set_compose_surface (VisVideo *self, uint8_t alpha)
290 {
291  visual_return_if_fail (self != nullptr);
292 
293  self->set_compose_surface (alpha);
294 }
295 
296 void visual_video_set_compose_function (VisVideo *self, VisVideoComposeFunc compose_func)
297 {
298  visual_return_if_fail (self != nullptr);
299  visual_return_if_fail (compose_func != nullptr);
300 
301  self->set_compose_function (compose_func);
302 }
303 
304 VisVideoComposeFunc visual_video_get_compose_function (VisVideo *self, VisVideo *src, int alpha)
305 {
306  visual_return_val_if_fail (self != nullptr, nullptr);
307  visual_return_val_if_fail (src != nullptr, nullptr);
308 
309  return self->get_compose_function (src, alpha);
310 }
311 
312 void visual_video_blit_area (VisVideo *self,
313  VisRectangle *drect,
314  VisVideo *src,
315  VisRectangle *srect,
316  int alpha)
317 {
318  visual_return_if_fail (self != nullptr);
319  visual_return_if_fail (drect != nullptr);
320  visual_return_if_fail (src != nullptr);
321  visual_return_if_fail (srect != nullptr);
322 
323  self->blit (*drect, LV::VideoPtr (src), *srect, alpha);
324 }
325 
326 void visual_video_compose_area (VisVideo *self,
327  VisRectangle *drect,
328  VisVideo *src,
329  VisRectangle *srect,
330  VisVideoComposeFunc compose_func)
331 {
332  visual_return_if_fail (self != nullptr);
333  visual_return_if_fail (drect != nullptr);
334  visual_return_if_fail (src != nullptr);
335  visual_return_if_fail (srect != nullptr);
336  visual_return_if_fail (compose_func != nullptr);
337 
338  self->compose (*drect, LV::VideoPtr (src), *srect, compose_func);
339 }
340 
341 void visual_video_blit_scale_area (VisVideo *self,
342  VisRectangle *drect,
343  VisVideo *src,
344  VisRectangle *srect,
345  int alpha,
346  VisVideoScaleMethod scale_method)
347 {
348  visual_return_if_fail (self != nullptr);
349  visual_return_if_fail (drect != nullptr);
350  visual_return_if_fail (src != nullptr);
351  visual_return_if_fail (srect != nullptr);
352 
353  self->blit_scale (*drect, LV::VideoPtr (src), *srect, alpha, scale_method);
354 }
355 
356 void visual_video_compose_scale_area (VisVideo *self,
357  VisRectangle *drect,
358  VisVideo *src,
359  VisRectangle *srect,
360  VisVideoScaleMethod scale_method,
361  VisVideoComposeFunc compose_func)
362 {
363  visual_return_if_fail (self != nullptr);
364  visual_return_if_fail (drect != nullptr);
365  visual_return_if_fail (src != nullptr);
366  visual_return_if_fail (srect != nullptr);
367  visual_return_if_fail (compose_func != nullptr);
368 
369  self->compose_scale (*drect, LV::VideoPtr (src), *srect, scale_method, compose_func);
370 }
371 
372 void visual_video_blit (VisVideo *self, VisVideo *src, int x, int y, int alpha)
373 {
374  visual_return_if_fail (self != nullptr);
375  visual_return_if_fail (src != nullptr);
376 
377  self->blit (LV::VideoPtr (src), x, y, alpha);
378 }
379 
380 void visual_video_compose (VisVideo *self, VisVideo *src, int x, int y, VisVideoComposeFunc compose_func)
381 {
382  visual_return_if_fail (self != nullptr);
383  visual_return_if_fail (src != nullptr);
384  visual_return_if_fail (compose_func != nullptr);
385 
386  self->compose (LV::VideoPtr (src), x, y, compose_func);
387 }
388 
389 void visual_video_fill_alpha (VisVideo *self, uint8_t alpha)
390 {
391  visual_return_if_fail (self != nullptr);
392 
393  self->fill_alpha (alpha);
394 }
395 
396 void visual_video_fill_alpha_area (VisVideo *self, uint8_t alpha, VisRectangle *area)
397 {
398  visual_return_if_fail (self != nullptr);
399  visual_return_if_fail (area != nullptr);
400 
401  self->fill_alpha (alpha, *area);
402 }
403 
404 void visual_video_fill_color (VisVideo *self, VisColor *color)
405 {
406  visual_return_if_fail (self != nullptr);
407 
408  if (color) {
409  self->fill_color (*color);
410  } else {
411  self->fill_color (LV::Color::black ());
412  }
413 }
414 
415 void visual_video_fill_color_area (VisVideo *self, VisColor *color, VisRectangle *area)
416 {
417  visual_return_if_fail (self != nullptr);
418  visual_return_if_fail (color != nullptr);
419  visual_return_if_fail (area != nullptr);
420 
421  self->fill_color (*color, *area);
422 }
423 
424 
425 void visual_video_flip_pixel_bytes (VisVideo *self, VisVideo *src)
426 {
427  visual_return_if_fail (self != nullptr);
428  visual_return_if_fail (src != nullptr);
429 
430  self->flip_pixel_bytes (LV::VideoPtr (src));
431 }
432 
433 void visual_video_rotate (VisVideo *self, VisVideo *src, VisVideoRotateDegrees degrees)
434 {
435  visual_return_if_fail (self != nullptr);
436  visual_return_if_fail (src != nullptr);
437 
438  self->rotate (LV::VideoPtr (src), degrees);
439 }
440 
441 void visual_video_mirror (VisVideo *self, VisVideo *src, VisVideoMirrorOrient orient)
442 {
443  visual_return_if_fail (self != nullptr);
444  visual_return_if_fail (src != nullptr);
445 
446  self->mirror (LV::VideoPtr (src), orient);
447 }
448 
449 void visual_video_convert_depth (VisVideo *self, VisVideo *src)
450 {
451  visual_return_if_fail (self != nullptr);
452  visual_return_if_fail (src != nullptr);
453 
454  self->convert_depth (LV::VideoPtr (src));
455 }
456 
457 void visual_video_scale (VisVideo *self, VisVideo *src, VisVideoScaleMethod method)
458 {
459  visual_return_if_fail (self != nullptr);
460  visual_return_if_fail (src != nullptr);
461 
462  self->scale (LV::VideoPtr (src), method);
463 }
464 
465 void visual_video_scale_depth (VisVideo *self, VisVideo *src, VisVideoScaleMethod scale_method)
466 {
467  visual_return_if_fail (self != nullptr);
468  visual_return_if_fail (src != nullptr);
469 
470  self->scale_depth (LV::VideoPtr (src), scale_method);
471 }
472 
473 VisVideo *visual_video_scale_depth_new (VisVideo* src,
474  int width,
475  int height,
476  VisVideoDepth depth,
477  VisVideoScaleMethod scale_method)
478 {
479  visual_return_val_if_fail (src != nullptr, nullptr);
480 
481  auto self = LV::Video::create_scale_depth (LV::VideoPtr (src), width, height, depth, scale_method);
482  if (self) {
483  LV::intrusive_ptr_add_ref (self.get ());
484  }
485 
486  return self.get ();
487 }
488 
489 void visual_video_ref (VisVideo *self)
490 {
491  visual_return_if_fail (self != nullptr);
492 
493  LV::intrusive_ptr_add_ref (self);
494 }
495 
496 void visual_video_unref (VisVideo *self)
497 {
498  visual_return_if_fail (self != nullptr);
499 
500  LV::intrusive_ptr_release (self);
501 }