1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// DeltaFilter.cpp 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "StdAfx.h" 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../C/Delta.h" 6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../Common/RegisterCodec.h" 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "BranchCoder.h" 10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 11baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CDelta 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync unsigned _delta; 14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Byte _state[DELTA_STATE_SIZE]; 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CDelta(): _delta(1) {} 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync void DeltaInit() { Delta_Init(_state); } 17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 19baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CDeltaEncoder: 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public ICompressFilter, 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public ICompressSetCoderProperties, 22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public ICompressWriteCoderProperties, 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CDelta, 24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public CMyUnknownImp 25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 26baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic: 27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync MY_UNKNOWN_IMP2(ICompressSetCoderProperties, ICompressWriteCoderProperties) 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(Init)(); 29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps); 31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); 32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 34baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CDeltaDecoder: 35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public ICompressFilter, 36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public ICompressSetDecoderProperties2, 37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CDelta, 38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public CMyUnknownImp 39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 40baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic: 41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2) 42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(Init)(); 43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); 44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); 45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 47baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CDeltaEncoder::Init() 48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync DeltaInit(); 50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 53baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP_(UInt32) CDeltaEncoder::Filter(Byte *data, UInt32 size) 54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Delta_Encode(_state, _delta, data, size); 56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return size; 57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 59baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CDeltaEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps) 60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 delta = _delta; 62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (UInt32 i = 0; i < numProps; i++) 63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const PROPVARIANT &prop = props[i]; 65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (propIDs[i] != NCoderPropID::kDefaultProp || prop.vt != VT_UI4 || prop.ulVal < 1 || prop.ulVal > 256) 66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return E_INVALIDARG; 67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync delta = prop.ulVal; 68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _delta = delta; 70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 73baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CDeltaEncoder::WriteCoderProperties(ISequentialOutStream *outStream) 74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Byte prop = (Byte)(_delta - 1); 76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return outStream->Write(&prop, 1, NULL); 77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 79baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CDeltaDecoder::Init() 80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync DeltaInit(); 82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 85baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP_(UInt32) CDeltaDecoder::Filter(Byte *data, UInt32 size) 86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Delta_Decode(_state, _delta, data, size); 88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return size; 89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 91baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CDeltaDecoder::SetDecoderProperties2(const Byte *props, UInt32 size) 92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (size != 1) 94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return E_INVALIDARG; 95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _delta = (unsigned)props[0] + 1; 96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 98baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define CREATE_CODEC(x) \ 100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## Decoder); } \ 101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## Encoder); } 102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 103baa3858d3f5d128a5c8466b700098109edcad5f2repo syncCREATE_CODEC(Delta) 104baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 105baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define METHOD_ITEM(x, id, name) { CreateCodec ## x, CreateCodec ## x ## Out, id, name, 1, true } 106baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 107baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic CCodecInfo g_CodecsInfo[] = 108baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 109baa3858d3f5d128a5c8466b700098109edcad5f2repo sync METHOD_ITEM(Delta, 3, L"Delta") 110baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 111baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 112baa3858d3f5d128a5c8466b700098109edcad5f2repo syncREGISTER_CODECS(Delta) 113