DistributionDlg.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:6k
- // DistributionDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "XvidQuantsParser.h"
- #include "DistributionDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDistributionDlg dialog
- CDistributionDlg::CDistributionDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CDistributionDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDistributionDlg)
- m_icount = 0;
- m_pcount = 0;
- m_pavg = 0.0f;
- m_iavg = 0.0f;
- m_imaxfs = 0;
- m_iminfs = 0;
- m_pmaxfs = 0;
- m_pminfs = 0;
- //}}AFX_DATA_INIT
- qarray = NULL;
- }
- void CDistributionDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDistributionDlg)
- DDX_Control(pDX, IDC_LIST_PFRAMES, m_listp);
- DDX_Control(pDX, IDC_LIST_IFRAMES, m_listi);
- DDX_Text(pDX, IDC_EDIT_ICOUNT, m_icount);
- DDX_Text(pDX, IDC_EDIT_PCOUNT, m_pcount);
- DDX_Text(pDX, IDC_EDIT_PAVG, m_pavg);
- DDX_Text(pDX, IDC_EDIT_IAVG, m_iavg);
- DDX_Control(pDX, IDC_GRAPH_G, m_graphg);
- DDX_Control(pDX, IDC_GRAPH_I, m_graphi);
- DDX_Control(pDX, IDC_GRAPH_P, m_graphp);
- DDX_Text(pDX, IDC_EDIT_IMAXFS, m_imaxfs);
- DDX_Text(pDX, IDC_EDIT_IMINFS, m_iminfs);
- DDX_Text(pDX, IDC_EDIT_PMAXFS, m_pmaxfs);
- DDX_Text(pDX, IDC_EDIT_PMINFS, m_pminfs);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDistributionDlg, CDialog)
- //{{AFX_MSG_MAP(CDistributionDlg)
- ON_BN_CLICKED(IDC_BUTTON_DRAW, OnButtonDraw)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDistributionDlg message handlers
- void CDistributionDlg::Init(CXvid &xvid, CXvid::QUANTS *quants, int nframes)
- {
- nelem = nframes;
- qarray = quants;
- pavg = xvid.GetPAvgQuants();
- pmaxfs = xvid.GetPMaxFrameSize();
- pminfs = xvid.GetPMinFrameSize();
- iavg = xvid.GetIAvgQuants();
- imaxfs = xvid.GetIMaxFrameSize();
- iminfs = xvid.GetIMinFrameSize();
- }
- //-----------------------------------------------------------------------------------
- void CDistributionDlg::ParsePFrames(void)
- {
- char index[3], percent[6], fcount[8];
- pcount=0;
- //初始化
- for (int i=0; i<31; i++)
- {
- phisto[i] = 0;
- }
- //分析
- for (int j=0; j<nelem; j++)
- {
- if (!qarray[j].isIFrame)
- {
- phisto[qarray[j].qvalue-2] += 1;
- pcount++;
- }
- }
- //输出到P帧的list控件
- for (int k=0; k<31; k++)
- {
- sprintf(index, "%dx", k+2);
- sprintf(percent, "%.3f", (float)(phisto[k]*100)/(float)pcount);
- sprintf(fcount, "%d", phisto[k]);
- m_listp.InsertItem (k, index); //Quants 索引
- m_listp.SetItemText(k, 1, percent); //百分比
- m_listp.SetItemText(k, 2, fcount); //百分比
- }
- m_pcount = pcount;
- m_pavg = pavg;
- m_pmaxfs = pmaxfs;
- m_pminfs = pminfs;
- UpdateData(FALSE);
- }
- //-----------------------------------------------------------------------------------
- void CDistributionDlg::ParseIFrames(void)
- {
- char index[3], percent[6], fcount[8];
- icount=0;
- //初始化
- for (int i=0; i<31; i++)
- {
- ihisto[i] = 0;
- }
- //分析
- for (int j=0; j<nelem; j++)
- {
- if (qarray[j].isIFrame)
- {
- ihisto[qarray[j].qvalue-2] += 1;
- icount++;
- }
- }
- //输出到list控件中
- for (int k=0; k<31; k++)
- {
- sprintf(index, "%dx", k+2);
- sprintf(percent, "%.3f", (float)(ihisto[k]*100)/(float)icount);
- sprintf(fcount, "%d", ihisto[k]);
- m_listi.InsertItem (k, index); //Quants 索引
- m_listi.SetItemText(k, 1, percent); //百分比
- m_listi.SetItemText(k, 2, fcount); //百分比
- }
- m_icount = icount;
- m_iavg = iavg;
- m_imaxfs = imaxfs;
- m_iminfs = iminfs;
- UpdateData(FALSE);
- }
- //-----------------------------------------------------------------------------------
- BOOL CDistributionDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
-
- //P-Frames listview
- m_listp.InsertColumn(0, "Quant",LVCFMT_CENTER, 45);
- m_listp.InsertColumn(1, "%", LVCFMT_CENTER, 70);
- m_listp.InsertColumn(2, "Count",LVCFMT_LEFT, 75);
- //I-Frames listview
- m_listi.InsertColumn(0, "Quant",LVCFMT_CENTER, 45);
- m_listi.InsertColumn(1, "%", LVCFMT_CENTER, 70);
- m_listi.InsertColumn(2, "Count",LVCFMT_LEFT, 75);
- ParsePFrames();
- ParseIFrames();
- ScaleHistograms();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- //-----------------------------------------------------------------------------------
- void CDistributionDlg::ScaleHistograms(void)
- {
- m_graphg.SetForeColor(RGB(200,0,0));
- m_graphg.SetLineWidth(3);
- m_graphg.SetScale(0, 0, 32, 110);
- m_graphp.SetForeColor(RGB(0,200,0));
- m_graphp.SetLineWidth(3);
- m_graphp.SetScale(0, 0, 32, 110);
- m_graphi.SetForeColor(RGB(0,0,200));
- m_graphi.SetLineWidth(3);
- m_graphi.SetScale(0, 0, 32, 110);
- }
- //-----------------------------------------------------------------------------------
- void CDistributionDlg::DrawHistograms(void)
- {
- int i;
- //Fill global histogram...
- for (i=0; i<31; i++)
- {
- ghisto[i] = phisto[i] + ihisto[i];
- }
- //global
- for (i=0; i<31; i++)
- {
- if (ghisto[i] > 0)
- m_graphg.DrawLine(i+1, 1, i+1, ((ghisto[i]*100)/(pcount+icount))+2);
- }
- //p-frames
- for (i=0; i<31; i++)
- {
- if (phisto[i] > 0)
- m_graphp.DrawLine(i+1, 1, i+1, ((phisto[i]*100)/pcount)+2);
- }
- //i-frames
- for (i=0; i<31; i++)
- {
- if (ihisto[i] > 0)
- m_graphi.DrawLine(i+1, 1, i+1, ((ihisto[i]*100)/icount)+2);
- }
- }
- //-----------------------------------------------------------------------------------
- void CDistributionDlg::OnButtonDraw()
- {
- DrawHistograms();
- }