summaryrefslogtreecommitdiff
path: root/fitz/filt_faxd.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-07-09 02:47:51 +0200
committerTor Andersson <tor@ghostscript.com>2010-07-09 02:47:51 +0200
commit8d68dec4b460ac292ce0021717160a8cd9fcc8dd (patch)
tree322b0a32d97fa288fad5d0114561047bc1c4bf08 /fitz/filt_faxd.c
parent3a4c396334bc500de4c9b1e957f030835b5df65e (diff)
downloadmupdf-8d68dec4b460ac292ce0021717160a8cd9fcc8dd.tar.xz
Rearrange and merge some files in the fitz directory.
Diffstat (limited to 'fitz/filt_faxd.c')
-rw-r--r--fitz/filt_faxd.c176
1 files changed, 170 insertions, 6 deletions
diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c
index c31a7ea2..b53cdd29 100644
--- a/fitz/filt_faxd.c
+++ b/fitz/filt_faxd.c
@@ -1,8 +1,174 @@
#include "fitz.h"
-#include "filt_faxd.h"
+/* Fax G3/G4 decoder */
-/* common bit magic */
+/* TODO: uncompressed */
+
+/*
+<raph> the first 2^(initialbits) entries map bit patterns to decodes
+<raph> let's say initial_bits is 8 for the sake of example
+<raph> and that the code is 1001
+<raph> that means that entries 0x90 .. 0x9f have the entry { val, 4 }
+<raph> because those are all the bytes that start with the code
+<raph> and the 4 is the length of the code
+... if (n_bits > initial_bits) ...
+<raph> anyway, in that case, it basically points to a mini table
+<raph> the n_bits is the maximum length of all codes beginning with that byte
+<raph> so 2^(n_bits - initial_bits) is the size of the mini-table
+<raph> peter came up with this, and it makes sense
+*/
+
+typedef struct cfd_node_s cfd_node;
+
+struct cfd_node_s
+{
+ short val;
+ short nbits;
+};
+
+enum
+{
+ cfd_white_initial_bits = 8,
+ cfd_black_initial_bits = 7,
+ cfd_2d_initial_bits = 7,
+ cfd_uncompressed_initial_bits = 6 /* must be 6 */
+};
+
+/* non-run codes in tables */
+enum
+{
+ ERROR = -1,
+ ZEROS = -2, /* EOL follows, possibly with more padding first */
+ UNCOMPRESSED = -3
+};
+
+/* semantic codes for cf_2d_decode */
+enum
+{
+ P = -4,
+ H = -5,
+ VR3 = 0,
+ VR2 = 1,
+ VR1 = 2,
+ V0 = 3,
+ VL1 = 4,
+ VL2 = 5,
+ VL3 = 6
+};
+
+/* White decoding table. */
+const cfd_node cf_white_decode[] = {
+ {256,12},{272,12},{29,8},{30,8},{45,8},{46,8},{22,7},{22,7},
+ {23,7},{23,7},{47,8},{48,8},{13,6},{13,6},{13,6},{13,6},{20,7},
+ {20,7},{33,8},{34,8},{35,8},{36,8},{37,8},{38,8},{19,7},{19,7},
+ {31,8},{32,8},{1,6},{1,6},{1,6},{1,6},{12,6},{12,6},{12,6},{12,6},
+ {53,8},{54,8},{26,7},{26,7},{39,8},{40,8},{41,8},{42,8},{43,8},
+ {44,8},{21,7},{21,7},{28,7},{28,7},{61,8},{62,8},{63,8},{0,8},
+ {320,8},{384,8},{10,5},{10,5},{10,5},{10,5},{10,5},{10,5},{10,5},
+ {10,5},{11,5},{11,5},{11,5},{11,5},{11,5},{11,5},{11,5},{11,5},
+ {27,7},{27,7},{59,8},{60,8},{288,9},{290,9},{18,7},{18,7},{24,7},
+ {24,7},{49,8},{50,8},{51,8},{52,8},{25,7},{25,7},{55,8},{56,8},
+ {57,8},{58,8},{192,6},{192,6},{192,6},{192,6},{1664,6},{1664,6},
+ {1664,6},{1664,6},{448,8},{512,8},{292,9},{640,8},{576,8},{294,9},
+ {296,9},{298,9},{300,9},{302,9},{256,7},{256,7},{2,4},{2,4},{2,4},
+ {2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},
+ {2,4},{2,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},
+ {3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{128,5},{128,5},{128,5},
+ {128,5},{128,5},{128,5},{128,5},{128,5},{8,5},{8,5},{8,5},{8,5},
+ {8,5},{8,5},{8,5},{8,5},{9,5},{9,5},{9,5},{9,5},{9,5},{9,5},{9,5},
+ {9,5},{16,6},{16,6},{16,6},{16,6},{17,6},{17,6},{17,6},{17,6},
+ {4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
+ {4,4},{4,4},{4,4},{4,4},{4,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
+ {5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
+ {14,6},{14,6},{14,6},{14,6},{15,6},{15,6},{15,6},{15,6},{64,5},
+ {64,5},{64,5},{64,5},{64,5},{64,5},{64,5},{64,5},{6,4},{6,4},
+ {6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},
+ {6,4},{6,4},{6,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},
+ {7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{-2,3},{-2,3},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-3,4},{1792,3},{1792,3},{1984,4},
+ {2048,4},{2112,4},{2176,4},{2240,4},{2304,4},{1856,3},{1856,3},
+ {1920,3},{1920,3},{2368,4},{2432,4},{2496,4},{2560,4},{1472,1},
+ {1536,1},{1600,1},{1728,1},{704,1},{768,1},{832,1},{896,1},
+ {960,1},{1024,1},{1088,1},{1152,1},{1216,1},{1280,1},{1344,1},
+ {1408,1}
+};
+
+/* Black decoding table. */
+const cfd_node cf_black_decode[] = {
+ {128,12},{160,13},{224,12},{256,12},{10,7},{11,7},{288,12},{12,7},
+ {9,6},{9,6},{8,6},{8,6},{7,5},{7,5},{7,5},{7,5},{6,4},{6,4},{6,4},
+ {6,4},{6,4},{6,4},{6,4},{6,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
+ {5,4},{5,4},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},
+ {1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{4,3},{4,3},{4,3},{4,3},
+ {4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
+ {4,3},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},
+ {3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},
+ {3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},
+ {2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
+ {2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
+ {2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
+ {-2,4},{-2,4},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-3,5},{1792,4},
+ {1792,4},{1984,5},{2048,5},{2112,5},{2176,5},{2240,5},{2304,5},
+ {1856,4},{1856,4},{1920,4},{1920,4},{2368,5},{2432,5},{2496,5},
+ {2560,5},{18,3},{18,3},{18,3},{18,3},{18,3},{18,3},{18,3},{18,3},
+ {52,5},{52,5},{640,6},{704,6},{768,6},{832,6},{55,5},{55,5},
+ {56,5},{56,5},{1280,6},{1344,6},{1408,6},{1472,6},{59,5},{59,5},
+ {60,5},{60,5},{1536,6},{1600,6},{24,4},{24,4},{24,4},{24,4},
+ {25,4},{25,4},{25,4},{25,4},{1664,6},{1728,6},{320,5},{320,5},
+ {384,5},{384,5},{448,5},{448,5},{512,6},{576,6},{53,5},{53,5},
+ {54,5},{54,5},{896,6},{960,6},{1024,6},{1088,6},{1152,6},{1216,6},
+ {64,3},{64,3},{64,3},{64,3},{64,3},{64,3},{64,3},{64,3},{13,1},
+ {13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{13,1},
+ {13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{23,4},{23,4},{50,5},
+ {51,5},{44,5},{45,5},{46,5},{47,5},{57,5},{58,5},{61,5},{256,5},
+ {16,3},{16,3},{16,3},{16,3},{17,3},{17,3},{17,3},{17,3},{48,5},
+ {49,5},{62,5},{63,5},{30,5},{31,5},{32,5},{33,5},{40,5},{41,5},
+ {22,4},{22,4},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},
+ {14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},
+ {15,2},{15,2},{15,2},{15,2},{15,2},{15,2},{15,2},{15,2},{128,5},
+ {192,5},{26,5},{27,5},{28,5},{29,5},{19,4},{19,4},{20,4},{20,4},
+ {34,5},{35,5},{36,5},{37,5},{38,5},{39,5},{21,4},{21,4},{42,5},
+ {43,5},{0,3},{0,3},{0,3},{0,3}
+};
+
+/* 2-D decoding table. */
+const cfd_node cf_2d_decode[] = {
+ {128,11},{144,10},{6,7},{0,7},{5,6},{5,6},{1,6},{1,6},{-4,4},
+ {-4,4},{-4,4},{-4,4},{-4,4},{-4,4},{-4,4},{-4,4},{-5,3},{-5,3},
+ {-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},
+ {-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{4,3},{4,3},{4,3},{4,3},{4,3},
+ {4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
+ {2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},
+ {2,3},{2,3},{2,3},{2,3},{2,3},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{-2,4},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-3,3}
+};
+
+/* Uncompresssed decoding table. */
+const cfd_node cf_uncompressed_decode[] = {
+ {64,12},{5,6},{4,5},{4,5},{3,4},{3,4},{3,4},{3,4},{2,3},{2,3},
+ {2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{1,2},{1,2},{1,2},{1,2},{1,2},
+ {1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
+ {0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},
+ {0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},
+ {0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},
+ {-1,0},{-1,0},{8,6},{9,6},{6,5},{6,5},{7,5},{7,5},{4,4},{4,4},
+ {4,4},{4,4},{5,4},{5,4},{5,4},{5,4},{2,3},{2,3},{2,3},{2,3},{2,3},
+ {2,3},{2,3},{2,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
+ {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
+ {0,2},{0,2},{0,2},{0,2},{0,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
+ {1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}
+};
+
+/* bit magic */
static inline void
printbits(FILE *f, int code, int nbits)
@@ -127,6 +293,8 @@ setbits(unsigned char *line, int x0, int x1)
}
}
+typedef struct fz_faxd_s fz_faxd;
+
typedef enum fax_stage_e
{
SNORMAL, /* neutral state, waiting for any code */
@@ -135,10 +303,6 @@ typedef enum fax_stage_e
SH1, SH2 /* in H part 1 and 2 (both makeup and terminating codes) */
} fax_stage_e;
-/* TODO: uncompressed */
-
-typedef struct fz_faxd_s fz_faxd;
-
struct fz_faxd_s
{
fz_filter super;