59#if defined(__cplusplus)
65#if defined(__cplusplus)
117#define EndOfData() (cp >= ep)
143#define NeedBits8(n, eoflab) \
146 if (BitsAvail < (n)) \
150 if (BitsAvail == 0) \
156 BitAcc |= ((uint32_t)bitmap[*cp++]) << BitsAvail; \
163#define NeedBits16(n, eoflab) \
166 if (BitsAvail < (n)) \
170 if (BitsAvail == 0) \
176 BitAcc |= ((uint32_t)bitmap[*cp++]) << BitsAvail; \
177 if ((BitsAvail += 8) < (n)) \
186 BitAcc |= ((uint32_t)bitmap[*cp++]) << BitsAvail; \
194#define GetBits(n) (BitAcc & ((1 << (n)) - 1))
203static const char *StateNames[] = {
204 "Null ",
"Pass ",
"Horiz ",
"V0 ",
"VR ",
"VL ",
"Ext ",
205 "TermW ",
"TermB ",
"MakeUpW",
"MakeUpB",
"MakeUp ",
"EOL ",
207#define DEBUG_SHOW putchar(BitAcc & (1 << t) ? '1' : '0')
208#define LOOKUP8(wid, tab, eoflab) \
212 NeedBits8(wid, eoflab); \
213 TabEnt = tab + GetBits(wid); \
214 printf("%08lX/%d: %s%5d\t", (long)BitAcc, BitsAvail, \
215 StateNames[TabEnt->State], TabEnt->Param); \
216 for (t = 0; t < TabEnt->Width; t++) \
220 ClrBits(TabEnt->Width); \
222#define LOOKUP16(wid, tab, eoflab) \
226 NeedBits16(wid, eoflab); \
227 TabEnt = tab + GetBits(wid); \
228 printf("%08lX/%d: %s%5d\t", (long)BitAcc, BitsAvail, \
229 StateNames[TabEnt->State], TabEnt->Param); \
230 for (t = 0; t < TabEnt->Width; t++) \
234 ClrBits(TabEnt->Width); \
240 *pa++ = RunLength + (x); \
241 printf("SETVALUE: %d\t%d\n", RunLength + (x), a0); \
246#define LOOKUP8(wid, tab, eoflab) \
249 NeedBits8(wid, eoflab); \
250 TabEnt = tab + GetBits(wid); \
251 ClrBits(TabEnt->Width); \
253#define LOOKUP16(wid, tab, eoflab) \
256 NeedBits16(wid, eoflab); \
257 TabEnt = tab + GetBits(wid); \
258 ClrBits(TabEnt->Width); \
268 if (pa >= thisrun + sp->nruns) \
270 TIFFErrorExtR(tif, module, "Buffer overflow at line %u of %s %u", \
271 sp->line, isTiled(tif) ? "tile" : "strip", \
272 isTiled(tif) ? tif->tif_curtile \
273 : tif->tif_curstrip); \
276 *pa++ = RunLength + (x); \
292#define SYNC_EOL(eoflab, retrywithouteol) \
295 if (!(sp->b.mode & FAXMODE_NOEOL)) \
301 NeedBits16(11, eoflab); \
302 if (GetBits(11) == 0) \
310 NeedBits8(8, noEOLFound); \
315 while (GetBits(1) == 0) \
321 sp->b.mode |= FAXMODE_NOEOL; \
322 tryG3WithoutEOL(a0); \
323 goto retrywithouteol; \
332#define CLEANUP_RUNS() \
339 badlength(a0, lastx); \
340 while (a0 > lastx && pa > thisrun) \
346 if ((pa - thisrun) & 1) \
348 SETVALUE(lastx - a0); \
350 else if (a0 > lastx) \
370#define EXPAND1D(eoflab) \
377 LOOKUP16(12, TIFFFaxWhiteTable, eof1d); \
378 switch (TabEnt->State) \
384 SETVALUE(TabEnt->Param); \
388 a0 += TabEnt->Param; \
389 RunLength += TabEnt->Param; \
392 unexpected("WhiteTable", a0); \
401 LOOKUP16(13, TIFFFaxBlackTable, eof1d); \
402 switch (TabEnt->State) \
408 SETVALUE(TabEnt->Param); \
412 a0 += TabEnt->Param; \
413 RunLength += TabEnt->Param; \
416 unexpected("BlackTable", a0); \
423 if (*(pa - 1) == 0 && *(pa - 2) == 0) \
442 while (b1 <= a0 && b1 < lastx) \
444 if (pb + 1 >= sp->refruns + sp->nruns) \
447 tif, module, "Buffer overflow at line %u of %s %u", \
448 sp->line, isTiled(tif) ? "tile" : "strip", \
449 isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
452 b1 += pb[0] + pb[1]; \
460#define EXPAND2D(eoflab) \
465 if (pa >= thisrun + sp->nruns) \
468 tif, module, "Buffer overflow at line %u of %s %u", \
469 sp->line, isTiled(tif) ? "tile" : "strip", \
470 isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
473 LOOKUP8(7, TIFFFaxMainTable, eof2d); \
474 switch (TabEnt->State) \
478 if (pb + 1 >= sp->refruns + sp->nruns) \
480 TIFFErrorExtR(tif, module, \
481 "Buffer overflow at line %u of %s %u", \
483 isTiled(tif) ? "tile" : "strip", \
484 isTiled(tif) ? tif->tif_curtile \
485 : tif->tif_curstrip); \
489 RunLength += b1 - a0; \
494 if ((pa - thisrun) & 1) \
498 LOOKUP16(13, TIFFFaxBlackTable, eof2d); \
499 switch (TabEnt->State) \
502 SETVALUE(TabEnt->Param); \
506 a0 += TabEnt->Param; \
507 RunLength += TabEnt->Param; \
516 LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \
517 switch (TabEnt->State) \
520 SETVALUE(TabEnt->Param); \
524 a0 += TabEnt->Param; \
525 RunLength += TabEnt->Param; \
537 LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \
538 switch (TabEnt->State) \
541 SETVALUE(TabEnt->Param); \
545 a0 += TabEnt->Param; \
546 RunLength += TabEnt->Param; \
555 LOOKUP16(13, TIFFFaxBlackTable, eof2d); \
556 switch (TabEnt->State) \
559 SETVALUE(TabEnt->Param); \
563 a0 += TabEnt->Param; \
564 RunLength += TabEnt->Param; \
577 if (pb >= sp->refruns + sp->nruns) \
579 TIFFErrorExtR(tif, module, \
580 "Buffer overflow at line %u of %s %u", \
582 isTiled(tif) ? "tile" : "strip", \
583 isTiled(tif) ? tif->tif_curtile \
584 : tif->tif_curstrip); \
591 SETVALUE(b1 - a0 + TabEnt->Param); \
592 if (pb >= sp->refruns + sp->nruns) \
594 TIFFErrorExtR(tif, module, \
595 "Buffer overflow at line %u of %s %u", \
597 isTiled(tif) ? "tile" : "strip", \
598 isTiled(tif) ? tif->tif_curtile \
599 : tif->tif_curstrip); \
606 if (b1 < (int)(a0 + TabEnt->Param)) \
608 unexpected("VL", a0); \
611 SETVALUE(b1 - a0 - TabEnt->Param); \
615 *pa++ = lastx - a0; \
619 *pa++ = lastx - a0; \
620 NeedBits8(4, eof2d); \
622 unexpected("EOL", a0); \
628 unexpected("MainTable", a0); \
631 unexpected("BlackTable", a0); \
634 unexpected("WhiteTable", a0); \
644 if (RunLength + a0 < lastx) \
647 NeedBits8(1, eof2d); \
const TIFFFaxTabEnt TIFFFaxMainTable[]
void(* TIFFFaxFillFunc)(unsigned char *, uint32_t *, uint32_t *, uint32_t)
const TIFFFaxTabEnt TIFFFaxBlackTable[]
void _TIFFFax3fillruns(unsigned char *, uint32_t *, uint32_t *, uint32_t)
const TIFFFaxTabEnt TIFFFaxWhiteTable[]