Back to index

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

#include <Stream.h>

Collaboration diagram for StreamPredictor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 StreamPredictor (Stream *strA, int predictorA, int widthA, int nCompsA, int nBitsA)
 ~StreamPredictor ()
int lookChar ()
int getChar ()

Private Member Functions

GBool getNextLine ()

Private Attributes

Streamstr
int predictor
int width
int nComps
int nBits
int nVals
int pixBytes
int rowBytes
GucharpredLine
int predIdx

Detailed Description

Definition at line 226 of file Stream.h.


Constructor & Destructor Documentation

StreamPredictor::StreamPredictor ( Stream strA,
int  predictorA,
int  widthA,
int  nCompsA,
int  nBitsA 
)

Definition at line 408 of file Stream.cc.

                                                                  {
  str = strA;
  predictor = predictorA;
  width = widthA;
  nComps = nCompsA;
  nBits = nBitsA;

  nVals = width * nComps;
  pixBytes = (nComps * nBits + 7) >> 3;
  rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes;
  predLine = (Guchar *)gmalloc(rowBytes);
  memset(predLine, 0, rowBytes);
  predIdx = rowBytes;
}

Here is the call graph for this function:

Definition at line 424 of file Stream.cc.

                                  {
  gfree(predLine);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 437 of file Stream.cc.

                             {
  if (predIdx >= rowBytes) {
    if (!getNextLine()) {
      return EOF;
    }
  }
  return predLine[predIdx++];
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 446 of file Stream.cc.

                                   {
  int curPred;
  Guchar upLeftBuf[4];
  int left, up, upLeft, p, pa, pb, pc;
  int c;
  Gulong inBuf, outBuf, bitMask;
  int inBits, outBits;
  int i, j, k;

  // get PNG optimum predictor number
  if (predictor >= 10) {
    if ((curPred = str->getRawChar()) == EOF) {
      return gFalse;
    }
    curPred += 10;
  } else {
    curPred = predictor;
  }

  // read the raw line, apply PNG (byte) predictor
  upLeftBuf[0] = upLeftBuf[1] = upLeftBuf[2] = upLeftBuf[3] = 0;
  for (i = pixBytes; i < rowBytes; ++i) {
    upLeftBuf[3] = upLeftBuf[2];
    upLeftBuf[2] = upLeftBuf[1];
    upLeftBuf[1] = upLeftBuf[0];
    upLeftBuf[0] = predLine[i];
    if ((c = str->getRawChar()) == EOF) {
      return gFalse;
    }
    switch (curPred) {
    case 11:                // PNG sub
      predLine[i] = predLine[i - pixBytes] + (Guchar)c;
      break;
    case 12:                // PNG up
      predLine[i] = predLine[i] + (Guchar)c;
      break;
    case 13:                // PNG average
      predLine[i] = ((predLine[i - pixBytes] + predLine[i]) >> 1) +
                   (Guchar)c;
      break;
    case 14:                // PNG Paeth
      left = predLine[i - pixBytes];
      up = predLine[i];
      upLeft = upLeftBuf[pixBytes];
      p = left + up - upLeft;
      if ((pa = p - left) < 0)
       pa = -pa;
      if ((pb = p - up) < 0)
       pb = -pb;
      if ((pc = p - upLeft) < 0)
       pc = -pc;
      if (pa <= pb && pa <= pc)
       predLine[i] = left + (Guchar)c;
      else if (pb <= pc)
       predLine[i] = up + (Guchar)c;
      else
       predLine[i] = upLeft + (Guchar)c;
      break;
    case 10:                // PNG none
    default:                // no predictor or TIFF predictor
      predLine[i] = (Guchar)c;
      break;
    }
  }

  // apply TIFF (component) predictor
  if (predictor == 2) {
    if (nBits == 1) {
      inBuf = predLine[pixBytes - 1];
      for (i = pixBytes; i < rowBytes; i += 8) {
       // 1-bit add is just xor
       inBuf = (inBuf << 8) | predLine[i];
       predLine[i] ^= inBuf >> nComps;
      }
    } else if (nBits == 8) {
      for (i = pixBytes; i < rowBytes; ++i) {
       predLine[i] += predLine[i - nComps];
      }
    } else {
      upLeftBuf[0] = upLeftBuf[1] = upLeftBuf[2] = upLeftBuf[3] = 0;
      bitMask = (1 << nBits) - 1;
      inBuf = outBuf = 0;
      inBits = outBits = 0;
      j = k = pixBytes;
      for (i = 0; i < nVals; ++i) {
       if (inBits < nBits) {
         inBuf = (inBuf << 8) | (predLine[j++] & 0xff);
         inBits += 8;
       }
       upLeftBuf[3] = upLeftBuf[2];
       upLeftBuf[2] = upLeftBuf[1];
       upLeftBuf[1] = upLeftBuf[0];
       upLeftBuf[0] = (upLeftBuf[nComps] +
                     (inBuf >> (inBits - nBits))) & bitMask;
       outBuf = (outBuf << nBits) | upLeftBuf[0];
       inBits -= nBits;
       outBits += nBits;
       if (outBits > 8) {
         predLine[k++] = (Guchar)(outBuf >> (outBits - 8));
       }
      }
      if (outBits > 0) {
       predLine[k++] = (Guchar)(outBuf << (8 - outBits));
      }
    }
  }

  // reset to start of line
  predIdx = pixBytes;

  return gTrue;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 428 of file Stream.cc.

                              {
  if (predIdx >= rowBytes) {
    if (!getNextLine()) {
      return EOF;
    }
  }
  return predLine[predIdx];
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 247 of file Stream.h.

Definition at line 246 of file Stream.h.

Definition at line 248 of file Stream.h.

Definition at line 249 of file Stream.h.

Definition at line 244 of file Stream.h.

Definition at line 252 of file Stream.h.

Definition at line 251 of file Stream.h.

Definition at line 250 of file Stream.h.

Definition at line 243 of file Stream.h.

Definition at line 245 of file Stream.h.


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