rlm@1: // MethodProps.cpp rlm@1: rlm@1: #include "StdAfx.h" rlm@1: rlm@1: #include "../../Common/MyCom.h" rlm@1: rlm@1: #include "../ICoder.h" rlm@1: rlm@1: #include "MethodProps.h" rlm@1: rlm@1: static UInt64 k_LZMA = 0x030101; rlm@1: // static UInt64 k_LZMA2 = 0x030102; rlm@1: rlm@1: HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder) rlm@1: { rlm@1: bool tryReduce = false; rlm@1: UInt32 reducedDictionarySize = 1 << 10; rlm@1: if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */)) rlm@1: { rlm@1: for (;;) rlm@1: { rlm@1: const UInt32 step = (reducedDictionarySize >> 1); rlm@1: if (reducedDictionarySize >= *inSizeForReduce) rlm@1: { rlm@1: tryReduce = true; rlm@1: break; rlm@1: } rlm@1: reducedDictionarySize += step; rlm@1: if (reducedDictionarySize >= *inSizeForReduce) rlm@1: { rlm@1: tryReduce = true; rlm@1: break; rlm@1: } rlm@1: if (reducedDictionarySize >= ((UInt32)3 << 30)) rlm@1: break; rlm@1: reducedDictionarySize += step; rlm@1: } rlm@1: } rlm@1: rlm@1: { rlm@1: int numProps = method.Props.Size(); rlm@1: CMyComPtr setCoderProperties; rlm@1: coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); rlm@1: if (setCoderProperties == NULL) rlm@1: { rlm@1: if (numProps != 0) rlm@1: return E_INVALIDARG; rlm@1: } rlm@1: else rlm@1: { rlm@1: CRecordVector propIDs; rlm@1: NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps]; rlm@1: HRESULT res = S_OK; rlm@1: try rlm@1: { rlm@1: for (int i = 0; i < numProps; i++) rlm@1: { rlm@1: const CProp &prop = method.Props[i]; rlm@1: propIDs.Add(prop.Id); rlm@1: NWindows::NCOM::CPropVariant &value = values[i]; rlm@1: value = prop.Value; rlm@1: // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal) rlm@1: if (tryReduce) rlm@1: if (prop.Id == NCoderPropID::kDictionarySize) rlm@1: if (value.vt == VT_UI4) rlm@1: if (reducedDictionarySize < value.ulVal) rlm@1: value.ulVal = reducedDictionarySize; rlm@1: } rlm@1: CMyComPtr setCoderProperties; rlm@1: coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); rlm@1: res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps); rlm@1: } rlm@1: catch(...) rlm@1: { rlm@1: delete []values; rlm@1: throw; rlm@1: } rlm@1: delete []values; rlm@1: RINOK(res); rlm@1: } rlm@1: } rlm@1: rlm@1: /* rlm@1: CMyComPtr writeCoderProperties; rlm@1: coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties); rlm@1: if (writeCoderProperties != NULL) rlm@1: { rlm@1: CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp; rlm@1: CMyComPtr outStream(outStreamSpec); rlm@1: outStreamSpec->Init(); rlm@1: RINOK(writeCoderProperties->WriteCoderProperties(outStream)); rlm@1: size_t size = outStreamSpec->GetSize(); rlm@1: filterProps.SetCapacity(size); rlm@1: memmove(filterProps, outStreamSpec->GetBuffer(), size); rlm@1: } rlm@1: */ rlm@1: return S_OK; rlm@1: } rlm@1: