| 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/common.h" | ||
| 22 | #include "mpeg4videodsp.h" | ||
| 23 | |||
| 24 | ✗ | static void gmc1_c(uint8_t *dst, const uint8_t *src, int stride, int h, | |
| 25 | int x16, int y16, int rounder) | ||
| 26 | { | ||
| 27 | ✗ | const int A = (16 - x16) * (16 - y16); | |
| 28 | ✗ | const int B = (x16) * (16 - y16); | |
| 29 | ✗ | const int C = (16 - x16) * (y16); | |
| 30 | ✗ | const int D = (x16) * (y16); | |
| 31 | int i; | ||
| 32 | |||
| 33 | ✗ | for (i = 0; i < h; i++) { | |
| 34 | ✗ | dst[0] = (A * src[0] + B * src[1] + C * src[stride + 0] + D * src[stride + 1] + rounder) >> 8; | |
| 35 | ✗ | dst[1] = (A * src[1] + B * src[2] + C * src[stride + 1] + D * src[stride + 2] + rounder) >> 8; | |
| 36 | ✗ | dst[2] = (A * src[2] + B * src[3] + C * src[stride + 2] + D * src[stride + 3] + rounder) >> 8; | |
| 37 | ✗ | dst[3] = (A * src[3] + B * src[4] + C * src[stride + 3] + D * src[stride + 4] + rounder) >> 8; | |
| 38 | ✗ | dst[4] = (A * src[4] + B * src[5] + C * src[stride + 4] + D * src[stride + 5] + rounder) >> 8; | |
| 39 | ✗ | dst[5] = (A * src[5] + B * src[6] + C * src[stride + 5] + D * src[stride + 6] + rounder) >> 8; | |
| 40 | ✗ | dst[6] = (A * src[6] + B * src[7] + C * src[stride + 6] + D * src[stride + 7] + rounder) >> 8; | |
| 41 | ✗ | dst[7] = (A * src[7] + B * src[8] + C * src[stride + 7] + D * src[stride + 8] + rounder) >> 8; | |
| 42 | ✗ | dst += stride; | |
| 43 | ✗ | src += stride; | |
| 44 | } | ||
| 45 | ✗ | } | |
| 46 | |||
| 47 | 6 | void ff_gmc_c(uint8_t *dst, const uint8_t *src, int stride, int h, int ox, int oy, | |
| 48 | int dxx, int dxy, int dyx, int dyy, int shift, int r, | ||
| 49 | int width, int height) | ||
| 50 | { | ||
| 51 | int y, vx, vy; | ||
| 52 | 6 | const int s = 1 << shift; | |
| 53 | |||
| 54 | 6 | width--; | |
| 55 | 6 | height--; | |
| 56 | |||
| 57 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 6 times.
|
102 | for (y = 0; y < h; y++) { |
| 58 | int x; | ||
| 59 | |||
| 60 | 96 | vx = ox; | |
| 61 | 96 | vy = oy; | |
| 62 |
2/2✓ Branch 0 taken 768 times.
✓ Branch 1 taken 96 times.
|
864 | for (x = 0; x < 8; x++) { // FIXME: optimize |
| 63 | int index; | ||
| 64 | 768 | int src_x = vx >> 16; | |
| 65 | 768 | int src_y = vy >> 16; | |
| 66 | 768 | int frac_x = src_x & (s - 1); | |
| 67 | 768 | int frac_y = src_y & (s - 1); | |
| 68 | |||
| 69 | 768 | src_x >>= shift; | |
| 70 | 768 | src_y >>= shift; | |
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 656 times.
✓ Branch 1 taken 112 times.
|
768 | if ((unsigned) src_x < width) { |
| 73 |
2/2✓ Branch 0 taken 450 times.
✓ Branch 1 taken 206 times.
|
656 | if ((unsigned) src_y < height) { |
| 74 | 450 | index = src_x + src_y * stride; | |
| 75 | 450 | dst[y * stride + x] = | |
| 76 | 450 | ((src[index] * (s - frac_x) + | |
| 77 | 450 | src[index + 1] * frac_x) * (s - frac_y) + | |
| 78 | 450 | (src[index + stride] * (s - frac_x) + | |
| 79 | 450 | src[index + stride + 1] * frac_x) * frac_y + | |
| 80 | 450 | r) >> (shift * 2); | |
| 81 | } else { | ||
| 82 | 206 | index = src_x + av_clip(src_y, 0, height) * stride; | |
| 83 | 206 | dst[y * stride + x] = | |
| 84 | 206 | ((src[index] * (s - frac_x) + | |
| 85 | 206 | src[index + 1] * frac_x) * s + | |
| 86 | 206 | r) >> (shift * 2); | |
| 87 | } | ||
| 88 | } else { | ||
| 89 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 98 times.
|
112 | if ((unsigned) src_y < height) { |
| 90 | 14 | index = av_clip(src_x, 0, width) + src_y * stride; | |
| 91 | 14 | dst[y * stride + x] = | |
| 92 | 14 | ((src[index] * (s - frac_y) + | |
| 93 | 14 | src[index + stride] * frac_y) * s + | |
| 94 | 14 | r) >> (shift * 2); | |
| 95 | } else { | ||
| 96 | 98 | index = av_clip(src_x, 0, width) + | |
| 97 | 98 | av_clip(src_y, 0, height) * stride; | |
| 98 | 98 | dst[y * stride + x] = src[index]; | |
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | 768 | vx += dxx; | |
| 103 | 768 | vy += dyx; | |
| 104 | } | ||
| 105 | 96 | ox += dxy; | |
| 106 | 96 | oy += dyy; | |
| 107 | } | ||
| 108 | 6 | } | |
| 109 | |||
| 110 | 201 | av_cold void ff_mpeg4videodsp_init(Mpeg4VideoDSPContext *c) | |
| 111 | { | ||
| 112 | 201 | c->gmc1 = gmc1_c; | |
| 113 | 201 | c->gmc = ff_gmc_c; | |
| 114 | |||
| 115 | #if ARCH_PPC | ||
| 116 | ff_mpeg4videodsp_init_ppc(c); | ||
| 117 | #elif ARCH_X86 | ||
| 118 | 201 | ff_mpeg4videodsp_init_x86(c); | |
| 119 | #endif | ||
| 120 | 201 | } | |
| 121 |