Add configuration option to set writer's maximum frames in memory.
[dcpomatic.git] / src / lib / magick_image_proxy.cc
index 2d1867fcc14a972c2296465178c07f50e7a4321f..fbb08b7b081229372ddb8fd83bc32f6607971e5e 100644 (file)
@@ -67,7 +67,7 @@ MagickImageProxy::MagickImageProxy (shared_ptr<cxml::Node>, shared_ptr<Socket> s
 }
 
 shared_ptr<Image>
-MagickImageProxy::image (optional<dcp::NoteHandler>) const
+MagickImageProxy::image (optional<dcp::NoteHandler>, optional<dcp::Size>) const
 {
        boost::mutex::scoped_lock lm (_mutex);
 
@@ -102,6 +102,18 @@ MagickImageProxy::image (optional<dcp::NoteHandler>) const
                throw DecodeError (String::compose (_("Could not decode image file (%1)"), error));
        }
 
+       unsigned char const * data = static_cast<unsigned char const *>(_blob.data());
+       if (data[801] == 1) {
+               /* The transfer characteristic in this file is "printing density"; in this case ImageMagick sets the colour space
+                  to LogColorspace.  Empirically we find that if we subsequently call colorSpace(Magick::RGBColorspace) the colours
+                  are very wrong.  To prevent this, set the image colour space to RGB to stop the ::colorSpace call below doing
+                  anything.  See #1123 and others.
+               */
+               magick_image->image()->colorspace = Magick::RGBColorspace;
+       }
+
+       magick_image->colorSpace(Magick::RGBColorspace);
+
        dcp::Size size (magick_image->columns(), magick_image->rows());
 
        _image.reset (new Image (AV_PIX_FMT_RGB24, size, true));