libvisual  0.5.0
lv_video.h
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 <descender@phreaker.net>
9  * Jean-Christophe Hoelt <jeko@ios-software.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as
13  * published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */
25 
26 #ifndef _LV_VIDEO_H
27 #define _LV_VIDEO_H
28 
29 #include <libvisual/lvconfig.h>
30 #include <libvisual/lv_defines.h>
31 #include <libvisual/lv_palette.h>
32 #include <libvisual/lv_rectangle.h>
33 #include <libvisual/lv_buffer.h>
34 #include <libvisual/lv_gl.h>
35 
41 /* NOTE: The depth find helper code in lv_actor depends on an arrangment from low to high */
45 typedef enum {
59 
63 typedef enum {
69 
73 typedef enum {
78 
82 typedef enum {
86 
90 typedef enum {
98 
99 typedef struct _VisVideoAttrOptions VisVideoAttrOptions;
100 
101 #ifdef __cplusplus
102 namespace LV {
103  class Video;
104 }
105 typedef LV::Video VisVideo;
106 #else
107 typedef struct _VisVideo VisVideo;
108 struct _VisVideo;
109 #endif
110 
112 typedef void (*VisVideoComposeFunc)(VisVideo *dest, VisVideo *src);
113 
115  VisVideoDepth depth;
116  VisGLAttrEntry gl_attrs[VISUAL_GL_ATTRIBUTE_LAST];
117 };
118 
119 #ifdef __cplusplus
120 
121 #include <libvisual/lv_intrusive_ptr.hpp>
122 #include <iosfwd>
123 #include <memory>
124 
125 namespace LV {
126 
127  class Video;
128 
129  typedef IntrusivePtr<Video> VideoPtr;
130  typedef IntrusivePtr<Video const> VideoConstPtr;
131 
133  class LV_API Video
134  {
135  public:
136 
137  Video (Video const&) = delete;
138 
139  Video& operator= (Video const&) = delete;
140 
144  static VideoPtr create ();
145 
153  static VideoPtr create (int width, int height, VisVideoDepth depth);
154 
155  static VideoPtr wrap (void* buffer, bool owner, int width, int height, VisVideoDepth depth, int pitch = 0);
156 
157  static VideoPtr create_sub (VideoConstPtr const& src, Rect const& srect);
158 
159  static VideoPtr create_sub (Rect const& drect, VideoConstPtr const& src, Rect const& srect);
160 
168  static VideoPtr create_from_file (std::string const& path);
169 
177  static VideoPtr create_from_stream (std::istream& input);
178 
180  ~Video ();
181 
187  int get_width () const;
188 
194  int get_height () const;
195 
201  void set_depth (VisVideoDepth depth);
202 
208  VisVideoDepth get_depth () const;
209 
217  void set_pitch (int pitch);
218 
224  int get_pitch () const;
225 
231  int get_bpp () const;
232 
240  bool allocate_buffer ();
241 
245  void free_buffer ();
246 
252  bool has_allocated_buffer () const;
253 
259  BufferPtr get_buffer () const;
260 
269  void set_attrs (int width, int height, int pitch, VisVideoDepth depth);
270 
276  void copy_attrs (VideoConstPtr const& src);
277 
285  bool compare_attrs (VideoConstPtr const& src) const;
286 
294  bool compare_attrs_ignore_pitch (VideoConstPtr const& src) const;
295 
301  std::size_t get_size () const;
302 
308  void set_palette (Palette const& palette);
309 
315  void set_palette (Palette&& palette);
316 
322  Palette const& get_palette () const;
323 
329  Palette& get_palette ();
330 
338  void* get_pixels () const;
339 
347  void* get_pixel_ptr (int x, int y) const;
348 
354  Rect const& get_extents () const;
355 
356  void set_extents(Rect area);
357 
358  void set_compose_type (VisVideoComposeType type);
359  void set_compose_colorkey (Color const& color);
360  void set_compose_surface (uint8_t alpha);
361  void set_compose_function (VisVideoComposeFunc func);
362 
363  VisVideoComposeFunc get_compose_function (VideoConstPtr const& src, bool alpha);
364 
373  void blit (VideoConstPtr const& src, int x, int y, bool alpha);
374 
383  void blit (Rect const& drect, VideoConstPtr const& src, Rect const& srect, bool alpha);
384 
385  void compose (VideoConstPtr const& src, int x, int y, VisVideoComposeFunc func);
386  void compose (Rect const& drect, VideoConstPtr const& src, Rect const& srect, VisVideoComposeFunc func);
387 
388  void blit_scale (Rect const& drect, VideoConstPtr const& src, Rect const& srect, bool alpha, VisVideoScaleMethod scale_method);
389  void compose_scale (Rect const& drect, VideoConstPtr const& src, Rect const& srect, VisVideoScaleMethod scale_method, VisVideoComposeFunc func);
390 
398  void fill_alpha (uint8_t alpha);
399 
400  void fill_alpha (uint8_t alpha, Rect const& area);
401 
407  void fill_color (Color const& color);
408 
409  void fill_color (Color const& color, Rect const& area);
410 
416  void flip_pixel_bytes (VideoConstPtr const& src);
417 
418  void rotate (VideoConstPtr const& src, VisVideoRotateDegrees degrees);
419  void mirror (VideoConstPtr const& src, VisVideoMirrorOrient orient);
420 
426  void convert_depth (VideoConstPtr const& src);
427 
434  void scale (VideoConstPtr const& src, VisVideoScaleMethod method);
435 
444  void scale_depth (VideoConstPtr const& src, VisVideoScaleMethod method);
445 
446  static VideoPtr create_scale_depth (VideoConstPtr const& src,
447  int width,
448  int height,
449  VisVideoDepth depth,
450  VisVideoScaleMethod scale_method);
451 
452  private:
453 
454  friend class VideoConvert;
455  friend class VideoTransform;
456  friend class VideoFill;
457  friend class VideoBlit;
458 
459  friend void intrusive_ptr_add_ref (Video const* video);
460  friend void intrusive_ptr_release (Video const* video);
461 
462  class Impl;
463  const std::unique_ptr<Impl> m_impl;
464 
465  mutable unsigned int m_ref_count;
466 
467  Video ();
468 
469  void set_dimension (int width, int height, int pitch = 0);
470  };
471 
472  inline void intrusive_ptr_add_ref (Video const* video)
473  {
474  video->m_ref_count++;
475  }
476 
477  inline void intrusive_ptr_release (Video const* video)
478  {
479  if (--video->m_ref_count == 0) {
480  delete video;
481  }
482  }
483 
484 } // LV namespace
485 
486 #endif
487 
488 LV_BEGIN_DECLS
489 
490 LV_API VisVideo *visual_video_new (void);
491 LV_API VisVideo *visual_video_new_with_buffer (int width, int height, VisVideoDepth depth);
492 LV_API VisVideo *visual_video_new_wrap_buffer (void *buffer, int owner, int width, int height, VisVideoDepth depth, int pitch);
493 LV_API VisVideo *visual_video_load_from_file (const char *path);
494 
495 LV_API void visual_video_ref (VisVideo *video);
496 LV_API void visual_video_unref (VisVideo *video);
497 
498 LV_API int visual_video_allocate_buffer (VisVideo *video);
499 LV_API void visual_video_free_buffer (VisVideo *video);
500 LV_API int visual_video_has_allocated_buffer (VisVideo *video);
501 
502 LV_API void visual_video_copy_attrs (VisVideo *dest, VisVideo *src);
503 
504 LV_API int visual_video_compare_attrs (VisVideo *src1, VisVideo *src2);
505 LV_API int visual_video_compare_attrs_ignore_pitch (VisVideo *src1, VisVideo *src2);
506 
507 LV_API void visual_video_set_palette (VisVideo *video, VisPalette *pal);
508 LV_API VisPalette* visual_video_get_palette (VisVideo *video);
509 
510 LV_API void visual_video_set_attrs (VisVideo *video, int width, int height, int pitch, VisVideoDepth depth);
511 
512 LV_API int visual_video_get_width (VisVideo *video);
513 LV_API int visual_video_get_height (VisVideo *video);
514 
515 LV_API void visual_video_set_pitch (VisVideo *video, int pitch);
516 LV_API int visual_video_get_pitch (VisVideo *video);
517 
518 LV_API void visual_video_set_depth (VisVideo *video, VisVideoDepth depth);
519 LV_API VisVideoDepth visual_video_get_depth (VisVideo *video);
520 
521 LV_API int visual_video_get_bpp (VisVideo *video);
522 
523 LV_API visual_size_t visual_video_get_size (VisVideo *video);
524 
525 LV_API void *visual_video_get_pixels (VisVideo *video);
526 LV_API void *visual_video_get_pixel_ptr (VisVideo *video, int x, int y);
527 
528 LV_API VisBuffer *visual_video_get_buffer (VisVideo *video);
529 
530 LV_API VisRectangle *visual_video_get_extents (VisVideo *video);
531 
532 LV_API VisVideo *visual_video_new_sub (VisVideo *src, VisRectangle *area);
533 LV_API VisVideo *visual_video_new_sub_by_values (VisVideo *src, int x, int y, int width, int height);
534 LV_API VisVideo *visual_video_new_sub_with_boundary (VisRectangle *drect, VisVideo *src, VisRectangle *srect);
535 LV_API VisVideo *visual_video_new_sub_all (VisVideo *src);
536 
537 LV_API void visual_video_set_compose_type (VisVideo *video, VisVideoComposeType type);
538 LV_API void visual_video_set_compose_colorkey (VisVideo *video, VisColor *color);
539 LV_API void visual_video_set_compose_surface (VisVideo *video, uint8_t alpha);
540 LV_API void visual_video_set_compose_function (VisVideo *video, VisVideoComposeFunc compfunc);
541 
542 LV_API VisVideoComposeFunc visual_video_get_compose_function (VisVideo *dest, VisVideo *src, int alpha);
543 
544 LV_API void visual_video_blit_area (VisVideo *dest, VisRectangle *drect, VisVideo *src, VisRectangle *srect, int alpha);
545 LV_API void visual_video_compose_area (VisVideo *dest, VisRectangle *drect, VisVideo *src, VisRectangle *srect, VisVideoComposeFunc func);
546 LV_API void visual_video_blit_scale_area (VisVideo *dest, VisRectangle *drect, VisVideo *src, VisRectangle *srect, int alpha, VisVideoScaleMethod scale_method);
547 LV_API void visual_video_compose_scale_area (VisVideo *dest, VisRectangle *drect, VisVideo *src, VisRectangle *srect, VisVideoScaleMethod scale_method, VisVideoComposeFunc compfunc);
548 
549 LV_API void visual_video_blit (VisVideo *dest, VisVideo *src, int x, int y, int alpha);
550 LV_API void visual_video_compose (VisVideo *dest, VisVideo *src, int x, int y, VisVideoComposeFunc compfunc);
551 
552 LV_API void visual_video_fill_alpha (VisVideo *video, uint8_t density);
553 LV_API void visual_video_fill_alpha_area (VisVideo *video, uint8_t density, VisRectangle *rect);
554 LV_API void visual_video_fill_color (VisVideo *video, VisColor *color);
555 LV_API void visual_video_fill_color_area (VisVideo *video, VisColor *color, VisRectangle *rect);
556 
557 LV_API void visual_video_convert_depth (VisVideo *dest, VisVideo *src);
558 LV_API void visual_video_flip_pixel_bytes (VisVideo *dest, VisVideo *src);
559 
560 LV_API void visual_video_rotate (VisVideo *dest, VisVideo *src, VisVideoRotateDegrees degrees);
561 LV_API void visual_video_mirror (VisVideo *dest, VisVideo *src, VisVideoMirrorOrient orient);
562 LV_API void visual_video_scale (VisVideo *dest, VisVideo *src, VisVideoScaleMethod scale_method);
563 
564 LV_API void visual_video_scale_depth (VisVideo *dest, VisVideo *src, VisVideoScaleMethod scale_method);
565 
566 LV_API VisVideo *visual_video_scale_depth_new (VisVideo* src,
567  int width,
568  int height,
569  VisVideoDepth depth,
570  VisVideoScaleMethod scale_method);
571 
572 LV_API const char *visual_video_depth_name (VisVideoDepth depth);
573 
582 LV_API int visual_video_depth_is_supported (int depthflag, VisVideoDepth depth);
583 
594 LV_API VisVideoDepth visual_video_depth_get_prev (int depthflag, VisVideoDepth depth);
595 
606 LV_API VisVideoDepth visual_video_depth_get_next (int depthflag, VisVideoDepth depth);
607 
615 LV_API VisVideoDepth visual_video_depth_get_lowest (int depthflag);
616 
624 LV_API VisVideoDepth visual_video_depth_get_highest (int depthflag);
625 
634 
642 LV_API int visual_video_depth_is_sane (VisVideoDepth depth);
643 
651 LV_API int visual_video_depth_bpp (VisVideoDepth depth);
652 
662 
663 LV_END_DECLS
664 
669 #endif /* _LV_VIDEO_H */