-
Notifications
You must be signed in to change notification settings - Fork 4
/
ColorHCFR.cpp
1639 lines (1374 loc) · 48.5 KB
/
ColorHCFR.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
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2005-2011 Association Homecinema Francophone. All rights reserved.
/////////////////////////////////////////////////////////////////////////////
//
// This file is subject to the terms of the GNU General Public License as
// published by the Free Software Foundation. A copy of this license is
// included with this software distribution in the file COPYING.htm. If you
// do not have a copy, you may obtain a copy by writing to the Free
// Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details
/////////////////////////////////////////////////////////////////////////////
// Author(s):
// François-Xavier CHABOUD
// Georges GALLERAND
/////////////////////////////////////////////////////////////////////////////
// ColorHCFR.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "ColorHCFR.h"
#include "ColorHCFRConfig.h"
#include "MainFrm.h"
#include "MultiFrm.h"
#include "DataSetDoc.h"
#include "DocTempl.h"
#include "Views/CIEChartView.h"
#include "Views/LuminanceHistoView.h"
#include "Views/RGBHistoView.h"
#include "Views/ColorTempHistoView.h"
#include "Views/MainView.h"
#include "CreditsCtrl.h" // Added by ClassView
#include "Hyperlink.h"
#include "Tools/MainWndPlacement.h"
#include "DocEnumerator.h" //Ki
#include "EyeOneSensor.h"
#include "SerialCom.h"
#include "VersionInfoFromFile.h"
#include "ximage.h"
#include "CWebUpdate.h"
#ifdef USE_NON_FREE_CODE
// Include for device interface (this device interface is outside GNU GPL license)
#include "devlib\CHCFRDI3.h"
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorHCFRApp
BEGIN_MESSAGE_MAP(CColorHCFRApp, CWinApp)
//{{AFX_MSG_MAP(CColorHCFRApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_UPDATE_COMMAND_UI(IDM_VIEW_DATASET, OnUpdateViewDataSet)
ON_UPDATE_COMMAND_UI(IDM_VIEW_CIECHART, OnUpdateViewCiechart)
ON_UPDATE_COMMAND_UI(IDM_VIEW_COLORTEMPHISTO, OnUpdateViewColortemphisto)
ON_UPDATE_COMMAND_UI(IDM_VIEW_LUMINANCEHISTO, OnUpdateViewLuminancehisto)
ON_UPDATE_COMMAND_UI(IDM_VIEW_GAMMAHISTO, OnUpdateViewGammahisto)
ON_UPDATE_COMMAND_UI(IDM_VIEW_NEARBLACKHISTO, OnUpdateViewNearBlackhisto)
ON_UPDATE_COMMAND_UI(IDM_VIEW_NEARWHITEHISTO, OnUpdateViewNearWhitehisto)
ON_UPDATE_COMMAND_UI(IDM_VIEW_RGBHISTO, OnUpdateViewRgbhisto)
ON_UPDATE_COMMAND_UI(IDM_VIEW_SATLUMHISTO, OnUpdateViewSatLumhisto)
ON_UPDATE_COMMAND_UI(IDM_VIEW_SATLUMSHIFT, OnUpdateViewSatLumshift)
ON_UPDATE_COMMAND_UI(IDM_VIEW_MEASURESCOMBO, OnUpdateViewMeasuresCombo)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorHCFRApp construction
CColorHCFRApp::CColorHCFRApp()
{
#ifdef _DEBUG
// uncomment to put on full memory checking which we still have lots of mem leaks/issues
//_CrtSetDbgFlag(0x37);
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_ERROR , _CRTDBG_MODE_DEBUG);
// _CrtSetBreakAlloc(28545);
// _CrtSetBreakAlloc(212642);
// _CrtSetBreakAlloc(28483);
// _CrtSetBreakAlloc(28483);
#endif
// Place all significant initialization in InitInstance
m_hCIEThread = NULL;
m_hCIEEvent = CreateEvent ( NULL, TRUE, FALSE, NULL ); // Manual event starting non-signaled
ResetEvent(m_hCIEEvent);
m_hCursorMeasure = NULL;
m_hSavedCursor = NULL;
m_pPatternWnd = NULL;
m_hLuxThread = NULL;
m_bStopLuxThread = FALSE;
InitializeCriticalSection ( & m_LuxCritSec );
memcpy ( m_RefLuxParams, "\0\0", 2 );
m_CurrentLuxValue = 0.0;
m_bLowLuxValue = FALSE;
m_bHighLuxValue = FALSE;
m_bLowestLuxScale = FALSE;
m_bHighestLuxScale = FALSE;
m_dwPreviousLuxValueTime = 0;
m_dwLuxValueTime = 0;
m_bInsideMeasure = FALSE;
m_dwMeasureStartTime = 0;
m_NbMeasures = 0;
m_bLastMeasureOutOfRange = FALSE;
m_bFirstMeasureWithNewScaleOk = FALSE;
m_bLuxMeasureValid = FALSE;
m_nFirstValidMeasure = 0;
m_MeasuredLuxValue = 0.0;
m_MeasuredLuxValue_Initial = 0.0;
// freopen( "HCFR.log", "w", stderr );
}
CColorHCFRApp::~CColorHCFRApp()
{
#ifdef USE_NON_FREE_CODE
CEyeOneSensor::CloseEyeOnePipe ();
#endif
if ( m_hCIEThread )
{
WaitForSingleObject ( m_hCIEEvent, 10000 );
CloseHandle ( m_hCIEThread );
m_hCIEThread = NULL;
}
CloseHandle ( m_hCIEEvent );
m_hCIEEvent = NULL;
if ( m_hLuxThread )
{
m_bStopLuxThread = TRUE;
if ( WaitForSingleObject ( m_hLuxThread, 10000 ) == WAIT_TIMEOUT )
TerminateThread ( m_hLuxThread, 0 );
CloseHandle ( m_hLuxThread );
m_hLuxThread = NULL;
}
if(m_pColorReference)
{
delete m_pColorReference;
}
if(m_pReferenceData)
{
delete m_pReferenceData;
}
DeleteCriticalSection ( & m_LuxCritSec );
fflush(stderr);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CColorHCFRApp object
CColorHCFRApp theApp;
CColorHCFRConfig * GetConfig()
{
return theApp.m_pConfig;
}
CDataSetDoc * GetDataRef() //Ki
{
return theApp.m_pReferenceData;
}
void SetDataRef(CDataSetDoc *m_pRefData) //Ki
{
theApp.m_pReferenceData = m_pRefData;
}
void UpdateDataRef(BOOL ActiveDataRef, CDataSetDoc * pDoc)
{
CDocEnumerator docEnumerator; // Update all views of all docs
CDocument* pOtherDoc;
if (ActiveDataRef)
{
// Pointer update on reference data
SetDataRef(pDoc);
}
else
{
SetDataRef(NULL);
}
while ( (pOtherDoc=docEnumerator.Next()) != NULL )
pOtherDoc->UpdateAllViews(NULL, UPD_DATAREFDOC);
AfxGetMainWnd () -> SendMessageToDescendants ( WM_COMMAND, IDM_REFRESH_REFERENCE );
}
/////////////////////////////////////////////////////////////////////////////
// CColorHCFRApp initialization
BOOL CColorHCFRApp::InitInstance()
{
// Create splash screen
int cx, cy;
RECT Rect;
CxImage SplashImage;
CWnd SplashWnd;
CDC * pDC;
HRSRC hRsrc = ::FindResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_SPLASH_SCREEN),"SPLASHSCREEN");
SplashImage.LoadResource(hRsrc,CXIMAGE_FORMAT_PNG,AfxGetInstanceHandle());
cx = SplashImage.GetWidth();
cy = SplashImage.GetHeight();
Rect.left = ( GetSystemMetrics(SM_CXSCREEN) - cx ) / 2;
Rect.top = ( GetSystemMetrics(SM_CYSCREEN) - cy ) / 2;
Rect.right = Rect.left + cx;
Rect.bottom = Rect.top + cy;
SplashWnd.CreateEx(WS_EX_TOPMOST,AfxRegisterWndClass(0,NULL,NULL,NULL),NULL,WS_POPUP|WS_VISIBLE, Rect, NULL, 0 );
pDC = SplashWnd.GetDC ();
HBITMAP hMaskBmp, hBmp, hBmp2;
HBITMAP hOldMaskBmp, hOldBmp, hOldBmp2;
CDC MaskDC, MemDC, MemDC2;
// Draw bitmap in memory
MemDC.CreateCompatibleDC ( pDC );
hBmp = CreateCompatibleBitmap ( pDC -> m_hDC, cx, cy );
hOldBmp = (HBITMAP) MemDC.SelectObject ( hBmp );
MemDC2.CreateCompatibleDC ( pDC );
hBmp2 = CreateCompatibleBitmap ( pDC -> m_hDC, cx, cy );
hOldBmp2 = (HBITMAP) MemDC2.SelectObject ( hBmp2 );
SetRect ( & Rect, 0, 0, cx, cy );
SplashImage.Draw ( MemDC.m_hDC, Rect );
// Create mask bitmap
MaskDC.CreateCompatibleDC ( pDC );
hMaskBmp = CreateBitmap ( cx, cy, 1, 1, NULL );
hOldMaskBmp = (HBITMAP) MaskDC.SelectObject ( hMaskBmp );
BitBlt ( MaskDC.m_hDC, 0, 0, cx, cy, MemDC.m_hDC, 0, 0, SRCCOPY );
MaskDC.SelectObject ( hOldMaskBmp );
MaskDC.DeleteDC ();
BitBlt ( MemDC2.m_hDC, 0, 0, cx, cy, pDC -> m_hDC, 0, 0, SRCCOPY );
MaskBlt ( MemDC2.m_hDC, 0, 0, cx, cy, MemDC.m_hDC, 0, 0, hMaskBmp, 0, 0, MAKEROP4(MERGEPAINT,SRCCOPY) );
BitBlt ( pDC -> m_hDC, 0, 0, cx, cy, MemDC2.m_hDC, 0, 0, SRCCOPY );
DeleteObject ( hMaskBmp );
MemDC.SelectObject ( hOldBmp );
MemDC.DeleteDC ();
DeleteObject ( hBmp );
MemDC2.SelectObject ( hOldBmp2 );
MemDC2.DeleteDC ();
DeleteObject ( hBmp2 );
SplashWnd.ReleaseDC ( pDC );
// Beginning of initializations
m_pColorReference = new CColorReference (SDTV,D65,2.2);
m_pConfig = new CColorHCFRConfig();
m_pReferenceData = NULL; //Ki
// SetRegistryKey(_T("ColorHCFR")); // used for MRU
m_pszRegistryKey=NULL; // used for storing parameters in .ini
m_pszProfileName=_tcsdup(m_pConfig->m_iniFileName);
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
if( !CHWinAppEx::InitInstance( _T("{B7C56C2E-F858-4f2b-9054-2F5626377F03}") ) )
if(!m_pConfig->m_doMultipleInstance)
return FALSE;
AfxEnableControlContainer();
CreateCIEBitmaps ( TRUE );
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#if _MFC_VER <= 0x700
# ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
# else
Enable3dControlsStatic(); // Call this when linking to MFC statically
# endif
#endif
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMyMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMyMultiDocTemplate(
IDR_MESURETYPE,
RUNTIME_CLASS(CDataSetDoc),
//RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CMultiFrame), // custom MDI child frame
RUNTIME_CLASS(CMainView));
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Loading toolbar icons into the menu
pDocTemplate->m_NewMenuShared.LoadToolBar(IDR_MENUBARGRAPH);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if(cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew)
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo)) // disabled to avoid default doc creation
return FALSE;
EnableShellOpen ();
RegisterShellFileTypes ();
// Destroy splash screen before displaying main window
SplashWnd.DestroyWindow ();
// The main window has been initialized, so show and update it.
if(GetConfig()->m_doSavePosition)
CMainWndPlacement::InitialShow(m_nCmdShow); // For window restoration
else
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
// Load measure cursor
m_hCursorMeasure = LoadCursor(IDC_CURSOR_MEASURE);
m_hSavedCursor = NULL;
m_LuxPort = GetConfig () -> GetProfileString ( "Defaults", "Luxmeter", "" );
if ( ! m_LuxPort.IsEmpty () )
StartLuxMeasures ();
//check for updates
if (m_pConfig->m_doUpdateCheck)
{
CWebUpdate WebUpdate;
HWND hDlg, hCtrl;
hDlg = ::CreateDialog ( AfxGetResourceHandle (), MAKEINTRESOURCE(IDD_WEB_UPDATE), NULL, NULL );
hCtrl = ::GetDlgItem ( hDlg, IDC_STATIC1 );
::ShowWindow ( hDlg, SW_HIDE );
::UpdateWindow ( hDlg );
WebUpdate.SetLocalDirectory("", true);
WebUpdate.SetUpdateFileURL(" ftp://prairie17.dyndns.org/shares/dload/CheckUpdate.txt");
WebUpdate.SetRemoteURL(" ftp://prairie17.dyndns.org/shares/dload/");
bool cacheDel = DeleteUrlCacheEntry("ftp://prairie17.dyndns.org/shares/dload/CheckUpdate.txt");
cacheDel = DeleteUrlCacheEntry("ftp://prairie17.dyndns.org/shares/dload/ColorHCFR.exe");
int m_WebUp = WebUpdate.DoUpdateCheck();
if (!m_WebUp)
{
//update check failed
::DestroyWindow ( hDlg );
// AfxMessageBox(IDS_UPD_IMPOSSIBLE, MB_OK | MB_ICONWARNING);
return TRUE;
} else if (m_WebUp == -99)
{
//update check timed out
::DestroyWindow ( hDlg );
return TRUE;
}
if (WebUpdate.GetNumberDifferent() == 1)
{
::ShowWindow ( hDlg, SW_SHOW );
::UpdateWindow ( hDlg );
::SetWindowText ( hCtrl, "Version "+WebUpdate.fileVer+" is available..." );
Sleep(1500);
::ShowWindow ( hDlg, SW_HIDE );
CString msg;
msg.LoadStringA(IDS_UPD_ASK_DOWNLOAD);
msg+="(v:"+WebUpdate.fileVer+")";
if (AfxMessageBox(msg, MB_YESNO | MB_ICONQUESTION) == IDYES)
{
::SetWindowText ( hCtrl, "Downloading install file for version to APPDATA, please wait..." );
::ShowWindow ( hDlg, SW_SHOW );
::UpdateWindow ( hDlg );
if (!WebUpdate.DownloadDifferent(0))
::SetWindowText ( hCtrl, "Update failed." );
else
{
CString path;
path = getenv("APPDATA");
path += "\\color\\HCFRSetup.EXE";
::SetWindowText ( hCtrl, "New install package saved to APPDATA." );
if (AfxMessageBox("Install new version(application will close)?", MB_YESNO) == IDYES)
{
ShellExecute(NULL,"open",path,NULL,NULL,1);
ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->SendMessage(WM_CLOSE);
}
}
}
else
{
::ShowWindow ( hDlg, SW_SHOW );
::UpdateWindow ( hDlg );
::SetWindowText ( hCtrl, "Update cancelled." );
}
Sleep(1000);
}
else
{
// ::SetWindowText ( hCtrl, "No updates found." );
// Sleep(1000);
}
::DestroyWindow ( hDlg );
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// Help handling in property sheets
IMPLEMENT_DYNAMIC(CPropertyPageWithHelp, CPropertyPage)
BEGIN_MESSAGE_MAP(CPropertyPageWithHelp, CPropertyPage)
ON_WM_CONTEXTMENU()
ON_COMMAND(IDHELP,OnHelp)
END_MESSAGE_MAP()
void CPropertyPageWithHelp::OnContextMenu(CWnd* pWnd, CPoint pos)
{
Default ();
}
IMPLEMENT_DYNAMIC(CPropertySheetWithHelp, CPropertySheet)
BEGIN_MESSAGE_MAP(CPropertySheetWithHelp, CPropertySheet)
ON_WM_HELPINFO()
ON_COMMAND(IDHELP,OnHelp)
END_MESSAGE_MAP()
void CPropertySheetWithHelp::OnHelp()
{
UINT nId = ( (CPropertyPageWithHelp *) GetActivePage () ) -> GetHelpId ( NULL );
if ( nId )
GetConfig () -> DisplayHelp ( nId, NULL );
}
BOOL CPropertySheetWithHelp::OnHelpInfo ( HELPINFO * pHelpInfo )
{
UINT nId = ( (CPropertyPageWithHelp *) GetActivePage () ) -> GetHelpId ( NULL );
if ( nId )
GetConfig () -> DisplayHelp ( nId, NULL );
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CStatic m_Version;
CHyperLink m_hcfrHyperLink;
CHyperLink m_donationHyperLink;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
CCreditsCtrl m_wndCredits;
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
//}}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)
DDX_Control(pDX, IDC_STATIC_VERSION, m_Version);
DDX_Control(pDX, IDC_HOMECINEMA_HYPERLINK, m_hcfrHyperLink);
DDX_Control(pDX, IDC_DONATION_HYPERLINK, m_donationHyperLink);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CColorHCFRApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CColorHCFRApp message handlers
int CColorHCFRApp::ExitInstance()
{
#ifdef USE_NON_FREE_CODE
DisconnectDevice3();
#endif
if(m_pConfig)
{
delete m_pConfig;
m_pConfig = NULL;
}
return CWinApp::ExitInstance();
}
void CColorHCFRApp::OnUpdateViewDataSet(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewCiechart(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewColortemphisto(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewLuminancehisto(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewGammahisto(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewNearBlackhisto(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewNearWhitehisto(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewRgbhisto(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewSatLumhisto(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewSatLumshift(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
void CColorHCFRApp::OnUpdateViewMeasuresCombo(CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck ( FALSE );
pCmdUI -> Enable ( FALSE );
}
extern void DrawCIEChart(CDC* pDC,int aWidth, int aHeight, BOOL doFullChart, BOOL doShowBlack, BOOL bCIEuv, BOOL bCIEab);
extern void DrawCIEChartWhiteSurrounding(CDC* pDC, int cxMax, int cyMax, BOOL bCIEuv, BOOL bCIEab );
#define CX_CIE_BITMAP 1400
#define CY_CIE_BITMAP 1000
DWORD WINAPI CreateCIEBitmapsThreadFunc ( LPVOID )
{
CrashDump useInThisThread;
try
{
CDC ScreenDC;
CDC BmpDC;
CDC WhiteBmpDC;
CColorHCFRApp * pApp = GetColorApp();
ScreenDC.CreateDC ( "DISPLAY", NULL, NULL, NULL );
BmpDC.CreateCompatibleDC ( & ScreenDC );
WhiteBmpDC.CreateCompatibleDC ( & ScreenDC );
pApp -> m_chartBitmap.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_lightenChartBitmap.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_chartBitmap_white.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_chartBitmap_uv.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_lightenChartBitmap_uv.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_chartBitmap_uv_white.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_chartBitmap_ab.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_lightenChartBitmap_ab.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
pApp -> m_chartBitmap_ab_white.CreateCompatibleBitmap ( & ScreenDC, CX_CIE_BITMAP, CY_CIE_BITMAP );
ScreenDC.DeleteDC ();
CBitmap * pOldBitmap = BmpDC.SelectObject ( & pApp -> m_chartBitmap );
BmpDC.FillSolidRect ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, RGB(0,10,10) );
DrawCIEChart ( & BmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, FALSE, TRUE, FALSE, FALSE );
CBitmap * pOldBitmap2 = WhiteBmpDC.SelectObject ( & pApp -> m_chartBitmap_white );
WhiteBmpDC.BitBlt ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, & BmpDC, 0, 0, SRCCOPY );
DrawCIEChartWhiteSurrounding( & WhiteBmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, FALSE, FALSE );
BmpDC.SelectObject ( & pApp -> m_lightenChartBitmap );
BmpDC.FillSolidRect ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, RGB(0,10,10) );
DrawCIEChart ( & BmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, TRUE, TRUE, FALSE, FALSE );
BmpDC.SelectObject ( & pApp -> m_chartBitmap_uv );
BmpDC.FillSolidRect ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, RGB(0,10,10) );
DrawCIEChart ( & BmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, FALSE, TRUE, TRUE, FALSE );
WhiteBmpDC.SelectObject ( & pApp -> m_chartBitmap_uv_white );
WhiteBmpDC.BitBlt ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, & BmpDC, 10, 10, SRCCOPY );
DrawCIEChartWhiteSurrounding( & WhiteBmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, TRUE, FALSE );
BmpDC.SelectObject ( & pApp -> m_lightenChartBitmap_uv );
BmpDC.FillSolidRect ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, RGB(0,10,10) );
DrawCIEChart ( & BmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, TRUE, TRUE, TRUE, FALSE );
BmpDC.SelectObject ( & pApp -> m_chartBitmap_ab );
BmpDC.FillSolidRect ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, RGB(0,10,10) );
DrawCIEChart ( & BmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, FALSE, TRUE, FALSE, TRUE );
WhiteBmpDC.SelectObject ( & pApp -> m_chartBitmap_ab_white );
WhiteBmpDC.BitBlt ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, & BmpDC, 0, 0, SRCCOPY );
DrawCIEChartWhiteSurrounding( & WhiteBmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, FALSE, TRUE );
BmpDC.SelectObject ( & pApp -> m_lightenChartBitmap_ab );
BmpDC.FillSolidRect ( 0, 0, CX_CIE_BITMAP, CY_CIE_BITMAP, RGB(0,10,10) );
DrawCIEChart ( & BmpDC, CX_CIE_BITMAP, CY_CIE_BITMAP, TRUE, TRUE, FALSE, TRUE );
BmpDC.SelectObject ( pOldBitmap );
WhiteBmpDC.SelectObject ( pOldBitmap2 );
BmpDC.DeleteDC ();
WhiteBmpDC.DeleteDC ();
Sleep ( 0 );
SetEvent ( pApp -> m_hCIEEvent );
if ( pApp -> m_hCIEThread )
{
CloseHandle ( pApp -> m_hCIEThread );
pApp -> m_hCIEThread = NULL;
}
}
catch(std::exception& e)
{
std::cerr << "Exception in bitmap create thread : " << e.what() << std::endl;
}
catch(...)
{
std::cerr << "Unexpected Exception in bitmap create thread" << std::endl;
}
return 0;
}
int CColorHCFRApp::Run()
{
try
{
return CWinApp::Run();
}
catch(std::exception& e)
{
std::cerr << "Exception in main thread : " << e.what() << std::endl;
}
catch(...)
{
std::cerr << "Unexpected Exception in main thread" << std::endl;
}
return 0;
}
void CColorHCFRApp::CreateCIEBitmaps ( BOOL bBackGround )
{
if ( bBackGround )
{
// Background call is only for initial bitmap creation
m_hCIEThread = ::CreateThread ( NULL, 65536, CreateCIEBitmapsThreadFunc, NULL, 0, NULL );
}
else
{
// Test if the thread is still running
if ( WAIT_TIMEOUT == WaitForSingleObject ( m_hCIEEvent, 0 ) )
{
if ( m_hCIEThread )
{
// Increase background thread priority
::SetThreadPriority ( m_hCIEThread, THREAD_PRIORITY_NORMAL );
}
WaitForSingleObject ( m_hCIEEvent, INFINITE );
}
if ( m_chartBitmap.m_hObject )
m_chartBitmap.DeleteObject ();
if ( m_lightenChartBitmap.m_hObject )
m_lightenChartBitmap.DeleteObject ();
if ( m_chartBitmap_white.m_hObject )
m_chartBitmap_white.DeleteObject ();
if ( m_chartBitmap_uv.m_hObject )
m_chartBitmap_uv.DeleteObject ();
if ( m_lightenChartBitmap_uv.m_hObject )
m_lightenChartBitmap_uv.DeleteObject ();
if ( m_chartBitmap_uv_white.m_hObject )
m_chartBitmap_uv_white.DeleteObject ();
if ( m_chartBitmap_ab.m_hObject )
m_chartBitmap_ab.DeleteObject ();
if ( m_lightenChartBitmap_ab.m_hObject )
m_lightenChartBitmap_ab.DeleteObject ();
if ( m_chartBitmap_ab_white.m_hObject )
m_chartBitmap_ab_white.DeleteObject ();
}
if ( m_hCIEThread == NULL )
{
// Cannot create thread: simply call function
CWaitCursor wait;
CreateCIEBitmapsThreadFunc ( NULL );
}
else
{
::SetThreadPriority ( m_hCIEThread, THREAD_PRIORITY_BELOW_NORMAL );
}
}
DWORD WINAPI LuxMeterThreadFunc ( LPVOID lParam )
{
CrashDump useInThisThread;
try
{
int i;
BOOL bRecord = FALSE;
BOOL bEndPacket = FALSE;
BYTE data = 0;
DWORD dwBytesTransferred;
DWORD dwStartTick;
CColorHCFRApp * pApp = (CColorHCFRApp *) lParam;
char szBuf [ 256 ];
HANDLE hCom;
COMMCONFIG cc;
COMMTIMEOUTS ct;
hCom = CreateFile ( pApp -> m_LuxPort, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL );
if ( hCom == INVALID_HANDLE_VALUE )
{
// Error, exit with error code 1
return 1;
}
memset ( & cc, 0, sizeof(cc) );
cc.dwSize = sizeof(cc);
cc.dcb.DCBlength = sizeof(cc.dcb);
dwBytesTransferred = sizeof(cc);
GetDefaultCommConfig ( pApp -> m_LuxPort, & cc, & dwBytesTransferred );
cc.dcb.BaudRate = CBR_9600;
cc.dcb.fBinary = TRUE;
cc.dcb.ByteSize = 8;
cc.dcb.Parity = NOPARITY;
cc.dcb.StopBits = ONESTOPBIT;
if ( ! SetCommConfig ( hCom, & cc, sizeof(cc) ) )
{
CloseHandle ( hCom );
// Exit with error code 2
return 2;
}
if ( ! SetCommMask ( hCom, 0 ) )
{
CloseHandle ( hCom );
// Exit with error code 3
return 3;
}
if ( ! PurgeComm ( hCom, PURGE_RXCLEAR ) )
{
CloseHandle ( hCom );
// Exit with error code 4
return 4;
}
ct.ReadIntervalTimeout = 0;
ct.ReadTotalTimeoutConstant = 1000;
ct.ReadTotalTimeoutMultiplier = 0;
ct.WriteTotalTimeoutConstant = 0;
ct.WriteTotalTimeoutMultiplier = 0;
if ( ! SetCommTimeouts ( hCom, & ct ) )
{
CloseHandle ( hCom );
// Exit with error code 3
return 3;
}
do
{
if ( ReadFile ( hCom, & data, 1, & dwBytesTransferred, NULL ) )
{
if ( dwBytesTransferred > 0 )
{
if ( data == 0x02 )
{
dwStartTick = GetTickCount ();
bRecord = TRUE;
i = 0;
}
if ( bRecord )
{
szBuf [ i ++ ] = (char) data;
if ( data == 0x0D )
{
bRecord = FALSE;
szBuf [ i ] = '\0';
// Interpret data
pApp -> SetLuxmeterValue ( szBuf, dwStartTick );
bEndPacket = TRUE;
}
}
}
}
if ( bEndPacket )
{
bEndPacket = FALSE;
Sleep ( 10 );
}
} while ( ! pApp -> m_bStopLuxThread );
CloseHandle ( hCom );
}
catch(std::exception& e)
{
std::cerr << "Exception in lux meter thread : " << e.what() << std::endl;
}
catch(...)
{
std::cerr << "Unexpected Exception in lux meter thread" << std::endl;
}
return 0;
}
void CColorHCFRApp::SetPatternWindow ( CWnd * pWnd )
{
m_pPatternWnd = pWnd;
}
void CColorHCFRApp::BringPatternWindowToTop ()
{
if ( m_pPatternWnd )
{
m_pPatternWnd -> ModifyStyleEx ( 0, WS_EX_TOPMOST );
m_pPatternWnd -> BringWindowToTop ();
m_pPatternWnd -> UpdateWindow ();
}
}
void CColorHCFRApp::BeginMeasureCursor ()
{
EndMeasureCursor ();
m_hSavedCursor = ::SetCursor ( m_hCursorMeasure );
}
void CColorHCFRApp::RestoreMeasureCursor ()
{
if ( m_hSavedCursor )
::SetCursor ( m_hCursorMeasure );
}
void CColorHCFRApp::EndMeasureCursor ()
{
if ( m_hSavedCursor )
{
::SetCursor ( m_hSavedCursor );
m_hSavedCursor = NULL;
}
}
LRESULT CALLBACK MsgBoxHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{// Process WH_CALLWNDPROCRET hook messages for MessageBox
//
// Local variables
//
// szClassName : Window classname
// pMenu : Pointer to system menu
// hWndParent : Handle to parent window
char szClassName[100] = { NULL };
HWND us = ((LPCWPRETSTRUCT)lParam)->hwnd;
HWND hWndParent = NULL;
if((hWndParent = GetParent(us)) == NULL)
{// No parent found
// Use the desktop window as the parent
hWndParent = GetDesktopWindow();
}
if(!(nCode < 0))
{// Process this message
// Get classname of window
GetClassName(us, szClassName, 100);
if(!lstrcmpi(szClassName, "#32770") && GetConfig()->m_bmoveMessage)
{// Window is messagebox