X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fimage.cc;h=8e6c5717b9064025a1adb03a619731a13835b347;hb=62f9b78a2eb5f0fc6b9028264bac6ad501d83309;hp=eff53a2aae15635811795408b608cf07a9e6e73d;hpb=71f3520ea315fb65ff151c99aa0b64fc8dccdb1d;p=dcpomatic.git diff --git a/src/lib/image.cc b/src/lib/image.cc index eff53a2aa..8e6c5717b 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -297,6 +297,15 @@ Image::crop_scale_window ( out->make_part_black (corner.x + cropped_size.width, out_size.width - cropped_size.width); } + if ( + video_range == VideoRange::VIDEO && + out_video_range == VideoRange::FULL && + av_pix_fmt_desc_get(_pixel_format)->flags & AV_PIX_FMT_FLAG_RGB + ) { + /* libswscale will not convert video range for RGB sources, so we have to do it ourselves */ + out->video_range_to_full_range (); + } + return out; } @@ -1440,6 +1449,22 @@ Image::video_range_to_full_range () } break; } + case AV_PIX_FMT_RGB48LE: + { + float const factor = 65536.0 / 56064.0; + uint16_t* p = reinterpret_cast(data()[0]); + int const lines = sample_size(0).height; + for (int y = 0; y < lines; ++y) { + uint16_t* q = p; + int const line_size_pixels = line_size()[0] / 2; + for (int x = 0; x < line_size_pixels; ++x) { + *q = clamp(lrintf((*q - 4096) * factor), 0L, 65535L); + ++q; + } + p += stride()[0] / 2; + } + break; + } case AV_PIX_FMT_GBRP12LE: { float const factor = 4096.0 / 3504.0;