| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * JPEG 2000 DSP functions | ||
| 3 | * Copyright (c) 2007 Kamil Nowosad | ||
| 4 | * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@gmail.com> | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "config.h" | ||
| 24 | #include "libavutil/attributes.h" | ||
| 25 | #include "jpeg2000dsp.h" | ||
| 26 | |||
| 27 | /* Inverse ICT parameters in float and integer. | ||
| 28 | * int value = (float value) * (1<<16) */ | ||
| 29 | const float ff_jpeg2000_f_ict_params[4] = { | ||
| 30 | 1.402f, | ||
| 31 | 0.34413f, | ||
| 32 | 0.71414f, | ||
| 33 | 1.772f | ||
| 34 | }; | ||
| 35 | |||
| 36 | static const int i_ict_params[4] = { | ||
| 37 | 91881, | ||
| 38 | 22553, | ||
| 39 | 46802, | ||
| 40 | 116130 | ||
| 41 | }; | ||
| 42 | |||
| 43 | 3 | static void ict_float(void *_src0, void *_src1, void *_src2, int csize) | |
| 44 | { | ||
| 45 | 3 | const float *const f_ict_params = ff_jpeg2000_f_ict_params; | |
| 46 | 3 | float *src0 = _src0, *src1 = _src1, *src2 = _src2; | |
| 47 | float i0f, i1f, i2f; | ||
| 48 | int i; | ||
| 49 | |||
| 50 |
2/2✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 3 times.
|
1539 | for (i = 0; i < csize; i++) { |
| 51 | 1536 | i0f = *src0 + (f_ict_params[0] * *src2); | |
| 52 | 1536 | i1f = *src0 - (f_ict_params[1] * *src1) | |
| 53 | 1536 | - (f_ict_params[2] * *src2); | |
| 54 | 1536 | i2f = *src0 + (f_ict_params[3] * *src1); | |
| 55 | 1536 | *src0++ = i0f; | |
| 56 | 1536 | *src1++ = i1f; | |
| 57 | 1536 | *src2++ = i2f; | |
| 58 | } | ||
| 59 | 3 | } | |
| 60 | |||
| 61 | 3 | static void ict_int(void *_src0, void *_src1, void *_src2, int csize) | |
| 62 | { | ||
| 63 | 3 | int32_t *src0 = _src0, *src1 = _src1, *src2 = _src2; | |
| 64 | int32_t i0, i1, i2; | ||
| 65 | int i; | ||
| 66 | |||
| 67 |
2/2✓ Branch 0 taken 4454400 times.
✓ Branch 1 taken 3 times.
|
4454403 | for (i = 0; i < csize; i++) { |
| 68 | 4454400 | i0 = *src0 + *src2 + ((int)((26345U * *src2) + (1 << 15)) >> 16); | |
| 69 | 4454400 | i1 = *src0 - ((int)(((unsigned)i_ict_params[1] * *src1) + (1 << 15)) >> 16) | |
| 70 | 4454400 | - ((int)(((unsigned)i_ict_params[2] * *src2) + (1 << 15)) >> 16); | |
| 71 | 4454400 | i2 = *src0 + (2 * *src1) + ((int)((-14942U * *src1) + (1 << 15)) >> 16); | |
| 72 | 4454400 | *src0++ = i0; | |
| 73 | 4454400 | *src1++ = i1; | |
| 74 | 4454400 | *src2++ = i2; | |
| 75 | } | ||
| 76 | 3 | } | |
| 77 | |||
| 78 | 8 | static void rct_int(void *_src0, void *_src1, void *_src2, int csize) | |
| 79 | { | ||
| 80 | 8 | uint32_t *src0 = _src0, *src1 = _src1, *src2 = _src2; | |
| 81 | int i; | ||
| 82 | |||
| 83 |
2/2✓ Branch 0 taken 8033 times.
✓ Branch 1 taken 8 times.
|
8041 | for (i = 0; i < csize; i++) { |
| 84 | 8033 | uint32_t i1 = *src0 - ((int32_t)(*src2 + *src1) >> 2); | |
| 85 | 8033 | int32_t i0 = i1 + *src2; | |
| 86 | 8033 | int32_t i2 = i1 + *src1; | |
| 87 | 8033 | *src0++ = i0; | |
| 88 | 8033 | *src1++ = i1; | |
| 89 | 8033 | *src2++ = i2; | |
| 90 | } | ||
| 91 | 8 | } | |
| 92 | |||
| 93 | 80 | av_cold void ff_jpeg2000dsp_init(Jpeg2000DSPContext *c) | |
| 94 | { | ||
| 95 | 80 | c->mct_decode[FF_DWT97] = ict_float; | |
| 96 | 80 | c->mct_decode[FF_DWT53] = rct_int; | |
| 97 | 80 | c->mct_decode[FF_DWT97_INT] = ict_int; | |
| 98 | |||
| 99 | #if ARCH_RISCV | ||
| 100 | ff_jpeg2000dsp_init_riscv(c); | ||
| 101 | #elif ARCH_X86 | ||
| 102 | 80 | ff_jpeg2000dsp_init_x86(c); | |
| 103 | #endif | ||
| 104 | 80 | } | |
| 105 |