2 * Copyright (c) 2002-2012 Michael Niedermayer
3 * Copyright (C) 2012 Ronald S. Bultje
5 * This file is part of FFmpeg.
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.
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.
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
22 #include "bit_depth_template.c"
23 void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src,
24 ptrdiff_t buf_linesize,
25 ptrdiff_t src_linesize,
26 int block_w, int block_h,
27 int src_x, int src_y, int w, int h)
30 int start_y, start_x, end_y, end_x;
35 av_assert2(block_w * sizeof(pixel) <= FFABS(buf_linesize));
38 src -= src_y * src_linesize;
39 src += (h - 1) * src_linesize;
41 } else if (src_y <= -block_h) {
42 src -= src_y * src_linesize;
43 src += (1 - block_h) * src_linesize;
47 // The subtracted expression has an unsigned type and must thus not be negative
48 src -= (1 + src_x - w) * sizeof(pixel);
50 } else if (src_x <= -block_w) {
51 src += (1 - block_w - src_x) * sizeof(pixel);
55 start_y = FFMAX(0, -src_y);
56 start_x = FFMAX(0, -src_x);
57 end_y = FFMIN(block_h, h-src_y);
58 end_x = FFMIN(block_w, w-src_x);
59 av_assert2(start_y < end_y && block_h);
60 av_assert2(start_x < end_x && block_w);
63 src += start_y * src_linesize + start_x * sizeof(pixel);
64 buf += start_x * sizeof(pixel);
67 for (y = 0; y < start_y; y++) {
68 memcpy(buf, src, w * sizeof(pixel));
73 for (; y < end_y; y++) {
74 memcpy(buf, src, w * sizeof(pixel));
81 for (; y < block_h; y++) {
82 memcpy(buf, src, w * sizeof(pixel));
86 buf -= block_h * buf_linesize + start_x * sizeof(pixel);
88 pixel *bufp = (pixel *) buf;
91 for(x = 0; x < start_x; x++) {
92 bufp[x] = bufp[start_x];
96 for (x = end_x; x < block_w; x++) {
97 bufp[x] = bufp[end_x - 1];