📄 motion_functions.c
字号:
/* <LIC_AMD_STD> * Copyright (c) 2005 Advanced Micro Devices, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * The full GNU General Public License is included in this distribution in the * file called COPYING * </LIC_AMD_STD> *//* <CTL_AMD_STD> * </CTL_AMD_STD> *//* <DOC_AMD_STD> * </DOC_AMD_STD> */#include "config.h"#include <inttypes.h>//#include <string.h>#include "mpeg2.h"#include "attributes.h"#include "mpeg2_internal.h"#include "vlc.h"#include "defines.h"#include "mae_pass_thru.h"void motion_mp1 (mpeg2_decoder_t * const, motion_t * const, mpeg2_mc_fct * const *const);void motion_fr_frame_420 (mpeg2_decoder_t * const, motion_t * const, mpeg2_mc_fct * const *const);void motion_fr_field_420 (mpeg2_decoder_t * const , motion_t * const , mpeg2_mc_fct * const *const );void motion_fr_dmv_420 (mpeg2_decoder_t * const , motion_t * const , mpeg2_mc_fct * const *const );void motion_reuse_420 (mpeg2_decoder_t * const , motion_t * const , mpeg2_mc_fct * const *const );void motion_zero_420 (mpeg2_decoder_t * const , motion_t * const , mpeg2_mc_fct * const *const );void motion_fi_field_420 (mpeg2_decoder_t * const , motion_t * const , mpeg2_mc_fct * const *const );void motion_fi_16x8_420 (mpeg2_decoder_t * const , motion_t * const , mpeg2_mc_fct * const *const );void motion_fi_dmv_420 (mpeg2_decoder_t * const , motion_t * const , mpeg2_mc_fct * const *const );void motion_fr_frame_422 (mpeg2_decoder_t * const a, motion_t * const b , mpeg2_mc_fct * const *const c){};void motion_fr_field_422 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fr_dmv_422 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_reuse_422 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_zero_422 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fi_field_422 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fi_16x8_422 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fi_dmv_422 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fr_frame_444 (mpeg2_decoder_t * const a , motion_t * const b , mpeg2_mc_fct * const *const c ){};void motion_fr_field_444 (mpeg2_decoder_t * const a, motion_t * const b , mpeg2_mc_fct * const *const c){};void motion_fr_dmv_444 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_reuse_444 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_zero_444 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fi_field_444 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fi_16x8_444 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fi_dmv_444 (mpeg2_decoder_t * const a, motion_t * const b, mpeg2_mc_fct * const *const c){};void motion_fr_conceal (mpeg2_decoder_t * const );void motion_fi_conceal (mpeg2_decoder_t * const );int get_motion_delta (mpeg2_decoder_t * const , const int );int bound_motion_vector (const int , const int );int get_dmv (mpeg2_decoder_t * const );#ifdef NO_PERFvoid MotionCompInterChecksRefBlocks (mpeg2_decoder_t * const , unsigned char *, int , int , int ,int );void MotionCompInterChecksRefBlocksDMV (mpeg2_decoder_t * const , unsigned char *, int , int , int ,int ,int);void MotionCompInterChecksOutput (mpeg2_decoder_t * const, unsigned char *, unsigned char *, unsigned char *,int, int, int);#endif //#ifdef NO_PERFextern mpeg2_mc_t mpeg2_mc;extern uint8_t LumaData[];extern uint8_t ChromaData[];extern uint8_t ChromaOffset;extern uint8_t LumaOffset;uint8_t ChromaData1[4 * 64] = {0};void motion_mp1 (mpeg2_decoder_t * const decoder, motion_t * const motion, mpeg2_mc_fct * const *const table){ int motion_x, motion_y; unsigned int pos_x, pos_y;#ifdef NO_PERF unsigned int xy_half, offset;#endif //NO_PERF do { if (((decoder->bitstream_bits) > 0)) { do { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder->bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; } while (0); (decoder->bitstream_bits) -= 16; } } while (0); motion_x = (motion->pmv[0][0] + (get_motion_delta (decoder, motion->f_code[0]) << motion->f_code[1])); motion_x = bound_motion_vector (motion_x, motion->f_code[0] + motion->f_code[1]); motion->pmv[0][0] = motion_x; do { if (((decoder->bitstream_bits) > 0)) { do { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder-> bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; } while (0); (decoder->bitstream_bits) -= 16; } } while (0); motion_y = (motion->pmv[0][1] + (get_motion_delta (decoder, motion->f_code[0]) << motion->f_code[1])); motion_y = bound_motion_vector (motion_y, motion->f_code[0] + motion->f_code[1]); motion->pmv[0][1] = motion_y;#ifdef NO_PERF pos_x = 2 * decoder->offset + motion_x; pos_y = 2 * decoder->v_offset + motion_y + 2 * 0; if ((pos_x > decoder->limit_x)) { pos_x = ((int) pos_x < 0) ? 0 : decoder->limit_x; motion_x = pos_x - 2 * decoder->offset; } if ((pos_y > decoder->limit_y_16)) { pos_y = ((int) pos_y < 0) ? 0 : decoder->limit_y_16; motion_y = pos_y - 2 * decoder->v_offset - 2 * 0; } xy_half = ((pos_y & 1) << 1) | (pos_x & 1); table[xy_half] (decoder->dest[0] + 0 * decoder->stride + decoder->offset, motion->ref[0][0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, decoder->stride, 16); motion_x /= 2; motion_y /= 2; xy_half = ((motion_y & 1) << 1) | (motion_x & 1); offset = (((decoder->offset + motion_x) >> 1) + ((((decoder->v_offset + motion_y) >> 1) + 0 / 2) * decoder->uv_stride)); table[4 + xy_half] (decoder->dest[1] + 0 / 2 * decoder->uv_stride + (decoder->offset >> 1), motion->ref[0][1] + offset, decoder->uv_stride, 16 / 2); table[4 + xy_half] (decoder->dest[2] + 0 / 2 * decoder->uv_stride + (decoder->offset >> 1), motion->ref[0][2] + offset, decoder->uv_stride, 16 / 2);#endif //#ifdef NO_PERF}void motion_fr_frame_420 (mpeg2_decoder_t * const decoder, motion_t * const motion, mpeg2_mc_fct * const *const table){ int motion_x, motion_y;#ifdef NO_PERF unsigned int pos_x, pos_y, xy_half, offset;#endif //NO_PERF do { if (((decoder->bitstream_bits) > 0)) { do { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder-> bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; } while (0); (decoder->bitstream_bits) -= 16; } } while (0); motion_x = motion->pmv[0][0] + get_motion_delta (decoder, motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion->pmv[0][0] = motion_x; do { if (((decoder->bitstream_bits) > 0)) { do { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder-> bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; } while (0); (decoder->bitstream_bits) -= 16; } } while (0); motion_y = motion->pmv[0][1] + get_motion_delta (decoder, motion->f_code[1]); motion_y = bound_motion_vector (motion_y, motion->f_code[1]); motion->pmv[1][1] = motion->pmv[0][1] = motion_y; #ifdef NO_PERF if (!decoder->bUseCModel) { pos_x = 2 * decoder->offset + motion_x; pos_y = 2 * decoder->v_offset + motion_y + 2 * 0; if ((pos_x > decoder->limit_x)) { pos_x = ((int) pos_x < 0) ? 0 : decoder->limit_x; motion_x = pos_x - 2 * decoder->offset; } if ((pos_y > decoder->limit_y_16)) { pos_y = ((int) pos_y < 0) ? 0 : decoder->limit_y_16; motion_y = pos_y - 2 * decoder->v_offset - 2 * 0; } // $PP //memset ((void*)&LumaData[0], 0, sizeof(uint8_t) * 4 *64); LumaOffset = 0; xy_half = ((pos_y & 1) << 1) | (pos_x & 1); table[xy_half] (decoder->dest[0] + 0 * decoder->stride + decoder->offset, motion->ref[0][0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, decoder->stride, 16); if (decoder->bDumpFiles) MotionCompInterChecksRefBlocks (decoder, (unsigned char*)(motion->ref[0][0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride), motion_x, motion_y, MBT_16x16, Y1_LUMA_BLOCK); motion_x /= 2; motion_y /= 2; xy_half = ((motion_y & 1) << 1) | (motion_x & 1); offset = (((decoder->offset + motion_x) >> 1) + ((((decoder->v_offset + motion_y) >> 1) + 0 / 2) * decoder->uv_stride)); // $PP ChromaOffset = 0; //memset ((void*)&ChromaData[0], 0, sizeof(uint8_t) * 2 *64); table[4 + xy_half] (decoder->dest[1] + 0 / 2 * decoder->uv_stride + (decoder->offset >> 1), motion->ref[0][1] + offset, decoder->uv_stride, 16 / 2); // $PP ChromaOffset = 64; table[4 + xy_half] (decoder->dest[2] + 0 / 2 * decoder->uv_stride + (decoder->offset >> 1), motion->ref[0][2] + offset, decoder->uv_stride, 16 / 2); if (decoder->bDumpFiles) MotionCompInterChecksRefBlocks (decoder, (unsigned char*)(motion->ref[0][1] + offset), motion_x, motion_y, MBT_16x16, U_CHROMA_BLOCK); if (decoder->bDumpFiles) { MotionCompInterChecksRefBlocks (decoder, (unsigned char*)(motion->ref[0][2] + offset), motion_x, motion_y, MBT_16x16, V_CHROMA_BLOCK); MotionCompInterChecksOutput (decoder, decoder->dest[0] + 0 * decoder->stride + decoder->offset, decoder->dest[1] + 0 / 2 * decoder->uv_stride + (decoder->offset >> 1), decoder->dest[2] + 0 / 2 * decoder->uv_stride + (decoder->offset >> 1), MBT_16x16, decoder->stride, decoder->uv_stride); } }#endif //#ifdef NO_PERF}void motion_fr_field_420 (mpeg2_decoder_t * const decoder, motion_t * const motion, mpeg2_mc_fct * const *const table){ int motion_x, motion_y, field;#ifdef NO_PERF unsigned int pos_x, pos_y, xy_half, offset; int i;#endif //NO_PERF unsigned char UBlock[64] = {0}; unsigned char VBlock[64] = {0}; if (((decoder->bitstream_bits) > 0)) { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder->bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; (decoder->bitstream_bits) -= 16; } if (decoder->iRefType == FORWARD_REFERENCES) decoder->fwd_top_motion_vertical_field_select = (int)(((uint32_t) ((decoder->bitstream_buf))) >> (32 - (1))); else decoder->bwd_top_motion_vertical_field_select = (int)(((uint32_t) ((decoder->bitstream_buf))) >> (32 - (1))); field = (((uint32_t) ((decoder->bitstream_buf))) >> (32 - (1))); (decoder->bitstream_buf) <<= (1); (decoder->bitstream_bits) += (1); motion_x = motion->pmv[0][0] + get_motion_delta (decoder, motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[0][0] = motion_x; if (((decoder->bitstream_bits) > 0)) { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder->bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; (decoder->bitstream_bits) -= 16; } motion_y = ((motion->pmv[0][1] >> 1) + get_motion_delta (decoder, motion->f_code[1])); motion->pmv[0][1] = motion_y << 1;#ifdef NO_PERF if (!decoder->bUseCModel) { pos_x = 2 * decoder->offset + motion_x; pos_y = decoder->v_offset + motion_y; if ((pos_x > decoder->limit_x)) { pos_x = ((int) pos_x < 0) ? 0 : decoder->limit_x; motion_x = pos_x - 2 * decoder->offset; } if ((pos_y > decoder->limit_y)) { pos_y = ((int) pos_y < 0) ? 0 : decoder->limit_y; motion_y = pos_y - decoder->v_offset; } xy_half = ((pos_y & 1) << 1) | (pos_x & 1); // $PP LumaOffset = 0; //memset ((void*)&LumaData[0], 0, sizeof(uint8_t) * 4 *64); table[xy_half] (decoder->dest[0] + 0 * decoder->stride + decoder->offset, (motion->ref[0][0] + (pos_x >> 1) + ((pos_y & ~1) + field) * decoder->stride), 2 * decoder->stride, 8); if (decoder->bDumpFiles && !decoder->bUseCModel) MotionCompInterChecksRefBlocks (decoder, (unsigned char*)(motion->ref[0][0] + (pos_x >> 1) + ((pos_y & ~1) + field) * decoder->stride), motion_x, motion_y, MBT_16x8, Y1_LUMA_BLOCK); motion_x /= 2; motion_y /= 2; xy_half = ((motion_y & 1) << 1) | (motion_x & 1); offset = (((decoder->offset + motion_x) >> 1) + (((decoder->v_offset >> 1) + (motion_y & ~1) + field) * decoder->uv_stride)); // $PP ChromaOffset = 0; //memset ((void*)&ChromaData[0], 0, sizeof(uint8_t) * 2 *64); table[4 + xy_half] (decoder->dest[1] + 0 * decoder->uv_stride + (decoder->offset >> 1), motion->ref[0][1] + offset, 2 * decoder->uv_stride, 4); for (i = 0; i < 4; i++) memcpy ((void*)&UBlock[0 + i * 8], motion->ref[0][1] + offset + i * decoder->uv_stride * 2, 8); // $PP ChromaOffset = 64; table[4 + xy_half] (decoder->dest[2] + 0 * decoder->uv_stride + (decoder->offset >> 1), motion->ref[0][2] + offset, 2 * decoder->uv_stride, 4); for (i = 0; i < 4; i++) memcpy ((void*)&VBlock[0 + i * 8], motion->ref[0][2] + offset + i * decoder->uv_stride * 2, 8); }#endif //#ifdef NO_PERF if (((decoder->bitstream_bits) > 0)) { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder-> bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; (decoder->bitstream_bits) -= 16; } if (decoder->iRefType == FORWARD_REFERENCES) decoder->fwd_bot_motion_vertical_field_select = (int)(((uint32_t) ((decoder->bitstream_buf))) >> (32 - (1))); else decoder->bwd_bot_motion_vertical_field_select = (int)(((uint32_t) ((decoder->bitstream_buf))) >> (32 - (1))); field = (((uint32_t) ((decoder->bitstream_buf))) >> (32 - (1))); (decoder->bitstream_buf) <<= (1); (decoder->bitstream_bits) += (1); motion_x = motion->pmv[1][0] + get_motion_delta (decoder, motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion_x; if (((decoder->bitstream_bits) > 0)) { (decoder->bitstream_buf) |= (((decoder->bitstream_ptr)[0] << 8) | (decoder-> bitstream_ptr)[1]) << ((decoder->bitstream_bits)); (decoder->bitstream_ptr) += 2; (decoder->bitstream_bits) -= 16; } motion_y = ((motion->pmv[1][1] >> 1) + get_motion_delta (decoder, motion->f_code[1]));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -