Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

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