5 #include "MethodProps.h"
6 #include "../../Common/MyCom.h"
8 static UInt64 k_LZMA = 0x030101;
9 // static UInt64 k_LZMA2 = 0x030102;
11 HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)
13 bool tryReduce = false;
14 UInt32 reducedDictionarySize = 1 << 10;
15 if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))
19 const UInt32 step = (reducedDictionarySize >> 1);
20 if (reducedDictionarySize >= *inSizeForReduce)
25 reducedDictionarySize += step;
26 if (reducedDictionarySize >= *inSizeForReduce)
31 if (reducedDictionarySize >= ((UInt32)3 << 30))
33 reducedDictionarySize += step;
38 int numProperties = method.Properties.Size();
39 CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
40 coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
41 if (setCoderProperties == NULL)
43 if (numProperties != 0)
48 CRecordVector<PROPID> propIDs;
49 NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties];
53 for (int i = 0; i < numProperties; i++)
55 const CProp &prop = method.Properties[i];
57 NWindows::NCOM::CPropVariant &value = values[i];
59 // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)
61 if (prop.Id == NCoderPropID::kDictionarySize)
62 if (value.vt == VT_UI4)
63 if (reducedDictionarySize < value.ulVal)
64 value.ulVal = reducedDictionarySize;
66 CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
67 coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
68 res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties);
81 CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
82 coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);
83 if (writeCoderProperties != NULL)
85 CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
86 CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
87 outStreamSpec->Init();
88 RINOK(writeCoderProperties->WriteCoderProperties(outStream));
89 size_t size = outStreamSpec->GetSize();
90 filterProps.SetCapacity(size);
91 memmove(filterProps, outStreamSpec->GetBuffer(), size);