Merge branch 'new-env-test'
[dcpomatic.git] / src / lib / image.h
index ea35fa0b9aee6dfc1f482e069ba71b4dd223c850..b2b9872792a3815de37a86507203419279edb1ff 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <string>
 #include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavfilter/avfilter.h>
@@ -48,7 +49,7 @@ class SimpleImage;
 class Image
 {
 public:
-       Image (PixelFormat p)
+       Image (AVPixelFormat p)
                : _pixel_format (p)
        {}
        
@@ -57,9 +58,12 @@ public:
        /** @return Array of pointers to arrays of the component data */
        virtual uint8_t ** data () const = 0;
 
-       /** @return Array of sizes of each line, in pixels */
+       /** @return Array of sizes of the data in each line, in bytes (without any alignment padding bytes) */
        virtual int * line_size () const = 0;
 
+       /** @return Array of strides for each line (including any alignment padding bytes) */
+       virtual int * stride () const = 0;
+
        /** @return Size of the image, in pixels */
        virtual Size size () const = 0;
 
@@ -71,13 +75,16 @@ public:
        void alpha_blend (boost::shared_ptr<Image> image, Position pos);
        
        void make_black ();
+
+       void read_from_socket (boost::shared_ptr<Socket>);
+       void write_to_socket (boost::shared_ptr<Socket>) const;
        
-       PixelFormat pixel_format () const {
+       AVPixelFormat pixel_format () const {
                return _pixel_format;
        }
 
 private:
-       PixelFormat _pixel_format; ///< FFmpeg's way of describing the pixel format of this Image
+       AVPixelFormat _pixel_format; ///< FFmpeg's way of describing the pixel format of this Image
 };
 
 /** @class FilterBufferImage
@@ -86,11 +93,12 @@ private:
 class FilterBufferImage : public Image
 {
 public:
-       FilterBufferImage (PixelFormat, AVFilterBufferRef *);
+       FilterBufferImage (AVPixelFormat, AVFilterBufferRef *);
        ~FilterBufferImage ();
 
        uint8_t ** data () const;
        int * line_size () const;
+       int * stride () const;
        Size size () const;
 
 private:
@@ -103,17 +111,33 @@ private:
 class SimpleImage : public Image
 {
 public:
-       SimpleImage (PixelFormat, Size);
+       SimpleImage (AVPixelFormat, Size, boost::function<int (int)> rounder);
        ~SimpleImage ();
 
        uint8_t ** data () const;
        int * line_size () const;
+       int * stride () const;
        Size size () const;
        
 private:
+       
        Size _size; ///< size in pixels
        uint8_t** _data; ///< array of pointers to components
-       int* _line_size; ///< array of widths of each line, in bytes
+       int* _line_size; ///< array of sizes of the data in each line, in pixels (without any alignment padding bytes)
+       int* _stride; ///< array of strides for each line (including any alignment padding bytes)
+};
+
+class AlignedImage : public SimpleImage
+{
+public:
+       AlignedImage (AVPixelFormat, Size);
+};
+
+class CompactImage : public SimpleImage
+{
+public:
+       CompactImage (AVPixelFormat, Size);
+       CompactImage (boost::shared_ptr<Image>);
 };
 
 /** @class RGBFrameImage
@@ -127,6 +151,7 @@ public:
 
        uint8_t ** data () const;
        int * line_size () const;
+       int * stride () const;
        Size size () const;
        AVFrame * frame () const {
                return _frame;