src/stream/ZStream_LZW.h

00001 /*  @(#) $Id: ZStream_LZW.h,v 1.9 2007/04/01 12:51:30 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2002 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZStream_LZW__
00026 #define __ZStream_LZW__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZBitStream.h"
00030 #include "ZStream.h"
00031 
00032 // =================================================================================================
00033 #pragma mark -
00034 #pragma mark * ZStreamR_LZWEncode
00035 
00036 /* This one is not done yet.
00037 class ZStreamR_LZWEncode : public ZStreamR
00038         {
00039 public:
00040         ZStreamR_LZWEncode(int iCodeSize_Alphabet, const ZStreamR& iStreamSource);
00041         ~ZStreamR_LZWEncode();
00042 
00043 // From ZStreamR
00044         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00045         virtual size_t Imp_CountReadable();
00046 
00047 protected:
00048         const ZStreamR& fStreamSource;
00049 
00050         int fCodeSize_Alphabet;
00051         int fCodeSize_Emitted;
00052 
00053         int fCode_Clear;
00054         int fCode_FIN;
00055 
00056         size_t fCountSinceClear;
00057 
00058         bool fSentFIN;
00059         bool fFinished;
00060 
00061         ZBitWriterBE fBitWriter;
00062         };
00063 */
00064 
00065 // =================================================================================================
00066 #pragma mark -
00067 #pragma mark * ZStreamR_LZWEncodeNoPatent
00068 
00069 class ZStreamR_LZWEncodeNoPatent : public ZStreamR
00070         {
00071 public:
00072         ZStreamR_LZWEncodeNoPatent(int iCodeSize_Alphabet, const ZStreamR& iStreamSource);
00073         ~ZStreamR_LZWEncodeNoPatent();
00074 
00075 // From ZStreamR
00076         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00077         virtual size_t Imp_CountReadable();
00078 
00079 protected:
00080         const ZStreamR& fStreamSource;
00081 
00082         int fCodeSize_Alphabet;
00083         int fCodeSize_Emitted;
00084 
00085         int fCode_Clear;
00086         int fCode_FIN;
00087 
00088         size_t fCountSinceClear;
00089 
00090         bool fSentFIN;
00091         bool fFinished;
00092 
00093         ZBitWriterBE fBitWriter;
00094         };
00095 
00096 // =================================================================================================
00097 #pragma mark -
00098 #pragma mark * ZStreamR_LZWDecode
00099 
00101 
00102 class ZStreamR_LZWDecode : public ZStreamR
00103         {
00104 public:
00105         ZStreamR_LZWDecode(int iCodeSize_Alphabet, const ZStreamR& iStreamSource);
00106         ~ZStreamR_LZWDecode();
00107 
00108 // From ZStreamR
00109         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00110         virtual size_t Imp_CountReadable();
00111 
00112 protected:
00113         const ZStreamR& fStreamSource;
00114 
00115         bool fSeenFIN;
00116 
00117         int fCodeSize_Alphabet;
00118         int fCodeSize_Read;
00119 
00120         int fCode_Clear;
00121         int fCode_FIN;
00122         int fCode_FirstAvailable;
00123         int fCode_Last;
00124         int fCode_ABCABCA;
00125 
00126         uint8* fStack;
00127         uint8* fStackEnd;
00128         uint8* fStackTop;
00129 
00130         uint16* fPrefix;
00131         uint8* fSuffix;
00132 
00133         ZBitReaderBE fBitReader;
00134         };
00135 
00136 // =================================================================================================
00137 #pragma mark -
00138 #pragma mark * ZStreamW_LZWEncode
00139 
00141 
00142 class ZStreamW_LZWEncode : public ZStreamW
00143         {
00144 public:
00145         ZStreamW_LZWEncode(int iCodeSize_Alphabet, const ZStreamW& iStreamSink);
00146         ~ZStreamW_LZWEncode();
00147 
00148 // From ZStreamW
00149         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00150         virtual void Imp_Flush();
00151 
00152 protected:
00153         const ZStreamW& fStreamSink;
00154 
00155         int fCodeSize_Alphabet;
00156         int fCodeSize_Emitted;
00157 
00158         int fCode_Clear;
00159         int fCode_FIN;
00160         int fCode_FirstAvailable;
00161 
00162         uint8* fCodes_Suffix;
00163         uint16* fCodes_Prefix;
00164         uint16* fChild;
00165 
00166         uint16 fPendingPrefix;
00167 
00168         bool  fFresh;
00169 
00170         ZBitWriterBE fBitWriter;
00171         };
00172 
00173 // =================================================================================================
00174 #pragma mark -
00175 #pragma mark * ZStreamW_LZWEncodeNoPatent
00176 
00177 class ZStreamW_LZWEncodeNoPatent : public ZStreamW
00178         {
00179 public:
00180         ZStreamW_LZWEncodeNoPatent(int iCodeSize_Alphabet, const ZStreamW& iStreamSink);
00181         ~ZStreamW_LZWEncodeNoPatent();
00182 
00183 // From ZStreamW
00184         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00185         virtual void Imp_Flush();
00186 
00187 protected:
00188         const ZStreamW& fStreamSink;
00189 
00190         int fCodeSize_Alphabet;
00191         int fCodeSize_Emitted;
00192 
00193         int fCode_Clear;
00194         int fCode_FIN;
00195 
00196         size_t fCountSinceClear;
00197 
00198         ZBitWriterBE fBitWriter;
00199         };
00200 
00201 // =================================================================================================
00202 #pragma mark -
00203 #pragma mark * ZStreamW_LZWDecode
00204 
00206 
00207 class ZStreamW_LZWDecode : public ZStreamW
00208         {
00209 public:
00210         ZStreamW_LZWDecode(int iCodeSize_Alphabet, const ZStreamW& iStreamSink);
00211         ~ZStreamW_LZWDecode();
00212 
00213 // From ZStreamW
00214         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00215         virtual void Imp_Flush();
00216 
00217 protected:
00218         const ZStreamW& fStreamSink;
00219 
00220         bool fSeenFIN;
00221 
00222         int fCodeSize_Alphabet;
00223         int fCodeSize_Read;
00224 
00225         int fCode_Clear;
00226         int fCode_FIN;
00227         int fCode_FirstAvailable;
00228         int fCode_Last;
00229         int fCode_ABCABCA;
00230 
00231         uint8* fStack;
00232         uint8* fStackEnd;
00233         uint8* fStackTop;
00234 
00235         uint16* fPrefix;
00236         uint8* fSuffix;
00237 
00238         ZBitReaderBE fBitReader;
00239         };
00240 
00241 // =================================================================================================
00242 
00243 #endif // __ZStream_LZW__

Generated on Thu Jul 26 11:21:53 2007 for ZooLib by  doxygen 1.4.7