25 using namespace KKLSC;
107 BuildConversionTables ();
108 AllocateWorkLineAndOutputBuf ();
109 memset (fourSpaces, 0,
sizeof (fourSpaces));
110 memset (fourBlackOuts, 7,
sizeof (fourBlackOuts));
127 BuildConversionTables ();
128 AllocateWorkLineAndOutputBuf ();
129 memset (fourSpaces, 0,
sizeof (fourSpaces));
130 memset (fourBlackOuts, 7,
sizeof (fourBlackOuts));
139 delete outputBuff; outputBuff = NULL;
140 delete workLine; workLine = NULL;
149 if (!convTable3BitTo8Bit)
153 float inc = 255.0f / 8.0f;
154 convTable3BitTo8Bit =
new uchar[8];
155 convTable8BitTo3Bit =
new uchar[256];
156 for (x = 0; x < 8; ++x)
161 kkint32 threeBitTo8BitNum = (
kkint32)(this8Bit + (x / 7.0f) * (next8Bit - this8Bit));
163 convTable3BitTo8Bit[x] = (
uchar)threeBitTo8BitNum;
164 for (y = this8Bit; y <= next8Bit; ++y)
165 convTable8BitTo3Bit[y] = x;
168 compensationTable =
new uchar[256];
169 for (
kkint16 pv = 0; pv < 256; ++pv)
171 uchar encodedValue = convTable8BitTo3Bit[pv];
172 compensationTable[pv] = convTable3BitTo8Bit[encodedValue];
175 atexit (ScannerFile3BitEncoded::ExitCleanUp);
186 if (!compensationTable)
187 BuildConversionTables ();
190 return compensationTable;
198 delete convTable3BitTo8Bit; convTable3BitTo8Bit = NULL;
199 delete convTable8BitTo3Bit; convTable8BitTo3Bit = NULL;
200 delete compensationTable; compensationTable = NULL;
209 delete outputBuff; outputBuff = NULL;
210 delete workLine; workLine = NULL;
212 workLineLen = Max (1024U, pixelsPerScanLine);
213 workLine =
new uchar[workLineLen];
215 outputBuffLen = workLineLen / 4 + 10;
216 outputBuff =
new OpRec[outputBuffLen];
224 ScannerFile::ScanRate (_scanRate);
234 if (feof (file) != 0)
236 memset (frameBuffer, 0, frameBufferSize);
241 kkuint32 numScanLinesReadThisFrameBuffer = 0;
244 while ((feof (file) == 0) && (numScanLinesReadThisFrameBuffer < frameHeight))
246 GetNextScanLine (buffPtr, pixelsPerScanLine);
247 frameBufferLen += pixelsPerScanLine;
248 buffPtr += pixelsPerScanLine;
249 ++numScanLinesReadThisFrameBuffer;
252 bool endOfFileFound = (feof (file) != 0);
254 cerr <<
"end of file was found." << endl;
258 return numScanLinesReadThisFrameBuffer;
267 kkuint32 numScanLinesReadThisFrameBuffer = 0;
268 while ((feof (file) == 0) && (numScanLinesReadThisFrameBuffer < frameHeight))
270 GetNextScanLine (scanLine, pixelsPerScanLine);
271 ++numScanLinesReadThisFrameBuffer;
277 if (feof (file) != 0)
280 return osFTELL (file);
296 char* textMsg = NULL;
301 recsRead = fread (&rec,
sizeof (rec), 1, file);
318 if (numTextBytes < 1)
325 char* textMsgPtr = NULL;
329 textMsg =
new char[numTextBytes];
330 textMsgLen = numTextBytes;
331 textMsgPtr = textMsg;
335 kkint32 newTextMsgLen = textMsgLen + numTextBytes;
336 char* newTextMsg =
new char[newTextMsgLen];
337 memcpy (newTextMsg, textMsg, textMsgLen);
338 textMsgPtr = newTextMsg + textMsgLen;
340 textMsg = newTextMsg;
342 textMsgLen = newTextMsgLen;
345 recsRead = fread (textMsgPtr, 1, numTextBytes, file);
346 if (recsRead < numTextBytes)
352 ReportTextMsg (textMsg, textMsgLen);
353 delete[] textMsg; textMsg = NULL;
363 if (lineSize >= (lineBuffSize - 4))
366 lineSize = lineBuffSize;
375 lineBuff[lineSize] = pix0;
378 lineBuff[lineSize] = pix1;
381 lineBuff[lineSize] = pix2;
384 lineBuff[lineSize] = pix3;
394 kkuint32 newLineSize = lineSize + numSpaces;
395 if (newLineSize >= lineBuffSize)
397 numSpaces = lineBuffSize - lineSize;
398 newLineSize = lineBuffSize;
401 memset (&(lineBuff[lineSize]), 0, numSpaces);
402 lineSize = newLineSize;
411 kkuint32 newLineSize = lineSize + numBlackOuts;
412 if (newLineSize >= lineBuffSize)
414 if (lineSize > lineBuffSize)
415 cout << endl <<
"How Can This Happen !!!!" << endl << endl;
417 numBlackOuts = lineBuffSize - lineSize;
418 newLineSize = lineBuffSize;
421 memset (&(lineBuff[lineSize]), 255, numBlackOuts);
422 lineSize = newLineSize;
432 kkuint32 newLineSize = lineSize + runLen;
433 if (newLineSize >= lineBuffSize)
435 runLen = lineBuffSize - lineSize;
436 newLineSize = lineBuffSize;
439 memset (&(lineBuff[lineSize]), pixelValue, runLen);
440 lineSize = newLineSize;
449 ReportTextMsg (textMsg, textMsgLen);
450 delete[] textMsg; textMsg = NULL;
493 if (num4SpacesInARow > 0)
500 num4SpacesInARow = 0;
512 if (num4BlackOutsInARow > 0)
519 num4BlackOutsInARow = 0;
531 if (bufferLen > workLineLen)
535 workLine =
new uchar[bufferLen];
536 workLineLen = bufferLen;
539 for (x = 0; x < bufferLen; ++x)
540 workLine[x] = convTable8BitTo3Bit[buffer[x]];
544 kkint32 num4BlackOutsInARow = 0;
546 uchar* workLinePtr = workLine;
547 OpRecPtr outputBuffPtr = outputBuff;
549 while (x < (bufferLen - 3))
551 if (memcmp (workLinePtr, fourSpaces,
sizeof (fourSpaces)) == 0)
553 Write4BlackOuts (outputBuffPtr, outputBuffUsed, num4BlackOutsInARow, 0);
559 else if (memcmp (workLinePtr, fourBlackOuts,
sizeof (fourBlackOuts)) == 0)
561 Write4Spaces (outputBuffPtr, outputBuffUsed, num4SpacesInARow, 0);
562 ++num4BlackOutsInARow;
569 Write4Spaces (outputBuffPtr, outputBuffUsed, num4SpacesInARow, 0);
570 Write4BlackOuts (outputBuffPtr, outputBuffUsed, num4BlackOutsInARow, 0);
572 outputBuffPtr->rawPixels.opCode = 1;
573 outputBuffPtr->rawPixels.eol = 0;
574 outputBuffPtr->rawPixels.pix0 = workLine[x]; ++x;
575 outputBuffPtr->rawPixels.pix1 = workLine[x]; ++x;
576 outputBuffPtr->rawPixels.pix2 = workLine[x]; ++x;
577 outputBuffPtr->rawPixels.pix3 = workLine[x]; ++x;
584 if (num4SpacesInARow > 0)
585 Write4Spaces (outputBuffPtr, outputBuffUsed, num4SpacesInARow, 1);
587 else if (num4BlackOutsInARow > 0)
588 Write4BlackOuts (outputBuffPtr, outputBuffUsed, num4BlackOutsInARow, 1);
593 fwrite (outputBuff,
sizeof (OpRec), outputBuffUsed, file);
608 if (bufferLen > workLineLen)
612 workLine =
new uchar[bufferLen];
613 workLineLen = bufferLen;
616 for (x = 0; x < bufferLen; ++x)
617 workLine[x] = convTable8BitTo3Bit[buffer[x]];
619 curCompStatus = csNull;
623 kkint32 num4BlackOutsInARow = 0;
625 uchar* workLinePtr = workLine;
626 OpRecPtr outputBuffPtr = outputBuff;
628 while (x < (bufferLen - 3))
630 if (memcmp (workLinePtr, fourSpaces,
sizeof (fourSpaces)) == 0)
632 Write4BlackOuts (outputBuffPtr, outputBuffUsed, num4BlackOutsInARow, 0);
638 else if (memcmp (workLinePtr, fourBlackOuts,
sizeof (fourBlackOuts)) == 0)
640 Write4Spaces (outputBuffPtr, outputBuffUsed, num4SpacesInARow, 0);
641 ++num4BlackOutsInARow;
648 Write4Spaces (outputBuffPtr, outputBuffUsed, num4SpacesInARow, 0);
649 Write4BlackOuts (outputBuffPtr, outputBuffUsed, num4BlackOutsInARow, 0);
651 outputBuffPtr->rawPixels.opCode = 1;
652 outputBuffPtr->rawPixels.eol = 0;
654 outputBuffPtr->rawPixels.pix0 = workLine[x]; ++x;
655 outputBuffPtr->rawPixels.pix1 = workLine[x]; ++x;
656 outputBuffPtr->rawPixels.pix2 = workLine[x]; ++x;
657 outputBuffPtr->rawPixels.pix3 = workLine[x]; ++x;
664 if (num4SpacesInARow > 0)
665 Write4Spaces (outputBuffPtr, outputBuffUsed, num4SpacesInARow, 1);
667 else if (num4BlackOutsInARow > 0)
668 Write4BlackOuts (outputBuffPtr, outputBuffUsed, num4BlackOutsInARow, 1);
673 fwrite (outputBuff,
sizeof (OpRec), outputBuffUsed, file);
687 kkint32 charsLeft = txtBlockLen;
688 const uchar* txtBlockPtr = txtBlock;
689 while (charsLeft > 0)
691 kkint32 charsToWrite = Min (4096, charsLeft);
696 fwrite (&rec,
sizeof (rec), 1, file);
697 fwrite (txtBlockPtr, 1, charsToWrite, file);
698 charsLeft -= charsToWrite;
699 txtBlockPtr += charsToWrite;
__int16 kkint16
16 bit signed integer.
kkint64 frameBufferFileOffsetLast
kkint64 frameBufferFileOffsetNext
kkint64 osFTELL(FILE *f)
Calls the appropriate 64 bit function for operating system.
virtual ~ScannerFile3BitEncoded()
unsigned __int32 kkuint32
OpRec4RawPixels rawPixels
virtual void ScanRate(float _scanRate)
unsigned char uchar
Unsigned character.
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
virtual kkint64 SkipToNextFrame()
Skip to start of next frame returning back byte offset of that frame.
Contains Classes that are specific to Cameras physical characteristics.
kkuint32 ReadBufferFrame()
Read on one Scanner File Frame.
unsigned short ushort
Unsigned short.
ScannerFile3BitEncoded(const KKStr &_fileName, kkuint32 _pixelsPerScanLine, kkuint32 _frameHeight, RunLog &_log)
Implements a 3 bit Encoded format.
static const uchar * CompensationTable()
kkuint32 frameBufferNextLine
kkuint32 pixelsPerScanLine
Used for logging messages.
virtual void WriteTextBlock(const uchar *txtBlock, kkuint32 txtBlockLen)
virtual void WriteBufferFrame()
Write the contents of 'frameBuffer' to he end of the scanner file.
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.
ScannerFile3BitEncoded(const KKStr &_fileName, RunLog &_log)
ScannerFile(const KKStr &_fileName, RunLog &_log)