Back to index

tetex-bin  3.0
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
CCITTFaxStream Class Reference

#include <Stream.h>

Inheritance diagram for CCITTFaxStream:
Inheritance graph
[legend]
Collaboration diagram for CCITTFaxStream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CCITTFaxStream (Stream *strA, int encodingA, GBool endOfLineA, GBool byteAlignA, int columnsA, int rowsA, GBool endOfBlockA, GBool blackA)
virtual ~CCITTFaxStream ()
virtual StreamKind getKind ()
virtual void reset ()
virtual int getChar ()
virtual int lookChar ()
virtual GStringgetPSFilter (int psLevel, char *indent)
virtual GBool isBinary (GBool last=gTrue)
virtual void close ()
virtual int getPos ()
virtual void setPos (Guint pos, int dir=0)
virtual BaseStreamgetBaseStream ()
virtual DictgetDict ()
virtual void ignoreLength ()
int incRef ()
int decRef ()
virtual int getRawChar ()
virtual char * getLine (char *buf, int size)
virtual GBool isEncoder ()
StreamaddFilters (Object *dict)

Protected Attributes

Streamstr

Private Member Functions

short getTwoDimCode ()
short getWhiteCode ()
short getBlackCode ()
short lookBits (int n)
void eatBits (int n)

Private Attributes

int encoding
GBool endOfLine
GBool byteAlign
int columns
int rows
GBool endOfBlock
GBool black
GBool eof
GBool nextLine2D
int row
int inputBuf
int inputBits
shortrefLine
int b1
shortcodingLine
int a0
int outputBits
int buf

Detailed Description

Definition at line 494 of file Stream.h.


Constructor & Destructor Documentation

CCITTFaxStream::CCITTFaxStream ( Stream strA,
int  encodingA,
GBool  endOfLineA,
GBool  byteAlignA,
int  columnsA,
int  rowsA,
GBool  endOfBlockA,
GBool  blackA 
)

Definition at line 1255 of file Stream.cc.

                                                            :
    FilterStream(strA) {
  encoding = encodingA;
  endOfLine = endOfLineA;
  byteAlign = byteAlignA;
  columns = columnsA;
  rows = rowsA;
  endOfBlock = endOfBlockA;
  black = blackA;
  refLine = (short *)gmalloc((columns + 3) * sizeof(short));
  codingLine = (short *)gmalloc((columns + 2) * sizeof(short));

  eof = gFalse;
  row = 0;
  nextLine2D = encoding < 0;
  inputBits = 0;
  codingLine[0] = 0;
  codingLine[1] = refLine[2] = columns;
  a0 = 1;

  buf = EOF;
}

Here is the call graph for this function:

Definition at line 1280 of file Stream.cc.

                                {
  delete str;
  gfree(refLine);
  gfree(codingLine);
}

Here is the call graph for this function:


Member Function Documentation

Stream * Stream::addFilters ( Object dict) [inherited]

