2 * Copyright (C) 2003 the ffmpeg project
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * Id RoQ Video common functions based on work by Dr. Tim Ferguson
30 static inline void block_copy(unsigned char *out, unsigned char *in,
31 int outstride, int instride, int sz)
41 void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
46 stride = ri->y_stride;
47 boffs = (y * stride) + x;
49 bptr = ri->current_frame->data[0] + boffs;
50 bptr[0 ] = cell->y[0];
51 bptr[1 ] = cell->y[1];
52 bptr[stride ] = cell->y[2];
53 bptr[stride+1] = cell->y[3];
55 bptr = ri->current_frame->data[1] + boffs;
59 bptr[stride+1] = cell->u;
61 bptr = ri->current_frame->data[2] + boffs;
65 bptr[stride+1] = cell->v;
68 void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
73 stride = ri->y_stride;
74 boffs = (y * stride) + x;
76 bptr = ri->current_frame->data[0] + boffs;
77 bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = cell->y[0];
78 bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = cell->y[1];
79 bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = cell->y[2];
80 bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[2];
82 bptr = ri->current_frame->data[1] + boffs;
83 bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
84 bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
85 bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
86 bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->u;
88 bptr = ri->current_frame->data[2] + boffs;
89 bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
90 bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
91 bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
92 bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->v;
96 static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
104 /* check MV against frame boundaries */
105 if ((mx < 0) || (mx > ri->avctx->width - sz) ||
106 (my < 0) || (my > ri->avctx->height - sz)) {
107 av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
108 mx, my, ri->avctx->width, ri->avctx->height);
112 for(cp = 0; cp < 3; cp++)
113 block_copy(ri->current_frame->data[cp] + (y * ri->y_stride) + x,
114 ri->last_frame->data[cp] + (my * ri->y_stride) + mx,
115 ri->y_stride, ri->y_stride, sz);
119 void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
120 int deltax, int deltay)
122 apply_motion_generic(ri, x, y, deltax, deltay, 4);
125 void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
126 int deltax, int deltay)
128 apply_motion_generic(ri, x, y, deltax, deltay, 8);