3ef8be2b |
/* |
7299663a |
* Copyright (C) 2003 Mike Melanson
* Copyright (C) 2003 Dr. Tim Ferguson |
3ef8be2b |
* |
b78e7197 |
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or |
3ef8be2b |
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either |
b78e7197 |
* version 2.1 of the License, or (at your option) any later version. |
3ef8be2b |
* |
b78e7197 |
* FFmpeg is distributed in the hope that it will be useful, |
3ef8be2b |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public |
b78e7197 |
* License along with FFmpeg; if not, write to the Free Software |
5509bffa |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
3ef8be2b |
*/
/** |
ba87f080 |
* @file |
88c52162 |
* id RoQ Video common functions based on work by Dr. Tim Ferguson |
3ef8be2b |
*/
#include "avcodec.h" |
55c970e3 |
#include "roqvideo.h" |
3ef8be2b |
|
3ccda4ca |
static inline void block_copy(unsigned char *out, unsigned char *in,
int outstride, int instride, int sz)
{
int rows = sz;
while(rows--) {
memcpy(out, in, sz);
out += outstride;
in += instride;
}
} |
3ef8be2b |
|
750cbd34 |
void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell) |
3ef8be2b |
{ |
3ccda4ca |
unsigned char *bptr;
int boffs,stride;
|
35c621e7 |
stride = ri->current_frame->linesize[0]; |
737b7fb9 |
boffs = y*stride + x; |
3ccda4ca |
bptr = ri->current_frame->data[0] + boffs;
bptr[0 ] = cell->y[0];
bptr[1 ] = cell->y[1];
bptr[stride ] = cell->y[2];
bptr[stride+1] = cell->y[3];
|
35c621e7 |
stride = ri->current_frame->linesize[1];
boffs = y*stride + x;
|
3ccda4ca |
bptr = ri->current_frame->data[1] + boffs;
bptr[0 ] =
bptr[1 ] =
bptr[stride ] =
bptr[stride+1] = cell->u;
bptr = ri->current_frame->data[2] + boffs;
bptr[0 ] =
bptr[1 ] =
bptr[stride ] =
bptr[stride+1] = cell->v; |
3ef8be2b |
}
|
750cbd34 |
void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell) |
3ef8be2b |
{ |
3ccda4ca |
unsigned char *bptr;
int boffs,stride;
|
35c621e7 |
stride = ri->current_frame->linesize[0]; |
737b7fb9 |
boffs = y*stride + x; |
3ccda4ca |
bptr = ri->current_frame->data[0] + boffs;
bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = cell->y[0];
bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = cell->y[1];
bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = cell->y[2]; |
606975ab |
bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3]; |
3ccda4ca |
|
35c621e7 |
stride = ri->current_frame->linesize[1];
boffs = y*stride + x;
|
3ccda4ca |
bptr = ri->current_frame->data[1] + boffs;
bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->u;
bptr = ri->current_frame->data[2] + boffs;
bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->v; |
3ef8be2b |
}
|
3ccda4ca |
static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
int deltay, int sz) |
3ef8be2b |
{ |
3ccda4ca |
int mx, my, cp; |
3ef8be2b |
|
750cbd34 |
mx = x + deltax;
my = y + deltay; |
3ef8be2b |
|
b9029997 |
/* check MV against frame boundaries */ |
9489d2ef |
if ((mx < 0) || (mx > ri->width - sz) ||
(my < 0) || (my > ri->height - sz)) { |
b9029997 |
av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n", |
9489d2ef |
mx, my, ri->width, ri->height); |
b9029997 |
return;
}
|
43c34675 |
if (ri->last_frame->data[0] == NULL) {
av_log(ri->avctx, AV_LOG_ERROR, "Invalid decode type. Invalid header?\n");
return;
}
|
a7ae617f |
for(cp = 0; cp < 3; cp++) { |
35c621e7 |
int outstride = ri->current_frame->linesize[cp];
int instride = ri->last_frame ->linesize[cp]; |
8448946e |
block_copy(ri->current_frame->data[cp] + y*outstride + x,
ri->last_frame->data[cp] + my*instride + mx, |
35c621e7 |
outstride, instride, sz); |
a7ae617f |
} |
3ccda4ca |
} |
3ef8be2b |
|
3ccda4ca |
void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
int deltax, int deltay)
{
apply_motion_generic(ri, x, y, deltax, deltay, 4); |
3ef8be2b |
}
|
750cbd34 |
void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
int deltax, int deltay) |
3ef8be2b |
{ |
3ccda4ca |
apply_motion_generic(ri, x, y, deltax, deltay, 8); |
3ef8be2b |
} |