diff options
author | James Almer <jamrial@gmail.com> | 2014-10-02 14:08:01 -0300 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2014-10-08 08:02:55 +0000 |
commit | 82f8eb5f773d87e3d9c0066ef19b501a461ddfae (patch) | |
tree | 18f9f13124aded32b83f6fe15c12d4f057d2f135 /libavcodec | |
parent | 9a03c2323593173a201cb75edd1b49887cf811ed (diff) | |
download | ffmpeg-82f8eb5f773d87e3d9c0066ef19b501a461ddfae.tar.gz |
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')
-rw-r--r-- | libavcodec/Makefile | 2 | ||||
-rw-r--r-- | libavcodec/jpeg2000dec.c | 72 | ||||
-rw-r--r-- | libavcodec/jpeg2000dsp.c | 98 | ||||
-rw-r--r-- | libavcodec/jpeg2000dsp.h | 35 | ||||
-rw-r--r-- | libavcodec/jpeg2000dwt.h | 3 |
5 files changed, 154 insertions, 56 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 178b61e530..69b92b66b8 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -229,7 +229,7 @@ OBJS-$(CONFIG_INDEO4_DECODER) += indeo4.o ivi_common.o ivi_dsp.o OBJS-$(CONFIG_INDEO5_DECODER) += indeo5.o ivi_common.o ivi_dsp.o OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o -OBJS-$(CONFIG_JPEG2000_DECODER) += jpeg2000dec.o jpeg2000.o \ +OBJS-$(CONFIG_JPEG2000_DECODER) += jpeg2000dec.o jpeg2000.o jpeg2000dsp.o \ jpeg2000dwt.o mqcdec.o mqc.o OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index aed9b2bda0..51352979e7 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -35,6 +35,7 @@ #include "internal.h" #include "thread.h" #include "jpeg2000.h" +#include "jpeg2000dsp.h" #define JP2_SIG_TYPE 0x6A502020 #define JP2_SIG_VALUE 0x0D0A870A @@ -85,6 +86,7 @@ typedef struct Jpeg2000DecoderContext { int16_t curtileno; Jpeg2000Tile *tile; + Jpeg2000DSPContext dsp; /*options parameters*/ int reduction_factor; @@ -1041,69 +1043,21 @@ 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 = 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, @@ -1406,6 +1360,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) { @@ -1510,6 +1473,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 = &class, .profiles = NULL_IF_CONFIG_SMALL(profiles) 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; +} diff --git a/libavcodec/jpeg2000dsp.h b/libavcodec/jpeg2000dsp.h new file mode 100644 index 0000000000..45a32c0dd8 --- /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@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 + */ + +#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 9aaa18bacb..f08340dbc9 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 { |