annotate mpegvideo_common.h @ 6850:521e1b55fc12 libavcodec

Simplify rms()
author vitor
date Sat, 24 May 2008 09:19:21 +0000
parents 4866b892ecbe
children c4a4495715dd
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
5830
1d83e9c34641 Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 5433
diff changeset
30 #ifndef FFMPEG_MPEGVIDEO_COMMON_H
1d83e9c34641 Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 5433
diff changeset
31 #define FFMPEG_MPEGVIDEO_COMMON_H
5204
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
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
240 static av_always_inline
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
241 void mpeg_motion_internal(MpegEncContext *s,
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
242 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
243 int field_based, int bottom_field, int field_select,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
244 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
245 int motion_x, int motion_y, int h, int is_mpeg12)
5204
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;
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
248 int dxy, uvdxy, mx, my, src_x, src_y,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
249 uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
250
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
251 #if 0
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
252 if(s->quarter_sample)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
253 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
254 motion_x>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
255 motion_y>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
256 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
257 #endif
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
258
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
259 v_edge_pos = s->v_edge_pos >> field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
260 linesize = s->current_picture.linesize[0] << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
261 uvlinesize = s->current_picture.linesize[1] << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
262
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
263 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
264 src_x = s->mb_x* 16 + (motion_x >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
265 src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
266
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
267 if (!is_mpeg12 && s->out_format == FMT_H263) {
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
268 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
269 mx = (motion_x>>1)|(motion_x&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
270 my = motion_y >>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
271 uvdxy = ((my & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
272 uvsrc_x = s->mb_x* 8 + (mx >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
273 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
274 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
275 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
276 uvsrc_x = src_x>>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
277 uvsrc_y = src_y>>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
278 }
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
279 }else if(!is_mpeg12 && s->out_format == FMT_H261){//even chroma mv's are full pel in H261
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
280 mx = motion_x / 4;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
281 my = motion_y / 4;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
282 uvdxy = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
283 uvsrc_x = s->mb_x*8 + mx;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
284 uvsrc_y = s->mb_y*8 + my;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
285 } else {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
286 if(s->chroma_y_shift){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
287 mx = motion_x / 2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
288 my = motion_y / 2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
289 uvdxy = ((my & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
290 uvsrc_x = s->mb_x* 8 + (mx >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
291 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
292 } else {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
293 if(s->chroma_x_shift){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
294 //Chroma422
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
295 mx = motion_x / 2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
296 uvdxy = ((motion_y & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
297 uvsrc_x = s->mb_x* 8 + (mx >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
298 uvsrc_y = src_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
299 } else {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
300 //Chroma444
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
301 uvdxy = dxy;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
302 uvsrc_x = src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
303 uvsrc_y = src_y;
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
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
308 ptr_y = ref_picture[0] + src_y * linesize + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
309 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
310 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
311
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
312 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
313 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
314 if(is_mpeg12 || s->codec_id == CODEC_ID_MPEG2VIDEO ||
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
315 s->codec_id == CODEC_ID_MPEG1VIDEO){
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
316 av_log(s->avctx,AV_LOG_DEBUG,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
317 "MPEG motion vector out of boundary\n");
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
318 return ;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
319 }
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
320 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
321 17, 17+field_based,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
322 src_x, src_y<<field_based,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
323 s->h_edge_pos, s->v_edge_pos);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
324 ptr_y = s->edge_emu_buffer;
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
325 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
326 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
327 ff_emulated_edge_mc(uvbuf ,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
328 ptr_cb, s->uvlinesize,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
329 9, 9+field_based,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
330 uvsrc_x, uvsrc_y<<field_based,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
331 s->h_edge_pos>>1, s->v_edge_pos>>1);
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
332 ff_emulated_edge_mc(uvbuf+16,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
333 ptr_cr, s->uvlinesize,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
334 9, 9+field_based,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
335 uvsrc_x, uvsrc_y<<field_based,
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
336 s->h_edge_pos>>1, s->v_edge_pos>>1);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
337 ptr_cb= uvbuf;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
338 ptr_cr= uvbuf+16;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
339 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
340 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
341
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
342 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
343 dest_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
344 dest_cb+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
345 dest_cr+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
346 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
347
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
348 if(field_select){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
349 ptr_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
350 ptr_cb+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
351 ptr_cr+= s->uvlinesize;
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 pix_op[0][dxy](dest_y, ptr_y, linesize, h);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
355
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
356 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
357 pix_op[s->chroma_x_shift][uvdxy]
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
358 (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
359 pix_op[s->chroma_x_shift][uvdxy]
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
360 (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
361 }
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
362 if(!is_mpeg12 && (ENABLE_H261_ENCODER || ENABLE_H261_DECODER) &&
6578
dfa423a2fc78 cosmetics: Break some overly long lines.
diego
parents: 6481
diff changeset
363 s->out_format == FMT_H261){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
364 ff_h261_loop_filter(s);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
365 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
366 }
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
367 /* apply one mpeg motion vector to the three components */
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
368 static av_always_inline
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
369 void mpeg_motion(MpegEncContext *s,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
370 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
371 int field_based, int bottom_field, int field_select,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
372 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
373 int motion_x, int motion_y, int h)
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
374 {
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
375 #ifndef CONFIG_SMALL
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
376 if(s->out_format == FMT_MPEG1)
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
377 mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
378 bottom_field, field_select, ref_picture, pix_op,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
379 motion_x, motion_y, h, 1);
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
380 else
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
381 #endif
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
382 mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
383 bottom_field, field_select, ref_picture, pix_op,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
384 motion_x, motion_y, h, 0);
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
385 }
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
386
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
387 //FIXME move to dsputil, avg variant, 16x16 version
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
388 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
389 int x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
390 uint8_t * const top = src[1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
391 uint8_t * const left = src[2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
392 uint8_t * const mid = src[0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
393 uint8_t * const right = src[3];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
394 uint8_t * const bottom= src[4];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
395 #define OBMC_FILTER(x, t, l, m, r, b)\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
396 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
397 #define OBMC_FILTER4(x, t, l, m, r, b)\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
398 OBMC_FILTER(x , t, l, m, r, b);\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
399 OBMC_FILTER(x+1 , t, l, m, r, b);\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
400 OBMC_FILTER(x +stride, t, l, m, r, b);\
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
401 OBMC_FILTER(x+1+stride, t, l, m, r, b);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
402
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
403 x=0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
404 OBMC_FILTER (x , 2, 2, 4, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
405 OBMC_FILTER (x+1, 2, 1, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
406 OBMC_FILTER4(x+2, 2, 1, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
407 OBMC_FILTER4(x+4, 2, 0, 5, 1, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
408 OBMC_FILTER (x+6, 2, 0, 5, 1, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
409 OBMC_FILTER (x+7, 2, 0, 4, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
410 x+= stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
411 OBMC_FILTER (x , 1, 2, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
412 OBMC_FILTER (x+1, 1, 2, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
413 OBMC_FILTER (x+6, 1, 0, 5, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
414 OBMC_FILTER (x+7, 1, 0, 5, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
415 x+= stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
416 OBMC_FILTER4(x , 1, 2, 5, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
417 OBMC_FILTER4(x+2, 1, 1, 6, 0, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
418 OBMC_FILTER4(x+4, 1, 0, 6, 1, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
419 OBMC_FILTER4(x+6, 1, 0, 5, 2, 0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
420 x+= 2*stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
421 OBMC_FILTER4(x , 0, 2, 5, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
422 OBMC_FILTER4(x+2, 0, 1, 6, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
423 OBMC_FILTER4(x+4, 0, 0, 6, 1, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
424 OBMC_FILTER4(x+6, 0, 0, 5, 2, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
425 x+= 2*stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
426 OBMC_FILTER (x , 0, 2, 5, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
427 OBMC_FILTER (x+1, 0, 2, 5, 0, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
428 OBMC_FILTER4(x+2, 0, 1, 5, 0, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
429 OBMC_FILTER4(x+4, 0, 0, 5, 1, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
430 OBMC_FILTER (x+6, 0, 0, 5, 2, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
431 OBMC_FILTER (x+7, 0, 0, 5, 2, 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
432 x+= stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
433 OBMC_FILTER (x , 0, 2, 4, 0, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
434 OBMC_FILTER (x+1, 0, 1, 5, 0, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
435 OBMC_FILTER (x+6, 0, 0, 5, 1, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
436 OBMC_FILTER (x+7, 0, 0, 4, 2, 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
437 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
438
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
439 /* obmc for 1 8x8 luma block */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
440 static inline void obmc_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
441 uint8_t *dest, uint8_t *src,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
442 int src_x, int src_y,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
443 op_pixels_func *pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
444 int16_t mv[5][2]/* mid top left right bottom*/)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
445 #define MID 0
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
446 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
447 int i;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
448 uint8_t *ptr[5];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
449
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
450 assert(s->quarter_sample==0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
451
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
452 for(i=0; i<5; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
453 if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
454 ptr[i]= ptr[MID];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
455 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
456 ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
457 hpel_motion(s, ptr[i], src, 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
458 src_x, src_y,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
459 s->width, s->height, s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
460 s->h_edge_pos, s->v_edge_pos,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
461 8, 8, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
462 mv[i][0], mv[i][1]);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
463 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
464 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
465
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
466 put_obmc(dest, ptr, s->linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
467 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
468
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
469 static inline void qpel_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
470 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
471 int field_based, int bottom_field, int field_select,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
472 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
473 qpel_mc_func (*qpix_op)[16],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
474 int motion_x, int motion_y, int h)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
475 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
476 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
477 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
478
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
479 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
480 src_x = s->mb_x * 16 + (motion_x >> 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
481 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
482
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
483 v_edge_pos = s->v_edge_pos >> field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
484 linesize = s->linesize << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
485 uvlinesize = s->uvlinesize << field_based;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
486
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
487 if(field_based){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
488 mx= motion_x/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
489 my= motion_y>>1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
490 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
491 static const int rtab[8]= {0,0,1,1,0,0,0,1};
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
492 mx= (motion_x>>1) + rtab[motion_x&7];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
493 my= (motion_y>>1) + rtab[motion_y&7];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
494 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
495 mx= (motion_x>>1)|(motion_x&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
496 my= (motion_y>>1)|(motion_y&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
497 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
498 mx= motion_x/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
499 my= motion_y/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
500 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
501 mx= (mx>>1)|(mx&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
502 my= (my>>1)|(my&1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
503
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
504 uvdxy= (mx&1) | ((my&1)<<1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
505 mx>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
506 my>>=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
507
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
508 uvsrc_x = s->mb_x * 8 + mx;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
509 uvsrc_y = s->mb_y * (8 >> field_based) + my;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
510
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
511 ptr_y = ref_picture[0] + src_y * linesize + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
512 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
513 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
514
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
515 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
516 || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){
6579
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
517 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
518 17, 17+field_based, src_x, src_y<<field_based,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
519 s->h_edge_pos, s->v_edge_pos);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
520 ptr_y= s->edge_emu_buffer;
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
521 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
522 uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
6579
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
523 ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
524 9, 9 + field_based,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
525 uvsrc_x, uvsrc_y<<field_based,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
526 s->h_edge_pos>>1, s->v_edge_pos>>1);
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
527 ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
528 9, 9 + field_based,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
529 uvsrc_x, uvsrc_y<<field_based,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
530 s->h_edge_pos>>1, s->v_edge_pos>>1);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
531 ptr_cb= uvbuf;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
532 ptr_cr= uvbuf + 16;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
533 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
534 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
535
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
536 if(!field_based)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
537 qpix_op[0][dxy](dest_y, ptr_y, linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
538 else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
539 if(bottom_field){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
540 dest_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
541 dest_cb+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
542 dest_cr+= s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
543 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
544
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
545 if(field_select){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
546 ptr_y += s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
547 ptr_cb += s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
548 ptr_cr += s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
549 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
550 //damn interlaced mode
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
551 //FIXME boundary mirroring is not exactly correct here
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
552 qpix_op[1][dxy](dest_y , ptr_y , linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
553 qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
554 }
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
555 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
556 pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
557 pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
558 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
559 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
560
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
561 /**
5428
750d76a34871 Fix typo
takis
parents: 5214
diff changeset
562 * h263 chroma 4mv motion compensation.
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
563 */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
564 static inline void chroma_4mv_motion(MpegEncContext *s,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
565 uint8_t *dest_cb, uint8_t *dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
566 uint8_t **ref_picture,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
567 op_pixels_func *pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
568 int mx, int my){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
569 int dxy, emu=0, src_x, src_y, offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
570 uint8_t *ptr;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
571
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
572 /* In case of 8X8, we construct a single chroma motion vector
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
573 with a special rounding */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
574 mx= ff_h263_round_chroma(mx);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
575 my= ff_h263_round_chroma(my);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
576
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
577 dxy = ((my & 1) << 1) | (mx & 1);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
578 mx >>= 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
579 my >>= 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
580
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
581 src_x = s->mb_x * 8 + mx;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
582 src_y = s->mb_y * 8 + my;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
583 src_x = av_clip(src_x, -8, s->width/2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
584 if (src_x == s->width/2)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
585 dxy &= ~1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
586 src_y = av_clip(src_y, -8, s->height/2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
587 if (src_y == s->height/2)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
588 dxy &= ~2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
589
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
590 offset = (src_y * (s->uvlinesize)) + src_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
591 ptr = ref_picture[1] + offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
592 if(s->flags&CODEC_FLAG_EMU_EDGE){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
593 if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
594 || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){
6579
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
595 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
596 9, 9, src_x, src_y,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
597 s->h_edge_pos>>1, s->v_edge_pos>>1);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
598 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
599 emu=1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
600 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
601 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
602 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
603
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
604 ptr = ref_picture[2] + offset;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
605 if(emu){
6579
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
606 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
607 9, 9, src_x, src_y,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
608 s->h_edge_pos>>1, s->v_edge_pos>>1);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
609 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
610 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
611 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
612 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
613
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
614 static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
615 /* fetch pixels for estimated mv 4 macroblocks ahead
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
616 * optimized for 64byte cache lines */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
617 const int shift = s->quarter_sample ? 2 : 1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
618 const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
619 const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
620 int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
621 s->dsp.prefetch(pix[0]+off, s->linesize, 4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
622 off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
623 s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
624 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
625
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
626 /**
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
627 * motion compensation of a single macroblock
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
628 * @param s context
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
629 * @param dest_y luma destination pointer
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
630 * @param dest_cb chroma cb/u destination pointer
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
631 * @param dest_cr chroma cr/v destination pointer
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
632 * @param dir direction (0->forward, 1->backward)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
633 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
634 * @param pic_op halfpel motion compensation function (average or put normally)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
635 * @param pic_op qpel motion compensation function (average or put normally)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
636 * 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
637 */
6659
4866b892ecbe Force inlining of MPV_motion_internal.
benoit
parents: 6658
diff changeset
638 static av_always_inline void MPV_motion_internal(MpegEncContext *s,
6579
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
639 uint8_t *dest_y, uint8_t *dest_cb,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
640 uint8_t *dest_cr, int dir,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
641 uint8_t **ref_picture,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
642 op_pixels_func (*pix_op)[4],
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
643 qpel_mc_func (*qpix_op)[16], int is_mpeg12)
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
644 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
645 int dxy, mx, my, src_x, src_y, motion_x, motion_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
646 int mb_x, mb_y, i;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
647 uint8_t *ptr, *dest;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
648
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
649 mb_x = s->mb_x;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
650 mb_y = s->mb_y;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
651
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
652 prefetch_motion(s, ref_picture, dir);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
653
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
654 if(!is_mpeg12 && s->obmc && s->pict_type != FF_B_TYPE){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
655 int16_t mv_cache[4][4][2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
656 const int xy= s->mb_x + s->mb_y*s->mb_stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
657 const int mot_stride= s->b8_stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
658 const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
659
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
660 assert(!s->mb_skipped);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
661
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
662 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
663 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
664 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
665
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
666 if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
667 memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
668 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
669 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
670 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
671
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
672 if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
673 *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
674 *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
675 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
676 *(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
677 *(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
678 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
679
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
680 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
681 *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
682 *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
683 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
684 *(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
685 *(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
686 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
687
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
688 mx = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
689 my = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
690 for(i=0;i<4;i++) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
691 const int x= (i&1)+1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
692 const int y= (i>>1)+1;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
693 int16_t mv[5][2]= {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
694 {mv_cache[y][x ][0], mv_cache[y][x ][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
695 {mv_cache[y-1][x][0], mv_cache[y-1][x][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
696 {mv_cache[y][x-1][0], mv_cache[y][x-1][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
697 {mv_cache[y][x+1][0], mv_cache[y][x+1][1]},
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
698 {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
699 //FIXME cleanup
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
700 obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
701 ref_picture[0],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
702 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
703 pix_op[1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
704 mv);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
705
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
706 mx += mv[0][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
707 my += mv[0][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
708 }
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
709 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
710 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
711
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
712 return;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
713 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
714
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
715 switch(s->mv_type) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
716 case MV_TYPE_16X16:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
717 if(s->mcsel){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
718 if(s->real_sprite_warping_points==1){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
719 gmc1_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
720 ref_picture);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
721 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
722 gmc_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
723 ref_picture);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
724 }
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
725 }else if(!is_mpeg12 && s->quarter_sample){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
726 qpel_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
727 0, 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
728 ref_picture, pix_op, qpix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
729 s->mv[dir][0][0], s->mv[dir][0][1], 16);
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
730 }else if(!is_mpeg12 && ENABLE_WMV2 && s->mspel){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
731 ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
732 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
733 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
734 }else
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
735 {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
736 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
737 0, 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
738 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
739 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
740 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
741 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
742 case MV_TYPE_8X8:
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
743 if (!is_mpeg12) {
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
744 mx = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
745 my = 0;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
746 if(s->quarter_sample){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
747 for(i=0;i<4;i++) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
748 motion_x = s->mv[dir][i][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
749 motion_y = s->mv[dir][i][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
750
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
751 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
752 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
753 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
754
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
755 /* WARNING: do no forget half pels */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
756 src_x = av_clip(src_x, -16, s->width);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
757 if (src_x == s->width)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
758 dxy &= ~3;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
759 src_y = av_clip(src_y, -16, s->height);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
760 if (src_y == s->height)
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
761 dxy &= ~12;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
762
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
763 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
764 if(s->flags&CODEC_FLAG_EMU_EDGE){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
765 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
766 || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){
6579
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
767 ff_emulated_edge_mc(s->edge_emu_buffer, ptr,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
768 s->linesize, 9, 9,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
769 src_x, src_y,
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
770 s->h_edge_pos, s->v_edge_pos);
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
771 ptr= s->edge_emu_buffer;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
772 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
773 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
774 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
775 qpix_op[1][dxy](dest, ptr, s->linesize);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
776
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
777 mx += s->mv[dir][i][0]/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
778 my += s->mv[dir][i][1]/2;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
779 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
780 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
781 for(i=0;i<4;i++) {
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
782 hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
783 ref_picture[0], 0, 0,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
784 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
785 s->width, s->height, s->linesize,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
786 s->h_edge_pos, s->v_edge_pos,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
787 8, 8, pix_op[1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
788 s->mv[dir][i][0], s->mv[dir][i][1]);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
789
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
790 mx += s->mv[dir][i][0];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
791 my += s->mv[dir][i][1];
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
792 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
793 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
794
5433
ce0db8111f94 make grayscale only decoding checks in inner loops compiletime killable
michael
parents: 5428
diff changeset
795 if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
796 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
797 }
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
798 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
799 case MV_TYPE_FIELD:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
800 if (s->picture_structure == PICT_FRAME) {
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
801 if(!is_mpeg12 && s->quarter_sample){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
802 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
803 qpel_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
804 1, i, s->field_select[dir][i],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
805 ref_picture, pix_op, qpix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
806 s->mv[dir][i][0], s->mv[dir][i][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
807 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
808 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
809 /* top field */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
810 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
811 1, 0, s->field_select[dir][0],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
812 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
813 s->mv[dir][0][0], s->mv[dir][0][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
814 /* bottom field */
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
815 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
816 1, 1, s->field_select[dir][1],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
817 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
818 s->mv[dir][1][0], s->mv[dir][1][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
819 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
820 } else {
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5830
diff changeset
821 if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != FF_B_TYPE && !s->first_field){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
822 ref_picture= s->current_picture_ptr->data;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
823 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
824
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
825 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
826 0, 0, s->field_select[dir][0],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
827 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
828 s->mv[dir][0][0], s->mv[dir][0][1], 16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
829 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
830 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
831 case MV_TYPE_16X8:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
832 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
833 uint8_t ** ref2picture;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
834
6579
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
835 if(s->picture_structure == s->field_select[dir][i] + 1
bd5c42ff9e27 cosmetics: Break some overly long lines.
diego
parents: 6578
diff changeset
836 || s->pict_type == FF_B_TYPE || s->first_field){
5204
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
837 ref2picture= ref_picture;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
838 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
839 ref2picture= s->current_picture_ptr->data;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
840 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
841
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
842 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
843 0, 0, s->field_select[dir][i],
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
844 ref2picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
845 s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
846
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
847 dest_y += 16*s->linesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
848 dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
849 dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
850 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
851 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
852 case MV_TYPE_DMV:
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
853 if(s->picture_structure == PICT_FRAME){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
854 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
855 int j;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
856 for(j=0; j<2; j++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
857 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
858 1, j, j^i,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
859 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
860 s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
861 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
862 pix_op = s->dsp.avg_pixels_tab;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
863 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
864 }else{
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
865 for(i=0; i<2; i++){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
866 mpeg_motion(s, dest_y, dest_cb, dest_cr,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
867 0, 0, s->picture_structure != i+1,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
868 ref_picture, pix_op,
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
869 s->mv[dir][2*i][0],s->mv[dir][2*i][1],16);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
870
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
871 // after put we make avg of the same block
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
872 pix_op=s->dsp.avg_pixels_tab;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
873
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
874 //opposite parity is always in the same frame if this is second field
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
875 if(!s->first_field){
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
876 ref_picture = s->current_picture_ptr->data;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
877 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
878 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
879 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
880 break;
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
881 default: assert(0);
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
882 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
883 }
1c3baf4323bb Description: split mpegvideo.c
benoit
parents:
diff changeset
884
6658
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
885 static inline void MPV_motion(MpegEncContext *s,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
886 uint8_t *dest_y, uint8_t *dest_cb,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
887 uint8_t *dest_cr, int dir,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
888 uint8_t **ref_picture,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
889 op_pixels_func (*pix_op)[4],
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
890 qpel_mc_func (*qpix_op)[16])
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
891 {
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
892 #ifndef CONFIG_SMALL
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
893 if(s->out_format == FMT_MPEG1)
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
894 MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
895 ref_picture, pix_op, qpix_op, 1);
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
896 else
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
897 #endif
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
898 MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
899 ref_picture, pix_op, qpix_op, 0);
7ecd59aa5757 Unroll codepath
benoit
parents: 6579
diff changeset
900 }
5830
1d83e9c34641 Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 5433
diff changeset
901 #endif /* FFMPEG_MPEGVIDEO_COMMON_H */