Skip to content

Latest commit

 

History

History
96 lines (89 loc) · 2.91 KB

MethodProps.cpp

File metadata and controls

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