[FFmpeg-devel] [PATCH] jpeg2000: split off inverse MCT decoding as Jpeg2000DSP

James Almer jamrial at gmail.com
Thu Oct 2 03:35:59 CEST 2014


This makes the addition of arch optimized functions easier.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/Makefile      |  2 +-
 libavcodec/jpeg2000dec.c | 71 +++++++++--------------------------
 libavcodec/jpeg2000dsp.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/jpeg2000dsp.h | 35 +++++++++++++++++
 libavcodec/jpeg2000dwt.h |  3 +-
 5 files changed, 153 insertions(+), 56 deletions(-)
 create mode 100644 libavcodec/jpeg2000dsp.c
 create mode 100644 libavcodec/jpeg2000dsp.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 10bd5e6..04a7944 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -275,7 +275,7 @@ OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 OBJS-$(CONFIG_JACOSUB_DECODER)         += jacosubdec.o ass.o
 OBJS-$(CONFIG_JPEG2000_ENCODER)        += j2kenc.o mqcenc.o mqc.o jpeg2000.o \
-                                          jpeg2000dwt.o
+                                          jpeg2000dwt.o jpeg2000dsp.o
 OBJS-$(CONFIG_JPEG2000_DECODER)        += jpeg2000dec.o jpeg2000.o      \
                                           jpeg2000dwt.o mqcdec.o mqc.o
 OBJS-$(CONFIG_JPEGLS_DECODER)          += jpeglsdec.o jpegls.o
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index d6204bb..17ee541 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -37,6 +37,7 @@
 #include "internal.h"
 #include "thread.h"
 #include "jpeg2000.h"
+#include "jpeg2000dsp.h"
 
 #define JP2_SIG_TYPE    0x6A502020
 #define JP2_SIG_VALUE   0x0D0A870A
@@ -93,6 +94,7 @@ typedef struct Jpeg2000DecoderContext {
     int             curtileno;
 
     Jpeg2000Tile    *tile;
+    Jpeg2000DSPContext dsp;
 
     /*options parameters*/
     int             reduction_factor;
@@ -1141,26 +1143,10 @@ static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk,
     }
 }
 
-/* Inverse ICT parameters in float and integer.
- * int value = (float value) * (1<<16) */
-static const float f_ict_params[4] = {
-    1.402f,
-    0.34413f,
-    0.71414f,
-    1.772f
-};
-static const int   i_ict_params[4] = {
-     91881,
-     22553,
-     46802,
-    116130
-};
-
-static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
+static inline void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
 {
     int i, csize = 1;
-    int32_t *src[3],  i0,  i1,  i2;
-    float   *srcf[3], i0f, i1f, i2f;
+    void *src[3];
 
     for (i = 1; i < 3; i++)
         if (tile->codsty[0].transform != tile->codsty[i].transform) {
@@ -1170,47 +1156,14 @@ static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
 
     for (i = 0; i < 3; i++)
         if (tile->codsty[0].transform == FF_DWT97)
-            srcf[i] = tile->comp[i].f_data;
+            src[i] = tile->comp[i].f_data;
         else
-            src [i] = tile->comp[i].i_data;
+            src[i] = tile->comp[i].i_data;
 
     for (i = 0; i < 2; i++)
         csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
 
-    switch (tile->codsty[0].transform) {
-    case FF_DWT97:
-        for (i = 0; i < csize; i++) {
-            i0f = *srcf[0] + (f_ict_params[0] * *srcf[2]);
-            i1f = *srcf[0] - (f_ict_params[1] * *srcf[1])
-                           - (f_ict_params[2] * *srcf[2]);
-            i2f = *srcf[0] + (f_ict_params[3] * *srcf[1]);
-            *srcf[0]++ = i0f;
-            *srcf[1]++ = i1f;
-            *srcf[2]++ = i2f;
-        }
-        break;
-    case FF_DWT97_INT:
-        for (i = 0; i < csize; i++) {
-            i0 = *src[0] + (((i_ict_params[0] * *src[2]) + (1 << 15)) >> 16);
-            i1 = *src[0] - (((i_ict_params[1] * *src[1]) + (1 << 15)) >> 16)
-                         - (((i_ict_params[2] * *src[2]) + (1 << 15)) >> 16);
-            i2 = *src[0] + (((i_ict_params[3] * *src[1]) + (1 << 15)) >> 16);
-            *src[0]++ = i0;
-            *src[1]++ = i1;
-            *src[2]++ = i2;
-        }
-        break;
-    case FF_DWT53:
-        for (i = 0; i < csize; i++) {
-            i1 = *src[0] - (*src[2] + *src[1] >> 2);
-            i0 = i1 + *src[2];
-            i2 = i1 + *src[1];
-            *src[0]++ = i0;
-            *src[1]++ = i1;
-            *src[2]++ = i2;
-        }
-        break;
-    }
+    s->dsp.mct_decode[tile->codsty[0].transform](src[0], src[1], src[2], csize);
 }
 
 static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
@@ -1621,6 +1574,15 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
     return 0;
 }
 
