[FFmpeg-devel] [PATCH] avutil: Add NV61 pixel format and enable IO support for NV16 and NV61 pixel formats
c.bicheru0 at gmail.com
c.bicheru0 at gmail.com
Fri Jun 19 19:35:42 EEST 2020
From: Cristian Bicheru <c.bicheru0 at gmail.com>
NV16 and NV61 are interleaved 4:2:2 8-bit formats. There was some internal NV16 support prior to this patch but the pixel format was not publicly accessible.
---
libavutil/pixdesc.c | 12 ++++++++
libavutil/pixfmt.h | 1 +
libavutil/version.h | 2 +-
libswscale/input.c | 2 ++
libswscale/output.c | 6 ++--
libswscale/swscale_unscaled.c | 51 ++++++++++++++++++++++++++++++++
libswscale/utils.c | 2 ++
tests/ref/fate/filter-pixdesc-nv16 | 1 +
tests/ref/fate/filter-pixdesc-nv61 | 1 +
tests/ref/fate/filter-pixfmts-copy | 2 ++
tests/ref/fate/filter-pixfmts-crop | 2 ++
tests/ref/fate/filter-pixfmts-field | 2 ++
tests/ref/fate/filter-pixfmts-fieldorder | 2 ++
tests/ref/fate/filter-pixfmts-hflip | 2 ++
tests/ref/fate/filter-pixfmts-il | 2 ++
tests/ref/fate/filter-pixfmts-null | 2 ++
tests/ref/fate/filter-pixfmts-pad | 2 ++
tests/ref/fate/filter-pixfmts-scale | 2 ++
tests/ref/fate/filter-pixfmts-vflip | 2 ++
tests/ref/fate/sws-pixdesc-query | 4 +++
20 files changed, 99 insertions(+), 3 deletions(-)
create mode 100644 tests/ref/fate/filter-pixdesc-nv16
create mode 100644 tests/ref/fate/filter-pixdesc-nv61
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 8274713..642692d 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -2057,6 +2057,18 @@ static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
},
.flags = AV_PIX_FMT_FLAG_PLANAR,
},
+ [AV_PIX_FMT_NV61] = {
+ .name = "nv61",
+ .nb_components = 3,
+ .log2_chroma_w = 1,
+ .log2_chroma_h = 0,
+ .comp = {
+ { 0, 1, 0, 0, 8, 0, 7, 1 }, /* Y */
+ { 1, 2, 1, 0, 8, 1, 7, 2 }, /* U */
+ { 1, 2, 0, 0, 8, 1, 7, 1 }, /* V */
+ },
+ .flags = AV_PIX_FMT_FLAG_PLANAR,
+ },
[AV_PIX_FMT_NV20LE] = {
.name = "nv20le",
.nb_components = 3,
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index a46acf3..24b053c 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -199,6 +199,7 @@ enum AVPixelFormat {
AV_PIX_FMT_XYZ12LE, ///< packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as little-endian, the 4 lower bits are set to 0
AV_PIX_FMT_XYZ12BE, ///< packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as big-endian, the 4 lower bits are set to 0
AV_PIX_FMT_NV16, ///< interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
+ AV_PIX_FMT_NV61, ///< as above, but U and V bytes are swapped
AV_PIX_FMT_NV20LE, ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
AV_PIX_FMT_NV20BE, ///< interleaved chroma YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
diff --git a/libavutil/version.h b/libavutil/version.h
index 3ce9b18..a63f79f 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 56
-#define LIBAVUTIL_VERSION_MINOR 55
+#define LIBAVUTIL_VERSION_MINOR 56
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libswscale/input.c b/libswscale/input.c
index 0bd1aa7..0256428 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -1114,10 +1114,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
break;
case AV_PIX_FMT_NV12:
case AV_PIX_FMT_NV24:
+ case AV_PIX_FMT_NV16:
c->chrToYV12 = nv12ToUV_c;
break;
case AV_PIX_FMT_NV21:
case AV_PIX_FMT_NV42:
+ case AV_PIX_FMT_NV61:
c->chrToYV12 = nv21ToUV_c;
break;
case AV_PIX_FMT_RGB8:
diff --git a/libswscale/output.c b/libswscale/output.c
index 4ef436e..d757a12 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -411,7 +411,8 @@ static void yuv2nv12cX_c(enum AVPixelFormat dstFormat, const uint8_t *chrDither,
int i;
if (dstFormat == AV_PIX_FMT_NV12 ||
- dstFormat == AV_PIX_FMT_NV24)
+ dstFormat == AV_PIX_FMT_NV24 ||
+ dstFormat == AV_PIX_FMT_NV16)
for (i=0; i<chrDstW; i++) {
int u = chrDither[i & 7] << 12;
int v = chrDither[(i + 3) & 7] << 12;
@@ -2586,7 +2587,8 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
*yuv2plane1 = yuv2plane1_8_c;
*yuv2planeX = yuv2planeX_8_c;
if (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21 ||
- dstFormat == AV_PIX_FMT_NV24 || dstFormat == AV_PIX_FMT_NV42)
+ dstFormat == AV_PIX_FMT_NV24 || dstFormat == AV_PIX_FMT_NV42 ||
+ dstFormat == AV_PIX_FMT_NV16 || dstFormat == AV_PIX_FMT_NV61)
*yuv2nv12cX = yuv2nv12cX_c;
}
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 5fb572b..c10ed62 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -180,6 +180,47 @@ static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *src[],
return srcSliceH;
}
+static int planarToNv16Wrapper(SwsContext *c, const uint8_t *src[],
+ int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t *dstParam[],
+ int dstStride[])
+{
+ uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY;
+
+ copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
+ dstParam[0], dstStride[0]);
+
+ if (c->dstFormat == AV_PIX_FMT_NV16)
+ interleaveBytes(src[1], src[2], dst, c->chrSrcW, srcSliceH,
+ srcStride[1], srcStride[2], dstStride[1]);
+ else
+ interleaveBytes(src[2], src[1], dst, c->chrSrcW, srcSliceH,
+ srcStride[2], srcStride[1], dstStride[1]);
+
+ return srcSliceH;
+}
+
+static int nv16ToPlanarWrapper(SwsContext *c, const uint8_t *src[],
+ int srcStride[], int srcSliceY,
+ int srcSliceH, uint8_t *dstParam[],
+ int dstStride[])
+{
+ uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY;
+ uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY;
+
+ copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
+ dstParam[0], dstStride[0]);
+
+ if (c->srcFormat == AV_PIX_FMT_NV16)
+ deinterleaveBytes(src[1], dst1, dst2, c->chrSrcW, srcSliceH,
+ srcStride[1], dstStride[1], dstStride[2]);
+ else
+ deinterleaveBytes(src[1], dst2, dst1, c->chrSrcW, srcSliceH,
+ srcStride[1], dstStride[2], dstStride[1]);
+
+ return srcSliceH;
+}
+
static int planarToNv24Wrapper(SwsContext *c, const uint8_t *src[],
int srcStride[], int srcSliceY,
int srcSliceH, uint8_t *dstParam[],
@@ -1941,6 +1982,11 @@ void ff_get_unscaled_swscale(SwsContext *c)
(dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
c->swscale = planarToNv12Wrapper;
}
+ /* yv16_to_nv16 */
+ if ((srcFormat == AV_PIX_FMT_YUV422P || srcFormat == AV_PIX_FMT_YUVA422P) &&
+ (dstFormat == AV_PIX_FMT_NV16 || dstFormat == AV_PIX_FMT_NV61)) {
+ c->swscale = planarToNv16Wrapper;
+ }
/* yv24_to_nv24 */
if ((srcFormat == AV_PIX_FMT_YUV444P || srcFormat == AV_PIX_FMT_YUVA444P) &&
(dstFormat == AV_PIX_FMT_NV24 || dstFormat == AV_PIX_FMT_NV42)) {
@@ -1951,6 +1997,11 @@ void ff_get_unscaled_swscale(SwsContext *c)
(srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
c->swscale = nv12ToPlanarWrapper;
}
+ /* nv16_to_yv16 */
+ if (dstFormat == AV_PIX_FMT_YUV422P &&
+ (srcFormat == AV_PIX_FMT_NV16 || srcFormat == AV_PIX_FMT_NV61)) {
+ c->swscale = nv16ToPlanarWrapper;
+ }
/* nv24_to_yv24 */
if (dstFormat == AV_PIX_FMT_YUV444P &&
(srcFormat == AV_PIX_FMT_NV24 || srcFormat == AV_PIX_FMT_NV42)) {
diff --git a/libswscale/utils.c b/libswscale/utils.c
index dcd1dba..5cba18d 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -270,6 +270,8 @@ static const FormatEntry format_entries[] = {
[AV_PIX_FMT_YUVA444P12LE] = { 1, 1 },
[AV_PIX_FMT_NV24] = { 1, 1 },
[AV_PIX_FMT_NV42] = { 1, 1 },
+ [AV_PIX_FMT_NV16] = { 1, 1 },
+ [AV_PIX_FMT_NV61] = { 1, 1 },
[AV_PIX_FMT_Y210LE] = { 1, 0 },
[AV_PIX_FMT_X2RGB10LE] = { 1, 1 },
};
diff --git a/tests/ref/fate/filter-pixdesc-nv16 b/tests/ref/fate/filter-pixdesc-nv16
new file mode 100644
index 0000000..4c4587c
--- /dev/null
+++ b/tests/ref/fate/filter-pixdesc-nv16
@@ -0,0 +1 @@
+pixdesc-nv16 cbbc5d904b8eebad3705a325c3ec5734
diff --git a/tests/ref/fate/filter-pixdesc-nv61 b/tests/ref/fate/filter-pixdesc-nv61
new file mode 100644
index 0000000..199082c
--- /dev/null
+++ b/tests/ref/fate/filter-pixdesc-nv61
@@ -0,0 +1 @@
+pixdesc-nv61 daf82c600b201384b73847a911987a6b
diff --git a/tests/ref/fate/filter-pixfmts-copy b/tests/ref/fate/filter-pixfmts-copy
index 1d7657c..9653b38 100644
--- a/tests/ref/fate/filter-pixfmts-copy
+++ b/tests/ref/fate/filter-pixfmts-copy
@@ -56,9 +56,11 @@ grayf32le fb6ea85bfbc8cd21c51fc0e110197294
monob 8b04f859fee6a0be856be184acd7a0b5
monow 54d16d2c01abfd72ecdb5e51e283937c
nv12 8e24feb2c544dc26a20047a71e4c27aa
+nv16 22b1916c0694c4e2979bab8eb71f3d6b
nv21 335d85c9af6110f26ae9e187a82ed2cf
nv24 f30fc8d0ac40af69e119ea919a314572
nv42 29a212f70f8780fe0eb99abcae81894d
+nv61 b4d780c3485a3eb5b9168c07e6cf5cec
p010be 7f9842d6015026136bad60d03c035cc3
p010le c453421b9f726bdaf2bacf59a492c43b
p016be 7f9842d6015026136bad60d03c035cc3
diff --git a/tests/ref/fate/filter-pixfmts-crop b/tests/ref/fate/filter-pixfmts-crop
index 8fc7614..6526e9d 100644
--- a/tests/ref/fate/filter-pixfmts-crop
+++ b/tests/ref/fate/filter-pixfmts-crop
@@ -54,9 +54,11 @@ gray9le 4d1932d4968a248584f5e39c25f1dd43
grayf32be cf40ec06a8abe54852b7f85a00549eec
grayf32le b672526c9da9c8959ab881f242f6890a
nv12 92cda427f794374731ec0321ee00caac
+nv16 3264b16aaae554c21f052102b491c13b
nv21 1bcfc197f4fb95de85ba58182d8d2f69
nv24 514c8f12082f0737e558778cbe7de258
nv42 ece9baae1c5de579dac2c66a89e08ef3
+nv61 2c1b7a68cdc72eff7ed4fc626c18e697
p010be 8b2de2eb6b099bbf355bfc55a0694ddc
p010le 373b50c766dfd0a8e79c9a73246d803a
p016be 8b2de2eb6b099bbf355bfc55a0694ddc
diff --git a/tests/ref/fate/filter-pixfmts-field b/tests/ref/fate/filter-pixfmts-field
index ce8e535..7dcf8f7 100644
--- a/tests/ref/fate/filter-pixfmts-field
+++ b/tests/ref/fate/filter-pixfmts-field
@@ -56,9 +56,11 @@ grayf32le 6b856bdbf2a2bfcd2bc7d50f109daaf0
monob 2129cc72a484d7e10a44de9117aa9f80
monow 03d783611d265cae78293f88ea126ea1
nv12 16f7a46708ef25ebd0b72e47920cc11e
+nv16 34f36b03f5fccf4eac147b26bbc0a5e5
nv21 7294574037cc7f9373ef5695d8ebe809
nv24 3b100fb527b64ee2b2d7120da573faf5
nv42 1841ce853152d86b27c130f319ea0db2
+nv61 9ebbf320cca60f9dedeab79ab414699f
p010be a0311a09bba7383553267d2b3b9c075e
p010le ee09a18aefa3ebe97715b3a7312cb8ff
p016be a0311a09bba7383553267d2b3b9c075e
diff --git a/tests/ref/fate/filter-pixfmts-fieldorder b/tests/ref/fate/filter-pixfmts-fieldorder
index 90d36ad..cf82081 100644
--- a/tests/ref/fate/filter-pixfmts-fieldorder
+++ b/tests/ref/fate/filter-pixfmts-fieldorder
@@ -53,8 +53,10 @@ gray9be ec877f5bcf0ea275a6f36c12cc9adf11
gray9le fba944fde7923d5089f4f52d12988b9e
grayf32be 1aa7960131f880c54fe3c77f13448674
grayf32le 4029ac9d197f255794c1b9e416520fc7
+nv16 085deb984ab986eb5cc961fe265e30c0
nv24 4fdbef26042c77f012df114e666efdb2
nv42 59608290fece913e6b7d61edf581a529
+nv61 0d39c7cf78d443db91c2342b44b4814d
rgb0 2e3d8c91c7a83d451593dfd06607ff39
rgb24 b82577f8215d3dc2681be60f1da247af
rgb444be 1c3afc3a0c53c51139c76504f59bb1f4
diff --git a/tests/ref/fate/filter-pixfmts-hflip b/tests/ref/fate/filter-pixfmts-hflip
index 0d40b93..e4ac98b 100644
--- a/tests/ref/fate/filter-pixfmts-hflip
+++ b/tests/ref/fate/filter-pixfmts-hflip
@@ -54,9 +54,11 @@ gray9le 424fc581947bc8c357c9ec5e3c1c04d1
grayf32be a69add7bbf892a71fe81b3b75982dbe2
grayf32le 4563e176a35dc8a8a07e0829fad5eb88
nv12 801e58f1be5fd0b5bc4bf007c604b0b4
+nv16 06ba714cb8b220c203f5898ef39abf93
nv21 9f10dfff8963dc327d3395af21f0554f
nv24 f0c5b2f42970f8d4003621d8857a872f
nv42 4dcf9aec82b110712b396a8b365dcb13
+nv61 1cf6475b0e021d7f1c9ac45ad6fbf2d1
p010be 744b13e44d39e1ff7588983fa03e0101
p010le a50b160346ab94f55a425065b57006f0
p016be 744b13e44d39e1ff7588983fa03e0101
diff --git a/tests/ref/fate/filter-pixfmts-il b/tests/ref/fate/filter-pixfmts-il
index d1bc866..f6bc85a 100644
--- a/tests/ref/fate/filter-pixfmts-il
+++ b/tests/ref/fate/filter-pixfmts-il
@@ -56,9 +56,11 @@ grayf32le 8bf3d295c3ffd53da0e06d0702e7c1ca
monob faba75df28033ba7ce3d82ff2a99ee68
monow 6e9cfb8d3a344c5f0c3e1d5e1297e580
nv12 3c3ba9b1b4c4dfff09c26f71b51dd146
+nv16 355d055f91793a171302021b3fc486b0
nv21 ab586d8781246b5a32d8760a61db9797
nv24 554153c71d142e3fd8e40b7dcaaec229
nv42 d699724c8deaeb4f87faf2766512eec3
+nv61 033701cb2418ed5dc6fcc1c7c7e15620
p010be 3df51286ef66b53e3e283dbbab582263
p010le eadcd8241e97e35b2b47d5eb2eaea6cd
p016be 3df51286ef66b53e3e283dbbab582263
diff --git a/tests/ref/fate/filter-pixfmts-null b/tests/ref/fate/filter-pixfmts-null
index 1d7657c..9653b38 100644
--- a/tests/ref/fate/filter-pixfmts-null
+++ b/tests/ref/fate/filter-pixfmts-null
@@ -56,9 +56,11 @@ grayf32le fb6ea85bfbc8cd21c51fc0e110197294
monob 8b04f859fee6a0be856be184acd7a0b5
monow 54d16d2c01abfd72ecdb5e51e283937c
nv12 8e24feb2c544dc26a20047a71e4c27aa
+nv16 22b1916c0694c4e2979bab8eb71f3d6b
nv21 335d85c9af6110f26ae9e187a82ed2cf
nv24 f30fc8d0ac40af69e119ea919a314572
nv42 29a212f70f8780fe0eb99abcae81894d
+nv61 b4d780c3485a3eb5b9168c07e6cf5cec
p010be 7f9842d6015026136bad60d03c035cc3
p010le c453421b9f726bdaf2bacf59a492c43b
p016be 7f9842d6015026136bad60d03c035cc3
diff --git a/tests/ref/fate/filter-pixfmts-pad b/tests/ref/fate/filter-pixfmts-pad
index 9a5db82..c872ea0 100644
--- a/tests/ref/fate/filter-pixfmts-pad
+++ b/tests/ref/fate/filter-pixfmts-pad
@@ -22,9 +22,11 @@ gray14le af3f2f911c71cb34a8179a3291b5c90f
gray16le 468bda6155bdc7a7a20c34d6e599fd16
gray9le f8f3dfe31ca5fcba828285bceefdab9a
nv12 381574979cb04be10c9168540310afad
+nv16 d3a50501d2ea8535489fd5ec49e7866d
nv21 0fdeb2cdd56cf5a7147dc273456fa217
nv24 193b9eadcc06ad5081609f76249b3e47
nv42 1738ad3c31c6c16e17679f5b09ce4677
+nv61 2c46057c46d62547686c542c64a3f177
rgb0 78d500c8361ab6423a4826a00268c908
rgb24 17f9e2e0c609009acaf2175c42d4a2a5
rgba b157c90191463d34fb3ce77b36c96386
diff --git a/tests/ref/fate/filter-pixfmts-scale b/tests/ref/fate/filter-pixfmts-scale
index d7020ad..3b96e30 100644
--- a/tests/ref/fate/filter-pixfmts-scale
+++ b/tests/ref/fate/filter-pixfmts-scale
@@ -56,9 +56,11 @@ grayf32le 2ff1b84023e820307b1ba7a9550115bc
monob f01cb0b623357387827902d9d0963435
monow 35c68b86c226d6990b2dcb573a05ff6b
nv12 b118d24a3653fe66e5d9e079033aef79
+nv16 68e757396b62b84aad657274b8f6ce15
nv21 c74bb1c10dbbdee8a1f682b194486c4d
nv24 2aa6e805bf6d4179ed8d7dea37d75db3
nv42 80714d1eb2d8bcaeab3abc3124df1abd
+nv61 da0e79bde2481fd647c5a45099de9300
p010be 1d6726d94bf1385996a9a9840dd0e878
p010le 4b316f2b9e18972299beb73511278fa8
p016be 31e204018cbb53f8988c4e1174ea8ce9
diff --git a/tests/ref/fate/filter-pixfmts-vflip b/tests/ref/fate/filter-pixfmts-vflip
index 732db8d..b336d04 100644
--- a/tests/ref/fate/filter-pixfmts-vflip
+++ b/tests/ref/fate/filter-pixfmts-vflip
@@ -56,9 +56,11 @@ grayf32le 8e6c048a5b3b8b26d3a5ddfce255f3f6
monob 7810c4857822ccfc844d78f5e803269a
monow 90a947bfcd5f2261e83b577f48ec57b1
nv12 261ebe585ae2aa4e70d39a10c1679294
+nv16 f20f3448c900847aaff74429196f5a00
nv21 2909feacd27bebb080c8e0fa41795269
nv24 334420b9d3df84499d2ca16bb66eed2b
nv42 ba4063e2795c17fea3c8a646b01fd1f5
+nv61 2b17960578fd7bb78d3e35ad023fe7b3
p010be 06e9354b6e0e38ba41736352cedc0bd5
p010le fd18d322bffbf5816902c13102872e22
p016be 06e9354b6e0e38ba41736352cedc0bd5
diff --git a/tests/ref/fate/sws-pixdesc-query b/tests/ref/fate/sws-pixdesc-query
index c3cccfa..fe477f4 100644
--- a/tests/ref/fate/sws-pixdesc-query
+++ b/tests/ref/fate/sws-pixdesc-query
@@ -186,6 +186,7 @@ isYUV:
nv21
nv24
nv42
+ nv61
p010be
p010le
p016be
@@ -280,6 +281,7 @@ isPlanarYUV:
nv21
nv24
nv42
+ nv61
p010be
p010le
p016be
@@ -363,6 +365,7 @@ isSemiPlanarYUV:
nv21
nv24
nv42
+ nv61
p010be
p010le
p016be
@@ -738,6 +741,7 @@ Planar:
nv21
nv24
nv42
+ nv61
p010be
p010le
p016be
--
2.7.4
More information about the ffmpeg-devel
mailing list