FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
videodsp_template.c
Go to the documentation of this file.
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"
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)
28 {
29  int x, y;
30  int start_y, start_x, end_y, end_x;
31 
32  if (!w || !h)
33  return;
34 
35  if (src_y >= h) {
36  src -= src_y * src_linesize;
37  src += (h - 1) * src_linesize;
38  src_y = h - 1;
39  } else if (src_y <= -block_h) {
40  src -= src_y * src_linesize;
41  src += (1 - block_h) * src_linesize;
42  src_y = 1 - block_h;
43  }
44  if (src_x >= w) {
45  src += (w - 1 - src_x) * sizeof(pixel);
46  src_x = w - 1;
47  } else if (src_x <= -block_w) {
48  src += (1 - block_w - src_x) * sizeof(pixel);
49  src_x = 1 - block_w;
50  }
51 
52  start_y = FFMAX(0, -src_y);
53  start_x = FFMAX(0, -src_x);
54  end_y = FFMIN(block_h, h-src_y);
55  end_x = FFMIN(block_w, w-src_x);
56  av_assert2(start_y < end_y && block_h);
57  av_assert2(start_x < end_x && block_w);
58 
59  w = end_x - start_x;
60  src += start_y * src_linesize + start_x * sizeof(pixel);
61  buf += start_x * sizeof(pixel);
62 
63  // top
64  for (y = 0; y < start_y; y++) {
65  memcpy(buf, src, w * sizeof(pixel));
66  buf += buf_linesize;
67  }
68 
69  // copy existing part
70  for (; y < end_y; y++) {
71  memcpy(buf, src, w * sizeof(pixel));
72  src += src_linesize;
73  buf += buf_linesize;
74  }
75 
76  // bottom
77  src -= src_linesize;
78  for (; y < block_h; y++) {
79  memcpy(buf, src, w * sizeof(pixel));
80  buf += buf_linesize;
81  }
82 
83  buf -= block_h * buf_linesize + start_x * sizeof(pixel);
84  while (block_h--) {
85  pixel *bufp = (pixel *) buf;
86 
87  // left
88  for(x = 0; x < start_x; x++) {
89  bufp[x] = bufp[start_x];
90  }
91 
92  // right
93  for (x = end_x; x < block_w; x++) {
94  bufp[x] = bufp[end_x - 1];
95  }
96  buf += buf_linesize;
97  }
98 }
void FUNC() ff_emulated_edge_mc(uint8_t *buf, const uint8_t *src, ptrdiff_t buf_linesize, ptrdiff_t src_linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
uint8_t
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
#define FUNC(a)
#define FFMAX(a, b)
Definition: common.h:64
#define FFMIN(a, b)
Definition: common.h:66
float y
AVS_Value src
Definition: avisynth_c.h:482
void * buf
Definition: avisynth_c.h:553
uint8_t pixel
Definition: tiny_ssim.c:42