Go to the first, previous, next, last section, table of contents.

QFAX File Format

General

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)

Header Fields

Header title

The title field contains QFAXTITLE.

Header version

The version field describes the functionality required to process a QFAX file.

0.04
Minimum supported version, multiple pages in a single file. All pages are same coding and resolution. All pages are MSB encoded, the lsb, hint and offset fields are not supported.
0.05
The hint field defines the size of the largest page (in scan lines) in a fax file.
0.06
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. All pages are the same bit order.
0.07
The offset field defines pages where the coding or resolution differs from that given in the header.

Header width

The width field contains one of the CCITT G3 pixel line widths of 1728, 2048 or 2432 (stored as codes 0,1,2).

Header resolution

The resolution field has value 0 for low resolution (3.85 line/mm) or 1 for high (7.7 line/mm).

Header coding

The coding field has values 0 for 1-D coding, 1 for 2-D coding.

Header page

The page field defines the page size (0=A4, 1=B4, 2=unlimited).

Header pagemax

The pagemax field define the number of pages in the fax.

Header stamp

The stamp field holds the system time (`C' time_t value) when a fax was received using qfax or encoded using text2g3.

Header tsi

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.

Header hint

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).

Header offset

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.

  1. v2.5 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.
  2. The QFAXHEADER.hint value is always defined in terms of the QFAXHEADER.resolution value, so if QFAXHEADER.resolution is zero (i.e. normal resolution) and a high resolution page of 2285 lines were the largest page received in a multi-page, varying format fax, then QFAXHEADER.hint would be 1143.
  3. All pages will be stored LSB or MSB as defined by the QFAXHEADER.lsb field.

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%

Header lsb

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.


Go to the first, previous, next, last section, table of contents.