Fix typo
[libav.git] / libavcodec / roqvideo.c
CommitLineData
3ef8be2b
MM
1/*
2 * Copyright (C) 2003 the ffmpeg project
3 *
b78e7197
DB
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
3ef8be2b
MM
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
3ef8be2b 10 *
b78e7197 11 * FFmpeg is distributed in the hope that it will be useful,
3ef8be2b
MM
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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
b78e7197 17 * License along with FFmpeg; if not, write to the Free Software
5509bffa 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3ef8be2b
MM
19 *
20 */
21
22/**
23 * @file roqvideo.c
55c970e3 24 * Id RoQ Video common functions based on work by Dr. Tim Ferguson
3ef8be2b
MM
25 */
26
3ef8be2b 27#include "avcodec.h"
55c970e3 28#include "roqvideo.h"
3ef8be2b 29
3ccda4ca
EL
30static inline void block_copy(unsigned char *out, unsigned char *in,
31 int outstride, int instride, int sz)
32{
33 int rows = sz;
34 while(rows--) {
35 memcpy(out, in, sz);
36 out += outstride;
37 in += instride;
38 }
39}
3ef8be2b 40
750cbd34 41void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
3ef8be2b 42{
3ccda4ca
EL
43 unsigned char *bptr;
44 int boffs,stride;
45
46 stride = ri->y_stride;
47 boffs = (y * stride) + x;
48
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];
54
55 bptr = ri->current_frame->data[1] + boffs;
56 bptr[0 ] =
57 bptr[1 ] =
58 bptr[stride ] =
59 bptr[stride+1] = cell->u;
60
61 bptr = ri->current_frame->data[2] + boffs;
62 bptr[0 ] =
63 bptr[1 ] =
64 bptr[stride ] =
65 bptr[stride+1] = cell->v;
3ef8be2b
MM
66}
67
750cbd34 68void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
3ef8be2b 69{
3ccda4ca
EL
70 unsigned char *bptr;
71 int boffs,stride;
72
73 stride = ri->y_stride;
74 boffs = (y * stride) + x;
75
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];
606975ab 80 bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3];
3ccda4ca
EL
81
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;
87
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;
3ef8be2b
MM
93}
94
3ccda4ca
EL
95
96static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
97 int deltay, int sz)
3ef8be2b 98{
3ccda4ca 99 int mx, my, cp;
3ef8be2b 100
750cbd34
VS
101 mx = x + deltax;
102 my = y + deltay;
3ef8be2b 103
b9029997 104 /* check MV against frame boundaries */
3ccda4ca
EL
105 if ((mx < 0) || (mx > ri->avctx->width - sz) ||
106 (my < 0) || (my > ri->avctx->height - sz)) {
b9029997
MM
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);
109 return;
110 }
111
3ccda4ca
EL
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);
116}
3ef8be2b 117
3ccda4ca
EL
118
119void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
120 int deltax, int deltay)
121{
122 apply_motion_generic(ri, x, y, deltax, deltay, 4);
3ef8be2b
MM
123}
124
750cbd34
VS
125void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
126 int deltax, int deltay)
3ef8be2b 127{
3ccda4ca 128 apply_motion_generic(ri, x, y, deltax, deltay, 8);
3ef8be2b 129}