+static av_cold int jpeg2000_decode_init(AVCodecContext *avctx)
+{
+    Jpeg2000DecoderContext *s = avctx->priv_data;
+
+    ff_jpeg2000dsp_init(&s->dsp);
+
+    return 0;
+}
+
 static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
                                  int *got_frame, AVPacket *avpkt)
 {
@@ -1731,6 +1693,7 @@ AVCodec ff_jpeg2000_decoder = {
     .capabilities     = CODEC_CAP_FRAME_THREADS,
     .priv_data_size   = sizeof(Jpeg2000DecoderContext),
     .init_static_data = jpeg2000_init_static_data,
+    .init             = jpeg2000_decode_init,
     .decode           = jpeg2000_decode_frame,
     .priv_class       = &jpeg2000_class,
     .max_lowres       = 5,
diff --git a/libavcodec/jpeg2000dsp.c b/libavcodec/jpeg2000dsp.c
new file mode 100644
index 0000000..a7c7f53
--- /dev/null
+++ b/libavcodec/jpeg2000dsp.c
@@ -0,0 +1,98 @@
+/*
+ * JPEG 2000 DSP functions
+ * Copyright (c) 2007 Kamil Nowosad
+ * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu at gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "jpeg2000dsp.h"
+
+/* Inverse ICT parameters in float and integer.
+ * int value = (float value) * (1<<16) */
+static const float f_ict_params[4] = {
+    1.402f,
+    0.34413f,
+    0.71414f,
+    1.772f
+};
+
+static const int i_ict_params[4] = {
+     91881,
+     22553,
+     46802,
+    116130
+};
+
+static void ict_float(void *_src0, void *_src1, void *_src2, int csize)
+{
+    float *src0 = _src0, *src1 = _src1, *src2 = _src2;
+    float i0f, i1f, i2f;
+    int i;
+
+    for (i = 0; i < csize; i++) {
+        i0f = *src0 + (f_ict_params[0] * *src2);
+        i1f = *src0 - (f_ict_params[1] * *src1)
+                    - (f_ict_params[2] * *src2);
+        i2f = *src0 + (f_ict_params[3] * *src1);
+        *src0++ = i0f;
+        *src1++ = i1f;
+        *src2++ = i2f;
+    }
+}
+
+static void ict_int(void *_src0, void *_src1, void *_src2, int csize)
+{
+    int32_t *src0 = _src0, *src1 = _src1, *src2 = _src2;
+    int32_t i0, i1, i2;
+    int i;
+
+    for (i = 0; i < csize; i++) {
+        i0 = *src0 + (((i_ict_params[0] * *src2) + (1 << 15)) >> 16);
+        i1 = *src0 - (((i_ict_params[1] * *src1) + (1 << 15)) >> 16)
+                   - (((i_ict_params[2] * *src2) + (1 << 15)) >> 16);
+        i2 = *src0 + (((i_ict_params[3] * *src1) + (1 << 15)) >> 16);
+        *src0++ = i0;
+        *src1++ = i1;
+        *src2++ = i2;
+    }
+}
+
+static void rct_int(void *_src0, void *_src1, void *_src2, int csize)
+{
+    int32_t *src0 = _src0, *src1 = _src1, *src2 = _src2;
+    int32_t i0, i1, i2;
+    int i;
+
+    for (i = 0; i < csize; i++) {
+        i1 = *src0 - (*src2 + *src1 >> 2);
+        i0 = i1 + *src2;
+        i2 = i1 + *src1;
+        *src0++ = i0;
+        *src1++ = i1;
+        *src2++ = i2;
+    }
+}
+
+av_cold void ff_jpeg2000dsp_init(Jpeg2000DSPContext *c)
+{
+    c->mct_decode[FF_DWT97]     = ict_float;
+    c->mct_decode[FF_DWT53]     = rct_int;
+    c->mct_decode[FF_DWT97_INT] = ict_int;
+}
diff --git a/libavcodec/jpeg2000dsp.h b/libavcodec/jpeg2000dsp.h
new file mode 100644
index 0000000..de1ddb9
--- /dev/null
+++ b/libavcodec/jpeg2000dsp.h
@@ -0,0 +1,35 @@
+/*
+ * JPEG 2000 DSP functions
+ * Copyright (c) 2007 Kamil Nowosad
+ * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu at gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_JPEG2000DSP_H
+#define AVCODEC_JPEG2000DSP_H
+
+#include <stdint.h>
+#include "jpeg2000dwt.h"
+
+typedef struct Jpeg2000DSPContext {
+    void (*mct_decode[FF_DWT_NB])(void *src0, void *src1, void *src2, int csize);
+} Jpeg2000DSPContext;
+
+void ff_jpeg2000dsp_init(Jpeg2000DSPContext *c);
+
+#endif /* AVCODEC_JPEG2000DSP_H */
diff --git a/libavcodec/jpeg2000dwt.h b/libavcodec/jpeg2000dwt.h
index b5be812..b6d296d 100644
--- a/libavcodec/jpeg2000dwt.h
+++ b/libavcodec/jpeg2000dwt.h
@@ -34,7 +34,8 @@
 enum DWTType {
     FF_DWT97,
     FF_DWT53,
-    FF_DWT97_INT
+    FF_DWT97_INT,
+    FF_DWT_NB
 };
 
 typedef struct DWTContext {
-- 
2.0.4



More information about the ffmpeg-devel mailing list