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 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 (src_y >= h) {
33  src += (h - 1 - src_y) * linesize;
34  src_y = h - 1;
35  } else if (src_y <= -block_h) {
36  src += (1 - block_h - src_y) * linesize;
37  src_y = 1 - block_h;
38  }
39  if (src_x >= w) {
40  src += (w - 1 - src_x) * sizeof(pixel);
41  src_x = w - 1;
42  } else if (src_x <= -block_w) {
43  src += (1 - block_w - src_x) * sizeof(pixel);
44  src_x = 1 - block_w;
45  }
46 
47  start_y = FFMAX(0, -src_y);
48  start_x = FFMAX(0, -src_x);
49  end_y = FFMIN(block_h, h-src_y);
50  end_x = FFMIN(block_w, w-src_x);
51  assert(start_y < end_y && block_h);
52  assert(start_x < end_x && block_w);
53 
54  w = end_x - start_x;
55  src += start_y * linesize + start_x * sizeof(pixel);
56  buf += start_x * sizeof(pixel);
57 
58  // top
59  for (y = 0; y < start_y; y++) {
60  memcpy(buf, src, w * sizeof(pixel));
61  buf += linesize;
62  }
63 
64  // copy existing part
65  for (; y < end_y; y++) {
66  memcpy(buf, src, w * sizeof(pixel));
67  src += linesize;
68  buf += linesize;
69  }
70 
71  // bottom
72  src -= linesize;
73  for (; y < block_h; y++) {
74  memcpy(buf, src, w * sizeof(pixel));
75  buf += linesize;
76  }
77 
78  buf -= block_h * linesize + start_x * sizeof(pixel);
79  while (block_h--) {
80  pixel *bufp = (pixel *) buf;
81 
82  // left
83  for(x = 0; x < start_x; x++) {
84  bufp[x] = bufp[start_x];
85  }
86 
87  // right
88  for (x = end_x; x < block_w; x++) {
89  bufp[x] = bufp[end_x - 1];
90  }
91  buf += linesize;
92  }
93 }
uint8_t
#define FUNC(a)
#define pixel
static void FUNC() ff_emulated_edge_mc(uint8_t *buf, const uint8_t *src, ptrdiff_t linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)