2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * @brief A set of classes to describe video images.
24 #ifndef DVDOMATIC_IMAGE_H
25 #define DVDOMATIC_IMAGE_H
28 #include <boost/shared_ptr.hpp>
29 #include <boost/function.hpp>
31 #include <libavcodec/avcodec.h>
32 #include <libavfilter/avfilter.h>
41 * @brief Parent class for wrappers of some image, in some format, that
42 * can present a set of components and a size in pixels.
44 * This class also has some conversion / processing methods.
46 * The main point of this class (and its subclasses) is to abstract
47 * details of FFmpeg's memory management and varying data formats.
52 Image (AVPixelFormat p)
58 /** @return Array of pointers to arrays of the component data */
59 virtual uint8_t ** data () const = 0;
61 /** @return Array of sizes of the data in each line, in bytes (without any alignment padding bytes) */
62 virtual int * line_size () const = 0;
64 /** @return Array of strides for each line (including any alignment padding bytes) */
65 virtual int * stride () const = 0;
67 /** @return Size of the image, in pixels */
68 virtual Size size () const = 0;
70 int components () const;
71 int lines (int) const;
72 boost::shared_ptr<Image> scale_and_convert_to_rgb (Size, int, Scaler const *) const;
73 boost::shared_ptr<Image> scale (Size, Scaler const *) const;
74 boost::shared_ptr<Image> post_process (std::string) const;
75 void alpha_blend (boost::shared_ptr<Image> image, Position pos);
79 void read_from_socket (boost::shared_ptr<Socket>);
80 void write_to_socket (boost::shared_ptr<Socket>) const;
82 AVPixelFormat pixel_format () const {
87 AVPixelFormat _pixel_format; ///< FFmpeg's way of describing the pixel format of this Image
90 /** @class FilterBufferImage
91 * @brief An Image that is held in an AVFilterBufferRef.
93 class FilterBufferImage : public Image
96 FilterBufferImage (AVPixelFormat, AVFilterBufferRef *);
97 ~FilterBufferImage ();
99 uint8_t ** data () const;
100 int * line_size () const;
101 int * stride () const;
105 AVFilterBufferRef* _buffer;
108 /** @class SimpleImage
109 * @brief An Image for which memory is allocated using a `simple' av_malloc().
111 class SimpleImage : public Image
114 SimpleImage (AVPixelFormat, Size, boost::function<int (int, int const *)> rounder);
117 uint8_t ** data () const;
118 int * line_size () const;
119 int * stride () const;
124 Size _size; ///< size in pixels
125 uint8_t** _data; ///< array of pointers to components
126 int* _line_size; ///< array of sizes of the data in each line, in pixels (without any alignment padding bytes)
127 int* _stride; ///< array of strides for each line (including any alignment padding bytes)
130 class AlignedImage : public SimpleImage
133 AlignedImage (AVPixelFormat, Size);
134 AlignedImage (boost::shared_ptr<Image>);
137 class CompactImage : public SimpleImage
140 CompactImage (AVPixelFormat, Size);
141 CompactImage (boost::shared_ptr<Image>);