?? yuvviewerdlg.cpp
字號:
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()
/////////////////////////////////////////////////////////////////////////////
// CYUVviewerDlg dialog
CYUVviewerDlg::CYUVviewerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CYUVviewerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CYUVviewerDlg)
m_nFrameFrom = 0;
m_nFrameTo = 0;
m_nFrameSize = 1;
m_nHeight = 144;
m_nWidth = 176;
m_sFrameRate = _T("30");
m_nZoom = -1;
m_zoom4 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CYUVviewerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CYUVviewerDlg)
DDX_Control(pDX, IDC_PREVIOUS5, m_buttonPrev5);
DDX_Control(pDX, IDC_ORDER, m_buttonOrder);
DDX_Control(pDX, IDC_NEXT5, m_buttonNext5);
DDX_Control(pDX, IDC_PREVIOUS, m_buttonPrev);
DDX_Control(pDX, IDC_PAUSEPLAY, m_buttonPausePlay);
DDX_Control(pDX, IDC_NEXT, m_buttonNext);
DDX_Control(pDX, IDC_OPENFILE, m_buttonOpen);
DDX_Text(pDX, IDC_FRAME_FROM, m_nFrameFrom);
DDX_Text(pDX, IDC_FRAME_TO, m_nFrameTo);
DDX_Radio(pDX, IDC_SIZE_CIF, m_nFrameSize);
DDX_Text(pDX, IDC_SIZE_HEIGHT, m_nHeight);
DDX_Text(pDX, IDC_SIZE_WIDTH, m_nWidth);
DDX_CBString(pDX, IDC_FRAME_RATE, m_sFrameRate);
DDX_Radio(pDX, IDC_ZOOM, m_nZoom);
DDX_Check(pDX, IDC_ZOOM4, m_zoom4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CYUVviewerDlg, CDialog)
//{{AFX_MSG_MAP(CYUVviewerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SIZE_CIF, OnSizeCif)
ON_BN_CLICKED(IDC_SIZE_QCIF, OnSizeQcif)
ON_BN_CLICKED(IDC_SIZE_OTHER, OnSizeOther)
ON_BN_CLICKED(IDC_OPENFILE, OnOpenfile)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_PAUSEPLAY, OnPauseplay)
ON_BN_CLICKED(IDC_PREVIOUS, OnPrevious)
ON_BN_CLICKED(IDC_NEXT5, OnNext5)
ON_BN_CLICKED(IDC_ORDER, OnOrder)
ON_BN_CLICKED(IDC_PREVIOUS5, OnPrevious5)
ON_BN_CLICKED(IDCLOSEALL, OnCloseall)
ON_BN_CLICKED(IDC_TRANSFER, OnTransfer)
ON_BN_CLICKED(IDC_ZOOM, OnZoom)
ON_MESSAGE(WM_DROPFILES,OnDropFiles)
ON_MESSAGE(WM_DRAG_FILE,OnDragFile)
ON_BN_CLICKED(IDC_ZOOM4, OnZoom4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYUVviewerDlg message handlers
BOOL CYUVviewerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_iCount = 0;
m_bPlay = true;
m_pWinThread = NULL;
// 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
for(int i=0;i<36;i++)
m_pFile[i]=NULL;
Disable(IDC_SIZE_WIDTH);
Disable(IDC_SIZE_HEIGHT);
Disable(IDC_STATIC_H);
Disable(IDC_STATIC_W);
HANDLE hPlay = NULL;
if( (hPlay=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"Play"))==NULL)
{
//如果沒有其他進程創建這個互斥量,則重新創建
hPlay = CreateMutex(NULL,FALSE,"Play");
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CYUVviewerDlg::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 CYUVviewerDlg::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 CYUVviewerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CYUVviewerDlg::OnSizeCif()
{
UpdateData(TRUE);
m_nWidth = 352;
m_nHeight = 288;
Disable(IDC_SIZE_WIDTH);
Disable(IDC_SIZE_HEIGHT);
Disable(IDC_STATIC_H);
Disable(IDC_STATIC_W);
UpdateData(FALSE);
if(m_pFile[m_iCount-1]!=NULL)
{
CYUVviewerDlg::OnCloseall();
CYUVviewerDlg::OnDragFile(0,0);
}
}
void CYUVviewerDlg::OnSizeQcif()
{
UpdateData(TRUE);
m_nWidth = 176;
m_nHeight = 144;
Disable(IDC_SIZE_WIDTH);
Disable(IDC_SIZE_HEIGHT);
Disable(IDC_STATIC_H);
Disable(IDC_STATIC_W);
UpdateData(FALSE);
if(m_pFile[m_iCount-1]!=NULL)
{
CYUVviewerDlg::OnCloseall();
CYUVviewerDlg::OnDragFile(0,0);
}
}
void CYUVviewerDlg::OnSizeOther()
{
Enable(IDC_SIZE_WIDTH);
Enable(IDC_SIZE_HEIGHT);
Enable(IDC_STATIC_H);
Enable(IDC_STATIC_W);
}
void CYUVviewerDlg::Disable(int nID)
{
CWnd *pObject1;
pObject1 = GetDlgItem(nID);
pObject1->EnableWindow(FALSE);
}
void CYUVviewerDlg::Enable(int nID)
{
CWnd *pObject1;
pObject1 = GetDlgItem(nID);
pObject1->EnableWindow(TRUE);
}
BOOL CYUVviewerDlg::Enabled(int nID)
{
CWnd *pObject1;
pObject1 = GetDlgItem(nID);
return (pObject1->IsWindowEnabled());
}
void CYUVviewerDlg::OnTransfer()
{
// the following code is to set the current displayed picture to the first frame, frame 0.
// added Jan. 15, 2002.
int i;
int picsize = m_nWidth*m_nHeight;
UpdateData(TRUE);
g_nStartFrame = m_nFrameFrom = 0;
if(m_nFrameTo != 0) g_nEndFrame = m_nFrameTo;
else g_nEndFrame = 10000;
g_nCurrentFrame = 0;
for(i=0; i<m_iCount; i++)
{
m_pFile[i]->SeekToBegin();
m_pWnd[i]->nPicShowOrder = g_nCurrentFrame;
}
if(g_nCurrentFrame < g_nEndFrame) // && !bEof)
{
g_nFrameNumber = g_nCurrentFrame;//j;
for(i=0; i<m_iCount; i++)
{
m_pFile[i]->Read(m_pWnd[i]->Y,picsize);
if(1)//bColorImage)
{
m_pFile[i]->Read(m_pWnd[i]->Cb,picsize/4);
m_pFile[i]->Read(m_pWnd[i]->Cr,picsize/4);
}
m_pWnd[i]->InvalidateRect (NULL,FALSE);
m_pWnd[i]->UpdateWindow ();
m_pWnd[i]->nPicShowOrder ++;
}
g_nCurrentFrame++;
//Sleep(200); // sleep time in milliseconds
}
/* int i, nframeno=750 ;
OnCloseall();
UpdateData(TRUE);
UINT picsize = m_nWidth*m_nHeight;
CFile fy, fu, fv, fyuv;
if(!fy.Open("d:\\sequences\\glasgow_qcif.y", CFile::modeRead ))
{
AfxMessageBox("Can't open input file");
return;
}
if(!fu.Open("d:\\sequences\\glasgow_qcif.u", CFile::modeRead ))
{
AfxMessageBox("Can't open input file");
return;
}
if(!fv.Open("d:\\sequences\\glasgow_qcif.v", CFile::modeRead ))
{
AfxMessageBox("Can't open input file");
return;
}
if(!fyuv.Open("d:\\sequences\\glasgow.qcif", CFile::modeCreate | CFile::modeWrite ))
{
AfxMessageBox("Can't open output file");
return;
}
CChildWindow *pWnd=new CChildWindow((CFrameWnd*)this, m_nWidth, m_nHeight,1);
pWnd->ShowWindow(SW_SHOW);
if(m_nZoom == -1) pWnd->CenterWindow(m_nWidth,m_nHeight);
else if(m_nZoom == 0) pWnd->CenterWindow(m_nWidth*2,m_nHeight*2);
for(i=0; i<nframeno; i++)
{
//if(i >= 260) fin.Seek(0, SEEK_SET);
if(picsize != fy.Read(pWnd->Y,picsize))
{
MessageBox("Get to end of file");
goto END;
}
fyuv.Write(pWnd->Y,picsize);
if(1)//bColorImage)
{
if(picsize/4 != fu.Read(pWnd->Cb,picsize/4))
{
MessageBox("Get to end of file");
goto END;
}
if(picsize/4 != fv.Read(pWnd->Cr,picsize/4))
{
MessageBox("Get to end of file");
goto END;
}
}
fyuv.Write(pWnd->Cb,picsize/4);
fyuv.Write(pWnd->Cr,picsize/4);
pWnd->nPicShowOrder=i +1;
pWnd->InvalidateRect (NULL,FALSE);
pWnd->UpdateWindow ();
}
END:
pWnd->DestroyWindow();
fy.Close();
fu.Close();
fv.Close();
fyuv.Close();
*/
}
void getSeqName(char *inseqpath, char *seqname)
{
int lastSlashPos, lastDotPos; // the last dot is located after the last slash "\"
int lastNonZeroPos; // last pos that tmp != 0
int i=0;
char tmp = '0';
while(tmp != 0)
{
tmp = inseqpath[i++];
if(tmp == '\\')
lastSlashPos = i-1;
if(tmp == '.')
lastDotPos = i-1;
}
lastNonZeroPos = i-1;
if(lastDotPos < lastSlashPos)
lastDotPos = -1; // that means the file name with no extention, such as "c:\seq\forman".
if(lastDotPos != -1)
{
for(i=lastSlashPos+1; i<lastDotPos; i++)
seqname[i-lastSlashPos-1] = inseqpath[i];
seqname[lastDotPos-lastSlashPos-1] = 0;
}
else
{
for(i=lastSlashPos+1; i<lastNonZeroPos+1; i++)
seqname[i-lastSlashPos-1] = inseqpath[i];
seqname[lastNonZeroPos-lastSlashPos] = 0;
}
}
void CYUVviewerDlg::OnZoom()
{
if(m_nZoom == -1)
{
m_nZoom = 0;
UpdateData(TRUE);
}
else if(m_nZoom ==0)
{
m_nZoom = -1;
UpdateData(FALSE);
}
if(m_pFile[m_iCount-1]!=NULL)
{
CYUVviewerDlg::OnCloseall();
CYUVviewerDlg::OnDragFile(0,0);
}
}
void CYUVviewerDlg::OnDropFiles(HDROP hDropInfo)
{
int DropCount=DragQueryFile(hDropInfo,-1,NULL,0);
//取得被拖動文件的數目
for(int i=0;i< DropCount;i++)
{
int NameSize=DragQueryFile(hDropInfo,i,NULL,0);
//取得第i個拖動文件名所占字節數
HANDLE hHeap=GetProcessHeap();
//根據字節數分配緩沖區
char *pName=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,NameSize++);
if (pName==NULL)
{
MessageBox("給文件名分配暫存空間時出錯!", "錯誤信息",MB_ICONERROR);
return;
}
DragQueryFile(hDropInfo,i,pName,NameSize);
//把文件名拷貝到緩沖區
// m_Dialog_List.AddString(pName);
//文件名加入listbox中顯示
strcpy(inSeqence[m_iCount],pName);
PostMessage(WM_DRAG_FILE);
HeapFree(hHeap,HEAP_ZERO_MEMORY,pName);
//釋放緩沖區
}
CDialog::OnDropFiles(hDropInfo);
}
void CYUVviewerDlg::OnDragFile(WPARAM wParam,LPARAM lParam)
{
UpdateData(TRUE);
UINT picsize = m_nWidth*m_nHeight;
m_pFile[m_iCount] = new CFile();
getSeqName(inSeqence[m_iCount], inSeqName[m_iCount]);
if(!m_pFile[m_iCount]->Open(inSeqence[m_iCount], CFile::modeRead ))
{
AfxMessageBox("Can't open input file");
return ;
}
m_pWnd[m_iCount]=new CChildWindow((CFrameWnd*)this, m_nWidth, m_nHeight,1);
if(picsize != m_pFile[m_iCount]->Read(m_pWnd[m_iCount]->Y,picsize))
{
MessageBox("Get to end of file");
return ;
}
if(1)//bColorImage)
{
if(picsize/4 != m_pFile[m_iCount]->Read(m_pWnd[m_iCount]->Cb,picsize/4))
{
MessageBox("Get to end of file");
return ;
}
if(picsize/4 != m_pFile[m_iCount]->Read(m_pWnd[m_iCount]->Cr,picsize/4))
{
MessageBox("Get to end of file");
return ;
}
}
m_pWnd[m_iCount]->ShowWindow(SW_SHOW);
if(m_nZoom == -1) m_pWnd[m_iCount]->CenterWindow(m_nWidth,m_nHeight);
else if(m_nZoom == 0) m_pWnd[m_iCount]->CenterWindow(m_nWidth*2,m_nHeight*2);
if(m_zoom4) m_pWnd[m_iCount]->CenterWindow(m_nWidth*4,m_nHeight*4);
m_iCount++;
}
void CYUVviewerDlg::OnZoom4()
{
// TODO: Add your control notification handler code here
if(m_zoom4 == FALSE)
{
m_zoom4 = TRUE;
UpdateData(TRUE);
}
else if(m_zoom4 == TRUE)
{
m_zoom4 = FALSE;
UpdateData(FALSE);
}
if(m_pFile[m_iCount-1]!=NULL)
{
CYUVviewerDlg::OnCloseall();
CYUVviewerDlg::OnDragFile(0,0);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -