| 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 "libavutil/attributes.h" | ||
| 22 | #include "libavutil/common.h" | ||
| 23 | #include "config.h" | ||
| 24 | #include "h263dsp.h" | ||
| 25 | |||
| 26 | const uint8_t ff_h263_loop_filter_strength[32] = { | ||
| 27 | 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, | ||
| 28 | 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12 | ||
| 29 | }; | ||
| 30 | |||
| 31 | 1153637 | static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale) | |
| 32 | { | ||
| 33 | int y; | ||
| 34 | 1153637 | const int strength = ff_h263_loop_filter_strength[qscale]; | |
| 35 | |||
| 36 |
2/2✓ Branch 0 taken 9229096 times.
✓ Branch 1 taken 1153637 times.
|
10382733 | for (y = 0; y < 8; y++) { |
| 37 | int d1, d2, ad1; | ||
| 38 | 9229096 | int p0 = src[y * stride - 2]; | |
| 39 | 9229096 | int p1 = src[y * stride - 1]; | |
| 40 | 9229096 | int p2 = src[y * stride + 0]; | |
| 41 | 9229096 | int p3 = src[y * stride + 1]; | |
| 42 | 9229096 | int d = (p0 - p3 + 4 * (p2 - p1)) / 8; | |
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 193324 times.
✓ Branch 1 taken 9035772 times.
|
9229096 | if (d < -2 * strength) |
| 45 | 193324 | d1 = 0; | |
| 46 |
2/2✓ Branch 0 taken 250493 times.
✓ Branch 1 taken 8785279 times.
|
9035772 | else if (d < -strength) |
| 47 | 250493 | d1 = -2 * strength - d; | |
| 48 |
2/2✓ Branch 0 taken 8137917 times.
✓ Branch 1 taken 647362 times.
|
8785279 | else if (d < strength) |
| 49 | 8137917 | d1 = d; | |
| 50 |
2/2✓ Branch 0 taken 386935 times.
✓ Branch 1 taken 260427 times.
|
647362 | else if (d < 2 * strength) |
| 51 | 386935 | d1 = 2 * strength - d; | |
| 52 | else | ||
| 53 | 260427 | d1 = 0; | |
| 54 | |||
| 55 | 9229096 | p1 += d1; | |
| 56 | 9229096 | p2 -= d1; | |
| 57 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 9228938 times.
|
9229096 | if (p1 & 256) |
| 58 | 158 | p1 = ~(p1 >> 31); | |
| 59 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 9229062 times.
|
9229096 | if (p2 & 256) |
| 60 | 34 | p2 = ~(p2 >> 31); | |
| 61 | |||
| 62 | 9229096 | src[y * stride - 1] = p1; | |
| 63 | 9229096 | src[y * stride + 0] = p2; | |
| 64 | |||
| 65 | 9229096 | ad1 = FFABS(d1) >> 1; | |
| 66 | |||
| 67 | 9229096 | d2 = av_clip((p0 - p3) / 4, -ad1, ad1); | |
| 68 | |||
| 69 | 9229096 | src[y * stride - 2] = p0 - d2; | |
| 70 | 9229096 | src[y * stride + 1] = p3 + d2; | |
| 71 | } | ||
| 72 | 1153637 | } | |
| 73 | |||
| 74 | 1165737 | static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale) | |
| 75 | { | ||
| 76 | int x; | ||
| 77 | 1165737 | const int strength = ff_h263_loop_filter_strength[qscale]; | |
| 78 | |||
| 79 |
2/2✓ Branch 0 taken 9325896 times.
✓ Branch 1 taken 1165737 times.
|
10491633 | for (x = 0; x < 8; x++) { |
| 80 | int d1, d2, ad1; | ||
| 81 | 9325896 | int p0 = src[x - 2 * stride]; | |
| 82 | 9325896 | int p1 = src[x - 1 * stride]; | |
| 83 | 9325896 | int p2 = src[x + 0 * stride]; | |
| 84 | 9325896 | int p3 = src[x + 1 * stride]; | |
| 85 | 9325896 | int d = (p0 - p3 + 4 * (p2 - p1)) / 8; | |
| 86 | |||
| 87 |
2/2✓ Branch 0 taken 244701 times.
✓ Branch 1 taken 9081195 times.
|
9325896 | if (d < -2 * strength) |
| 88 | 244701 | d1 = 0; | |
| 89 |
2/2✓ Branch 0 taken 253372 times.
✓ Branch 1 taken 8827823 times.
|
9081195 | else if (d < -strength) |
| 90 | 253372 | d1 = -2 * strength - d; | |
| 91 |
2/2✓ Branch 0 taken 8087169 times.
✓ Branch 1 taken 740654 times.
|
8827823 | else if (d < strength) |
| 92 | 8087169 | d1 = d; | |
| 93 |
2/2✓ Branch 0 taken 439653 times.
✓ Branch 1 taken 301001 times.
|
740654 | else if (d < 2 * strength) |
| 94 | 439653 | d1 = 2 * strength - d; | |
| 95 | else | ||
| 96 | 301001 | d1 = 0; | |
| 97 | |||
| 98 | 9325896 | p1 += d1; | |
| 99 | 9325896 | p2 -= d1; | |
| 100 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 9325822 times.
|
9325896 | if (p1 & 256) |
| 101 | 74 | p1 = ~(p1 >> 31); | |
| 102 |
2/2✓ Branch 0 taken 180 times.
✓ Branch 1 taken 9325716 times.
|
9325896 | if (p2 & 256) |
| 103 | 180 | p2 = ~(p2 >> 31); | |
| 104 | |||
| 105 | 9325896 | src[x - 1 * stride] = p1; | |
| 106 | 9325896 | src[x + 0 * stride] = p2; | |
| 107 | |||
| 108 | 9325896 | ad1 = FFABS(d1) >> 1; | |
| 109 | |||
| 110 | 9325896 | d2 = av_clip((p0 - p3) / 4, -ad1, ad1); | |
| 111 | |||
| 112 | 9325896 | src[x - 2 * stride] = p0 - d2; | |
| 113 | 9325896 | src[x + stride] = p3 + d2; | |
| 114 | } | ||
| 115 | 1165737 | } | |
| 116 | |||
| 117 | 407 | av_cold void ff_h263dsp_init(H263DSPContext *ctx) | |
| 118 | { | ||
| 119 | 407 | ctx->h263_h_loop_filter = h263_h_loop_filter_c; | |
| 120 | 407 | ctx->h263_v_loop_filter = h263_v_loop_filter_c; | |
| 121 | |||
| 122 | #if ARCH_RISCV | ||
| 123 | ff_h263dsp_init_riscv(ctx); | ||
| 124 | #elif ARCH_X86 && HAVE_X86ASM | ||
| 125 | 407 | ff_h263dsp_init_x86(ctx); | |
| 126 | #elif ARCH_MIPS | ||
| 127 | ff_h263dsp_init_mips(ctx); | ||
| 128 | #endif | ||
| 129 | 407 | } | |
| 130 |