2012-12-15 20:46:02 +03:00
|
|
|
/*
|
2012-12-21 20:17:33 +03:00
|
|
|
* Copyright (c) 2002-2012 Michael Niedermayer
|
2012-12-15 20:46:02 +03:00
|
|
|
* Copyright (C) 2012 Ronald S. Bultje
|
|
|
|
*
|
2012-12-21 20:37:52 +03:00
|
|
|
* This file is part of FFmpeg.
|
2012-12-15 20:46:02 +03:00
|
|
|
*
|
2012-12-21 20:37:52 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2012-12-15 20:46:02 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-12-21 20:37:52 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2012-12-15 20:46:02 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-12-21 20:37:52 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2012-12-15 20:46:02 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bit_depth_template.c"
|
2013-11-15 15:56:05 +03:00
|
|
|
void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src,
|
|
|
|
ptrdiff_t buf_linesize,
|
|
|
|
ptrdiff_t src_linesize,
|
2013-09-20 15:01:19 +03:00
|
|
|
int block_w, int block_h,
|
|
|
|
int src_x, int src_y, int w, int h)
|
2012-12-15 20:46:02 +03:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int start_y, start_x, end_y, end_x;
|
2012-12-21 19:18:43 +03:00
|
|
|
|
|
|
|
if (!w || !h)
|
|
|
|
return;
|
2012-12-15 20:46:02 +03:00
|
|
|
|
2015-07-08 00:49:04 +02:00
|
|
|
av_assert2(block_w * sizeof(pixel) <= FFABS(buf_linesize));
|
|
|
|
|
2012-12-15 20:46:02 +03:00
|
|
|
if (src_y >= h) {
|
2013-11-15 15:56:05 +03:00
|
|
|
src -= src_y * src_linesize;
|
|
|
|
src += (h - 1) * src_linesize;
|
2012-12-15 20:46:02 +03:00
|
|
|
src_y = h - 1;
|
|
|
|
} else if (src_y <= -block_h) {
|
2013-11-15 15:56:05 +03:00
|
|
|
src -= src_y * src_linesize;
|
|
|
|
src += (1 - block_h) * src_linesize;
|
2012-12-15 20:46:02 +03:00
|
|
|
src_y = 1 - block_h;
|
|
|
|
}
|
|
|
|
if (src_x >= w) {
|
2019-06-15 00:47:06 +02:00
|
|
|
// The subtracted expression has an unsigned type and must thus not be negative
|
|
|
|
src -= (1 + src_x - w) * sizeof(pixel);
|
2012-12-15 20:46:02 +03:00
|
|
|
src_x = w - 1;
|
|
|
|
} else if (src_x <= -block_w) {
|
|
|
|
src += (1 - block_w - src_x) * sizeof(pixel);
|
|
|
|
src_x = 1 - block_w;
|
|
|
|
}
|
|
|
|
|
|
|
|
start_y = FFMAX(0, -src_y);
|
|
|
|
start_x = FFMAX(0, -src_x);
|
|
|
|
end_y = FFMIN(block_h, h-src_y);
|
|
|
|
end_x = FFMIN(block_w, w-src_x);
|
2012-12-21 19:18:43 +03:00
|
|
|
av_assert2(start_y < end_y && block_h);
|
|
|
|
av_assert2(start_x < end_x && block_w);
|
2012-12-15 20:46:02 +03:00
|
|
|
|
|
|
|
w = end_x - start_x;
|
2013-10-14 04:13:10 +03:00
|
|
|
src += start_y * src_linesize + start_x * sizeof(pixel);
|
2012-12-15 20:46:02 +03:00
|
|
|
buf += start_x * sizeof(pixel);
|
|
|
|
|
|
|
|
// top
|
|
|
|
for (y = 0; y < start_y; y++) {
|
|
|
|
memcpy(buf, src, w * sizeof(pixel));
|
2013-10-14 04:13:10 +03:00
|
|
|
buf += buf_linesize;
|
2012-12-15 20:46:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy existing part
|
|
|
|
for (; y < end_y; y++) {
|
|
|
|
memcpy(buf, src, w * sizeof(pixel));
|
2013-10-14 04:13:10 +03:00
|
|
|
src += src_linesize;
|
|
|
|
buf += buf_linesize;
|
2012-12-15 20:46:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// bottom
|
2013-10-14 04:13:10 +03:00
|
|
|
src -= src_linesize;
|
2012-12-15 20:46:02 +03:00
|
|
|
for (; y < block_h; y++) {
|
|
|
|
memcpy(buf, src, w * sizeof(pixel));
|
2013-10-14 04:13:10 +03:00
|
|
|
buf += buf_linesize;
|
2012-12-15 20:46:02 +03:00
|
|
|
}
|
|
|
|
|
2013-10-14 04:13:10 +03:00
|
|
|
buf -= block_h * buf_linesize + start_x * sizeof(pixel);
|
2012-12-15 20:46:02 +03:00
|
|
|
while (block_h--) {
|
|
|
|
pixel *bufp = (pixel *) buf;
|
|
|
|
|
|
|
|
// left
|
|
|
|
for(x = 0; x < start_x; x++) {
|
|
|
|
bufp[x] = bufp[start_x];
|
|
|
|
}
|
|
|
|
|
|
|
|
// right
|
|
|
|
for (x = end_x; x < block_w; x++) {
|
|
|
|
bufp[x] = bufp[end_x - 1];
|
|
|
|
}
|
2013-10-14 04:13:10 +03:00
|
|
|
buf += buf_linesize;
|
2012-12-15 20:46:02 +03:00
|
|
|
}
|
|
|
|
}
|