diff mbox series

[FFmpeg-devel,08/11] avcodec/j2kenc: Planar RGB support

Message ID 20230330180106.11275-8-michael@niedermayer.cc
State Accepted
Commit b41dabd00dcaaf83e6750cceffa5543451ff12fc
Headers show
Series [FFmpeg-devel,01/11] avcodec/j2kenc: fix 5/3 DWT identifer | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer March 30, 2023, 6:01 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/j2kenc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Anton Khirnov March 31, 2023, 2:19 p.m. UTC | #1
Quoting Michael Niedermayer (2023-03-30 20:01:03)
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/j2kenc.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)

Having tests for all these new features would be really nice.
Michael Niedermayer April 2, 2023, 9:19 p.m. UTC | #2
On Fri, Mar 31, 2023 at 04:19:12PM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2023-03-30 20:01:03)
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/j2kenc.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> Having tests for all these new features would be really nice.

ill add some tests
if you want me to add more say so, iam not sure how exhaustive to
cover pixel formats for example

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 8d9c1fdb1c0..0715d424a15 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);