2003-09-02 04:32:02 +00:00
|
|
|
/*
|
2007-06-26 20:13:09 +00:00
|
|
|
* Copyright (C) 2003 Mike Melanson
|
|
|
|
* Copyright (C) 2003 Dr. Tim Ferguson
|
2003-09-02 04:32:02 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2003-09-02 04:32:02 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-09-02 04:32:02 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2003-09-02 04:32:02 +00:00
|
|
|
* 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
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-09-02 04:32:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2008-05-15 22:51:38 +00:00
|
|
|
* id RoQ Video common functions based on work by Dr. Tim Ferguson
|
2003-09-02 04:32:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
2007-05-29 15:01:33 +00:00
|
|
|
#include "roqvideo.h"
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2007-06-05 08:05:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2007-05-29 12:20:40 +00:00
|
|
|
void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
|
2003-09-02 04:32:02 +00:00
|
|
|
{
|
2007-06-05 08:05:16 +00:00
|
|
|
unsigned char *bptr;
|
|
|
|
int boffs,stride;
|
|
|
|
|
2007-07-02 10:21:41 +00:00
|
|
|
stride = ri->current_frame->linesize[0];
|
2007-07-03 02:52:40 +00:00
|
|
|
boffs = y*stride + x;
|
2007-06-05 08:05:16 +00:00
|
|
|
|
|
|
|
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];
|
|
|
|
|
2007-07-02 10:21:41 +00:00
|
|
|
stride = ri->current_frame->linesize[1];
|
|
|
|
boffs = y*stride + x;
|
|
|
|
|
2007-06-05 08:05:16 +00:00
|
|
|
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;
|
2003-09-02 04:32:02 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 12:20:40 +00:00
|
|
|
void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
|
2003-09-02 04:32:02 +00:00
|
|
|
{
|
2007-06-05 08:05:16 +00:00
|
|
|
unsigned char *bptr;
|
|
|
|
int boffs,stride;
|
|
|
|
|
2007-07-02 10:21:41 +00:00
|
|
|
stride = ri->current_frame->linesize[0];
|
2007-07-03 02:52:40 +00:00
|
|
|
boffs = y*stride + x;
|
2007-06-05 08:05:16 +00:00
|
|
|
|
|
|
|
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];
|
2007-06-25 07:29:45 +00:00
|
|
|
bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3];
|
2007-06-05 08:05:16 +00:00
|
|
|
|
2007-07-02 10:21:41 +00:00
|
|
|
stride = ri->current_frame->linesize[1];
|
|
|
|
boffs = y*stride + x;
|
|
|
|
|
2007-06-05 08:05:16 +00:00
|
|
|
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;
|
2003-09-02 04:32:02 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 08:05:16 +00:00
|
|
|
|
|
|
|
static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
|
|
|
|
int deltay, int sz)
|
2003-09-02 04:32:02 +00:00
|
|
|
{
|
2007-06-05 08:05:16 +00:00
|
|
|
int mx, my, cp;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2007-05-29 12:20:40 +00:00
|
|
|
mx = x + deltax;
|
|
|
|
my = y + deltay;
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2005-08-13 18:25:17 +00:00
|
|
|
/* check MV against frame boundaries */
|
2007-06-26 20:10:26 +00:00
|
|
|
if ((mx < 0) || (mx > ri->width - sz) ||
|
|
|
|
(my < 0) || (my > ri->height - sz)) {
|
2005-08-13 18:25:17 +00:00
|
|
|
av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
|
2007-06-26 20:10:26 +00:00
|
|
|
mx, my, ri->width, ri->height);
|
2005-08-13 18:25:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-27 10:40:29 +00:00
|
|
|
for(cp = 0; cp < 3; cp++) {
|
2007-07-02 10:21:41 +00:00
|
|
|
int outstride = ri->current_frame->linesize[cp];
|
|
|
|
int instride = ri->last_frame ->linesize[cp];
|
2007-07-05 03:01:53 +00:00
|
|
|
block_copy(ri->current_frame->data[cp] + y*outstride + x,
|
|
|
|
ri->last_frame->data[cp] + my*instride + mx,
|
2007-07-02 10:21:41 +00:00
|
|
|
outstride, instride, sz);
|
2007-06-27 10:40:29 +00:00
|
|
|
}
|
2007-06-05 08:05:16 +00:00
|
|
|
}
|
2003-09-02 04:32:02 +00:00
|
|
|
|
2007-06-05 08:05:16 +00:00
|
|
|
|
|
|
|
void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
|
|
|
|
int deltax, int deltay)
|
|
|
|
{
|
|
|
|
apply_motion_generic(ri, x, y, deltax, deltay, 4);
|
2003-09-02 04:32:02 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 12:20:40 +00:00
|
|
|
void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
|
|
|
|
int deltax, int deltay)
|
2003-09-02 04:32:02 +00:00
|
|
|
{
|
2007-06-05 08:05:16 +00:00
|
|
|
apply_motion_generic(ri, x, y, deltax, deltay, 8);
|
2003-09-02 04:32:02 +00:00
|
|
|
}
|