[FFmpeg-cvslog] avcodec/j2kenc: simplify pixel format setup
Michael Niedermayer
git at videolan.org
Mon Oct 30 02:09:07 EET 2023
ffmpeg | branch: release/5.1 | Michael Niedermayer <michael at niedermayer.cc> | Thu Mar 30 18:40:31 2023 +0200| [cf6ae79a71e302b25e6cd32314d46a5740340e8a] | committer: Michael Niedermayer
avcodec/j2kenc: simplify pixel format setup
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 644d15716d5cfb28e4ea0c0ada163f70807e9a5c)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cf6ae79a71e302b25e6cd32314d46a5740340e8a
---
libavcodec/j2kenc.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 67dad9f1b7..fbb2f991ca 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -1716,6 +1716,7 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
Jpeg2000EncoderContext *s = avctx->priv_data;
Jpeg2000CodingStyle *codsty = &s->codsty;
Jpeg2000QuantStyle *qntsty = &s->qntsty;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
s->avctx = avctx;
av_log(s->avctx, AV_LOG_DEBUG, "init\n");
@@ -1758,20 +1759,13 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
s->width = avctx->width;
s->height = avctx->height;
+ s->ncomponents = desc->nb_components;
for (i = 0; i < 3; i++) {
- if (avctx->pix_fmt == AV_PIX_FMT_GRAY16 || avctx->pix_fmt == AV_PIX_FMT_RGB48)
- s->cbps[i] = 16;
- else
- s->cbps[i] = 8;
+ s->cbps[i] = desc->comp[i].depth;
}
- if (avctx->pix_fmt == AV_PIX_FMT_RGB24 || avctx->pix_fmt == AV_PIX_FMT_RGB48){
- s->ncomponents = 3;
- } else if (avctx->pix_fmt == AV_PIX_FMT_GRAY8 || avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY16){
- s->ncomponents = 1;
- } else{ // planar YUV
+ if ((desc->flags & AV_PIX_FMT_FLAG_PLANAR) && s->ncomponents > 1) {
s->planar = 1;
- s->ncomponents = 3;
ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt,
s->chroma_shift, s->chroma_shift + 1);
if (ret)
More information about the ffmpeg-cvslog
mailing list