Statistics
| Branch: | Revision:

ffmpeg / libavcodec / roqvideo.c @ 606975ab

History | View | Annotate | Download (4.23 KB)

1
/*
2
 * Copyright (C) 2003 the ffmpeg project
3
 *
4
 * This file is part of FFmpeg.
5
 *
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.
10
 *
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.
15
 *
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
19
 *
20
 */
21

    
22
/**
23
 * @file roqvideo.c
24
 * Id RoQ Video common functions based on work by Dr. Tim Ferguson
25
 */
26

    
27
#include "avcodec.h"
28
#include "roqvideo.h"
29

    
30
static 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
}
40

    
41
void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
42
{
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;
66
}
67

    
68
void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
69
{
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];
80
    bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3];
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;
93
}
94

    
95

    
96
static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
97
                                        int deltay, int sz)
98
{
99
    int mx, my, cp;
100

    
101
    mx = x + deltax;
102
    my = y + deltay;
103

    
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);
109
        return;
110
    }
111

    
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
}
117

    
118

    
119
void 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);
123
}
124

    
125
void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
126
                             int deltax, int deltay)
127
{
128
    apply_motion_generic(ri, x, y, deltax, deltay, 8);
129
}