1 /* libhpojip -- HP OfficeJet image-processing library. */
3 /* Copyright (C) 1995-2002 Hewlett-Packard Company
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
13 * NON-INFRINGEMENT. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * In addition, as a special exception, Hewlett-Packard Company
21 * gives permission to link the code of this program with any
22 * version of the OpenSSL library which is distributed under a
23 * license identical to that listed in the included LICENSE.OpenSSL
24 * file, and distribute linked combinations including the two.
25 * You must obey the GNU General Public License in all respects
26 * for all of the code used other than OpenSSL. If you modify
27 * this file, you may extend this exception to your version of the
28 * file, but you are not obligated to do so. If you do not wish to
29 * do so, delete this exception statement from your version.
32 /* Original author: Mark Overton and others.
34 * Ported to Linux by David Paschal.
37 /*****************************************************************************\
39 * xfax.c - encoder and decoder for fax data (MH, MR and MMR)
41 *****************************************************************************
43 * Name of Global Jump-Table:
45 * faxEncodeTbl = the encoder,
46 * faxDecodeTbl = the decoder.
48 * Items in aXformInfo array passed into setXformSpec:
50 * aXformInfo[IP_FAX_FORMAT]: Format of data (both encoder & decoder).
51 * Values are: IP_FAX_MH, IP_FAX_MR, IP_FAX_MMR.
53 * aXformInfo[IP_FAX_NO_EOLS]: No EOLs in the data?
54 * 0 = EOLs are in data as usual;
55 * 1 = no EOLs in data.
56 * This tells the encoder whether to output EOLs.
57 * This tells the decoder if there are EOLs in the data.
59 * aXformInfo[IP_FAX_MIN_ROW_LEN]: Minimum # bits to put in each output row
61 * Only the encoder needs this, and guarantees that each
62 * row it outputs contains at least this many bits. It
63 * inserts fill 0's as needed. The fax standard needs
64 * this to insure that a row consumes a minimum amout of
65 * time when sent over the modem, hence there's a minimum
66 * number of bits to be transmitted per row.
68 * Capabilities and Limitations:
70 * Bits per pixel must be 1 (bi-level only).
71 * Encodes and decodes MH, MR and MMR per the fax standard.
72 * Encoding MR uses a k-factor of 2 if vert dpi < 150, else k-factor is 4.
73 * If an error occurs in MH or MR data, the previous good row is returned.
75 * Default Input Traits, and Output Traits:
77 * For both encoder and decoder:
79 * trait default input output
80 * ------------------- ------------------- ------------------------
81 * iPixelsPerRow * passed into output same as default input
82 * iBitsPerPixel * must be 1 1
83 * iComponentsPerPixel passed into output same as default input
84 * lHorizDPI passed into output same as default input
85 * lVertDPI passed into output same as default input
86 * lNumRows passed into output same as default input
87 * iNumPages passed into output same as default input
88 * iPageNum passed into output same as default input
90 * Above, a "*" by an item indicates it must be valid (not negative).
92 * Mark Overton, Jan 1998
94 \*****************************************************************************/
98 #include "string.h" /* for memset and memcpy */
99 #include "assert.h" /* todo: eliminate all asserts */
106 #define PRINT(msg,arg1,arg2) \
107 _ftprintf(stdout, msg, (int)arg1, (int)arg2)
109 #define PRINT(msg,arg1,arg2)
112 #define CHECK_VALUE 0x1ce5ca7e
118 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
119 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
122 @@ U T I L I T I E S @@
125 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
126 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
130 /* baLeftZeroesTbl returns number of leading zeroes in byte index */
132 static const BYTE baLeftZeroesTbl[256] =
134 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
135 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
136 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
137 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
138 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
139 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
140 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
141 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
153 /* baRightZeroesTbl returns number of trailing zeroes in byte index */
155 static const BYTE baRightZeroesTbl[256] =
157 8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
158 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
159 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
160 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
161 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
162 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
163 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
164 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
165 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
166 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
167 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
168 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
169 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
170 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
171 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
172 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
177 /*____________________________________________________________________________
179 | scan_to | Scan pixels rightward until hitting desired color (white/black) |
180 |_________|__________________________________________________________________|
182 | Pos, the initial search position, must not be negative nor greater than |
183 | pixels_in_row+1. This function will not return a value greater than |
186 | WARNING: Before calling this routine, the first byte after the end of the |
187 | buffer must be set to alternating zeroes and ones (such as 0x55).|
188 | This allows us to scan bytes for a pixel-change without doing |
189 | the end-of-buffer boundary-check. |
191 | Function return value: index of first pixel of desired color. |
192 |____________________________________________________________________________|
195 UINT skip, /* color to skip over (FF=black, 00=white) */
196 BYTE *buf_p, /* buffer in which to search */
197 int start_pos, /* start-index for search (0=leftmost pixel in buf) */
198 int pixels_in_row) /* # pixels in the buffer */
200 /**************************************************************************
204 * This routine skips all-white and all-black areas a *byte* at a time
205 * using a three-instruction loop. The old routine did this a *word*
206 * (2 bytes) at a time using a three-instruction loop. But this routine
207 * results in faster G3/G4 encoding/decoding, even for mostly white areas,
208 * because it has so little overhead outside the loop. Also, its small
209 * size doesn't toss as much other G3/G4 code out of the cache, improving
210 * performance even more.
212 * Seconds to MMR encode+decode 1000 rows of 1728 pixels (bench_fax.c):
214 * black density: 0% 10% 20% 50%
215 * old routine: 2.1 10.2 18.8 45.1
216 * this routine: 2.2 7.4 12.8 29.9
217 * inlining this routine: 2.2 7.9 13.8 32.4
219 * Inlining this routine *hurt* performance a little because more MMR
220 * code was kicked out of the cache.
222 *************************************************************************/
230 cur_p = buf_p + (start_pos >> 3);
232 byte = (*cur_p ^ skip) & (byte_mask >> (start_pos & 7));
238 } while (byte == skip);
242 pos = ((cur_p-buf_p)<<3) + baLeftZeroesTbl[byte];
244 if (pos > pixels_in_row)
251 /*____________________________________________________________________________
253 | worst_buf_size | calculates worst buffer-usage for a compressed row |
254 |________________|___________________________________________________________|
256 /* worst-case failure of compression (which is expansion) */
257 #define WORST_EXPAND_1D (9<<1) /* = 4.5 in 14.2 fixed-point */
258 #define WORST_EXPAND_2D (6<<2) /* = 6.0 in 14.2 fixed-point */
260 static int worst_buf_size (
261 WORD wFmt, /* fax format (IP_FAX_MH/MR/MMR) */
262 int iRowWidth) /* width of each row of bitmap (# pixels) */
264 return ( ( (wFmt==IP_FAX_MH ? WORST_EXPAND_1D : WORST_EXPAND_2D)
273 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
274 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
280 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
281 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
285 /* ENC_INST - our instance variables */
288 IP_IMAGE_TRAITS traits; /* traits of the image */
289 DWORD dwValidChk; /* struct validity check value */
290 DWORD dwInNextPos; /* file pos for subsequent input */
291 DWORD dwOutNextPos; /* file pos for subsequent output */
292 int iRowLen; /* # pixels in each uncompressed input row */
293 BYTE wOutFmt; /* output format (IP_FAX_MH/FAX_MR/FAX_MMR) */
294 BOOL fNoEOLs; /* don't output any EOLs? */
295 UINT w12Cycle; /* (MR only) # rows in [1d,2d,2d...] cycle */
296 UINT wMinBits; /* minimum # bits to output in each row */
297 int iRowNum; /* current row-number of output, 0 is first */
298 BYTE *prior_p; /* (MR/MMR only) the prior row */
300 /* Variables for "Outputting Bits" section */
301 BYTE *pbBufStart; /* beginning of output buffer */
302 BYTE *pbOutByte; /* current byte in output buffer */
303 DWORD dwBitBuffer; /* buffer of bits (to be written to pbOutByte) */
304 UINT wBitsAvail; /* # of unused bits in dwBitBuffer */
305 } ENC_INST, *PENC_INST;
309 /*****************************************************************************
311 * O U T P U T T I N G B I T S *
313 *****************************************************************************
316 Interface into this section:
317 put_init - initializes this section
318 put_bits - outputs a variable-number of bits (buffered)
319 put_fill_bits - Outputs fill bits (if necessary) to reach the minimum
320 put_grab - gives all bytes except the partial one to caller
321 put_new_buf - tells us to use a new buffer (after put_grab was called)
322 put_done - writes any remaining bits in the buffer
327 /*____________________________________________________________________________
329 | put_init | Initializes this 'put' section |
330 |__________|_________________________________________________________________|
332 static void put_init (
338 g->pbOutByte = pbOutBuf;
339 g->pbBufStart = pbOutBuf;
344 /*____________________________________________________________________________
346 | put_bits | Outputs (buffered) the low-order 'length' bits in 'bits' |
347 |__________|_________________________________________________________________|
349 | 'length' must be no larger than 25. |
350 | The bits in 'bits' that are not to be written must be zeroes. |
352 | This routine lets dwBitBuffer fill up until data won't fit. Then it |
353 | writes out as many bytes as possible from the buffer in a loop. I |
354 | did it this way so the byte-write code would be in cache for more of |
355 | the writes, and so 'write_bytes' will be called as seldom as possible. |
356 |____________________________________________________________________________|
359 static void write_bytes (ENC_INST *g)
361 /* PERFORMANCE NOTE: inlining this routine slows down the encoder
362 * due to worse cache usage.
368 /* assert (g->wBitsAvail <= 24); */
369 byte_p = g->pbOutByte;
370 bitbuf = g->dwBitBuffer;
371 bitsavail = g->wBitsAvail;
374 *byte_p++ = (BYTE )(bitbuf >> 24);
377 } while (bitsavail <= 24);
379 g->pbOutByte = byte_p;
380 g->dwBitBuffer = bitbuf;;
381 g->wBitsAvail = bitsavail;
385 #define put_bits(g, length_par, bits_par) \
387 UINT length_loc = length_par; \
388 DWORD bits_loc = bits_par; \
390 if (length_loc > g->wBitsAvail) \
393 g->wBitsAvail -= length_loc; \
394 g->dwBitBuffer |= bits_loc << g->wBitsAvail; \
398 static void put_bits_routine (
403 put_bits (g, length, bits);
408 /*____________________________________________________________________________
410 | put_flush | Writes out all bytes containing any data in dwBitBuffer |
411 |___________|________________________________________________________________|
413 static void put_flush (ENC_INST *g)
415 if (g->wBitsAvail < 32) {
416 g->wBitsAvail &= ~7ul; /* reduce to a multiple of 8 (byte-boundary) */
420 assert (g->wBitsAvail == 32);
425 /*____________________________________________________________________________
427 | put_fill_bits | Outputs fill bits (if necessary) to reach the minimum |
428 |_______________|____________________________________________________________|
430 | We want put_grab to return the minimum # of bits, but it returns an |
431 | array of bytes (not bits). So this routine insures that at least |
432 | the minimum # of bits have been written (as bytes) into the output |
434 |____________________________________________________________________________|
436 static void put_fill_bits (ENC_INST *g)
442 /* write out zero-bytes until we're at (or past) the minimum # bits */
444 iMore = (int)g->wMinBits - 8*(g->pbOutByte - g->pbBufStart);
446 iMore = (iMore+7) / 8;
447 memset (g->pbOutByte, 0, iMore);
448 g->pbOutByte += iMore;
454 /*____________________________________________________________________________
456 | put_grab | Returns # of bytes written so far, and restarts at buffer-start |
457 |__________|_________________________________________________________________|
459 | The caller is expected to copy N bytes from the buffer, where N is the |
460 | number this function returns. |
461 |____________________________________________________________________________|
463 static int put_grab (ENC_INST *g)
467 n = g->pbOutByte - g->pbBufStart;
468 g->pbOutByte = g->pbBufStart; /* next byte goes into beginning of buffer */
474 /*____________________________________________________________________________
476 | put_new_buf | Use a new buffer (must be called after put_grab) |
477 |_____________|______________________________________________________________|
479 static void put_new_buf (
483 assert (g->pbOutByte == g->pbBufStart);
484 g->pbOutByte = pbOutBuf;
485 g->pbBufStart = pbOutBuf;
490 /*____________________________________________________________________________
492 | put_done | Writes any buffered bits, and returns total # of bytes written |
493 |__________|_________________________________________________________________|
495 static int put_done (
499 return g->pbOutByte - g->pbBufStart;
505 *****************************************************************************
507 * E N C O D I N G R O W S *
509 *****************************************************************************
512 Interface into this section:
513 encode_row_1d - compresses a row into 1-dim format for MH and MR
514 encode_row_2d - compresses a row into 2-dim format for MR and MMR
519 /* Structure for storing G3 codes */
527 /* run-length = index, index is in 0..63 */
528 static const huff_t MHWhiteRuns[] = {
529 {0x35, 8}, {0x7, 6}, {0x7, 4}, {0x8, 4},
530 {0xb, 4}, {0xc, 4}, {0xe, 4}, {0xf, 4},
531 {0x13, 5}, {0x14, 5}, {0x7, 5}, {0x8, 5},
532 {0x8, 6}, {0x3, 6}, {0x34, 6}, {0x35, 6},
533 {0x2a, 6}, {0x2b, 6}, {0x27, 7}, {0xc, 7},
534 {0x8, 7}, {0x17, 7}, {0x3, 7}, {0x4, 7},
535 {0x28, 7}, {0x2b, 7}, {0x13, 7}, {0x24, 7},
536 {0x18, 7}, {0x2, 8}, {0x3, 8}, {0x1a, 8},
537 {0x1b, 8}, {0x12, 8}, {0x13, 8}, {0x14, 8},
538 {0x15, 8}, {0x16, 8}, {0x17, 8}, {0x28, 8},
539 {0x29, 8}, {0x2a, 8}, {0x2b, 8}, {0x2c, 8},
540 {0x2d, 8}, {0x4, 8}, {0x5, 8}, {0xa, 8},
541 {0xb, 8}, {0x52, 8}, {0x53, 8}, {0x54, 8},
542 {0x55, 8}, {0x24, 8}, {0x25, 8}, {0x58, 8},
543 {0x59, 8}, {0x5a, 8}, {0x5b, 8}, {0x4a, 8},
544 {0x4b, 8}, {0x32, 8}, {0x33, 8}, {0x34, 8}
548 /* run-length = 64*(index+1), index is in 0..26 */
549 static const huff_t MHMakeupWhite[] = {
550 {0x1b, 5}, {0x12, 5}, {0x17, 6}, {0x37, 7},
551 {0x36, 8}, {0x37, 8}, {0x64, 8}, {0x65, 8},
552 {0x68, 8}, {0x67, 8}, {0xcc, 9}, {0xcd, 9},
553 {0xd2, 9}, {0xd3, 9}, {0xd4, 9}, {0xd5, 9},
554 {0xd6, 9}, {0xd7, 9}, {0xd8, 9}, {0xd9, 9},
555 {0xda, 9}, {0xdb, 9}, {0x98, 9}, {0x99, 9},
556 {0x9a, 9}, {0x18, 6}, {0x9b, 9}
560 /* run-length = index, index is in 0..63 */
561 static const huff_t MHBlackRuns[] = {
562 {0x37, 10}, {0x2, 3}, {0x3, 2}, {0x2, 2},
563 {0x3, 3}, {0x3, 4}, {0x2, 4}, {0x3, 5},
564 {0x5, 6}, {0x4, 6}, {0x4, 7}, {0x5, 7},
565 {0x7, 7}, {0x4, 8}, {0x7, 8}, {0x18, 9},
566 {0x17, 10}, {0x18, 10}, {0x8, 10}, {0x67, 11},
567 {0x68, 11}, {0x6c, 11}, {0x37, 11}, {0x28, 11},
568 {0x17, 11}, {0x18, 11}, {0xca, 12}, {0xcb, 12},
569 {0xcc, 12}, {0xcd, 12}, {0x68, 12}, {0x69, 12},
570 {0x6a, 12}, {0x6b, 12}, {0xd2, 12}, {0xd3, 12},
571 {0xd4, 12}, {0xd5, 12}, {0xd6, 12}, {0xd7, 12},
572 {0x6c, 12}, {0x6d, 12}, {0xda, 12}, {0xdb, 12},
573 {0x54, 12}, {0x55, 12}, {0x56, 12}, {0x57, 12},
574 {0x64, 12}, {0x65, 12}, {0x52, 12}, {0x53, 12},
575 {0x24, 12}, {0x37, 12}, {0x38, 12}, {0x27, 12},
576 {0x28, 12}, {0x58, 12}, {0x59, 12}, {0x2b, 12},
577 {0x2c, 12}, {0x5a, 12}, {0x66, 12}, {0x67, 12}
581 /* run-length = 64*(index+1), index is in 0..26 */
582 static const huff_t MHMakeupBlack[] = {
583 {0xf, 10}, {0xc8, 12}, {0xc9, 12}, {0x5b, 12},
584 {0x33, 12}, {0x34, 12}, {0x35, 12}, {0x6c, 13},
585 {0x6d, 13}, {0x4a, 13}, {0x4b, 13}, {0x4c, 13},
586 {0x4d, 13}, {0x72, 13}, {0x73, 13}, {0x74, 13},
587 {0x75, 13}, {0x76, 13}, {0x77, 13}, {0x52, 13},
588 {0x53, 13}, {0x54, 13}, {0x55, 13}, {0x5a, 13},
589 {0x5b, 13}, {0x64, 13}, {0x65, 13}
593 /* run-length = 64*(index+28), index is in 0..12 */
594 static const huff_t MHExtMakeup[] = {
595 {0x8, 11}, {0xc, 11}, {0xd, 11}, {0x12, 12},
596 {0x13, 12}, {0x14, 12}, {0x15, 12}, {0x16, 12},
597 {0x17, 12}, {0x1c, 12}, {0x1d, 12}, {0x1e, 12},
602 /* vertical-offset = index-3 */
603 static const huff_t VertTbl[] = {
615 /*____________________________________________________________________________
617 | put_run | Outputs a white or black run |
618 |_________|__________________________________________________________________|
620 static void put_run_routine(
623 const huff_t *makeup_tbl,
624 const huff_t *code_tbl)
628 while (iRunLen >= 1792) {
630 tpos = (iRunLen>>6) - (1792>>6);
633 te = MHExtMakeup [tpos];
634 put_bits_routine (g, te.length, te.bits);
635 iRunLen -= (tpos+(1792>>6)) << 6;
639 te = makeup_tbl [(iRunLen>>6) - 1];
640 put_bits_routine (g, te.length, te.bits);
644 te = code_tbl [iRunLen];
645 put_bits_routine (g, te.length, te.bits);
648 #define put_run(g, par_run_len, par_makeup_tbl, par_code_tbl) \
651 int loc_run_len = par_run_len; \
653 if (loc_run_len >= 64) \
654 put_run_routine (g, loc_run_len, par_makeup_tbl, par_code_tbl); \
656 te = par_code_tbl [loc_run_len]; \
657 put_bits (g, te.length, te.bits); \
663 #define PutWhiteRun(g, iRunLen) \
664 put_run (g, iRunLen, MHMakeupWhite, MHWhiteRuns)
667 #define PutBlackRun(g, iRunLen) \
668 put_run (g, iRunLen, MHMakeupBlack, MHBlackRuns)
671 static void PutEOL(ENC_INST *g) /* output the EOL code (11 zeroes and a one) */
673 put_bits_routine (g, 12, 0x001);
678 /*____________________________________________________________________________
680 | encode_row_1d | Converts a pixel-row into MH (CCITT G3) format |
681 |_______________|____________________________________________________________|
683 | Before calling this routine, you must call put_init. |
684 | After calling this routine, you must call put_grab/put_done. |
685 | This routine puts the EOL at the beginning of the line. |
686 |____________________________________________________________________________|
688 static void encode_row_1d (
690 BYTE *pbPixelRow, /* ptr to pixel-row */
691 int iPixels, /* # of pixels in above row */
692 BOOL fDoingMR) /* Sending MR? Ie, send a 1d/2d tag-bit after EOL? */
696 UINT skip; /* the color we're skipping over; 0x00=black, 0xFF=white */
700 put_bits_routine (g,1,1); /* tag-bit after EOL means 1-dim row-data */
702 pbPixelRow[iPixels>>3] = 0x55u; /* scan_to requires this */
706 while (iStartPos < iPixels) {
707 iChange = scan_to (skip, pbPixelRow, iStartPos, iPixels);
708 if (skip) PutBlackRun (g, iChange-iStartPos);
709 else PutWhiteRun (g, iChange-iStartPos);
717 /*____________________________________________________________________________
719 | encode_row_2d | Converts a pixel-row into 2-dimensional format |
720 |_______________|____________________________________________________________|
722 | Before calling this routine, you must call put_init. |
723 | After calling this routine, you must call put_grab/put_done. |
724 | For MR data, this routine puts the EOL+tag at the beginning of the line. |
725 |____________________________________________________________________________|
728 * The variable 'need' below is a bit-array telling us which values (a1, b0,
729 * etc) are needed. It is determined by the cases below.
731 * b0 is not in the standard. I've defined it as, "A pixel on the reference
732 * line above or to the right of a0, and to the left of b1." Since b1 is the
733 * first changing pixel, b0 must be the same color as a0. b0 is the point at
734 * which the search for b1 begins.
736 * In the code below, b0 uses the b1 variable because if we're using b0, then
737 * b1 is not known, so it's okay to clobber it.
739 * Below, a0, a1, b0, b1 etc denote positions before coding, and A0, A1,
740 * B0, B1, etc denote positions after coding.
751 * A0 = b2, specified by the standard.
752 * A1 = a1, because A0 is to the left of a1, a1 does not move.
753 * B0 = b2, which is known to be the same color as A0.
768 * A0 = a1, specified by the standard.
769 * B1 = b2, the first changing pixel of opposite color as A0.
773 * An exception (a1=b2):
781 * Here, b2 is above A0, and therefore cannot be used as B1.
782 * And its color is opposite A0, so it's not even usable as B0.
783 * So B0 and B1 must be scanned.
785 * Needed: A1, B0, B1, B2.
787 * A subtle exception (a1 is at least 2 pixels to the left of b1):
796 * b1 and b2 move *backwards* after coding.
797 * B1 = b1-1, and B2=b1. Since it's not worth the time to check
798 * for this rare pixel-arrangement, we'll just rescan B0, B1 and B2.
800 * Needed: A1, B0, B1, B2.
804 * First case (a2 > b2):
812 * Since b2 is left of A0, we know nothing about what's above A0.
813 * So everything must be scanned.
815 * Needed: A1, B0, B1, B2.
817 * Second case: (a2 <= b2):
826 * A0 = a2, specified by the standard.
827 * B0 = b2, because it's the same color as A0, and not to left of A0.
829 * Needed: A1, B1, B2.
831 * Exception to above case (a2 < b1):
840 * b1 is to the right of A0, so b1 and b2 don't move.
841 * This case is common because it occurs whenever a row with some
842 * data follows a blank row.
846 static void encode_row_2d (
848 BYTE *pbPixelRow, /* ptr to pixel-row */
849 BYTE *pbRefRow, /* ptr to reference-row */
850 int iPixels, /* # of pixels in above row */
851 BOOL fDoingMR) /* Sending MR? Ie, output an EOL + tag-bit? */
861 UINT skip; /* the color we're skipping over; 00=white, FF=black */
866 put_bits_routine (g,1,0); /* tag-bit after EOL means 2-dim row-data */
869 pbPixelRow[iPixels>>3] = 0x55u; /* scan_to requires this */
870 pbRefRow [iPixels>>3] = 0x55u; /* scan_to requires this */
872 /* The imaginary pixel before the first is considered a white pixel.
873 * So if the first pixel in the row is black, it is considered
874 * a "changing" pixel (white->black).
876 a1 = scan_to ( 0x00, pbPixelRow, 0, iPixels);
877 b1 = scan_to ( 0x00, pbRefRow, 0, iPixels);
878 b2 = scan_to ((UINT)~0x00, pbRefRow, b1+1, iPixels);
879 skip = (UINT)~0x00u; /* white, initially */
884 /* output one of the modes */
888 if (b2 < a1) { /* pass mode */
893 } else if (-3<=iDelta && iDelta<=3) { /* vertical mode */
894 huff_t te = VertTbl[iDelta+3];
895 put_bits (g, te.length, te.bits);
897 if (b2==a1 || iDelta<=-2)
898 need = A1 | B0 | B1 | B2;
902 } else { /* horizontal mode */
903 a2 = scan_to (skip, pbPixelRow, a1+1, iPixels);
906 PutWhiteRun (g,a1-a0);
907 PutBlackRun (g,a2-a1);
909 PutBlackRun (g,a1-a0);
910 PutWhiteRun (g,a2-a1);
913 need = A1 | B0 | B1 | B2;
914 } else if (a2 < b1) {
926 /* compute next a1, b1, b2 */
928 if (need & A1) a1 = scan_to (~skip, pbPixelRow, a0+1, iPixels);
929 if (need & B0) b1 = scan_to ( skip, pbRefRow, a0, iPixels);
930 if (need & B1) b1 = scan_to (~skip, pbRefRow, b1+1, iPixels);
931 if (need & B2) b2 = scan_to ( skip, pbRefRow, b1+1, iPixels);
938 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
939 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
945 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
946 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
951 /*****************************************************************************\
953 * faxEncode_openXform - Creates a new instance of the transformer
955 *****************************************************************************
957 * This returns a handle for the new instance to be passed into
958 * all subsequent calls.
960 * Return value: IP_DONE=success; IP_FATAL_ERROR=misc error.
962 \*****************************************************************************/
964 static WORD faxEncode_openXform (
965 IP_XFORM_HANDLE *pXform) /* out: returned handle */
969 INSURE (pXform != NULL);
970 IP_MEM_ALLOC (sizeof(ENC_INST), g);
972 memset (g, 0, sizeof(ENC_INST));
973 g->dwValidChk = CHECK_VALUE;
974 put_init (g, NULL); /* put_new_buf will be called later */
979 return IP_FATAL_ERROR;
984 /*****************************************************************************\
986 * faxEncode_setDefaultInputTraits - Specifies default input image traits
988 *****************************************************************************
990 * The header of the file-type handled by the transform probably does
991 * not include *all* the image traits we'd like to know. Those not
992 * specified in the file-header are filled in from info provided by
995 * Return value: IP_DONE=success; IP_FATAL_ERROR=misc error.
997 \*****************************************************************************/
999 static WORD faxEncode_setDefaultInputTraits (
1000 IP_XFORM_HANDLE hXform, /* in: handle for xform */
1001 PIP_IMAGE_TRAITS pTraits) /* in: default image traits */
1005 HANDLE_TO_PTR (hXform, g);
1007 /* Insure that values we actually use or care about are known */
1008 INSURE (pTraits->iPixelsPerRow > 0); /* we need the row-length */
1009 INSURE (pTraits->iBitsPerPixel == 1); /* image must be bi-level */
1011 g->traits = *pTraits; /* a structure copy */
1016 return IP_FATAL_ERROR;
1021 /*****************************************************************************\
1023 * faxEncode_setXformSpec - Provides xform-specific information
1025 \*****************************************************************************/
1027 static WORD faxEncode_setXformSpec (
1028 IP_XFORM_HANDLE hXform, /* in: handle for xform */
1029 DWORD_OR_PVOID aXformInfo[]) /* in: xform information */
1033 HANDLE_TO_PTR (hXform, g);
1034 g->wOutFmt = (BYTE)aXformInfo[IP_FAX_FORMAT].dword;
1035 g->fNoEOLs = (BOOL)aXformInfo[IP_FAX_NO_EOLS].dword;
1036 g->wMinBits = (WORD)aXformInfo[IP_FAX_MIN_ROW_LEN].dword;
1040 return IP_FATAL_ERROR;
1045 /*****************************************************************************\
1047 * faxEncode_getHeaderBufSize- Returns size of input buf needed to hold header
1049 \*****************************************************************************/
1051 static WORD faxEncode_getHeaderBufSize (
1052 IP_XFORM_HANDLE hXform, /* in: handle for xform */
1053 DWORD *pdwInBufLen) /* out: buf size for parsing header */
1055 /* since input is raw pixels, there is no header, so set it to zero */
1062 /*****************************************************************************\
1064 * faxEncode_getActualTraits - Parses header, and returns input & output traits
1066 *****************************************************************************
1068 * For this fax xform driver, this routine merely returns input traits.
1070 \*****************************************************************************/
1072 static WORD faxEncode_getActualTraits (
1073 IP_XFORM_HANDLE hXform, /* in: handle for xform */
1074 DWORD dwInputAvail, /* in: # avail bytes in input buf */
1075 PBYTE pbInputBuf, /* in: ptr to input buffer */
1076 PDWORD pdwInputUsed, /* out: # bytes used from input buf */
1077 PDWORD pdwInputNextPos,/* out: file-pos to read from next */
1078 PIP_IMAGE_TRAITS pInTraits, /* out: input image traits */
1079 PIP_IMAGE_TRAITS pOutTraits) /* out: output image traits */
1084 HANDLE_TO_PTR (hXform, g);
1086 /* Since there is no header, we'll report no usage of input */
1089 *pdwInputNextPos = 0;
1091 /* Since we don't change traits, just copy out the default traits */
1093 *pInTraits = g->traits;
1094 *pOutTraits = g->traits;
1096 /* Compute some stuff */
1098 g->iRowLen = g->traits.iPixelsPerRow; /* todo: eliminate redundant var */
1100 /* below, if vert dpi is unknown (negative), we use cycle-len of 2 */
1101 g->w12Cycle = (g->traits.lVertDPI < (150l<<16)) ? 2 : 4;
1103 /* Allocate the prior-row buffer, if needed */
1105 if (g->wOutFmt != IP_FAX_MH) {
1106 if (g->prior_p != NULL)
1107 IP_MEM_FREE (g->prior_p);
1108 inBytes = (g->iRowLen+7) / 8;
1109 IP_MEM_ALLOC (inBytes, g->prior_p);
1110 memset (g->prior_p, 0, inBytes);
1113 return IP_DONE | IP_READY_FOR_DATA;
1116 return IP_FATAL_ERROR;
1121 /****************************************************************************\
1123 * faxEncode_getActualBufSizes - Returns buf sizes needed for remainder of job
1125 \****************************************************************************/
1127 static WORD faxEncode_getActualBufSizes (
1128 IP_XFORM_HANDLE hXform, /* in: handle for xform */
1129 PDWORD pdwMinInBufLen, /* out: min input buf size */
1130 PDWORD pdwMinOutBufLen) /* out: min output buf size */
1133 UINT uWorstBuf, uMinBytes;
1135 HANDLE_TO_PTR (hXform, g);
1136 *pdwMinInBufLen = (g->iRowLen+7) / 8;
1138 uWorstBuf = worst_buf_size (g->wOutFmt, g->iRowLen);
1139 uMinBytes = (g->wMinBits+7) / 8;
1140 *pdwMinOutBufLen = uWorstBuf > uMinBytes ? uWorstBuf : uMinBytes;
1144 return IP_FATAL_ERROR;
1149 /*****************************************************************************\
1151 * faxEncode_convert - the work-horse routine
1153 *****************************************************************************
1155 * This routine (actually put_bits) hangs onto the last 1-3 bytes of
1156 * encoded row-data due to its buffering method.
1158 \*****************************************************************************/
1160 static WORD faxEncode_convert (
1161 IP_XFORM_HANDLE hXform,
1162 DWORD dwInputAvail, /* in: # avail bytes in in-buf */
1163 PBYTE pbInputBuf, /* in: ptr to in-buffer */
1164 PDWORD pdwInputUsed, /* out: # bytes used from in-buf */
1165 PDWORD pdwInputNextPos, /* out: file-pos to read from next */
1166 DWORD dwOutputAvail, /* in: # avail bytes in out-buf */
1167 PBYTE pbOutputBuf, /* in: ptr to out-buffer */
1168 PDWORD pdwOutputUsed, /* out: # bytes written in out-buf */
1169 PDWORD pdwOutputThisPos) /* out: file-pos to write the data */
1175 HANDLE_TO_PTR (hXform, g);
1177 put_new_buf (g, pbOutputBuf);
1179 /********************************************************/
1180 /* If we're being told to flush, output the ending EOLs */
1181 /********************************************************/
1183 if (dwInputAvail == 0) {
1185 switch (g->wOutFmt) {
1192 for (i=6; i>0; i--) {
1194 put_bits_routine (g,1,1);
1205 *pdwOutputUsed = put_done (g);
1206 *pdwInputNextPos = g->dwInNextPos;
1207 *pdwOutputThisPos = g->dwOutNextPos;
1211 /******************************/
1212 /* Normal Case (not flushing) */
1213 /******************************/
1215 inBytes = (g->iRowLen+7) / 8;
1216 INSURE (dwInputAvail >= (DWORD)inBytes);
1217 INSURE (dwOutputAvail > 0);
1219 switch (g->wOutFmt) {
1221 encode_row_1d (g, pbInputBuf, g->iRowLen, FALSE);
1226 if (g->iRowNum % g->w12Cycle == 0)
1227 encode_row_1d (g, pbInputBuf, g->iRowLen, TRUE);
1229 encode_row_2d (g, pbInputBuf, g->prior_p, g->iRowLen, TRUE);
1234 encode_row_2d (g, pbInputBuf, g->prior_p, g->iRowLen, FALSE);
1238 if (g->prior_p != NULL)
1239 memcpy (g->prior_p, pbInputBuf, inBytes);
1241 *pdwInputUsed = inBytes;
1242 g->dwInNextPos += inBytes;
1243 *pdwInputNextPos = g->dwInNextPos;
1245 *pdwOutputUsed = put_grab (g);
1246 *pdwOutputThisPos = g->dwOutNextPos;
1247 g->dwOutNextPos += *pdwOutputUsed;
1250 return IP_CONSUMED_ROW | IP_PRODUCED_ROW | IP_READY_FOR_DATA;
1253 return IP_FATAL_ERROR;
1258 /*****************************************************************************\
1260 * faxEncode_insertedData - client inserted into our output stream
1262 \*****************************************************************************/
1264 static WORD faxEncode_insertedData (
1265 IP_XFORM_HANDLE hXform,
1269 return IP_FATAL_ERROR; /* must never be called (can't insert data) */
1274 /*****************************************************************************\
1276 * faxEncode_newPage - Tells us to flush this page, and start a new page
1278 \*****************************************************************************/
1280 static WORD faxEncode_newPage (
1281 IP_XFORM_HANDLE hXform)
1285 HANDLE_TO_PTR (hXform, g);
1286 /* todo: output EOLs to mark a new page */
1290 return IP_FATAL_ERROR;
1296 /*****************************************************************************\
1298 * faxEncode_closeXform - Destroys this instance
1300 \*****************************************************************************/
1302 static WORD faxEncode_closeXform (IP_XFORM_HANDLE hXform)
1306 HANDLE_TO_PTR (hXform, g);
1308 if (g->prior_p != NULL)
1309 IP_MEM_FREE (g->prior_p);
1312 IP_MEM_FREE (g); /* free memory for the instance */
1316 return IP_FATAL_ERROR;
1321 /*****************************************************************************\
1323 * faxEncodeTbl - Jump-table for encoder
1325 \*****************************************************************************/
1327 IP_XFORM_TBL faxEncodeTbl = {
1328 faxEncode_openXform,
1329 faxEncode_setDefaultInputTraits,
1330 faxEncode_setXformSpec,
1331 faxEncode_getHeaderBufSize,
1332 faxEncode_getActualTraits,
1333 faxEncode_getActualBufSizes,
1336 faxEncode_insertedData,
1337 faxEncode_closeXform
1343 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1344 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1350 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1351 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1355 /* white/nonwhite might be put in interface later on */
1356 #define NONWHITE_ROW 0x0000 /* row is not all white */
1357 #define WHITE_ROW 0x0000 /* row is all white */
1359 #define MAX_CODE_LEN 13 /* length of longest code */
1360 #define EOL_LEN 12 /* EOL is 11 zeroes and a one */
1361 #define EOLS_FOR_MH_MR 3 /* the std says 6, but some might be zapped */
1362 #define EOLS_FOR_MMR 1 /* the std says 2, but we'll stop at first because
1363 * we might not be able to fetch the second EOL from
1364 * the cache because we won't fetch anything unless
1365 * it contains 13 bits, and an EOL is only 12 */
1367 /* Huffman tables (at end of file): */
1369 extern const BYTE fax_vert_huff_index[];
1370 extern const USHORT fax_vert_huff[];
1371 extern const BYTE fax_black_huff_index[];
1372 extern const USHORT fax_black_huff[];
1373 extern const BYTE fax_white_huff_index[];
1374 extern const USHORT fax_white_huff[];
1376 #define MAX_BLACK_CODELEN 13
1377 #define MAX_WHITE_CODELEN 12
1378 #define MAX_VERT_CODELEN 7
1380 #define CODELEN_SHIFT 12
1381 #define VALUE_MASK 0x0fffu
1383 /* items only in fax_vert_huff table: */
1386 #define HORIZ_MODE 8
1389 RET_GOT_CODE, /* we parsed a good code (ret in *piResult) */
1390 RET_BAD_CODE, /* trash in row-data */
1391 RET_FILL, /* got some fill-zeroes */
1392 RET_HIT_EOL, /* hit EOL; no row-data was parsed or returned */
1393 RET_NEED_MORE /* need more input-bytes to complete the row */
1398 /*____________________________________________________________________________
1400 | Type-definition of our instance-variables |
1401 |____________________________________________________________________________|
1411 IP_IMAGE_TRAITS traits; /* traits of the image */
1412 DWORD dwInNextPos; /* file pos for subsequent input */
1413 DWORD dwOutNextPos; /* file pos for subsequent output */
1414 DWORD dwValidChk; /* struct validity check value */
1416 /* Variables for getting bits: */
1417 BYTE *gb_buf_p; /* beginning of our buffer */
1418 BYTE *gb_buf_after_p; /* 1st byte after our buffer */
1419 BYTE *gb_byte_p; /* ptr to next byte */
1420 int gb_cache_cnt; /* # of available bits in gb_cache */
1421 DWORD gb_cache; /* 32-bit buffer to cache the next few bits */
1422 /* is also pos of next avail bit; msb=32, lsb=1 */
1423 int gb_num_zeroes; /* # of successive zero-bits we've gotten */
1425 /* Variables for row-decoding functions: */
1426 int pixel_pos; /* coordinate of next pixel; 0 is leftmost */
1427 BYTE white; /* doing a white run? (00=black, FF=white) */
1428 STATE_2D state_2d; /* state of the 2-dim decoder */
1429 int a0; /* pixel before 1st is an imaginary white pixel */
1430 BYTE *prior_p; /* buffer containing prior row */
1431 BOOL ref_row_invalid; /* (MR only) reference row invalid due to error?*/
1433 /* Variables for the exported functions: */
1434 BYTE input_format; /* input format (IP_FAX_MH/MR/MMR) */
1435 BYTE num_eols; /* number of successive EOLs we've gotten */
1436 BOOL no_eols; /* are EOLs not present in input? */
1437 BOOL toss_everything; /* are we discarding all data due to prior err? */
1438 BOOL flushing_to_eol; /* are we ignoring bits until an EOL? */
1439 BOOL got_fill; /* gotten any fill-zeroes? */
1440 BOOL got_black; /* set any black pixels in the row? */
1441 BOOL two_dim; /* next row is 2-dimensional encoding? */
1442 int row_len; /* # pixels in each row */
1443 int bytes_in_row; /* # bytes in each row */
1444 } DEC_INST, *PDEC_INST;
1448 /*****************************************************************************
1450 * F E T C H I N G B I T S *
1452 *****************************************************************************
1455 Interface into this section:
1457 bits_init - inits this section
1458 bits_buf_open - gives us (this section) a buffer to consume
1459 BITS_REFILL_CACHE - fills cache; must be called before parsing
1460 BITS_IN_CACHE - returns # bits currently in the cache
1461 BITS_LOAD - returns next N bits of input (no advance is done)
1462 BITS_ADVANCE - advances input by the given # of bits
1463 bits_buf_close - returns # bytes consumed in buffer
1464 bits_flush - discards all unread bits
1465 bits_flush_to_eol - flushes input bits until EOL is encountered
1470 /*____________________________________________________________________________
1472 | bits_init | initializes this "fetching bits" section |
1473 |___________|________________________________________________________________|
1475 static void bits_init (DEC_INST *g)
1477 g->gb_num_zeroes = 0;
1478 g->gb_cache_cnt = 0; /* the cache is empty */
1483 /*____________________________________________________________________________
1485 | bits_buf_open | gives us (this section) a buffer to consume |
1486 |_______________|____________________________________________________________|
1488 static void bits_buf_open (
1493 g->gb_byte_p = buf_p;
1494 g->gb_buf_p = buf_p;
1495 g->gb_buf_after_p = buf_p + num_bytes;
1500 /*____________________________________________________________________________
1502 | bits_buf_close | returns # bytes consumed in buffer |
1503 |________________|___________________________________________________________|
1505 static UINT bits_buf_close (DEC_INST *g)
1507 return (g->gb_byte_p - g->gb_buf_p);
1512 /*____________________________________________________________________________
1514 | bits_flush | discards all unread bits |
1515 |____________|_______________________________________________________________|
1517 static void bits_flush (DEC_INST *g)
1519 g->gb_cache_cnt = 0;
1520 g->gb_byte_p = g->gb_buf_after_p;
1525 /*____________________________________________________________________________
1527 | BITS_REFILL_CACHE | fills cache as full as possible |
1528 |___________________|________________________________________________________|
1530 #define BITS_REFILL_CACHE(g) \
1532 int cache_cnt = g->gb_cache_cnt; \
1533 DWORD cache = g->gb_cache; \
1534 BYTE *byte_p = g->gb_byte_p; \
1535 BYTE *buf_after_p = g->gb_buf_after_p; \
1537 while (cache_cnt<=24 && byte_p<buf_after_p) { \
1538 cache = (cache << 8) | (*byte_p++); \
1542 g->gb_cache_cnt = cache_cnt; \
1543 g->gb_cache = cache; \
1544 g->gb_byte_p = byte_p; \
1549 /*____________________________________________________________________________
1551 | BITS_IN_CACHE | returns # bits currently in the bit-cache |
1552 |_______________|____________________________________________________________|
1554 #define BITS_IN_CACHE(g) (g->gb_cache_cnt)
1558 /*____________________________________________________________________________
1560 | bits_flush_to_eol | flushes input bits until EOL is encountered |
1561 |___________________|________________________________________________________|
1563 | If got_fill is TRUE, then we merely scan for a set bit. |
1564 | Otherwise, we first count leading zeroes until it reaches 11. |
1566 | Return value: TRUE = We hit an EOL. In this case, if leave_a_bit is |
1567 | TRUE, the cache will contain at least one bit so |
1568 | you can fetch a 1-dim/2-dim bit. |
1569 | FALSE = We need more input data. |
1570 |____________________________________________________________________________|
1572 static BOOL bits_flush_to_eol (
1573 DEC_INST *g, /* our instance vars */
1574 BOOL got_fill, /* have we gotten fill zeroes? */
1575 BOOL leave_a_bit) /* after hitting EOL, insure that cache isn't empty? */
1577 #define CLEAR_UNUSED_CACHE_BITS \
1578 if (g->gb_cache_cnt < 32) \
1579 g->gb_cache &= (1lu << g->gb_cache_cnt) - 1lu;
1584 /*********************************************/
1585 /* Scan input until 11 zeroes have been seen */
1586 /*********************************************/
1588 if (g->gb_num_zeroes >= 11)
1593 if (g->gb_cache_cnt != 0) {
1594 for (bit = (1lu<<(g->gb_cache_cnt-1));
1597 g->gb_cache_cnt -= 1;
1598 if (bit & g->gb_cache)
1599 g->gb_num_zeroes =0;
1601 g->gb_num_zeroes += 1;
1602 if (g->gb_num_zeroes >= 11)
1608 /* the cache is now empty; start scanning bytes */
1611 if (g->gb_byte_p >= g->gb_buf_after_p)
1613 byt = *(g->gb_byte_p)++;
1614 g->gb_num_zeroes += baLeftZeroesTbl[byt];
1615 if (g->gb_num_zeroes >= 11) {
1620 g->gb_num_zeroes = baRightZeroesTbl[byt];
1624 /*******************************************/
1625 /* Scan input until a non-zero bit is seen */
1626 /*******************************************/
1630 BITS_REFILL_CACHE (g)
1631 if (g->gb_cache_cnt==0 || (leave_a_bit && g->gb_cache_cnt==1))
1634 CLEAR_UNUSED_CACHE_BITS
1636 if (g->gb_cache == 0)
1637 g->gb_cache_cnt = 0; /* cache is all zeroes; discard it */
1639 /* we hit the EOL */
1640 for (bit = (1lu<<(g->gb_cache_cnt-1));
1641 (bit & g->gb_cache) == 0;
1643 g->gb_cache_cnt -= 1; /* discard the 0's before the 1 */
1645 /* After discarding the set bit, if leave_a_bit is TRUE, we want
1646 * the cache to be non-empty so that a 1-dim/2-dim bit can then
1647 * be fetched. Hence the check for 2 bits in cache below.
1649 if (!leave_a_bit || g->gb_cache_cnt>=2) {
1650 g->gb_cache_cnt -= 1; /* discard the set bit we found above */
1651 g->gb_num_zeroes = 0;
1656 /* discard zero bytes */
1658 /* Warning: If fax_decode_convert_row was told to flush, both
1659 * pointers gb_byte_p and gb_buf_after_p can be NULL. So the
1660 * pointer-compare below must be *before* the dereference in the
1661 * test of the while loop, to avoid dereferencing a NULL pointer.
1663 if (g->gb_cache_cnt == 0)
1664 while (g->gb_byte_p<g->gb_buf_after_p && *(g->gb_byte_p)==0)
1671 /*____________________________________________________________________________
1673 | BITS_LOAD | returns the next num_bits of input, with NO advance |
1674 |___________|________________________________________________________________|
1676 #define BITS_LOAD(g, num_bits, par_result) { \
1677 int n_bits = (int)(num_bits); \
1679 par_result = (g->gb_cache >> (g->gb_cache_cnt-n_bits)) \
1680 & ((1u<<n_bits) - 1u); \
1685 #define BITS_LOAD(g, num_bits, par_result) { \
1686 int n_bits = (int)(num_bits); \
1688 par_result = g->gb_cache; \
1690 asm ("extract %1,%2,%0" \
1691 : "=d" (par_result) \
1692 : "dI" (g->gb_cache_cnt - n_bits), "dI" (n_bits), "0" (par_result)); \
1699 /*____________________________________________________________________________
1701 | BITS_ADVANCE | advances input by num_bits bits |
1702 |______________|_____________________________________________________________|
1704 #define BITS_ADVANCE(g, num_bits) { \
1705 g->gb_cache_cnt -= (num_bits); \
1710 /*****************************************************************************
1712 * U T I L I T I E S *
1714 *****************************************************************************/
1718 /*____________________________________________________________________________
1720 | parse_code_routine | Parses a Huffman code using the given code tables |
1721 |____________________|_______________________________________________________|
1723 | Function return values: RET_GOT_CODE |
1729 | This function must NOT be called to scan for an EOL after it has |
1730 | returned RET_BAD_CODE or RET_FILL. |
1732 | Warning: When this returns RET_HIT_EOL, it must guarantee that the |
1733 | bit-cache is not empty so a 1-dim/2-dim bit can be fetched. |
1734 |____________________________________________________________________________|
1737 static UINT parse_code_routine (
1739 int bits_in_index, /* in: # bits in index for index_tbl */
1740 const BYTE index_tbl[], /* in: contains indices into value_tbl */
1741 const USHORT value_tbl[], /* in: contains [codelen, value] pairs */
1742 int *value_p) /* out: the value corresponding to the code */
1746 BITS_REFILL_CACHE(g)
1747 if (BITS_IN_CACHE(g) < bits_in_index)
1748 return RET_NEED_MORE;
1750 BITS_LOAD (g, bits_in_index, blob);
1751 values = value_tbl[index_tbl[blob]];
1754 /* normal case: we got a valid code */
1755 BITS_ADVANCE (g, values >> CODELEN_SHIFT);
1756 *value_p = values & VALUE_MASK;
1757 return RET_GOT_CODE;
1760 if (BITS_IN_CACHE(g) < MAX_CODE_LEN)
1761 return RET_NEED_MORE;
1763 BITS_LOAD (g, EOL_LEN, blob);
1766 BITS_ADVANCE (g, EOL_LEN);
1771 BITS_ADVANCE (g, EOL_LEN);
1775 return RET_BAD_CODE;
1780 /*____________________________________________________________________________
1782 | PARSE_CODE | A fast macro for parsing Huffman codes |
1783 |____________|_______________________________________________________________|
1785 #define PARSE_CODE( \
1787 bits_in_index, /* in: # bits in index for index_tbl */ \
1788 index_tbl, /* in: contains indices into value_tbl */ \
1789 value_tbl, /* in: contains [codelen, value] pairs */ \
1790 out_result, /* out: RET_GOT_CODE, RET_BAD_CODE, etc */ \
1791 out_value) /* out: the value corresponding to the code */ \
1793 UINT blob, values; \
1795 if (BITS_IN_CACHE(g) < bits_in_index) \
1796 goto call##value_tbl; \
1798 BITS_LOAD (g, bits_in_index, blob); \
1799 values = value_tbl[index_tbl[blob]]; \
1801 if (values == 0) { \
1803 out_result = parse_code_routine \
1804 (g, bits_in_index, index_tbl, value_tbl, &out_value); \
1806 BITS_ADVANCE (g, values >> CODELEN_SHIFT); \
1807 out_result = RET_GOT_CODE; \
1808 out_value = values & VALUE_MASK; \
1814 /*____________________________________________________________________________
1816 | runs_array | all possible runs that fit in 16 bits |
1817 |____________|_______________________________________________________________|
1819 | This array is indexed by (leftbit<<4)+rightbit. |
1820 | Leftbit and rightbit are in 0..15. 0=msb, 15=lsb. |
1821 |____________________________________________________________________________|
1824 static const USHORT runs_array_le[256] = { /* little-endian array */
1825 0x0080, 0x00c0, 0x00e0, 0x00f0, 0x00f8, 0x00fc, 0x00fe, 0x00ff,
1826 0x80ff, 0xc0ff, 0xe0ff, 0xf0ff, 0xf8ff, 0xfcff, 0xfeff, 0xffff,
1827 0x0000, 0x0040, 0x0060, 0x0070, 0x0078, 0x007c, 0x007e, 0x007f,
1828 0x807f, 0xc07f, 0xe07f, 0xf07f, 0xf87f, 0xfc7f, 0xfe7f, 0xff7f,
1829 0x0000, 0x0000, 0x0020, 0x0030, 0x0038, 0x003c, 0x003e, 0x003f,
1830 0x803f, 0xc03f, 0xe03f, 0xf03f, 0xf83f, 0xfc3f, 0xfe3f, 0xff3f,
1831 0x0000, 0x0000, 0x0000, 0x0010, 0x0018, 0x001c, 0x001e, 0x001f,
1832 0x801f, 0xc01f, 0xe01f, 0xf01f, 0xf81f, 0xfc1f, 0xfe1f, 0xff1f,
1833 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x000c, 0x000e, 0x000f,
1834 0x800f, 0xc00f, 0xe00f, 0xf00f, 0xf80f, 0xfc0f, 0xfe0f, 0xff0f,
1835 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0004, 0x0006, 0x0007,
1836 0x8007, 0xc007, 0xe007, 0xf007, 0xf807, 0xfc07, 0xfe07, 0xff07,
1837 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0003,
1838 0x8003, 0xc003, 0xe003, 0xf003, 0xf803, 0xfc03, 0xfe03, 0xff03,
1839 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001,
1840 0x8001, 0xc001, 0xe001, 0xf001, 0xf801, 0xfc01, 0xfe01, 0xff01,
1841 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1842 0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
1843 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1844 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x7f00,
1845 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1846 0x0000, 0x0000, 0x2000, 0x3000, 0x3800, 0x3c00, 0x3e00, 0x3f00,
1847 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1848 0x0000, 0x0000, 0x0000, 0x1000, 0x1800, 0x1c00, 0x1e00, 0x1f00,
1849 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1850 0x0000, 0x0000, 0x0000, 0x0000, 0x0800, 0x0c00, 0x0e00, 0x0f00,
1851 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1852 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0400, 0x0600, 0x0700,
1853 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1854 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0200, 0x0300,
1855 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1856 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0100,
1859 static const USHORT runs_array_be[256] = { /* big-endian array */
1860 0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
1861 0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
1862 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x7f00,
1863 0x7f80, 0x7fc0, 0x7fe0, 0x7ff0, 0x7ff8, 0x7ffc, 0x7ffe, 0x7fff,
1864 0x0000, 0x0000, 0x2000, 0x3000, 0x3800, 0x3c00, 0x3e00, 0x3f00,
1865 0x3f80, 0x3fc0, 0x3fe0, 0x3ff0, 0x3ff8, 0x3ffc, 0x3ffe, 0x3fff,
1866 0x0000, 0x0000, 0x0000, 0x1000, 0x1800, 0x1c00, 0x1e00, 0x1f00,
1867 0x1f80, 0x1fc0, 0x1fe0, 0x1ff0, 0x1ff8, 0x1ffc, 0x1ffe, 0x1fff,
1868 0x0000, 0x0000, 0x0000, 0x0000, 0x0800, 0x0c00, 0x0e00, 0x0f00,
1869 0x0f80, 0x0fc0, 0x0fe0, 0x0ff0, 0x0ff8, 0x0ffc, 0x0ffe, 0x0fff,
1870 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0400, 0x0600, 0x0700,
1871 0x0780, 0x07c0, 0x07e0, 0x07f0, 0x07f8, 0x07fc, 0x07fe, 0x07ff,
1872 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0200, 0x0300,
1873 0x0380, 0x03c0, 0x03e0, 0x03f0, 0x03f8, 0x03fc, 0x03fe, 0x03ff,
1874 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0100,
1875 0x0180, 0x01c0, 0x01e0, 0x01f0, 0x01f8, 0x01fc, 0x01fe, 0x01ff,
1876 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1877 0x0080, 0x00c0, 0x00e0, 0x00f0, 0x00f8, 0x00fc, 0x00fe, 0x00ff,
1878 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1879 0x0000, 0x0040, 0x0060, 0x0070, 0x0078, 0x007c, 0x007e, 0x007f,
1880 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1881 0x0000, 0x0000, 0x0020, 0x0030, 0x0038, 0x003c, 0x003e, 0x003f,
1882 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1883 0x0000, 0x0000, 0x0000, 0x0010, 0x0018, 0x001c, 0x001e, 0x001f,
1884 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1885 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x000c, 0x000e, 0x000f,
1886 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1887 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0004, 0x0006, 0x0007,
1888 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1889 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0003,
1890 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
1891 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001,
1894 static const USHORT *runs_array = runs_array_le;
1896 static void initRunArray(void) {
1898 char *pcTest=((char *)(&iTest));
1901 runs_array = runs_array_le;
1903 runs_array = runs_array_be;
1908 /*____________________________________________________________________________
1910 | set_run | Sets a run of pixels to black |
1911 |_________|__________________________________________________________________|
1913 | This routine does bounds-checking to avoid setting any pixels outside the |
1916 | Since this is called often, it's written to be as fast as I could make it. |
1917 |____________________________________________________________________________|
1919 static void set_run (
1920 BYTE *buf_p, /* buffer in which we're to set the run */
1921 int start_pos, /* pixel-index of left side of run */
1922 int run_len, /* # of pixels in the run (non-negative) */
1923 int row_len) /* # of pixels in the buffer */
1925 /*************************************************************************
1929 * Inlining this routine slows it down a little.
1930 * Seconds to MMR encode+decode 1000 rows of 1728 pixels (bench_fax.c):
1932 * black density: 0% 10% 20% 50%
1933 * calling this routine: 2.2 7.4 12.8 29.9
1934 * inlining this routine: 2.2 7.5 13.2 30.6
1936 * Inlining this routine *hurt* performance a little because more MMR
1937 * code was kicked out of the cache.
1939 *************************************************************************/
1941 int end_pos; /* pixel-index of rightmost pixel in run */
1942 int start_index; /* byte-index of first byte in run */
1943 BYTE *left_p; /* ptr to byte containing leftmost pixel in run */
1944 BYTE *right_p; /* ptr to byte containing rightmost pixel in run */
1946 end_pos = start_pos + run_len - 1;
1948 if (end_pos >= row_len)
1949 end_pos = row_len - 1;
1951 start_index = start_pos >> 4;
1953 if ((end_pos >> 4) == start_index) {
1954 /* the run is contained within an even-aligned 2-byte word */
1955 ((USHORT*)buf_p)[start_index] |=
1956 runs_array [((start_pos & 15)<<4) | (end_pos & 15)];
1957 } else if (end_pos > start_pos) {
1958 /* the run spans two or more bytes */
1959 left_p = buf_p + (start_pos >> 3);
1960 right_p = buf_p + (end_pos >> 3);
1962 *left_p |= (BYTE )0xFFu >> (UINT)( start_pos & 7u );
1963 *right_p = (BYTE )0xFFu << (UINT)(7u - (end_pos & 7u));
1966 while (left_p < right_p)
1972 /*****************************************************************************
1974 * DECODING ROW-DATA *
1976 *****************************************************************************
1979 Interface into this section:
1981 decode_row_init - inits instance-vars for this section
1982 decode_row_1d - parses a row of 1-dim data
1983 decode_row_2d - parses a row of 2-dim data
1985 The parsing routines return these bit-values:
1989 DECODE_HIT_EOL (defined below, not in the public interface)
1990 DECODE_HIT_FILL (ditto)
1992 A return-value of zero (ie, none of the above bits are set) means that the
1993 routine wants to be called again with more input-bytes.
1995 These routines fetch input by calling BITS_LOAD, so bits_init and
1996 bits_buf_open must have already been called.
1999 #define DECODE_HIT_EOL 0x4000u
2000 #define DECODE_HIT_FILL 0x8000u
2003 /*____________________________________________________________________________
2005 | decode_row_init | inits instance-variables for this section |
2006 |_________________|__________________________________________________________|
2008 static void decode_row_init (DEC_INST *g)
2011 g->white = 0xFFu; /* start with a white run */
2012 g->state_2d = NORMAL_2D;
2013 g->a0 = -1; /* pixel before 1st is an imaginary white pixel */
2014 g->got_black = FALSE; /* haven't gotten any black pixels */
2019 /*____________________________________________________________________________
2021 | decode_row_1d | Decodes a row of MH (1-dimensional G3) data |
2022 |_______________|____________________________________________________________|
2024 static UINT decode_row_1d (
2025 DEC_INST *g, /* in: pointer to our instance-variables */
2026 BYTE *pbPrevOutBuf, /* in: prev output row (for error-handling) */
2027 BYTE *pbOutBuf) /* out: output buf */
2029 int run_len; /* # pixels in current run */
2033 UINT ret_val = 0; /* init to zap a compiler warning */
2035 const BYTE *index_tbl_p;
2036 const USHORT *value_tbl_p;
2038 if (g->pixel_pos == 0) {
2039 memset (pbOutBuf, 0, g->bytes_in_row); /* set whole row to white */
2040 g->ref_row_invalid = TRUE;
2043 white = (UINT)(int )(signed char)g->white; /* must be all 0's or all 1's */
2044 pixel_pos = g->pixel_pos;
2049 index_length = MAX_WHITE_CODELEN;
2050 index_tbl_p = fax_white_huff_index;
2051 value_tbl_p = fax_white_huff;
2053 index_length = MAX_BLACK_CODELEN;
2054 index_tbl_p = fax_black_huff_index;
2055 value_tbl_p = fax_black_huff;
2058 PARSE_CODE (g, index_length, index_tbl_p, value_tbl_p, result, run_len);
2059 PRINT (_T("pc result=%d, len=%d\n"), result, run_len);
2061 if (result == RET_GOT_CODE) {
2062 /* todo: below, we call set_run for EVERY make-up code (slow) */
2064 set_run (pbOutBuf, pixel_pos, run_len, g->row_len);
2065 g->got_black = TRUE;
2068 pixel_pos += run_len;
2069 if (run_len <= 63) /* this is a final run (not a make-up) */
2071 continue; /* go to top of main 'while' loop */
2074 switch (result) { /* handle unusual condition */
2082 memcpy (pbOutBuf, pbPrevOutBuf, g->bytes_in_row);
2083 ret_val = IP_PRODUCED_ROW | IP_INPUT_ERROR;
2089 ret_val = result==RET_FILL ? DECODE_HIT_FILL : DECODE_HIT_EOL;
2092 if (pixel_pos == g->row_len) {
2093 ret_val |= IP_PRODUCED_ROW;
2094 g->ref_row_invalid = FALSE;
2097 memcpy (pbOutBuf, pbPrevOutBuf, g->bytes_in_row);
2098 ret_val |= IP_PRODUCED_ROW | IP_INPUT_ERROR;
2104 } /* end of switch */
2105 } /* end of while */
2110 g->pixel_pos = pixel_pos;
2117 /*____________________________________________________________________________
2119 | decode_row_2d | Decodes a row of MR/MMR (2-dimensional) data |
2120 |_______________|____________________________________________________________|
2122 static UINT decode_row_2d (
2123 DEC_INST *g, /* in: pointer to our instance-variables */
2124 BYTE *pbPrevBuf, /* in: prev output row ("reference row") */
2125 BYTE *pbOutBuf) /* out: output buffer */
2130 UINT result = 0; /* the 0 eliminates a compiler warning */
2134 int b1=0, b2; /* the 0 eliminates a compiler warning */
2136 UINT ret_val = 0; /* the 0 eliminates a compiler warning */
2138 group4 = (g->input_format == IP_FAX_MMR);
2139 row_len = g->row_len;
2140 white = (UINT)(int)(signed char)g->white; /* must be all 0's or all 1's so sign extend */
2144 memset (pbOutBuf, 0, g->bytes_in_row); /* set whole row to white */
2145 pbPrevBuf[g->bytes_in_row] = 0x55u; /* scan_to requires this */
2150 /****************************************/
2151 /* Process a usual code -- normal state */
2152 /****************************************/
2156 while (g->state_2d == NORMAL_2D) {
2158 if (a0>=row_len && group4) {
2159 /* ret_val = IP_PRODUCED_ROW; goto bail_out;
2160 * todo: undelete the line above? */
2161 if (a0 == row_len) ret_val = IP_PRODUCED_ROW;
2162 else ret_val = IP_INPUT_ERROR;
2166 PARSE_CODE (g, MAX_VERT_CODELEN, fax_vert_huff_index,
2167 fax_vert_huff, result, iAction);
2168 if (result != RET_GOT_CODE)
2169 goto unusual_condition;
2171 if (iAction == HORIZ_MODE) {
2172 g->state_2d = HORIZ_1ST;
2178 b1 = -1; /* a kludge so scan below will start at pixel 0 */
2180 b1 = scan_to (white, pbPrevBuf, a0, row_len);
2182 b1 = scan_to (~white, pbPrevBuf, b1+1, row_len);
2184 if (iAction <= LAST_VERT) { /* vertical mode */
2187 need_b0 = (iAction<-1 || iAction>0);
2189 set_run (pbOutBuf, a0, a1-a0, row_len);
2190 g->got_black = TRUE;
2192 if (a1<a0 || a1>row_len) goto corrupt;
2195 } else { /* pass mode */
2196 b2 = scan_to (white, pbPrevBuf, b1+1, row_len);
2198 set_run (pbOutBuf, a0, b2-a0, row_len);
2199 g->got_black = TRUE;
2205 } /* while NORMAL_2D */
2207 /*******************************************/
2208 /* Process a usual code -- horizontal mode */
2209 /*******************************************/
2211 while (TRUE) { /* HORIZ_1ST or HORIZ_2ND */
2213 const BYTE *index_tbl_p;
2214 const USHORT *value_tbl_p;
2218 index_length = MAX_WHITE_CODELEN;
2219 index_tbl_p = fax_white_huff_index;
2220 value_tbl_p = fax_white_huff;
2222 index_length = MAX_BLACK_CODELEN;
2223 index_tbl_p = fax_black_huff_index;
2224 value_tbl_p = fax_black_huff;
2227 PARSE_CODE (g, index_length, index_tbl_p, value_tbl_p,
2230 if (result != RET_GOT_CODE)
2231 goto unusual_condition;
2232 if (a0 < 0) /* Exception: See Fascicle VII.3, */
2233 a0 = 0; /* rec T.4, section 4.2.1.3.4 */
2234 /* todo: below, we call set_run for EVERY make-up code (slow) */
2236 set_run (pbOutBuf, a0, run_len, row_len);
2237 g->got_black = TRUE;
2240 } while (run_len > 63);
2243 if (g->state_2d == HORIZ_1ST)
2244 g->state_2d = HORIZ_2ND;
2246 g->state_2d = NORMAL_2D;
2247 if (a0 > row_len) goto corrupt;
2248 break; /* exit while */
2252 continue; /* no unusual condition, so resume main while loop */
2254 /*****************************/
2255 /* Handle unusual conditions */
2256 /*****************************/
2259 result = RET_BAD_CODE;
2266 /* normal case: was handled in the block of code above */
2275 g->state_2d = NORMAL_2D;
2276 memcpy (pbOutBuf, pbPrevBuf, g->bytes_in_row);
2277 ret_val = IP_PRODUCED_ROW | IP_INPUT_ERROR;
2278 g->ref_row_invalid = TRUE;
2284 ret_val = result==RET_FILL ? DECODE_HIT_FILL : DECODE_HIT_EOL;
2285 g->state_2d = NORMAL_2D;
2288 /* We should only hit EOL when no row-data is present */
2289 /* todo: Always report error if fill-zeroes were seen? */
2291 ret_val |= IP_INPUT_ERROR;
2293 if (!g->ref_row_invalid && a0==row_len)
2294 ret_val |= IP_PRODUCED_ROW;
2296 memcpy (pbOutBuf, pbPrevBuf, g->bytes_in_row);
2297 ret_val |= IP_PRODUCED_ROW | IP_INPUT_ERROR;
2298 g->ref_row_invalid = TRUE;
2307 } /* end of switch to handle unusual condition */
2308 } /* end of while */
2312 /* save variables needed in next call */
2321 /*****************************************************************************\
2323 * faxDecode_openXform - Creates a new instance of the transformer
2325 *****************************************************************************
2327 * This returns a handle for the new instance to be passed into
2328 * all subsequent calls.
2330 * Return value: IP_DONE=success; IP_FATAL_ERROR=misc error.
2332 \*****************************************************************************/
2334 static WORD faxDecode_openXform (
2335 IP_XFORM_HANDLE *pXform) /* out: returned handle */
2340 INSURE (pXform != NULL);
2341 IP_MEM_ALLOC (sizeof(DEC_INST), g);
2343 memset (g, 0, sizeof(DEC_INST));
2344 g->dwValidChk = CHECK_VALUE;
2347 decode_row_init (g);
2351 return IP_FATAL_ERROR;
2356 /*****************************************************************************\
2358 * faxDecode_setDefaultInputTraits - Specifies default input image traits
2360 *****************************************************************************
2362 * The header of the file-type handled by the transform probably does
2363 * not include *all* the image traits we'd like to know. Those not
2364 * specified in the file-header are filled in from info provided by
2367 * Return value: IP_DONE=success; IP_FATAL_ERROR=misc error.
2369 \*****************************************************************************/
2371 static WORD faxDecode_setDefaultInputTraits (
2372 IP_XFORM_HANDLE hXform, /* in: handle for xform */
2373 PIP_IMAGE_TRAITS pTraits) /* in: default image traits */
2377 HANDLE_TO_PTR (hXform, g);
2379 /* Insure that values we actually use or care about are known */
2380 INSURE (pTraits->iPixelsPerRow > 0); /* we need the row-length */
2381 INSURE (pTraits->iBitsPerPixel == 1); /* image must be bi-level */
2383 g->traits = *pTraits; /* a structure copy */
2388 return IP_FATAL_ERROR;
2393 /*****************************************************************************\
2395 * faxDecode_setXformSpec - Provides xform-specific information
2397 \*****************************************************************************/
2399 static WORD faxDecode_setXformSpec (
2400 IP_XFORM_HANDLE hXform, /* in: handle for xform */
2401 DWORD_OR_PVOID aXformInfo[]) /* in: xform information */
2405 HANDLE_TO_PTR (hXform, g);
2406 g->input_format = (BYTE)aXformInfo[IP_FAX_FORMAT].dword;
2407 g->no_eols = (BOOL)aXformInfo[IP_FAX_NO_EOLS].dword;
2411 return IP_FATAL_ERROR;
2416 /*****************************************************************************\
2418 * faxDecode_getHeaderBufSize- Returns size of input buf needed to hold header
2420 \*****************************************************************************/
2422 static WORD faxDecode_getHeaderBufSize (
2423 IP_XFORM_HANDLE hXform, /* in: handle for xform */
2424 DWORD *pdwInBufLen) /* out: buf size for parsing header */
2426 /* since input is raw pixels, there is no header, so set it to zero */
2433 /*****************************************************************************\
2435 * faxDecode_getActualTraits - Parses header, and returns input & output traits
2437 *****************************************************************************
2439 * There is no header, so this routine merely computes some stuff
2441 \*****************************************************************************/
2443 static WORD faxDecode_getActualTraits (
2444 IP_XFORM_HANDLE hXform, /* in: handle for xform */
2445 DWORD dwInputAvail, /* in: # avail bytes in input buf */
2446 PBYTE pbInputBuf, /* in: ptr to input buffer */
2447 PDWORD pdwInputUsed, /* out: # bytes used from input buf */
2448 PDWORD pdwInputNextPos,/* out: file-pos to read from next */
2449 PIP_IMAGE_TRAITS pInTraits, /* out: input image traits */
2450 PIP_IMAGE_TRAITS pOutTraits) /* out: output image traits */
2455 HANDLE_TO_PTR (hXform, g);
2457 /* Since there is no header, we'll report no usage of input */
2460 *pdwInputNextPos = 0;
2462 /* Since we don't change traits, just copy out the default traits */
2464 *pInTraits = g->traits;
2465 *pOutTraits = g->traits;
2467 /* Compute some stuff */
2469 g->row_len = g->traits.iPixelsPerRow; /* todo: zap redundant var */
2470 g->bytes_in_row = inBytes = (g->row_len+7) / 8;
2471 g->two_dim = (g->input_format == IP_FAX_MMR);
2473 /* For MH and MR: Discard bits before the first EOL */
2474 g->flushing_to_eol = ! g->two_dim;
2476 /* allocate the prior-row buffer */
2478 if (g->prior_p != NULL)
2479 IP_MEM_FREE (g->prior_p);
2480 IP_MEM_ALLOC (inBytes, g->prior_p);
2481 memset (g->prior_p, 0, inBytes);
2483 return IP_DONE | IP_READY_FOR_DATA;
2486 return IP_FATAL_ERROR;
2491 /****************************************************************************\
2493 * faxDecode_getActualBufSizes - Returns buf sizes needed for remainder of job
2495 \****************************************************************************/
2497 static WORD faxDecode_getActualBufSizes (
2498 IP_XFORM_HANDLE hXform, /* in: handle for xform */
2499 PDWORD pdwMinInBufLen, /* out: min input buf size */
2500 PDWORD pdwMinOutBufLen) /* out: min output buf size */
2504 HANDLE_TO_PTR (hXform, g);
2505 *pdwMinInBufLen = 1;
2506 *pdwMinOutBufLen = g->bytes_in_row;
2510 return IP_FATAL_ERROR;
2515 /*****************************************************************************\
2517 * faxDecode_convert - the work-horse routine
2519 \*****************************************************************************/
2521 static WORD faxDecode_convert (
2522 IP_XFORM_HANDLE hXform,
2523 DWORD dwInputAvail, /* in: # avail bytes in in-buf */
2524 PBYTE pbInputBuf, /* in: ptr to in-buffer */
2525 PDWORD pdwInputUsed, /* out: # bytes used from in-buf */
2526 PDWORD pdwInputNextPos, /* out: file-pos to read from next */
2527 DWORD dwOutputAvail, /* in: # avail bytes in out-buf */
2528 PBYTE pbOutputBuf, /* in: ptr to out-buffer */
2529 PDWORD pdwOutputUsed, /* out: # bytes written in out-buf */
2530 PDWORD pdwOutputThisPos) /* out: file-pos to write the data */
2534 UINT ret_val; /* return-value of this function */
2536 HANDLE_TO_PTR (hXform, g);
2540 if (dwInputAvail==0 && BITS_IN_CACHE(g)<MAX_CODE_LEN) {
2541 /* We're being told to flush; indicate we're done. */
2542 /* Our only buffer is the cache */
2544 *pdwInputNextPos = g->dwInNextPos;
2545 *pdwOutputThisPos = g->dwOutNextPos;
2549 if (g->toss_everything) {
2550 *pdwInputUsed = dwInputAvail;
2551 *pdwInputNextPos = g->dwInNextPos = g->dwInNextPos + dwInputAvail;
2552 *pdwOutputThisPos = g->dwOutNextPos;
2553 return IP_READY_FOR_DATA;
2556 bits_buf_open (g, pbInputBuf, dwInputAvail);
2558 if (g->flushing_to_eol) {
2559 ret_val = bits_flush_to_eol(g, g->got_fill,
2560 (BOOL)(g->input_format==IP_FAX_MR))
2561 ? DECODE_HIT_EOL : 0;
2563 if (g->two_dim) ret_val = decode_row_2d(g, g->prior_p, pbOutputBuf);
2564 else ret_val = decode_row_1d(g, g->prior_p, pbOutputBuf);
2565 PRINT (_T("decoder returned %x\n"), ret_val, 0);
2568 if (ret_val & IP_INPUT_ERROR) {
2569 if (g->input_format == IP_FAX_MMR) {
2571 g->toss_everything = TRUE;
2572 /* This isn't fatal any more. We merely toss all following data */
2573 /* ret_val |= IP_INPUT_ERROR; */
2575 g->flushing_to_eol = TRUE;
2580 if (ret_val & IP_PRODUCED_ROW) {
2581 if (g->got_black) ret_val |= NONWHITE_ROW | IP_CONSUMED_ROW;
2582 else ret_val |= WHITE_ROW | IP_CONSUMED_ROW;
2583 *pdwOutputUsed = g->bytes_in_row;
2584 memcpy (g->prior_p, pbOutputBuf, g->bytes_in_row);
2585 decode_row_init (g);
2586 g->num_eols = 0; /* ignore all EOLs before the row */
2589 if (ret_val & DECODE_HIT_FILL) {
2590 g->flushing_to_eol = TRUE;
2594 if (ret_val & DECODE_HIT_EOL) {
2595 if (g->input_format == IP_FAX_MR) {
2596 /* read the tag-bit for 1-dim/2-dim */
2597 BITS_LOAD (g, 1, bit)
2598 g->two_dim = (bit == 0);
2602 decode_row_init (g);
2603 g->flushing_to_eol = FALSE;
2604 g->got_fill = FALSE;
2607 if (g->num_eols>=EOLS_FOR_MH_MR ||
2608 (g->input_format==IP_FAX_MMR && g->num_eols>=EOLS_FOR_MMR)) {
2609 /* WE HIT END OF PAGE */
2612 ret_val |= IP_NEW_OUTPUT_PAGE;
2616 *pdwInputUsed = bits_buf_close (g);
2617 g->dwInNextPos += *pdwInputUsed;
2618 *pdwInputNextPos = g->dwInNextPos;
2620 *pdwOutputUsed = (ret_val & IP_PRODUCED_ROW) ? g->bytes_in_row : 0;
2621 *pdwOutputThisPos = g->dwOutNextPos;
2622 g->dwOutNextPos += *pdwOutputUsed;
2627 for (i=0; i<*pdwInputUsed; i++)
2628 PRINT (_T("%02x "), pbInputBuf[i], 0);
2632 return (ret_val | IP_READY_FOR_DATA)
2633 & (IP_CONSUMED_ROW | IP_PRODUCED_ROW | IP_READY_FOR_DATA |
2634 /* NONWHITE_ROW | WHITE_ROW | */
2635 IP_NEW_OUTPUT_PAGE |
2636 IP_INPUT_ERROR | IP_FATAL_ERROR);
2639 return IP_FATAL_ERROR;
2644 /*****************************************************************************\
2646 * faxDecode_insertedData - client inserted into our output stream
2648 \*****************************************************************************/
2650 static WORD faxDecode_insertedData (
2651 IP_XFORM_HANDLE hXform,
2655 return IP_FATAL_ERROR; /* must never be called (can't insert data) */
2660 /*****************************************************************************\
2662 * faxDecode_newPage - Tells us to flush this page, and start a new page
2664 \*****************************************************************************/
2666 static WORD faxDecode_newPage (
2667 IP_XFORM_HANDLE hXform)
2671 HANDLE_TO_PTR (hXform, g);
2672 /* todo: flush bits until we see a page boundary */
2676 return IP_FATAL_ERROR;
2682 /*****************************************************************************\
2684 * faxDecode_closeXform - Destroys this instance
2686 \*****************************************************************************/
2688 static WORD faxDecode_closeXform (IP_XFORM_HANDLE hXform)
2692 HANDLE_TO_PTR (hXform, g);
2694 if (g->prior_p != NULL)
2695 IP_MEM_FREE (g->prior_p);
2698 IP_MEM_FREE (g); /* free memory for the instance */
2702 return IP_FATAL_ERROR;
2707 /*****************************************************************************\
2709 * faxDecodeTbl - Jump-table for Decoder
2711 \*****************************************************************************/
2713 IP_XFORM_TBL faxDecodeTbl = {
2714 faxDecode_openXform,
2715 faxDecode_setDefaultInputTraits,
2716 faxDecode_setXformSpec,
2717 faxDecode_getHeaderBufSize,
2718 faxDecode_getActualTraits,
2719 faxDecode_getActualBufSizes,
2722 faxDecode_insertedData,
2723 faxDecode_closeXform
2730 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2732 @ T A B L E S F O R D E C O D E R @
2734 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2739 const USHORT fax_white_huff[105] = { 0,
2740 0x4002, 0x4003, 0x4004, 0x4005, 0x4006, 0x4007, 0x500a, 0x500b,
2741 0x5080, 0x5008, 0x5009, 0x5040, 0x600d, 0x6001, 0x600c, 0x60c0,
2742 0x6680, 0x6010, 0x6011, 0x600e, 0x600f, 0x7016, 0x7017, 0x7014,
2743 0x7013, 0x701a, 0x7015, 0x701c, 0x701b, 0x7012, 0x7018, 0x7019,
2744 0x7100, 0x801d, 0x801e, 0x802d, 0x802e, 0x802f, 0x8030, 0x8021,
2745 0x8022, 0x8023, 0x8024, 0x8025, 0x8026, 0x801f, 0x8020, 0x8035,
2746 0x8036, 0x8027, 0x8028, 0x8029, 0x802a, 0x802b, 0x802c, 0x803d,
2747 0x803e, 0x803f, 0x8000, 0x8140, 0x8180, 0x803b, 0x803c, 0x8031,
2748 0x8032, 0x8033, 0x8034, 0x8037, 0x8038, 0x8039, 0x803a, 0x81c0,
2749 0x8200, 0x8280, 0x8240, 0x95c0, 0x9600, 0x9640, 0x96c0, 0x92c0,
2750 0x9300, 0x9340, 0x9380, 0x93c0, 0x9400, 0x9440, 0x9480, 0x94c0,
2751 0x9500, 0x9540, 0x9580, 0xb700, 0xb740, 0xb780, 0xc7c0, 0xc800,
2752 0xc840, 0xc880, 0xc8c0, 0xc900, 0xc940, 0xc980, 0xc9c0, 0xca00,
2756 const BYTE fax_white_huff_index[4096] = {
2757 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2758 92, 92, 95, 96, 97, 98, 99, 100, 93, 93, 94, 94, 101, 102, 103, 104,
2759 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
2760 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2761 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
2762 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
2763 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
2764 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
2765 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
2766 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
2767 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
2768 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
2769 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
2770 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
2771 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
2772 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
2773 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
2774 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
2775 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
2776 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
2777 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
2778 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
2779 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
2780 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
2781 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
2782 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
2783 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
2784 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
2785 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
2786 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
2787 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
2788 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
2789 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
2790 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
2791 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
2792 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
2793 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
2794 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
2795 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
2796 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
2797 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
2798 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
2799 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
2800 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
2801 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
2802 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
2803 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
2804 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
2805 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
2806 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
2807 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
2808 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
2809 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
2810 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
2811 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
2812 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
2813 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2814 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2815 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2816 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2817 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2818 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2819 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2820 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2821 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2822 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2823 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2824 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2825 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2826 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2827 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2828 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
2829 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
2830 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
2831 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
2832 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
2833 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77,
2834 78, 78, 78, 78, 78, 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, 79,
2835 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
2836 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
2837 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
2838 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
2839 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
2840 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
2841 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
2842 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
2843 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
2844 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
2845 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
2846 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
2847 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
2848 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
2849 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
2850 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
2851 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
2852 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
2853 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
2854 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
2855 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
2856 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
2857 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
2858 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
2859 80, 80, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81, 81,
2860 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74,
2861 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
2862 82, 82, 82, 82, 82, 82, 82, 82, 83, 83, 83, 83, 83, 83, 83, 83,
2863 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85,
2864 86, 86, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87,
2865 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89, 89,
2866 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 91, 91,
2867 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
2868 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
2869 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2870 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2871 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2872 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2873 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2874 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2875 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2876 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2877 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2878 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2879 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2880 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2,
2901 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2902 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2903 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2904 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2905 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2906 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2907 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2908 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
2909 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2910 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2911 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2912 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2913 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2914 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2915 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2916 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
2917 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2918 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2919 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2920 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2921 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2922 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2923 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2924 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
2925 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
2926 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
2927 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
2928 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
2929 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
2930 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
2931 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
2932 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
2933 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2934 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2935 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2936 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2937 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2938 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2939 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2940 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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,
2961 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2962 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2963 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2964 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2965 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
2966 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
2967 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
2968 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
2969 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
2970 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
2971 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
2972 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
2973 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2974 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2975 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2976 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2977 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2978 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2979 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2980 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
2981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6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3002 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3003 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3004 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3005 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3006 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3007 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3008 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3009 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3010 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3011 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3012 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3016 const USHORT fax_black_huff[105] = { 0,
3017 0x2003, 0x2002, 0x3001, 0x3004, 0x4006, 0x4005, 0x5007, 0x6009,
3018 0x6008, 0x700a, 0x700b, 0x700c, 0x800d, 0x800e, 0x900f, 0xa012,
3019 0xa040, 0xa010, 0xa011, 0xa000, 0xb700, 0xb740, 0xb780, 0xb018,
3020 0xb019, 0xb017, 0xb016, 0xb013, 0xb014, 0xb015, 0xc7c0, 0xc800,
3021 0xc840, 0xc880, 0xc8c0, 0xc900, 0xc940, 0xc980, 0xc9c0, 0xca00,
3022 0xc034, 0xc037, 0xc038, 0xc03b, 0xc03c, 0xc140, 0xc180, 0xc1c0,
3023 0xc035, 0xc036, 0xc032, 0xc033, 0xc02c, 0xc02d, 0xc02e, 0xc02f,
3024 0xc039, 0xc03a, 0xc03d, 0xc100, 0xc030, 0xc031, 0xc03e, 0xc03f,
3025 0xc01e, 0xc01f, 0xc020, 0xc021, 0xc028, 0xc029, 0xc080, 0xc0c0,
3026 0xc01a, 0xc01b, 0xc01c, 0xc01d, 0xc022, 0xc023, 0xc024, 0xc025,
3027 0xc026, 0xc027, 0xc02a, 0xc02b, 0xd280, 0xd2c0, 0xd300, 0xd340,
3028 0xd500, 0xd540, 0xd580, 0xd5c0, 0xd600, 0xd640, 0xd680, 0xd6c0,
3029 0xd200, 0xd240, 0xd380, 0xd3c0, 0xd400, 0xd440, 0xd480, 0xd4c0,
3033 const BYTE fax_black_huff_index[8192] = {
3034 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3035 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3036 21, 21, 21, 21, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36,
3037 22, 22, 22, 22, 23, 23, 23, 23, 37, 37, 38, 38, 39, 39, 40, 40,
3038 16, 16, 16, 16, 16, 16, 16, 16, 41, 41, 85, 86, 87, 88, 42, 42,
3039 43, 43, 89, 90, 91, 92, 44, 44, 45, 45, 93, 94, 24, 24, 24, 24,
3040 25, 25, 25, 25, 95, 96, 46, 46, 47, 47, 48, 48, 97, 98, 49, 49,
3041 50, 50, 99, 100, 101, 102, 103, 104, 17, 17, 17, 17, 17, 17, 17, 17,
3042 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
3043 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
3044 26, 26, 26, 26, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56,
3045 57, 57, 58, 58, 59, 59, 60, 60, 18, 18, 18, 18, 18, 18, 18, 18,
3046 19, 19, 19, 19, 19, 19, 19, 19, 61, 61, 62, 62, 63, 63, 64, 64,
3047 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, 27, 27, 27, 27,
3048 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
3049 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
3050 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
3051 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
3052 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
3053 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
3054 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
3055 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
3056 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
3057 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
3058 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
3059 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76, 28, 28, 28, 28,
3060 29, 29, 29, 29, 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82,
3061 30, 30, 30, 30, 83, 83, 84, 84, 20, 20, 20, 20, 20, 20, 20, 20,
3062 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
3063 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
3064 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
3065 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
3066 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
3067 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8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