[FFmpeg-cvslog] avcodec/j2kenc: Planar RGB support

Michael Niedermayer git at videolan.org
Mon Apr 3 00:57:36 EEST 2023


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Thu Mar 30 19:27:00 2023 +0200| [b41dabd00dcaaf83e6750cceffa5543451ff12fc] | committer: Michael Niedermayer

avcodec/j2kenc: Planar RGB support

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b41dabd00dcaaf83e6750cceffa5543451ff12fc
---

 libavcodec/j2kenc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 8d9c1fdb1c..0715d424a1 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -115,6 +115,7 @@ typedef struct {
 
     int width, height; ///< image width and height
     uint8_t cbps[4]; ///< bits per sample in particular components
+    uint8_t comp_remap[4];
     int chroma_shift[2];
     uint8_t planar;
     int ncomponents;
@@ -512,17 +513,18 @@ static int init_tiles(Jpeg2000EncoderContext *s)
             Jpeg2000Tile *tile = s->tile + tileno;                                                                          \
             if (s->planar){                                                                                                 \
                 for (compno = 0; compno < s->ncomponents; compno++){                                                        \
+                    int icompno = s->comp_remap[compno];                                                                    \
                     Jpeg2000Component *comp = tile->comp + compno;                                                          \
                     int *dst = comp->i_data;                                                                                \
                     int cbps = s->cbps[compno];                                                                             \
-                    line = (const PIXEL*)s->picture->data[compno]                                                           \
-                           + comp->coord[1][0] * (s->picture->linesize[compno] / sizeof(PIXEL))                             \
+                    line = (const PIXEL*)s->picture->data[icompno]                                                           \
+                           + comp->coord[1][0] * (s->picture->linesize[icompno] / sizeof(PIXEL))                             \
                            + comp->coord[0][0];                                                                             \
                     for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){                                                \
                         const PIXEL *ptr = line;                                                                            \
                         for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++)                                             \
                             *dst++ = *ptr++ - (1 << (cbps - 1));                                                            \
-                        line += s->picture->linesize[compno] / sizeof(PIXEL);                                               \
+                        line += s->picture->linesize[icompno] / sizeof(PIXEL);                                               \
                     }                                                                                                       \
                 }                                                                                                           \
             } else{                                                                                                         \
@@ -1763,6 +1765,7 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
     s->ncomponents = desc->nb_components;
     for (i = 0; i < 3; i++) {
         s->cbps[i] = desc->comp[i].depth;
+        s->comp_remap[i] = i; //default
     }
 
     if ((desc->flags & AV_PIX_FMT_FLAG_PLANAR) && s->ncomponents > 1) {
@@ -1771,6 +1774,11 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
                                                s->chroma_shift, s->chroma_shift + 1);
         if (ret)
             return ret;
+        if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
+            s->comp_remap[0] = 2;
+            s->comp_remap[1] = 0;
+            s->comp_remap[2] = 1;
+        }
     }
 
     ff_thread_once(&init_static_once, init_luts);



More information about the ffmpeg-cvslog mailing list