encode.c
来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 673 行 · 第 1/2 页
C
673 行
/* DESCRIPTION: Vertical mode is encoded by writing a particualr code/* depending on the offset between a1 and b1./* a0 is moved to a1*/vertical_mode (t4_lineptr)bit_string * t4_lineptr;{ static code_word code [7] = { {7,0x080 }, /* -3 */ {6,0x100 }, /* -2 */ {3,0x800 }, /* -1 */ {1,0x1000 }, /* 0 */ {3,0xc00 }, /* 1 */ {6,0x180 }, /* 2 */ {7,0xc0 }, /* 3 */ }; put_code (t4_lineptr, code[a1 - b1 + 3]); a0 = a1;}/* ROUTINE: Horizontal_mode/*/* SYNOPSIS: Encodes horizontal mode/*/* DESCRIPTION: When horizontal mode is detected no further compaction can/* can take place, so the next two run lengths are written to the output./* a0 is moved to after these runs.*/horizontal_mode (code_lineptr,t4_lineptr,colour)bit_string * t4_lineptr;bit_string * code_lineptr;char colour;{ int a2; static code_word h_code = {3,0x0400}; full_code code; if (a0 == 0) /* special case at start of line */ a0 = 1; /* find a2 */ a2 = *(++code_lineptr->run_pos); if (a2 >= STOP) code_lineptr->run_pos--; put_code (t4_lineptr, h_code); /* code for horiz mode */ /* get & put first run */ code = get_code (a1 - a0, colour); if (code.make.length != 0) put_code (t4_lineptr, code.make); put_code (t4_lineptr, code.term); /* get & put second run */ code = get_code (a2 - a1, 1 - colour); if (code.make.length != 0) put_code (t4_lineptr, code.make); put_code (t4_lineptr, code.term); a0 = a2;}/* ROUTINE: Put_code () *//* *//* SYNOPSIS: appends the code word to the 'line'. *//* */put_code (lineptr,code)bit_string * lineptr;code_word code;{ int i; short mask; mask = MSB_MASK; /* set mask to first bit of pattern */ for (i=0; i< code.length ; i++) { if ((code.pattern & mask) == WHITE) clr_bit (lineptr); else set_bit (lineptr); mask >>= 1; }}/* ROUTINE: put_eoln *//* *//* SYNOPSIS: Puts an end of line marker at the end of a t4 line. *//* An end of line (eoln) marker is 11 (or more) zero's *//* followed by a 1. */put_eoln (lineptr)bit_string * lineptr;{ int i; for (i=0 ; i< 11; i++) clr_bit (lineptr); set_bit (lineptr);}/* ROUTINE: get_runs * * SYNOPSIS: set the runs change buffer fo the next input line * * DESCRIPTION: To optimise the input process, sequences of all 1's or 0's * - the most likely combinations are looked for as special cases, if not * found the runs are counted as bits. * */get_runs (lineptr)bit_string * lineptr;{ register i; char colour = WHITE; *lineptr->run_pos++ = 0; for (i = 1; i <= PIC_LINESIZE; i++) if (get_bit (lineptr) != colour) { *(lineptr->run_pos++) = i; colour = 1 - colour; } *lineptr->run_pos++ = STOP; *lineptr->run_pos = STOP;}/* ROUTINE: set_output; * * SYNOPSIS: Initialises the output buffers, writes the ENODE id, and * leaves room for the length (to be filled in later);*/set_output (lineptr)bit_string * lineptr;{ lineptr->dbuf_top += 28; /* leave room for ASN.1 preamble */ lineptr->dbuf = lineptr->dbuf_top; lineptr->mask = BIT_MASK;}/* ROUTINE: flush_output; * * SYNOPSIS: Flush the output buffer, and set the ASN.1 preamble if * allowed. The normal preamble consists of a SEQUENCE definition * which wraps a SET and a SEQUENCE of BIT STRING. The SET * includes G3-Fax nonbasic parameter indications (such as * twoDimensional, fineResolution, etc.). Optionally, the * old BIT STRING-ish preamble may be selected. */flush_output (lineptr)bit_string * lineptr;{ long length, len; int count, i; if ( lineptr->mask != BIT_MASK ) /* writes last char if necessary */ *lineptr->dbuf++ = lineptr->pos; if ( nopreamble ) { optlen = lineptr->dbuf - lineptr->dbuf_top; return; } /* set byte which indicates unused bits in last byte of image data */ if ( !oldformat ) *(--lineptr->dbuf_top) = 0x00; /* set image length */ len = length = lineptr->dbuf - lineptr->dbuf_top; if (length <= 127) { /* short form length */ *(--lineptr->dbuf_top) = length; } else { /* see how many bytes needed for length */ count = 0; while (len != 0) { len >>= 8; count++; } /* go back and write this info */ for (i = 0; i < count; i++) *(--lineptr->dbuf_top) = (length >> (8 * i)); *(--lineptr->dbuf_top) = 0x80 + count; /* length marker*/ } /* set BIT STRING identifier */ *(--lineptr->dbuf_top) = 0x03; if ( oldformat ) { optlen = lineptr->dbuf - lineptr->dbuf_top; return; } /* set length of BIT STRING sequence */ len = length = lineptr->dbuf - lineptr->dbuf_top; if (length <= 127) { /* short form length */ *(--lineptr->dbuf_top) = length; } else { /* see how many bytes needed for length */ count = 0; while (len != 0) { len >>= 8; count++; } /* go back and write this info */ for (i = 0; i < count; i++) *(--lineptr->dbuf_top) = (length >> (8 * i)); *(--lineptr->dbuf_top) = 0x80 + count; /* length marker*/ } /* set SEQUENCE identifier */ *(--lineptr->dbuf_top) = 0x30; /* set SET which includes g3NonBasicParams */ *(--lineptr->dbuf_top) = uncompressed ? 0x02 : 0x00; *(--lineptr->dbuf_top) = 0; if (unlimitedLength) *lineptr->dbuf_top |= 0x08; if (b4Length) *lineptr->dbuf_top |= 0x04; if (a3Width) *lineptr->dbuf_top |= 0x02; if (b4Width) *lineptr->dbuf_top |= 0x01; *(--lineptr->dbuf_top) = 0; if (twoDimensional) *lineptr->dbuf_top |= 0x80; if (fineResolution) *lineptr->dbuf_top |= 0x40; *(--lineptr->dbuf_top) = 0x00; /* first byte of BIT STRING */ *(--lineptr->dbuf_top) = 0x01; /* count of unused bits */ *(--lineptr->dbuf_top) = 5; /* BIT STRING length */ *(--lineptr->dbuf_top) = 0x81; /* [1] IMPLICIT G3NonBasicParams */ *(--lineptr->dbuf_top) = 7; /* length of SET */ *(--lineptr->dbuf_top) = 0x31; /* SET */ /* set length of entire sequence */ len = length = lineptr->dbuf - lineptr->dbuf_top; if (length <= 127) { /* short form length */ *(--lineptr->dbuf_top) = length; } else { /* see how many bytes needed for length */ count = 0; while (len != 0) { len >>= 8; count++; } /* go back and write this info */ for (i = 0; i < count; i++) *(--lineptr->dbuf_top) = (length >> (8 * i)); *(--lineptr->dbuf_top) = 0x80 + count; /* length marker*/ } /* set [3] IMPLICIT G3Fax identifier */ *(--lineptr->dbuf_top) = 0xa3; optlen = lineptr->dbuf - lineptr->dbuf_top;}/* ROUTINE: set_input;/*/* SYNOPSIS: Initialises the input buffers*/set_input (lineptr)bit_string * lineptr;{ lineptr->mask = BIT_MASK; lineptr->dbuf = lineptr->dbuf_top; lineptr->pos = *lineptr->dbuf++;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?