Back to index

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

#include <Stream.h>

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

List of all members.

Public Member Functions

 LZWStream (Stream *strA, int predictor, int columns, int colors, int bits, int earlyA)
virtual ~LZWStream ()
virtual StreamKind getKind ()
virtual void reset ()
virtual int getChar ()
virtual int lookChar ()
virtual int getRawChar ()
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 char * getLine (char *buf, int size)
virtual GBool isEncoder ()
StreamaddFilters (Object *dict)

Protected Attributes

Streamstr

Private Member Functions

GBool processNextCode ()
void clearTable ()
int getCode ()

Private Attributes

StreamPredictorpred
int early
GBool eof
int inputBuf
int inputBits
struct {
int length
int head
Guchar tail
table [4097]
int nextCode
int nextBits
int prevCode
int newChar
Guchar seqBuf [4097]
int seqLength
int seqIndex
GBool first

Detailed Description

Definition at line 420 of file Stream.h.


Constructor & Destructor Documentation

LZWStream::LZWStream ( Stream strA,
int  predictor,
int  columns,
int  colors,
int  bits,
int  earlyA 
)

Definition at line 1010 of file Stream.cc.

                                        :
    FilterStream(strA) {
  if (predictor != 1) {
    pred = new StreamPredictor(this, predictor, columns, colors, bits);
  } else {
    pred = NULL;
  }
  early = earlyA;
  eof = gFalse;
  inputBits = 0;
  clearTable();
}

Here is the call graph for this function:

LZWStream::~LZWStream ( ) [virtual]

Definition at line 1024 of file Stream.cc.

                      {
  if (pred) {
    delete pred;
  }
  delete str;
}

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 LZWStream::clearTable ( ) [private]

Definition at line 1149 of file Stream.cc.

                           {
  nextCode = 258;
  nextBits = 9;
  seqIndex = seqLength = 0;
  first = gTrue;
}

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; }
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:

int LZWStream::getChar ( ) [virtual]

Implements Stream.

Definition at line 1031 of file Stream.cc.

                       {
  if (pred) {
    return pred->getChar();
  }
  if (eof) {
    return EOF;
  }
  if (seqIndex >= seqLength) {
    if (!processNextCode()) {
      return EOF;
    }
  }
  return seqBuf[seqIndex++];
}

Here is the call graph for this function:

int LZWStream::getCode ( ) [private]

Definition at line 1156 of file Stream.cc.

                       {
  int c;
  int code;

  while (inputBits < nextBits) {
    if ((c = str->getChar()) == EOF)
      return EOF;
    inputBuf = (inputBuf << 8) | (c & 0xff);
    inputBits += 8;
  }
  code = (inputBuf >> (inputBits - nextBits)) & ((1 << nextBits) - 1);
  inputBits -= nextBits;
  return code;
}

Here is the call graph for this function:

Here is the caller 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 LZWStream::getKind ( ) [inline, virtual]

Implements Stream.

Definition at line 426 of file Stream.h.

{ return strLZW; }
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 * LZWStream::getPSFilter ( int  psLevel,
char *  indent 
) [virtual]

Reimplemented from Stream.

Definition at line 1171 of file Stream.cc.

                                                         {
  GString *s;

  if (psLevel < 2 || pred) {
    return NULL;
  }
  if (!(s = str->getPSFilter(psLevel, indent))) {
    return NULL;
  }
  s->append(indent)->append("/LZWDecode filter\n");
  return s;
}

Here is the call graph for this function:

int LZWStream::getRawChar ( ) [virtual]

Reimplemented from Stream.

Definition at line 1061 of file Stream.cc.

                          {
  if (eof) {
    return EOF;
  }
  if (seqIndex >= seqLength) {
    if (!processNextCode()) {
      return EOF;
    }
  }
  return seqBuf[seqIndex++];
}

Here is the call 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 LZWStream::isBinary ( GBool  last = gTrue) [virtual]

Implements Stream.

Definition at line 1184 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:

int LZWStream::lookChar ( ) [virtual]

Implements Stream.

Definition at line 1046 of file Stream.cc.

                        {
  if (pred) {
    return pred->lookChar();
  }
  if (eof) {
    return EOF;
  }
  if (seqIndex >= seqLength) {
    if (!processNextCode()) {
      return EOF;
    }
  }
  return seqBuf[seqIndex];
}

Here is the call graph for this function:

Definition at line 1080 of file Stream.cc.

                                 {
  int code;
  int nextLength;
  int i, j;

  // check for EOF
  if (eof) {
    return gFalse;
  }

  // check for eod and clear-table codes
 start:
  code = getCode();
  if (code == EOF || code == 257) {
    eof = gTrue;
    return gFalse;
  }
  if (code == 256) {
    clearTable();
    goto start;
  }
  if (nextCode >= 4097) {
    error(getPos(), "Bad LZW stream - expected clear-table code");
    clearTable();
  }

  // process the next code
  nextLength = seqLength + 1;
  if (code < 256) {
    seqBuf[0] = code;
    seqLength = 1;
  } else if (code < nextCode) {
    seqLength = table[code].length;
    for (i = seqLength - 1, j = code; i > 0; --i) {
      seqBuf[i] = table[j].tail;
      j = table[j].head;
    }
    seqBuf[0] = j;
  } else if (code == nextCode) {
    seqBuf[seqLength] = newChar;
    ++seqLength;
  } else {
    error(getPos(), "Bad LZW stream - unexpected code");
    eof = gTrue;
    return gFalse;
  }
  newChar = seqBuf[0];
  if (first) {
    first = gFalse;
  } else {
    table[nextCode].length = nextLength;
    table[nextCode].head = prevCode;
    table[nextCode].tail = newChar;
    ++nextCode;
    if (nextCode + early == 512)
      nextBits = 10;
    else if (nextCode + early == 1024)
      nextBits = 11;
    else if (nextCode + early == 2048)
      nextBits = 12;
  }
  prevCode = code;

  // reset buffer
  seqIndex = 0;

  return gTrue;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void LZWStream::reset ( ) [virtual]

Implements Stream.

Definition at line 1073 of file Stream.cc.

                      {
  str->reset();
  eof = gFalse;
  inputBits = 0;
  clearTable();
}

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

int LZWStream::early [private]

Definition at line 437 of file Stream.h.

GBool LZWStream::eof [private]

Definition at line 438 of file Stream.h.

Definition at line 453 of file Stream.h.

Definition at line 440 of file Stream.h.

Definition at line 439 of file Stream.h.

Definition at line 449 of file Stream.h.

Definition at line 447 of file Stream.h.

Definition at line 446 of file Stream.h.

Definition at line 436 of file Stream.h.

Definition at line 448 of file Stream.h.

Guchar LZWStream::seqBuf[4097] [private]

Definition at line 450 of file Stream.h.

Definition at line 452 of file Stream.h.

Definition at line 451 of file Stream.h.

Stream* FilterStream::str [protected, inherited]

Definition at line 180 of file Stream.h.

struct { ... } LZWStream::table[4097] [private]

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