source: trunk/poppler/mypoppler/poppler/FlateStream.cc @ 2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 16 years ago

First import

File size: 2.4 KB
RevLine 
[2]1//========================================================================
2//
3// FlateStream.cc
4//
5// Copyright (C) 2005, Jeff Muizelaar
6//
7//========================================================================
8#include "FlateStream.h"
9FlateStream::FlateStream(Stream *strA, int predictor, int columns, int colors, int bits) :
10  FilterStream(strA)
11{
12  if (predictor != 1) {
13    pred = new StreamPredictor(this, predictor, columns, colors, bits);
14  } else {
15    pred = NULL;
16  }
17  out_pos = 0;
18  memset(&d_stream, 0, sizeof(d_stream));
19}
20
21FlateStream::~FlateStream() {
22  inflateEnd(&d_stream);
23  delete pred;
24  delete str;
25}
26
27void FlateStream::reset() {
28  //FIXME: what are the semantics of reset?
29  //i.e. how much intialization has to happen in the constructor?
30  str->reset();
31  memset(&d_stream, 0, sizeof(d_stream));
32  inflateInit(&d_stream);
33  d_stream.avail_in = 0;
34  status = Z_OK;
35  out_pos = 0;
36  out_buf_len = 0;
37}
38
39int FlateStream::getRawChar() {
40  if (fill_buffer())
41    return EOF;
42
43  return out_buf[out_pos++];
44}
45
46int FlateStream::getChar() {
47  if (pred)
48    return pred->getChar();
49  else
50    return getRawChar();
51}
52
53int FlateStream::lookChar() {
54  if (pred)
55    return pred->lookChar();
56
57  if (fill_buffer())
58    return EOF;
59
60  return out_buf[out_pos];
61}
62
63int FlateStream::fill_buffer() {
64  if (out_pos >= out_buf_len) {
65    if (status == Z_STREAM_END) {
66      return -1;
67    }
68    d_stream.avail_out = sizeof(out_buf);
69    d_stream.next_out = out_buf;
70    out_pos = 0;
71    /* buffer is empty so we need to fill it */
72    if (d_stream.avail_in == 0) {
73      int c;
74      /* read from the source stream */
75      while (d_stream.avail_in < sizeof(in_buf) && (c = str->getChar()) != EOF) {
76        in_buf[d_stream.avail_in++] = c;
77      }
78      d_stream.next_in = in_buf;
79    }
80    while (d_stream.avail_out && d_stream.avail_in && (status == Z_OK || status == Z_BUF_ERROR)) {
81      status = inflate(&d_stream, Z_SYNC_FLUSH);
82    }
83    out_buf_len = sizeof(out_buf) - d_stream.avail_out;
84    if (status != Z_OK && status != Z_STREAM_END)
85      return -1;
86    if (!out_buf_len)
87      return -1;
88  }
89
90  return 0;
91}
92
93GooString *FlateStream::getPSFilter(int psLevel, char *indent) {
94  GooString *s;
95
96  if (psLevel < 3 || pred) {
97    return NULL;
98  }
99  if (!(s = str->getPSFilter(psLevel, indent))) {
100    return NULL;
101  }
102  s->append(indent)->append("<< >> /FlateDecode filter\n");
103  return s;
104}
105
106GBool FlateStream::isBinary(GBool last) {
107  return str->isBinary(gTrue);
108}
Note: See TracBrowser for help on using the repository browser.