1 // DeltaFilter.cpp
2
3 #include "StdAfx.h"
4
5 #include "../../../C/Delta.h"
6
7 #include "../../Common/MyCom.h"
8
9 #include "../ICoder.h"
10
11 #include "../Common/RegisterCodec.h"
12
13 namespace NCompress {
14 namespace NDelta {
15
16 struct CDelta
17 {
18 unsigned _delta;
19 Byte _state[DELTA_STATE_SIZE];
20
CDeltaNCompress::NDelta::CDelta21 CDelta(): _delta(1) {}
DeltaInitNCompress::NDelta::CDelta22 void DeltaInit() { Delta_Init(_state); }
23 };
24
25
26 #ifndef Z7_EXTRACT_ONLY
27
28 class CEncoder Z7_final:
29 public ICompressFilter,
30 public ICompressSetCoderProperties,
31 public ICompressWriteCoderProperties,
32 public CMyUnknownImp,
33 CDelta
34 {
35 Z7_IFACES_IMP_UNK_3(
36 ICompressFilter,
37 ICompressSetCoderProperties,
38 ICompressWriteCoderProperties)
39 };
40
Z7_COM7F_IMF(CEncoder::Init ())41 Z7_COM7F_IMF(CEncoder::Init())
42 {
43 DeltaInit();
44 return S_OK;
45 }
46
Z7_COM7F_IMF2(UInt32,CEncoder::Filter (Byte * data,UInt32 size))47 Z7_COM7F_IMF2(UInt32, CEncoder::Filter(Byte *data, UInt32 size))
48 {
49 Delta_Encode(_state, _delta, data, size);
50 return size;
51 }
52
Z7_COM7F_IMF(CEncoder::SetCoderProperties (const PROPID * propIDs,const PROPVARIANT * props,UInt32 numProps))53 Z7_COM7F_IMF(CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps))
54 {
55 unsigned delta = _delta;
56 for (UInt32 i = 0; i < numProps; i++)
57 {
58 const PROPVARIANT &prop = props[i];
59 const PROPID propID = propIDs[i];
60 if (propID >= NCoderPropID::kReduceSize)
61 continue;
62 if (prop.vt != VT_UI4)
63 return E_INVALIDARG;
64 switch (propID)
65 {
66 case NCoderPropID::kDefaultProp:
67 if (prop.ulVal < 1 || prop.ulVal > 256)
68 return E_INVALIDARG;
69 delta = prop.ulVal;
70 break;
71 case NCoderPropID::kNumThreads: break;
72 case NCoderPropID::kLevel: break;
73 default: return E_INVALIDARG;
74 }
75 }
76 _delta = delta;
77 return S_OK;
78 }
79
Z7_COM7F_IMF(CEncoder::WriteCoderProperties (ISequentialOutStream * outStream))80 Z7_COM7F_IMF(CEncoder::WriteCoderProperties(ISequentialOutStream *outStream))
81 {
82 const Byte prop = (Byte)(_delta - 1);
83 return outStream->Write(&prop, 1, NULL);
84 }
85
86 #endif
87
88
89 class CDecoder Z7_final:
90 public ICompressFilter,
91 public ICompressSetDecoderProperties2,
92 public CMyUnknownImp,
93 CDelta
94 {
95 Z7_IFACES_IMP_UNK_2(
96 ICompressFilter,
97 ICompressSetDecoderProperties2)
98 };
99
Z7_COM7F_IMF(CDecoder::Init ())100 Z7_COM7F_IMF(CDecoder::Init())
101 {
102 DeltaInit();
103 return S_OK;
104 }
105
Z7_COM7F_IMF2(UInt32,CDecoder::Filter (Byte * data,UInt32 size))106 Z7_COM7F_IMF2(UInt32, CDecoder::Filter(Byte *data, UInt32 size))
107 {
108 Delta_Decode(_state, _delta, data, size);
109 return size;
110 }
111
Z7_COM7F_IMF(CDecoder::SetDecoderProperties2 (const Byte * props,UInt32 size))112 Z7_COM7F_IMF(CDecoder::SetDecoderProperties2(const Byte *props, UInt32 size))
113 {
114 if (size != 1)
115 return E_INVALIDARG;
116 _delta = (unsigned)props[0] + 1;
117 return S_OK;
118 }
119
120
121 REGISTER_FILTER_E(Delta,
122 CDecoder(),
123 CEncoder(),
124 3, "Delta")
125
126 }}
127