| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2002-2012 Michael Niedermayer | ||
| 3 | * Copyright (C) 2012 Ronald S. Bultje | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "bit_depth_template.c" | ||
| 23 | #if BIT_DEPTH != 8 | ||
| 24 | // ff_emulated_edge_mc_8 is used by the x86 MpegVideoDSP API. | ||
| 25 | static | ||
| 26 | #endif | ||
| 27 | 16801691 | void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, | |
| 28 | ptrdiff_t buf_linesize, | ||
| 29 | ptrdiff_t src_linesize, | ||
| 30 | int block_w, int block_h, | ||
| 31 | int src_x, int src_y, int w, int h) | ||
| 32 | { | ||
| 33 | int x, y; | ||
| 34 | int start_y, start_x, end_y, end_x; | ||
| 35 | |||
| 36 | 16801691 | if (!w || !h) | |
| 37 | ✗ | return; | |
| 38 | |||
| 39 | av_assert2(block_w * sizeof(pixel) <= FFABS(buf_linesize)); | ||
| 40 | |||
| 41 | 16801691 | if (src_y >= h) { | |
| 42 | 229851 | src -= src_y * src_linesize; | |
| 43 | 229851 | src += (h - 1) * src_linesize; | |
| 44 | 229851 | src_y = h - 1; | |
| 45 | 16571840 | } else if (src_y <= -block_h) { | |
| 46 | 100795 | src -= src_y * src_linesize; | |
| 47 | 100795 | src += (1 - block_h) * src_linesize; | |
| 48 | 100795 | src_y = 1 - block_h; | |
| 49 | } | ||
| 50 | 16801691 | if (src_x >= w) { | |
| 51 | // The subtracted expression has an unsigned type and must thus not be negative | ||
| 52 | 250110 | src -= (1 + src_x - w) * sizeof(pixel); | |
| 53 | 250110 | src_x = w - 1; | |
| 54 | 16551581 | } else if (src_x <= -block_w) { | |
| 55 | 104036 | src += (1 - block_w - src_x) * sizeof(pixel); | |
| 56 | 104036 | src_x = 1 - block_w; | |
| 57 | } | ||
| 58 | |||
| 59 | 16801691 | start_y = FFMAX(0, -src_y); | |
| 60 | 16801691 | start_x = FFMAX(0, -src_x); | |
| 61 | 16801691 | end_y = FFMIN(block_h, h-src_y); | |
| 62 | 16801691 | end_x = FFMIN(block_w, w-src_x); | |
| 63 | av_assert2(start_y < end_y && block_h); | ||
| 64 | av_assert2(start_x < end_x && block_w); | ||
| 65 | |||
| 66 | 16801691 | w = end_x - start_x; | |
| 67 | 16801691 | src += start_y * src_linesize + start_x * (ptrdiff_t)sizeof(pixel); | |
| 68 | 16801691 | buf += start_x * sizeof(pixel); | |
| 69 | |||
| 70 | // top | ||
| 71 | 25406866 | for (y = 0; y < start_y; y++) { | |
| 72 | 8605175 | memcpy(buf, src, w * sizeof(pixel)); | |
| 73 | 8605175 | buf += buf_linesize; | |
| 74 | } | ||
| 75 | |||
| 76 | // copy existing part | ||
| 77 | 230185383 | for (; y < end_y; y++) { | |
| 78 | 213383692 | memcpy(buf, src, w * sizeof(pixel)); | |
| 79 | 213383692 | src += src_linesize; | |
| 80 | 213383692 | buf += buf_linesize; | |
| 81 | } | ||
| 82 | |||
| 83 | // bottom | ||
| 84 | 16801691 | src -= src_linesize; | |
| 85 | 45196851 | for (; y < block_h; y++) { | |
| 86 | 28395160 | memcpy(buf, src, w * sizeof(pixel)); | |
| 87 | 28395160 | buf += buf_linesize; | |
| 88 | } | ||
| 89 | |||
| 90 | 16801691 | buf -= block_h * buf_linesize + start_x * (ptrdiff_t)sizeof(pixel); | |
| 91 | 267185718 | while (block_h--) { | |
| 92 | 250384027 | pixel *bufp = (pixel *) buf; | |
| 93 | |||
| 94 | // left | ||
| 95 | 376195575 | for(x = 0; x < start_x; x++) { | |
| 96 | 125811548 | bufp[x] = bufp[start_x]; | |
| 97 | } | ||
| 98 | |||
| 99 | // right | ||
| 100 | 525900009 | for (x = end_x; x < block_w; x++) { | |
| 101 | 275515982 | bufp[x] = bufp[end_x - 1]; | |
| 102 | } | ||
| 103 | 250384027 | buf += buf_linesize; | |
| 104 | } | ||
| 105 | } | ||
| 106 |