Add a load of explicit keywords.
[dcpomatic.git] / src / lib / image.h
1 /*
2     Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file src/image.h
22  *  @brief A set of classes to describe video images.
23  */
24
25 #ifndef DCPOMATIC_IMAGE_H
26 #define DCPOMATIC_IMAGE_H
27
28 #include "position.h"
29 #include "position_image.h"
30 #include "types.h"
31 extern "C" {
32 #include <libavutil/pixfmt.h>
33 }
34 #include <dcp/colour_conversion.h>
35 #include <boost/shared_ptr.hpp>
36
37 struct AVFrame;
38 class Socket;
39
40 class Image
41 {
42 public:
43         Image (AVPixelFormat p, dcp::Size s, bool aligned, int extra_pixels = 0);
44         explicit Image (AVFrame *);
45         explicit Image (Image const &);
46         Image (boost::shared_ptr<const Image>, bool);
47         Image& operator= (Image const &);
48         ~Image ();
49
50         uint8_t * const * data () const;
51         int const * line_size () const;
52         int const * stride () const;
53         dcp::Size size () const;
54         bool aligned () const;
55
56         int planes () const;
57         int vertical_factor (int) const;
58         int horizontal_factor (int) const;
59         dcp::Size sample_size (int) const;
60         float bytes_per_pixel (int) const;
61
62         boost::shared_ptr<Image> convert_pixel_format (dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool aligned, bool fast) const;
63         boost::shared_ptr<Image> scale (dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool aligned, bool fast) const;
64         boost::shared_ptr<Image> crop_scale_window (
65                 Crop crop, dcp::Size inter_size, dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool aligned, bool fast
66                 ) const;
67
68         void make_black ();
69         void make_transparent ();
70         void alpha_blend (boost::shared_ptr<const Image> image, Position<int> pos);
71         void copy (boost::shared_ptr<const Image> image, Position<int> pos);
72         void fade (float);
73
74         void read_from_socket (boost::shared_ptr<Socket>);
75         void write_to_socket (boost::shared_ptr<Socket>) const;
76
77         AVPixelFormat pixel_format () const {
78                 return _pixel_format;
79         }
80
81         size_t memory_used () const;
82
83         static boost::shared_ptr<Image> ensure_aligned (boost::shared_ptr<Image> image);
84
85 private:
86         friend struct pixel_formats_test;
87
88         void allocate ();
89         void swap (Image &);
90         void yuv_16_black (uint16_t, bool);
91         static uint16_t swap_16 (uint16_t);
92
93         dcp::Size _size;
94         AVPixelFormat _pixel_format; ///< FFmpeg's way of describing the pixel format of this Image
95         uint8_t** _data; ///< array of pointers to components
96         int* _line_size; ///< array of sizes of the data in each line, in bytes (without any alignment padding bytes)
97         int* _stride; ///< array of strides for each line, in bytes (including any alignment padding bytes)
98         bool _aligned;
99         int _extra_pixels;
100 };
101
102 extern PositionImage merge (std::list<PositionImage> images);
103 extern bool operator== (Image const & a, Image const & b);
104
105 #endif