• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/wmv2.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2002 The FFmpeg Project
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include "avcodec.h"
00022 #include "mpegvideo.h"
00023 #include "msmpeg4data.h"
00024 #include "simple_idct.h"
00025 #include "wmv2.h"
00026 
00027 
00028 av_cold void ff_wmv2_common_init(Wmv2Context * w){
00029     MpegEncContext * const s= &w->s;
00030 
00031     ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0], wmv2_scantableA);
00032     ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1], wmv2_scantableB);
00033 }
00034 
00035 static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
00036     MpegEncContext * const s= &w->s;
00037 
00038   if (s->block_last_index[n] >= 0) {
00039     switch(w->abt_type_table[n]){
00040     case 0:
00041         s->dsp.idct_add (dst, stride, block1);
00042         break;
00043     case 1:
00044         ff_simple_idct84_add(dst           , stride, block1);
00045         ff_simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);
00046         s->dsp.clear_block(w->abt_block2[n]);
00047         break;
00048     case 2:
00049         ff_simple_idct48_add(dst           , stride, block1);
00050         ff_simple_idct48_add(dst + 4       , stride, w->abt_block2[n]);
00051         s->dsp.clear_block(w->abt_block2[n]);
00052         break;
00053     default:
00054         av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
00055     }
00056   }
00057 }
00058 
00059 void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
00060     Wmv2Context * const w= (Wmv2Context*)s;
00061 
00062     wmv2_add_block(w, block1[0], dest_y                    , s->linesize, 0);
00063     wmv2_add_block(w, block1[1], dest_y + 8                , s->linesize, 1);
00064     wmv2_add_block(w, block1[2], dest_y +     8*s->linesize, s->linesize, 2);
00065     wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);
00066 
00067     if(s->flags&CODEC_FLAG_GRAY) return;
00068 
00069     wmv2_add_block(w, block1[4], dest_cb                   , s->uvlinesize, 4);
00070     wmv2_add_block(w, block1[5], dest_cr                   , s->uvlinesize, 5);
00071 }
00072 
00073 void ff_mspel_motion(MpegEncContext *s,
00074                                uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
00075                                uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
00076                                int motion_x, int motion_y, int h)
00077 {
00078     Wmv2Context * const w= (Wmv2Context*)s;
00079     uint8_t *ptr;
00080     int dxy, offset, mx, my, src_x, src_y, v_edge_pos, linesize, uvlinesize;
00081     int emu=0;
00082 
00083     dxy = ((motion_y & 1) << 1) | (motion_x & 1);
00084     dxy = 2*dxy + w->hshift;
00085     src_x = s->mb_x * 16 + (motion_x >> 1);
00086     src_y = s->mb_y * 16 + (motion_y >> 1);
00087 
00088     /* WARNING: do no forget half pels */
00089     v_edge_pos = s->v_edge_pos;
00090     src_x = av_clip(src_x, -16, s->width);
00091     src_y = av_clip(src_y, -16, s->height);
00092 
00093     if(src_x<=-16 || src_x >= s->width)
00094         dxy &= ~3;
00095     if(src_y<=-16 || src_y >= s->height)
00096         dxy &= ~4;
00097 
00098     linesize   = s->linesize;
00099     uvlinesize = s->uvlinesize;
00100     ptr = ref_picture[0] + (src_y * linesize) + src_x;
00101 
00102     if(s->flags&CODEC_FLAG_EMU_EDGE){
00103         if(src_x<1 || src_y<1 || src_x + 17  >= s->h_edge_pos
00104                               || src_y + h+1 >= v_edge_pos){
00105             ff_emulated_edge_mc(s->edge_emu_buffer, ptr - 1 - s->linesize, s->linesize, 19, 19,
00106                              src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos);
00107             ptr= s->edge_emu_buffer + 1 + s->linesize;
00108             emu=1;
00109         }
00110     }
00111 
00112     s->dsp.put_mspel_pixels_tab[dxy](dest_y             , ptr             , linesize);
00113     s->dsp.put_mspel_pixels_tab[dxy](dest_y+8           , ptr+8           , linesize);
00114     s->dsp.put_mspel_pixels_tab[dxy](dest_y  +8*linesize, ptr  +8*linesize, linesize);
00115     s->dsp.put_mspel_pixels_tab[dxy](dest_y+8+8*linesize, ptr+8+8*linesize, linesize);
00116 
00117     if(s->flags&CODEC_FLAG_GRAY) return;
00118 
00119     if (s->out_format == FMT_H263) {
00120         dxy = 0;
00121         if ((motion_x & 3) != 0)
00122             dxy |= 1;
00123         if ((motion_y & 3) != 0)
00124             dxy |= 2;
00125         mx = motion_x >> 2;
00126         my = motion_y >> 2;
00127     } else {
00128         mx = motion_x / 2;
00129         my = motion_y / 2;
00130         dxy = ((my & 1) << 1) | (mx & 1);
00131         mx >>= 1;
00132         my >>= 1;
00133     }
00134 
00135     src_x = s->mb_x * 8 + mx;
00136     src_y = s->mb_y * 8 + my;
00137     src_x = av_clip(src_x, -8, s->width >> 1);
00138     if (src_x == (s->width >> 1))
00139         dxy &= ~1;
00140     src_y = av_clip(src_y, -8, s->height >> 1);
00141     if (src_y == (s->height >> 1))
00142         dxy &= ~2;
00143     offset = (src_y * uvlinesize) + src_x;
00144     ptr = ref_picture[1] + offset;
00145     if(emu){
00146         ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
00147                          src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
00148         ptr= s->edge_emu_buffer;
00149     }
00150     pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
00151 
00152     ptr = ref_picture[2] + offset;
00153     if(emu){
00154         ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
00155                          src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
00156         ptr= s->edge_emu_buffer;
00157     }
00158     pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);
00159 }

Generated on Fri Sep 16 2011 17:17:46 for FFmpeg by  doxygen 1.7.1