58#if defined(__cplusplus)
62#if defined(__cplusplus)
111#define EndOfData() (cp >= ep)
137#define NeedBits8(n,eoflab) do { \
138 if (BitsAvail < (n)) { \
140 if (BitsAvail == 0) \
144 BitAcc |= ((uint32) bitmap[*cp++])<<BitsAvail; \
151#define NeedBits16(n,eoflab) do { \
152 if (BitsAvail < (n)) { \
154 if (BitsAvail == 0) \
158 BitAcc |= ((uint32) bitmap[*cp++])<<BitsAvail; \
159 if ((BitsAvail += 8) < (n)) { \
164 BitAcc |= ((uint32) bitmap[*cp++])<<BitsAvail; \
172#define GetBits(n) (BitAcc & ((1<<(n))-1))
173#define ClrBits(n) do { \
179static const char* StateNames[] = {
194#define DEBUG_SHOW putchar(BitAcc & (1 << t) ? '1' : '0')
195#define LOOKUP8(wid,tab,eoflab) do { \
197 NeedBits8(wid,eoflab); \
198 TabEnt = tab + GetBits(wid); \
199 printf("%08lX/%d: %s%5d\t", (long) BitAcc, BitsAvail, \
200 StateNames[TabEnt->State], TabEnt->Param); \
201 for (t = 0; t < TabEnt->Width; t++) \
205 ClrBits(TabEnt->Width); \
207#define LOOKUP16(wid,tab,eoflab) do { \
209 NeedBits16(wid,eoflab); \
210 TabEnt = tab + GetBits(wid); \
211 printf("%08lX/%d: %s%5d\t", (long) BitAcc, BitsAvail, \
212 StateNames[TabEnt->State], TabEnt->Param); \
213 for (t = 0; t < TabEnt->Width; t++) \
217 ClrBits(TabEnt->Width); \
220#define SETVALUE(x) do { \
221 *pa++ = RunLength + (x); \
222 printf("SETVALUE: %d\t%d\n", RunLength + (x), a0); \
227#define LOOKUP8(wid,tab,eoflab) do { \
228 NeedBits8(wid,eoflab); \
229 TabEnt = tab + GetBits(wid); \
230 ClrBits(TabEnt->Width); \
232#define LOOKUP16(wid,tab,eoflab) do { \
233 NeedBits16(wid,eoflab); \
234 TabEnt = tab + GetBits(wid); \
235 ClrBits(TabEnt->Width); \
242#define SETVALUE(x) do { \
243 *pa++ = RunLength + (x); \
259#define SYNC_EOL(eoflab) do { \
262 NeedBits16(11,eoflab); \
263 if (GetBits(11) == 0) \
269 NeedBits8(8,eoflab); \
274 while (GetBits(1) == 0) \
285#define CLEANUP_RUNS() do { \
289 badlength(a0, lastx); \
290 while (a0 > lastx && pa > thisrun) \
295 if ((pa-thisrun)&1) \
297 SETVALUE(lastx - a0); \
298 } else if (a0 > lastx) { \
317#define EXPAND1D(eoflab) do { \
320 LOOKUP16(12, TIFFFaxWhiteTable, eof1d); \
321 switch (TabEnt->State) { \
326 SETVALUE(TabEnt->Param); \
330 a0 += TabEnt->Param; \
331 RunLength += TabEnt->Param; \
334 unexpected("WhiteTable", a0); \
342 LOOKUP16(13, TIFFFaxBlackTable, eof1d); \
343 switch (TabEnt->State) { \
348 SETVALUE(TabEnt->Param); \
352 a0 += TabEnt->Param; \
353 RunLength += TabEnt->Param; \
356 unexpected("BlackTable", a0); \
363 if( *(pa-1) == 0 && *(pa-2) == 0 ) \
378#define CHECK_b1 do { \
379 if (pa != thisrun) while (b1 <= a0 && b1 < lastx) { \
380 b1 += pb[0] + pb[1]; \
388#define EXPAND2D(eoflab) do { \
389 while (a0 < lastx) { \
390 LOOKUP8(7, TIFFFaxMainTable, eof2d); \
391 switch (TabEnt->State) { \
395 RunLength += b1 - a0; \
400 if ((pa-thisrun)&1) { \
402 LOOKUP16(13, TIFFFaxBlackTable, eof2d); \
403 switch (TabEnt->State) { \
405 SETVALUE(TabEnt->Param); \
409 a0 += TabEnt->Param; \
410 RunLength += TabEnt->Param; \
418 LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \
419 switch (TabEnt->State) { \
421 SETVALUE(TabEnt->Param); \
425 a0 += TabEnt->Param; \
426 RunLength += TabEnt->Param; \
435 LOOKUP16(12, TIFFFaxWhiteTable, eof2d); \
436 switch (TabEnt->State) { \
438 SETVALUE(TabEnt->Param); \
442 a0 += TabEnt->Param; \
443 RunLength += TabEnt->Param; \
451 LOOKUP16(13, TIFFFaxBlackTable, eof2d); \
452 switch (TabEnt->State) { \
454 SETVALUE(TabEnt->Param); \
458 a0 += TabEnt->Param; \
459 RunLength += TabEnt->Param; \
476 SETVALUE(b1 - a0 + TabEnt->Param); \
481 if (b1 <= (int) (a0 + TabEnt->Param)) { \
482 if (b1 < (int) (a0 + TabEnt->Param) || pa != thisrun) { \
483 unexpected("VL", a0); \
487 SETVALUE(b1 - a0 - TabEnt->Param); \
491 *pa++ = lastx - a0; \
495 *pa++ = lastx - a0; \
496 NeedBits8(4,eof2d); \
498 unexpected("EOL", a0); \
504 unexpected("MainTable", a0); \
507 unexpected("BlackTable", a0); \
510 unexpected("WhiteTable", a0); \
519 if (RunLength + a0 < lastx) { \
521 NeedBits8(1,eof2d); \
const TIFFFaxTabEnt TIFFFaxMainTable[]
void _TIFFFax3fillruns(unsigned char *, uint32 *, uint32 *, uint32)
void(* TIFFFaxFillFunc)(unsigned char *, uint32 *, uint32 *, uint32)
const TIFFFaxTabEnt TIFFFaxBlackTable[]
const TIFFFaxTabEnt TIFFFaxWhiteTable[]