Definition at line 92 of file Stream.cc.

                                       {
  Object obj, obj2;
  Object params, params2;
  Stream *str;
  int i;

  str = this;
  dict->dictLookup("Filter", &obj);
  if (obj.isNull()) {
    obj.free();
    dict->dictLookup("F", &obj);
  }
  dict->dictLookup("DecodeParms", &params);
  if (params.isNull()) {
    params.free();
    dict->dictLookup("DP", &params);
  }
  if (obj.isName()) {
    str = makeFilter(obj.getName(), str, &params);
  } else if (obj.isArray()) {
    for (i = 0; i < obj.arrayGetLength(); ++i) {
      obj.arrayGet(i, &obj2);
      if (params.isArray())
       params.arrayGet(i, &params2);
      else
       params2.initNull();
      if (obj2.isName()) {
       str = makeFilter(obj2.getName(), str, &params2);
      } else {
       error(getPos(), "Bad filter name");
       str = new EOFStream(str);
      }
      obj2.free();
      params2.free();
    }
  } else if (!obj.isNull()) {
    error(getPos(), "Bad 'Filter' attribute in stream");
  }
  obj.free();
  params.free();

  return str;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FilterStream::close ( ) [virtual, inherited]

Reimplemented from Stream.

Definition at line 306 of file Stream.cc.

                         {
  str->close();
}

Here is the call graph for this function:

int Stream::decRef ( ) [inline, inherited]

Definition at line 58 of file Stream.h.

{ return --ref; }
void CCITTFaxStream::eatBits ( int  n) [inline, private]

Definition at line 534 of file Stream.h.

{ inputBits -= n; }

Here is the caller graph for this function:

virtual BaseStream* FilterStream::getBaseStream ( ) [inline, virtual, inherited]

Implements Stream.

Definition at line 174 of file Stream.h.

{ return str->getBaseStream(); }

Here is the call graph for this function:

Definition at line 1665 of file Stream.cc.

                                   {
  short code;
  CCITTCode *p;
  int n;

  code = 0; // make gcc happy
  if (endOfBlock) {
    code = lookBits(13);
    if ((code >> 7) == 0) {
      p = &blackTab1[code];
    } else if ((code >> 9) == 0) {
      p = &blackTab2[(code >> 1) - 64];
    } else {
      p = &blackTab3[code >> 7];
    }
    if (p->bits > 0) {
      eatBits(p->bits);
      return p->n;
    }
  } else {
    for (n = 2; n <= 6; ++n) {
      code = lookBits(n);
      if (n < 6) {
       code <<= 6 - n;
      }
      p = &blackTab3[code];
      if (p->bits == n) {
       eatBits(n);
       return p->n;
      }
    }
    for (n = 7; n <= 12; ++n) {
      code = lookBits(n);
      if (n < 12) {
       code <<= 12 - n;
      }
      if (code >= 64) {
       p = &blackTab2[code - 64];
       if (p->bits == n) {
         eatBits(n);
         return p->n;
       }
      }
    }
    for (n = 10; n <= 13; ++n) {
      code = lookBits(n);
      if (n < 13) {
       code <<= 13 - n;
      }
      p = &blackTab1[code];
      if (p->bits == n) {
       eatBits(n);
       return p->n;
      }
    }
  }
  error(getPos(), "Bad black code (%04x) in CCITTFax stream", code);
  // eat a bit and return a positive number so that the caller doesn't
  // go into an infinite loop
  eatBits(1);
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual int CCITTFaxStream::getChar ( ) [inline, virtual]

Implements Stream.

Definition at line 503 of file Stream.h.

    { int c = lookChar(); buf = EOF; return c; }

Here is the call graph for this function:

virtual Dict* FilterStream::getDict ( ) [inline, virtual, inherited]

Implements Stream.

Definition at line 175 of file Stream.h.

{ return str->getDict(); }

Here is the call graph for this function:

virtual StreamKind CCITTFaxStream::getKind ( ) [inline, virtual]

Implements Stream.

Definition at line 501 of file Stream.h.

{ return strCCITTFax; }
char * Stream::getLine ( char *  buf,
int  size 
) [virtual, inherited]

Definition at line 67 of file Stream.cc.

                                         {
  int i;
  int c;

  if (lookChar() == EOF)
    return NULL;
  for (i = 0; i < size - 1; ++i) {
    c = getChar();
    if (c == EOF || c == '\n')
      break;
    if (c == '\r') {
      if ((c = lookChar()) == '\n')
       getChar();
      break;
    }
    buf[i] = c;
  }
  buf[i] = '\0';
  return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual int FilterStream::getPos ( ) [inline, virtual, inherited]

Implements Stream.

Definition at line 172 of file Stream.h.

{ return str->getPos(); }

Here is the call graph for this function:

GString * CCITTFaxStream::getPSFilter ( int  psLevel,
char *  indent 
) [virtual]

Reimplemented from Stream.

Definition at line 1748 of file Stream.cc.

                                                              {
  GString *s;
  char s1[50];

  if (psLevel < 2) {
    return NULL;
  }
  if (!(s = str->getPSFilter(psLevel, indent))) {
    return NULL;
  }
  s->append(indent)->append("<< ");
  if (encoding != 0) {
    sprintf(s1, "/K %d ", encoding);
    s->append(s1);
  }
  if (endOfLine) {
    s->append("/EndOfLine true ");
  }
  if (byteAlign) {
    s->append("/EncodedByteAlign true ");
  }
  sprintf(s1, "/Columns %d ", columns);
  s->append(s1);
  if (rows != 0) {
    sprintf(s1, "/Rows %d ", rows);
    s->append(s1);
  }
  if (!endOfBlock) {
    s->append("/EndOfBlock false ");
  }
  if (black) {
    s->append("/BlackIs1 true ");
  }
  s->append(">> /CCITTFaxDecode filter\n");
  return s;
}

Here is the call graph for this function:

int Stream::getRawChar ( ) [virtual, inherited]

Reimplemented in FlateStream, and LZWStream.

Definition at line 62 of file Stream.cc.

                       {
  error(-1, "Internal: called getRawChar() on non-predictor stream");
  return EOF;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1587 of file Stream.cc.

                                    {
  short code;
  CCITTCode *p;
  int n;

  code = 0; // make gcc happy
  if (endOfBlock) {
    code = lookBits(7);
    p = &twoDimTab1[code];
    if (p->bits > 0) {
      eatBits(p->bits);
      return p->n;
    }
  } else {
    for (n = 1; n <= 7; ++n) {
      code = lookBits(n);
      if (n < 7) {
       code <<= 7 - n;
      }
      p = &twoDimTab1[code];
      if (p->bits == n) {
       eatBits(n);
       return p->n;
      }
    }
  }
  error(getPos(), "Bad two dim code (%04x) in CCITTFax stream", code);
  return EOF;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1617 of file Stream.cc.

                                   {
  short code;
  CCITTCode *p;
  int n;

  code = 0; // make gcc happy
  if (endOfBlock) {
    code = lookBits(12);
    if ((code >> 5) == 0) {
      p = &whiteTab1[code];
    } else {
      p = &whiteTab2[code >> 3];
    }
    if (p->bits > 0) {
      eatBits(p->bits);
      return p->n;
    }
  } else {
    for (n = 1; n <= 9; ++n) {
      code = lookBits(n);
      if (n < 9) {
       code <<= 9 - n;
      }
      p = &whiteTab2[code];
      if (p->bits == n) {
       eatBits(n);
       return p->n;
      }
    }
    for (n = 11; n <= 12; ++n) {
      code = lookBits(n);
      if (n < 12) {
       code <<= 12 - n;
      }
      p = &whiteTab1[code];
      if (p->bits == n) {
       eatBits(n);
       return p->n;
      }
    }
  }
  error(getPos(), "Bad white code (%04x) in CCITTFax stream", code);
  // eat a bit and return a positive number so that the caller doesn't
  // go into an infinite loop
  eatBits(1);
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void FilterStream::ignoreLength ( ) [inline, virtual, inherited]

Reimplemented from Stream.

Definition at line 176 of file Stream.h.

{ str->ignoreLength(); }

Here is the call graph for this function:

int Stream::incRef ( ) [inline, inherited]

Definition at line 57 of file Stream.h.

{ return ++ref; }
GBool CCITTFaxStream::isBinary ( GBool  last = gTrue) [virtual]

Implements Stream.

Definition at line 1785 of file Stream.cc.

                                         {
  return str->isBinary(gTrue);
}

Here is the call graph for this function:

virtual GBool Stream::isEncoder ( ) [inline, virtual, inherited]

Reimplemented in RunLengthEncoder, ASCII85Encoder, ASCIIHexEncoder, and FixedLengthEncoder.

Definition at line 103 of file Stream.h.

{ return gFalse; }

Here is the caller graph for this function:

Definition at line 1728 of file Stream.cc.

                                    {
  int c;

  while (inputBits < n) {
    if ((c = str->getChar()) == EOF) {
      if (inputBits == 0) {
       return EOF;
      }
      // near the end of the stream, the caller may ask for more bits
      // than are available, but there may still be a valid code in
      // however many bits are available -- we need to return correct
      // data in this case
      return (inputBuf << (n - inputBits)) & (0xffff >> (16 - n));
    }
    inputBuf = (inputBuf << 8) + c;
    inputBits += 8;
  }
  return (inputBuf >> (inputBits - n)) & (0xffff >> (16 - n));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements Stream.

Definition at line 1313 of file Stream.cc.

                             {
  short code1, code2, code3;
  int a0New;
  GBool err, gotEOL;
  int ret;
  int bits, i;

  // if at eof just return EOF
  if (eof && codingLine[a0] >= columns) {
    return EOF;
  }

  // read the next row
  err = gFalse;
  if (codingLine[a0] >= columns) {

    // 2-D encoding
    if (nextLine2D) {
      for (i = 0; codingLine[i] < columns; ++i)
       refLine[i] = codingLine[i];
      refLine[i] = refLine[i + 1] = columns;
      b1 = 1;
      a0New = codingLine[a0 = 0] = 0;
      do {
       code1 = getTwoDimCode();
       switch (code1) {
       case twoDimPass:
         if (refLine[b1] < columns) {
           a0New = refLine[b1 + 1];
           b1 += 2;
         }
         break;
       case twoDimHoriz:
         if ((a0 & 1) == 0) {
           code1 = code2 = 0;
           do {
             code1 += code3 = getWhiteCode();
           } while (code3 >= 64);
           do {
             code2 += code3 = getBlackCode();
           } while (code3 >= 64);
         } else {
           code1 = code2 = 0;
           do {
             code1 += code3 = getBlackCode();
           } while (code3 >= 64);
           do {
             code2 += code3 = getWhiteCode();
           } while (code3 >= 64);
         }
         if (code1 > 0 || code2 > 0) {
           codingLine[a0 + 1] = a0New + code1;
           ++a0;
           a0New = codingLine[a0 + 1] = codingLine[a0] + code2;
           ++a0;
           while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
             b1 += 2;
         }
         break;
       case twoDimVert0:
         a0New = codingLine[++a0] = refLine[b1];
         if (refLine[b1] < columns) {
           ++b1;
           while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
             b1 += 2;
         }
         break;
       case twoDimVertR1:
         a0New = codingLine[++a0] = refLine[b1] + 1;
         if (refLine[b1] < columns) {
           ++b1;
           while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
             b1 += 2;
         }
         break;
       case twoDimVertL1:
         a0New = codingLine[++a0] = refLine[b1] - 1;
         --b1;
         while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
           b1 += 2;
         break;
       case twoDimVertR2:
         a0New = codingLine[++a0] = refLine[b1] + 2;
         if (refLine[b1] < columns) {
           ++b1;
           while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
             b1 += 2;
         }
         break;
       case twoDimVertL2:
         a0New = codingLine[++a0] = refLine[b1] - 2;
         --b1;
         while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
           b1 += 2;
         break;
       case twoDimVertR3:
         a0New = codingLine[++a0] = refLine[b1] + 3;
         if (refLine[b1] < columns) {
           ++b1;
           while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
             b1 += 2;
         }
         break;
       case twoDimVertL3:
         a0New = codingLine[++a0] = refLine[b1] - 3;
         --b1;
         while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
           b1 += 2;
         break;
       case EOF:
         eof = gTrue;
         codingLine[a0 = 0] = columns;
         return EOF;
       default:
         error(getPos(), "Bad 2D code %04x in CCITTFax stream", code1);
         err = gTrue;
         break;
       }
      } while (codingLine[a0] < columns);

    // 1-D encoding
    } else {
      codingLine[a0 = 0] = 0;
      while (1) {
       code1 = 0;
       do {
         code1 += code3 = getWhiteCode();
       } while (code3 >= 64);
       codingLine[a0+1] = codingLine[a0] + code1;
       ++a0;
       if (codingLine[a0] >= columns)
         break;
       code2 = 0;
       do {
         code2 += code3 = getBlackCode();
       } while (code3 >= 64);
       codingLine[a0+1] = codingLine[a0] + code2;
       ++a0;
       if (codingLine[a0] >= columns)
         break;
      }
    }

    if (codingLine[a0] != columns) {
      error(getPos(), "CCITTFax row is wrong length (%d)", codingLine[a0]);
      // force the row to be the correct length
      while (codingLine[a0] > columns) {
       --a0;
      }
      codingLine[++a0] = columns;
      err = gTrue;
    }

    // byte-align the row
    if (byteAlign) {
      inputBits &= ~7;
    }

    // check for end-of-line marker, skipping over any extra zero bits
    gotEOL = gFalse;
    if (!endOfBlock && row == rows - 1) {
      eof = gTrue;
    } else {
      code1 = lookBits(12);
      while (code1 == 0) {
       eatBits(1);
       code1 = lookBits(12);
      }
      if (code1 == 0x001) {
       eatBits(12);
       gotEOL = gTrue;
      } else if (code1 == EOF) {
       eof = gTrue;
      }
    }

    // get 2D encoding tag
    if (!eof && encoding > 0) {
      nextLine2D = !lookBits(1);
      eatBits(1);
    }

    // check for end-of-block marker
    if (endOfBlock && gotEOL) {
      code1 = lookBits(12);
      if (code1 == 0x001) {
       eatBits(12);
       if (encoding > 0) {
         lookBits(1);
         eatBits(1);
       }
       if (encoding >= 0) {
         for (i = 0; i < 4; ++i) {
           code1 = lookBits(12);
           if (code1 != 0x001) {
             error(getPos(), "Bad RTC code in CCITTFax stream");
           }
           eatBits(12);
           if (encoding > 0) {
             lookBits(1);
             eatBits(1);
           }
         }
       }
       eof = gTrue;
      }

    // look for an end-of-line marker after an error -- we only do
    // this if we know the stream contains end-of-line markers because
    // the "just plow on" technique tends to work better otherwise
    } else if (err && endOfLine) {
      do {
       if (code1 == EOF) {
         eof = gTrue;
         return EOF;
       }
       eatBits(1);
       code1 = lookBits(13);
      } while ((code1 >> 1) != 0x001);
      eatBits(12); 
      if (encoding > 0) {
       eatBits(1);
       nextLine2D = !(code1 & 1);
      }
    }

    a0 = 0;
    outputBits = codingLine[1] - codingLine[0];
    if (outputBits == 0) {
      a0 = 1;
      outputBits = codingLine[2] - codingLine[1];
    }

    ++row;
  }

  // get a byte
  if (outputBits >= 8) {
    ret = ((a0 & 1) == 0) ? 0xff : 0x00;
    if ((outputBits -= 8) == 0) {
      ++a0;
      if (codingLine[a0] < columns) {
       outputBits = codingLine[a0 + 1] - codingLine[a0];
      }
    }
  } else {
    bits = 8;
    ret = 0;
    do {
      if (outputBits > bits) {
       i = bits;
       bits = 0;
       if ((a0 & 1) == 0) {
         ret |= 0xff >> (8 - i);
       }
       outputBits -= i;
      } else {
       i = outputBits;
       bits -= outputBits;
       if ((a0 & 1) == 0) {
         ret |= (0xff >> (8 - i)) << bits;
       }
       outputBits = 0;
       ++a0;
       if (codingLine[a0] < columns) {
         outputBits = codingLine[a0 + 1] - codingLine[a0];
       }
      }
    } while (bits > 0 && codingLine[a0] < columns);
  }
  buf = black ? (ret ^ 0xff) : ret;
  return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CCITTFaxStream::reset ( ) [virtual]

Implements Stream.

Definition at line 1286 of file Stream.cc.

                           {
  short code1;

  str->reset();
  eof = gFalse;
  row = 0;
  nextLine2D = encoding < 0;
  inputBits = 0;
  codingLine[0] = 0;
  codingLine[1] = refLine[2] = columns;
  a0 = 1;
  buf = EOF;

  // skip any initial zero bits and end-of-line marker, and get the 2D
  // encoding tag
  while ((code1 = lookBits(12)) == 0) {
    eatBits(1);
  }
  if (code1 == 0x001) {
    eatBits(12);
  }
  if (encoding > 0) {
    nextLine2D = !lookBits(1);
    eatBits(1);
  }
}

Here is the call graph for this function:

void FilterStream::setPos ( Guint  pos,
int  dir = 0 
) [virtual, inherited]

Implements Stream.

Definition at line 310 of file Stream.cc.

                                            {
  error(-1, "Internal: called setPos() on FilterStream");
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 526 of file Stream.h.

Definition at line 524 of file Stream.h.

Definition at line 517 of file Stream.h.

Definition at line 528 of file Stream.h.

Definition at line 513 of file Stream.h.

Definition at line 525 of file Stream.h.

Definition at line 514 of file Stream.h.

Definition at line 511 of file Stream.h.

Definition at line 516 of file Stream.h.

Definition at line 512 of file Stream.h.

Definition at line 518 of file Stream.h.

Definition at line 522 of file Stream.h.

Definition at line 521 of file Stream.h.

Definition at line 519 of file Stream.h.

Definition at line 527 of file Stream.h.

Definition at line 523 of file Stream.h.

Definition at line 520 of file Stream.h.

Definition at line 515 of file Stream.h.

Stream* FilterStream::str [protected, inherited]

Definition at line 180 of file Stream.h.


The documentation for this class was generated from the following files: