summaryrefslogtreecommitdiff
path: root/libavcodec/jpeg2000dsp.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2014-10-02 14:08:01 -0300
committerAnton Khirnov <anton@khirnov.net>2014-10-08 08:02:55 +0000
commit82f8eb5f773d87e3d9c0066ef19b501a461ddfae (patch)
tree18f9f13124aded32b83f6fe15c12d4f057d2f135 /libavcodec/jpeg2000dsp.c
parent9a03c2323593173a201cb75edd1b49887cf811ed (diff)
jpeg2000: split off inverse MCT as Jpeg2000DSP
This makes the addition of arch optimized functions easier. Signed-off-by: James Almer <jamrial@gmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavcodec/jpeg2000dsp.c')
-rw-r--r--libavcodec/jpeg2000dsp.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/libavcodec/jpeg2000dsp.c b/libavcodec/jpeg2000dsp.c
new file mode 100644
index 0000000000..6e04c3a37d
--- /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@gmail.com>
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; 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;
+}