KSquare Utilities
ScannerFileSimple.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <stdio.h>
3 #include <errno.h>
4 #include <string.h>
5 #include <ctype.h>
6 
7 #include <iostream>
8 #include <fstream>
9 #include <map>
10 #include <vector>
11 
12 #include "MemoryDebug.h"
13 
14 using namespace std;
15 
16 #include "GlobalGoalKeeper.h"
17 #include "KKBaseTypes.h"
18 #include "OSservices.h"
19 #include "RunLog.h"
20 #include "KKStr.h"
21 using namespace KKB;
22 
23 
24 #include "ScannerFile.h"
25 #include "Variables.h"
26 
27 #include "ScannerFileSimple.h"
28 
29 
30 using namespace KKLSC;
31 
32 
33 ScannerFileSimple::ScannerFileSimple (const KKStr& _fileName,
34  RunLog& _log
35  ):
36  ScannerFile (_fileName, _log)
37 {
38 }
39 
40 
41 
42 ScannerFileSimple::ScannerFileSimple (const KKStr& _fileName,
43  kkuint32 _pixelsPerScanLine,
44  kkuint32 _frameHeight,
45  RunLog& _log
46  ):
47  ScannerFile (_fileName, _pixelsPerScanLine, _frameHeight, _log)
48 {
49 }
50 
51 
52 
53 
55 {
56  if (opened)
57  Close ();
58 }
59 
60 
61 
62 
64 {
65  frameBufferLen = 0;
67  if (feof (file) != 0)
68  {
69  memset (frameBuffer, 0, frameBufferSize);
70  return 0;
71  }
72 
74  frameBufferLen = fread (frameBuffer, 1, frameBufferSize, file);
78 } /* ReadBufferFrame */
79 
80 
81 
83 {
84  //int64 byteOffset = osFTELL (file);
85  kkint64 byteOffset = osFTELL (file);
86 
87  kkint64 nextFrameByteOffset = byteOffset + frameBufferSize;
88  kkint32 returnCd = osFSEEK (file, nextFrameByteOffset - 1, SEEK_SET);
89 
90  char buff[10];
91  returnCd = fread (buff, 1, 1, file);
92  if (returnCd < 1)
93  return -1;
94  else
95  return nextFrameByteOffset;
96 } /* SkipToNextFrame */
97 
98 
99 
101 {
103 
104  kkuint32 frameBufferSpaceUsed = frameBufferNextLine * pixelsPerScanLine;
105  fwrite (frameBuffer, 1, frameBufferSpaceUsed, file);
106 
107  kkuint32 paddingNeeded = frameBufferSize - frameBufferSpaceUsed;
108  if (paddingNeeded > 0)
109  {
110  uchar* buff = new uchar[paddingNeeded];
111  memset (buff, 0, paddingNeeded);
112  fwrite (buff, 1, paddingNeeded, file);
113  delete[] buff;
114  }
115 
117 
120 } /* WriteBufferFrame */
121 
122 
123 
124 
125 void ScannerFileSimple::WriteTextBlock (const uchar* txtBlock,
126  kkuint32 txtBlockLen
127  )
128 {
129  log.Level (-1) << endl
130  << "ScannerFileSimple::WriteTextBlock ***ERROR*** The SimpleFormat does not support TextBlocks" << endl
131  << endl;
132 } /* WriteTextBlock */
133 
134 
135 
136 
138 {
140 
141  uchar* cs = new uchar[256];
142  for (kkuint32 x = 0; x < 256; ++x)
143  cs[x] = x;
144 
146 
147  return cs;
148 }
kkint64 frameBufferFileOffsetLast
Definition: ScannerFile.h:427
kkint64 frameBufferFileOffsetNext
Definition: ScannerFile.h:429
kkint64 fileSizeInBytes
Definition: ScannerFile.h:396
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint64 osFTELL(FILE *f)
Calls the appropriate 64 bit function for operating system.
Definition: OSservices.cpp:93
static const uchar * CompensationTable()
virtual void WriteTextBlock(const uchar *txtBlock, kkuint32 txtBlockLen)
virtual void WriteBufferFrame()
Write the contents of &#39;frameBuffer&#39; to he end of the scanner file.
kkuint32 frameBufferLen
Definition: ScannerFile.h:435
kkuint32 frameBufferSize
Definition: ScannerFile.h:447
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
__int64 kkint64
Definition: KKBaseTypes.h:90
KKTHread * KKTHreadPtr
ScannerFileSimple(const KKStr &_fileName, kkuint32 _pixelsPerScanLine, kkuint32 _frameHeight, RunLog &_log)
virtual kkint64 SkipToNextFrame()
Skip to start of next frame returning back byte offset of that frame.
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
Contains Classes that are specific to Cameras physical characteristics.
kkuint32 frameBufferNextLine
Definition: ScannerFile.h:441
kkuint32 pixelsPerScanLine
Definition: ScannerFile.h:407
Used for logging messages.
Definition: RunLog.h:49
ScannerFileSimple(const KKStr &_fileName, RunLog &_log)
ScannerFile(const KKStr &_fileName, kkuint32 _pixelsPerScanLine, kkuint32 _frameHeight, RunLog &_log)
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.
ScannerFile(const KKStr &_fileName, RunLog &_log)
Definition: ScannerFile.cpp:40
virtual kkuint32 ReadBufferFrame()
Read in one Scanner File Frame return number of actual scan-lines read.