📄 g4tdecod.c
字号:
}
else /* color == BLACK */
{
(*p_decode_black) ((short) (b1 - a0));
color = WHITE;
}
a0 = b1;
if (current_row == EVEN)
{
even_runs [++even_index] = a0;
odd_index++;
}
else /* current_row == ODD */
{
odd_runs [++odd_index] = a0;
even_index++;
}
bit_number = next_state;
break;
case VERTICAL_VR1_MODE: /* the next color change begins one pixel to the
right of its location on the previous row */
#if defined (TRACE)
if (row_number >= TRACE_BEGIN && row_number <= TRACE_END)
printf (" VR1 ");
#endif
if (color == WHITE)
{
(*p_decode_white) ((short) (b1 - a0 + 1));
color = BLACK;
}
else /* color == BLACK */
{
(*p_decode_black) ((short) (b1 - a0 + 1));
color = WHITE;
}
a0 = b1 + 1;
if (current_row == EVEN)
{
even_runs [++even_index] = a0;
odd_index++;
}
else /* current_row == ODD */
{
odd_runs [++odd_index] = a0;
even_index++;
}
bit_number = next_state;
break;
case VERTICAL_VR2_MODE: /* the next color change begins two pixels to
the right of its location on the previous row */
#if defined (TRACE)
if (row_number >= TRACE_BEGIN && row_number <= TRACE_END)
printf (" VR2 ");
#endif
if (color == WHITE)
{
(*p_decode_white) ((short) (b1 - a0 + 2));
color = BLACK;
}
else /* color == BLACK */
{
(*p_decode_black) ((short) (b1 - a0 + 2));
color = WHITE;
}
a0 = b1 + 2;
if (current_row == EVEN)
{
even_runs [++even_index] = a0;
odd_index++;
}
else /* current_row == ODD */
{
odd_runs [++odd_index] = a0;
even_index++;
}
bit_number = next_state;
break;
case VERTICAL_VR3_MODE: /* the next color change begins three pixels to
the right of its location on the previous row */
#if defined (TRACE)
if (row_number >= TRACE_BEGIN && row_number <= TRACE_END)
printf (" VR3 ");
#endif
if (color == WHITE)
{
(*p_decode_white) ((short) (b1 - a0 + 3));
color = BLACK;
}
else /* color == BLACK */
{
(*p_decode_black) ((short) (b1 - a0 + 3));
color = WHITE;
}
a0 = b1 + 3;
if (current_row == EVEN)
{
even_runs [++even_index] = a0;
odd_index++;
}
else /* current_row == ODD */
{
odd_runs [++odd_index] = a0;
even_index++;
}
bit_number = next_state;
break;
case VERTICAL_VL1_MODE: /* the next color change begins one pixel to the
left of its location on the previous row */
#if defined (TRACE)
if (row_number >= TRACE_BEGIN && row_number <= TRACE_END)
printf (" VL1 ");
#endif
if (color == WHITE)
{
(*p_decode_white) ((short) (b1 - a0 - 1));
color = BLACK;
}
else /* color == BLACK */
{
(*p_decode_black) ((short) (b1 - a0 - 1));
color = WHITE;
}
a0 = b1 - 1;
if (current_row == EVEN)
{
even_runs [++even_index] = a0;
odd_index++;
}
else /* current_row == ODD */
{
odd_runs [++odd_index] = a0;
even_index++;
}
bit_number = next_state;
break;
case VERTICAL_VL2_MODE: /* the next color change begins two pixels to
the left of its location on the previous row */
#if defined (TRACE)
if (row_number >= TRACE_BEGIN && row_number <= TRACE_END)
printf (" VL2 ");
#endif
if (color == WHITE)
{
(*p_decode_white) ((short) (b1 - a0 - 2));
color = BLACK;
}
else /* color == BLACK */
{
(*p_decode_black) ((short) (b1 - a0 - 2));
color = WHITE;
}
a0 = b1 - 2;
if (current_row == EVEN)
{
even_runs [++even_index] = a0;
if (a0 < b0) odd_index--;
else odd_index++;
}
else /* current_row == ODD */
{
odd_runs [++odd_index] = a0;
if (a0 < b0) even_index--;
else even_index++;
}
bit_number = next_state;
break;
case VERTICAL_VL3_MODE: /* the next color change begins three pixels to
the left of its location on the previous row */
#if defined (TRACE)
if (row_number >= TRACE_BEGIN && row_number <= TRACE_END)
printf (" VL3 ");
#endif
if (color == WHITE)
{
(*p_decode_white) ((short) (b1 - a0 - 3));
color = BLACK;
}
else /* color == BLACK */
{
(*p_decode_black) ((short) (b1 - a0 - 3));
color = WHITE;
}
a0 = b1 - 3;
if (current_row == EVEN)
{
even_runs [++even_index] = a0;
if (a0 < b0) odd_index--;
else odd_index++;
}
else /* current_row == ODD */
{
odd_runs [++odd_index] = a0;
if (a0 < b0) even_index--;
else even_index++;
}
bit_number = next_state;
break;
case EXT_MODE_UNCOMPRESSED: /* enter extension type 7 ("111"), an
uncompressed encoding scheme */
return (ERROR_UNSUPPORTED_EXTENSION);
break;
case ERROR_MODE: /* The bit pattern found corresponds to an unknown or
invalid codeword. This MAY be one of the seven possible extensions
not defined by the specification. */
return (ERROR_INVALID_CODEWORD);
break;
case ERROR_MODE_1: /* assumed in this implementation to be equivalent
to EOFB (end-of-facsimile-block) */
return (RETURN_OK);
break;
default: /* we should never get here; if we do, the tables are bad */
return (ERROR_PROGRAM_LOGIC);
break;
}
}
if (a0 >= column_limit) new_row ();
}
return (decode_return);
}
/* g4i_initialize () is called to set up to decode a new image. All of the
static data (flags, etc) for g4i_decode () are initialized, allowing the
decoding of multiple images in a run as long as g4i_initialize () is
called before each one. */
char g4i_initialize (short image_width, short image_length)
{
color = WHITE;
bit_number= 0;
current_row = ODD;
even_runs [0] = 0;
even_runs [1] = image_width; /* initial b1 */
even_runs [2] = image_width; /* initial b2 */
odd_runs [0] = 0;
a0 = 0;
even_index = 1; odd_index = 0;
column_limit = image_width;
row_number = 0;
b1 = -1;
decode_return = 0;
return (0);
}
static void new_row ()
{
(*p_decode_new_row) ();
color = WHITE;
if (current_row == ODD)
{
current_row = EVEN;
odd_runs [++odd_index] = a0;
odd_runs [++odd_index] = a0;
odd_index = 1;
even_index = 0;
}
else /* current_row == EVEN */
{
current_row = ODD;
even_runs [++even_index] = a0;
even_runs [++even_index] = a0;
even_index = 1;
odd_index = 0;
}
a0 = 0;
b1 = -1;
#if defined (TRACE)
row_number++;
#endif
}
static short run_length_table [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 128, 192, 256, 320,
384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 1088, 1152, 1216,
1280, 1344, 1408, 1472, 1536, 1600, 1664, 1728, 1792, 1856, 1920, 1984,
2048, 2112, 2176, 2240, 2304, 2368, 2432, 2496, 2560};
static short decode_black_run ()
{
short runlength, accum_runlength = 0;
next_state = (unsigned char) (bit_number + 8);
for (;;) /* exit with "return" */
{
if (!bit_number) code_byte = (*p_decode_next_byte) ();
/* this will fetch a new byte
if the previous codeword ended on a byte boundary */
mode = horiz_mode [next_state] [code_byte];
next_state = horiz_mode_next_state [next_state] [code_byte];
if (mode) /* if digestible */
{
bit_number = next_state;
runlength = run_length_table [mode - 106];
accum_runlength += runlength;
if (runlength < 64) return (accum_runlength);
next_state += 8;
}
else bit_number = 0;
}
}
static short decode_white_run ()
{
short runlength, accum_runlength = 0;
next_state = (unsigned char) bit_number;
for (;;) /* exit with "return" */
{
if (!bit_number) code_byte = (*p_decode_next_byte) ();
/* this will fetch a new byte
if the previous codeword ended on a byte boundary */
mode = horiz_mode [next_state] [code_byte];
next_state = horiz_mode_next_state [next_state] [code_byte];
if (mode) /* if digestible */
{
bit_number = next_state;
runlength = run_length_table [mode - 2];
accum_runlength += runlength;
if (runlength < 64) return (accum_runlength);
}
else bit_number = 0;
}
}
/* end $RCSfile: g4tdecod.c $ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -