annotate roqvideo.c @ 5192:3bfa0f33c854 libavcodec

use the right stride patch by Vitor: [vitor1001 gmail com]
author benoit
date Wed, 27 Jun 2007 10:40:29 +0000
parents ab669ac706dc
children 0af35881395e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
1 /*
5189
ab669ac706dc right copyrights
benoit
parents: 5188
diff changeset
2 * Copyright (C) 2003 Mike Melanson
ab669ac706dc right copyrights
benoit
parents: 5188
diff changeset
3 * Copyright (C) 2003 Dr. Tim Ferguson
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
15 * Lesser General Public License for more details.
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
16 *
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
20 */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
21
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
22 /**
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
23 * @file roqvideo.c
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents: 5078
diff changeset
24 * Id RoQ Video common functions based on work by Dr. Tim Ferguson
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
25 */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
26
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
27 #include "avcodec.h"
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents: 5078
diff changeset
28 #include "roqvideo.h"
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
29
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
30 static inline void block_copy(unsigned char *out, unsigned char *in,
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
31 int outstride, int instride, int sz)
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
32 {
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
33 int rows = sz;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
34 while(rows--) {
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
35 memcpy(out, in, sz);
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
36 out += outstride;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
37 in += instride;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
38 }
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
39 }
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
40
5078
4f36b52179d1 cosmetics and function rename
benoit
parents: 5067
diff changeset
41 void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
42 {
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
43 unsigned char *bptr;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
44 int boffs,stride;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
45
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
46 stride = ri->y_stride;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
47 boffs = (y * stride) + x;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
48
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
49 bptr = ri->current_frame->data[0] + boffs;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
50 bptr[0 ] = cell->y[0];
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
51 bptr[1 ] = cell->y[1];
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
52 bptr[stride ] = cell->y[2];
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
53 bptr[stride+1] = cell->y[3];
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
54
5192
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
55 stride = ri->c_stride;
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
56 bptr = ri->current_frame->data[1] + boffs;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
57 bptr[0 ] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
58 bptr[1 ] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
59 bptr[stride ] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
60 bptr[stride+1] = cell->u;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
61
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
62 bptr = ri->current_frame->data[2] + boffs;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
63 bptr[0 ] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
64 bptr[1 ] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
65 bptr[stride ] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
66 bptr[stride+1] = cell->v;
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
67 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
68
5078
4f36b52179d1 cosmetics and function rename
benoit
parents: 5067
diff changeset
69 void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
70 {
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
71 unsigned char *bptr;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
72 int boffs,stride;
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
73
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
74 stride = ri->y_stride;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
75 boffs = (y * stride) + x;
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
76
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
77 bptr = ri->current_frame->data[0] + boffs;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
78 bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = cell->y[0];
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
79 bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = cell->y[1];
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
80 bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = cell->y[2];
5183
3adfa650c7ad Fix typo
benoit
parents: 5099
diff changeset
81 bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3];
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
82
5192
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
83 stride = ri->c_stride;
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
84 bptr = ri->current_frame->data[1] + boffs;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
85 bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
86 bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
87 bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
88 bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->u;
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
89
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
90 bptr = ri->current_frame->data[2] + boffs;
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
91 bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
92 bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
93 bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
94 bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->v;
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
95 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
96
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
97
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
98 static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
99 int deltay, int sz)
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
100 {
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
101 int mx, my, cp;
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
102
5078
4f36b52179d1 cosmetics and function rename
benoit
parents: 5067
diff changeset
103 mx = x + deltax;
4f36b52179d1 cosmetics and function rename
benoit
parents: 5067
diff changeset
104 my = y + deltay;
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
105
2828
2aae25679885 tinfoil patch: validate motion vectors and do not free frame on exit if
melanson
parents: 2028
diff changeset
106 /* check MV against frame boundaries */
5188
c2a475157299 add width and height in context and use them
benoit
parents: 5183
diff changeset
107 if ((mx < 0) || (mx > ri->width - sz) ||
c2a475157299 add width and height in context and use them
benoit
parents: 5183
diff changeset
108 (my < 0) || (my > ri->height - sz)) {
2828
2aae25679885 tinfoil patch: validate motion vectors and do not free frame on exit if
melanson
parents: 2028
diff changeset
109 av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
5188
c2a475157299 add width and height in context and use them
benoit
parents: 5183
diff changeset
110 mx, my, ri->width, ri->height);
2828
2aae25679885 tinfoil patch: validate motion vectors and do not free frame on exit if
melanson
parents: 2028
diff changeset
111 return;
2aae25679885 tinfoil patch: validate motion vectors and do not free frame on exit if
melanson
parents: 2028
diff changeset
112 }
2aae25679885 tinfoil patch: validate motion vectors and do not free frame on exit if
melanson
parents: 2028
diff changeset
113
5192
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
114 for(cp = 0; cp < 3; cp++) {
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
115 int stride = ri->current_frame->linesize[cp];
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
116 block_copy(ri->current_frame->data[cp] + (y*stride) + x,
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
117 ri->last_frame->data[cp] + (my*stride) + mx,
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
118 stride, stride, sz);
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
119 }
3bfa0f33c854 use the right stride
benoit
parents: 5189
diff changeset
120
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
121 }
1495
07029b2cd44f experimental half-pel motion compensation for C planes, courtesy of Dr.
tmmm
parents: 1439
diff changeset
122
07029b2cd44f experimental half-pel motion compensation for C planes, courtesy of Dr.
tmmm
parents: 1439
diff changeset
123
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
124 void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
125 int deltax, int deltay)
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
126 {
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
127 apply_motion_generic(ri, x, y, deltax, deltay, 4);
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
128 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
129
5078
4f36b52179d1 cosmetics and function rename
benoit
parents: 5067
diff changeset
130 void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
4f36b52179d1 cosmetics and function rename
benoit
parents: 5067
diff changeset
131 int deltax, int deltay)
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
132 {
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5080
diff changeset
133 apply_motion_generic(ri, x, y, deltax, deltay, 8);
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
134 }