forked from leixiaohua1020/VideoEye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dfanalysis.cpp
1423 lines (1281 loc) · 42.2 KB
/
Dfanalysis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
*
* VideoEye
*
* 雷霄骅 Lei Xiaohua
* 中国传媒大学/数字电视技术
* Communication University of China / Digital TV Technology
* http://blog.csdn.net/leixiaohua1020
*
*/
#include "stdafx.h"
#include "Dfanalysis.h"
#include "afxdialogex.h"
// Dfanalysis 对话框
IMPLEMENT_DYNAMIC(Dfanalysis, CDialogEx)
Dfanalysis::Dfanalysis(CWnd* pParent /*=NULL*/)
: CDialogEx(Dfanalysis::IDD, pParent)
{
m_dfanalysisnum16x16 = 0;
m_dfanalysisnum16x8 = 0;
m_dfanalysisnum8x16 = 0;
m_dfanalysisnum8x8 = 0;
m_dfanalysisnumavgq = 0;
m_dfanalysisnumintra16x16 = 0;
m_dfanalysisnumintra4x4 = 0;
m_dfanalysisnumskip = 0;
m_dfanalysisnummaxq = 0;
m_dfanalysisnumminq = 0;
m_dfanalysisnuml0 = 0;
m_dfanalysisnuml1 = 0;
m_dfanalysisautointerframenum = 0;
}
Dfanalysis::~Dfanalysis()
{
}
void Dfanalysis::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_DFANALYSIS_METHOD, m_dfanalysismethod);
DDX_Control(pDX, IDC_DFANALYSIS_MB_HEIGHT, m_dfanalysismbheight);
DDX_Control(pDX, IDC_DFANALYSIS_MB_SUM, m_dfanalysismbsum);
DDX_Control(pDX, IDC_DFANALYSIS_MB_WIDTH, m_dfanalysismbwidth);
DDX_Control(pDX, IDC_DFANALYSIS_MV_SUBSAMPLE, m_dfanalysismvsubsample);
DDX_Control(pDX, IDC_DFANALYSIS_OPTION, m_dfanalysisoption);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_16X16, m_dfanalysisnum16x16);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_16X8, m_dfanalysisnum16x8);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_8X16, m_dfanalysisnum8x16);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_8X8, m_dfanalysisnum8x8);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_AVGQ, m_dfanalysisnumavgq);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_INTRA16X16, m_dfanalysisnumintra16x16);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_INTRA4X4, m_dfanalysisnumintra4x4);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_SKIP, m_dfanalysisnumskip);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_MAXQ, m_dfanalysisnummaxq);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_MINQ, m_dfanalysisnumminq);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_L0, m_dfanalysisnuml0);
DDX_Text(pDX, IDC_DFANALYSIS_NUM_L1, m_dfanalysisnuml1);
// DDX_Control(pDX, IDC_DFANALYSIS_MB_PACKETSIZE, m_dfanalysismbpacketsize);
DDX_Control(pDX, IDC_DFANALYSIS_MB_PICTTYPE, m_dfanalysismbpictype);
DDX_Control(pDX, IDC_DFANALYSIS_MB_PTIME, m_dfanalysismbptime);
DDX_Control(pDX, IDC_DFANALYSIS_MB_PTS, m_dfanalysismbpts);
DDX_Control(pDX, IDC_DFANALYSIS_MB_REF, m_dfanalysismbref);
DDX_Control(pDX, IDC_DFANALYSIS_MB_FRAMEINDEX, m_dfanalysismbframeindex);
DDX_Control(pDX, IDC_DFANALYSIS_MB_QTYPE, m_dfanalysismbqtype);
DDX_Text(pDX, IDC_DFANALYSIS_AUTO_INTERFRAMENUM, m_dfanalysisautointerframenum);
DDX_Control(pDX, IDC_DFANALYSIS_AUTO, m_dfanalysisauto);
DDX_Control(pDX, IDC_DFANALYSIS_OUTPICFOLDER, m_dfanalysisoutpicfolder);
DDX_Control(pDX, IDC_DFANALYSIS_OUTPICFOLDER_URL, m_dfanalysisoutpicfolderurl);
DDX_Control(pDX, IDC_DFANALYSIS_OUTDATAFOLDER, m_dfanalysisoutdatafolder);
DDX_Control(pDX, IDC_DFANALYSIS_OUTDATAFOLDER_URL, m_dfanalysisoutdatafolderurl);
}
BEGIN_MESSAGE_MAP(Dfanalysis, CDialogEx)
ON_BN_CLICKED(IDC_DFANALYSIS_OPEN, &Dfanalysis::OnBnClickedDfanalysisOpen)
ON_BN_CLICKED(IDC_DFANALYSIS_AUTO, &Dfanalysis::OnBnClickedDfanalysisAuto)
ON_EN_KILLFOCUS(IDC_DFANALYSIS_AUTO_INTERFRAMENUM, &Dfanalysis::OnKillfocusDfanalysisAutoInterframenum)
ON_WM_PAINT()
ON_BN_CLICKED(IDCANCEL, &Dfanalysis::OnBnClickedCancel)
// ON_WM_CLOSE()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_DFANALYSIS_OUTPICFOLDER, &Dfanalysis::OnClickedDfanalysisOutpicfolder)
ON_BN_CLICKED(IDC_DFANALYSIS_OUTDATAFOLDER, &Dfanalysis::OnClickedDfanalysisOutdatafolder)
END_MESSAGE_MAP()
// Dfanalysis 消息处理程序
BOOL Dfanalysis::OnInitDialog(){
CDialogEx::OnInitDialog();
//默认不开启自动分析
m_dfanalysisautointerframenum=20;
UpdateData(FALSE);
GetDlgItem(IDC_DFANALYSIS_AUTO_INTERFRAMENUM)->EnableWindow(FALSE);
m_dfanalysisauto.SetCheck(0);
//-----------------
//加载StringTable
CString resloader;
resloader.LoadString(IDS_DFANALYSIS_PARAMETER_QP);
m_dfanalysismethod.InsertString(0,resloader);
resloader.LoadString(IDS_DFANALYSIS_PARAMETER_MBTYPE);
m_dfanalysismethod.InsertString(1,resloader);
resloader.LoadString(IDS_DFANALYSIS_PARAMETER_MV0);
m_dfanalysismethod.InsertString(2,resloader);
resloader.LoadString(IDS_DFANALYSIS_PARAMETER_MV1);
m_dfanalysismethod.InsertString(3,resloader);
resloader.LoadString(IDS_DFANALYSIS_PARAMETER_REF0);
m_dfanalysismethod.InsertString(4,resloader);
resloader.LoadString(IDS_DFANALYSIS_PARAMETER_REF1);
m_dfanalysismethod.InsertString(5,resloader);
m_dfanalysismethod.SetCurSel(0);
//-----------------
m_dfanalysisoption.EnableDescriptionArea();
m_dfanalysisoption.SetVSDotNetLook();
m_dfanalysisoption.MarkModifiedProperties();
m_dfanalysisoption.EnableHeaderCtrl(FALSE);
//把第一列调整宽一些-----------------------
HDITEM item;
item.cxy=120;
item.mask=HDI_WIDTH;
//m_dfanalysisoption.GetHeaderCtrl().SetItem(0, new HDITEM(item));
m_dfanalysisoption.GetHeaderCtrl().SetItem(0, &item);
resloader.LoadString(IDS_DFANALYSIS_OPT_GLOBAL);
prop_global=new CMFCPropertyGridProperty(resloader);
resloader.LoadString(IDS_DFANALYSIS_OPT_Q);
prop_q=new CMFCPropertyGridProperty(resloader);
resloader.LoadString(IDS_DFANALYSIS_OPT_MBTYPE);
prop_mb_type=new CMFCPropertyGridProperty(resloader);
resloader.LoadString(IDS_DFANALYSIS_OPT_MV0);
prop_mv0=new CMFCPropertyGridProperty(resloader);
resloader.LoadString(IDS_DFANALYSIS_OPT_MV1);
prop_mv1=new CMFCPropertyGridProperty(resloader);
resloader.LoadString(IDS_DFANALYSIS_OPT_GLOBAL_MBBORDER);
prop_global_showmbedge=new CMFCPropertyGridProperty(resloader,(_variant_t) true, _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_GLOBAL_MBBORDER_COLOR);
prop_global_showmbedge_color=new CMFCPropertyGridColorProperty(resloader,RGB(0, 0, 0), NULL,_T(""));
//字体
//LOGFONT lf;
//CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
//font->GetLogFont(&lf);
//resloader.LoadString(IDS_DFANALYSIS_OPT_GLOBAL_FONT);
//prop_global_font=new CMFCPropertyGridFontProperty(resloader, lf, CF_EFFECTS | CF_SCREENFONTS, "画图时的字体");
resloader.LoadString(IDS_DFANALYSIS_OPT_GLOBAL_WINSIZE);
prop_global_winsize=new CMFCPropertyGridProperty(resloader,(_variant_t) 120, _T(""));
prop_global_winsize->EnableSpinControl(TRUE,80,200);
resloader.LoadString(IDS_DFANALYSIS_OPT_Q_SHOWVAL);
prop_q_shownum=new CMFCPropertyGridProperty(resloader,(_variant_t) true, _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_Q_SHOWCOLOR);
prop_q_showcolor=new CMFCPropertyGridProperty(resloader, (_variant_t) false, _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_MBTYPE_SHOWSUBMB);
prop_mb_type_showsubmb=new CMFCPropertyGridProperty(resloader,(_variant_t) true, _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_MBTYPE_SHOWCOLOR);
prop_mb_type_showcolor=new CMFCPropertyGridProperty(resloader,(_variant_t) false, _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_MBTYPE_SHOWSKIP);
prop_mb_type_showskip=new CMFCPropertyGridProperty(resloader,(_variant_t) true, _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_MBTYPE_SHOWLIST);
prop_mb_type_showlist=new CMFCPropertyGridProperty(resloader,(_variant_t) false, _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_MV0_COLOR);
prop_mv0_colortype=new CMFCPropertyGridColorProperty(resloader,RGB(255, 0, 0), NULL, _T(""));
prop_mv0_colortype->EnableOtherButton(_T("Other..."));
prop_mv0_colortype->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));
resloader.LoadString(IDS_DFANALYSIS_OPT_MV0_STYLE);
prop_mv0_linetype=new CMFCPropertyGridProperty(resloader,(_variant_t) "line", _T(""));
resloader.LoadString(IDS_DFANALYSIS_OPT_MV1_COLOR);
prop_mv1_colortype=new CMFCPropertyGridColorProperty(resloader,RGB(0, 0, 255), NULL, _T(""));
prop_mv1_colortype->EnableOtherButton(_T("Other..."));
prop_mv1_colortype->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));
resloader.LoadString(IDS_DFANALYSIS_OPT_MV1_STYLE);
prop_mv1_linetype=new CMFCPropertyGridProperty(resloader,(_variant_t) "line", _T(""));
prop_global->AddSubItem(prop_global_showmbedge);
prop_global->AddSubItem(prop_global_showmbedge_color);
//prop_global->AddSubItem(prop_global_font);
prop_global->AddSubItem(prop_global_winsize);
prop_q->AddSubItem(prop_q_shownum);
prop_q->AddSubItem(prop_q_showcolor);
prop_mb_type->AddSubItem(prop_mb_type_showsubmb);
prop_mb_type->AddSubItem(prop_mb_type_showcolor);
prop_mb_type->AddSubItem(prop_mb_type_showskip);
prop_mb_type->AddSubItem(prop_mb_type_showlist);
prop_mv0->AddSubItem(prop_mv0_colortype);
prop_mv0->AddSubItem(prop_mv0_linetype);
prop_mv0->AddOption(_T("line"));
prop_mv0->AddOption(_T("arrow"));
prop_mv0->AllowEdit(FALSE);
prop_mv1->AddSubItem(prop_mv1_colortype);
prop_mv1->AddSubItem(prop_mv1_linetype);
prop_mv1->AddOption(_T("line"));
prop_mv1->AddOption(_T("arrow"));
prop_mv1->AllowEdit(FALSE);
m_dfanalysisoption.AddProperty(prop_global);
m_dfanalysisoption.AddProperty(prop_q);
m_dfanalysisoption.AddProperty(prop_mb_type);
m_dfanalysisoption.AddProperty(prop_mv0);
m_dfanalysisoption.AddProperty(prop_mv1);
//------------------
m_dfanalysisoutpicfolderurl.EnableFolderBrowseButton();
m_dfanalysisoutdatafolderurl.EnableFolderBrowseButton();
TCHAR realpathpic[MAX_URL_LENGTH]={0};
TCHAR realpathdata[MAX_URL_LENGTH]={0};
//生成文件路径
GetCurrentDirectory(MAX_URL_LENGTH,realpathpic);
GetCurrentDirectory(MAX_URL_LENGTH,realpathdata);
CString realpathpic1(realpathpic);
CString realpathdata1(realpathdata);
realpathpic1.Append(_T("\\dfanalysispic"));
realpathdata1.Append(_T("\\dfanalysisdata"));
m_dfanalysisoutpicfolderurl.SetWindowText(realpathpic1);
m_dfanalysisoutpicfolderurl.EnableWindow(FALSE);
m_dfanalysisoutdatafolderurl.SetWindowText(realpathdata1);
m_dfanalysisoutdatafolderurl.EnableWindow(FALSE);
//------------------
picdlg=new Dfanalysispic;
picdlg->Create(IDD_DFANALYSIS_PIC,NULL);
picdlg->dfanalysisdlg=this;
//------------------
dffinish=FALSE;
//------------------
return TRUE;
}
void Dfanalysis::GetOption(){
prop_global_showmbedge_val=prop_global_showmbedge->GetValue().boolVal;
prop_q_shownum_val=prop_q_shownum->GetValue().boolVal;
prop_q_showcolor_val=prop_q_showcolor->GetValue().boolVal;
prop_mb_type_showsubmb_val=prop_mb_type_showsubmb->GetValue().boolVal;
prop_mb_type_showcolor_val=prop_mb_type_showcolor->GetValue().boolVal;
prop_mb_type_showskip_val=prop_mb_type_showskip->GetValue().boolVal;
prop_mb_type_showlist_val=prop_mb_type_showlist->GetValue().boolVal;
prop_mv0_colortype_val=prop_mv0_colortype->GetColor();
prop_mv1_colortype_val=prop_mv1_colortype->GetColor();
prop_global_showmbedge_color_val=prop_global_showmbedge_color->GetColor();
prop_global_winsize_val=(float)(prop_global_winsize->GetValue().intVal)/100.0;
/*
LOGFONT lf;
lf=*prop_global_font->GetLogFont();
if(prop_global_font_val!=NULL){
prop_global_font_val=new CFont;
}
prop_global_font_val->CreateFontIndirect(&lf);
*/
//字符串比较,稍后实现
//prop_mv0_linetype;
//prop_mv1_linetype;
}
void Dfanalysis::OnBnClickedDfanalysisOpen(){
try{
DrawPic();
}catch(...){
CString resloader;
resloader.LoadString(IDS_MSGBOX_ERROR);
AfxMessageBox(resloader);
return;
}
}
void Dfanalysis::DrawPic(){
dffinish=FALSE;
//本窗口重画
//Invalidate();
//如果没有播放,就不分析
if(maindlg->is_playing==0){
CString resloader;
resloader.LoadString(IDS_MSGBOX_NOPLAYING);
AfxMessageBox(resloader);
return ;
}
//显示窗口---
picdlg->ShowWindow(TRUE);
//选项----
GetOption();
//设置参数------------------
CString temp;
temp.Format(_T("%d"),mb_width);
m_dfanalysismbwidth.SetWindowText(temp);
temp.Format(_T("%d"),mb_sum/mb_width);
m_dfanalysismbheight.SetWindowText(temp);
temp.Format(_T("%d"),mb_sum);
m_dfanalysismbsum.SetWindowText(temp);
//每个宏块包含的运动矢量
int mv_sample_log2_temp= 4 - motion_subsample_log2;
temp.Format(_T("%d"),1<<(mv_sample_log2_temp*2));
m_dfanalysismvsubsample.SetWindowText(temp);
//后添加的几个参数---------------------
temp.Format(_T("%d"),frame_index);
m_dfanalysismbframeindex.SetWindowText(temp);
temp.Format(_T("%ld"),pts);
m_dfanalysismbpts.SetWindowText(temp);
temp.Format(_T("%.3fs"),ptime);
m_dfanalysismbptime.SetWindowText(temp);
switch(pict_type){
case AV_PICTURE_TYPE_I:
temp.Format(_T("I"));
m_dfanalysismbpictype.SetWindowText(temp);
break;
case AV_PICTURE_TYPE_B:
temp.Format(_T("B"));
m_dfanalysismbpictype.SetWindowText(temp);
break;
case AV_PICTURE_TYPE_P:
temp.Format(_T("P"));
m_dfanalysismbpictype.SetWindowText(temp);
break;
default:
temp.Format(_T("Other"));
m_dfanalysismbpictype.SetWindowText(temp);
break;
}
temp.Format(_T("%d"),refs);
m_dfanalysismbref.SetWindowText(temp);
switch(qscale_type){
case FF_QSCALE_TYPE_MPEG1:
temp.Format(_T("MPEG1"));break;
case FF_QSCALE_TYPE_MPEG2:
temp.Format(_T("MPEG2"));break;
case FF_QSCALE_TYPE_H264:
temp.Format(_T("H.264"));break;
case FF_QSCALE_TYPE_VP56:
temp.Format(_T("VP5,VP6"));break;
default:
temp.Format(_T("Unknown"));break;
}
m_dfanalysismbqtype.SetWindowText(temp);
CRect rect;
CWnd *dcd=NULL;
HWND phWnd=NULL;
//dcd = picdlg->GetDlgItem(IDD_DFANALYSIS_PIC); // 获取控件句柄
//晕。。。没想到竟然可以强制类型转换
dcd=(CWnd *)picdlg;
CDC *pDC = dcd->GetDC(); // 获取控件设备
dcd->Invalidate();
//这一句会触发cdc的OnPaint()
dcd->UpdateWindow();
//窗口设置大点,看着方便
picdlg->SetWindowPos(NULL,0,0,(int)(width*prop_global_winsize_val),(int)(height*prop_global_winsize_val),SWP_NOMOVE);
dcd->GetClientRect(&rect);
//加载画面
DrawFrame();
pDC->SetWindowExt(rect.Width(), rect.Height()); // 设置窗口范围
//保证绘图不画到框框外面
CRgn rgn;
rgn.CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom);
pDC->SelectClipRgn(&rgn,RGN_AND);
//统计一下--------------------------
int total_intra4x4=0;
int total_intra16x16=0;
int total_16x16=0;
int total_16x8=0;
int total_8x16=0;
int total_8x8=0;
int total_skip=0;
int total_l0=0;
int total_l1=0;
int avgq=0;
int totalq=0;
int maxq=0;
int minq=100;
//输出数据----------------------------------
CString datastat;
//画网格图
//step_w,step_h网格的宽和高
float step_h=(float)rect.Height()/(float)(mb_sum/mb_stride);
//改:最后一列数值总为0,先不输出
float step_w=(float)rect.Width()/(float)(mb_stride-1);
//x,y代表了屏幕坐标
float i,x,y,j;
//输出时候用到的变量
int qval,qvalt,mbtype,refval,refvalt;
//存放运动矢量(x,y)
short mv[2];
CString qval_s,refval_s;
//画刷-------------------
pBrush=new CBrush();
//循环输出
for(j=0;j<(mb_sum/mb_stride);j++){
//for(i=0;i<mb_stride;i++){
//最右侧一行总为0,先不输出
for(i=0;i<mb_width;i++){
//生成一个Rect
CRect rect(i*step_w,j*step_h,(i+1)*step_w,(j+1)*step_h);
//宏块个数
int num=j*mb_stride+i;
//运动矢量个数
//q值
switch(m_dfanalysismethod.GetCurSel()){
case DRAW_Q:{
qval=qscale_table[num];
qval_s.Format(_T("%d"),qval);
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("%d,"),qval);
//等比拉伸一下
//qp取值范围0-51,颜色取值范围0-255
if(prop_q_showcolor_val!=FALSE){
qvalt=qval*255/51;
//会导致内存泄露
//pDC->FillRect(rect,new CBrush(RGB(qvalt,qvalt,qvalt)));
//先创建一个,然后每次Create一个画笔,还要记得DeleteObject
pBrush->CreateSolidBrush(RGB(qvalt,qvalt,qvalt));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
}
//输出字符
if(prop_q_shownum_val!=FALSE){
//背景色透明
//if(prop_global_font_val!=NULL){
// pDC->SelectObject(prop_global_font_val);
//}
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut(rect.left+2,rect.top+2,qval_s);
}
//在指定的矩形内画出字符,(没看出有什么区别)
//pDC->DrawText(qval_s,2,rect,DT_CENTER);
//统计量-------
if(maxq<qval){
maxq=qval;
}
//边缘上总有一个q=0的宏块
if(minq>qval&&qval!=0){
minq=qval;
}
totalq=totalq+qval;
//-------
break;
}
case DRAW_MB_TYPE:{
//防止图片,音频等没有此类信息
if(mb_type==NULL){
return;
}
CPen pen;
pen.CreatePen(PS_SOLID,0,prop_global_showmbedge_color_val);
pDC->SelectObject(pen);
mbtype=mb_type[num];
if(mbtype&MB_TYPE_INTRA4x4){
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("intra4x4,"));
//4x4宏块
if(prop_mb_type_showcolor_val!=FALSE){
pBrush->CreateSolidBrush(RGB(255,0,0));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
}
if(prop_mb_type_showsubmb_val!=FALSE){
//画3条横线和竖线
int m;
//竖线
for(m=1;m<4;m++){
pDC->MoveTo(rect.left+m*rect.Width()/4,rect.top);
pDC->LineTo(rect.left+m*rect.Width()/4,rect.bottom);
}
//横线
for(m=1;m<4;m++){
pDC->MoveTo(rect.left,rect.top+m*rect.Height()/4);
pDC->LineTo(rect.right,rect.top+m*rect.Height()/4);
}
}
//-----
total_intra4x4++;
//-----
}
if(mbtype&MB_TYPE_INTRA16x16){
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("intra16x16,"));
if(prop_mb_type_showcolor_val!=FALSE){
pBrush->CreateSolidBrush(RGB(128,0,0));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
}
//-----
total_intra16x16++;
//-----
}
if(mbtype&MB_TYPE_INTRA_PCM){
if(prop_mb_type_showcolor_val!=FALSE){
pBrush->CreateSolidBrush(RGB(166,0,0));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
}
}
if(mbtype&MB_TYPE_16x16){
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("16x16,"));
if(prop_mb_type_showcolor_val!=FALSE){
pBrush->CreateSolidBrush(RGB(255,99,0));
pDC->FillRect(rect,pBrush);//棕黄
pBrush->DeleteObject();
}
//-----
total_16x16++;
//-----
}
if(mbtype&MB_TYPE_16x8){
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("16x8,"));
if(prop_mb_type_showcolor_val!=FALSE){
pBrush->CreateSolidBrush(RGB(0,99,0));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
}
if(prop_mb_type_showsubmb_val!=FALSE){
//画1条横线
int m;
//横线
for(m=1;m<2;m++){
pDC->MoveTo(rect.left,rect.top+m*rect.Height()/2);
pDC->LineTo(rect.right,rect.top+m*rect.Height()/2);
}
}
//-----
total_16x8++;
//-----
}
if(mbtype&MB_TYPE_8x16){
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("8x16,"));
if(prop_mb_type_showcolor_val!=FALSE){
pBrush->CreateSolidBrush(RGB(255,99,255));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
}
if(prop_mb_type_showsubmb_val!=FALSE){
//画1条竖线
int m;
//竖线
for(m=1;m<2;m++){
pDC->MoveTo(rect.left+m*rect.Width()/2,rect.top);
pDC->LineTo(rect.left+m*rect.Width()/2,rect.bottom);
}
}
//-----
total_8x16++;
//-----
}
if(mbtype&MB_TYPE_8x8){
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("8x8,"));
if(prop_mb_type_showcolor_val!=FALSE){
pBrush->CreateSolidBrush(RGB(0,99,255));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
}
if(prop_mb_type_showsubmb_val!=FALSE){
//画1条横线和竖线
int m;
//竖线
for(m=1;m<2;m++){
pDC->MoveTo(rect.left+m*rect.Width()/2,rect.top);
pDC->LineTo(rect.left+m*rect.Width()/2,rect.bottom);
}
//横线
for(m=1;m<2;m++){
pDC->MoveTo(rect.left,rect.top+m*rect.Height()/2);
pDC->LineTo(rect.right,rect.top+m*rect.Height()/2);
}
}
//-----
total_8x8++;
//-----
}
if(mbtype&MB_TYPE_SKIP){
//“跳过”宏块
if(prop_mb_type_showskip_val!=FALSE){
//背景色透明
pDC->SetBkMode(TRANSPARENT);
//输出字符
pDC->TextOut(rect.left+2,rect.top+2,_T("s"));
}
//-----
total_skip++;
//-----
}
//是否使用list0或者list1进行预测
//画斜线
if(mbtype&MB_TYPE_L0&&(prop_mb_type_showlist_val!=FALSE)){
pDC->SetBkMode(TRANSPARENT);
pDC->MoveTo(rect.left,rect.top);
pDC->LineTo(rect.right,rect.bottom);
total_l0++;
}
if(mbtype&MB_TYPE_L1&&(prop_mb_type_showlist_val!=FALSE)){
pDC->SetBkMode(TRANSPARENT);
pDC->MoveTo(rect.left,rect.bottom);
pDC->LineTo(rect.right,rect.top);
total_l1++;
}
/*
//没弄懂~
//宏块其他特性
if(mbtype&MB_TYPE_INTERLACED){
pDC->FillRect(rect,new CBrush(RGB(0,255,0)));}
if(mbtype&MB_TYPE_DIRECT2){pDC->FillRect(rect,new CBrush(RGB(0,200,0)));
}
if(mbtype&MB_TYPE_ACPRED){
pDC->FillRect(rect,new CBrush(RGB(0,166,0)));}
if(mbtype&MB_TYPE_GMC){pDC->FillRect(rect,new CBrush(RGB(0,133,0)));
}
if(mbtype&MB_TYPE_QUANT){
pDC->FillRect(rect,new CBrush(RGB(0,0,66)));
}
if(mbtype&MB_TYPE_CBP){
pDC->FillRect(rect,new CBrush(RGB(0,0,33)));
}
*/
break;
}
case DRAW_MV0:{
//防止图片,音频,MPEG2等没有此类信息
if(motion_val0==NULL){
CString resloader;
resloader.LoadString(IDS_MSGBOX_NODATA);
AfxMessageBox(resloader);
return;
}
//注意:FFMPEG中运动矢量是单独存放的,与宏块并没有直接的关系
//但是在此处,我们需要通过宏块单元来显示
//例如8x8划分的运动矢量与宏块的关系:
//-------------------------
//| | |
//|mv[x] |mv[x+1] |
//-------------------------
//| | |
//|mv[x+line]|mv[x+line+1]|
//-------------------------
//因此要费不少周折= =
//运动适量加箭头-------------
//ARROWSTRUCT a;
//a.bFill=FALSE;
//a.nWidth=5;
//a.fTheta=60;
//-------------
int mv_sample_log2= 4 - motion_subsample_log2;
//一行MV的个数
//FIX:目前发现H.264的mv_stride和MPEG4,RMVB不一样
//只能区别处理
int mv_stride=0;
if(codec_id==AV_CODEC_ID_H264){
mv_stride=(mb_width << mv_sample_log2);
}else{
mv_stride=(mb_width << mv_sample_log2)+1;
}
//一排宏块包含的MV个数
int mv_mb_stride= mv_stride<<mv_sample_log2;
//一个宏块一行或一列MV个数
int mv_sample=1<<mv_sample_log2;
//当前宏块第一个MV索引值
int mv_num=j*mv_mb_stride+i*mv_sample;
//画运动矢量
CPen pen;
//加载颜色
//pen.CreatePen(PS_SOLID,0,RGB(255,0,0));//设为红色
pen.CreatePen(PS_SOLID,0,prop_mv0_colortype_val);
pDC->SelectObject(pen);
int m,n;
//输出数据[宏块边界]
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("[,"));
//按行和列画出m代表列,n代表行
for(m=0;m<mv_sample;m++){
for(n=0;n<mv_sample;n++){
mv[0]=motion_val0[mv_num+n+m*mv_stride][0];
mv[1]=motion_val0[mv_num+n+m*mv_stride][1];
pDC->MoveTo(rect.left+n*rect.Width()/mv_sample,rect.top+m*rect.Height()/mv_sample);
pDC->LineTo(rect.left+n*rect.Width()/mv_sample+mv[0],rect.top+m*rect.Height()/mv_sample+mv[1]);
//画出来的是箭头而不是直线
//ArrowTo1(pDC->m_hDC,rect.left+n*rect.Width()/mv_sample+mv[0],rect.top+m*rect.Height()/mv_sample+mv[1],&a);
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("(%d-%d),"),mv[0],mv[1]);
}
}
//输出数据[宏块边界]
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("],"));
break;
}
case DRAW_MV1:{
//防止图片,音频,MPEG2等没有此类信息
if(motion_val1==NULL){
CString resloader;
resloader.LoadString(IDS_MSGBOX_NODATA);
AfxMessageBox(resloader);
return;
}
//因此要费不少周折= =
int mv_sample_log2= 4 - motion_subsample_log2;
//一行MV的个数
int mv_stride= (mb_width << mv_sample_log2);
//一排宏块包含的MV个数
int mv_mb_stride= mv_stride<<mv_sample_log2;
//一个宏块一行或一列MV个数
int mv_sample=1<<mv_sample_log2;
//当前宏块第一个MV索引值
int mv_num=j*mv_mb_stride+i*mv_sample;
//画运动矢量
CPen pen;
//pen.CreatePen(PS_SOLID,0,RGB(0,0,255));//设为蓝色
pen.CreatePen(PS_SOLID,0,prop_mv1_colortype_val);
pDC->SelectObject(pen);
int m,n;
//输出数据[宏块边界]
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("[,"));
//按行和列画出m代表列,n代表行
for(m=0;m<mv_sample;m++){
for(n=0;n<mv_sample;n++){
mv[0]=motion_val1[mv_num+n+m*mv_stride][0];
mv[1]=motion_val1[mv_num+n+m*mv_stride][1];
pDC->MoveTo(rect.left+n*rect.Width()/mv_sample,rect.top+m*rect.Height()/mv_sample);
pDC->LineTo(rect.left+n*rect.Width()/mv_sample+mv[0],rect.top+m*rect.Height()/mv_sample+mv[1]);
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("(%d-%d),"),mv[0],mv[1]);
}
}
//输出数据[宏块边界]
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("],"));
break;
}
case DRAW_REFINDEX0:{
//防止图片,音频,MPEG2等没有此类信息
if(ref_index0==NULL){
CString resloader;
resloader.LoadString(IDS_MSGBOX_NODATA);
AfxMessageBox(resloader);
return;
}
//ref_index根据源码判断,每个宏块有4个
//此处只提取第一个
//如果提取四个的话,屏幕会显示不下的= =
refval=ref_index0[num*4];
refval_s.Format(_T("%d"),refval);
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("%d,"),refval);
//等比拉伸一下
//假设参考帧最大值是16帧
//拉伸,平移
//refvalt=refval*255/16;
//获取参考帧的最大值refs
refvalt=refval*128/refs;
refvalt=refvalt+128;
pBrush->CreateSolidBrush(RGB(refvalt,refvalt,refvalt));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
//显示
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut(rect.left+2,rect.top+2,refval_s);
break;
}
case DRAW_REFINDEX1:{
//防止图片,音频,MPEG2等没有此类信息
if(ref_index1==NULL){
CString resloader;
resloader.LoadString(IDS_MSGBOX_NODATA);
AfxMessageBox(resloader);
return;
}
//ref_index根据源码判断,每个宏块有4个
//此处只提取第一个
//如果提取四个的话,屏幕会显示不下的= =
refval=ref_index1[num*4];
refval_s.Format(_T("%d"),refval);
//输出数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("%d,"),refval);
//等比拉伸一下
//假设参考帧最大值是16帧
//拉伸,平移
//refvalt=refval*255/16;
//获取参考帧的最大值refs
refvalt=refval*128/refs;
refvalt=refvalt+128;
pBrush->CreateSolidBrush(RGB(refvalt,refvalt,refvalt));
pDC->FillRect(rect,pBrush);
pBrush->DeleteObject();
//显示
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut(rect.left+2,rect.top+2,refval_s);
break;
}
}
}
//数据输出,统计完一行宏块
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE)
datastat.AppendFormat(_T("\n"));
}
//输出统计量----------------
if(m_dfanalysismethod.GetCurSel()==DRAW_MB_TYPE){
m_dfanalysisnumintra4x4=total_intra4x4;
m_dfanalysisnumintra16x16=total_intra16x16;
m_dfanalysisnum16x16=total_16x16;
m_dfanalysisnum16x8=total_16x8;
m_dfanalysisnum8x16=total_8x16;
m_dfanalysisnum8x8=total_8x8;
m_dfanalysisnumskip=total_skip;
m_dfanalysisnuml0=total_l0;
m_dfanalysisnuml1=total_l1;
//其他线程中调用,不支持UpdateData
if(m_dfanalysisauto.GetCheck()!=1)
UpdateData(FALSE);
}
//---------------------------
if(m_dfanalysismethod.GetCurSel()==DRAW_Q){
m_dfanalysisnumavgq=totalq/((mb_sum/mb_stride)*mb_width);
m_dfanalysisnummaxq=maxq;
m_dfanalysisnumminq=minq;
//其他线程中调用,不支持UpdateData
if(m_dfanalysisauto.GetCheck()!=1)
UpdateData(FALSE);
}
//----------------
//把宏块画成网格图
if(prop_global_showmbedge_val!=FALSE){
CPen pen_default;
//pen_default.CreatePen(PS_SOLID,0,RGB(0,0,0));//设为黑色
pen_default.CreatePen(PS_SOLID,0,prop_global_showmbedge_color_val);
pDC->SelectObject(pen_default);
//画竖线
x=0;
y=0;
for(i=0;i<mb_stride;i++){
x=x+step_w;
pDC->MoveTo(x, 0);
pDC->LineTo(x,rect.Height());
}
//划横线
x=0;
y=0;
for(j=0;j<(mb_sum/mb_stride);j++){
y=y+step_h;
pDC->MoveTo(0, y);
pDC->LineTo(rect.Width(),y);
}
}
delete pBrush;
//-----------
//------------------
ReleaseDC(pDC);
//------
dffinish=TRUE;
//最后结果要保存成BMP,以备万一
hpic=CopyDCToBitmap(picdlg->GetDC()->GetSafeHdc(),rect);
//保存图像
if(m_dfanalysisoutpicfolder.GetCheck()==TRUE){
CString folder_url,pic_name;
m_dfanalysisoutpicfolderurl.GetWindowText(folder_url);
//检查文件夹路径是否存在
CreateDirectory(folder_url,NULL);
switch(m_dfanalysismethod.GetCurSel()){
case DRAW_Q:pic_name.Format(_T("qp_%d.bmp"),frame_index);break;
case DRAW_MB_TYPE:pic_name.Format(_T("mbtype_%d.bmp"),frame_index);break;
case DRAW_MV0:pic_name.Format(_T("mv0_%d.bmp"),frame_index);break;
case DRAW_MV1:pic_name.Format(_T("mv1_%d.bmp"),frame_index);break;
case DRAW_REFINDEX0:pic_name.Format(_T("refindex_%d.bmp"),frame_index);break;
case DRAW_REFINDEX1:pic_name.Format(_T("refindex_%d.bmp"),frame_index);break;
}
folder_url.AppendFormat(_T("\\%s"),pic_name);
SaveBmp(hpic, folder_url);
}
//保存数据
if(m_dfanalysisoutdatafolder.GetCheck()==TRUE){
CString folder_url,data_name;
m_dfanalysisoutdatafolderurl.GetWindowText(folder_url);
//检查文件夹路径是否存在
CreateDirectory(folder_url,NULL);
switch(m_dfanalysismethod.GetCurSel()){
case DRAW_Q:data_name.Format(_T("qp_%d.csv"),frame_index);break;
case DRAW_MB_TYPE:data_name.Format(_T("mbtype_%d.csv"),frame_index);break;
case DRAW_MV0:data_name.Format(_T("mv0_%d.csv"),frame_index);break;
case DRAW_MV1:data_name.Format(_T("mv1_%d.csv"),frame_index);break;
case DRAW_REFINDEX0:data_name.Format(_T("refindex_%d.csv"),frame_index);break;
case DRAW_REFINDEX1:data_name.Format(_T("refindex_%d.csv"),frame_index);break;
}
folder_url.AppendFormat(_T("\\%s"),data_name);
CFile mFile(folder_url,CFile::modeReadWrite|CFile::modeCreate);
mFile.Write(datastat,datastat.GetLength()*sizeof(TCHAR));
mFile.Close();
}
}
void Dfanalysis::ArrowTo1(HDC hDC, int x, int y, ARROWSTRUCT *pA) {
POINT ptTo = {x, y};
ArrowTo(hDC, &ptTo, pA);
}
void Dfanalysis::ArrowTo(HDC hDC, const POINT *lpTo, ARROWSTRUCT *pA) {
POINT pFrom;
POINT pBase;
POINT aptPoly[3];
float vecLine[2];
float vecLeft[2];
float fLength;
float th;
float ta;
// get from point
MoveToEx(hDC, 0, 0, &pFrom);
// set to point
aptPoly[0].x = lpTo->x;
aptPoly[0].y = lpTo->y;
// build the line vector
vecLine[0] = (float) aptPoly[0].x - pFrom.x;
vecLine[1] = (float) aptPoly[0].y - pFrom.y;
// build the arrow base vector - normal to the line
vecLeft[0] = -vecLine[1];
vecLeft[1] = vecLine[0];
// setup length parameters
fLength = (float) sqrt(vecLine[0] * vecLine[0] + vecLine[1] * vecLine[1]);
th = pA->nWidth / (2.0f * fLength);
ta = pA->nWidth / (2.0f * (tanf(pA->fTheta) / 2.0f) * fLength);