📄 rfc798.txt
字号:
fact be many scan lines in a block.
The 585 bit data block is composed of a 24 bit sync code which is
used to recognize the beginning of a block, a 37 bit header, 512 bits
of actual data, and a 12 bit CRC checksum:
------------------------------------------------------------------
| 24-bit | 37-bit | 512-bit | 12-bit |
|sync code | header | data | checksum |
------------------------------------------------------------------
The number of useful data bits is variable and can be between 0 and
512 (although there are always 512 bits there, some of them are to be
ignored). The number of data bits to be used is given in the header.
[page 6] Alan R. Katz
RFC 798 DECODING FACSIMILE DATA
IV. The Setup Block and the Data Header
The 37 bits of header is composed of:
------------------------------------------------------------------
| 2-bit |5-bit| 10-bit | 12-bit | 3-bit | 3-bit |2-bit|
|seq num|flags|data count| x position|black size|white size|state|
------------------------------------------------------------------
An explanation of these fields follows:
IMPORTANT NOTE: Most (but not all) of these fields are sent by
the fax machine in REVERSE ORDER. The order of each n-bit field
must be inverted.
Sync code
This is used to synchronize on each block. The value of this
24 bit field is 30474730 octal (not reversed).
Sequence number
This number cycles through 0, 1, 2, 3 for the data blocks. It
is 0 for the Set-Up block (not reversed).
Flags
Each of these flags are 1 bit wide:
Run
Purpose unknown, it always seems to be 1.
Cofb
Purpose unknown, it always seems to be 0.
Rpt
1 for Set-Up blocks (which are repeated when coming from
the fax machine though only one of them is transfered by
FAXIE to TOPS20 and stored in the file) and 0 for data
blocks.
Spare
Purpose unknown, doesn't matter.
Alan R. Katz [page 7]
DECODING FACSIMILE DATA RFC 798
IV. The Setup Block and the Data Header
Sub
1 if this is a Set-Up block.
Data Count
Number of useful bits to use out of the 512 data bits. NOT ALL
of the 512 data bits are used, only this number of them. This
number can be 0 (usually in one of the first data blocks) which
means to throw away this block. (This field is reversed!)
X Position
Current position on the scan line, a value between 0 and 1725.
If this number is greater than where the previous block left
off, the intervening space should be filled with white (0's).
If this number is less than where the previous block left off,
set the X position to this value and replace the overlapped
data with the new data from this block. If this number is
greater than 1726, ignore this field and continue from where
the previous block left off. (This field is reversed!)
Black Size
The size of the black run length field, must be between 2 and
7. This is the correct value for the black size. It may
differ from what was found at the end of the previous block.
(This field is reversed!)
White Size
The size of the white run length field, must be between 2 and
7. It may differ from what was found at the end of the
previous block. (This field is reversed!)
State
The current state. This is the correct state. It may differ
from the state at the end of the previous block. (This field is
not reversed.)
Data
512 bits of the actual encoding of the document. NOT ALL of
this data is used in general, only the amount specified by the
[page 8] Alan R. Katz
RFC 798 DECODING FACSIMILE DATA
IV. The Setup Block and the Data Header
data count. If this is a set up block, the data contains
information about the type of document (see below).
Checksum
CRC checksum on the entire block. Uses polynomial
x**12+x**8+x**7+x**5+x**3+1.
In a setup block, the data portion of the data block consists of:
-----------------------------------------------------------
| 6-bit | 5-bit | 1-bit | 20-bits | 480-bits
| flags | spare |multi page| of zeros | 1's and 0's
-----------------------------------------------------------
Specifically these are:
6 flags (each are 1 bit):
Start bit
Always 0.
Speed
Is 1 if express mode.
Detail
Is 1 if detail mode. (NOTE: If the Detail and Speed flags
are both 0, then data is in Quality mode).
14 inch paper
is 1 if 14 inch paper length.
5.5 inch paper
is 1 if 5.5 inch paper length. (NOTE: If the 14 inch and 5
inch flags are both 0, then paper length is 11 inch).
paper present
is 1 if paper is present at scanner (should be always 1).
Alan R. Katz [page 9]
DECODING FACSIMILE DATA RFC 798
IV. The Setup Block and the Data Header
Spare:
These 5 bits can be any value.
Multi-page:
1 if multi page mode
Rest of data of set-up block:
The above fields are followed by twenty 0 bits and the rest of
the 512 bits of the block are alternating 0's and 1's.
There are a number of important points to be remembered in regard to
the header of a data block. First of all, the data count, the
x-position, and the black and white run sizes must be read IN REVERSE
ORDER. The reason for this is that the fax machine sends these bits
in reverse order. However, the sequence number and the state fields
ARE NOT REVERSED. In addition to this, each run field in the data IS
REVERSED. This reversing of the bits in each n-bit field is
completely separate from the reversing and complementing of each
octet mentioned earlier.
Second, only the first n bits, where n is the value of the data count
field (remember its reversed!), of the data is valid, the rest is to
be ignored. If n is zero, the whole block is to be ignored.
Third, if the x position is beyond where the last block ended, fill
the space between where the last block ended and the current x
postion with white (0's). If the x postition is less then where the
last block ended, replace the overlapped data with the data in the
new block. If the x postition is greater than 1726, ignore it and
continue from where the previous block left off.
Fourth, the black size, white size (reversed), and state (not
reversed!) given in the header are the correct values even if they
disagree with the end of the previous block.
Finally, the sequence number (not reversed) should count through
0,1,2,3. If it does not, a block is missing.
[page 10] Alan R. Katz
RFC 798 DECODING FACSIMILE DATA
V. The Decoding Algorithm
V. The Decoding Algorithm
Upon first glance at the finite state diagram in Figure 1, it may
seem that it would be difficult to create a decoding procedure. For
example, if you are in the WW state, and the next bit is a 1, how do
you know whether to do a transition to WB or BW? The answer to this
is to recognize that every arc out of the BW state begins with 0 and
every arc out of WB begins with 1. Thus, if you are in the WW state,
and the next bit is 1, followed by a 0, you know to go to the BW
state. If the next bit is 1, followed by a 1, you know to go to the
WB state.
In writing the decoding program it was necessary to have two ways of
reading the next bit in the data stream. The first way reads the bit
and "consumes" it, i.e. increments the bit pointer to point at the
next bit. The other way does not "consume" it. Below are four
statements which show how to decode fax data. The numbers in
parentheses are not to be consumed, that is to say they will be read
again in making the next transition.
If I am in state BW (2) and the next bits are:
0 (0): go to BW
0111: go to BB
010 (1): go to WB
0100: go to WW
If I am in state WB (1) and the next bits are:
1 (1): go to WB
1000: go to WW
101 (0): go to BW
1011: go to BB
If I am in state WW (0), then first go through the run length
algorithm, then if the next bits are:
0: go to BB
1 (0): go to BW
1 (1): go to WB
If I am in state BB (3), then first go through the run length
algorithm, then if the next bits are:
0: go to WW
1 (0): go to BW
1 (1): go to WB
For the run length algorithm, remember, look at the next n bits,
where n is the length of either the black or white run length
Alan R. Katz [page 11]
DECODING FACSIMILE DATA RFC 798
V. The Decoding Algorithm
word, REVERSE the bits, and output that many BB's or WW's
(depending on whether black or white run). If the field is full,
increment the size of the word, and get that many bits more, i.e.
get the next n+1 bits, etc. Also, the run length word length can
be decremented according to the rules given in section III.
You always go through the run length even if there is only one WW
or BB, in this case, the run field will be 0.
Let us look at the first example given in section III. Suppose we
want to decode the bits: 110111100010100100100101000... (we have
already reversed the run lengths to make things easier).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -