annotate mpegvideo_common.h @ 5740:4d62c0055174 libavcodec

replace FIR with finite differences. 3x faster decode_subframe_fixed(). overall flac decoding: 10% faster if file was encoded with fixed predictors.
author lorenm
date Sun, 30 Sep 2007 02:12:03 +0000
parents ce0db8111f94
children 1d83e9c34641
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
1 /*
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
2 * The simplest mpeg encoder (well, it was the simplest!)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
3 * Copyright (c) 2000,2001 Fabrice Bellard.
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
5 *
5214
470601203f44 Group all copyright and author notices together.
diego
parents: 5204
diff changeset
6 * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
470601203f44 Group all copyright and author notices together.
diego
parents: 5204
diff changeset
7 *
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
8 * This file is part of FFmpeg.
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
9 *
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
10 * FFmpeg is free software; you can redistribute it and/or
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
11 * modify it under the terms of the GNU Lesser General Public
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
12 * License as published by the Free Software Foundation; either
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
13 * version 2.1 of the License, or (at your option) any later version.
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
14 *
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
15 * FFmpeg is distributed in the hope that it will be useful,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
18 * Lesser General Public License for more details.
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
19 *
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
20 * You should have received a copy of the GNU Lesser General Public
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
21 * License along with FFmpeg; if not, write to the Free Software
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
23 */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
24
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
25 /**
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
26 * @file mpegvideo_common.h
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
27 * The simplest mpeg encoder (well, it was the simplest!).
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
28 */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
29
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
30 #ifndef MPEGVIDEO_COMMON_H
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
31 #define MPEGVIDEO_COMMON_H
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
32
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
33 #include "avcodec.h"
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
34 #include "dsputil.h"
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
35 #include "mpegvideo.h"
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
36 #include "mjpegenc.h"
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
37 #include "msmpeg4.h"
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
38 #include "faandct.h"
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
39 #include <limits.h>
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
40
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
41 int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
42 int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
43 void denoise_dct_c(MpegEncContext *s, DCTELEM *block);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
44 void copy_picture(Picture *dst, Picture *src);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
45
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
46 /**
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
47 * allocates a Picture
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
48 * The pixels are allocated/set by calling get_buffer() if shared=0
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
49 */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
50 int alloc_picture(MpegEncContext *s, Picture *pic, int shared);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
51
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
52 /**
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
53 * sets the given MpegEncContext to common defaults (same for encoding and decoding).
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
54 * the changed fields will not depend upon the prior state of the MpegEncContext.
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
55 */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
56 void MPV_common_defaults(MpegEncContext *s);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
57
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
58 static inline void gmc1_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
59 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
60 uint8_t **ref_picture)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
61 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
62 uint8_t *ptr;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
63 int offset, src_x, src_y, linesize, uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
64 int motion_x, motion_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
65 int emu=0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
66
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
67 motion_x= s->sprite_offset[0][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
68 motion_y= s->sprite_offset[0][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
69 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
70 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
71 motion_x<<=(3-s->sprite_warping_accuracy);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
72 motion_y<<=(3-s->sprite_warping_accuracy);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
73 src_x = av_clip(src_x, -16, s->width);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
74 if (src_x == s->width)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
75 motion_x =0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
76 src_y = av_clip(src_y, -16, s->height);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
77 if (src_y == s->height)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
78 motion_y =0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
79
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
80 linesize = s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
81 uvlinesize = s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
82
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
83 ptr = ref_picture[0] + (src_y * linesize) + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
84
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
85 if(s->flags&CODEC_FLAG_EMU_EDGE){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
86 if( (unsigned)src_x >= s->h_edge_pos - 17
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
87 || (unsigned)src_y >= s->v_edge_pos - 17){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
88 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
89 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
90 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
91 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
92
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
93 if((motion_x|motion_y)&7){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
94 s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
95 s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
96 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
97 int dxy;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
98
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
99 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
100 if (s->no_rounding){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
101 s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
102 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
103 s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
104 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
105 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
106
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
107 if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return;
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
108
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
109 motion_x= s->sprite_offset[1][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
110 motion_y= s->sprite_offset[1][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
111 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
112 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
113 motion_x<<=(3-s->sprite_warping_accuracy);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
114 motion_y<<=(3-s->sprite_warping_accuracy);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
115 src_x = av_clip(src_x, -8, s->width>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
116 if (src_x == s->width>>1)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
117 motion_x =0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
118 src_y = av_clip(src_y, -8, s->height>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
119 if (src_y == s->height>>1)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
120 motion_y =0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
121
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
122 offset = (src_y * uvlinesize) + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
123 ptr = ref_picture[1] + offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
124 if(s->flags&CODEC_FLAG_EMU_EDGE){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
125 if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
126 || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
127 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
128 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
129 emu=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
130 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
131 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
132 s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
133
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
134 ptr = ref_picture[2] + offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
135 if(emu){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
136 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
137 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
138 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
139 s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
140
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
141 return;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
142 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
143
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
144 static inline void gmc_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
145 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
146 uint8_t **ref_picture)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
147 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
148 uint8_t *ptr;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
149 int linesize, uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
150 const int a= s->sprite_warping_accuracy;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
151 int ox, oy;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
152
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
153 linesize = s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
154 uvlinesize = s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
155
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
156 ptr = ref_picture[0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
157
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
158 ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
159 oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
160
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
161 s->dsp.gmc(dest_y, ptr, linesize, 16,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
162 ox,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
163 oy,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
164 s->sprite_delta[0][0], s->sprite_delta[0][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
165 s->sprite_delta[1][0], s->sprite_delta[1][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
166 a+1, (1<<(2*a+1)) - s->no_rounding,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
167 s->h_edge_pos, s->v_edge_pos);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
168 s->dsp.gmc(dest_y+8, ptr, linesize, 16,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
169 ox + s->sprite_delta[0][0]*8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
170 oy + s->sprite_delta[1][0]*8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
171 s->sprite_delta[0][0], s->sprite_delta[0][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
172 s->sprite_delta[1][0], s->sprite_delta[1][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
173 a+1, (1<<(2*a+1)) - s->no_rounding,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
174 s->h_edge_pos, s->v_edge_pos);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
175
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
176 if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return;
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
177
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
178 ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
179 oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
180
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
181 ptr = ref_picture[1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
182 s->dsp.gmc(dest_cb, ptr, uvlinesize, 8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
183 ox,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
184 oy,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
185 s->sprite_delta[0][0], s->sprite_delta[0][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
186 s->sprite_delta[1][0], s->sprite_delta[1][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
187 a+1, (1<<(2*a+1)) - s->no_rounding,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
188 s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
189
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
190 ptr = ref_picture[2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
191 s->dsp.gmc(dest_cr, ptr, uvlinesize, 8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
192 ox,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
193 oy,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
194 s->sprite_delta[0][0], s->sprite_delta[0][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
195 s->sprite_delta[1][0], s->sprite_delta[1][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
196 a+1, (1<<(2*a+1)) - s->no_rounding,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
197 s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
198 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
199
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
200 static inline int hpel_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
201 uint8_t *dest, uint8_t *src,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
202 int field_based, int field_select,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
203 int src_x, int src_y,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
204 int width, int height, int stride,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
205 int h_edge_pos, int v_edge_pos,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
206 int w, int h, op_pixels_func *pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
207 int motion_x, int motion_y)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
208 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
209 int dxy;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
210 int emu=0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
211
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
212 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
213 src_x += motion_x >> 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
214 src_y += motion_y >> 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
215
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
216 /* WARNING: do no forget half pels */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
217 src_x = av_clip(src_x, -16, width); //FIXME unneeded for emu?
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
218 if (src_x == width)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
219 dxy &= ~1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
220 src_y = av_clip(src_y, -16, height);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
221 if (src_y == height)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
222 dxy &= ~2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
223 src += src_y * stride + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
224
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
225 if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
226 if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
227 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
228 ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
229 src_x, src_y<<field_based, h_edge_pos, s->v_edge_pos);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
230 src= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
231 emu=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
232 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
233 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
234 if(field_select)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
235 src += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
236 pix_op[dxy](dest, src, stride, h);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
237 return emu;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
238 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
239
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
240 /* apply one mpeg motion vector to the three components */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
241 static av_always_inline void mpeg_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
242 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
243 int field_based, int bottom_field, int field_select,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
244 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
245 int motion_x, int motion_y, int h)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
246 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
247 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
248 int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
249
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
250 #if 0
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
251 if(s->quarter_sample)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
252 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
253 motion_x>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
254 motion_y>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
255 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
256 #endif
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
257
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
258 v_edge_pos = s->v_edge_pos >> field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
259 linesize = s->current_picture.linesize[0] << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
260 uvlinesize = s->current_picture.linesize[1] << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
261
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
262 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
263 src_x = s->mb_x* 16 + (motion_x >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
264 src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
265
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
266 if (s->out_format == FMT_H263) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
267 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
268 mx = (motion_x>>1)|(motion_x&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
269 my = motion_y >>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
270 uvdxy = ((my & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
271 uvsrc_x = s->mb_x* 8 + (mx >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
272 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
273 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
274 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
275 uvsrc_x = src_x>>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
276 uvsrc_y = src_y>>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
277 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
278 }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
279 mx = motion_x / 4;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
280 my = motion_y / 4;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
281 uvdxy = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
282 uvsrc_x = s->mb_x*8 + mx;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
283 uvsrc_y = s->mb_y*8 + my;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
284 } else {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
285 if(s->chroma_y_shift){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
286 mx = motion_x / 2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
287 my = motion_y / 2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
288 uvdxy = ((my & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
289 uvsrc_x = s->mb_x* 8 + (mx >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
290 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
291 } else {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
292 if(s->chroma_x_shift){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
293 //Chroma422
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
294 mx = motion_x / 2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
295 uvdxy = ((motion_y & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
296 uvsrc_x = s->mb_x* 8 + (mx >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
297 uvsrc_y = src_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
298 } else {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
299 //Chroma444
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
300 uvdxy = dxy;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
301 uvsrc_x = src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
302 uvsrc_y = src_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
303 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
304 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
305 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
306
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
307 ptr_y = ref_picture[0] + src_y * linesize + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
308 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
309 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
310
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
311 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
312 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
313 if(s->codec_id == CODEC_ID_MPEG2VIDEO ||
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
314 s->codec_id == CODEC_ID_MPEG1VIDEO){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
315 av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n");
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
316 return ;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
317 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
318 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
319 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
320 ptr_y = s->edge_emu_buffer;
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
321 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
322 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
323 ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
324 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
325 ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
326 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
327 ptr_cb= uvbuf;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
328 ptr_cr= uvbuf+16;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
329 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
330 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
331
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
332 if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
333 dest_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
334 dest_cb+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
335 dest_cr+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
336 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
337
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
338 if(field_select){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
339 ptr_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
340 ptr_cb+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
341 ptr_cr+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
342 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
343
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
344 pix_op[0][dxy](dest_y, ptr_y, linesize, h);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
345
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
346 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
347 pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
348 pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
349 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
350 if((ENABLE_H261_ENCODER || ENABLE_H261_DECODER) && s->out_format == FMT_H261){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
351 ff_h261_loop_filter(s);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
352 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
353 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
354
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
355 //FIXME move to dsputil, avg variant, 16x16 version
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
356 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
357 int x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
358 uint8_t * const top = src[1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
359 uint8_t * const left = src[2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
360 uint8_t * const mid = src[0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
361 uint8_t * const right = src[3];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
362 uint8_t * const bottom= src[4];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
363 #define OBMC_FILTER(x, t, l, m, r, b)\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
364 dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
365 #define OBMC_FILTER4(x, t, l, m, r, b)\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
366 OBMC_FILTER(x , t, l, m, r, b);\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
367 OBMC_FILTER(x+1 , t, l, m, r, b);\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
368 OBMC_FILTER(x +stride, t, l, m, r, b);\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
369 OBMC_FILTER(x+1+stride, t, l, m, r, b);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
370
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
371 x=0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
372 OBMC_FILTER (x , 2, 2, 4, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
373 OBMC_FILTER (x+1, 2, 1, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
374 OBMC_FILTER4(x+2, 2, 1, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
375 OBMC_FILTER4(x+4, 2, 0, 5, 1, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
376 OBMC_FILTER (x+6, 2, 0, 5, 1, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
377 OBMC_FILTER (x+7, 2, 0, 4, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
378 x+= stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
379 OBMC_FILTER (x , 1, 2, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
380 OBMC_FILTER (x+1, 1, 2, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
381 OBMC_FILTER (x+6, 1, 0, 5, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
382 OBMC_FILTER (x+7, 1, 0, 5, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
383 x+= stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
384 OBMC_FILTER4(x , 1, 2, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
385 OBMC_FILTER4(x+2, 1, 1, 6, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
386 OBMC_FILTER4(x+4, 1, 0, 6, 1, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
387 OBMC_FILTER4(x+6, 1, 0, 5, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
388 x+= 2*stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
389 OBMC_FILTER4(x , 0, 2, 5, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
390 OBMC_FILTER4(x+2, 0, 1, 6, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
391 OBMC_FILTER4(x+4, 0, 0, 6, 1, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
392 OBMC_FILTER4(x+6, 0, 0, 5, 2, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
393 x+= 2*stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
394 OBMC_FILTER (x , 0, 2, 5, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
395 OBMC_FILTER (x+1, 0, 2, 5, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
396 OBMC_FILTER4(x+2, 0, 1, 5, 0, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
397 OBMC_FILTER4(x+4, 0, 0, 5, 1, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
398 OBMC_FILTER (x+6, 0, 0, 5, 2, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
399 OBMC_FILTER (x+7, 0, 0, 5, 2, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
400 x+= stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
401 OBMC_FILTER (x , 0, 2, 4, 0, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
402 OBMC_FILTER (x+1, 0, 1, 5, 0, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
403 OBMC_FILTER (x+6, 0, 0, 5, 1, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
404 OBMC_FILTER (x+7, 0, 0, 4, 2, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
405 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
406
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
407 /* obmc for 1 8x8 luma block */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
408 static inline void obmc_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
409 uint8_t *dest, uint8_t *src,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
410 int src_x, int src_y,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
411 op_pixels_func *pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
412 int16_t mv[5][2]/* mid top left right bottom*/)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
413 #define MID 0
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
414 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
415 int i;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
416 uint8_t *ptr[5];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
417
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
418 assert(s->quarter_sample==0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
419
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
420 for(i=0; i<5; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
421 if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
422 ptr[i]= ptr[MID];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
423 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
424 ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
425 hpel_motion(s, ptr[i], src, 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
426 src_x, src_y,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
427 s->width, s->height, s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
428 s->h_edge_pos, s->v_edge_pos,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
429 8, 8, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
430 mv[i][0], mv[i][1]);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
431 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
432 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
433
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
434 put_obmc(dest, ptr, s->linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
435 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
436
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
437 static inline void qpel_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
438 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
439 int field_based, int bottom_field, int field_select,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
440 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
441 qpel_mc_func (*qpix_op)[16],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
442 int motion_x, int motion_y, int h)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
443 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
444 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
445 int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
446
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
447 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
448 src_x = s->mb_x * 16 + (motion_x >> 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
449 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
450
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
451 v_edge_pos = s->v_edge_pos >> field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
452 linesize = s->linesize << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
453 uvlinesize = s->uvlinesize << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
454
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
455 if(field_based){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
456 mx= motion_x/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
457 my= motion_y>>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
458 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
459 static const int rtab[8]= {0,0,1,1,0,0,0,1};
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
460 mx= (motion_x>>1) + rtab[motion_x&7];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
461 my= (motion_y>>1) + rtab[motion_y&7];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
462 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
463 mx= (motion_x>>1)|(motion_x&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
464 my= (motion_y>>1)|(motion_y&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
465 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
466 mx= motion_x/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
467 my= motion_y/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
468 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
469 mx= (mx>>1)|(mx&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
470 my= (my>>1)|(my&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
471
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
472 uvdxy= (mx&1) | ((my&1)<<1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
473 mx>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
474 my>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
475
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
476 uvsrc_x = s->mb_x * 8 + mx;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
477 uvsrc_y = s->mb_y * (8 >> field_based) + my;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
478
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
479 ptr_y = ref_picture[0] + src_y * linesize + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
480 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
481 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
482
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
483 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
484 || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
485 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
486 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
487 ptr_y= s->edge_emu_buffer;
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
488 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
489 uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
490 ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
491 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
492 ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
493 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
494 ptr_cb= uvbuf;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
495 ptr_cr= uvbuf + 16;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
496 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
497 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
498
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
499 if(!field_based)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
500 qpix_op[0][dxy](dest_y, ptr_y, linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
501 else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
502 if(bottom_field){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
503 dest_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
504 dest_cb+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
505 dest_cr+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
506 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
507
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
508 if(field_select){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
509 ptr_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
510 ptr_cb += s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
511 ptr_cr += s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
512 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
513 //damn interlaced mode
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
514 //FIXME boundary mirroring is not exactly correct here
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
515 qpix_op[1][dxy](dest_y , ptr_y , linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
516 qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
517 }
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
518 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
519 pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
520 pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
521 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
522 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
523
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
524 /**
5428
750d76a34871 Fix typo
takis
parents: 5214
diff changeset
525 * h263 chroma 4mv motion compensation.
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
526 */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
527 static inline void chroma_4mv_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
528 uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
529 uint8_t **ref_picture,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
530 op_pixels_func *pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
531 int mx, int my){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
532 int dxy, emu=0, src_x, src_y, offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
533 uint8_t *ptr;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
534
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
535 /* In case of 8X8, we construct a single chroma motion vector
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
536 with a special rounding */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
537 mx= ff_h263_round_chroma(mx);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
538 my= ff_h263_round_chroma(my);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
539
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
540 dxy = ((my & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
541 mx >>= 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
542 my >>= 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
543
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
544 src_x = s->mb_x * 8 + mx;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
545 src_y = s->mb_y * 8 + my;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
546 src_x = av_clip(src_x, -8, s->width/2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
547 if (src_x == s->width/2)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
548 dxy &= ~1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
549 src_y = av_clip(src_y, -8, s->height/2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
550 if (src_y == s->height/2)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
551 dxy &= ~2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
552
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
553 offset = (src_y * (s->uvlinesize)) + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
554 ptr = ref_picture[1] + offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
555 if(s->flags&CODEC_FLAG_EMU_EDGE){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
556 if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
557 || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
558 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
559 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
560 emu=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
561 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
562 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
563 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
564
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
565 ptr = ref_picture[2] + offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
566 if(emu){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
567 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
568 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
569 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
570 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
571 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
572
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
573 static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
574 /* fetch pixels for estimated mv 4 macroblocks ahead
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
575 * optimized for 64byte cache lines */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
576 const int shift = s->quarter_sample ? 2 : 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
577 const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
578 const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
579 int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
580 s->dsp.prefetch(pix[0]+off, s->linesize, 4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
581 off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
582 s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
583 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
584
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
585 /**
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
586 * motion compensation of a single macroblock
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
587 * @param s context
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
588 * @param dest_y luma destination pointer
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
589 * @param dest_cb chroma cb/u destination pointer
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
590 * @param dest_cr chroma cr/v destination pointer
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
591 * @param dir direction (0->forward, 1->backward)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
592 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
593 * @param pic_op halfpel motion compensation function (average or put normally)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
594 * @param pic_op qpel motion compensation function (average or put normally)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
595 * the motion vectors are taken from s->mv and the MV type from s->mv_type
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
596 */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
597 static inline void MPV_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
598 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
599 int dir, uint8_t **ref_picture,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
600 op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
601 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
602 int dxy, mx, my, src_x, src_y, motion_x, motion_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
603 int mb_x, mb_y, i;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
604 uint8_t *ptr, *dest;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
605
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
606 mb_x = s->mb_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
607 mb_y = s->mb_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
608
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
609 prefetch_motion(s, ref_picture, dir);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
610
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
611 if(s->obmc && s->pict_type != B_TYPE){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
612 int16_t mv_cache[4][4][2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
613 const int xy= s->mb_x + s->mb_y*s->mb_stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
614 const int mot_stride= s->b8_stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
615 const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
616
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
617 assert(!s->mb_skipped);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
618
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
619 memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
620 memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
621 memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
622
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
623 if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
624 memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
625 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
626 memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
627 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
628
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
629 if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
630 *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
631 *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
632 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
633 *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
634 *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
635 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
636
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
637 if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
638 *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
639 *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
640 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
641 *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
642 *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
643 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
644
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
645 mx = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
646 my = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
647 for(i=0;i<4;i++) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
648 const int x= (i&1)+1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
649 const int y= (i>>1)+1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
650 int16_t mv[5][2]= {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
651 {mv_cache[y][x ][0], mv_cache[y][x ][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
652 {mv_cache[y-1][x][0], mv_cache[y-1][x][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
653 {mv_cache[y][x-1][0], mv_cache[y][x-1][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
654 {mv_cache[y][x+1][0], mv_cache[y][x+1][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
655 {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
656 //FIXME cleanup
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
657 obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
658 ref_picture[0],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
659 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
660 pix_op[1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
661 mv);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
662
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
663 mx += mv[0][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
664 my += mv[0][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
665 }
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
666 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
667 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
668
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
669 return;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
670 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
671
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
672 switch(s->mv_type) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
673 case MV_TYPE_16X16:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
674 if(s->mcsel){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
675 if(s->real_sprite_warping_points==1){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
676 gmc1_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
677 ref_picture);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
678 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
679 gmc_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
680 ref_picture);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
681 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
682 }else if(s->quarter_sample){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
683 qpel_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
684 0, 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
685 ref_picture, pix_op, qpix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
686 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
687 }else if(ENABLE_WMV2 && s->mspel){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
688 ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
689 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
690 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
691 }else
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
692 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
693 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
694 0, 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
695 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
696 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
697 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
698 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
699 case MV_TYPE_8X8:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
700 mx = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
701 my = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
702 if(s->quarter_sample){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
703 for(i=0;i<4;i++) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
704 motion_x = s->mv[dir][i][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
705 motion_y = s->mv[dir][i][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
706
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
707 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
708 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
709 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
710
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
711 /* WARNING: do no forget half pels */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
712 src_x = av_clip(src_x, -16, s->width);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
713 if (src_x == s->width)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
714 dxy &= ~3;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
715 src_y = av_clip(src_y, -16, s->height);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
716 if (src_y == s->height)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
717 dxy &= ~12;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
718
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
719 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
720 if(s->flags&CODEC_FLAG_EMU_EDGE){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
721 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
722 || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
723 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
724 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
725 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
726 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
727 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
728 qpix_op[1][dxy](dest, ptr, s->linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
729
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
730 mx += s->mv[dir][i][0]/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
731 my += s->mv[dir][i][1]/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
732 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
733 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
734 for(i=0;i<4;i++) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
735 hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
736 ref_picture[0], 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
737 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
738 s->width, s->height, s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
739 s->h_edge_pos, s->v_edge_pos,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
740 8, 8, pix_op[1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
741 s->mv[dir][i][0], s->mv[dir][i][1]);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
742
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
743 mx += s->mv[dir][i][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
744 my += s->mv[dir][i][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
745 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
746 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
747
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
748 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
749 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
750 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
751 case MV_TYPE_FIELD:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
752 if (s->picture_structure == PICT_FRAME) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
753 if(s->quarter_sample){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
754 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
755 qpel_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
756 1, i, s->field_select[dir][i],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
757 ref_picture, pix_op, qpix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
758 s->mv[dir][i][0], s->mv[dir][i][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
759 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
760 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
761 /* top field */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
762 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
763 1, 0, s->field_select[dir][0],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
764 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
765 s->mv[dir][0][0], s->mv[dir][0][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
766 /* bottom field */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
767 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
768 1, 1, s->field_select[dir][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
769 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
770 s->mv[dir][1][0], s->mv[dir][1][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
771 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
772 } else {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
773 if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
774 ref_picture= s->current_picture_ptr->data;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
775 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
776
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
777 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
778 0, 0, s->field_select[dir][0],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
779 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
780 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
781 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
782 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
783 case MV_TYPE_16X8:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
784 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
785 uint8_t ** ref2picture;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
786
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
787 if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
788 ref2picture= ref_picture;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
789 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
790 ref2picture= s->current_picture_ptr->data;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
791 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
792
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
793 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
794 0, 0, s->field_select[dir][i],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
795 ref2picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
796 s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
797
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
798 dest_y += 16*s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
799 dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
800 dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
801 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
802 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
803 case MV_TYPE_DMV:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
804 if(s->picture_structure == PICT_FRAME){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
805 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
806 int j;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
807 for(j=0; j<2; j++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
808 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
809 1, j, j^i,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
810 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
811 s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
812 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
813 pix_op = s->dsp.avg_pixels_tab;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
814 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
815 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
816 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
817 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
818 0, 0, s->picture_structure != i+1,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
819 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
820 s->mv[dir][2*i][0],s->mv[dir][2*i][1],16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
821
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
822 // after put we make avg of the same block
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
823 pix_op=s->dsp.avg_pixels_tab;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
824
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
825 //opposite parity is always in the same frame if this is second field
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
826 if(!s->first_field){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
827 ref_picture = s->current_picture_ptr->data;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
828 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
829 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
830 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
831 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
832 default: assert(0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
833 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
834 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
835
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
836 #endif /* MPEGVIDEO_COMMON_H */