Skip to content

Commit 3ae5521

Browse files
committed
mp_image: keep chroma location consistent for non-subsampled formats
Could also be set to unknown, but let's keep it center, so any fallbacks in other places wouldn't trigger. In practice it shouldn't be used for non-subsampled formats.
1 parent 7dd035e commit 3ae5521

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

video/img_format.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,12 @@ int mp_imgfmt_select_best_list(int *dst, int num_dst, int src)
824824
return best;
825825
}
826826

827+
bool mp_imgfmt_is_subsampled(enum mp_imgfmt fmt)
828+
{
829+
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt);
830+
return desc.chroma_xs || desc.chroma_ys;
831+
}
832+
827833
bool mp_imgfmt_is_420_subsampled(enum mp_imgfmt fmt)
828834
{
829835
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(fmt);

video/img_format.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ char **mp_imgfmt_name_list(void);
336336

337337
int mp_imgfmt_select_best(int dst1, int dst2, int src);
338338
int mp_imgfmt_select_best_list(int *dst, int num_dst, int src);
339+
bool mp_imgfmt_is_subsampled(enum mp_imgfmt fmt);
339340
bool mp_imgfmt_is_420_subsampled(enum mp_imgfmt fmt);
340341

341342
#endif /* MPLAYER_IMG_FORMAT_H */

video/mp_image.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,11 +1032,16 @@ void mp_image_params_guess_csp(struct mp_image_params *params)
10321032
params->color.hdr = pl_hdr_metadata_empty;
10331033
}
10341034

1035-
if (params->chroma_location == PL_CHROMA_UNKNOWN) {
1036-
if (params->repr.levels == PL_COLOR_LEVELS_LIMITED)
1037-
params->chroma_location = PL_CHROMA_LEFT;
1038-
if (params->repr.levels == PL_COLOR_LEVELS_FULL)
1039-
params->chroma_location = PL_CHROMA_CENTER;
1035+
if (mp_imgfmt_is_subsampled(params->hw_subfmt ? params->hw_subfmt : params->imgfmt)) {
1036+
if (params->chroma_location == PL_CHROMA_UNKNOWN) {
1037+
if (params->repr.levels == PL_COLOR_LEVELS_LIMITED)
1038+
params->chroma_location = PL_CHROMA_LEFT;
1039+
if (params->repr.levels == PL_COLOR_LEVELS_FULL)
1040+
params->chroma_location = PL_CHROMA_CENTER;
1041+
}
1042+
} else {
1043+
// Set to center for non-subsampled formats.
1044+
params->chroma_location = PL_CHROMA_CENTER;
10401045
}
10411046

10421047
if (params->light == MP_CSP_LIGHT_AUTO) {

0 commit comments

Comments
 (0)