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>
30 #include <libavcodec/avcodec.h>
31 #include <libavfilter/avfilter.h>
40 * @brief Parent class for wrappers of some image, in some format, that
41 * can present a set of components and a size in pixels.
43 * This class also has some conversion / processing methods.
45 * The main point of this class (and its subclasses) is to abstract
46 * details of FFmpeg's memory management and varying data formats.
57 /** @return Array of pointers to arrays of the component data */
58 virtual uint8_t ** data () const = 0;
60 /** @return Array of sizes of each line, in pixels */
61 virtual int * line_size () const = 0;
63 /** @return Size of the image, in pixels */
64 virtual Size size () const = 0;
66 int components () const;
67 int lines (int) const;
68 boost::shared_ptr<RGBFrameImage> scale_and_convert_to_rgb (Size, int, Scaler const *) const;
69 boost::shared_ptr<Image> scale (Size, Scaler const *) const;
70 boost::shared_ptr<SimpleImage> post_process (std::string) const;
74 PixelFormat pixel_format () const {
79 PixelFormat _pixel_format; ///< FFmpeg's way of describing the pixel format of this Image
82 /** @class FilterBufferImage
83 * @brief An Image that is held in an AVFilterBufferRef.
85 class FilterBufferImage : public Image
88 FilterBufferImage (PixelFormat, AVFilterBufferRef *);
89 ~FilterBufferImage ();
91 uint8_t ** data () const;
92 int * line_size () const;
96 AVFilterBufferRef* _buffer;
99 /** @class SimpleImage
100 * @brief An Image for which memory is allocated using a `simple' av_malloc().
102 class SimpleImage : public Image
105 SimpleImage (PixelFormat, Size);
108 uint8_t ** data () const;
109 int * line_size () const;
113 Size _size; ///< size in pixels
114 uint8_t** _data; ///< array of pointers to components
115 int* _line_size; ///< array of widths of each line, in bytes
118 /** @class RGBFrameImage
119 * @brief An RGB image that is held within an AVFrame.
121 class RGBFrameImage : public Image
124 RGBFrameImage (Size);
127 uint8_t ** data () const;
128 int * line_size () const;
130 AVFrame * frame () const {