summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp87
1 files changed, 57 insertions, 30 deletions
diff --git a/3rdparty/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp b/3rdparty/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp
index 06a11f10eae..0dc7e23b463 100644
--- a/3rdparty/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp
+++ b/3rdparty/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp
@@ -21,18 +21,20 @@ namespace NLzma2 {
CEncoder::CEncoder()
{
- _encoder = 0;
- _encoder = Lzma2Enc_Create(&g_Alloc, &g_BigAlloc);
- if (_encoder == 0)
+ _encoder = NULL;
+ _encoder = Lzma2Enc_Create(&g_AlignedAlloc, &g_BigAlloc);
+ if (!_encoder)
throw 1;
}
CEncoder::~CEncoder()
{
- if (_encoder != 0)
+ if (_encoder)
Lzma2Enc_Destroy(_encoder);
}
+
+HRESULT SetLzma2Prop(PROPID propID, const PROPVARIANT &prop, CLzma2EncProps &lzma2Props);
HRESULT SetLzma2Prop(PROPID propID, const PROPVARIANT &prop, CLzma2EncProps &lzma2Props)
{
switch (propID)
@@ -42,57 +44,82 @@ HRESULT SetLzma2Prop(PROPID propID, const PROPVARIANT &prop, CLzma2EncProps &lzm
if (prop.vt == VT_UI4)
lzma2Props.blockSize = prop.ulVal;
else if (prop.vt == VT_UI8)
- {
- size_t v = (size_t)prop.uhVal.QuadPart;
- if (v != prop.uhVal.QuadPart)
- return E_INVALIDARG;
- lzma2Props.blockSize = v;
- }
+ lzma2Props.blockSize = prop.uhVal.QuadPart;
else
return E_INVALIDARG;
break;
}
case NCoderPropID::kNumThreads:
- if (prop.vt != VT_UI4) return E_INVALIDARG; lzma2Props.numTotalThreads = (int)(prop.ulVal); break;
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ lzma2Props.numTotalThreads = (int)(prop.ulVal);
+ break;
default:
- RINOK(NLzma::SetLzmaProp(propID, prop, lzma2Props.lzmaProps));
+ RINOK(NLzma::SetLzmaProp(propID, prop, lzma2Props.lzmaProps))
}
return S_OK;
}
-STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
- const PROPVARIANT *coderProps, UInt32 numProps)
+
+Z7_COM7F_IMF(CEncoder::SetCoderProperties(const PROPID *propIDs,
+ const PROPVARIANT *coderProps, UInt32 numProps))
{
CLzma2EncProps lzma2Props;
Lzma2EncProps_Init(&lzma2Props);
for (UInt32 i = 0; i < numProps; i++)
{
- RINOK(SetLzma2Prop(propIDs[i], coderProps[i], lzma2Props));
+ RINOK(SetLzma2Prop(propIDs[i], coderProps[i], lzma2Props))
}
return SResToHRESULT(Lzma2Enc_SetProps(_encoder, &lzma2Props));
}
-STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
+
+Z7_COM7F_IMF(CEncoder::SetCoderPropertiesOpt(const PROPID *propIDs,
+ const PROPVARIANT *coderProps, UInt32 numProps))
{
- Byte prop = Lzma2Enc_WriteProperties(_encoder);
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ const PROPVARIANT &prop = coderProps[i];
+ const PROPID propID = propIDs[i];
+ if (propID == NCoderPropID::kExpectedDataSize)
+ if (prop.vt == VT_UI8)
+ Lzma2Enc_SetDataSize(_encoder, prop.uhVal.QuadPart);
+ }
+ return S_OK;
+}
+
+
+Z7_COM7F_IMF(CEncoder::WriteCoderProperties(ISequentialOutStream *outStream))
+{
+ const Byte prop = Lzma2Enc_WriteProperties(_encoder);
return WriteStream(outStream, &prop, 1);
}
-STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
- const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+
+#define RET_IF_WRAP_ERROR(wrapRes, sRes, sResErrorCode) \
+ if (wrapRes != S_OK /* && (sRes == SZ_OK || sRes == sResErrorCode) */) return wrapRes;
+
+Z7_COM7F_IMF(CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress))
{
- CSeqInStreamWrap inWrap(inStream);
- CSeqOutStreamWrap outWrap(outStream);
- CCompressProgressWrap progressWrap(progress);
-
- SRes res = Lzma2Enc_Encode(_encoder, &outWrap.p, &inWrap.p, progress ? &progressWrap.p : NULL);
- if (res == SZ_ERROR_READ && inWrap.Res != S_OK)
- return inWrap.Res;
- if (res == SZ_ERROR_WRITE && outWrap.Res != S_OK)
- return outWrap.Res;
- if (res == SZ_ERROR_PROGRESS && progressWrap.Res != S_OK)
- return progressWrap.Res;
+ CSeqInStreamWrap inWrap;
+ CSeqOutStreamWrap outWrap;
+ CCompressProgressWrap progressWrap;
+
+ inWrap.Init(inStream);
+ outWrap.Init(outStream);
+ progressWrap.Init(progress);
+
+ SRes res = Lzma2Enc_Encode2(_encoder,
+ &outWrap.vt, NULL, NULL,
+ &inWrap.vt, NULL, 0,
+ progress ? &progressWrap.vt : NULL);
+
+ RET_IF_WRAP_ERROR(inWrap.Res, res, SZ_ERROR_READ)
+ RET_IF_WRAP_ERROR(outWrap.Res, res, SZ_ERROR_WRITE)
+ RET_IF_WRAP_ERROR(progressWrap.Res, res, SZ_ERROR_PROGRESS)
+
return SResToHRESULT(res);
}