csputils: add MP_CHROMA_TOPLEFT

This is commonly used by UHD/HDR sources, and mpv hilariously ignores it
up until now, just blindly mapping it to MP_CHROMA_AUTO without even so
much as a warning message.

It would be justified to add all the other chroma locations as well, but
I'm lazy and just wanted to quickly fix this bug.
This commit is contained in:
Niklas Haas 2020-12-02 01:34:42 +01:00
parent f16c6472a1
commit a74b6619f2
3 changed files with 8 additions and 1 deletions

View File

@ -103,6 +103,7 @@ const struct m_opt_choice_alternatives mp_csp_light_names[] = {
const struct m_opt_choice_alternatives mp_chroma_names[] = {
{"unknown", MP_CHROMA_AUTO},
{"uhd", MP_CHROMA_TOPLEFT},
{"mpeg2/4/h264",MP_CHROMA_LEFT},
{"mpeg1/jpeg", MP_CHROMA_CENTER},
{0}
@ -288,6 +289,7 @@ enum mp_csp_prim mp_csp_guess_primaries(int width, int height)
enum mp_chroma_location avchroma_location_to_mp(int avloc)
{
switch (avloc) {
case AVCHROMA_LOC_TOPLEFT: return MP_CHROMA_TOPLEFT;
case AVCHROMA_LOC_LEFT: return MP_CHROMA_LEFT;
case AVCHROMA_LOC_CENTER: return MP_CHROMA_CENTER;
default: return MP_CHROMA_AUTO;
@ -297,6 +299,7 @@ enum mp_chroma_location avchroma_location_to_mp(int avloc)
int mp_chroma_location_to_av(enum mp_chroma_location mploc)
{
switch (mploc) {
case MP_CHROMA_TOPLEFT: return AVCHROMA_LOC_TOPLEFT;
case MP_CHROMA_LEFT: return AVCHROMA_LOC_LEFT;
case MP_CHROMA_CENTER: return AVCHROMA_LOC_CENTER;
default: return AVCHROMA_LOC_UNSPECIFIED;
@ -309,8 +312,10 @@ void mp_get_chroma_location(enum mp_chroma_location loc, int *x, int *y)
{
*x = 0;
*y = 0;
if (loc == MP_CHROMA_LEFT)
if (loc == MP_CHROMA_LEFT || loc == MP_CHROMA_TOPLEFT)
*x = -1;
if (loc == MP_CHROMA_TOPLEFT)
*y = -1;
}
void mp_invert_matrix3x3(float m[3][3])

View File

@ -186,6 +186,7 @@ bool mp_colorspace_equal(struct mp_colorspace c1, struct mp_colorspace c2);
enum mp_chroma_location {
MP_CHROMA_AUTO,
MP_CHROMA_TOPLEFT, // uhd
MP_CHROMA_LEFT, // mpeg2/4, h264
MP_CHROMA_CENTER, // mpeg1, jpeg
MP_CHROMA_COUNT,

View File

@ -123,6 +123,7 @@ static void mp_zimg_update_from_cmdline(struct mp_zimg_context *ctx)
static zimg_chroma_location_e mp_to_z_chroma(enum mp_chroma_location cl)
{
switch (cl) {
case MP_CHROMA_TOPLEFT: return ZIMG_CHROMA_TOP_LEFT;
case MP_CHROMA_LEFT: return ZIMG_CHROMA_LEFT;
case MP_CHROMA_CENTER: return ZIMG_CHROMA_CENTER;
default: return ZIMG_CHROMA_LEFT;