//------------------------------------------------------------------------------ void idle(void) { if( !sim_pause ) { frame_id++; interpolate_frame(); } glutPostRedisplay(); }
void InterpolatedSkeletController::ApplyFrame() { if (!m_animation) return; float k = m_frame_time * m_animation->GetFPS(); size_t next_frame = m_crnt_frame + 1; if (next_frame >= m_animation->GetFrames()) { next_frame = (m_loop!=1) ? 0 : m_crnt_frame; } for (sb::vector<SkeletObjectPtr>::const_iterator it = m_objects.begin();it!=m_objects.end();++it ) { for (size_t i = 0; i < m_data->GetNodesCount();++i ) { const SkeletonNodeFrame& next = m_animation->GetNodeFrame(next_frame, i); const SkeletonNodeFrame& frame = m_animation->GetNodeFrame(m_crnt_frame, i); const SkeletonNodeData& node = m_data->GetNode(frame.node); (*it)->SetSlot(i,node,interpolate_frame(frame,next,k),m_data->GetImage(frame.image)); } } }
void interpolate_frames(yuv_frame_t* new_frame, yuv_frame_t* ref0, yuv_frame_t* ref1, int ratio, int pos) { int widthin = ref0->width; int heightin = ref0->height; int max_levels=min(MAX_LEVELS, (int) (log10(min(widthin, heightin))/log10(2.0)-4.0)); mv_data_t * mv_data[MAX_LEVELS]; mv_data_t * spatial_mv_data[MAX_LEVELS]; mv_data_t * guide_mv_data[NUM_GUIDES]; yuv_frame_t* in_down[MAX_LEVELS][2]; yuv_frame_t* out_down[MAX_LEVELS]; int interpolate = 1; for (int j=1; j<max_levels; j++) { out_down[j]=malloc(sizeof(yuv_frame_t)); create_yuv_frame(out_down[j],widthin>>j,heightin>>j, 32, 32, 16, 16); } out_down[0]=new_frame; for (int j=0; j<max_levels; j++) { mv_data[j] = alloc_mv_data(widthin>>j, heightin>>j, BLOCK_STEP/2, BLOCK_STEP, ratio, pos, interpolate); mv_data[j]->ratio = ratio; spatial_mv_data[j] = alloc_mv_data(widthin>>j, heightin>>j, BLOCK_STEP/2, BLOCK_STEP, ratio, pos, interpolate); spatial_mv_data[j]->ratio = ratio; } /* Higher levels are down-sampled*/ for (int i=1; i<max_levels; ++i) { in_down[i][0]=malloc(sizeof(yuv_frame_t)); in_down[i][1]=malloc(sizeof(yuv_frame_t)); create_yuv_frame(in_down[i][0],widthin>>i, heightin>>i, 32, 32, 16, 16); create_yuv_frame(in_down[i][1],widthin>>i, heightin>>i, 32, 32, 16, 16); } // Level 0 is just the original pictures in_down[0][0]=ref0; in_down[0][1]=ref1; for (int l=0; l<max_levels-1; ++l) { if (use_simd) { scale_frame_down2x2_simd(in_down[l][0], in_down[l+1][0]); scale_frame_down2x2_simd(in_down[l][1], in_down[l+1][1]); } else { scale_frame_down2x2(in_down[l][0], in_down[l+1][0]); scale_frame_down2x2(in_down[l][1], in_down[l+1][1]); } } for (int lvl=max_levels-1; lvl>=0; --lvl) { int num_guides=0; if (lvl!=max_levels-1) { guide_mv_data[num_guides++]=spatial_mv_data[lvl]; } motion_estimate_bi(mv_data[lvl], guide_mv_data, num_guides, in_down[lvl][0], in_down[lvl][1], pos); if (lvl==0) interpolate_frame(mv_data[lvl], in_down[lvl][0], in_down[lvl][1], out_down[lvl], widthin, heightin, pos, ratio); if (lvl>0) { upscale_mv_data_2x2(mv_data[lvl], spatial_mv_data[lvl-1]); } } for (int j=1; j<max_levels; j++) { close_yuv_frame(out_down[j]); free(out_down[j]); } for (int j=0; j<max_levels; j++) { free_mv_data(mv_data[j]); free_mv_data(spatial_mv_data[j]); } /* Higher levels are down-sampled*/ for (int i=1; i<max_levels; ++i) { close_yuv_frame(in_down[i][0]); close_yuv_frame(in_down[i][1]); free(in_down[i][0]); free(in_down[i][1]); } }