Skip to content
This repository was archived by the owner on May 7, 2020. It is now read-only.

Commit ecc953c

Browse files
committed
Add P010 pixel format and basic swscale support
1 parent 8985609 commit ecc953c

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

libavutil/pixdesc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,30 @@ static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
19661966
},
19671967
.flags = AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_BE,
19681968
},
1969+
[AV_PIX_FMT_P010LE] = {
1970+
.name = "p010le",
1971+
.nb_components = 3,
1972+
.log2_chroma_w = 1,
1973+
.log2_chroma_h = 1,
1974+
.comp = {
1975+
{ 0, 1, 1, 6, 9 }, /* Y */
1976+
{ 1, 3, 1, 6, 9 }, /* U */
1977+
{ 1, 3, 3, 6, 9 }, /* V */
1978+
},
1979+
.flags = AV_PIX_FMT_FLAG_PLANAR,
1980+
},
1981+
[AV_PIX_FMT_P010BE] = {
1982+
.name = "p010be",
1983+
.nb_components = 3,
1984+
.log2_chroma_w = 1,
1985+
.log2_chroma_h = 1,
1986+
.comp = {
1987+
{ 0, 1, 1, 6, 9 }, /* Y */
1988+
{ 1, 3, 1, 6, 9 }, /* U */
1989+
{ 1, 3, 3, 6, 9 }, /* V */
1990+
},
1991+
.flags = AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_BE,
1992+
},
19691993
[AV_PIX_FMT_VDA] = {
19701994
.name = "vda",
19711995
.flags = AV_PIX_FMT_FLAG_HWACCEL,

libavutil/pixfmt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ enum AVPixelFormat {
289289

290290
AV_PIX_FMT_VIDEOTOOLBOX, ///< hardware decoding through Videotoolbox
291291

292+
AV_PIX_FMT_P010BE, ///< like NV12, with 10bpp per component, data in the high bits, zeros in the low bits
293+
AV_PIX_FMT_P010LE,
294+
292295
AV_PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
293296
};
294297

@@ -365,6 +368,7 @@ enum AVPixelFormat {
365368
#define AV_PIX_FMT_XYZ12 AV_PIX_FMT_NE(XYZ12BE, XYZ12LE)
366369
#define AV_PIX_FMT_NV20 AV_PIX_FMT_NE(NV20BE, NV20LE)
367370
#define AV_PIX_FMT_AYUV64 AV_PIX_FMT_NE(AYUV64BE, AYUV64LE)
371+
#define AV_PIX_FMT_P010 AV_PIX_FMT_NE(P010BE, P010LE)
368372

369373
/**
370374
* Chromaticity coordinates of the source primaries.

libswscale/input.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,30 @@ static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
679679
nvXXtoUV_c(dstV, dstU, src1, width);
680680
}
681681

682+
static void p010ToUV_c(uint8_t *dstU, uint8_t *dstV,
683+
const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2,
684+
int width, uint32_t *unused)
685+
{
686+
uint16_t *dstU16 = (uint16_t *)dstU, *dstV16 = (uint16_t *)dstV;
687+
const uint16_t *src16 = (uint16_t *)src1;
688+
int i;
689+
for (i = 0; i < width; i++) {
690+
dstU16[i] = src16[2 * i + 0] >> 6;
691+
dstV16[i] = src16[2 * i + 1] >> 6;
692+
}
693+
}
694+
695+
static void p010ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused1, const uint8_t *unused2, int width,
696+
uint32_t *unused)
697+
{
698+
uint16_t *dst = (uint16_t *)_dst;
699+
const uint16_t *src = (uint16_t *)_src;
700+
int i;
701+
for (i = 0; i < width; i++) {
702+
dst[i] = src[i] >> 6;
703+
}
704+
}
705+
682706
#define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
683707

684708
static void bgr24ToY_c(uint8_t *_dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,
@@ -910,6 +934,9 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
910934
case AV_PIX_FMT_NV21:
911935
c->chrToYV12 = nv21ToUV_c;
912936
break;
937+
case AV_PIX_FMT_P010:
938+
c->chrToYV12 = p010ToUV_c;
939+
break;
913940
case AV_PIX_FMT_RGB8:
914941
case AV_PIX_FMT_BGR8:
915942
case AV_PIX_FMT_PAL8:
@@ -1226,6 +1253,9 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
12261253
case AV_PIX_FMT_GBRP:
12271254
c->readLumPlanar = planar_rgb_to_y;
12281255
break;
1256+
case AV_PIX_FMT_P010:
1257+
c->lumToYV12 = p010ToY_c;
1258+
break;
12291259
#if HAVE_BIGENDIAN
12301260
case AV_PIX_FMT_YUV444P9LE:
12311261
case AV_PIX_FMT_YUV422P9LE:

libswscale/swscale_unscaled.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,8 +1751,8 @@ void ff_get_unscaled_swscale(SwsContext *c)
17511751
(isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
17521752
c->chrDstHSubSample == c->chrSrcHSubSample &&
17531753
c->chrDstVSubSample == c->chrSrcVSubSample &&
1754-
dstFormat != AV_PIX_FMT_NV12 && dstFormat != AV_PIX_FMT_NV21 &&
1755-
srcFormat != AV_PIX_FMT_NV12 && srcFormat != AV_PIX_FMT_NV21))
1754+
dstFormat != AV_PIX_FMT_NV12 && dstFormat != AV_PIX_FMT_NV21 && dstFormat != AV_PIX_FMT_P010 &&
1755+
srcFormat != AV_PIX_FMT_NV12 && srcFormat != AV_PIX_FMT_NV21 && srcFormat != AV_PIX_FMT_P010))
17561756
{
17571757
if (isPacked(c->srcFormat))
17581758
c->swscale = packedCopyWrapper;

libswscale/utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ static const FormatEntry format_entries[AV_PIX_FMT_NB] = {
227227
[AV_PIX_FMT_XYZ12BE] = { 1, 1, 1 },
228228
[AV_PIX_FMT_XYZ12LE] = { 1, 1, 1 },
229229
[AV_PIX_FMT_AYUV64LE] = { 1, 1},
230+
[AV_PIX_FMT_P010] = { 1, 0 },
230231
};
231232

232233
int sws_isSupportedInput(enum AVPixelFormat pix_fmt)

0 commit comments

Comments
 (0)