Libav
videodsp_template.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2004 Michael Niedermayer
3  * Copyright (C) 2012 Ronald S. Bultje
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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 
24 static void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src,
25  ptrdiff_t buf_linesize,
26  ptrdiff_t src_linesize,
27  int block_w, int block_h,
28  int src_x, int src_y, int w, int h)
29 {
30  int x, y;
31  int start_y, start_x, end_y, end_x;
32 
33  if (src_y >= h) {
34  src += (h - 1 - src_y) * src_linesize;
35  src_y = h - 1;
36  } else if (src_y <= -block_h) {
37  src += (1 - block_h - src_y) * src_linesize;
38  src_y = 1 - block_h;
39  }
40  if (src_x >= w) {
41  src += (w - 1 - src_x) * sizeof(pixel);
42  src_x = w - 1;
43  } else if (src_x <= -block_w) {
44  src += (1 - block_w - src_x) * sizeof(pixel);
45  src_x = 1 - block_w;
46  }
47 
48  start_y = FFMAX(0, -src_y);
49  start_x = FFMAX(0, -src_x);
50  end_y = FFMIN(block_h, h-src_y);
51  end_x = FFMIN(block_w, w-src_x);
52  assert(start_y < end_y && block_h);
53  assert(start_x < end_x && block_w);
54 
55  w = end_x - start_x;
56  src += start_y * src_linesize + start_x * sizeof(pixel);
57  buf += start_x * sizeof(pixel);
58 
59  // top
60  for (y = 0; y < start_y; y++) {
61  memcpy(buf, src, w * sizeof(pixel));
62  buf += buf_linesize;
63  }
64 
65  // copy existing part
66  for (; y < end_y; y++) {
67  memcpy(buf, src, w * sizeof(pixel));
68  src += src_linesize;
69  buf += buf_linesize;
70  }
71 
72  // bottom
73  src -= src_linesize;
74  for (; y < block_h; y++) {
75  memcpy(buf, src, w * sizeof(pixel));
76  buf += buf_linesize;
77  }
78 
79  buf -= block_h * buf_linesize + start_x * sizeof(pixel);
80  while (block_h--) {
81  pixel *bufp = (pixel *) buf;
82 
83  // left
84  for(x = 0; x < start_x; x++) {
85  bufp[x] = bufp[start_x];
86  }
87 
88  // right
89  for (x = end_x; x < block_w; x++) {
90  bufp[x] = bufp[end_x - 1];
91  }
92  buf += buf_linesize;
93  }
94 }