mirror of http://192.168.1.51:8099/lmh188/twain3.0
669 lines
23 KiB
C
669 lines
23 KiB
C
|
#pragma once
|
||
|
#define White 0
|
||
|
#define Black 1
|
||
|
#define Black_byte 255 // byte of all black bits: 11111111b
|
||
|
|
||
|
|
||
|
/* WARNING */
|
||
|
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
|
||
|
/* !!!!!!!!!!!!!!!!!! Change Here. Redeclaration of Type. !!!!!!!!!!!!!!!! */
|
||
|
#define SHORT int /* this type was just a regular old C "short". */
|
||
|
/* In images with > 2^15 rows the 2 byte definition */
|
||
|
/* gave garbage output because short overflowed. */
|
||
|
/* Increasing all variables from 2 to 4 bytes seems */
|
||
|
/* to fix it. I have used the macro SHORT here to show */
|
||
|
/* where this change applies, so that it can be undone */
|
||
|
/* if desired. Some variables of type "int" existed in */
|
||
|
/* the code before this change, and the SHORT macro */
|
||
|
/* allows reversal of just the correct ones. */
|
||
|
/* Patrick Grother Dec 9 1994 */
|
||
|
/* !!!!!!!!!!!!!!!!!! Change Here. Redeclaration of Type. !!!!!!!!!!!!!!!! */
|
||
|
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
|
||
|
|
||
|
|
||
|
#define Largest_code 2560
|
||
|
#define Size_of_make_up_code_increments 64
|
||
|
#define Max_terminating_length 63 /* longest terminating code*/
|
||
|
#define Number_of_different_bytes 256
|
||
|
|
||
|
#define Pixels_per_byte 8
|
||
|
#define Bits_per_byte 8
|
||
|
#define Last_bit_in_a_byte 7 /* assumes bits numbered from 0 - 7 */
|
||
|
#define Last_bit_mask 1 /* masks the last (low magnitude) bit */
|
||
|
#define Default_width_in_pixels 2560 /* default width of a scan line */
|
||
|
#define Default_number_of_lines 3300 /* default length of an image */
|
||
|
|
||
|
#define Invalid -1
|
||
|
#define Extra_positions 25 /* ensures extra room in allocations */
|
||
|
#define Not_done_yet 0
|
||
|
|
||
|
#define VL3 -3 /* Vertical Left 3 mode */
|
||
|
#define VL2 -2 /* Vertical Left 2 mode */
|
||
|
#define VL1 -1 /* Vertical Left 1 mode */
|
||
|
#define V0 0 /* Vertical mode */
|
||
|
#define VR1 1 /* Vertical Right 1 mode */
|
||
|
#define VR2 2 /* Vertical Right 2 mode */
|
||
|
#define VR3 3 /* Vertical Right 3 mode */
|
||
|
#define P 4 /* Pass mode */
|
||
|
#define H 5 /* Horizontal mode */
|
||
|
#define EOFB 6 /* End Of File Buffer */
|
||
|
|
||
|
#define No_offset 0 /* no offset during fseek() */
|
||
|
#define End_of_file 2 /* start at EOF during fseek() */
|
||
|
#define Start_of_file 0 /* start at SOF during fseek() */
|
||
|
|
||
|
/*
|
||
|
unsigned char *calloc();
|
||
|
SHORT *malloc();
|
||
|
*/
|
||
|
|
||
|
struct parameters {
|
||
|
SHORT previous_color; /* color of last run of pixels */
|
||
|
SHORT index; /* indicates current position in "coding_line" */
|
||
|
SHORT max_pixel; /* the number of pixels in a scan line */
|
||
|
SHORT pixel; /* pixel number of the last changing element */
|
||
|
SHORT *reference_line; /* array of changing elements on reference line */
|
||
|
SHORT *coding_line; /* array of changing elements on coding line */
|
||
|
};
|
||
|
|
||
|
struct compressed_descriptor {
|
||
|
unsigned char *data; /* pointer to compressed image */
|
||
|
SHORT pixels_per_line; /* the number of pixels in a scan line */
|
||
|
SHORT number_of_lines; /* the number of scan lines in the image */
|
||
|
int length_in_bytes; /* length of the compressed image in bytes */
|
||
|
};
|
||
|
|
||
|
struct uncompressed_descriptor {
|
||
|
unsigned char *data; /* pointer to uncompressed image */
|
||
|
SHORT pixels_per_line; /* the number of pixels in a scan line */
|
||
|
SHORT number_of_lines; /* the number of scan lines in the image */
|
||
|
};
|
||
|
|
||
|
static const char write_one[Pixels_per_byte] =
|
||
|
{
|
||
|
(char)0x80,
|
||
|
(char)0x40,
|
||
|
(char)0x20,
|
||
|
(char)0x10,
|
||
|
(char)0x8,
|
||
|
(char)0x4,
|
||
|
(char)0x2,
|
||
|
(char)0x1,
|
||
|
};
|
||
|
|
||
|
static const char write_zero[Pixels_per_byte] =
|
||
|
{
|
||
|
(char)0x7F,
|
||
|
(char)0xBF,
|
||
|
(char)0xDF,
|
||
|
(char)0xEF,
|
||
|
(char)0xF7,
|
||
|
(char)0xFB,
|
||
|
(char)0xFD,
|
||
|
(char)0xFE,
|
||
|
};
|
||
|
|
||
|
static const char *white_terminating_code[64] =
|
||
|
{
|
||
|
"00110101",
|
||
|
"000111",
|
||
|
"0111",
|
||
|
"1000",
|
||
|
"1011",
|
||
|
"1100",
|
||
|
"1110",
|
||
|
"1111",
|
||
|
"10011",
|
||
|
"10100",
|
||
|
"00111",
|
||
|
"01000",
|
||
|
"001000",
|
||
|
"000011",
|
||
|
"110100",
|
||
|
"110101",
|
||
|
"101010",
|
||
|
"101011",
|
||
|
"0100111",
|
||
|
"0001100",
|
||
|
"0001000",
|
||
|
"0010111",
|
||
|
"0000011",
|
||
|
"0000100",
|
||
|
"0101000",
|
||
|
"0101011",
|
||
|
"0010011",
|
||
|
"0100100",
|
||
|
"0011000",
|
||
|
"00000010",
|
||
|
"00000011",
|
||
|
"00011010",
|
||
|
"00011011",
|
||
|
"00010010",
|
||
|
"00010011",
|
||
|
"00010100",
|
||
|
"00010101",
|
||
|
"00010110",
|
||
|
"00010111",
|
||
|
"00101000",
|
||
|
"00101001",
|
||
|
"00101010",
|
||
|
"00101011",
|
||
|
"00101100",
|
||
|
"00101101",
|
||
|
"00000100",
|
||
|
"00000101",
|
||
|
"00001010",
|
||
|
"00001011",
|
||
|
"01010010",
|
||
|
"01010011",
|
||
|
"01010100",
|
||
|
"01010101",
|
||
|
"00100100",
|
||
|
"00100101",
|
||
|
"01011000",
|
||
|
"01011001",
|
||
|
"01011010",
|
||
|
"01011011",
|
||
|
"01001010",
|
||
|
"01001011",
|
||
|
"00110010",
|
||
|
"00110011",
|
||
|
"00110100",
|
||
|
};/* end array of white terminating code */
|
||
|
|
||
|
|
||
|
static const char *black_terminating_code[64] =
|
||
|
{
|
||
|
"0000110111",
|
||
|
"010",
|
||
|
"11",
|
||
|
"10",
|
||
|
"011",
|
||
|
"0011",
|
||
|
"0010",
|
||
|
"00011",
|
||
|
"000101",
|
||
|
"000100",
|
||
|
"0000100",
|
||
|
"0000101",
|
||
|
"0000111",
|
||
|
"00000100",
|
||
|
"00000111",
|
||
|
"000011000",
|
||
|
"0000010111",
|
||
|
"0000011000",
|
||
|
"0000001000",
|
||
|
"00001100111",
|
||
|
"00001101000",
|
||
|
"00001101100",
|
||
|
"00000110111",
|
||
|
"00000101000",
|
||
|
"00000010111",
|
||
|
"00000011000",
|
||
|
"000011001010",
|
||
|
"000011001011",
|
||
|
"000011001100",
|
||
|
"000011001101",
|
||
|
"000001101000",
|
||
|
"000001101001",
|
||
|
"000001101010",
|
||
|
"000001101011",
|
||
|
"000011010010",
|
||
|
"000011010011",
|
||
|
"000011010100",
|
||
|
"000011010101",
|
||
|
"000011010110",
|
||
|
"000011010111",
|
||
|
"000001101100",
|
||
|
"000001101101",
|
||
|
"000011011010",
|
||
|
"000011011011",
|
||
|
"000001010100",
|
||
|
"000001010101",
|
||
|
"000001010110",
|
||
|
"000001010111",
|
||
|
"000001100100",
|
||
|
"000001100101",
|
||
|
"000001010010",
|
||
|
"000001010011",
|
||
|
"000000100100",
|
||
|
"000000110111",
|
||
|
"000000111000",
|
||
|
"000000100111",
|
||
|
"000000101000",
|
||
|
"000001011000",
|
||
|
"000001011001",
|
||
|
"000000101011",
|
||
|
"000000101100",
|
||
|
"000001011010",
|
||
|
"000001100110",
|
||
|
"000001100111",
|
||
|
}; /* end black_terminating_array */
|
||
|
|
||
|
|
||
|
static const char *white_make_up_code[40] =
|
||
|
{
|
||
|
"11011",
|
||
|
"10010",
|
||
|
"010111",
|
||
|
"0110111",
|
||
|
"00110110",
|
||
|
"00110111",
|
||
|
"01100100",
|
||
|
"01100101",
|
||
|
"01101000",
|
||
|
"01100111",
|
||
|
"011001100",
|
||
|
"011001101",
|
||
|
"011010010",
|
||
|
"011010011",
|
||
|
"011010100",
|
||
|
"011010101",
|
||
|
"011010110",
|
||
|
"011010111",
|
||
|
"011011000",
|
||
|
"011011001",
|
||
|
"011011010",
|
||
|
"011011011",
|
||
|
"010011000",
|
||
|
"010011001",
|
||
|
"010011010",
|
||
|
"011000",
|
||
|
"010011011",
|
||
|
|
||
|
/*
|
||
|
* from this line on, the codes are colorless and represnt runs from
|
||
|
* 1792 pixels to 2560 pixels. In other words, the longest run length
|
||
|
* codes have been added onto both the white make up codes and the black
|
||
|
* make up codes. This has been done to make the procedure
|
||
|
* "write_run_length()" easier to write and to understand. No other
|
||
|
* procedure in the compression algorithm is affected by this merging of
|
||
|
* different types of run length codes, and the compatibility of the
|
||
|
* program is in no way effected.
|
||
|
*/
|
||
|
|
||
|
"00000001000",
|
||
|
"00000001100",
|
||
|
"00000001101",
|
||
|
"000000010010",
|
||
|
"000000010011",
|
||
|
"000000010100",
|
||
|
"000000010101",
|
||
|
"000000010110",
|
||
|
"000000010111",
|
||
|
"000000011100",
|
||
|
"000000011101",
|
||
|
"000000011110",
|
||
|
"000000011111",
|
||
|
}; /* end case of white makeup code */
|
||
|
|
||
|
|
||
|
static const char *black_make_up_code[40] =
|
||
|
{
|
||
|
"0000001111",
|
||
|
"000011001000",
|
||
|
"000011001001",
|
||
|
"000001011011",
|
||
|
"000000110011",
|
||
|
"000000110100",
|
||
|
"000000110101",
|
||
|
"0000001101100",
|
||
|
"0000001101101",
|
||
|
"0000001001010",
|
||
|
"0000001001011",
|
||
|
"0000001001100",
|
||
|
"0000001001101",
|
||
|
"0000001110010",
|
||
|
"0000001110011",
|
||
|
"0000001110100",
|
||
|
"0000001110101",
|
||
|
"0000001110110",
|
||
|
"0000001110111",
|
||
|
"0000001010010",
|
||
|
"0000001010011",
|
||
|
"0000001010100",
|
||
|
"0000001010101",
|
||
|
"0000001011010",
|
||
|
"0000001011011",
|
||
|
"0000001100100",
|
||
|
"0000001100101",
|
||
|
|
||
|
/*
|
||
|
* from this line on, the codes are colorless and represnt runs from
|
||
|
* 1792 pixels to 2560 pixels. In other words, the longest run length
|
||
|
* codes have been added onto both the white make up codes and the black
|
||
|
* make up codes. This has been done to make the procedure
|
||
|
* "write_run_length()" easier to write and to understand. No other
|
||
|
* procedure in the compression algorithm is affected by this merging of
|
||
|
* different types of run length codes, and the compatibility of the
|
||
|
* program is in no way compromised.
|
||
|
*/
|
||
|
|
||
|
"00000001000",
|
||
|
"00000001100",
|
||
|
"00000001101",
|
||
|
"000000010010",
|
||
|
"000000010011",
|
||
|
"000000010100",
|
||
|
"000000010101",
|
||
|
"000000010110",
|
||
|
"000000010111",
|
||
|
"000000011100",
|
||
|
"000000011101",
|
||
|
"000000011110",
|
||
|
"000000011111",
|
||
|
}; /* end black makeup code */
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
struct byte_descriptor {
|
||
|
SHORT pixel[9];
|
||
|
};
|
||
|
|
||
|
|
||
|
static const struct byte_descriptor table[Number_of_different_bytes] =
|
||
|
{
|
||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
7, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
6, 7, -1, -1, -1, -1, -1, -1, -1,
|
||
|
6, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
5, 6, -1, -1, -1, -1, -1, -1, -1,
|
||
|
5, 6, 7, -1, -1, -1, -1, -1, -1,
|
||
|
5, 7, -1, -1, -1, -1, -1, -1, -1,
|
||
|
5, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
4, 5, -1, -1, -1, -1, -1, -1, -1,
|
||
|
4, 5, 7, -1, -1, -1, -1, -1, -1,
|
||
|
4, 5, 6, 7, -1, -1, -1, -1, -1,
|
||
|
4, 5, 6, -1, -1, -1, -1, -1, -1,
|
||
|
4, 6, -1, -1, -1, -1, -1, -1, -1,
|
||
|
4, 6, 7, -1, -1, -1, -1, -1, -1,
|
||
|
4, 7, -1, -1, -1, -1, -1, -1, -1,
|
||
|
4, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
3, 4, -1, -1, -1, -1, -1, -1, -1,
|
||
|
3, 4, 7, -1, -1, -1, -1, -1, -1,
|
||
|
3, 4, 6, 7, -1, -1, -1, -1, -1,
|
||
|
3, 4, 6, -1, -1, -1, -1, -1, -1,
|
||
|
3, 4, 5, 6, -1, -1, -1, -1, -1,
|
||
|
3, 4, 5, 6, 7, -1, -1, -1, -1,
|
||
|
3, 4, 5, 7, -1, -1, -1, -1, -1,
|
||
|
3, 4, 5, -1, -1, -1, -1, -1, -1,
|
||
|
3, 5, -1, -1, -1, -1, -1, -1, -1,
|
||
|
3, 5, 7, -1, -1, -1, -1, -1, -1,
|
||
|
3, 5, 6, 7, -1, -1, -1, -1, -1,
|
||
|
3, 5, 6, -1, -1, -1, -1, -1, -1,
|
||
|
3, 6, -1, -1, -1, -1, -1, -1, -1,
|
||
|
3, 6, 7, -1, -1, -1, -1, -1, -1,
|
||
|
3, 7, -1, -1, -1, -1, -1, -1, -1,
|
||
|
3, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
2, 3, -1, -1, -1, -1, -1, -1, -1,
|
||
|
2, 3, 7, -1, -1, -1, -1, -1, -1,
|
||
|
2, 3, 6, 7, -1, -1, -1, -1, -1,
|
||
|
2, 3, 6, -1, -1, -1, -1, -1, -1,
|
||
|
2, 3, 5, 6, -1, -1, -1, -1, -1,
|
||
|
2, 3, 5, 6, 7, -1, -1, -1, -1,
|
||
|
2, 3, 5, 7, -1, -1, -1, -1, -1,
|
||
|
2, 3, 5, -1, -1, -1, -1, -1, -1,
|
||
|
2, 3, 4, 5, -1, -1, -1, -1, -1,
|
||
|
2, 3, 4, 5, 7, -1, -1, -1, -1,
|
||
|
2, 3, 4, 5, 6, 7, -1, -1, -1,
|
||
|
2, 3, 4, 5, 6, -1, -1, -1, -1,
|
||
|
2, 3, 4, 6, -1, -1, -1, -1, -1,
|
||
|
2, 3, 4, 6, 7, -1, -1, -1, -1,
|
||
|
2, 3, 4, 7, -1, -1, -1, -1, -1,
|
||
|
2, 3, 4, -1, -1, -1, -1, -1, -1,
|
||
|
2, 4, -1, -1, -1, -1, -1, -1, -1,
|
||
|
2, 4, 7, -1, -1, -1, -1, -1, -1,
|
||
|
2, 4, 6, 7, -1, -1, -1, -1, -1,
|
||
|
2, 4, 6, -1, -1, -1, -1, -1, -1,
|
||
|
2, 4, 5, 6, -1, -1, -1, -1, -1,
|
||
|
2, 4, 5, 6, 7, -1, -1, -1, -1,
|
||
|
2, 4, 5, 7, -1, -1, -1, -1, -1,
|
||
|
2, 4, 5, -1, -1, -1, -1, -1, -1,
|
||
|
2, 5, -1, -1, -1, -1, -1, -1, -1,
|
||
|
2, 5, 7, -1, -1, -1, -1, -1, -1,
|
||
|
2, 5, 6, 7, -1, -1, -1, -1, -1,
|
||
|
2, 5, 6, -1, -1, -1, -1, -1, -1,
|
||
|
2, 6, -1, -1, -1, -1, -1, -1, -1,
|
||
|
2, 6, 7, -1, -1, -1, -1, -1, -1,
|
||
|
2, 7, -1, -1, -1, -1, -1, -1, -1,
|
||
|
2, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
1, 2, -1, -1, -1, -1, -1, -1, -1,
|
||
|
1, 2, 7, -1, -1, -1, -1, -1, -1,
|
||
|
1, 2, 6, 7, -1, -1, -1, -1, -1,
|
||
|
1, 2, 6, -1, -1, -1, -1, -1, -1,
|
||
|
1, 2, 5, 6, -1, -1, -1, -1, -1,
|
||
|
1, 2, 5, 6, 7, -1, -1, -1, -1,
|
||
|
1, 2, 5, 7, -1, -1, -1, -1, -1,
|
||
|
1, 2, 5, -1, -1, -1, -1, -1, -1,
|
||
|
1, 2, 4, 5, -1, -1, -1, -1, -1,
|
||
|
1, 2, 4, 5, 7, -1, -1, -1, -1,
|
||
|
1, 2, 4, 5, 6, 7, -1, -1, -1,
|
||
|
1, 2, 4, 5, 6, -1, -1, -1, -1,
|
||
|
1, 2, 4, 6, -1, -1, -1, -1, -1,
|
||
|
1, 2, 4, 6, 7, -1, -1, -1, -1,
|
||
|
1, 2, 4, 7, -1, -1, -1, -1, -1,
|
||
|
1, 2, 4, -1, -1, -1, -1, -1, -1,
|
||
|
1, 2, 3, 4, -1, -1, -1, -1, -1,
|
||
|
1, 2, 3, 4, 7, -1, -1, -1, -1,
|
||
|
1, 2, 3, 4, 6, 7, -1, -1, -1,
|
||
|
1, 2, 3, 4, 6, -1, -1, -1, -1,
|
||
|
1, 2, 3, 4, 5, 6, -1, -1, -1,
|
||
|
1, 2, 3, 4, 5, 6, 7, -1, -1,
|
||
|
1, 2, 3, 4, 5, 7, -1, -1, -1,
|
||
|
1, 2, 3, 4, 5, -1, -1, -1, -1,
|
||
|
1, 2, 3, 5, -1, -1, -1, -1, -1,
|
||
|
1, 2, 3, 5, 7, -1, -1, -1, -1,
|
||
|
1, 2, 3, 5, 6, 7, -1, -1, -1,
|
||
|
1, 2, 3, 5, 6, -1, -1, -1, -1,
|
||
|
1, 2, 3, 6, -1, -1, -1, -1, -1,
|
||
|
1, 2, 3, 6, 7, -1, -1, -1, -1,
|
||
|
1, 2, 3, 7, -1, -1, -1, -1, -1,
|
||
|
1, 2, 3, -1, -1, -1, -1, -1, -1,
|
||
|
1, 3, -1, -1, -1, -1, -1, -1, -1,
|
||
|
1, 3, 7, -1, -1, -1, -1, -1, -1,
|
||
|
1, 3, 6, 7, -1, -1, -1, -1, -1,
|
||
|
1, 3, 6, -1, -1, -1, -1, -1, -1,
|
||
|
1, 3, 5, 6, -1, -1, -1, -1, -1,
|
||
|
1, 3, 5, 6, 7, -1, -1, -1, -1,
|
||
|
1, 3, 5, 7, -1, -1, -1, -1, -1,
|
||
|
1, 3, 5, -1, -1, -1, -1, -1, -1,
|
||
|
1, 3, 4, 5, -1, -1, -1, -1, -1,
|
||
|
1, 3, 4, 5, 7, -1, -1, -1, -1,
|
||
|
1, 3, 4, 5, 6, 7, -1, -1, -1,
|
||
|
1, 3, 4, 5, 6, -1, -1, -1, -1,
|
||
|
1, 3, 4, 6, -1, -1, -1, -1, -1,
|
||
|
1, 3, 4, 6, 7, -1, -1, -1, -1,
|
||
|
1, 3, 4, 7, -1, -1, -1, -1, -1,
|
||
|
1, 3, 4, -1, -1, -1, -1, -1, -1,
|
||
|
1, 4, -1, -1, -1, -1, -1, -1, -1,
|
||
|
1, 4, 7, -1, -1, -1, -1, -1, -1,
|
||
|
1, 4, 6, 7, -1, -1, -1, -1, -1,
|
||
|
1, 4, 6, -1, -1, -1, -1, -1, -1,
|
||
|
1, 4, 5, 6, -1, -1, -1, -1, -1,
|
||
|
1, 4, 5, 6, 7, -1, -1, -1, -1,
|
||
|
1, 4, 5, 7, -1, -1, -1, -1, -1,
|
||
|
1, 4, 5, -1, -1, -1, -1, -1, -1,
|
||
|
1, 5, -1, -1, -1, -1, -1, -1, -1,
|
||
|
1, 5, 7, -1, -1, -1, -1, -1, -1,
|
||
|
1, 5, 6, 7, -1, -1, -1, -1, -1,
|
||
|
1, 5, 6, -1, -1, -1, -1, -1, -1,
|
||
|
1, 6, -1, -1, -1, -1, -1, -1, -1,
|
||
|
1, 6, 7, -1, -1, -1, -1, -1, -1,
|
||
|
1, 7, -1, -1, -1, -1, -1, -1, -1,
|
||
|
1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, 1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, 1, 7, -1, -1, -1, -1, -1, -1,
|
||
|
0, 1, 6, 7, -1, -1, -1, -1, -1,
|
||
|
0, 1, 6, -1, -1, -1, -1, -1, -1,
|
||
|
0, 1, 5, 6, -1, -1, -1, -1, -1,
|
||
|
0, 1, 5, 6, 7, -1, -1, -1, -1,
|
||
|
0, 1, 5, 7, -1, -1, -1, -1, -1,
|
||
|
0, 1, 5, -1, -1, -1, -1, -1, -1,
|
||
|
0, 1, 4, 5, -1, -1, -1, -1, -1,
|
||
|
0, 1, 4, 5, 7, -1, -1, -1, -1,
|
||
|
0, 1, 4, 5, 6, 7, -1, -1, -1,
|
||
|
0, 1, 4, 5, 6, -1, -1, -1, -1,
|
||
|
0, 1, 4, 6, -1, -1, -1, -1, -1,
|
||
|
0, 1, 4, 6, 7, -1, -1, -1, -1,
|
||
|
0, 1, 4, 7, -1, -1, -1, -1, -1,
|
||
|
0, 1, 4, -1, -1, -1, -1, -1, -1,
|
||
|
0, 1, 3, 4, -1, -1, -1, -1, -1,
|
||
|
0, 1, 3, 4, 7, -1, -1, -1, -1,
|
||
|
0, 1, 3, 4, 6, 7, -1, -1, -1,
|
||
|
0, 1, 3, 4, 6, -1, -1, -1, -1,
|
||
|
0, 1, 3, 4, 5, 6, -1, -1, -1,
|
||
|
0, 1, 3, 4, 5, 6, 7, -1, -1,
|
||
|
0, 1, 3, 4, 5, 7, -1, -1, -1,
|
||
|
0, 1, 3, 4, 5, -1, -1, -1, -1,
|
||
|
0, 1, 3, 5, -1, -1, -1, -1, -1,
|
||
|
0, 1, 3, 5, 7, -1, -1, -1, -1,
|
||
|
0, 1, 3, 5, 6, 7, -1, -1, -1,
|
||
|
0, 1, 3, 5, 6, -1, -1, -1, -1,
|
||
|
0, 1, 3, 6, -1, -1, -1, -1, -1,
|
||
|
0, 1, 3, 6, 7, -1, -1, -1, -1,
|
||
|
0, 1, 3, 7, -1, -1, -1, -1, -1,
|
||
|
0, 1, 3, -1, -1, -1, -1, -1, -1,
|
||
|
0, 1, 2, 3, -1, -1, -1, -1, -1,
|
||
|
0, 1, 2, 3, 7, -1, -1, -1, -1,
|
||
|
0, 1, 2, 3, 6, 7, -1, -1, -1,
|
||
|
0, 1, 2, 3, 6, -1, -1, -1, -1,
|
||
|
0, 1, 2, 3, 5, 6, -1, -1, -1,
|
||
|
0, 1, 2, 3, 5, 6, 7, -1, -1,
|
||
|
0, 1, 2, 3, 5, 7, -1, -1, -1,
|
||
|
0, 1, 2, 3, 5, -1, -1, -1, -1,
|
||
|
0, 1, 2, 3, 4, 5, -1, -1, -1,
|
||
|
0, 1, 2, 3, 4, 5, 7, -1, -1,
|
||
|
0, 1, 2, 3, 4, 5, 6, 7, -1,
|
||
|
0, 1, 2, 3, 4, 5, 6, -1, -1,
|
||
|
0, 1, 2, 3, 4, 6, -1, -1, -1,
|
||
|
0, 1, 2, 3, 4, 6, 7, -1, -1,
|
||
|
0, 1, 2, 3, 4, 7, -1, -1, -1,
|
||
|
0, 1, 2, 3, 4, -1, -1, -1, -1,
|
||
|
0, 1, 2, 4, -1, -1, -1, -1, -1,
|
||
|
0, 1, 2, 4, 7, -1, -1, -1, -1,
|
||
|
0, 1, 2, 4, 6, 7, -1, -1, -1,
|
||
|
0, 1, 2, 4, 6, -1, -1, -1, -1,
|
||
|
0, 1, 2, 4, 5, 6, -1, -1, -1,
|
||
|
0, 1, 2, 4, 5, 6, 7, -1, -1,
|
||
|
0, 1, 2, 4, 5, 7, -1, -1, -1,
|
||
|
0, 1, 2, 4, 5, -1, -1, -1, -1,
|
||
|
0, 1, 2, 5, -1, -1, -1, -1, -1,
|
||
|
0, 1, 2, 5, 7, -1, -1, -1, -1,
|
||
|
0, 1, 2, 5, 6, 7, -1, -1, -1,
|
||
|
0, 1, 2, 5, 6, -1, -1, -1, -1,
|
||
|
0, 1, 2, 6, -1, -1, -1, -1, -1,
|
||
|
0, 1, 2, 6, 7, -1, -1, -1, -1,
|
||
|
0, 1, 2, 7, -1, -1, -1, -1, -1,
|
||
|
0, 1, 2, -1, -1, -1, -1, -1, -1,
|
||
|
0, 2, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, 2, 7, -1, -1, -1, -1, -1, -1,
|
||
|
0, 2, 6, 7, -1, -1, -1, -1, -1,
|
||
|
0, 2, 6, -1, -1, -1, -1, -1, -1,
|
||
|
0, 2, 5, 6, -1, -1, -1, -1, -1,
|
||
|
0, 2, 5, 6, 7, -1, -1, -1, -1,
|
||
|
0, 2, 5, 7, -1, -1, -1, -1, -1,
|
||
|
0, 2, 5, -1, -1, -1, -1, -1, -1,
|
||
|
0, 2, 4, 5, -1, -1, -1, -1, -1,
|
||
|
0, 2, 4, 5, 7, -1, -1, -1, -1,
|
||
|
0, 2, 4, 5, 6, 7, -1, -1, -1,
|
||
|
0, 2, 4, 5, 6, -1, -1, -1, -1,
|
||
|
0, 2, 4, 6, -1, -1, -1, -1, -1,
|
||
|
0, 2, 4, 6, 7, -1, -1, -1, -1,
|
||
|
0, 2, 4, 7, -1, -1, -1, -1, -1,
|
||
|
0, 2, 4, -1, -1, -1, -1, -1, -1,
|
||
|
0, 2, 3, 4, -1, -1, -1, -1, -1,
|
||
|
0, 2, 3, 4, 7, -1, -1, -1, -1,
|
||
|
0, 2, 3, 4, 6, 7, -1, -1, -1,
|
||
|
0, 2, 3, 4, 6, -1, -1, -1, -1,
|
||
|
0, 2, 3, 4, 5, 6, -1, -1, -1,
|
||
|
0, 2, 3, 4, 5, 6, 7, -1, -1,
|
||
|
0, 2, 3, 4, 5, 7, -1, -1, -1,
|
||
|
0, 2, 3, 4, 5, -1, -1, -1, -1,
|
||
|
0, 2, 3, 5, -1, -1, -1, -1, -1,
|
||
|
0, 2, 3, 5, 7, -1, -1, -1, -1,
|
||
|
0, 2, 3, 5, 6, 7, -1, -1, -1,
|
||
|
0, 2, 3, 5, 6, -1, -1, -1, -1,
|
||
|
0, 2, 3, 6, -1, -1, -1, -1, -1,
|
||
|
0, 2, 3, 6, 7, -1, -1, -1, -1,
|
||
|
0, 2, 3, 7, -1, -1, -1, -1, -1,
|
||
|
0, 2, 3, -1, -1, -1, -1, -1, -1,
|
||
|
0, 3, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, 3, 7, -1, -1, -1, -1, -1, -1,
|
||
|
0, 3, 6, 7, -1, -1, -1, -1, -1,
|
||
|
0, 3, 6, -1, -1, -1, -1, -1, -1,
|
||
|
0, 3, 5, 6, -1, -1, -1, -1, -1,
|
||
|
0, 3, 5, 6, 7, -1, -1, -1, -1,
|
||
|
0, 3, 5, 7, -1, -1, -1, -1, -1,
|
||
|
0, 3, 5, -1, -1, -1, -1, -1, -1,
|
||
|
0, 3, 4, 5, -1, -1, -1, -1, -1,
|
||
|
0, 3, 4, 5, 7, -1, -1, -1, -1,
|
||
|
0, 3, 4, 5, 6, 7, -1, -1, -1,
|
||
|
0, 3, 4, 5, 6, -1, -1, -1, -1,
|
||
|
0, 3, 4, 6, -1, -1, -1, -1, -1,
|
||
|
0, 3, 4, 6, 7, -1, -1, -1, -1,
|
||
|
0, 3, 4, 7, -1, -1, -1, -1, -1,
|
||
|
0, 3, 4, -1, -1, -1, -1, -1, -1,
|
||
|
0, 4, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, 4, 7, -1, -1, -1, -1, -1, -1,
|
||
|
0, 4, 6, 7, -1, -1, -1, -1, -1,
|
||
|
0, 4, 6, -1, -1, -1, -1, -1, -1,
|
||
|
0, 4, 5, 6, -1, -1, -1, -1, -1,
|
||
|
0, 4, 5, 6, 7, -1, -1, -1, -1,
|
||
|
0, 4, 5, 7, -1, -1, -1, -1, -1,
|
||
|
0, 4, 5, -1, -1, -1, -1, -1, -1,
|
||
|
0, 5, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, 5, 7, -1, -1, -1, -1, -1, -1,
|
||
|
0, 5, 6, 7, -1, -1, -1, -1, -1,
|
||
|
0, 5, 6, -1, -1, -1, -1, -1, -1,
|
||
|
0, 6, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, 6, 7, -1, -1, -1, -1, -1, -1,
|
||
|
0, 7, -1, -1, -1, -1, -1, -1, -1,
|
||
|
0, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
|
}; /* end of data for list of byte descriptors */
|
||
|
|
||
|
// Constants
|
||
|
#define NOALLOC 0
|
||
|
#define ALLOC 1
|
||
|
|
||
|
class TiffG4Compression
|
||
|
{
|
||
|
public:
|
||
|
TiffG4Compression();
|
||
|
~TiffG4Compression();
|
||
|
public:
|
||
|
int G4Compress(unsigned char *indata, int inbytes, int width, int height, unsigned char *outdata, int *outbytes);
|
||
|
private:
|
||
|
void control_compression(struct uncompressed_descriptor *uncompressed, struct compressed_descriptor *compressed);
|
||
|
void read_uncompressed_file_into_memory(struct uncompressed_descriptor *uncompressed);
|
||
|
void prepare_to_compress(struct uncompressed_descriptor* uncompressed,struct compressed_descriptor* compressed,struct parameters* params);
|
||
|
void compress_image(struct uncompressed_descriptor* uncompressed, struct compressed_descriptor* compressed, struct parameters* params);
|
||
|
void make_array_of_changing_elements(struct parameters *params, struct uncompressed_descriptor* uncompressed, SHORT line_number);
|
||
|
void set_up_first_and_last_changing_elements_c(struct parameters *params);
|
||
|
void prepare_to_compress_next_line(struct parameters *params);
|
||
|
void set_up_first_line_c(struct parameters *params);
|
||
|
void compress_line(struct parameters *params);
|
||
|
void initialize_b1(struct parameters *params);
|
||
|
void pass_mode_c(struct parameters *params);
|
||
|
void vertical_mode_c(struct parameters *params);
|
||
|
void horizontal_mode_c(struct parameters *params);
|
||
|
void prepare_to_write_bits_c(struct compressed_descriptor *compressed);
|
||
|
void write_bits_c(char *string_ptr);
|
||
|
unsigned int flush_buffer();
|
||
|
void write_run_length(SHORT length, SHORT color);
|
||
|
void process_char(unsigned char data_byte, struct parameters *params);
|
||
|
private:
|
||
|
const char* largest_colorless_code =
|
||
|
{
|
||
|
"000000011111"
|
||
|
};
|
||
|
|
||
|
int comp_alloc_flag = ALLOC;
|
||
|
int comp_write_init_flag;
|
||
|
char *output_area=nullptr;
|
||
|
int bit_place_mark;
|
||
|
int byte_place_mark;
|
||
|
SHORT A_0, A0_color, A_1, a2, b1, b2;
|
||
|
};
|
||
|
|