⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stream.h

📁 source code: Covert TXT to PDF
💻 H
📖 第 1 页 / 共 2 页
字号:
//========================================================================//// Stream.h//// Copyright 1996-2002 Glyph & Cog, LLC////========================================================================#ifndef STREAM_H#define STREAM_H#include <aconf.h>#ifdef USE_GCC_PRAGMAS#pragma interface#endif#include <stdio.h>#include "gtypes.h"#include "Object.h"#ifndef NO_DECRYPTIONclass Decrypt;#endifclass BaseStream;//------------------------------------------------------------------------enum StreamKind {  strFile,  strASCIIHex,  strASCII85,  strLZW,  strRunLength,  strCCITTFax,  strDCT,  strFlate,  strJBIG2,  strWeird			// internal-use stream types};//------------------------------------------------------------------------// Stream (base class)//------------------------------------------------------------------------class Stream {public:  // Constructor.  Stream();  // Destructor.  virtual ~Stream();  // Reference counting.  int incRef() { return ++ref; }  int decRef() { return --ref; }  // Get kind of stream.  virtual StreamKind getKind() = 0;  // Reset stream to beginning.  virtual void reset() = 0;  // Close down the stream.  virtual void close();  // Get next char from stream.  virtual int getChar() = 0;  // Peek at next char in stream.  virtual int lookChar() = 0;  // Get next char from stream without using the predictor.  // This is only used by StreamPredictor.  virtual int getRawChar();  // Get next line from stream.  virtual char *getLine(char *buf, int size);  // Get current position in file.  virtual int getPos() = 0;  // Go to a position in the stream.  If <dir> is negative, the  // position is from the end of the file; otherwise the position is  // from the start of the file.  virtual void setPos(Guint pos, int dir = 0) = 0;  // Get PostScript command for the filter(s).  virtual GString *getPSFilter(char *indent);  // Does this stream type potentially contain non-printable chars?  virtual GBool isBinary(GBool last = gTrue) = 0;  // Get the BaseStream or EmbedStream of this stream.  virtual BaseStream *getBaseStream() = 0;  // Get the dictionary associated with this stream.  virtual Dict *getDict() = 0;  // Is this an encoding filter?  virtual GBool isEncoder() { return gFalse; }  // Add filters to this stream according to the parameters in <dict>.  // Returns the new stream.  Stream *addFilters(Object *dict);private:  Stream *makeFilter(char *name, Stream *str, Object *params);  int ref;			// reference count};//------------------------------------------------------------------------// BaseStream//// This is the base class for all streams that read directly from a file.//------------------------------------------------------------------------class BaseStream: public Stream {public:  BaseStream(Object *dictA);  virtual ~BaseStream();  virtual Stream *makeSubStream(Guint start, GBool limited,				Guint length, Object *dict) = 0;  virtual void setPos(Guint pos, int dir = 0) = 0;  virtual BaseStream *getBaseStream() { return this; }  virtual Dict *getDict() { return dict.getDict(); }  // Get/set position of first byte of stream within the file.  virtual Guint getStart() = 0;  virtual void moveStart(int delta) = 0;#ifndef NO_DECRYPTION  // Set decryption for this stream.  virtual void doDecryption(Guchar *fileKey, int keyLength,			    int objNum, int objGen);#endif#ifndef NO_DECRYPTIONprotected:  Decrypt *decrypt;#endifprivate:  Object dict;};//------------------------------------------------------------------------// FilterStream//// This is the base class for all streams that filter another stream.//------------------------------------------------------------------------class FilterStream: public Stream {public:  FilterStream(Stream *strA);  virtual ~FilterStream();  virtual void close();  virtual int getPos() { return str->getPos(); }  virtual void setPos(Guint pos, int dir = 0);  virtual BaseStream *getBaseStream() { return str->getBaseStream(); }  virtual Dict *getDict() { return str->getDict(); }protected:  Stream *str;};//------------------------------------------------------------------------// ImageStream//------------------------------------------------------------------------class ImageStream {public:  // Create an image stream object for an image with the specified  // parameters.  Note that these are the actual image parameters,  // which may be different from the predictor parameters.  ImageStream(Stream *strA, int widthA, int nCompsA, int nBitsA);  ~ImageStream();  // Reset the stream.  void reset();  // Gets the next pixel from the stream.  <pix> should be able to hold  // at least nComps elements.  Returns false at end of file.  GBool getPixel(Guchar *pix);  // Returns a pointer to the next line of pixels.  Returns NULL at  // end of file.  Guchar *getLine();  // Skip an entire line from the image.  void skipLine();private:  Stream *str;			// base stream  int width;			// pixels per line  int nComps;			// components per pixel  int nBits;			// bits per component  int nVals;			// components per line  Guchar *imgLine;		// line buffer  int imgIdx;			// current index in imgLine};//------------------------------------------------------------------------// StreamPredictor//------------------------------------------------------------------------class StreamPredictor {public:  // Create a predictor object.  Note that the parameters are for the  // predictor, and may not match the actual image parameters.  StreamPredictor(Stream *strA, int predictorA,		  int widthA, int nCompsA, int nBitsA);  ~StreamPredictor();  int lookChar();  int getChar();private:  GBool getNextLine();  Stream *str;			// base stream  int predictor;		// predictor  int width;			// pixels per line  int nComps;			// components per pixel  int nBits;			// bits per component  int nVals;			// components per line  int pixBytes;			// bytes per pixel  int rowBytes;			// bytes per line  Guchar *predLine;		// line buffer  int predIdx;			// current index in predLine};//------------------------------------------------------------------------// FileStream//------------------------------------------------------------------------#define fileStreamBufSize 256class FileStream: public BaseStream {public:  FileStream(FILE *fA, Guint startA, GBool limitedA,	     Guint lengthA, Object *dictA);  virtual ~FileStream();  virtual Stream *makeSubStream(Guint startA, GBool limitedA,				Guint lengthA, Object *dictA);  virtual StreamKind getKind() { return strFile; }  virtual void reset();  virtual void close();  virtual int getChar()    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }  virtual int lookChar()    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }  virtual int getPos() { return bufPos + (bufPtr - buf); }  virtual void setPos(Guint pos, int dir = 0);  virtual GBool isBinary(GBool last = gTrue) { return last; }  virtual Guint getStart() { return start; }  virtual void moveStart(int delta);private:  GBool fillBuf();  FILE *f;  Guint start;  GBool limited;  Guint length;  char buf[fileStreamBufSize];  char *bufPtr;  char *bufEnd;  Guint bufPos;  int savePos;  GBool saved;};//------------------------------------------------------------------------// MemStream//------------------------------------------------------------------------class MemStream: public BaseStream {public:  MemStream(char *bufA, Guint lengthA, Object *dictA);  virtual ~MemStream();  virtual Stream *makeSubStream(Guint start, GBool limited,				Guint lengthA, Object *dictA);  virtual StreamKind getKind() { return strWeird; }  virtual void reset();  virtual void close();  virtual int getChar()    { return (bufPtr < bufEnd) ? (*bufPtr++ & 0xff) : EOF; }  virtual int lookChar()    { return (bufPtr < bufEnd) ? (*bufPtr & 0xff) : EOF; }  virtual int getPos() { return bufPtr - buf; }  virtual void setPos(Guint pos, int dir = 0);  virtual GBool isBinary(GBool last = gTrue) { return last; }  virtual Guint getStart() { return 0; }  virtual void moveStart(int delta);#ifndef NO_DECRYPTION  virtual void doDecryption(Guchar *fileKey, int keyLength,			    int objNum, int objGen);#endifprivate:  char *buf;  Guint length;  GBool needFree;  char *bufEnd;  char *bufPtr;};//------------------------------------------------------------------------// EmbedStream//// This is a special stream type used for embedded streams (inline// images).  It reads directly from the base stream -- after the// EmbedStream is deleted, reads from the base stream will proceed where// the BaseStream left off.  Note that this is very different behavior// that creating a new FileStream (using makeSubStream).//------------------------------------------------------------------------class EmbedStream: public BaseStream {public:  EmbedStream(Stream *strA, Object *dictA);  virtual ~EmbedStream();  virtual Stream *makeSubStream(Guint start, GBool limited,				Guint length, Object *dictA);  virtual StreamKind getKind() { return str->getKind(); }  virtual void reset() {}  virtual int getChar() { return str->getChar(); }  virtual int lookChar() { return str->lookChar(); }  virtual int getPos() { return str->getPos(); }  virtual void setPos(Guint pos, int dir = 0);  virtual GBool isBinary(GBool last = gTrue) { return last; }  virtual Guint getStart();  virtual void moveStart(int delta);private:  Stream *str;};//------------------------------------------------------------------------// ASCIIHexStream//------------------------------------------------------------------------class ASCIIHexStream: public FilterStream {public:  ASCIIHexStream(Stream *strA);  virtual ~ASCIIHexStream();  virtual StreamKind getKind() { return strASCIIHex; }  virtual void reset();  virtual int getChar()    { int c = lookChar(); buf = EOF; return c; }  virtual int lookChar();  virtual GString *getPSFilter(char *indent);  virtual GBool isBinary(GBool last = gTrue);private:  int buf;  GBool eof;};//------------------------------------------------------------------------// ASCII85Stream//------------------------------------------------------------------------class ASCII85Stream: public FilterStream {public:  ASCII85Stream(Stream *strA);  virtual ~ASCII85Stream();  virtual StreamKind getKind() { return strASCII85; }  virtual void reset();  virtual int getChar()    { int ch = lookChar(); ++index; return ch; }  virtual int lookChar();  virtual GString *getPSFilter(char *indent);  virtual GBool isBinary(GBool last = gTrue);private:  int c[5];  int b[4];  int index, n;  GBool eof;};//------------------------------------------------------------------------// LZWStream//------------------------------------------------------------------------class LZWStream: public FilterStream {public:  LZWStream(Stream *strA, int predictor, int columns, int colors,	    int bits, int earlyA);  virtual ~LZWStream();  virtual StreamKind getKind() { return strLZW; }  virtual void reset();  virtual int getChar();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -