Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Inflater.cs
Go to the documentation of this file.
1 //
2 // © Copyright Henrik Ravn 2004
3 //
4 // Use, modification and distribution are subject to the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 using System;
9 using System.Diagnostics;
10 using System.Runtime.InteropServices;
11 
12 namespace DotZLib
13 {
14 
18  public class Inflater : CodecBase
19  {
20  #region Dll imports
21  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
22  private static extern int inflateInit_(ref ZStream sz, string vs, int size);
23 
24  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
25  private static extern int inflate(ref ZStream sz, int flush);
26 
27  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
28  private static extern int inflateReset(ref ZStream sz);
29 
30  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
31  private static extern int inflateEnd(ref ZStream sz);
32  #endregion
33 
37  public Inflater() : base()
38  {
39  int retval = inflateInit_(ref _ztream, Info.Version, Marshal.SizeOf(_ztream));
40  if (retval != 0)
41  throw new ZLibException(retval, "Could not initialize inflater");
42 
43  resetOutput();
44  }
45 
46 
54  public override void Add(byte[] data, int offset, int count)
55  {
56  if (data == null) throw new ArgumentNullException();
57  if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
58  if ((offset+count) > data.Length) throw new ArgumentException();
59 
60  int total = count;
61  int inputIndex = offset;
62  int err = 0;
63 
64  while (err >= 0 && inputIndex < total)
65  {
66  copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize));
67  err = inflate(ref _ztream, (int)FlushTypes.None);
68  if (err == 0)
69  while (_ztream.avail_out == 0)
70  {
72  err = inflate(ref _ztream, (int)FlushTypes.None);
73  }
74 
75  inputIndex += (int)_ztream.total_in;
76  }
77  setChecksum( _ztream.adler );
78  }
79 
80 
84  public override void Finish()
85  {
86  int err;
87  do
88  {
89  err = inflate(ref _ztream, (int)FlushTypes.Finish);
91  }
92  while (err == 0);
93  setChecksum( _ztream.adler );
94  inflateReset(ref _ztream);
95  resetOutput();
96  }
97 
101  protected override void CleanUp() { inflateEnd(ref _ztream); }
102 
103 
104  }
105 }
void setChecksum(uint newSum)
Updates the running checksum property
Definition: CodecBase.cs:191
Implements the common functionality needed for all Codecs
Definition: CodecBase.cs:16
override void Add(byte[] data, int offset, int count)
Adds more data to the codec to be processed.
Definition: Inflater.cs:54
Inflater()
Constructs an new instance of the Inflater
Definition: Inflater.cs:37
Implements a data decompressor, using the inflate algorithm in the ZLib dll
Definition: Inflater.cs:18
unsigned char byte
Definition: tif_acorn.c:69
GLenum GLint ref
void copyInput(byte[] data, int startIndex, int count)
Copies a number of bytes to the internal codec buffer - ready for proccesing
Definition: CodecBase.cs:168
override void CleanUp()
Closes the internal zlib inflate stream
Definition: Inflater.cs:101
GLsizei GLsizei GLenum GLenum const GLvoid * data
static string Version
Gets the version of ZLib as a string, e.g.
Definition: DotZLib.cs:283
void OnDataAvailable()
Fires the DataAvailable event
Definition: CodecBase.cs:75
GLintptr offset
typedef int
Definition: png.h:978
int flush
Definition: zlib.h:309
void resetOutput()
Resets the internal output buffers to a known state - ready for processing
Definition: CodecBase.cs:180
GLuint GLuint GLsizei count
Encapsulates general information about the ZLib library
Definition: DotZLib.cs:216
const int kBufferSize
The size of the internal buffers
Definition: CodecBase.cs:35
GLsizeiptr size
override void Finish()
Finishes up any pending data that needs to be processed and handled.
Definition: Inflater.cs:84
The exception that is thrown when an error occurs on the zlib dll
Definition: DotZLib.cs:86