| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Unquantize functions for mpegvideo | ||
| 3 | * Copyright (c) 2000,2001 Fabrice Bellard | ||
| 4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
| 5 | * | ||
| 6 | * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> | ||
| 7 | * | ||
| 8 | * This file is part of FFmpeg. | ||
| 9 | * | ||
| 10 | * FFmpeg is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU Lesser General Public | ||
| 12 | * License as published by the Free Software Foundation; either | ||
| 13 | * version 2.1 of the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * Lesser General Public License for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU Lesser General Public | ||
| 21 | * License along with FFmpeg; if not, write to the Free Software | ||
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <stdint.h> | ||
| 26 | |||
| 27 | #include "config.h" | ||
| 28 | |||
| 29 | #include "libavutil/attributes.h" | ||
| 30 | #include "libavutil/avassert.h" | ||
| 31 | #include "avcodec.h" | ||
| 32 | #include "mpegvideo.h" | ||
| 33 | #include "mpegvideodata.h" | ||
| 34 | #include "mpegvideo_unquantize.h" | ||
| 35 | |||
| 36 | 5635 | av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st, | |
| 37 | const uint8_t *src_scantable) | ||
| 38 | { | ||
| 39 | 5635 | st->scantable = src_scantable; | |
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 360640 times.
✓ Branch 1 taken 5635 times.
|
366275 | for (int i = 0, end = -1; i < 64; i++) { |
| 42 | 360640 | int j = src_scantable[i]; | |
| 43 | 360640 | st->permutated[i] = permutation[j]; | |
| 44 |
2/2✓ Branch 0 taken 106160 times.
✓ Branch 1 taken 254480 times.
|
360640 | if (permutation[j] > end) |
| 45 | 106160 | end = permutation[j]; | |
| 46 | 360640 | st->raster_end[i] = end; | |
| 47 | } | ||
| 48 | 5635 | } | |
| 49 | |||
| 50 | 126028 | static void dct_unquantize_mpeg1_intra_c(const MPVContext *s, | |
| 51 | int16_t *block, int n, int qscale) | ||
| 52 | { | ||
| 53 | int i, level, nCoeffs; | ||
| 54 | const uint16_t *quant_matrix; | ||
| 55 | |||
| 56 | 126028 | nCoeffs= s->block_last_index[n]; | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 84016 times.
✓ Branch 1 taken 42012 times.
|
126028 | block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; |
| 59 | /* XXX: only MPEG-1 */ | ||
| 60 | 126028 | quant_matrix = s->intra_matrix; | |
| 61 |
2/2✓ Branch 0 taken 2913718 times.
✓ Branch 1 taken 126028 times.
|
3039746 | for(i=1;i<=nCoeffs;i++) { |
| 62 | 2913718 | int j= s->intra_scantable.permutated[i]; | |
| 63 | 2913718 | level = block[j]; | |
| 64 |
2/2✓ Branch 0 taken 1215090 times.
✓ Branch 1 taken 1698628 times.
|
2913718 | if (level) { |
| 65 |
2/2✓ Branch 0 taken 604400 times.
✓ Branch 1 taken 610690 times.
|
1215090 | if (level < 0) { |
| 66 | 604400 | level = -level; | |
| 67 | 604400 | level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 68 | 604400 | level = (level - 1) | 1; | |
| 69 | 604400 | level = -level; | |
| 70 | } else { | ||
| 71 | 610690 | level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 72 | 610690 | level = (level - 1) | 1; | |
| 73 | } | ||
| 74 | 1215090 | block[j] = level; | |
| 75 | } | ||
| 76 | } | ||
| 77 | 126028 | } | |
| 78 | |||
| 79 | 285603 | static void dct_unquantize_mpeg1_inter_c(const MPVContext *s, | |
| 80 | int16_t *block, int n, int qscale) | ||
| 81 | { | ||
| 82 | int i, level, nCoeffs; | ||
| 83 | const uint16_t *quant_matrix; | ||
| 84 | |||
| 85 | 285603 | nCoeffs= s->block_last_index[n]; | |
| 86 | |||
| 87 | 285603 | quant_matrix = s->inter_matrix; | |
| 88 |
2/2✓ Branch 0 taken 9213306 times.
✓ Branch 1 taken 285603 times.
|
9498909 | for(i=0; i<=nCoeffs; i++) { |
| 89 | 9213306 | int j= s->intra_scantable.permutated[i]; | |
| 90 | 9213306 | level = block[j]; | |
| 91 |
2/2✓ Branch 0 taken 2101116 times.
✓ Branch 1 taken 7112190 times.
|
9213306 | if (level) { |
| 92 |
2/2✓ Branch 0 taken 1051984 times.
✓ Branch 1 taken 1049132 times.
|
2101116 | if (level < 0) { |
| 93 | 1051984 | level = -level; | |
| 94 | 1051984 | level = (((level << 1) + 1) * qscale * | |
| 95 | 1051984 | ((int) (quant_matrix[j]))) >> 4; | |
| 96 | 1051984 | level = (level - 1) | 1; | |
| 97 | 1051984 | level = -level; | |
| 98 | } else { | ||
| 99 | 1049132 | level = (((level << 1) + 1) * qscale * | |
| 100 | 1049132 | ((int) (quant_matrix[j]))) >> 4; | |
| 101 | 1049132 | level = (level - 1) | 1; | |
| 102 | } | ||
| 103 | 2101116 | block[j] = level; | |
| 104 | } | ||
| 105 | } | ||
| 106 | 285603 | } | |
| 107 | |||
| 108 | 131268 | static void dct_unquantize_mpeg2_intra_c(const MPVContext *s, | |
| 109 | int16_t *block, int n, int qscale) | ||
| 110 | { | ||
| 111 | int i, level, nCoeffs; | ||
| 112 | const uint16_t *quant_matrix; | ||
| 113 | |||
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 131268 times.
|
131268 | if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; |
| 115 | 131268 | else qscale <<= 1; | |
| 116 | |||
| 117 | 131268 | nCoeffs= s->block_last_index[n]; | |
| 118 | |||
| 119 |
2/2✓ Branch 0 taken 87512 times.
✓ Branch 1 taken 43756 times.
|
131268 | block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; |
| 120 | 131268 | quant_matrix = s->intra_matrix; | |
| 121 |
2/2✓ Branch 0 taken 462435 times.
✓ Branch 1 taken 131268 times.
|
593703 | for(i=1;i<=nCoeffs;i++) { |
| 122 | 462435 | int j= s->intra_scantable.permutated[i]; | |
| 123 | 462435 | level = block[j]; | |
| 124 |
2/2✓ Branch 0 taken 152199 times.
✓ Branch 1 taken 310236 times.
|
462435 | if (level) { |
| 125 |
2/2✓ Branch 0 taken 74700 times.
✓ Branch 1 taken 77499 times.
|
152199 | if (level < 0) { |
| 126 | 74700 | level = -level; | |
| 127 | 74700 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 128 | 74700 | level = -level; | |
| 129 | } else { | ||
| 130 | 77499 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 131 | } | ||
| 132 | 152199 | block[j] = level; | |
| 133 | } | ||
| 134 | } | ||
| 135 | 131268 | } | |
| 136 | |||
| 137 | 1310561 | static void dct_unquantize_mpeg2_intra_bitexact(const MPVContext *s, | |
| 138 | int16_t *block, int n, int qscale) | ||
| 139 | { | ||
| 140 | int i, level, nCoeffs; | ||
| 141 | const uint16_t *quant_matrix; | ||
| 142 | 1310561 | int sum=-1; | |
| 143 | |||
| 144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1310561 times.
|
1310561 | if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; |
| 145 | 1310561 | else qscale <<= 1; | |
| 146 | |||
| 147 | 1310561 | nCoeffs= s->block_last_index[n]; | |
| 148 | |||
| 149 |
2/2✓ Branch 0 taken 822024 times.
✓ Branch 1 taken 488537 times.
|
1310561 | block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; |
| 150 | 1310561 | sum += block[0]; | |
| 151 | 1310561 | quant_matrix = s->intra_matrix; | |
| 152 |
2/2✓ Branch 0 taken 21892877 times.
✓ Branch 1 taken 1310561 times.
|
23203438 | for(i=1;i<=nCoeffs;i++) { |
| 153 | 21892877 | int j= s->intra_scantable.permutated[i]; | |
| 154 | 21892877 | level = block[j]; | |
| 155 |
2/2✓ Branch 0 taken 10763068 times.
✓ Branch 1 taken 11129809 times.
|
21892877 | if (level) { |
| 156 |
2/2✓ Branch 0 taken 5418224 times.
✓ Branch 1 taken 5344844 times.
|
10763068 | if (level < 0) { |
| 157 | 5418224 | level = -level; | |
| 158 | 5418224 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 159 | 5418224 | level = -level; | |
| 160 | } else { | ||
| 161 | 5344844 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 162 | } | ||
| 163 | 10763068 | block[j] = level; | |
| 164 | 10763068 | sum+=level; | |
| 165 | } | ||
| 166 | } | ||
| 167 | 1310561 | block[63]^=sum&1; | |
| 168 | 1310561 | } | |
| 169 | |||
| 170 | 3123068 | static void dct_unquantize_mpeg2_inter_c(const MPVContext *s, | |
| 171 | int16_t *block, int n, int qscale) | ||
| 172 | { | ||
| 173 | int i, level, nCoeffs; | ||
| 174 | const uint16_t *quant_matrix; | ||
| 175 | 3123068 | int sum=-1; | |
| 176 | |||
| 177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3123068 times.
|
3123068 | if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; |
| 178 | 3123068 | else qscale <<= 1; | |
| 179 | |||
| 180 | 3123068 | nCoeffs= s->block_last_index[n]; | |
| 181 | |||
| 182 | 3123068 | quant_matrix = s->inter_matrix; | |
| 183 |
2/2✓ Branch 0 taken 73863820 times.
✓ Branch 1 taken 3123068 times.
|
76986888 | for(i=0; i<=nCoeffs; i++) { |
| 184 | 73863820 | int j= s->intra_scantable.permutated[i]; | |
| 185 | 73863820 | level = block[j]; | |
| 186 |
2/2✓ Branch 0 taken 26449943 times.
✓ Branch 1 taken 47413877 times.
|
73863820 | if (level) { |
| 187 |
2/2✓ Branch 0 taken 13265983 times.
✓ Branch 1 taken 13183960 times.
|
26449943 | if (level < 0) { |
| 188 | 13265983 | level = -level; | |
| 189 | 13265983 | level = (((level << 1) + 1) * qscale * | |
| 190 | 13265983 | ((int) (quant_matrix[j]))) >> 5; | |
| 191 | 13265983 | level = -level; | |
| 192 | } else { | ||
| 193 | 13183960 | level = (((level << 1) + 1) * qscale * | |
| 194 | 13183960 | ((int) (quant_matrix[j]))) >> 5; | |
| 195 | } | ||
| 196 | 26449943 | block[j] = level; | |
| 197 | 26449943 | sum+=level; | |
| 198 | } | ||
| 199 | } | ||
| 200 | 3123068 | block[63]^=sum&1; | |
| 201 | 3123068 | } | |
| 202 | |||
| 203 | 3305902 | static void dct_unquantize_h263_intra_c(const MPVContext *s, | |
| 204 | int16_t *block, int n, int qscale) | ||
| 205 | { | ||
| 206 | int i, level, qmul, qadd; | ||
| 207 | int nCoeffs; | ||
| 208 | |||
| 209 | av_assert2(s->block_last_index[n]>=0 || s->h263_aic); | ||
| 210 | |||
| 211 | 3305902 | qmul = qscale << 1; | |
| 212 | |||
| 213 |
2/2✓ Branch 0 taken 3132702 times.
✓ Branch 1 taken 173200 times.
|
3305902 | if (!s->h263_aic) { |
| 214 |
2/2✓ Branch 0 taken 2088468 times.
✓ Branch 1 taken 1044234 times.
|
3132702 | block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; |
| 215 | 3132702 | qadd = (qscale - 1) | 1; | |
| 216 | }else{ | ||
| 217 | 173200 | qadd = 0; | |
| 218 | } | ||
| 219 |
2/2✓ Branch 0 taken 68304 times.
✓ Branch 1 taken 3237598 times.
|
3305902 | if(s->ac_pred) |
| 220 | 68304 | nCoeffs=63; | |
| 221 | else | ||
| 222 | 3237598 | nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]; | |
| 223 | |||
| 224 |
2/2✓ Branch 0 taken 111824431 times.
✓ Branch 1 taken 3305902 times.
|
115130333 | for(i=1; i<=nCoeffs; i++) { |
| 225 | 111824431 | level = block[i]; | |
| 226 |
2/2✓ Branch 0 taken 35459541 times.
✓ Branch 1 taken 76364890 times.
|
111824431 | if (level) { |
| 227 |
2/2✓ Branch 0 taken 17751613 times.
✓ Branch 1 taken 17707928 times.
|
35459541 | if (level < 0) { |
| 228 | 17751613 | level = level * qmul - qadd; | |
| 229 | } else { | ||
| 230 | 17707928 | level = level * qmul + qadd; | |
| 231 | } | ||
| 232 | 35459541 | block[i] = level; | |
| 233 | } | ||
| 234 | } | ||
| 235 | 3305902 | } | |
| 236 | |||
| 237 | 5774547 | static void dct_unquantize_h263_inter_c(const MPVContext *s, | |
| 238 | int16_t *block, int n, int qscale) | ||
| 239 | { | ||
| 240 | int i, level, qmul, qadd; | ||
| 241 | int nCoeffs; | ||
| 242 | |||
| 243 | av_assert2(s->block_last_index[n]>=0); | ||
| 244 | |||
| 245 | 5774547 | qadd = (qscale - 1) | 1; | |
| 246 | 5774547 | qmul = qscale << 1; | |
| 247 | |||
| 248 | 5774547 | nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; | |
| 249 | |||
| 250 |
2/2✓ Branch 0 taken 221460958 times.
✓ Branch 1 taken 5774547 times.
|
227235505 | for(i=0; i<=nCoeffs; i++) { |
| 251 | 221460958 | level = block[i]; | |
| 252 |
2/2✓ Branch 0 taken 46172961 times.
✓ Branch 1 taken 175287997 times.
|
221460958 | if (level) { |
| 253 |
2/2✓ Branch 0 taken 23009577 times.
✓ Branch 1 taken 23163384 times.
|
46172961 | if (level < 0) { |
| 254 | 23009577 | level = level * qmul - qadd; | |
| 255 | } else { | ||
| 256 | 23163384 | level = level * qmul + qadd; | |
| 257 | } | ||
| 258 | 46172961 | block[i] = level; | |
| 259 | } | ||
| 260 | } | ||
| 261 | 5774547 | } | |
| 262 | |||
| 263 | 775 | av_cold void ff_mpv_unquantize_init(MPVUnquantDSPContext *s, | |
| 264 | int bitexact, int q_scale_type) | ||
| 265 | { | ||
| 266 | 775 | s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; | |
| 267 | 775 | s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; | |
| 268 | 775 | s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c; | |
| 269 | 775 | s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c; | |
| 270 | 775 | s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c; | |
| 271 |
2/2✓ Branch 0 taken 609 times.
✓ Branch 1 taken 166 times.
|
775 | if (bitexact) |
| 272 | 609 | s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact; | |
| 273 | 775 | s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; | |
| 274 | |||
| 275 | #if HAVE_INTRINSICS_NEON | ||
| 276 | ff_mpv_unquantize_init_neon(s, bitexact); | ||
| 277 | #endif | ||
| 278 | |||
| 279 | #if ARCH_ARM | ||
| 280 | ff_mpv_unquantize_init_arm(s, bitexact); | ||
| 281 | #elif ARCH_PPC | ||
| 282 | ff_mpv_unquantize_init_ppc(s, bitexact); | ||
| 283 | #elif ARCH_RISCV | ||
| 284 | ff_mpv_unquantize_init_riscv(s, bitexact); | ||
| 285 | #elif ARCH_X86 | ||
| 286 | 775 | ff_mpv_unquantize_init_x86(s, bitexact); | |
| 287 | #elif ARCH_MIPS | ||
| 288 | ff_mpv_unquantize_init_mips(s, bitexact, q_scale_type); | ||
| 289 | #endif | ||
| 290 | 775 | } | |
| 291 |