Skip to content

Commit 405fdd6

Browse files
committed
Add initial cut of LZW. Not yet included in repository projects as the code is not well tested...
1 parent 6da2d63 commit 405fdd6

3 files changed

Lines changed: 780 additions & 0 deletions

File tree

src/Lzw/LzwConstants.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// LzwConstants.cs
2+
//
3+
// Copyright (C) 2009 Gabriel Burca
4+
//
5+
// This program is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU General Public License
7+
// as published by the Free Software Foundation; either version 2
8+
// of the License, or (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
//
19+
// Linking this library statically or dynamically with other modules is
20+
// making a combined work based on this library. Thus, the terms and
21+
// conditions of the GNU General Public License cover the whole
22+
// combination.
23+
//
24+
// As a special exception, the copyright holders of this library give you
25+
// permission to link this library with independent modules to produce an
26+
// executable, regardless of the license terms of these independent
27+
// modules, and to copy and distribute the resulting executable under
28+
// terms of your choice, provided that you also meet, for each linked
29+
// independent module, the terms and conditions of the license of that
30+
// module. An independent module is a module which is not derived from
31+
// or based on this library. If you modify this library, you may extend
32+
// this exception to your version of the library, but you are not
33+
// obligated to do so. If you do not wish to do so, delete this
34+
// exception statement from your version.
35+
36+
namespace ICSharpCode.SharpZipLib.LZW {
37+
38+
/// <summary>
39+
/// This class contains constants used for LZW
40+
/// </summary>
41+
sealed public class LzwConstants {
42+
/// <summary>
43+
/// Magic number found at start of LZW header: 0x1f 0x9d
44+
/// </summary>
45+
public const int MAGIC = 0x1f9d;
46+
47+
/// <summary>
48+
/// Maximum number of bits per code
49+
/// </summary>
50+
public const int MAX_BITS = 16;
51+
52+
/* 3rd header byte:
53+
* bit 0..4 Number of compression bits
54+
* bit 5 Extended header
55+
* bit 6 Free
56+
* bit 7 Block mode
57+
*/
58+
59+
/// <summary>
60+
/// Mask for 'number of compression bits'
61+
/// </summary>
62+
public const int BIT_MASK = 0x1f;
63+
64+
/// <summary>
65+
/// Indicates the presence of a fourth header byte
66+
/// </summary>
67+
public const int EXTENDED_MASK = 0x20;
68+
//public const int FREE_MASK = 0x40;
69+
70+
/// <summary>
71+
/// Reserved bits
72+
/// </summary>
73+
public const int RESERVED_MASK = 0x60;
74+
75+
/// <summary>
76+
/// Block compression: if table is full and compression rate is dropping,
77+
/// clear the dictionary.
78+
/// </summary>
79+
public const int BLOCK_MODE_MASK = 0x80;
80+
81+
/// <summary>
82+
/// LZW file header size (in bytes)
83+
/// </summary>
84+
public const int HDR_SIZE = 3;
85+
86+
/// <summary>
87+
/// Initial number of bits per code
88+
/// </summary>
89+
public const int INIT_BITS = 9;
90+
91+
LzwConstants() {
92+
}
93+
}
94+
}

src/Lzw/LzwException.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// LzwException.cs
2+
//
3+
// Copyright (C) 2009 Gabriel Burca
4+
//
5+
// This program is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU General Public License
7+
// as published by the Free Software Foundation; either version 2
8+
// of the License, or (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
//
19+
// Linking this library statically or dynamically with other modules is
20+
// making a combined work based on this library. Thus, the terms and
21+
// conditions of the GNU General Public License cover the whole
22+
// combination.
23+
//
24+
// As a special exception, the copyright holders of this library give you
25+
// permission to link this library with independent modules to produce an
26+
// executable, regardless of the license terms of these independent
27+
// modules, and to copy and distribute the resulting executable under
28+
// terms of your choice, provided that you also meet, for each linked
29+
// independent module, the terms and conditions of the license of that
30+
// module. An independent module is a module which is not derived from
31+
// or based on this library. If you modify this library, you may extend
32+
// this exception to your version of the library, but you are not
33+
// obligated to do so. If you do not wish to do so, delete this
34+
// exception statement from your version.
35+
36+
using System;
37+
38+
#if !NETCF_1_0 && !NETCF_2_0
39+
using System.Runtime.Serialization;
40+
#endif
41+
42+
namespace ICSharpCode.SharpZipLib.LZW
43+
{
44+
45+
/// <summary>
46+
/// LzwException represents a LZW specific exception
47+
/// </summary>
48+
#if !NETCF_1_0 && !NETCF_2_0
49+
[Serializable]
50+
#endif
51+
public class LzwException : SharpZipBaseException
52+
{
53+
54+
#if !NETCF_1_0 && !NETCF_2_0
55+
/// <summary>
56+
/// Deserialization constructor
57+
/// </summary>
58+
/// <param name="info"><see cref="SerializationInfo"/> for this constructor</param>
59+
/// <param name="context"><see cref="StreamingContext"/> for this constructor</param>
60+
protected LzwException(SerializationInfo info, StreamingContext context)
61+
: base(info, context) {
62+
}
63+
#endif
64+
65+
/// <summary>
66+
/// Initialise a new instance of LzwException
67+
/// </summary>
68+
public LzwException() {
69+
}
70+
71+
/// <summary>
72+
/// Initialise a new instance of LzwException with its message string.
73+
/// </summary>
74+
/// <param name="message">A <see cref="string"/> that describes the error.</param>
75+
public LzwException(string message)
76+
: base(message) {
77+
}
78+
79+
/// <summary>
80+
/// Initialise a new instance of <see cref="LzwException"></see>.
81+
/// </summary>
82+
/// <param name="message">A <see cref="string"/> that describes the error.</param>
83+
/// <param name="innerException">The <see cref="Exception"/> that caused this exception.</param>
84+
public LzwException(string message, Exception innerException)
85+
: base(message, innerException) {
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)