} /* ReadNextScanLine */ private char[] ProcessTextBlock(DecodeOpRec dr) { uint lowerTextBlockLen = GetNextByte(); uint textBlockLen = dr.textBlockLenHighByte + lowerTextBlockLen; byte[] buff = GetNextBuff(textBlockLen); if (buff == null) { char[] tb = new char[1]; tb[0] = ' '; return(tb); } char[] textBlock = new char[buff.Length]; for (int x = 0; x < buff.Length; ++x) { textBlock[x] = (char)buff[x]; } return(textBlock); } /* ProcessTextBlock */
private void BuildDecodeRecs() { if (convTable4BitTo8Bit == null) { BuildConversionTables(); } decodeRecs = new DecodeOpRec[256]; int x = 0; for (x = 0; x < decodeRecs.Length; x++) { decodeRecs[x] = new DecodeOpRec((Byte)x, convTable4BitTo8Bit); } decodeRawBytes = new DecodeRawByte[256]; for (x = 0; x < decodeRawBytes.Length; x++) { decodeRawBytes[x] = new DecodeRawByte((byte)x, convTable4BitTo8Bit); } } /* BuildDecodeRecs */
} /* ProcessTextBlock */ private void ProcessInstrumentData(DecodeOpRec dr) { UInt32 scanLine = GetNextUint(); UInt32 data = GetNextUint(); }
} /* SkipNextScanLine */ override public void ReadNextScanLine(byte[] scanLine) { bool eol = false; int idx = 0; byte rec = GetNextByte(); while ((!eof) && (!eol)) { DecodeOpRec dr = decodeRecs[rec]; switch (dr.opCode) { case 0:// End of Line eol = true; break; case 1:// Text Block { ProcessTextBlock(dr); } break; case 2:// Instrument Data { // ProcessInstrumentData(dr); } break; case 3: break; // Unused. case 4: // Run Length of 2 case 5: // Run Length of 3 case 6: // Run Length of 4 case 7: // Run Length of 5 case 8: // Run Length of 6 case 9: // Run Length of 7 { int endIdx = idx + (int)dr.runLength - 1; if (endIdx >= scanLine.Length) { endIdx = scanLine.Length - 1; } while (idx <= endIdx) { scanLine[idx] = dr.runLengthChar; ++idx; } } break; case 10: { // Will need to get next byte to determine runLength; int runLen = GetNextByte() + 1; int endIdx = idx + runLen - 1; if (endIdx >= scanLine.Length) { endIdx = scanLine.Length - 1; } while (idx <= endIdx) { scanLine[idx] = dr.runLengthChar; ++idx; } } break; case 11:// Raw-String (1 Pixel Length). { scanLine[idx] = dr.rawPixel; ++idx; } break; case 12:// Raw-String (Even length 2 thru 32). { byte[] buff = GetNextBuff((uint)dr.rawStringBytesToRead); if (buff != null) { for (int x = 0; x < buff.Length; ++x) { decodeRawBytes[buff[x]].FillIntoScanLine(scanLine, ref idx); } } } break; case 13:// Raw-String (Odd Length 1 thru 513). { byte nextByte = GetNextByte(); DecodeRawByte rb = decodeRawBytes[nextByte]; uint bytesToRead = (dr.bytesToReadHighOrder + rb.lower4Bits) + 1; if (idx < scanLine.Length) { scanLine[idx] = rb.pixel1; } byte[] buff = GetNextBuff((uint)bytesToRead); if (buff != null) { for (int x = 0; x < buff.Length; ++x) { decodeRawBytes[buff[x]].FillIntoScanLine(scanLine, ref idx); } } } break; case 14: break; // Unused. case 15: break; // Unused. } if (!eol) { rec = GetNextByte(); } } } /* ReadNextScanLine */
} /* BuildConversionTables */ override public int LengthNextScanLine() { bool eol = false; uint scanLineLen = 0; List <DecodeOpRec> history = new List <DecodeOpRec> (); int[] histogram = new int[16]; for (int x = 0; x < histogram.Length; ++x) { histogram[x] = 0; } Byte rec = GetNextByte(); int recCount = 0; while ((!eof) && (!eol)) { recCount++; DecodeOpRec dr = decodeRecs[rec]; history.Add(dr); histogram[dr.opCode]++; switch (dr.opCode) { case 0:// End of Line eol = true; break; case 1:// Text Block { ProcessTextBlock(dr); } break; case 2:// Instrument Data { ProcessInstrumentData(dr); } break; case 3: break; // Unused. case 4: // Run Length of 2 case 5: // Run Length of 3 case 6: // Run Length of 4 case 7: // Run Length of 5 case 8: // Run Length of 6 case 9: // Run Length of 7 { scanLineLen += dr.runLength; } break; case 10: { // Will need to get next byte to determine runLength; uint runLen = GetNextByte() + (uint)1; scanLineLen += runLen; } break; case 11:// Raw-String (1 Pixel Length). { scanLineLen += 1; } break; case 12:// Raw-String (Even length 2 thru 32). { GetNextBuff((uint)dr.rawStringBytesToRead); scanLineLen += dr.rawStringLen; } break; case 13:// Raw-String (Odd Length 1 thru 513). { byte nextByte = GetNextByte(); uint bytesToRead = (dr.bytesToReadHighOrder + decodeRawBytes[nextByte].lower4Bits) + 1; uint rawStrLen = 1 + bytesToRead * 2; GetNextBuff((uint)bytesToRead); scanLineLen += rawStrLen; } break; case 14: break; // Unused. case 15: break; // Unused. } if (!eol) { rec = GetNextByte(); } } return((int)scanLineLen); } /* LengthNextScanLine */