79 uint32_t *erun, uint32_t lastx);
84#if defined(__cplusplus)
111 uint32_t *erun, uint32_t lastx);
112#if defined(__cplusplus)
205#define EndOfData() (cp >= ep)
231#define NeedBits8(n, eoflab) \
234 if (BitsAvail < (n)) \
238 if (BitsAvail == 0) \
244 BitAcc |= ((uint32_t)bitmap[*cp++]) << BitsAvail; \
251#define NeedBits16(n, eoflab) \
254 if (BitsAvail < (n)) \
258 if (BitsAvail == 0) \
264 BitAcc |= ((uint32_t)bitmap[*cp++]) << BitsAvail; \
265 if ((BitsAvail += 8) < (n)) \
274 BitAcc |= ((uint32_t)bitmap[*cp++]) << BitsAvail; \
282#define GetBits(n) (BitAcc & ((1 << (n)) - 1))
298static const char *StateNames[] = {
299 "Null ",
"Pass ",
"Horiz ",
"V0 ",
"VR ",
"VL ",
"Ext ",
300 "TermW ",
"TermB ",
"MakeUpW",
"MakeUpB",
"MakeUp ",
"EOL ",
310#define DEBUG_SHOW putchar(BitAcc & (1 << t) ? '1' : '0')
311#define LOOKUP8(wid, tab, eoflab) \
315 NeedBits8(wid, eoflab); \
316 TabEnt = tab + GetBits(wid); \
317 printf("%08lX/%d: %s%5d\t", (long)BitAcc, BitsAvail, \
318 StateNames[TabEnt->State], TabEnt->Param); \
319 for (t = 0; t < TabEnt->Width; t++) \
323 ClrBits(TabEnt->Width); \
325#define LOOKUP16(wid, tab, eoflab) \
329 NeedBits16(wid, eoflab); \
330 TabEnt = tab + GetBits(wid); \
331 printf("%08lX/%d: %s%5d\t", (long)BitAcc, BitsAvail, \
332 StateNames[TabEnt->State], TabEnt->Param); \
333 for (t = 0; t < TabEnt->Width; t++) \
337 ClrBits(TabEnt->Width); \
343 if (pa >= thisrun + sp->nruns) \
345 TIFFErrorExtR(tif, module, "Buffer overflow at line %d of %s %u", \
346 sp->line, isTiled(tif) ? "tile" : "strip", \
347 isTiled(tif) ? tif->tif_dir.td_curtile \
348 : tif->tif_dir.td_curstrip); \
351 *pa++ = RunLength + (x); \
352 printf("SETVALUE: %d\t%d\n", RunLength + (x), a0); \
357#define LOOKUP8(wid, tab, eoflab) \
360 NeedBits8(wid, eoflab); \
361 TabEnt = tab + GetBits(wid); \
362 ClrBits(TabEnt->Width); \
364#define LOOKUP16(wid, tab, eoflab) \
367 NeedBits16(wid, eoflab); \
368 TabEnt = tab + GetBits(wid); \
369 ClrBits(TabEnt->Width); \
379 if (pa >= thisrun + sp->nruns) \
381 TIFFErrorExtR(tif, module, "Buffer overflow at line %d of %s %u", \
382 sp->line, isTiled(tif) ? "tile" : "strip", \
383 isTiled(tif) ? tif->tif_dir.td_curtile \
384 : tif->tif_dir.td_curstrip); \
387 *pa++ = (uint32_t)((uint32_t)RunLength + (uint32_t)(x)); \
388 a0 += (int)(uint32_t)(x); \
403#define SYNC_EOL(eoflab, retrywithouteol) \
406 if (!(sp->b.mode & FAXMODE_NOEOL)) \
412 NeedBits16(11, eoflab); \
413 if (GetBits(11) == 0) \
421 NeedBits8(8, noEOLFound); \
426 while (GetBits(1) == 0) \
432 sp->b.mode |= FAXMODE_NOEOL; \
433 tryG3WithoutEOL(a0); \
434 goto retrywithouteol; \
443#define CLEANUP_RUNS() \
448 if (a0 != (int)lastx) \
450 badlength(a0, lastx); \
451 while (a0 > (int)lastx && pa > thisrun) \
453 if (a0 < (int)lastx) \
457 if ((pa - thisrun) & 1) \
459 SETVALUE((uint32_t)((int)lastx - a0)); \
461 else if (a0 > (int)lastx) \
481#define EXPAND1D(eoflab) \
488 LOOKUP16(12, TIFFFaxWhiteTable, eof1d); \
489 switch (TabEnt->State) \
495 SETVALUE(TabEnt->Param); \
499 a0 = (int)((uint32_t)a0 + TabEnt->Param); \
501 (int)((uint32_t)RunLength + TabEnt->Param); \
504 unexpected("WhiteTable", a0); \
509 if (a0 >= (int)lastx) \
513 LOOKUP16(13, TIFFFaxBlackTable, eof1d); \
514 switch (TabEnt->State) \
520 SETVALUE(TabEnt->Param); \
524 a0 += (int)TabEnt->Param; \
525 RunLength += (int)TabEnt->Param; \
528 unexpected("BlackTable", a0); \
533 if (a0 >= (int)lastx) \
535 if (*(pa - 1) == 0 && *(pa - 2) == 0) \
554 while (b1 <= a0 && b1 < (int)lastx) \
556 if (pb + 1 >= sp->refruns + sp->nruns) \
558 TIFFErrorExtR(tif, module, \
559 "Buffer overflow at line %d of %s %u", \
560 sp->line, isTiled(tif) ? "tile" : "strip", \
561 isTiled(tif) ? tif->tif_dir.td_curtile \
562 : tif->tif_dir.td_curstrip); \
565 b1 += (int)(pb[0] + pb[1]); \
573#define EXPAND2D(eoflab) \
576 while (a0 < (int)lastx) \
578 if (pa >= thisrun + sp->nruns) \
580 TIFFErrorExtR(tif, module, \
581 "Buffer overflow at line %d of %s %u", sp->line, \
582 isTiled(tif) ? "tile" : "strip", \
583 isTiled(tif) ? tif->tif_dir.td_curtile \
584 : tif->tif_dir.td_curstrip); \
587 LOOKUP8(7, TIFFFaxMainTable, eof2d); \
588 switch (TabEnt->State) \
592 if (pb + 1 >= sp->refruns + sp->nruns) \
596 "Buffer overflow at line %d of %s %u", sp->line, \
597 isTiled(tif) ? "tile" : "strip", \
598 isTiled(tif) ? tif->tif_dir.td_curtile \
599 : tif->tif_dir.td_curstrip); \
602 b1 = b1 + (int)*pb++; \
604 (int)((uint32_t)RunLength + (uint32_t)(b1 - a0)); \
606 b1 = b1 + (int)*pb++; \
609 if ((pa - thisrun) & 1) \
613 LOOKUP16(13, TIFFFaxBlackTable, eof2d); \
614 switch (TabEnt->State) \
617 SETVALUE(TabEnt->Param); \
621 a0 = (int)((uint32_t)a0 + TabEnt->Param); \
622 RunLength = (int)((uint32_t)RunLength + \
632 LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \
633 switch (TabEnt->State) \
636 SETVALUE(TabEnt->Param); \
640 a0 = (int)((uint32_t)a0 + TabEnt->Param); \
641 RunLength = (int)((uint32_t)RunLength + \
654 LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \
655 switch (TabEnt->State) \
658 SETVALUE(TabEnt->Param); \
662 a0 = (int)((uint32_t)a0 + TabEnt->Param); \
663 RunLength = (int)((uint32_t)RunLength + \
673 LOOKUP16(13, TIFFFaxBlackTable, eof2d); \
674 switch (TabEnt->State) \
677 SETVALUE(TabEnt->Param); \
681 a0 = (int)((uint32_t)a0 + TabEnt->Param); \
682 RunLength = (int)((uint32_t)RunLength + \
696 if (pb >= sp->refruns + sp->nruns) \
700 "Buffer overflow at line %d of %s %u", sp->line, \
701 isTiled(tif) ? "tile" : "strip", \
702 isTiled(tif) ? tif->tif_dir.td_curtile \
703 : tif->tif_dir.td_curstrip); \
706 b1 = b1 + (int)*pb++; \
710 SETVALUE((int)((uint32_t)(b1 - a0) + TabEnt->Param)); \
711 if (pb >= sp->refruns + sp->nruns) \
715 "Buffer overflow at line %d of %s %u", sp->line, \
716 isTiled(tif) ? "tile" : "strip", \
717 isTiled(tif) ? tif->tif_dir.td_curtile \
718 : tif->tif_dir.td_curstrip); \
721 b1 = b1 + (int)*pb++; \
725 if (b1 < (int)((uint32_t)a0 + TabEnt->Param)) \
727 unexpected("VL", a0); \
730 SETVALUE((int)((uint32_t)(b1 - a0) - TabEnt->Param)); \
731 b1 = b1 - (int)*--pb; \
734 *pa++ = (uint32_t)((int)lastx - a0); \
738 *pa++ = (uint32_t)((int)lastx - a0); \
739 NeedBits8(4, eof2d); \
741 unexpected("EOL", a0); \
747 unexpected("MainTable", a0); \
750 unexpected("BlackTable", a0); \
753 unexpected("WhiteTable", a0); \
763 if (RunLength + a0 < lastx) \
766 NeedBits8(1, eof2d); \
void(* TIFFFaxFillFunc)(unsigned char *buf, uint32_t *runs, uint32_t *erun, uint32_t lastx)
Render decoded fax runs through an installed callback.
const TIFFFaxTabEnt TIFFFaxMainTable[]
Decode seven-bit two-dimensional (Group3 2D and Group4) mode prefixes.
void _TIFFFax3fillruns(unsigned char *buf, uint32_t *runs, uint32_t *erun, uint32_t lastx)
Render alternating white/black fax runs into an MSB-first row.
const TIFFFaxTabEnt TIFFFaxBlackTable[]
Decode thirteen-bit black-run prefixes.
const TIFFFaxTabEnt TIFFFaxWhiteTable[]
Decode twelve-bit white-run prefixes.
Describe one generated fax decoding state transition.
uint32_t Param
Run length or vertical offset magnitude interpreted by State; fixed ABI layout.
unsigned char Width
Number of input code bits consumed by this entry.
unsigned char State
Finite-state operation code S_Null through S_EOL.
Define TIFF file-format types, tag identifiers, and constant values.