-
Notifications
You must be signed in to change notification settings - Fork 3
/
JPEGsnoopDoc.cpp
2200 lines (1757 loc) · 56.1 KB
/
JPEGsnoopDoc.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
// JPEGsnoop - JPEG Image Decoder & Analysis Utility
// Copyright (C) 2010 - Calvin Hass
// http://www.impulseadventure.com/photo/jpeg-snoop.html
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program 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.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// JPEGsnoopDoc.cpp : implementation of the CJPEGsnoopDoc class
//
#include "stdafx.h"
#include "JPEGsnoop.h"
#include "JPEGsnoopDoc.h"
#include "CntrItem.h"
#include ".\jpegsnoopdoc.h"
#include "WindowBuf.h"
#include "OffsetDlg.h"
#include "DbSubmitDlg.h"
#include "NoteDlg.h"
#include "OverlayBufDlg.h"
#include "LookupDlg.h"
#include "ExportDlg.h"
#include "DecodeDetailDlg.h"
#include "ExportTiffDlg.h"
//#include "OperationDlg.h"
#include "General.h"
#include "FileTiff.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CJPEGsnoopDoc
IMPLEMENT_DYNCREATE(CJPEGsnoopDoc, CRichEditDoc)
BEGIN_MESSAGE_MAP(CJPEGsnoopDoc, CRichEditDoc)
// Enable default OLE container implementation
ON_COMMAND(ID_OLE_EDIT_LINKS, CRichEditDoc::OnEditLinks)
ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, CRichEditDoc::OnUpdateEditLinksMenu)
ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, CRichEditDoc::OnUpdateObjectVerbMenu)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
//ON_COMMAND(ID_FILE_OPENIMAGE, OnFileOpenimage)
ON_COMMAND(ID_FILE_OFFSET, OnFileOffset)
ON_COMMAND(ID_FILE_REPROCESS, OnFileReprocess)
ON_COMMAND(ID_TOOLS_ADDCAMERATODB, OnToolsAddcameratodb)
ON_COMMAND(ID_TOOLS_SEARCHFORWARD, OnToolsSearchforward)
ON_COMMAND(ID_TOOLS_SEARCHREVERSE, OnToolsSearchreverse)
ON_UPDATE_COMMAND_UI(ID_TOOLS_ADDCAMERATODB, OnUpdateToolsAddcameratodb)
ON_UPDATE_COMMAND_UI(ID_TOOLS_SEARCHFORWARD, OnUpdateToolsSearchforward)
ON_UPDATE_COMMAND_UI(ID_TOOLS_SEARCHREVERSE, OnUpdateToolsSearchreverse)
ON_COMMAND_RANGE(ID_PREVIEW_RGB,ID_PREVIEW_CR,OnPreviewRng)
ON_UPDATE_COMMAND_UI_RANGE(ID_PREVIEW_RGB,ID_PREVIEW_CR,OnUpdatePreviewRng)
ON_COMMAND_RANGE(ID_IMAGEZOOM_ZOOMIN,ID_IMAGEZOOM_800,OnZoomRng)
ON_UPDATE_COMMAND_UI_RANGE(ID_IMAGEZOOM_ZOOMIN,ID_IMAGEZOOM_800,OnUpdateZoomRng)
ON_COMMAND(ID_TOOLS_SEARCHEXECUTABLEFORDQT, OnToolsSearchexecutablefordqt)
ON_UPDATE_COMMAND_UI(ID_FILE_REPROCESS, OnUpdateFileReprocess)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
ON_COMMAND(ID_TOOLS_EXTRACTEMBEDDEDJPEG, OnToolsExtractembeddedjpeg)
ON_UPDATE_COMMAND_UI(ID_TOOLS_EXTRACTEMBEDDEDJPEG, OnUpdateToolsExtractembeddedjpeg)
ON_COMMAND(ID_TOOLS_FILEOVERLAY, OnToolsFileoverlay)
ON_UPDATE_COMMAND_UI(ID_TOOLS_FILEOVERLAY, OnUpdateToolsFileoverlay)
ON_COMMAND(ID_TOOLS_LOOKUPMCUOFFSET, OnToolsLookupmcuoffset)
ON_UPDATE_COMMAND_UI(ID_TOOLS_LOOKUPMCUOFFSET, OnUpdateToolsLookupmcuoffset)
ON_COMMAND(ID_OVERLAYS_MCUGRID, OnOverlaysMcugrid)
ON_UPDATE_COMMAND_UI(ID_OVERLAYS_MCUGRID, OnUpdateOverlaysMcugrid)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_YCC, OnUpdateIndicatorYcc)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_MCU, OnUpdateIndicatorMcu)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_FILEPOS, OnUpdateIndicatorFilePos)
ON_COMMAND(ID_SCANSEGMENT_DETAILEDDECODE, OnScansegmentDetaileddecode)
ON_UPDATE_COMMAND_UI(ID_SCANSEGMENT_DETAILEDDECODE, OnUpdateScansegmentDetaileddecode)
ON_COMMAND(ID_TOOLS_EXPORTTIFF, OnToolsExporttiff)
ON_UPDATE_COMMAND_UI(ID_TOOLS_EXPORTTIFF, OnUpdateToolsExporttiff)
END_MESSAGE_MAP()
// CJPEGsnoopDoc construction/destruction
CJPEGsnoopDoc::CJPEGsnoopDoc()
: m_pView(NULL)
{
m_pLog = new CDocLog(this);
if (!m_pLog) {
AfxMessageBox("ERROR: Not enough memory for Document");
exit(1);
}
m_pWBuf = new CwindowBuf();
if (!m_pWBuf) {
AfxMessageBox("ERROR: Not enough memory for Document");
exit(1);
}
// Allocate the JPEG decoder
m_pImgDec = new CimgDecode(m_pLog,m_pWBuf);
if (!m_pWBuf) {
AfxMessageBox("ERROR: Not enough memory for Image Decoder");
exit(1);
}
m_pJfifDec = new CjfifDecode(m_pLog,m_pWBuf,m_pImgDec);
if (!m_pWBuf) {
AfxMessageBox("ERROR: Not enough memory for JFIF Decoder");
exit(1);
}
// Reset all members
Reset();
// Start in quick mode
#ifdef QUICKLOG
m_bLogQuickMode = true;
#else
m_bLogQuickMode = false;
#endif
}
// Cleanup all of the allocated classes
CJPEGsnoopDoc::~CJPEGsnoopDoc()
{
if (m_pJfifDec != NULL)
{
delete m_pJfifDec;
m_pJfifDec = NULL;
}
if (m_pLog != NULL) {
delete m_pLog;
m_pLog = NULL;
}
if (m_pWBuf != NULL) {
delete m_pWBuf;
m_pWBuf = NULL;
}
if (m_pImgDec != NULL) {
delete m_pImgDec;
m_pImgDec = NULL;
}
}
// Reset is only called by the constructor, New and Open
void CJPEGsnoopDoc::Reset()
{
// Reset all members
m_pFile = NULL;
m_lFileSize = 0L;
// No log data available until we open & process a file
m_bFileOpened = FALSE;
m_strPathNameOpened = "";
m_nModeScanDetail = 0;
// Indicate to JFIF process() that document has changed
// and that the scan decode needs to be redone if it
// is to be displayed.
m_pJfifDec->ImgSrcChanged();
// Clean up the quick log
m_saLogQuickTxt.RemoveAll();
m_naLogQuickCol.RemoveAll();
}
BOOL CJPEGsnoopDoc::OnNewDocument()
{
if (!CRichEditDoc::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
Reset();
return TRUE;
}
CRichEditCntrItem* CJPEGsnoopDoc::CreateClientItem(REOBJECT* preo) const
{
return new CJPEGsnoopCntrItem(preo, const_cast<CJPEGsnoopDoc*>(this));
}
// CJPEGsnoopDoc serialization
//CAL! This is called during the standard OnOpenDocument() and presumably
// OnSaveDocument(). Currently it is not implemented.
void CJPEGsnoopDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
// Calling the base class CRichEditDoc enables serialization
// of the container document's COleClientItem objects.
// TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text
CRichEditDoc::Serialize(ar);
}
// CJPEGsnoopDoc diagnostics
#ifdef _DEBUG
void CJPEGsnoopDoc::AssertValid() const
{
CRichEditDoc::AssertValid();
}
void CJPEGsnoopDoc::Dump(CDumpContext& dc) const
{
CRichEditDoc::Dump(dc);
}
#endif //_DEBUG
// CJPEGsnoopDoc commands
// Add a line to the end of the log
int CJPEGsnoopDoc::AppendToLog(CString str, COLORREF color)
{
if (m_bLogQuickMode) {
// Don't exceed a realistic maximum!
unsigned numLines = m_saLogQuickTxt.GetCount();
if (numLines == DOCLOG_MAX_LINES) {
m_saLogQuickTxt.Add("*** TOO MANY LINES IN REPORT -- TRUNCATING ***");
m_naLogQuickCol.Add((unsigned)color);
m_nDisplayRows++;
return 0;
} else if (numLines > DOCLOG_MAX_LINES) {
return 0;
}
m_saLogQuickTxt.Add(str);
m_naLogQuickCol.Add((unsigned)color);
return 0;
}
ASSERT(m_pView);
if (!m_pView) return -1;
CRichEditCtrl* pCtrl = &m_pView->GetRichEditCtrl();
ASSERT(pCtrl);
if (!pCtrl) return -1;
int nOldLines = 0, nNewLines = 0, nScroll = 0;
long nInsertionPoint = 0;
CHARFORMAT cf;
// Save number of lines before insertion of new text
nOldLines = pCtrl->GetLineCount();
// Initialize character format structure
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.dwEffects = 0; // To disable CFE_AUTOCOLOR
cf.crTextColor = color;
// Set insertion point to end of text
nInsertionPoint = pCtrl->GetWindowTextLength();
pCtrl->SetSel(nInsertionPoint, -1);
// Set the character format
pCtrl->SetSelectionCharFormat(cf);
// Replace selection. Because we have nothing
// selected, this will simply insert
// the string at the current caret position.
pCtrl->ReplaceSel(str);
// Get new line count
nNewLines = pCtrl->GetLineCount();
// Scroll by the number of lines just inserted
nScroll = nNewLines - nOldLines;
//pCtrl->LineScroll(nScroll);
// **********************************************************
// Very important that we mark the RichEdit log as not
// being modified. Otherwise we will be asked to save
// changes... If the user hit Yes, they may overwrite their
// image file with the log file!
SetModifiedFlag(false); // Mark as not modified
// **********************************************************
#ifndef QUICKLOG
pCtrl->RedrawWindow();
#endif
return 0;
}
int CJPEGsnoopDoc::InsertQuickLog()
{
if (!m_bLogQuickMode) {
return 0;
}
ASSERT(m_pView);
if (!m_pView) return -1;
CRichEditCtrl* pCtrl = &m_pView->GetRichEditCtrl();
ASSERT(pCtrl);
if (!pCtrl) return -1;
int nOldLines = 0, nNewLines = 0, nScroll = 0;
long nInsertionPoint = 0;
CHARFORMAT cf;
// Save number of lines before insertion of new text
nOldLines = pCtrl->GetLineCount();
// Set insertion point to end of text
nInsertionPoint = pCtrl->GetWindowTextLength();
pCtrl->SetSel(nInsertionPoint, -1);
// Replace selection. Because we have nothing
// selected, this will simply insert
// the string at the current caret position.
pCtrl->SetRedraw(false);
unsigned nQuickLines = m_saLogQuickTxt.GetCount();
COLORREF nCurCol = RGB(0,0,0);
COLORREF nLastCol = RGB(255,255,255);
for (unsigned ind=0;ind<nQuickLines;ind++)
{
nCurCol = m_naLogQuickCol.GetAt(ind);
if (nCurCol != nLastCol) {
// Initialize character format structure
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.dwEffects = 0; // To disable CFE_AUTOCOLOR
cf.crTextColor = nCurCol;
// Set the character format
pCtrl->SetSelectionCharFormat(cf);
}
pCtrl->ReplaceSel(m_saLogQuickTxt.GetAt(ind));
}
pCtrl->SetRedraw(true);
pCtrl->RedrawWindow();
// Empty the quick log since we've used it now
m_saLogQuickTxt.RemoveAll();
m_naLogQuickCol.RemoveAll();
// Get new line count
nNewLines = pCtrl->GetLineCount();
// Scroll by the number of lines just inserted
nScroll = nNewLines - nOldLines;
//pCtrl->LineScroll(nScroll);
// Scroll to the top of the window
pCtrl->LineScroll(-nNewLines);
// **********************************************************
// Very important that we mark the RichEdit log as not
// being modified. Otherwise we will be asked to save
// changes... If the user hit Yes, they may overwrite their
// image file with the log file!
SetModifiedFlag(false); // Mark as not modified
// **********************************************************
return 0;
}
// Save the view pointer (from View init)
void CJPEGsnoopDoc::SetupView(CRichEditView* pView)
{
m_pView = pView;
}
void CJPEGsnoopDoc::AddLine(CString strTxt)
{
AppendToLog(strTxt+"\n",RGB(1, 1, 1));
}
void CJPEGsnoopDoc::AddLineHdr(CString strTxt)
{
AppendToLog(strTxt+"\n",RGB(1, 1, 255));
}
void CJPEGsnoopDoc::AddLineHdrDesc(CString strTxt)
{
AppendToLog(strTxt+"\n",RGB(32, 32, 255));
}
void CJPEGsnoopDoc::AddLineWarn(CString strTxt)
{
AppendToLog(strTxt+"\n",RGB(128, 1, 1));
}
void CJPEGsnoopDoc::AddLineErr(CString strTxt)
{
AppendToLog(strTxt+"\n",RGB(255, 1, 1));
}
void CJPEGsnoopDoc::AddLineGood(CString strTxt)
{
AppendToLog(strTxt+"\n",RGB(16, 128, 16));
}
// ***************************************
CStatusBar* CJPEGsnoopDoc::GetStatusBar()
{
CWnd *pMainWnd = AfxGetMainWnd();
if (!pMainWnd) return NULL;
if (pMainWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
{
CWnd* pMessageBar = ((CFrameWnd*)pMainWnd)->GetMessageBar();
return DYNAMIC_DOWNCAST(CStatusBar,pMessageBar);
}
else
return DYNAMIC_DOWNCAST(CStatusBar,pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR));
}
BOOL CJPEGsnoopDoc::AnalyzeOpen()
{
ASSERT(m_strPathName != "");
if (m_strPathName == "") { AfxMessageBox("ERROR: AnalyzeOpen() but m_strPathName empty"); }
// Clean up if a file is already open
if (m_pFile != NULL)
{
// Mark previous buffer as closed
m_pWBuf->BufFileUnset();
m_pFile->Close();
delete m_pFile;
m_pFile = NULL;
m_lFileSize = 0L;
}
try
{
// Open specified file
// Added in shareDenyNone as this apparently helps resolve some people's troubles
// with an error showing: Couldn't open file "Sharing Violation"
m_pFile = new CFile(m_strPathName, CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone);
}
catch (CFileException* e)
{
char msg[512];
CString strError;
e->GetErrorMessage(msg,sizeof(msg));
// Note: msg includes m_strPathName
strError.Format(_T("ERROR: Couldn't open file: [%s]"),msg);
AfxMessageBox(strError);
m_pFile = NULL;
return FALSE;
}
// Set the file size variable
m_lFileSize = m_pFile->GetLength();
// Don't attempt to load buffer with zero length file!
if (m_lFileSize==0) {
return TRUE;
}
// Open up the buffer
m_pWBuf->BufFileSet(m_pFile);
m_pWBuf->BufLoadWindow(0);
return TRUE;
}
void CJPEGsnoopDoc::AnalyzeClose()
{
// Close the buffer window
m_pWBuf->BufFileUnset();
// Now that we've finished parsing the file, close it!
if (m_pFile != NULL)
{
m_pFile->Close();
delete m_pFile;
m_pFile = NULL;
}
// Mark the doc as clean so that we don't get questioned to save anytime
// we change the file or quit.
//SetModifiedFlag(false);
}
void CJPEGsnoopDoc::AnalyzeFileDo()
{
//CAL! - start
// Get the status bar and configure the decoder to link up to it
CStatusBar* pStatBar;
pStatBar = GetStatusBar();
// Hook up the status bar
m_pJfifDec->SetStatusBar(pStatBar);
m_pImgDec->SetStatusBar(pStatBar);
// Show coach message once
if (theApp.m_pAppConfig->bDecodeScanImg &&
theApp.m_pAppConfig->bCoachDecodeIdct) {
// Show the coaching dialog
CNoteDlg dlg;
if (theApp.m_pAppConfig->bDecodeScanImgAc) {
dlg.strMsg = COACH_DECODE_IDCT_AC;
} else {
dlg.strMsg = COACH_DECODE_IDCT_DC;
}
dlg.DoModal();
theApp.m_pAppConfig->bCoachDecodeIdct = !dlg.bCoachOff;
theApp.m_pAppConfig->Dirty();
}
// Start in Quick mode
#ifdef QUICKLOG
m_bLogQuickMode = true;
#else
m_bLogQuickMode = false;
#endif
CString tmpStr;
AddLine(_T(""));
tmpStr.Format(_T("JPEGsnoop %s by Calvin Hass"),VERSION_STR);
AddLine(tmpStr);
AddLine(_T(" http://www.impulseadventure.com/photo/"));
AddLine(_T(" -------------------------------------"));
AddLine(_T(""));
tmpStr.Format(_T(" Filename: [%s]"),m_strPathName);
AddLine(tmpStr);
tmpStr.Format(_T(" Filesize: [%lu] Bytes"),m_lFileSize);
AddLine(tmpStr);
AddLine(_T(""));
// Perform the actual decoding
if (m_lFileSize>(1<<31)) {
AddLineErr(_T("ERROR: Files larger than 2GB not supported in this version of JPEGsnoop."));
} else if (m_lFileSize == 0) {
AddLineErr(_T("ERROR: File length is zero, no decoding done."));
} else {
m_pJfifDec->process(m_pFile);
}
// In case we are in quick log mode, insert everything at once
InsertQuickLog();
// Now get out of quick mode, because user may issue menu commands
// where we will want to see interactive output
m_bLogQuickMode = false;
// Finished the decoding
// Now force a redraw (especially for Img View window)
// Force a redraw so that we can see animated previews (e.g. AVI)
// when holding down Fwd/Rev Search hotkey
POSITION pos = GetFirstViewPosition();
if (pos != NULL) {
CView* pFirstView = GetNextView( pos );
pFirstView->Invalidate();
pFirstView->RedrawWindow(NULL,0,RDW_UPDATENOW);
}
if (pos != NULL) {
CView* pSecondView = GetNextView( pos );
pSecondView->Invalidate();
pSecondView->RedrawWindow(NULL,0,RDW_UPDATENOW);
}
/*
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = GetNextView(pos);
//pView->UpdateWindow();
pView->RedrawWindow(NULL,0,RDW_UPDATENOW);
}
*/
}
BOOL CJPEGsnoopDoc::AnalyzeFile()
{
BOOL retval;
// Assumes that we have set up the member vars already
// Perform the actual processing. We have this in a routine
// so that we can quickly recalculate the log file again
// if an option changes.
retval = AnalyzeOpen();
if (retval) {
// Only now that we have successfully opened the document
// should be mark the flag as such. This flag is used by
// other menu items to know whether or not the file is ready.
m_bFileOpened = TRUE;
AnalyzeFileDo();
}
AnalyzeClose();
// In the last part of AnalyzeClose(), we mark the file
// as not modified, so that we don't get prompted to save.
return retval;
}
BOOL CJPEGsnoopDoc::ReadLine(CString& strLine,
int nLength,
LONG lOffset /* = -1L */)
{
ULONGLONG lPosition;
if (lOffset != -1L)
lPosition = m_pFile->Seek(lOffset,CFile::begin);
else
lPosition = m_pFile->GetPosition();
if (lPosition == -1L)
{
TRACE2("CJPEGsnoopDoc::ReadLine returns FALSE Seek"
"(%8.8lX, %8.8lX)\n",
lOffset, lPosition);
return FALSE;
}
BYTE* pszBuffer = new BYTE[nLength];
if (!pszBuffer) {
AfxMessageBox("ERROR: Not enough memory for Document ReadLine");
exit(1);
}
int nReturned = m_pFile->Read(pszBuffer, nLength);
if (nReturned <= 0)
{
TRACE2("CJPEGsnoopDoc::ReadLine returns FALSE Read"
"(%d, %d)\n",
nLength,
nReturned);
delete pszBuffer;
return FALSE;
}
CString strTemp;
CString strCharsIn;
strTemp.Format(_T("%8.8lX - "), lPosition);
strLine = strTemp;
for (int nIndex = 0; nIndex < nReturned; nIndex++)
{
if (nIndex == 0)
strTemp.Format(_T("%2.2X"), pszBuffer[nIndex]);
else if (nIndex %16 == 0)
strTemp.Format(_T("=%2.2X"), pszBuffer[nIndex]);
else if (nIndex %8 == 0)
strTemp.Format(_T("-%2.2X"), pszBuffer[nIndex]);
else
strTemp.Format(_T(" %2.2X"), pszBuffer[nIndex]);
if (_istprint(pszBuffer[nIndex]))
strCharsIn += pszBuffer[nIndex];
else
strCharsIn += _T('.');
strLine += strTemp;
}
if (nReturned < nLength)
{
CString strPadding(_T(' '),3*(nLength-nReturned));
strLine += strPadding;
}
strLine += _T(" ");
strLine += strCharsIn;
delete pszBuffer;
return TRUE;
}
// --------------------------------------------------------------------
// --- START OF BATCH PROCESSING
// --------------------------------------------------------------------
// The root of the batch recursion. It simply jumps into the
// recursion loop but initializes the search to start with an
// empty search result.
void CJPEGsnoopDoc::batchProcess()
{
CFolderDialog myFolderDlg(NULL);
CString strDir;
bool bSubdirs;
LPCITEMIDLIST myItemIdList;
myItemIdList = myFolderDlg.BrowseForFolder("Select folder to process",0,0,false);
strDir = myFolderDlg.GetPathName(myItemIdList);
// If the user did not select CANCEL, then proceed with
// the batch operation.
if (strDir != "") {
// Bring up dialog to select subdir recursion
CBatchDlg myBatchDlg;
myBatchDlg.m_bProcessSubdir = false;
myBatchDlg.m_strDir = strDir;
if (myBatchDlg.DoModal() == IDOK) {
// Fetch the settings from the dialog
bSubdirs = myBatchDlg.m_bProcessSubdir;
// Indicate long operation ahead!
CWaitCursor wc;
// TODO:
// - What is the best way to provide a "Cancel Dialog" for a
// recursive operation? I can easily create the cancel / progress
// dialog with operations that have can be single-stepped, but
// not ones that require accumulation on the stack.
// - For now, just leave as-is.
// Example code that I can use for single-stepping the operation:
//
// // === START
// COperationDlg LengthyOp(this);
// LengthyOp.SetFunctions( PrepareOperation, NextIteration, GetProgress );
//
// // Until-done based
// BOOL bOk = LengthyOp.RunUntilDone( true );
// // === END
// Start the batch operation
recurseBatch(strDir,bSubdirs);
// TODO: Clean up after last log output
// Alert the user that we are done
AfxMessageBox("Batch Processing Complete!");
}
}
}
// Recursive routine that searches for files and folders
// Used in batch file processing mode
// INPUT: szPathName = Directory path for current search
// INPUT: bSubdirs = Are we recursing down into subdirectories?
void CJPEGsnoopDoc::recurseBatch(CString szPathName,bool bSubdirs)
{
// The following code snippet is based on MSDN code:
// http://msdn.microsoft.com/en-us/library/scx99850%28VS.80%29.aspx
CFileFind finder;
// build a string with wildcards
CString strWildcard(szPathName);
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we'd
// recur infinitely!
if (finder.IsDots())
continue;
CString strPath = finder.GetFilePath();
// if it's a directory, recursively search it
if (finder.IsDirectory())
{
if (bSubdirs) {
recurseBatch(strPath,bSubdirs);
}
} else {
// GetFilePath() includes both the path & filename
// when called on a file entry, so there is no need
// to specifically call GetFileName()
// CString strFname = finder.GetFileName();
// Perform the actual processing on the file
doBatchSingle(strPath);
}
}
finder.Close();
}
// Perform processing on file selected by the batch recursion
// process recurseBatch().
// PRECONDITION: fName is a file (ie. not directory)
void CJPEGsnoopDoc::doBatchSingle(CString fName)
{
CString fNameExt;
bool bDoSubmit = false;
unsigned ind;
CString fNameOnly;
CString fNameLog;
// Extract the filename (without extension) from the full pathname
fNameOnly = fName.Mid(fName.ReverseFind('\\')+1);
ind = fNameOnly.ReverseFind('.');
fNameOnly = fNameOnly.Mid(0,ind);
// Extract the file extension
ind = fName.ReverseFind('.');
fNameExt = fName.Mid(ind);
fNameExt.MakeLower();
// Only process files that have an extension that implies JPEG
// TODO: Should enable the user to provide a list of extensions
// or even disable check altogether.
if ((fNameExt == ".jpg") || (fNameExt == ".jpeg")) {
// Open the file & begin normal processing
OnOpenDocument(fName);
// Now that we have completed processing, optionally create
// a log file with the report results. Note that this call
// automatically overwrites the previous log filename.
//
// TODO: Add an option in the batch dialog to specify
// action to take if logfile already exists.
//
// ==== WARNING! WARNING! WARNING! ====
// It is *essential* that this Append function work properly
// as it is used to generate the log filename from the
// image filename. Since we may be automatically overwriting
// the logfile, it is imperative that we ensure that there is
// no chance that the log filename happens to be the original
// JPEG filename!
//
// This is perhaps being a bit paranoid, but I feel it is
// worth adding some additional code here to ensure that
// this doesn't happen.
// ==== WARNING! WARNING! WARNING! ====
fNameLog = fName;
fNameLog.Append(".txt");
// Now perform the paranoid checks as described above!
// - Is the last 4 characters of the fName ".txt"?
if (fNameLog.Right(4) != ".txt") {
// Report error message and skip logfile save
AfxMessageBox("ERROR: Internal error #10100");
return;
}
// - Is the fNameLog different from the input filename (fName)?
if (fNameLog == fName) {
// Report error message and skip logfile save
AfxMessageBox("ERROR: Internal error #10101");
return;
}
// Guess the filename is safe, proceed with save
DoDirectSave(fNameLog);
// Now submit entry to database!
#ifdef BATCH_DO_DBSUBMIT
m_pJfifDec->m_strFileName = fNameOnly; // BUG? Should this be "fName"?
bDoSubmit = m_pJfifDec->CompareSignature(true);
if (bDoSubmit) {
m_pJfifDec->PrepareSendSubmit(m_pJfifDec->m_strImgQualExif,m_pJfifDec->m_nDbReqSuggest,"","BATCH");
}
#endif
}
}
// --------------------------------------------------------------------
// --- END OF BATCH PROCESSING
// --------------------------------------------------------------------
void CJPEGsnoopDoc::OnFileOffset()
{
COffsetDlg offsetDlg;
CString dlgStr;
// This function assumes that we've previously opened a file!!!
// Otherwise, there isn't much point in setting the offset value
// since it gets reset to 0 when we open a new file manually!
if (m_bFileOpened) {
AnalyzeOpen();
}
offsetDlg.SetOffset(theApp.m_pAppConfig->nPosStart);
if (offsetDlg.DoModal() == IDOK) {
theApp.m_pAppConfig->nPosStart = offsetDlg.m_nOffsetVal;
m_pJfifDec->ImgSrcChanged();
Reprocess();
} else {
}
if (m_bFileOpened) {
AnalyzeClose();
}
}
void CJPEGsnoopDoc::OnToolsAddcameratodb()
{
CDbSubmitDlg submitDlg;
unsigned nUserSrcPre;
unsigned nUserSrc;
CString strUserSoftware;
CString strQual;
CString strUserNotes;
if (m_pJfifDec->m_strHash == "NONE")
{
// No valid signature, can't submit!
AfxMessageBox("No valid signature could be created, so DB submit is temporarily disabled");
return;
}
submitDlg.m_strExifMake = m_pJfifDec->m_strImgExifMake;
submitDlg.m_strExifModel = m_pJfifDec->m_strImgExifModel;
submitDlg.m_strExifSoftware = m_pJfifDec->m_strSoftware;
submitDlg.m_strUserSoftware = m_pJfifDec->m_strSoftware;
submitDlg.m_strSig = m_pJfifDec->m_strHash; // Only show unrotated sig
submitDlg.m_strQual = m_pJfifDec->m_strImgQualExif;
// Does the image appear to be edited? If so, warn
// the user before submission...
if (m_pJfifDec->m_nDbReqSuggest == DB_ADD_SUGGEST_CAM) {
submitDlg.m_nSource = 0; // Camera
} else if (m_pJfifDec->m_nDbReqSuggest == DB_ADD_SUGGEST_SW) {
submitDlg.m_nSource = 1; // Software
} else {
submitDlg.m_nSource = 2; // I don't know!
}