📄 newmotiondlg.cpp
字号:
// newmotionDlg.cpp : implementation file
//
#include "stdafx.h"
#include "newmotion.h"
#include "newmotionDlg.h"
#include "globaldec.h"
#include <math.h>
#include "getvlc.h"
#include "Showbasic1.h"
#include "ShowMV.h"
#include "ShowMIH.h"
//#include "global.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewmotionDlg dialog
CNewmotionDlg::CNewmotionDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNewmotionDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNewmotionDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//DlgSetup=TRUE;
}
void CNewmotionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNewmotionDlg)
DDX_Control(pDX, IDC_ACTIVEMOVIECONTROL1, m_ActiveMovie);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNewmotionDlg, CDialog)
//{{AFX_MSG_MAP(CNewmotionDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_PFRAME, OnPframe)
ON_BN_CLICKED(IDC_BAISC, OnBaisc)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_MIH, OnMih)
ON_BN_CLICKED(IDC_SEND, OnSend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewmotionDlg message handlers
BOOL CNewmotionDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
bfr=new BYTE[BUFFER_SIZE];
ld=&base;
ld->quantizer_scale = quantizer_scale_code;
for(int i=0;i<8;i++)
{
masks[i]=0x01<<i;
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CNewmotionDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CNewmotionDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CNewmotionDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CNewmotionDlg::OnOpen()
{
// TODO: Add your control notification handler code here
char szFileFilter[]=
"MPEG File(*.mpg)|*.mpg|"
"Mp3 File(*.mp3)|*.mp3|"
"Wma File(*.wma)|*.wma|"
"Video File(*.dat)|*.dat|"
"Wave File(*.wav)|*.wav|"
"AVI File(*.avi)|*.avi|"
"Movie File(*.mov)|*.mov|"
"Media File(*.mmm)|*.mmm|"
"Mid File(*.mid;*,rmi)|*.mid;*.rmi|"
"All File(*.*)|*.*||";
// if(DlgSetup==TRUE)
// {
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter);
// DlgSetup=FALSE;
// }
// dlg.lpszFilter=szFileFilter;
if(dlg.DoModal()==IDOK)
{
//CString
PathName=dlg.GetPathName();
PathName.MakeUpper();
postfix = strrchr(PathName,'.');
strPostfix=postfix;
m_ActiveMovie.SetFileName(PathName);
}
}
void CNewmotionDlg::OnPframe()
{
// int PMV[2][2][2]={0};
// int MBA;
// int MBAinc;
if(strPostfix=="")
AfxMessageBox("Please open a mpeg file first!");
else if(strPostfix == ".MPG"||strPostfix == ".MPEG")
{
InitGetBits();
SeekSync(FULL_GROUP_START_CODE, 32);
// int postfix;
int Slice_Num;
block_count=6;
int MBAmax;
int ret;
P_Num=0;
/* number of macroblocks per picture */
MBAmax = mb_width*mb_height;
for(int k=0;k<100;k++)// 初始化数组
{
for(int i=0;i<1000;i++)
{
for(int j=0;j<2;j++)
{ PMV_out[k][i][j]=0; }
}
}
while( Next_Pic_Start_Code()==1)//SeekSync(FULL_PICTURE_START_CODE, 32))//
{ // ;
//Next_Pic_Start_Code();
GetBits(10);
CodeType=GetBits(3);
GetBits(16);
if (CodeType==P_TYPE || CodeType==B_TYPE)
{
full_pel_forward_vector = Get1Bit();
forward_f_code = GetBits(3);
}
if (CodeType==B_TYPE)
{
full_pel_backward_vector = Get1Bit();
backward_f_code = GetBits(3);
}
if(Get1Bit()==1)
GetBits(8);
Get1Bit();
// Next_Start_Code();
if(CodeType==2)
{
MB_Num=0;
Slice_Num=0;
for(;;)
{
if((ret=slice(MBAmax))>=0)
Slice_Num++;
else
break;
}
P_Num++;
}
// if(PFrame_Num==2)
// break;
}
FinishGetBits();
CShowMV showdlg1;
showdlg1.m_MV1h=PMV_out[0][0][0];
showdlg1.m_MV1v=PMV_out[0][0][1];
showdlg1.m_MV2h=PMV_out[1][0][0];
showdlg1.m_MV2v=PMV_out[1][0][1];
showdlg1.m_MV3h=PMV_out[10][0][0];
showdlg1.m_MV3v=PMV_out[10][0][1];
showdlg1.DoModal() ;
}
else
AfxMessageBox("This format is not supported!");
}
int CNewmotionDlg::slice(int MBAmax)
{
int MBA;
int MBAinc,macroblock_type, motion_type, dct_type;
int dc_dct_pred[3];
int PMV[2][2][2], motion_vertical_field_select[2][2];
int dmvector[2];
int stwtype, stwclass;
// int SNRMBA, SNRMBAinc;
int ret;
MBA = 0; /* macroblock address */
MBAinc = 0;
int j=0;
if((ret=start_of_slice(MBAmax, &MBA, &MBAinc, dc_dct_pred, PMV))!=1)
return(ret);
Fault_Flag=0;
for (;;)
{
/* this is how we properly exit out of picture */
if (MBA>=MBAmax)
return(-1); /* all macroblocks decoded */
ld = &base;
if (MBAinc==0)
{
if (!LookAhead(23) || Fault_Flag) /* next_start_code or fault */
{
resync: /* if Fault_Flag: resynchronize to next next_start_code */
Fault_Flag = 0;
return(0); /* trigger: go to next slice */
}
else /* neither next_start_code nor Fault_Flag */
{
/* decode macroblock address increment */
MBAinc = Get_macroblock_address_increment();
if (Fault_Flag) goto resync;
}
}
if (MBA>=MBAmax)
{
/* MBAinc points beyond picture dimensions */
if (!Quiet_Flag)
printf("Too many macroblocks in picture\n");
return(-1);
}
if (MBAinc==1) /* not skipped */
{
ret = decode_macroblock(¯oblock_type, &stwtype, &stwclass,
&motion_type, &dct_type, PMV, dc_dct_pred,
motion_vertical_field_select, dmvector);
PMV_out[P_Num][MB_Num][0]=PMV[0][0][0];
PMV_out[P_Num][MB_Num][1]=PMV[0][0][1];
MB_Num++;
if(ret==-1)
return(-1);
if(ret==0)
goto resync;
}
else /* MBAinc!=1: skipped macroblock */
{
/* ISO/IEC 13818-2 section 7.6.6 */
skipped_macroblock(dc_dct_pred, PMV, &motion_type,
motion_vertical_field_select, &stwtype, ¯oblock_type);
}
/* ISO/IEC 13818-2 section 7.6 */
// motion_compensation(MBA, macroblock_type, motion_type, PMV,
// motion_vertical_field_select, dmvector, stwtype, dct_type);
/* advance to next macroblock */
MBA++;
MBAinc--;
if (MBA>=MBAmax)
return(-1); /* all macroblocks decoded */
}
}
int CNewmotionDlg::start_of_slice(int MBAmax, int *MBA, int *MBAinc,int dc_dct_pred[3], int PMV[2][2][2])
{
unsigned int code;
// int slice_vert_pos_ext;
// ld = &base;
// Fault_Flag = 0;
Next_Start_Code();
code = LookAhead(8);
if(code==EXTENSION_START_CODE)
{
GetBits(8);
while(LookAhead(32)!=0x1)
{GetBits(8);}
Next_Start_Code();
code = LookAhead(8);
}
if(code==USER_DATA_START_CODE)
{
GetBits(8);
while(LookAhead(32)!=0x1)
{GetBits(8);}
Next_Start_Code();
code = LookAhead(8);
}
if (code<SLICE_START_CODE_MIN || code>SLICE_START_CODE_MAX)
{
/* only slice headers are allowed in picture_data */
// if (!Quiet_Flag)
// printf("start_of_slice(): Premature end of picture\n");
return(-1); /* trigger: go to next picture */
}
slice_vert_pos=GetBits(8);
quantizer_scale_code=GetBits(5);
while(Get1Bit()==1)
{
GetBits(8);
}
Get1Bit();
//slice_num++;
/* decode slice header (may change quantizer_scale) */
// slice_vert_pos_ext = slice_header();
/* decode macroblock address increment */
// *MBAinc = Get_macroblock_address_increment();
/*
if (Fault_Flag)
{
printf("start_of_slice(): MBAinc unsuccessful\n");
return(0); /* trigger: go to next slice
}
*/
/* set current location */
/* NOTE: the arithmetic used to derive macroblock_address below is
* equivalent to ISO/IEC 13818-2 section 6.3.17: Macroblock
*/
*MBA = 0;//(slice_vert_pos - 1)*mb_width + *MBAinc - 1;
*MBAinc = 1; /* first macroblock in slice: not skipped */
/* reset all DC coefficient and motion vector predictors */
/* reset all DC coefficient and motion vector predictors */
/* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */
dc_dct_pred[0]=dc_dct_pred[1]=dc_dct_pred[2]=0;
/* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
PMV[0][0][0]=PMV[0][0][1]=PMV[1][0][0]=PMV[1][0][1]=0;
PMV[0][1][0]=PMV[0][1][1]=PMV[1][1][0]=PMV[1][1][1]=0;
/* successfull: trigger decode macroblocks in slice */
return(1);
}
void CNewmotionDlg::OnBaisc()
{
// TODO: Add your control notification handler code here
width=0;
height=0;
if(strPostfix =="")
AfxMessageBox("Please open a mpeg file first!");
// m_file = new CFile;
else if(strPostfix == ".MPG"||strPostfix == ".MPEG")
{
InitGetBits(); // DWORD s=
Sequence_Header_Code();
mb_width=(GetBits(12)+15)/16;//
mb_height=(GetBits(12)+15)/16;// 352*240 为N制525line;
width = 16*mb_width;
height = 16*mb_height;
GetBits(4);
Pic_Rate=GetBits(4);
Frame_Num=0;
PFrame_Num=0;
IFrame_Num=0;
BFrame_Num=0;
// MB_Intra_Num=0;
while( Next_Pic_Start_Code()==1)
{
Frame_Num++;
GetBits(10);
CodeType=GetBits(3);
switch(CodeType)
{
case 1:
IFrame_Num++;
break;
case 2://break;
PFrame_Num++;
break;
case 3:
BFrame_Num++;
break;
default:
break;
}
}
FinishGetBits();
CShowbasic showdlg;
showdlg.m_Width=width;
showdlg.m_Height=height;
showdlg.m_FrameNum=Frame_Num;
showdlg.m_PFrameNum=PFrame_Num;
showdlg.DoModal() ;
}
else
AfxMessageBox("This format is not supported!");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -