wmv2.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 The Libav Project
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "avcodec.h"
22 #include "mpegvideo.h"
23 #include "msmpeg4data.h"
24 #include "simple_idct.h"
25 #include "wmv2.h"
26 
27 
29  MpegEncContext * const s= &w->s;
30 
33 }
34 
35 static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
36  MpegEncContext * const s= &w->s;
37 
38  if (s->block_last_index[n] >= 0) {
39  switch(w->abt_type_table[n]){
40  case 0:
41  s->dsp.idct_add (dst, stride, block1);
42  break;
43  case 1:
44  ff_simple_idct84_add(dst , stride, block1);
45  ff_simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);
46  s->dsp.clear_block(w->abt_block2[n]);
47  break;
48  case 2:
49  ff_simple_idct48_add(dst , stride, block1);
50  ff_simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);
51  s->dsp.clear_block(w->abt_block2[n]);
52  break;
53  default:
54  av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
55  }
56  }
57 }
58 
59 void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
60  Wmv2Context * const w= (Wmv2Context*)s;
61 
62  wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);
63  wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);
64  wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);
65  wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);
66 
67  if(s->flags&CODEC_FLAG_GRAY) return;
68 
69  wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);
70  wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);
71 }
72 
74  uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
75  uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
76  int motion_x, int motion_y, int h)
77 {
78  Wmv2Context * const w= (Wmv2Context*)s;
79  uint8_t *ptr;
80  int dxy, offset, mx, my, src_x, src_y, v_edge_pos, linesize, uvlinesize;
81  int emu=0;
82 
83  dxy = ((motion_y & 1) << 1) | (motion_x & 1);
84  dxy = 2*dxy + w->hshift;
85  src_x = s->mb_x * 16 + (motion_x >> 1);
86  src_y = s->mb_y * 16 + (motion_y >> 1);
87 
88  /* WARNING: do no forget half pels */
89  v_edge_pos = s->v_edge_pos;
90  src_x = av_clip(src_x, -16, s->width);
91  src_y = av_clip(src_y, -16, s->height);
92 
93  if(src_x<=-16 || src_x >= s->width)
94  dxy &= ~3;
95  if(src_y<=-16 || src_y >= s->height)
96  dxy &= ~4;
97 
98  linesize = s->linesize;
99  uvlinesize = s->uvlinesize;
100  ptr = ref_picture[0] + (src_y * linesize) + src_x;
101 
102  if(s->flags&CODEC_FLAG_EMU_EDGE){
103  if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos
104  || src_y + h+1 >= v_edge_pos){
105  s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr - 1 - s->linesize, s->linesize, 19, 19,
106  src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos);
107  ptr= s->edge_emu_buffer + 1 + s->linesize;
108  emu=1;
109  }
110  }
111 
112  s->dsp.put_mspel_pixels_tab[dxy](dest_y , ptr , linesize);
113  s->dsp.put_mspel_pixels_tab[dxy](dest_y+8 , ptr+8 , linesize);
114  s->dsp.put_mspel_pixels_tab[dxy](dest_y +8*linesize, ptr +8*linesize, linesize);
115  s->dsp.put_mspel_pixels_tab[dxy](dest_y+8+8*linesize, ptr+8+8*linesize, linesize);
116 
117  if(s->flags&CODEC_FLAG_GRAY) return;
118 
119  if (s->out_format == FMT_H263) {
120  dxy = 0;
121  if ((motion_x & 3) != 0)
122  dxy |= 1;
123  if ((motion_y & 3) != 0)
124  dxy |= 2;
125  mx = motion_x >> 2;
126  my = motion_y >> 2;
127  } else {
128  mx = motion_x / 2;
129  my = motion_y / 2;
130  dxy = ((my & 1) << 1) | (mx & 1);
131  mx >>= 1;
132  my >>= 1;
133  }
134 
135  src_x = s->mb_x * 8 + mx;
136  src_y = s->mb_y * 8 + my;
137  src_x = av_clip(src_x, -8, s->width >> 1);
138  if (src_x == (s->width >> 1))
139  dxy &= ~1;
140  src_y = av_clip(src_y, -8, s->height >> 1);
141  if (src_y == (s->height >> 1))
142  dxy &= ~2;
143  offset = (src_y * uvlinesize) + src_x;
144  ptr = ref_picture[1] + offset;
145  if(emu){
146  s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
147  src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
148  ptr= s->edge_emu_buffer;
149  }
150  pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
151 
152  ptr = ref_picture[2] + offset;
153  if(emu){
154  s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
155  src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
156  ptr= s->edge_emu_buffer;
157  }
158  pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);
159 }
void(* emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
Motion estimation with emulated edge values.
Definition: dsputil.h:253
void(* idct_add)(uint8_t *dest, int line_size, DCTELEM *block)
block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
Definition: dsputil.h:491
int v_edge_pos
horizontal / vertical position of the right/bottom edge (pixel replication)
Definition: mpegvideo.h:241
int abt_type_table[6]
Definition: wmv2.h:42
mpegvideo header.
DCTELEM abt_block2[6][64]
Definition: wmv2.h:53
int stride
Definition: mace.c:143
#define av_cold
Definition: attributes.h:71
enum OutputFormat out_format
output format
Definition: mpegvideo.h:209
void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr)
Definition: wmv2.c:59
MSMPEG4 data tables.
uint8_t idct_permutation[64]
idct input permutation.
Definition: dsputil.h:505
MpegEncContext s
Definition: wmv2.h:36
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:640
qpel_mc_func put_mspel_pixels_tab[8]
Definition: dsputil.h:363
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
Definition: mpegvideo.h:319
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n)
Definition: wmv2.c:35
void(* clear_block)(DCTELEM *block)
Definition: dsputil.h:265
#define CODEC_FLAG_EMU_EDGE
Don't draw edges.
Definition: avcodec.h:641
void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
Definition: simple_idct.c:177
static DCTELEM block1[64]
Definition: dct-test.c:190
ScanTable abt_scantable[2]
Definition: wmv2.h:52
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:251
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
Definition: dsputil.h:157
external API header
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
const uint8_t wmv2_scantableA[64]
Definition: msmpeg4data.c:1989
DSPContext dsp
pointers for accelerated dsp functions
Definition: mpegvideo.h:343
short DCTELEM
Definition: dsputil.h:39
MpegEncContext.
Definition: mpegvideo.h:201
struct AVCodecContext * avctx
Definition: mpegvideo.h:203
void ff_mspel_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture, op_pixels_func(*pix_op)[4], int motion_x, int motion_y, int h)
Definition: wmv2.c:73
int hshift
Definition: wmv2.h:50
simple idct header.
void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
Definition: dsputil.c:124
av_cold void ff_wmv2_common_init(Wmv2Context *w)
Definition: wmv2.c:28
int linesize
line size, in bytes, may be different from width
Definition: mpegvideo.h:243
int flags
AVCodecContext.flags (HQ, MV4, ...)
Definition: mpegvideo.h:220
void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
Definition: simple_idct.c:192
int uvlinesize
line size, for chroma in bytes, may be different from width
Definition: mpegvideo.h:244
const uint8_t wmv2_scantableB[64]
Definition: msmpeg4data.c:1996