/src/ffmpeg/libavcodec/videodsp_template.c
Line | Count | 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 | | 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 | 218M | { |
33 | 218M | int x, y; |
34 | 218M | int start_y, start_x, end_y, end_x; |
35 | | |
36 | 218M | if (!w || !h) |
37 | 471k | return; |
38 | | |
39 | 217M | av_assert2(block_w * sizeof(pixel) <= FFABS(buf_linesize)); |
40 | | |
41 | 217M | if (src_y >= h) { |
42 | 10.4M | src -= src_y * src_linesize; |
43 | 10.4M | src += (h - 1) * src_linesize; |
44 | 10.4M | src_y = h - 1; |
45 | 207M | } else if (src_y <= -block_h) { |
46 | 10.0M | src -= src_y * src_linesize; |
47 | 10.0M | src += (1 - block_h) * src_linesize; |
48 | 10.0M | src_y = 1 - block_h; |
49 | 10.0M | } |
50 | 217M | if (src_x >= w) { |
51 | | // The subtracted expression has an unsigned type and must thus not be negative |
52 | 13.2M | src -= (1 + src_x - w) * sizeof(pixel); |
53 | 13.2M | src_x = w - 1; |
54 | 204M | } else if (src_x <= -block_w) { |
55 | 11.7M | src += (1 - block_w - src_x) * sizeof(pixel); |
56 | 11.7M | src_x = 1 - block_w; |
57 | 11.7M | } |
58 | | |
59 | 217M | start_y = FFMAX(0, -src_y); |
60 | 217M | start_x = FFMAX(0, -src_x); |
61 | 217M | end_y = FFMIN(block_h, h-src_y); |
62 | 217M | end_x = FFMIN(block_w, w-src_x); |
63 | 217M | av_assert2(start_y < end_y && block_h); |
64 | 217M | av_assert2(start_x < end_x && block_w); |
65 | | |
66 | 217M | w = end_x - start_x; |
67 | 217M | src += start_y * src_linesize + start_x * (ptrdiff_t)sizeof(pixel); |
68 | 217M | buf += start_x * sizeof(pixel); |
69 | | |
70 | | // top |
71 | 396M | for (y = 0; y < start_y; y++) { |
72 | 178M | memcpy(buf, src, w * sizeof(pixel)); |
73 | 178M | buf += buf_linesize; |
74 | 178M | } |
75 | | |
76 | | // copy existing part |
77 | 2.29G | for (; y < end_y; y++) { |
78 | 2.07G | memcpy(buf, src, w * sizeof(pixel)); |
79 | 2.07G | src += src_linesize; |
80 | 2.07G | buf += buf_linesize; |
81 | 2.07G | } |
82 | | |
83 | | // bottom |
84 | 217M | src -= src_linesize; |
85 | 608M | for (; y < block_h; y++) { |
86 | 390M | memcpy(buf, src, w * sizeof(pixel)); |
87 | 390M | buf += buf_linesize; |
88 | 390M | } |
89 | | |
90 | 217M | buf -= block_h * buf_linesize + start_x * (ptrdiff_t)sizeof(pixel); |
91 | 2.86G | while (block_h--) { |
92 | 2.64G | pixel *bufp = (pixel *) buf; |
93 | | |
94 | | // left |
95 | 4.64G | for(x = 0; x < start_x; x++) { |
96 | 2.00G | bufp[x] = bufp[start_x]; |
97 | 2.00G | } |
98 | | |
99 | | // right |
100 | 9.86G | for (x = end_x; x < block_w; x++) { |
101 | 7.21G | bufp[x] = bufp[end_x - 1]; |
102 | 7.21G | } |
103 | 2.64G | buf += buf_linesize; |
104 | 2.64G | } |
105 | 217M | } Line | Count | Source | 32 | 173M | { | 33 | 173M | int x, y; | 34 | 173M | int start_y, start_x, end_y, end_x; | 35 | | | 36 | 173M | if (!w || !h) | 37 | 471k | return; | 38 | | | 39 | 172M | av_assert2(block_w * sizeof(pixel) <= FFABS(buf_linesize)); | 40 | | | 41 | 172M | if (src_y >= h) { | 42 | 8.20M | src -= src_y * src_linesize; | 43 | 8.20M | src += (h - 1) * src_linesize; | 44 | 8.20M | src_y = h - 1; | 45 | 164M | } else if (src_y <= -block_h) { | 46 | 6.36M | src -= src_y * src_linesize; | 47 | 6.36M | src += (1 - block_h) * src_linesize; | 48 | 6.36M | src_y = 1 - block_h; | 49 | 6.36M | } | 50 | 172M | if (src_x >= w) { | 51 | | // The subtracted expression has an unsigned type and must thus not be negative | 52 | 10.6M | src -= (1 + src_x - w) * sizeof(pixel); | 53 | 10.6M | src_x = w - 1; | 54 | 161M | } else if (src_x <= -block_w) { | 55 | 8.22M | src += (1 - block_w - src_x) * sizeof(pixel); | 56 | 8.22M | src_x = 1 - block_w; | 57 | 8.22M | } | 58 | | | 59 | 172M | start_y = FFMAX(0, -src_y); | 60 | 172M | start_x = FFMAX(0, -src_x); | 61 | 172M | end_y = FFMIN(block_h, h-src_y); | 62 | 172M | end_x = FFMIN(block_w, w-src_x); | 63 | 172M | av_assert2(start_y < end_y && block_h); | 64 | 172M | av_assert2(start_x < end_x && block_w); | 65 | | | 66 | 172M | w = end_x - start_x; | 67 | 172M | src += start_y * src_linesize + start_x * (ptrdiff_t)sizeof(pixel); | 68 | 172M | buf += start_x * sizeof(pixel); | 69 | | | 70 | | // top | 71 | 290M | for (y = 0; y < start_y; y++) { | 72 | 118M | memcpy(buf, src, w * sizeof(pixel)); | 73 | 118M | buf += buf_linesize; | 74 | 118M | } | 75 | | | 76 | | // copy existing part | 77 | 1.77G | for (; y < end_y; y++) { | 78 | 1.60G | memcpy(buf, src, w * sizeof(pixel)); | 79 | 1.60G | src += src_linesize; | 80 | 1.60G | buf += buf_linesize; | 81 | 1.60G | } | 82 | | | 83 | | // bottom | 84 | 172M | src -= src_linesize; | 85 | 449M | for (; y < block_h; y++) { | 86 | 277M | memcpy(buf, src, w * sizeof(pixel)); | 87 | 277M | buf += buf_linesize; | 88 | 277M | } | 89 | | | 90 | 172M | buf -= block_h * buf_linesize + start_x * (ptrdiff_t)sizeof(pixel); | 91 | 2.17G | while (block_h--) { | 92 | 2.00G | pixel *bufp = (pixel *) buf; | 93 | | | 94 | | // left | 95 | 3.18G | for(x = 0; x < start_x; x++) { | 96 | 1.18G | bufp[x] = bufp[start_x]; | 97 | 1.18G | } | 98 | | | 99 | | // right | 100 | 7.32G | for (x = end_x; x < block_w; x++) { | 101 | 5.32G | bufp[x] = bufp[end_x - 1]; | 102 | 5.32G | } | 103 | 2.00G | buf += buf_linesize; | 104 | 2.00G | } | 105 | 172M | } |
videodsp.c:ff_emulated_edge_mc_16 Line | Count | Source | 32 | 45.3M | { | 33 | 45.3M | int x, y; | 34 | 45.3M | int start_y, start_x, end_y, end_x; | 35 | | | 36 | 45.3M | if (!w || !h) | 37 | 0 | return; | 38 | | | 39 | 45.3M | av_assert2(block_w * sizeof(pixel) <= FFABS(buf_linesize)); | 40 | | | 41 | 45.3M | if (src_y >= h) { | 42 | 2.28M | src -= src_y * src_linesize; | 43 | 2.28M | src += (h - 1) * src_linesize; | 44 | 2.28M | src_y = h - 1; | 45 | 43.0M | } else if (src_y <= -block_h) { | 46 | 3.71M | src -= src_y * src_linesize; | 47 | 3.71M | src += (1 - block_h) * src_linesize; | 48 | 3.71M | src_y = 1 - block_h; | 49 | 3.71M | } | 50 | 45.3M | if (src_x >= w) { | 51 | | // The subtracted expression has an unsigned type and must thus not be negative | 52 | 2.62M | src -= (1 + src_x - w) * sizeof(pixel); | 53 | 2.62M | src_x = w - 1; | 54 | 42.7M | } else if (src_x <= -block_w) { | 55 | 3.50M | src += (1 - block_w - src_x) * sizeof(pixel); | 56 | 3.50M | src_x = 1 - block_w; | 57 | 3.50M | } | 58 | | | 59 | 45.3M | start_y = FFMAX(0, -src_y); | 60 | 45.3M | start_x = FFMAX(0, -src_x); | 61 | 45.3M | end_y = FFMIN(block_h, h-src_y); | 62 | 45.3M | end_x = FFMIN(block_w, w-src_x); | 63 | 45.3M | av_assert2(start_y < end_y && block_h); | 64 | 45.3M | av_assert2(start_x < end_x && block_w); | 65 | | | 66 | 45.3M | w = end_x - start_x; | 67 | 45.3M | src += start_y * src_linesize + start_x * (ptrdiff_t)sizeof(pixel); | 68 | 45.3M | buf += start_x * sizeof(pixel); | 69 | | | 70 | | // top | 71 | 105M | for (y = 0; y < start_y; y++) { | 72 | 59.9M | memcpy(buf, src, w * sizeof(pixel)); | 73 | 59.9M | buf += buf_linesize; | 74 | 59.9M | } | 75 | | | 76 | | // copy existing part | 77 | 515M | for (; y < end_y; y++) { | 78 | 469M | memcpy(buf, src, w * sizeof(pixel)); | 79 | 469M | src += src_linesize; | 80 | 469M | buf += buf_linesize; | 81 | 469M | } | 82 | | | 83 | | // bottom | 84 | 45.3M | src -= src_linesize; | 85 | 159M | for (; y < block_h; y++) { | 86 | 113M | memcpy(buf, src, w * sizeof(pixel)); | 87 | 113M | buf += buf_linesize; | 88 | 113M | } | 89 | | | 90 | 45.3M | buf -= block_h * buf_linesize + start_x * (ptrdiff_t)sizeof(pixel); | 91 | 688M | while (block_h--) { | 92 | 643M | pixel *bufp = (pixel *) buf; | 93 | | | 94 | | // left | 95 | 1.45G | for(x = 0; x < start_x; x++) { | 96 | 815M | bufp[x] = bufp[start_x]; | 97 | 815M | } | 98 | | | 99 | | // right | 100 | 2.53G | for (x = end_x; x < block_w; x++) { | 101 | 1.89G | bufp[x] = bufp[end_x - 1]; | 102 | 1.89G | } | 103 | 643M | buf += buf_linesize; | 104 | 643M | } | 105 | 45.3M | } |
|