diff options
author | Paul B Mahol <onemda@gmail.com> | 2017-12-31 12:47:27 +0300 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2018-01-02 15:41:50 +0300 |
commit | 57d0c24132c544441266b3f561d9af15d4f8cf42 (patch) | |
tree | 6b30147762485cef28c125017288570ec2ba0c9d /libavcodec/utvideoenc.c | |
parent | 92b32664cdc064523c60ddba5ed139855e08470c (diff) |
avcodec/utvideoenc: switch to planar RGB formats
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavcodec/utvideoenc.c')
-rw-r--r-- | libavcodec/utvideoenc.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c index 840742caf7..a829b7aaac 100644 --- a/libavcodec/utvideoenc.c +++ b/libavcodec/utvideoenc.c @@ -67,12 +67,12 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx) c->slice_stride = FFALIGN(avctx->width, 32); switch (avctx->pix_fmt) { - case AV_PIX_FMT_RGB24: + case AV_PIX_FMT_GBRP: c->planes = 3; avctx->codec_tag = MKTAG('U', 'L', 'R', 'G'); original_format = UTVIDEO_RGB; break; - case AV_PIX_FMT_RGBA: + case AV_PIX_FMT_GBRAP: c->planes = 4; avctx->codec_tag = MKTAG('U', 'L', 'R', 'A'); original_format = UTVIDEO_RGBA; @@ -243,36 +243,43 @@ FF_ENABLE_DEPRECATION_WARNINGS } static void mangle_rgb_planes(uint8_t *dst[4], ptrdiff_t dst_stride, - uint8_t *src, int step, ptrdiff_t stride, + uint8_t *const src[4], int planes, const int stride[4], int width, int height) { int i, j; int k = 2 * dst_stride; + const uint8_t *sg = src[0]; + const uint8_t *sb = src[1]; + const uint8_t *sr = src[2]; + const uint8_t *sa = src[3]; unsigned int g; for (j = 0; j < height; j++) { - if (step == 3) { - for (i = 0; i < width * step; i += step) { - g = src[i + 1]; + if (planes == 3) { + for (i = 0; i < width; i++) { + g = sg[i]; dst[0][k] = g; g += 0x80; - dst[1][k] = src[i + 2] - g; - dst[2][k] = src[i + 0] - g; + dst[1][k] = sb[i] - g; + dst[2][k] = sr[i] - g; k++; } } else { - for (i = 0; i < width * step; i += step) { - g = src[i + 1]; + for (i = 0; i < width; i++) { + g = sg[i]; dst[0][k] = g; g += 0x80; - dst[1][k] = src[i + 2] - g; - dst[2][k] = src[i + 0] - g; - dst[3][k] = src[i + 3]; + dst[1][k] = sb[i] - g; + dst[2][k] = sr[i] - g; + dst[3][k] = sa[i]; k++; } + sa += stride[3]; } k += dst_stride - width; - src += stride; + sg += stride[0]; + sb += stride[1]; + sr += stride[2]; } } @@ -572,14 +579,14 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, } /* In case of RGB, mangle the planes to Ut Video's format */ - if (avctx->pix_fmt == AV_PIX_FMT_RGBA || avctx->pix_fmt == AV_PIX_FMT_RGB24) - mangle_rgb_planes(c->slice_buffer, c->slice_stride, pic->data[0], - c->planes, pic->linesize[0], width, height); + if (avctx->pix_fmt == AV_PIX_FMT_GBRAP || avctx->pix_fmt == AV_PIX_FMT_GBRP) + mangle_rgb_planes(c->slice_buffer, c->slice_stride, pic->data, + c->planes, pic->linesize, width, height); /* Deal with the planes */ switch (avctx->pix_fmt) { - case AV_PIX_FMT_RGB24: - case AV_PIX_FMT_RGBA: + case AV_PIX_FMT_GBRP: + case AV_PIX_FMT_GBRAP: for (i = 0; i < c->planes; i++) { ret = encode_plane(avctx, c->slice_buffer[i] + 2 * c->slice_stride, c->slice_buffer[i], c->slice_stride, i, @@ -690,7 +697,7 @@ AVCodec ff_utvideo_encoder = { .close = utvideo_encode_close, .capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY, .pix_fmts = (const enum AVPixelFormat[]) { - AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_YUV422P, + AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE }, }; |