Skip to content

Commit 863abed

Browse files
committed
Don't change colorspace/range on mlt_image_none
This image format is supposed to instruct the producer to provide as native or closest to source as possible. That can be useful by API but also Movit uses this because it tries to handle things as much as possible. This improves the color accuracy of SDR within a BT.2020/HLG project on Movit.
1 parent 73cfdd0 commit 863abed

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/modules/avformat/producer_avformat.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,7 @@ static mlt_colorspace convert_image_yuvp(producer_avformat self,
18221822
int height,
18231823
int src_pix_fmt,
18241824
int dst_pix_fmt,
1825+
int dst_colorspace,
18251826
int dst_full_range)
18261827
{
18271828
mlt_colorspace result = self->yuv_colorspace;
@@ -1834,10 +1835,10 @@ static mlt_colorspace convert_image_yuvp(producer_avformat self,
18341835
mlt_image_format_planes(format, width, height, buffer, out_data, out_stride);
18351836
if (!mlt_set_luma_transfer(context,
18361837
self->yuv_colorspace,
1837-
profile->colorspace,
1838+
dst_colorspace,
18381839
self->full_range,
18391840
dst_full_range))
1840-
result = profile->colorspace;
1841+
result = dst_colorspace;
18411842
sws_scale(context,
18421843
(const uint8_t *const *) frame->data,
18431844
frame->linesize,
@@ -1942,6 +1943,7 @@ static void convert_image(producer_avformat self,
19421943
int width,
19431944
int height,
19441945
uint8_t **alpha,
1946+
int dst_colorspace,
19451947
int dst_full_range)
19461948
{
19471949
mlt_profile profile = mlt_service_profile(MLT_PRODUCER_SERVICE(self->parent));
@@ -1955,7 +1957,7 @@ static void convert_image(producer_avformat self,
19551957
width,
19561958
height,
19571959
self->yuv_colorspace,
1958-
profile->colorspace,
1960+
dst_colorspace,
19591961
self->full_range,
19601962
dst_full_range);
19611963

@@ -2030,6 +2032,7 @@ static void convert_image(producer_avformat self,
20302032
height,
20312033
src_pix_fmt,
20322034
dst_pix_fmt,
2035+
dst_colorspace,
20332036
dst_full_range);
20342037
} else {
20352038
int i, c;
@@ -2039,7 +2042,7 @@ static void convert_image(producer_avformat self,
20392042
.frame = frame,
20402043
.dst_format = AV_PIX_FMT_YUYV422,
20412044
.src_colorspace = self->yuv_colorspace,
2042-
.dst_colorspace = profile->colorspace,
2045+
.dst_colorspace = dst_colorspace,
20432046
.src_full_range = self->full_range,
20442047
.dst_full_range = dst_full_range,
20452048
};
@@ -2093,7 +2096,7 @@ static void convert_image(producer_avformat self,
20932096
sliced_h_pix_fmt_conv_proc(i, i, c, &ctx);
20942097
}
20952098

2096-
colorspace = profile->colorspace;
2099+
colorspace = dst_colorspace;
20972100
}
20982101
mlt_log_timings_end(NULL, __FUNCTION__);
20992102

@@ -2257,8 +2260,11 @@ static int producer_get_image(mlt_frame frame,
22572260
uint8_t *alpha = NULL;
22582261
int got_picture = 0;
22592262
int image_size = 0;
2263+
mlt_profile profile = mlt_service_profile(MLT_PRODUCER_SERVICE(self->parent));
2264+
int dst_colorspace = (*format == mlt_image_none) ? self->yuv_colorspace : profile->colorspace;
22602265
const char *dst_color_range = mlt_properties_get(frame_properties, "consumer.color_range");
2261-
int dst_full_range = mlt_image_full_range(dst_color_range);
2266+
int dst_full_range = (*format == mlt_image_none) ? self->full_range
2267+
: mlt_image_full_range(dst_color_range);
22622268

22632269
// if 10-bit libswscale only changes range when scaling, not simple pix_fmt conversion
22642270
const struct AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(self->video_codec->pix_fmt);
@@ -2383,6 +2389,7 @@ static int producer_get_image(mlt_frame frame,
23832389
*width,
23842390
*height,
23852391
&alpha,
2392+
dst_colorspace,
23862393
dst_full_range);
23872394
got_picture = 1;
23882395
}
@@ -2661,6 +2668,7 @@ static int producer_get_image(mlt_frame frame,
26612668
*width,
26622669
*height,
26632670
&alpha,
2671+
dst_colorspace,
26642672
dst_full_range);
26652673
self->current_position = int_position;
26662674
} else {

0 commit comments

Comments
 (0)