| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stdint.h> | ||
| 20 | |||
| 21 | #include "config.h" | ||
| 22 | #include "libavutil/attributes.h" | ||
| 23 | #include "libavutil/common.h" | ||
| 24 | |||
| 25 | #include "apv.h" | ||
| 26 | #include "apv_dsp.h" | ||
| 27 | |||
| 28 | |||
| 29 | static const int8_t apv_trans_matrix[8][8] = { | ||
| 30 | { 64, 64, 64, 64, 64, 64, 64, 64 }, | ||
| 31 | { 89, 75, 50, 18, -18, -50, -75, -89 }, | ||
| 32 | { 84, 35, -35, -84, -84, -35, 35, 84 }, | ||
| 33 | { 75, -18, -89, -50, 50, 89, 18, -75 }, | ||
| 34 | { 64, -64, -64, 64, 64, -64, -64, 64 }, | ||
| 35 | { 50, -89, 18, 75, -75, -18, 89, -50 }, | ||
| 36 | { 35, -84, 84, -35, -35, 84, -84, 35 }, | ||
| 37 | { 18, -50, 75, -89, 89, -75, 50, -18 }, | ||
| 38 | }; | ||
| 39 | |||
| 40 | 8646 | static void apv_decode_transquant_c(void *output, | |
| 41 | ptrdiff_t pitch, | ||
| 42 | const int16_t *input_flat, | ||
| 43 | const int16_t *qmatrix_flat, | ||
| 44 | int bit_depth, | ||
| 45 | int qp_shift) | ||
| 46 | { | ||
| 47 | 8646 | const int16_t (*input)[8] = (const int16_t(*)[8])input_flat; | |
| 48 | 8646 | const int16_t (*qmatrix)[8] = (const int16_t(*)[8])qmatrix_flat; | |
| 49 | |||
| 50 | int16_t scaled_coeff[8][8]; | ||
| 51 | int32_t recon_sample[8][8]; | ||
| 52 | |||
| 53 | // Dequant. | ||
| 54 | { | ||
| 55 | // Note that level_scale was already combined into qmatrix | ||
| 56 | // before we got here. | ||
| 57 | 8646 | int bd_shift = bit_depth + 3 - 5; | |
| 58 | |||
| 59 |
2/2✓ Branch 0 taken 69168 times.
✓ Branch 1 taken 8646 times.
|
77814 | for (int y = 0; y < 8; y++) { |
| 60 |
2/2✓ Branch 0 taken 553344 times.
✓ Branch 1 taken 69168 times.
|
622512 | for (int x = 0; x < 8; x++) { |
| 61 | 553344 | int coeff = ((int)(input[y][x] * qmatrix[y][x] * (1U << qp_shift) + | |
| 62 | 553344 | (1 << (bd_shift - 1)))) >> bd_shift; | |
| 63 | |||
| 64 | 553344 | scaled_coeff[y][x] = | |
| 65 | 553344 | av_clip(coeff, APV_MIN_TRANS_COEFF, | |
| 66 | APV_MAX_TRANS_COEFF); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | // Transform. | ||
| 72 | { | ||
| 73 | int32_t tmp[8][8]; | ||
| 74 | |||
| 75 | // Vertical transform of columns. | ||
| 76 |
2/2✓ Branch 0 taken 69168 times.
✓ Branch 1 taken 8646 times.
|
77814 | for (int x = 0; x < 8; x++) { |
| 77 |
2/2✓ Branch 0 taken 553344 times.
✓ Branch 1 taken 69168 times.
|
622512 | for (int i = 0; i < 8; i++) { |
| 78 | 553344 | int sum = 0; | |
| 79 |
2/2✓ Branch 0 taken 4426752 times.
✓ Branch 1 taken 553344 times.
|
4980096 | for (int j = 0; j < 8; j++) |
| 80 | 4426752 | sum += apv_trans_matrix[j][i] * scaled_coeff[j][x]; | |
| 81 | 553344 | tmp[i][x] = sum; | |
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | // Renormalise. | ||
| 86 |
2/2✓ Branch 0 taken 69168 times.
✓ Branch 1 taken 8646 times.
|
77814 | for (int x = 0; x < 8; x++) { |
| 87 |
2/2✓ Branch 0 taken 553344 times.
✓ Branch 1 taken 69168 times.
|
622512 | for (int y = 0; y < 8; y++) |
| 88 | 553344 | tmp[y][x] = (tmp[y][x] + 64) >> 7; | |
| 89 | } | ||
| 90 | |||
| 91 | // Horizontal transform of rows. | ||
| 92 |
2/2✓ Branch 0 taken 69168 times.
✓ Branch 1 taken 8646 times.
|
77814 | for (int y = 0; y < 8; y++) { |
| 93 |
2/2✓ Branch 0 taken 553344 times.
✓ Branch 1 taken 69168 times.
|
622512 | for (int i = 0; i < 8; i++) { |
| 94 | 553344 | int sum = 0; | |
| 95 |
2/2✓ Branch 0 taken 4426752 times.
✓ Branch 1 taken 553344 times.
|
4980096 | for (int j = 0; j < 8; j++) |
| 96 | 4426752 | sum += apv_trans_matrix[j][i] * tmp[y][j]; | |
| 97 | 553344 | recon_sample[y][i] = sum; | |
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | // Output. | ||
| 103 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8643 times.
|
8646 | if (bit_depth == 8) { |
| 104 | 3 | uint8_t *ptr = output; | |
| 105 | 3 | int bd_shift = 20 - bit_depth; | |
| 106 | |||
| 107 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
|
27 | for (int y = 0; y < 8; y++) { |
| 108 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
|
216 | for (int x = 0; x < 8; x++) { |
| 109 | 192 | int sample = ((recon_sample[y][x] + | |
| 110 | 192 | (1 << (bd_shift - 1))) >> bd_shift) + | |
| 111 | 192 | (1 << (bit_depth - 1)); | |
| 112 | 192 | ptr[x] = av_clip_uintp2(sample, bit_depth); | |
| 113 | } | ||
| 114 | 24 | ptr += pitch; | |
| 115 | } | ||
| 116 | } else { | ||
| 117 | 8643 | uint16_t *ptr = output; | |
| 118 | 8643 | int bd_shift = 20 - bit_depth; | |
| 119 | 8643 | pitch /= 2; // Pitch was in bytes, 2 bytes per sample. | |
| 120 | |||
| 121 |
2/2✓ Branch 0 taken 69144 times.
✓ Branch 1 taken 8643 times.
|
77787 | for (int y = 0; y < 8; y++) { |
| 122 |
2/2✓ Branch 0 taken 553152 times.
✓ Branch 1 taken 69144 times.
|
622296 | for (int x = 0; x < 8; x++) { |
| 123 | 553152 | int sample = ((recon_sample[y][x] + | |
| 124 | 553152 | (1 << (bd_shift - 1))) >> bd_shift) + | |
| 125 | 553152 | (1 << (bit_depth - 1)); | |
| 126 | 553152 | ptr[x] = av_clip_uintp2(sample, bit_depth); | |
| 127 | } | ||
| 128 | 69144 | ptr += pitch; | |
| 129 | } | ||
| 130 | } | ||
| 131 | 8646 | } | |
| 132 | |||
| 133 | 22 | av_cold void ff_apv_dsp_init(APVDSPContext *dsp) | |
| 134 | { | ||
| 135 | 22 | dsp->decode_transquant = apv_decode_transquant_c; | |
| 136 | |||
| 137 | #if ARCH_X86_64 && HAVE_X86ASM | ||
| 138 | 22 | ff_apv_dsp_init_x86_64(dsp); | |
| 139 | #endif | ||
| 140 | 22 | } | |
| 141 |