CAPS Universe documentation  1.0.4
All you need to know to be successful
Data Structures | Macros | Functions
encode_method_1027.h File Reference

Declarations for the 1027 encoding method. More...

Go to the source code of this file.

Data Structures

struct  cm1027_block_data_header
 Brother 1027 encoding method data block's binary header. More...
 
struct  cm1027_block_header
 Brother 1027 encoding method block's binary header. More...
 
struct  cm1027_line
 Brother 1027 method encoded line data. More...
 
struct  cm1027_block
 Collected line data to process a Brother 1027 method print data block. More...
 

Macros

#define C1027_LINE_LENGTH   640
 
#define C1027_MAX_LINES_IN_ONE_BAND   64
 
#define C1027_MAX_WORDS_IN_ONE_BLOCK   0x7FFC
 

Functions

void hl_c1027_block_init (struct cm1027_block *block, unsigned llength)
 
void hl_c1027_block_exit (struct cm1027_block *block)
 
bool hl_c1027_line_check_if_empty (unsigned cnt, const uint16_t line[cnt])
 
void hl_c1027_line_encode (struct cm1027_line *cline, unsigned cnt, const uint16_t line[cnt], const uint16_t *prev)
 
int hl_c1027_block_line_add (struct cm1027_block *block, const struct cm1027_line *line, FILE *outstream)
 
int hl_c1027_block_line_twin_add (struct cm1027_block *block, const struct cm1027_line *line, unsigned cnt, FILE *outstream)
 
int hl_c1027_block_flush (struct cm1027_block *block, FILE *outstream)
 

Macro Definition Documentation

◆ C1027_LINE_LENGTH

#define C1027_LINE_LENGTH   640

Line length in short words for a letter paper at 1200 DPI

Letter has 215.9 mm or 10,200 dots at 1200 DPI. 638 words can cover this amount of dots

◆ C1027_MAX_LINES_IN_ONE_BAND

#define C1027_MAX_LINES_IN_ONE_BAND   64

In the 1027 encoding format, the full page is divided vertically into bands and each band has a maximum count of lines.

The real count depends on the printer device and its available memory. This value is a default only and can be overwritten by the band_line_count_1027 INI variable.

◆ C1027_MAX_WORDS_IN_ONE_BLOCK

#define C1027_MAX_WORDS_IN_ONE_BLOCK   0x7FFC

After reaching this size limit, the current block must be flushed and a new block must start

Calculation of its value: sizeof(struct cm1027_block_header) + encoded data = 0xFFFF

Limited by 16-bit #cm1027_block_header.band_size field - sizeof(struct cm1027_block_data_header) + 0xFFF8 bytes data

Function Documentation

◆ hl_c1027_block_init()

void hl_c1027_block_init ( struct cm1027_block block,
unsigned  llength 
)

Init the printer data block as a preparation of hl_c1027_block_line_add()

Parameters
[in,out]blockPrinter data block info
[in]llengthMax line length in count of words

◆ hl_c1027_block_exit()

void hl_c1027_block_exit ( struct cm1027_block block)

Free resources allocated when processing

Parameters
[in]blockPrinter data block info

◆ hl_c1027_line_check_if_empty()

bool hl_c1027_line_check_if_empty ( unsigned  cnt,
const uint16_t  line[cnt] 
)

Check if a line is empty, e.g. nothing to print

Parameters
[in]lineThe line data to check
[in]cntCount of words in *line
Return values
trueNothing to print
falseLine contains something to print

If all bits in the line are '0' the line contains nothing to print and can be skipped instead. Empty lines can maybe skipped entirely if they are leading a block.

◆ hl_c1027_line_encode()

void hl_c1027_line_encode ( struct cm1027_line cline,
unsigned  cnt,
const uint16_t  line[cnt],
const uint16_t *  prev 
)

Encode one line into the printer's wire format according to the 1027 method

Parameters
[in,out]clineWhere to store the encoded result
[in]cntCount of words in line
[in]lineThe current line to encode
[in]prevThe previous line for reference (can be NULL)
Precondition
line and prev must be independent

◆ hl_c1027_block_line_add()

int hl_c1027_block_line_add ( struct cm1027_block block,
const struct cm1027_line line,
FILE *  outstream 
)

Add one line data to the block

Parameters
[in,out]blockBlock info
[in]lineThe line to add to this block
[in]outstreamThe IO stream to send the printer data to (on demand)
Return values
0on success
-errnoif the data flushing to the printer's stream has failed
-EAGAINAdd the line again, because the block was flushed

This function adds the given line data to the block data and considers the block size limit of C1027_MAX_WORDS_IN_ONE_BLOCK. If the limit is hit, the block gets flushed out to the printer's stream via hl_c1027_block_flush().

Note
In case the already accumulated data hits the block size limit, the line gets ignored and must be added again.
Precondition
A block should never cross a band's boundaries

◆ hl_c1027_block_line_twin_add()

int hl_c1027_block_line_twin_add ( struct cm1027_block block,
const struct cm1027_line line,
unsigned  cnt,
FILE *  outstream 
)

Add one line and a twin of it to the encoded data

Parameters
[in,out]blockBlock info
[in]lineThe line to add to this block
[in]cntFinal length in words of one fully decoded line
[in]outstreamThe IO stream to send the printer data to (on demand)

This function adds two lines to the block for the HQ1200 mode, where the vertical resolution is still 600 DPI but the printer expects the lines for 1200 DPI.

The first line is the line and the second one is a twin of it, encoded as a reuse of the full line content.

◆ hl_c1027_block_flush()

int hl_c1027_block_flush ( struct cm1027_block block,
FILE *  outstream 
)

Flush out the current block and prepare for the next block

Parameters
[in]blockPrinter data block info
[in,out]outstreamThe stream to send the printer data to
Return values
0on success
-errnoif the data flushing to the printer has failed

This flushes the data out to the printer's tream with a leading PCL command of the form:

  • the ESC char
  • "*b"
  • 'block->bused_cnt * 2 + header length' as an integer ASCII number (variable length)
  • the char 'W' (one byte)
  • the c0127_band_header structure content
  • and then appends the whole block data at once.
Attention
The block, e.g. cm1027_block::block_started gets cleared if called!
Note
'Flushing' here means only to write the accumulated line encoding data including the required data header into the printer's stream. Then everything gets prepared to start the next block. It doesn't mean, the printer receives this data immediately (but it can, if the stream's buffer is already full). The real stream flush should happen when processing of the current page finishes.