| 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 | 126024 | static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, | |
| 37 | int16_t *block, int n, int qscale) | ||
| 38 | { | ||
| 39 | int i, level, nCoeffs; | ||
| 40 | const uint16_t *quant_matrix; | ||
| 41 | |||
| 42 | 126024 | nCoeffs= s->block_last_index[n]; | |
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 84016 times.
✓ Branch 1 taken 42008 times.
|
126024 | block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; |
| 45 | /* XXX: only MPEG-1 */ | ||
| 46 | 126024 | quant_matrix = s->intra_matrix; | |
| 47 |
2/2✓ Branch 0 taken 2913490 times.
✓ Branch 1 taken 126024 times.
|
3039514 | for(i=1;i<=nCoeffs;i++) { |
| 48 | 2913490 | int j= s->intra_scantable.permutated[i]; | |
| 49 | 2913490 | level = block[j]; | |
| 50 |
2/2✓ Branch 0 taken 1214954 times.
✓ Branch 1 taken 1698536 times.
|
2913490 | if (level) { |
| 51 |
2/2✓ Branch 0 taken 604308 times.
✓ Branch 1 taken 610646 times.
|
1214954 | if (level < 0) { |
| 52 | 604308 | level = -level; | |
| 53 | 604308 | level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 54 | 604308 | level = (level - 1) | 1; | |
| 55 | 604308 | level = -level; | |
| 56 | } else { | ||
| 57 | 610646 | level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 58 | 610646 | level = (level - 1) | 1; | |
| 59 | } | ||
| 60 | 1214954 | block[j] = level; | |
| 61 | } | ||
| 62 | } | ||
| 63 | 126024 | } | |
| 64 | |||
| 65 | 285599 | static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, | |
| 66 | int16_t *block, int n, int qscale) | ||
| 67 | { | ||
| 68 | int i, level, nCoeffs; | ||
| 69 | const uint16_t *quant_matrix; | ||
| 70 | |||
| 71 | 285599 | nCoeffs= s->block_last_index[n]; | |
| 72 | |||
| 73 | 285599 | quant_matrix = s->inter_matrix; | |
| 74 |
2/2✓ Branch 0 taken 9213074 times.
✓ Branch 1 taken 285599 times.
|
9498673 | for(i=0; i<=nCoeffs; i++) { |
| 75 | 9213074 | int j= s->intra_scantable.permutated[i]; | |
| 76 | 9213074 | level = block[j]; | |
| 77 |
2/2✓ Branch 0 taken 2100996 times.
✓ Branch 1 taken 7112078 times.
|
9213074 | if (level) { |
| 78 |
2/2✓ Branch 0 taken 1051940 times.
✓ Branch 1 taken 1049056 times.
|
2100996 | if (level < 0) { |
| 79 | 1051940 | level = -level; | |
| 80 | 1051940 | level = (((level << 1) + 1) * qscale * | |
| 81 | 1051940 | ((int) (quant_matrix[j]))) >> 4; | |
| 82 | 1051940 | level = (level - 1) | 1; | |
| 83 | 1051940 | level = -level; | |
| 84 | } else { | ||
| 85 | 1049056 | level = (((level << 1) + 1) * qscale * | |
| 86 | 1049056 | ((int) (quant_matrix[j]))) >> 4; | |
| 87 | 1049056 | level = (level - 1) | 1; | |
| 88 | } | ||
| 89 | 2100996 | block[j] = level; | |
| 90 | } | ||
| 91 | } | ||
| 92 | 285599 | } | |
| 93 | |||
| 94 | 131268 | static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, | |
| 95 | int16_t *block, int n, int qscale) | ||
| 96 | { | ||
| 97 | int i, level, nCoeffs; | ||
| 98 | const uint16_t *quant_matrix; | ||
| 99 | |||
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 131268 times.
|
131268 | if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; |
| 101 | 131268 | else qscale <<= 1; | |
| 102 | |||
| 103 | 131268 | nCoeffs= s->block_last_index[n]; | |
| 104 | |||
| 105 |
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; |
| 106 | 131268 | quant_matrix = s->intra_matrix; | |
| 107 |
2/2✓ Branch 0 taken 462435 times.
✓ Branch 1 taken 131268 times.
|
593703 | for(i=1;i<=nCoeffs;i++) { |
| 108 | 462435 | int j= s->intra_scantable.permutated[i]; | |
| 109 | 462435 | level = block[j]; | |
| 110 |
2/2✓ Branch 0 taken 152199 times.
✓ Branch 1 taken 310236 times.
|
462435 | if (level) { |
| 111 |
2/2✓ Branch 0 taken 74700 times.
✓ Branch 1 taken 77499 times.
|
152199 | if (level < 0) { |
| 112 | 74700 | level = -level; | |
| 113 | 74700 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 114 | 74700 | level = -level; | |
| 115 | } else { | ||
| 116 | 77499 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 117 | } | ||
| 118 | 152199 | block[j] = level; | |
| 119 | } | ||
| 120 | } | ||
| 121 | 131268 | } | |
| 122 | |||
| 123 | 1267406 | static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, | |
| 124 | int16_t *block, int n, int qscale) | ||
| 125 | { | ||
| 126 | int i, level, nCoeffs; | ||
| 127 | const uint16_t *quant_matrix; | ||
| 128 | 1267406 | int sum=-1; | |
| 129 | |||
| 130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1267406 times.
|
1267406 | if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; |
| 131 | 1267406 | else qscale <<= 1; | |
| 132 | |||
| 133 | 1267406 | nCoeffs= s->block_last_index[n]; | |
| 134 | |||
| 135 |
2/2✓ Branch 0 taken 793256 times.
✓ Branch 1 taken 474150 times.
|
1267406 | block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; |
| 136 | 1267406 | sum += block[0]; | |
| 137 | 1267406 | quant_matrix = s->intra_matrix; | |
| 138 |
2/2✓ Branch 0 taken 21672238 times.
✓ Branch 1 taken 1267406 times.
|
22939644 | for(i=1;i<=nCoeffs;i++) { |
| 139 | 21672238 | int j= s->intra_scantable.permutated[i]; | |
| 140 | 21672238 | level = block[j]; | |
| 141 |
2/2✓ Branch 0 taken 10640425 times.
✓ Branch 1 taken 11031813 times.
|
21672238 | if (level) { |
| 142 |
2/2✓ Branch 0 taken 5352342 times.
✓ Branch 1 taken 5288083 times.
|
10640425 | if (level < 0) { |
| 143 | 5352342 | level = -level; | |
| 144 | 5352342 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 145 | 5352342 | level = -level; | |
| 146 | } else { | ||
| 147 | 5288083 | level = (int)(level * qscale * quant_matrix[j]) >> 4; | |
| 148 | } | ||
| 149 | 10640425 | block[j] = level; | |
| 150 | 10640425 | sum+=level; | |
| 151 | } | ||
| 152 | } | ||
| 153 | 1267406 | block[63]^=sum&1; | |
| 154 | 1267406 | } | |
| 155 | |||
| 156 | 3083297 | static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, | |
| 157 | int16_t *block, int n, int qscale) | ||
| 158 | { | ||
| 159 | int i, level, nCoeffs; | ||
| 160 | const uint16_t *quant_matrix; | ||
| 161 | 3083297 | int sum=-1; | |
| 162 | |||
| 163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3083297 times.
|
3083297 | if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; |
| 164 | 3083297 | else qscale <<= 1; | |
| 165 | |||
| 166 | 3083297 | nCoeffs= s->block_last_index[n]; | |
| 167 | |||
| 168 | 3083297 | quant_matrix = s->inter_matrix; | |
| 169 |
2/2✓ Branch 0 taken 72796401 times.
✓ Branch 1 taken 3083297 times.
|
75879698 | for(i=0; i<=nCoeffs; i++) { |
| 170 | 72796401 | int j= s->intra_scantable.permutated[i]; | |
| 171 | 72796401 | level = block[j]; | |
| 172 |
2/2✓ Branch 0 taken 26322458 times.
✓ Branch 1 taken 46473943 times.
|
72796401 | if (level) { |
| 173 |
2/2✓ Branch 0 taken 13200549 times.
✓ Branch 1 taken 13121909 times.
|
26322458 | if (level < 0) { |
| 174 | 13200549 | level = -level; | |
| 175 | 13200549 | level = (((level << 1) + 1) * qscale * | |
| 176 | 13200549 | ((int) (quant_matrix[j]))) >> 5; | |
| 177 | 13200549 | level = -level; | |
| 178 | } else { | ||
| 179 | 13121909 | level = (((level << 1) + 1) * qscale * | |
| 180 | 13121909 | ((int) (quant_matrix[j]))) >> 5; | |
| 181 | } | ||
| 182 | 26322458 | block[j] = level; | |
| 183 | 26322458 | sum+=level; | |
| 184 | } | ||
| 185 | } | ||
| 186 | 3083297 | block[63]^=sum&1; | |
| 187 | 3083297 | } | |
| 188 | |||
| 189 | 3308544 | static void dct_unquantize_h263_intra_c(MpegEncContext *s, | |
| 190 | int16_t *block, int n, int qscale) | ||
| 191 | { | ||
| 192 | int i, level, qmul, qadd; | ||
| 193 | int nCoeffs; | ||
| 194 | |||
| 195 | av_assert2(s->block_last_index[n]>=0 || s->h263_aic); | ||
| 196 | |||
| 197 | 3308544 | qmul = qscale << 1; | |
| 198 | |||
| 199 |
2/2✓ Branch 0 taken 3135348 times.
✓ Branch 1 taken 173196 times.
|
3308544 | if (!s->h263_aic) { |
| 200 |
2/2✓ Branch 0 taken 2090232 times.
✓ Branch 1 taken 1045116 times.
|
3135348 | block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; |
| 201 | 3135348 | qadd = (qscale - 1) | 1; | |
| 202 | }else{ | ||
| 203 | 173196 | qadd = 0; | |
| 204 | } | ||
| 205 |
2/2✓ Branch 0 taken 68304 times.
✓ Branch 1 taken 3240240 times.
|
3308544 | if(s->ac_pred) |
| 206 | 68304 | nCoeffs=63; | |
| 207 | else | ||
| 208 | 3240240 | nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]; | |
| 209 | |||
| 210 |
2/2✓ Branch 0 taken 111855579 times.
✓ Branch 1 taken 3308544 times.
|
115164123 | for(i=1; i<=nCoeffs; i++) { |
| 211 | 111855579 | level = block[i]; | |
| 212 |
2/2✓ Branch 0 taken 35463766 times.
✓ Branch 1 taken 76391813 times.
|
111855579 | if (level) { |
| 213 |
2/2✓ Branch 0 taken 17754986 times.
✓ Branch 1 taken 17708780 times.
|
35463766 | if (level < 0) { |
| 214 | 17754986 | level = level * qmul - qadd; | |
| 215 | } else { | ||
| 216 | 17708780 | level = level * qmul + qadd; | |
| 217 | } | ||
| 218 | 35463766 | block[i] = level; | |
| 219 | } | ||
| 220 | } | ||
| 221 | 3308544 | } | |
| 222 | |||
| 223 | 5789701 | static void dct_unquantize_h263_inter_c(MpegEncContext *s, | |
| 224 | int16_t *block, int n, int qscale) | ||
| 225 | { | ||
| 226 | int i, level, qmul, qadd; | ||
| 227 | int nCoeffs; | ||
| 228 | |||
| 229 | av_assert2(s->block_last_index[n]>=0); | ||
| 230 | |||
| 231 | 5789701 | qadd = (qscale - 1) | 1; | |
| 232 | 5789701 | qmul = qscale << 1; | |
| 233 | |||
| 234 | 5789701 | nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; | |
| 235 | |||
| 236 |
2/2✓ Branch 0 taken 222003125 times.
✓ Branch 1 taken 5789701 times.
|
227792826 | for(i=0; i<=nCoeffs; i++) { |
| 237 | 222003125 | level = block[i]; | |
| 238 |
2/2✓ Branch 0 taken 46310047 times.
✓ Branch 1 taken 175693078 times.
|
222003125 | if (level) { |
| 239 |
2/2✓ Branch 0 taken 23077395 times.
✓ Branch 1 taken 23232652 times.
|
46310047 | if (level < 0) { |
| 240 | 23077395 | level = level * qmul - qadd; | |
| 241 | } else { | ||
| 242 | 23232652 | level = level * qmul + qadd; | |
| 243 | } | ||
| 244 | 46310047 | block[i] = level; | |
| 245 | } | ||
| 246 | } | ||
| 247 | 5789701 | } | |
| 248 | |||
| 249 | 681 | av_cold void ff_mpv_unquantize_init(MPVUnquantDSPContext *s, | |
| 250 | int bitexact, int q_scale_type) | ||
| 251 | { | ||
| 252 | 681 | s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; | |
| 253 | 681 | s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; | |
| 254 | 681 | s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c; | |
| 255 | 681 | s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c; | |
| 256 | 681 | s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c; | |
| 257 |
2/2✓ Branch 0 taken 569 times.
✓ Branch 1 taken 112 times.
|
681 | if (bitexact) |
| 258 | 569 | s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact; | |
| 259 | 681 | s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; | |
| 260 | |||
| 261 | #if HAVE_INTRINSICS_NEON | ||
| 262 | ff_mpv_unquantize_init_neon(s, bitexact); | ||
| 263 | #endif | ||
| 264 | |||
| 265 | #if ARCH_ARM | ||
| 266 | ff_mpv_unquantize_init_arm(s, bitexact); | ||
| 267 | #elif ARCH_PPC | ||
| 268 | ff_mpv_unquantize_init_ppc(s, bitexact); | ||
| 269 | #elif ARCH_X86 | ||
| 270 | 681 | ff_mpv_unquantize_init_x86(s, bitexact); | |
| 271 | #elif ARCH_MIPS | ||
| 272 | ff_mpv_unquantize_init_mips(s, bitexact, q_scale_type); | ||
| 273 | #endif | ||
| 274 | 681 | } | |
| 275 |