| 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 "config.h" | ||
| 20 | #include "config_components.h" | ||
| 21 | #include "libavutil/attributes.h" | ||
| 22 | #include "libavutil/common.h" | ||
| 23 | #include "avcodec.h" | ||
| 24 | #include "dct.h" | ||
| 25 | #include "faanidct.h" | ||
| 26 | #include "idctdsp.h" | ||
| 27 | #include "simple_idct.h" | ||
| 28 | #include "xvididct.h" | ||
| 29 | |||
| 30 | 16767 | av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], | |
| 31 | const uint8_t permutation[64]) | ||
| 32 | { | ||
| 33 |
2/2✓ Branch 0 taken 1073088 times.
✓ Branch 1 taken 16767 times.
|
1089855 | for (int i = 0; i < 64; i++) { |
| 34 | 1073088 | int j = src[i]; | |
| 35 | 1073088 | dst[i] = permutation[j]; | |
| 36 | } | ||
| 37 | 16767 | } | |
| 38 | |||
| 39 | 1719 | av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation, | |
| 40 | enum idct_permutation_type perm_type) | ||
| 41 | { | ||
| 42 | int i; | ||
| 43 | |||
| 44 | #if ARCH_X86 | ||
| 45 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1717 times.
|
1719 | if (ff_init_scantable_permutation_x86(idct_permutation, |
| 46 | perm_type)) | ||
| 47 | 2 | return; | |
| 48 | #endif | ||
| 49 | |||
| 50 |
3/5✓ Branch 0 taken 1451 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 262 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1717 | switch (perm_type) { |
| 51 | 1451 | case FF_IDCT_PERM_NONE: | |
| 52 |
2/2✓ Branch 0 taken 92864 times.
✓ Branch 1 taken 1451 times.
|
94315 | for (i = 0; i < 64; i++) |
| 53 | 92864 | idct_permutation[i] = i; | |
| 54 | 1451 | break; | |
| 55 | 4 | case FF_IDCT_PERM_LIBMPEG2: | |
| 56 |
2/2✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
|
260 | for (i = 0; i < 64; i++) |
| 57 | 256 | idct_permutation[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); | |
| 58 | 4 | break; | |
| 59 | 262 | case FF_IDCT_PERM_TRANSPOSE: | |
| 60 |
2/2✓ Branch 0 taken 16768 times.
✓ Branch 1 taken 262 times.
|
17030 | for (i = 0; i < 64; i++) |
| 61 | 16768 | idct_permutation[i] = ((i & 7) << 3) | (i >> 3); | |
| 62 | 262 | break; | |
| 63 | ✗ | case FF_IDCT_PERM_PARTTRANS: | |
| 64 | ✗ | for (i = 0; i < 64; i++) | |
| 65 | ✗ | idct_permutation[i] = (i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3); | |
| 66 | ✗ | break; | |
| 67 | ✗ | default: | |
| 68 | ✗ | av_log(NULL, AV_LOG_ERROR, | |
| 69 | "Internal error, IDCT permutation not set\n"); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | 163833 | void ff_put_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels, | |
| 74 | ptrdiff_t line_size) | ||
| 75 | { | ||
| 76 | int i; | ||
| 77 | |||
| 78 | /* read the pixels */ | ||
| 79 |
2/2✓ Branch 0 taken 1310664 times.
✓ Branch 1 taken 163833 times.
|
1474497 | for (i = 0; i < 8; i++) { |
| 80 | 1310664 | pixels[0] = av_clip_uint8(block[0]); | |
| 81 | 1310664 | pixels[1] = av_clip_uint8(block[1]); | |
| 82 | 1310664 | pixels[2] = av_clip_uint8(block[2]); | |
| 83 | 1310664 | pixels[3] = av_clip_uint8(block[3]); | |
| 84 | 1310664 | pixels[4] = av_clip_uint8(block[4]); | |
| 85 | 1310664 | pixels[5] = av_clip_uint8(block[5]); | |
| 86 | 1310664 | pixels[6] = av_clip_uint8(block[6]); | |
| 87 | 1310664 | pixels[7] = av_clip_uint8(block[7]); | |
| 88 | |||
| 89 | 1310664 | pixels += line_size; | |
| 90 | 1310664 | block += 8; | |
| 91 | } | ||
| 92 | 163833 | } | |
| 93 | |||
| 94 | 14262 | static void put_pixels_clamped4_c(const int16_t *block, uint8_t *restrict pixels, | |
| 95 | int line_size) | ||
| 96 | { | ||
| 97 | int i; | ||
| 98 | |||
| 99 | /* read the pixels */ | ||
| 100 |
2/2✓ Branch 0 taken 57048 times.
✓ Branch 1 taken 14262 times.
|
71310 | for(i=0;i<4;i++) { |
| 101 | 57048 | pixels[0] = av_clip_uint8(block[0]); | |
| 102 | 57048 | pixels[1] = av_clip_uint8(block[1]); | |
| 103 | 57048 | pixels[2] = av_clip_uint8(block[2]); | |
| 104 | 57048 | pixels[3] = av_clip_uint8(block[3]); | |
| 105 | |||
| 106 | 57048 | pixels += line_size; | |
| 107 | 57048 | block += 8; | |
| 108 | } | ||
| 109 | 14262 | } | |
| 110 | |||
| 111 | ✗ | static void put_pixels_clamped2_c(const int16_t *block, uint8_t *restrict pixels, | |
| 112 | int line_size) | ||
| 113 | { | ||
| 114 | int i; | ||
| 115 | |||
| 116 | /* read the pixels */ | ||
| 117 | ✗ | for(i=0;i<2;i++) { | |
| 118 | ✗ | pixels[0] = av_clip_uint8(block[0]); | |
| 119 | ✗ | pixels[1] = av_clip_uint8(block[1]); | |
| 120 | |||
| 121 | ✗ | pixels += line_size; | |
| 122 | ✗ | block += 8; | |
| 123 | } | ||
| 124 | ✗ | } | |
| 125 | |||
| 126 | 1102033 | static void put_signed_pixels_clamped_c(const int16_t *block, | |
| 127 | uint8_t *restrict pixels, | ||
| 128 | ptrdiff_t line_size) | ||
| 129 | { | ||
| 130 | int i, j; | ||
| 131 | |||
| 132 |
2/2✓ Branch 0 taken 8816264 times.
✓ Branch 1 taken 1102033 times.
|
9918297 | for (i = 0; i < 8; i++) { |
| 133 |
2/2✓ Branch 0 taken 70530112 times.
✓ Branch 1 taken 8816264 times.
|
79346376 | for (j = 0; j < 8; j++) { |
| 134 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 70529995 times.
|
70530112 | if (*block < -128) |
| 135 | 117 | *pixels = 0; | |
| 136 |
2/2✓ Branch 0 taken 44013 times.
✓ Branch 1 taken 70485982 times.
|
70529995 | else if (*block > 127) |
| 137 | 44013 | *pixels = 255; | |
| 138 | else | ||
| 139 | 70485982 | *pixels = (uint8_t) (*block + 128); | |
| 140 | 70530112 | block++; | |
| 141 | 70530112 | pixels++; | |
| 142 | } | ||
| 143 | 8816264 | pixels += (line_size - 8); | |
| 144 | } | ||
| 145 | 1102033 | } | |
| 146 | |||
| 147 | 452108 | void ff_add_pixels_clamped_c(const int16_t *block, uint8_t *restrict pixels, | |
| 148 | ptrdiff_t line_size) | ||
| 149 | { | ||
| 150 | int i; | ||
| 151 | |||
| 152 | /* read the pixels */ | ||
| 153 |
2/2✓ Branch 0 taken 3616864 times.
✓ Branch 1 taken 452108 times.
|
4068972 | for (i = 0; i < 8; i++) { |
| 154 | 3616864 | pixels[0] = av_clip_uint8(pixels[0] + block[0]); | |
| 155 | 3616864 | pixels[1] = av_clip_uint8(pixels[1] + block[1]); | |
| 156 | 3616864 | pixels[2] = av_clip_uint8(pixels[2] + block[2]); | |
| 157 | 3616864 | pixels[3] = av_clip_uint8(pixels[3] + block[3]); | |
| 158 | 3616864 | pixels[4] = av_clip_uint8(pixels[4] + block[4]); | |
| 159 | 3616864 | pixels[5] = av_clip_uint8(pixels[5] + block[5]); | |
| 160 | 3616864 | pixels[6] = av_clip_uint8(pixels[6] + block[6]); | |
| 161 | 3616864 | pixels[7] = av_clip_uint8(pixels[7] + block[7]); | |
| 162 | 3616864 | pixels += line_size; | |
| 163 | 3616864 | block += 8; | |
| 164 | } | ||
| 165 | 452108 | } | |
| 166 | |||
| 167 | 73763 | static void add_pixels_clamped4_c(const int16_t *block, uint8_t *restrict pixels, | |
| 168 | int line_size) | ||
| 169 | { | ||
| 170 | int i; | ||
| 171 | |||
| 172 | /* read the pixels */ | ||
| 173 |
2/2✓ Branch 0 taken 295052 times.
✓ Branch 1 taken 73763 times.
|
368815 | for(i=0;i<4;i++) { |
| 174 | 295052 | pixels[0] = av_clip_uint8(pixels[0] + block[0]); | |
| 175 | 295052 | pixels[1] = av_clip_uint8(pixels[1] + block[1]); | |
| 176 | 295052 | pixels[2] = av_clip_uint8(pixels[2] + block[2]); | |
| 177 | 295052 | pixels[3] = av_clip_uint8(pixels[3] + block[3]); | |
| 178 | 295052 | pixels += line_size; | |
| 179 | 295052 | block += 8; | |
| 180 | } | ||
| 181 | 73763 | } | |
| 182 | |||
| 183 | ✗ | static void add_pixels_clamped2_c(const int16_t *block, uint8_t *restrict pixels, | |
| 184 | int line_size) | ||
| 185 | { | ||
| 186 | int i; | ||
| 187 | |||
| 188 | /* read the pixels */ | ||
| 189 | ✗ | for(i=0;i<2;i++) { | |
| 190 | ✗ | pixels[0] = av_clip_uint8(pixels[0] + block[0]); | |
| 191 | ✗ | pixels[1] = av_clip_uint8(pixels[1] + block[1]); | |
| 192 | ✗ | pixels += line_size; | |
| 193 | ✗ | block += 8; | |
| 194 | } | ||
| 195 | ✗ | } | |
| 196 | |||
| 197 | 14262 | static void ff_jref_idct4_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block) | |
| 198 | { | ||
| 199 | 14262 | ff_j_rev_dct4 (block); | |
| 200 | 14262 | put_pixels_clamped4_c(block, dest, line_size); | |
| 201 | 14262 | } | |
| 202 | 73763 | static void ff_jref_idct4_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block) | |
| 203 | { | ||
| 204 | 73763 | ff_j_rev_dct4 (block); | |
| 205 | 73763 | add_pixels_clamped4_c(block, dest, line_size); | |
| 206 | 73763 | } | |
| 207 | |||
| 208 | ✗ | static void ff_jref_idct2_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block) | |
| 209 | { | ||
| 210 | ✗ | ff_j_rev_dct2 (block); | |
| 211 | ✗ | put_pixels_clamped2_c(block, dest, line_size); | |
| 212 | ✗ | } | |
| 213 | ✗ | static void ff_jref_idct2_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block) | |
| 214 | { | ||
| 215 | ✗ | ff_j_rev_dct2 (block); | |
| 216 | ✗ | add_pixels_clamped2_c(block, dest, line_size); | |
| 217 | ✗ | } | |
| 218 | |||
| 219 | ✗ | static void ff_jref_idct1_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block) | |
| 220 | { | ||
| 221 | ✗ | dest[0] = av_clip_uint8((block[0] + 4)>>3); | |
| 222 | ✗ | } | |
| 223 | ✗ | static void ff_jref_idct1_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block) | |
| 224 | { | ||
| 225 | ✗ | dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3)); | |
| 226 | ✗ | } | |
| 227 | |||
| 228 | 1575 | av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx) | |
| 229 | { | ||
| 230 | 1575 | av_unused const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8; | |
| 231 | |||
| 232 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1574 times.
|
1575 | if (avctx->lowres==1) { |
| 233 | 1 | c->idct_put = ff_jref_idct4_put; | |
| 234 | 1 | c->idct_add = ff_jref_idct4_add; | |
| 235 | 1 | c->idct = ff_j_rev_dct4; | |
| 236 | 1 | c->perm_type = FF_IDCT_PERM_NONE; | |
| 237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1574 times.
|
1574 | } else if (avctx->lowres==2) { |
| 238 | ✗ | c->idct_put = ff_jref_idct2_put; | |
| 239 | ✗ | c->idct_add = ff_jref_idct2_add; | |
| 240 | ✗ | c->idct = ff_j_rev_dct2; | |
| 241 | ✗ | c->perm_type = FF_IDCT_PERM_NONE; | |
| 242 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1574 times.
|
1574 | } else if (avctx->lowres==3) { |
| 243 | ✗ | c->idct_put = ff_jref_idct1_put; | |
| 244 | ✗ | c->idct_add = ff_jref_idct1_add; | |
| 245 | ✗ | c->idct = ff_j_rev_dct1; | |
| 246 | ✗ | c->perm_type = FF_IDCT_PERM_NONE; | |
| 247 | } else { | ||
| 248 |
3/4✓ Branch 0 taken 1549 times.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1549 times.
|
1574 | if (avctx->bits_per_raw_sample == 10 || avctx->bits_per_raw_sample == 9) { |
| 249 | /* 10-bit MPEG-4 Simple Studio Profile requires a higher precision IDCT | ||
| 250 | However, it only uses idct_put */ | ||
| 251 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
|
25 | if (c->mpeg4_studio_profile) { |
| 252 | 1 | c->idct_put = ff_simple_idct_put_int32_10bit; | |
| 253 | 1 | c->idct_add = NULL; | |
| 254 | 1 | c->idct = NULL; | |
| 255 | } else { | ||
| 256 | 24 | c->idct_put = ff_simple_idct_put_int16_10bit; | |
| 257 | 24 | c->idct_add = ff_simple_idct_add_int16_10bit; | |
| 258 | 24 | c->idct = ff_simple_idct_int16_10bit; | |
| 259 | } | ||
| 260 | 25 | c->perm_type = FF_IDCT_PERM_NONE; | |
| 261 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1545 times.
|
1549 | } else if (avctx->bits_per_raw_sample == 12) { |
| 262 | 4 | c->idct_put = ff_simple_idct_put_int16_12bit; | |
| 263 | 4 | c->idct_add = ff_simple_idct_add_int16_12bit; | |
| 264 | 4 | c->idct = ff_simple_idct_int16_12bit; | |
| 265 | 4 | c->perm_type = FF_IDCT_PERM_NONE; | |
| 266 | } else { | ||
| 267 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1541 times.
|
1545 | if (avctx->idct_algo == FF_IDCT_INT) { |
| 268 | 4 | c->idct_put = ff_jref_idct_put; | |
| 269 | 4 | c->idct_add = ff_jref_idct_add; | |
| 270 | 4 | c->idct = ff_j_rev_dct; | |
| 271 | 4 | c->perm_type = FF_IDCT_PERM_LIBMPEG2; | |
| 272 | #if CONFIG_FAANIDCT | ||
| 273 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1541 times.
|
1541 | } else if (avctx->idct_algo == FF_IDCT_FAAN) { |
| 274 | ✗ | c->idct_put = ff_faanidct_put; | |
| 275 | ✗ | c->idct_add = ff_faanidct_add; | |
| 276 | ✗ | c->idct = ff_faanidct; | |
| 277 | ✗ | c->perm_type = FF_IDCT_PERM_NONE; | |
| 278 | #endif /* CONFIG_FAANIDCT */ | ||
| 279 | #if CONFIG_MPEG4_DECODER | ||
| 280 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1537 times.
|
1541 | } else if (avctx->idct_algo == FF_IDCT_XVID) { |
| 281 | 4 | ff_xvid_idct_init(c); | |
| 282 | #endif | ||
| 283 | } else { // accurate/default | ||
| 284 | 1537 | c->idct_put = ff_simple_idct_put_int16_8bit; | |
| 285 | 1537 | c->idct_add = ff_simple_idct_add_int16_8bit; | |
| 286 | 1537 | c->idct = ff_simple_idct_int16_8bit; | |
| 287 | 1537 | c->perm_type = FF_IDCT_PERM_NONE; | |
| 288 | } | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | 1575 | c->put_pixels_clamped = ff_put_pixels_clamped_c; | |
| 293 | 1575 | c->put_signed_pixels_clamped = put_signed_pixels_clamped_c; | |
| 294 | 1575 | c->add_pixels_clamped = ff_add_pixels_clamped_c; | |
| 295 | |||
| 296 | #if ARCH_AARCH64 | ||
| 297 | ff_idctdsp_init_aarch64(c, avctx, high_bit_depth); | ||
| 298 | #elif ARCH_ARM | ||
| 299 | ff_idctdsp_init_arm(c, avctx, high_bit_depth); | ||
| 300 | #elif ARCH_PPC | ||
| 301 | ff_idctdsp_init_ppc(c, avctx, high_bit_depth); | ||
| 302 | #elif ARCH_RISCV | ||
| 303 | ff_idctdsp_init_riscv(c, avctx, high_bit_depth); | ||
| 304 | #elif ARCH_X86 | ||
| 305 | 1575 | ff_idctdsp_init_x86(c, avctx, high_bit_depth); | |
| 306 | #elif ARCH_MIPS | ||
| 307 | ff_idctdsp_init_mips(c, avctx, high_bit_depth); | ||
| 308 | #elif ARCH_LOONGARCH | ||
| 309 | ff_idctdsp_init_loongarch(c, avctx, high_bit_depth); | ||
| 310 | #endif | ||
| 311 | |||
| 312 | 1575 | ff_init_scantable_permutation(c->idct_permutation, | |
| 313 | c->perm_type); | ||
| 314 | 1575 | } | |
| 315 |