summaryrefslogtreecommitdiff
path: root/src/lib/image.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-04-24 12:05:21 +0100
committerCarl Hetherington <cth@carlh.net>2015-04-24 12:05:21 +0100
commit1cdedd1c19bd34f1c41043f9bbeae39cb54a0ed8 (patch)
tree460ee0ad60988d641cf00e458fef6c91e3621370 /src/lib/image.cc
parent666808c7f735d5ff0daff70dfb7b0c409113874e (diff)
parent2d3092216e97c02bf715a3df19725518312a0b65 (diff)
Merge branch '2.0' of git.carlh.net:git/dcpomatic into 2.0
Diffstat (limited to 'src/lib/image.cc')
-rw-r--r--src/lib/image.cc32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 177219813..bba5eeda1 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -87,7 +87,9 @@ Image::components () const
/** Crop this image, scale it to `inter_size' and then place it in a black frame of `out_size' */
shared_ptr<Image>
-Image::crop_scale_window (Crop crop, dcp::Size inter_size, dcp::Size out_size, AVPixelFormat out_format, bool out_aligned) const
+Image::crop_scale_window (
+ Crop crop, dcp::Size inter_size, dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool out_aligned
+ ) const
{
/* Empirical testing suggests that sws_scale() will crash if
the input image is not aligned.
@@ -115,6 +117,19 @@ Image::crop_scale_window (Crop crop, dcp::Size inter_size, dcp::Size out_size, A
throw StringError (N_("Could not allocate SwsContext"));
}
+ DCPOMATIC_ASSERT (yuv_to_rgb < dcp::YUV_TO_RGB_COUNT);
+ int const lut[dcp::YUV_TO_RGB_COUNT] = {
+ SWS_CS_ITU601,
+ SWS_CS_ITU709
+ };
+
+ sws_setColorspaceDetails (
+ scale_context,
+ sws_getCoefficients (lut[yuv_to_rgb]), 0,
+ sws_getCoefficients (lut[yuv_to_rgb]), 0,
+ 0, 1 << 16, 1 << 16
+ );
+
/* Prepare input data pointers with crop */
uint8_t* scale_in_data[components()];
for (int c = 0; c < components(); ++c) {
@@ -142,7 +157,7 @@ Image::crop_scale_window (Crop crop, dcp::Size inter_size, dcp::Size out_size, A
}
shared_ptr<Image>
-Image::scale (dcp::Size out_size, AVPixelFormat out_format, bool out_aligned) const
+Image::scale (dcp::Size out_size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat out_format, bool out_aligned) const
{
/* Empirical testing suggests that sws_scale() will crash if
the input image is not aligned.
@@ -157,6 +172,19 @@ Image::scale (dcp::Size out_size, AVPixelFormat out_format, bool out_aligned) co
SWS_BICUBIC, 0, 0, 0
);
+ DCPOMATIC_ASSERT (yuv_to_rgb < dcp::YUV_TO_RGB_COUNT);
+ int const lut[dcp::YUV_TO_RGB_COUNT] = {
+ SWS_CS_ITU601,
+ SWS_CS_ITU709
+ };
+
+ sws_setColorspaceDetails (
+ scale_context,
+ sws_getCoefficients (lut[yuv_to_rgb]), 0,
+ sws_getCoefficients (lut[yuv_to_rgb]), 0,
+ 0, 1 << 16, 1 << 16
+ );
+
sws_scale (
scale_context,
data(), stride(),