The QFAX file format consists of a 64 byte header and a stream of G3 data as defined by the CCITT specification. The data may be encoded lsb or msb first, as defined by the header lsb field. The features of a particular fax file is defined by the version field.
The header is described by the 'C' fragment.
typedef struct { long title; long version; short width; short page; short pagemax; unsigned char resolution; unsigned char coding; int stamp; char tsi[24]; int hint; long offset; char lsb; char dummy[11]; } QFAXHEADER, *PQFAXHEADER; #define QFAXTITLE 'QFAX' #define QFAXVERS '0.07' #define QFAXHEADLEN sizeof(QFAXHEADER)
The title
field contains QFAXTITLE
.
The version field describes the functionality required to process a QFAX file.
0.04
0.05
0.06
0.07
The width
field contains
one of the CCITT G3 pixel line widths of 1728, 2048 or 2432 (stored as
codes 0,1,2).
The resolution field has value 0 for low resolution (3.85 line/mm) or 1 for high (7.7 line/mm).
The coding field has values 0 for 1-D coding, 1 for 2-D coding.
The page
field defines the page size (0=A4, 1=B4, 2=unlimited).
The pagemax
field define the number of pages in the fax.
The stamp
field holds the system time (`C' time_t
value)
when a fax was received using qfax
or encoded using
text2g3
.
The TSI field holds the transmitting station ID, this is filled in by
qfax
when receiving and set to the local ID (`QFAX_DATA' ID
parameter) by text2g3
. The values set by text2g3
are for
convenience, they are not used elsewhere.
The hint
field defines the maximum number of lines in any page in
the fax. It is used as a "hint" by QFAX decoding programs to decide
how much memory is required. Applications that do not support this field
should either set the hint
value to zero set the version
field to 0.04 (or, preferably do both).
The fax file header will be version number '0.07' or greater for variable page size support.
The offset field holds offset from the beginning of file to an array of "page descriptors" that describe any fax pages in the file that differ in coding or resolution from that described by the file header. If all the pages in the file have the same coding and resolution then the offset value will be zero. The offset parameter is only valid for file version '0.07' and greater. The "page descriptors" will be after all valid T.4 fax data in the file and be followed by EOF.
A v0.07 file with a non-zero offset parameter might therefore appear as
Header high res, 1-D, offset != 0 Page 1 data high res, 1-D RTC Page 2 data high res, 2-D RTC Page 3 data low res, 1-D RTC Page 4 data high res, 1-D RTC Descriptor, page 2 (at file position = offset) Descriptor, page 3 EOF
The 'page descriptor' structure is described by the following 'C' fragment.
typedef struct { long offset; // Offset from start of file short pageno; // Page number short code; // Coding value (0/1) short res; // Resolution (0/1) short page; // Page length (0/1/2) } OFFREC;
The following should be carefully noted.
qfax
, qfv
and printfax
recognise a change of
format by the OFFREC.offset value rather than the OFFREC.pageno value.
The OFFREC.pageno and OFFREC.page values are currently maintained for
information only. All offset fields are absolute [lseek(fd, offset,
SEEK_SET)] values.
The following BASIC code may be used to determine the number of pages in a QFAX format fax.
ch = FOP_IN(tfax_fax) GET #ch\12,maxp% CLOSE #ch PRINT "Number of pages in fax file : ";maxp%
The lsb field defines the bit order of the file. If the version is >= 0.06 and lsb != 0, then the file is LSB format, otherwise it is MSB. All pages are the same bit order.