aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrcombs <rcombs@rcombs.me>2021-12-23 03:49:27 -0600
committerrcombs <rcombs@rcombs.me>2022-01-04 20:01:10 -0600
commitdf94cdde4bd87f22a1150cf9cfc185a7dfad8136 (patch)
tree6f9d59cfcb67d1aad33cf79f1869d3a7d68a2dcc
parent1292a8d91b62e707c8b183b6ddae0eb8b027c7f6 (diff)
downloadffmpeg-df94cdde4bd87f22a1150cf9cfc185a7dfad8136.tar.gz
swscale: introduce isSwappedChroma
-rw-r--r--libswscale/swscale_internal.h19
-rw-r--r--libswscale/tests/pixdesc_query.c1
-rw-r--r--tests/ref/fate/sws-pixdesc-query5
3 files changed, 25 insertions, 0 deletions
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index b4acaceebd..3a78d95ba6 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -911,6 +911,25 @@ static av_always_inline int isDataInHighBits(enum AVPixelFormat pix_fmt)
return 1;
}
+/*
+ * Identity formats where the chroma planes are swapped (CrCb order).
+ */
+static av_always_inline int isSwappedChroma(enum AVPixelFormat pix_fmt)
+{
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+ av_assert0(desc);
+ if (!isYUV(pix_fmt))
+ return 0;
+ if ((desc->flags & AV_PIX_FMT_FLAG_ALPHA) && desc->nb_components < 4)
+ return 0;
+ if (desc->nb_components < 3)
+ return 0;
+ if (!isPlanarYUV(pix_fmt) || isSemiPlanarYUV(pix_fmt))
+ return desc->comp[1].offset > desc->comp[2].offset;
+ else
+ return desc->comp[1].plane > desc->comp[2].plane;
+}
+
extern const uint64_t ff_dither4[2];
extern const uint64_t ff_dither8[2];
diff --git a/libswscale/tests/pixdesc_query.c b/libswscale/tests/pixdesc_query.c
index dce2e50577..eb793877a0 100644
--- a/libswscale/tests/pixdesc_query.c
+++ b/libswscale/tests/pixdesc_query.c
@@ -46,6 +46,7 @@ static const struct {
{"PlanarRGB", isPlanarRGB},
{"usePal", usePal},
{"DataInHighBits", isDataInHighBits},
+ {"SwappedChroma", isSwappedChroma},
};
static int cmp_str(const void *a, const void *b)
diff --git a/tests/ref/fate/sws-pixdesc-query b/tests/ref/fate/sws-pixdesc-query
index a17284784f..76104bc5a6 100644
--- a/tests/ref/fate/sws-pixdesc-query
+++ b/tests/ref/fate/sws-pixdesc-query
@@ -964,3 +964,8 @@ DataInHighBits:
y210be
y210le
+SwappedChroma:
+ nv21
+ nv42
+ yvyu422
+