| 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 "libavutil/attributes.h" | ||
| 21 | #include "libavutil/intreadwrite.h" | ||
| 22 | #include "lossless_videoencdsp.h" | ||
| 23 | #include "mathops.h" | ||
| 24 | |||
| 25 | #if HAVE_FAST_64BIT | ||
| 26 | typedef uint64_t uint_native; | ||
| 27 | #define READ AV_RN64 | ||
| 28 | #define WRITE AV_WN64 | ||
| 29 | #else | ||
| 30 | typedef uint32_t uint_native; | ||
| 31 | #define READ AV_RN32 | ||
| 32 | #define WRITE AV_WN32 | ||
| 33 | #endif | ||
| 34 | // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size | ||
| 35 | #define pb_7f (~(uint_native)0 / 255 * 0x7f) | ||
| 36 | #define pb_80 (~(uint_native)0 / 255 * 0x80) | ||
| 37 | |||
| 38 | 473035 | static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w) | |
| 39 | { | ||
| 40 | long i; | ||
| 41 | |||
| 42 | #if !HAVE_FAST_UNALIGNED | ||
| 43 | if (((uintptr_t)src1 | (uintptr_t)src2) & (sizeof(uint_native) - 1)) { | ||
| 44 | for (i = 0; i + 7 < w; i += 8) { | ||
| 45 | dst[i + 0] = src1[i + 0] - src2[i + 0]; | ||
| 46 | dst[i + 1] = src1[i + 1] - src2[i + 1]; | ||
| 47 | dst[i + 2] = src1[i + 2] - src2[i + 2]; | ||
| 48 | dst[i + 3] = src1[i + 3] - src2[i + 3]; | ||
| 49 | dst[i + 4] = src1[i + 4] - src2[i + 4]; | ||
| 50 | dst[i + 5] = src1[i + 5] - src2[i + 5]; | ||
| 51 | dst[i + 6] = src1[i + 6] - src2[i + 6]; | ||
| 52 | dst[i + 7] = src1[i + 7] - src2[i + 7]; | ||
| 53 | } | ||
| 54 | } else | ||
| 55 | #endif | ||
| 56 |
2/2✓ Branch 0 taken 25182031 times.
✓ Branch 1 taken 473035 times.
|
25655066 | for (i = 0; i <= w - (int) sizeof(uint_native); i += sizeof(uint_native)) { |
| 57 | 25182031 | uint_native a = READ(src1 + i); | |
| 58 | 25182031 | uint_native b = READ(src2 + i); | |
| 59 | 25182031 | WRITE(dst + i, ((a | pb_80) - (b & pb_7f)) ^ ((a ^ b ^ pb_80) & pb_80)); | |
| 60 | } | ||
| 61 |
2/2✓ Branch 0 taken 28950 times.
✓ Branch 1 taken 473035 times.
|
501985 | for (; i < w; i++) |
| 62 | 28950 | dst[i + 0] = src1[i + 0] - src2[i + 0]; | |
| 63 | 473035 | } | |
| 64 | |||
| 65 | 220150 | static void sub_median_pred_c(uint8_t *dst, const uint8_t *src1, | |
| 66 | const uint8_t *src2, intptr_t w, | ||
| 67 | int *left, int *left_top) | ||
| 68 | { | ||
| 69 | int i; | ||
| 70 | uint8_t l, lt; | ||
| 71 | |||
| 72 | 220150 | l = *left; | |
| 73 | 220150 | lt = *left_top; | |
| 74 | |||
| 75 |
2/2✓ Branch 0 taken 68350700 times.
✓ Branch 1 taken 220150 times.
|
68570850 | for (i = 0; i < w; i++) { |
| 76 | 68350700 | const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF); | |
| 77 | 68350700 | lt = src1[i]; | |
| 78 | 68350700 | l = src2[i]; | |
| 79 | 68350700 | dst[i] = l - pred; | |
| 80 | } | ||
| 81 | |||
| 82 | 220150 | *left = l; | |
| 83 | 220150 | *left_top = lt; | |
| 84 | 220150 | } | |
| 85 | |||
| 86 | 809 | static void sub_left_predict_c(uint8_t *dst, const uint8_t *src, | |
| 87 | ptrdiff_t stride, ptrdiff_t width, int height) | ||
| 88 | { | ||
| 89 | int i, j; | ||
| 90 | 809 | uint8_t prev = 0x80; /* Set the initial value */ | |
| 91 |
2/2✓ Branch 0 taken 217328 times.
✓ Branch 1 taken 809 times.
|
218137 | for (j = 0; j < height; j++) { |
| 92 |
2/2✓ Branch 0 taken 68775168 times.
✓ Branch 1 taken 217328 times.
|
68992496 | for (i = 0; i < width; i++) { |
| 93 | 68775168 | *dst++ = src[i] - prev; | |
| 94 | 68775168 | prev = src[i]; | |
| 95 | } | ||
| 96 | 217328 | src += stride; | |
| 97 | } | ||
| 98 | 809 | } | |
| 99 | |||
| 100 | 210 | av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c) | |
| 101 | { | ||
| 102 | 210 | c->diff_bytes = diff_bytes_c; | |
| 103 | 210 | c->sub_median_pred = sub_median_pred_c; | |
| 104 | 210 | c->sub_left_predict = sub_left_predict_c; | |
| 105 | |||
| 106 | #if ARCH_RISCV | ||
| 107 | ff_llvidencdsp_init_riscv(c); | ||
| 108 | #elif ARCH_X86 | ||
| 109 | 210 | ff_llvidencdsp_init_x86(c); | |
| 110 | #endif | ||
| 111 | 210 | } | |
| 112 |