| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Lossless video DSP utils | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with FFmpeg; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "config.h" | ||
| 22 | #include "lossless_videodsp.h" | ||
| 23 | #include "libavcodec/mathops.h" | ||
| 24 | #include "libavutil/attributes.h" | ||
| 25 | |||
| 26 | // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size | ||
| 27 | #define pb_7f (~0UL / 255 * 0x7f) | ||
| 28 | #define pb_80 (~0UL / 255 * 0x80) | ||
| 29 | |||
| 30 | 58755 | static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w) | |
| 31 | { | ||
| 32 | long i; | ||
| 33 | |||
| 34 |
2/2✓ Branch 0 taken 3683968 times.
✓ Branch 1 taken 58755 times.
|
3742723 | for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) { |
| 35 | 3683968 | long a = *(long *) (src + i); | |
| 36 | 3683968 | long b = *(long *) (dst + i); | |
| 37 | 3683968 | *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80); | |
| 38 | } | ||
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58755 times.
|
58755 | for (; i < w; i++) |
| 40 | ✗ | dst[i + 0] += src[i + 0]; | |
| 41 | 58755 | } | |
| 42 | |||
| 43 | 52760 | static void add_median_pred_c(uint8_t *dst, const uint8_t *src1, | |
| 44 | const uint8_t *diff, ptrdiff_t w, | ||
| 45 | int *left, int *left_top) | ||
| 46 | { | ||
| 47 | int i; | ||
| 48 | uint8_t l, lt; | ||
| 49 | |||
| 50 | 52760 | l = *left; | |
| 51 | 52760 | lt = *left_top; | |
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 28946994 times.
✓ Branch 1 taken 52760 times.
|
28999754 | for (i = 0; i < w; i++) { |
| 54 | 28946994 | l = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i]; | |
| 55 | 28946994 | lt = src1[i]; | |
| 56 | 28946994 | dst[i] = l; | |
| 57 | } | ||
| 58 | |||
| 59 | 52760 | *left = l; | |
| 60 | 52760 | *left_top = lt; | |
| 61 | 52760 | } | |
| 62 | |||
| 63 | 436946 | static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w, | |
| 64 | int acc) | ||
| 65 | { | ||
| 66 | int i; | ||
| 67 | |||
| 68 |
2/2✓ Branch 0 taken 64530313 times.
✓ Branch 1 taken 436946 times.
|
64967259 | for (i = 0; i < w - 1; i++) { |
| 69 | 64530313 | acc += src[i]; | |
| 70 | 64530313 | dst[i] = acc; | |
| 71 | 64530313 | i++; | |
| 72 | 64530313 | acc += src[i]; | |
| 73 | 64530313 | dst[i] = acc; | |
| 74 | } | ||
| 75 | |||
| 76 |
2/2✓ Branch 0 taken 5516 times.
✓ Branch 1 taken 436946 times.
|
442462 | for (; i < w; i++) { |
| 77 | 5516 | acc += src[i]; | |
| 78 | 5516 | dst[i] = acc; | |
| 79 | } | ||
| 80 | |||
| 81 | 436946 | return acc; | |
| 82 | } | ||
| 83 | |||
| 84 | 359203 | static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){ | |
| 85 | int i; | ||
| 86 | |||
| 87 |
2/2✓ Branch 0 taken 49609172 times.
✓ Branch 1 taken 359203 times.
|
49968375 | for(i=0; i<w-1; i++){ |
| 88 | 49609172 | acc+= src[i]; | |
| 89 | 49609172 | dst[i]= acc &= mask; | |
| 90 | 49609172 | i++; | |
| 91 | 49609172 | acc+= src[i]; | |
| 92 | 49609172 | dst[i]= acc &= mask; | |
| 93 | } | ||
| 94 | |||
| 95 |
2/2✓ Branch 0 taken 5100 times.
✓ Branch 1 taken 359203 times.
|
364303 | for(; i<w; i++){ |
| 96 | 5100 | acc+= src[i]; | |
| 97 | 5100 | dst[i]= acc &= mask; | |
| 98 | } | ||
| 99 | |||
| 100 | 359203 | return acc; | |
| 101 | } | ||
| 102 | |||
| 103 | 46608 | static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){ | |
| 104 | int A, B, C, i; | ||
| 105 | |||
| 106 |
2/2✓ Branch 0 taken 14456184 times.
✓ Branch 1 taken 46608 times.
|
14502792 | for (i = 0; i < width; i++) { |
| 107 | 14456184 | A = src[i - stride]; | |
| 108 | 14456184 | B = src[i - (stride + 1)]; | |
| 109 | 14456184 | C = src[i - 1]; | |
| 110 | 14456184 | src[i] = (A - B + C + src[i]) & 0xFF; | |
| 111 | } | ||
| 112 | 46608 | } | |
| 113 | |||
| 114 | 190 | av_cold void ff_llviddsp_init(LLVidDSPContext *c) | |
| 115 | { | ||
| 116 | 190 | c->add_bytes = add_bytes_c; | |
| 117 | 190 | c->add_median_pred = add_median_pred_c; | |
| 118 | 190 | c->add_left_pred = add_left_pred_c; | |
| 119 | |||
| 120 | 190 | c->add_left_pred_int16 = add_left_pred_int16_c; | |
| 121 | 190 | c->add_gradient_pred = add_gradient_pred_c; | |
| 122 | |||
| 123 | #if ARCH_PPC | ||
| 124 | ff_llviddsp_init_ppc(c); | ||
| 125 | #elif ARCH_RISCV | ||
| 126 | ff_llviddsp_init_riscv(c); | ||
| 127 | #elif ARCH_X86 | ||
| 128 | 190 | ff_llviddsp_init_x86(c); | |
| 129 | #endif | ||
| 130 | 190 | } | |
| 131 |