Hand-apply a2f81da6d9afc5d3b5e647e1e05ca5d4507af42c from master;
[dcpomatic.git] / src / lib / image.cc
index ffe9f3e0b5f656eac2b8f5204a718e387922dd23..2085b54eeeb14a44e611bdd6d77b1cf501db697f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
  *  @brief A class to describe a video image.
  */
 
-#include <iostream>
-extern "C" {
-#include <libswscale/swscale.h>
-#include <libavutil/pixfmt.h>
-#include <libavutil/pixdesc.h>
-}
 #include "image.h"
 #include "exceptions.h"
 #include "scaler.h"
 #include "timer.h"
 #include "rect.h"
+#include "util.h"
 #include "md5_digester.h"
+#include "dcpomatic_socket.h"
+extern "C" {
+#include <libswscale/swscale.h>
+#include <libavutil/pixfmt.h>
+#include <libavutil/pixdesc.h>
+}
+#include <iostream>
 
 #include "i18n.h"
 
@@ -389,9 +391,9 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                        uint8_t* op = other->data()[0] + oy * other->stride()[0];
                        for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
                                float const alpha = float (op[3]) / 255;
-                               tp[0] = op[0] + (tp[0] * (1 - alpha));
-                               tp[1] = op[1] + (tp[1] * (1 - alpha));
-                               tp[2] = op[2] + (tp[2] * (1 - alpha));
+                               tp[0] = op[0] * alpha + tp[0] * (1 - alpha);
+                               tp[1] = op[1] * alpha + tp[1] * (1 - alpha);
+                               tp[2] = op[2] * alpha + tp[2] * (1 - alpha);
                                
                                tp += this_bpp;
                                op += other_bpp;
@@ -408,10 +410,10 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                        uint8_t* op = other->data()[0] + oy * other->stride()[0];
                        for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
                                float const alpha = float (op[3]) / 255;
-                               tp[0] = op[0] + (tp[0] * (1 - alpha));
-                               tp[1] = op[1] + (tp[1] * (1 - alpha));
-                               tp[2] = op[2] + (tp[2] * (1 - alpha));
-                               tp[3] = op[3] + (tp[3] * (1 - alpha));
+                               tp[0] = op[0] * alpha + tp[0] * (1 - alpha);
+                               tp[1] = op[1] * alpha + tp[1] * (1 - alpha);
+                               tp[2] = op[2] * alpha + tp[2] * (1 - alpha);
+                               tp[3] = op[3] * alpha + tp[3] * (1 - alpha);
                                
                                tp += this_bpp;
                                op += other_bpp;
@@ -428,9 +430,9 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
                        for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
                                float const alpha = float (op[3]) / 255;
                                /* Blend high bytes */
-                               tp[1] = op[0] + (tp[1] * (1 - alpha));
-                               tp[3] = op[1] + (tp[3] * (1 - alpha));
-                               tp[5] = op[2] + (tp[5] * (1 - alpha));
+                               tp[1] = op[0] * alpha + tp[1] * (1 - alpha);
+                               tp[3] = op[1] * alpha + tp[3] * (1 - alpha);
+                               tp[5] = op[2] * alpha + tp[5] * (1 - alpha);
                                
                                tp += this_bpp;
                                op += other_bpp;
@@ -523,7 +525,7 @@ Image::bytes_per_pixel (int c) const
  *  @param s Size in pixels.
  */
 Image::Image (AVPixelFormat p, dcp::Size s, bool aligned)
-       : dcp::Image (s)
+       : _size (s)
        , _pixel_format (p)
        , _aligned (aligned)
 {
@@ -565,8 +567,8 @@ Image::allocate ()
 }
 
 Image::Image (Image const & other)
-       : dcp::Image (other)
-       ,  _pixel_format (other._pixel_format)
+       : _size (other._size)
+       , _pixel_format (other._pixel_format)
        , _aligned (other._aligned)
 {
        allocate ();
@@ -583,7 +585,7 @@ Image::Image (Image const & other)
 }
 
 Image::Image (AVFrame* frame)
-       : dcp::Image (dcp::Size (frame->width, frame->height))
+       : _size (frame->width, frame->height)
        , _pixel_format (static_cast<AVPixelFormat> (frame->format))
        , _aligned (true)
 {
@@ -602,7 +604,7 @@ Image::Image (AVFrame* frame)
 }
 
 Image::Image (shared_ptr<const Image> other, bool aligned)
-       : dcp::Image (other)
+       : _size (other->_size)
        , _pixel_format (other->_pixel_format)
        , _aligned (aligned)
 {
@@ -635,8 +637,7 @@ Image::operator= (Image const & other)
 void
 Image::swap (Image & other)
 {
-       dcp::Image::swap (other);
-       
+       std::swap (_size, other._size);
        std::swap (_pixel_format, other._pixel_format);
 
        for (int i = 0; i < 4; ++i) {