rlm@1
|
1 // MethodProps.cpp
|
rlm@1
|
2
|
rlm@1
|
3 #include "StdAfx.h"
|
rlm@1
|
4
|
rlm@1
|
5 #include "../../Common/MyCom.h"
|
rlm@1
|
6
|
rlm@1
|
7 #include "../ICoder.h"
|
rlm@1
|
8
|
rlm@1
|
9 #include "MethodProps.h"
|
rlm@1
|
10
|
rlm@1
|
11 static UInt64 k_LZMA = 0x030101;
|
rlm@1
|
12 // static UInt64 k_LZMA2 = 0x030102;
|
rlm@1
|
13
|
rlm@1
|
14 HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)
|
rlm@1
|
15 {
|
rlm@1
|
16 bool tryReduce = false;
|
rlm@1
|
17 UInt32 reducedDictionarySize = 1 << 10;
|
rlm@1
|
18 if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))
|
rlm@1
|
19 {
|
rlm@1
|
20 for (;;)
|
rlm@1
|
21 {
|
rlm@1
|
22 const UInt32 step = (reducedDictionarySize >> 1);
|
rlm@1
|
23 if (reducedDictionarySize >= *inSizeForReduce)
|
rlm@1
|
24 {
|
rlm@1
|
25 tryReduce = true;
|
rlm@1
|
26 break;
|
rlm@1
|
27 }
|
rlm@1
|
28 reducedDictionarySize += step;
|
rlm@1
|
29 if (reducedDictionarySize >= *inSizeForReduce)
|
rlm@1
|
30 {
|
rlm@1
|
31 tryReduce = true;
|
rlm@1
|
32 break;
|
rlm@1
|
33 }
|
rlm@1
|
34 if (reducedDictionarySize >= ((UInt32)3 << 30))
|
rlm@1
|
35 break;
|
rlm@1
|
36 reducedDictionarySize += step;
|
rlm@1
|
37 }
|
rlm@1
|
38 }
|
rlm@1
|
39
|
rlm@1
|
40 {
|
rlm@1
|
41 int numProps = method.Props.Size();
|
rlm@1
|
42 CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
|
rlm@1
|
43 coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
|
rlm@1
|
44 if (setCoderProperties == NULL)
|
rlm@1
|
45 {
|
rlm@1
|
46 if (numProps != 0)
|
rlm@1
|
47 return E_INVALIDARG;
|
rlm@1
|
48 }
|
rlm@1
|
49 else
|
rlm@1
|
50 {
|
rlm@1
|
51 CRecordVector<PROPID> propIDs;
|
rlm@1
|
52 NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];
|
rlm@1
|
53 HRESULT res = S_OK;
|
rlm@1
|
54 try
|
rlm@1
|
55 {
|
rlm@1
|
56 for (int i = 0; i < numProps; i++)
|
rlm@1
|
57 {
|
rlm@1
|
58 const CProp &prop = method.Props[i];
|
rlm@1
|
59 propIDs.Add(prop.Id);
|
rlm@1
|
60 NWindows::NCOM::CPropVariant &value = values[i];
|
rlm@1
|
61 value = prop.Value;
|
rlm@1
|
62 // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)
|
rlm@1
|
63 if (tryReduce)
|
rlm@1
|
64 if (prop.Id == NCoderPropID::kDictionarySize)
|
rlm@1
|
65 if (value.vt == VT_UI4)
|
rlm@1
|
66 if (reducedDictionarySize < value.ulVal)
|
rlm@1
|
67 value.ulVal = reducedDictionarySize;
|
rlm@1
|
68 }
|
rlm@1
|
69 CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
|
rlm@1
|
70 coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
|
rlm@1
|
71 res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);
|
rlm@1
|
72 }
|
rlm@1
|
73 catch(...)
|
rlm@1
|
74 {
|
rlm@1
|
75 delete []values;
|
rlm@1
|
76 throw;
|
rlm@1
|
77 }
|
rlm@1
|
78 delete []values;
|
rlm@1
|
79 RINOK(res);
|
rlm@1
|
80 }
|
rlm@1
|
81 }
|
rlm@1
|
82
|
rlm@1
|
83 /*
|
rlm@1
|
84 CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
|
rlm@1
|
85 coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);
|
rlm@1
|
86 if (writeCoderProperties != NULL)
|
rlm@1
|
87 {
|
rlm@1
|
88 CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
|
rlm@1
|
89 CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
|
rlm@1
|
90 outStreamSpec->Init();
|
rlm@1
|
91 RINOK(writeCoderProperties->WriteCoderProperties(outStream));
|
rlm@1
|
92 size_t size = outStreamSpec->GetSize();
|
rlm@1
|
93 filterProps.SetCapacity(size);
|
rlm@1
|
94 memmove(filterProps, outStreamSpec->GetBuffer(), size);
|
rlm@1
|
95 }
|
rlm@1
|
96 */
|
rlm@1
|
97 return S_OK;
|
rlm@1
|
98 }
|
rlm@1
|
99
|