Beispiel #1
0
            public SRes Lzma2Enc_SetProps(CLzma2EncProps props)
            {
                TR("Lzma2Enc_SetProps:level", props.mLzmaProps.mLevel);
                TR("Lzma2Enc_SetProps:dictSize", props.mLzmaProps.mDictSize);
                TR("Lzma2Enc_SetProps:lc", props.mLzmaProps.mLC);
                TR("Lzma2Enc_SetProps:lp", props.mLzmaProps.mLP);
                TR("Lzma2Enc_SetProps:pb", props.mLzmaProps.mPB);
                TR("Lzma2Enc_SetProps:algo", props.mLzmaProps.mAlgo);
                TR("Lzma2Enc_SetProps:fb", props.mLzmaProps.mFB);
                TR("Lzma2Enc_SetProps:btMode", props.mLzmaProps.mBtMode);
                TR("Lzma2Enc_SetProps:numHashBytes", props.mLzmaProps.mNumHashBytes);
                TR("Lzma2Enc_SetProps:mc", props.mLzmaProps.mMC);
                TR("Lzma2Enc_SetProps:writeEndMark", props.mLzmaProps.mWriteEndMark);
                TR("Lzma2Enc_SetProps:numThreads", props.mLzmaProps.mNumThreads);
                TR("Lzma2Enc_SetProps:blockSize", checked ((int)props.mBlockSize));
                TR("Lzma2Enc_SetProps:numBlockThreads", props.mNumBlockThreads);
                TR("Lzma2Enc_SetProps:numTotalThreads", props.mNumTotalThreads);

                CLzmaEncProps lzmaProps = new CLzmaEncProps(props.mLzmaProps);

                lzmaProps.LzmaEncProps_Normalize();
                if (lzmaProps.mLC + lzmaProps.mLP > LZMA2_LCLP_MAX)
                {
                    return(SZ_ERROR_PARAM);
                }

                mProps = new CLzma2EncProps(props);
                mProps.Lzma2EncProps_Normalize();
                return(SZ_OK);
            }
Beispiel #2
0
 public void Lzma2EncProps_Init()
 {
     mLzmaProps       = CLzmaEncProps.LzmaEncProps_Init();
     mNumTotalThreads = -1;
     mNumBlockThreads = -1;
     mBlockSize       = 0;
 }
Beispiel #3
0
 public void Lzma2EncProps_Init()
 {
     mLzmaProps = CLzmaEncProps.LzmaEncProps_Init();
     mNumTotalThreads = -1;
     mNumBlockThreads = -1;
     mBlockSize = 0;
 }
Beispiel #4
0
 public CLzma2EncProps(CLzma2EncProps other)
 {
     mLzmaProps       = new CLzmaEncProps(other.mLzmaProps);
     mBlockSize       = other.mBlockSize;
     mNumBlockThreads = other.mNumBlockThreads;
     mNumTotalThreads = other.mNumTotalThreads;
 }
Beispiel #5
0
 public CLzma2EncProps(CLzma2EncProps other)
 {
     mLzmaProps = new CLzmaEncProps(other.mLzmaProps);
     mBlockSize = other.mBlockSize;
     mNumBlockThreads = other.mNumBlockThreads;
     mNumTotalThreads = other.mNumTotalThreads;
 }
Beispiel #6
0
        /* ---------- One Call Interface ---------- */
        /* LzmaEncode
        Return code:
          SZ_OK               - OK
          SZ_ERROR_MEM        - Memory allocation error
          SZ_ERROR_PARAM      - Incorrect paramater
          SZ_ERROR_OUTPUT_EOF - output buffer overflow
          SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
        */
        public static SRes LzmaEncode(P<byte> dest, ref long destLen, P<byte> src, long srcLen, CLzmaEncProps props, P<byte> propsEncoded, ref long propsSize, bool writeEndMark, ICompressProgress progress, ISzAlloc alloc, ISzAlloc allocBig)
        {
            CLzmaEnc encoder = LzmaEnc_Create(alloc);
            if (encoder == null)
                return SZ_ERROR_MEM;

            SRes res;
            res = encoder.LzmaEnc_SetProps(props);
            if (res == SZ_OK)
            {
                res = encoder.LzmaEnc_WriteProperties(propsEncoded, ref propsSize);
                if (res == SZ_OK)
                    res = encoder.LzmaEnc_MemEncode(dest, ref destLen, src, srcLen, writeEndMark, progress, alloc, allocBig);
            }

            encoder.LzmaEnc_Destroy(alloc, allocBig);
            return res;
        }
Beispiel #7
0
        /*
         * RAM requirements for LZMA:
         * for compression:   (dictSize * 11.5 + 6 MB) + state_size
         * for decompression: dictSize + state_size
         *  state_size = (4 + (1.5 << (lc + lp))) KB
         *  by default (lc=3, lp=0), state_size = 16 KB.
         *
         * LZMA properties (5 bytes) format
         *  Offset Size  Description
         *    0     1    lc, lp and pb in encoded form.
         *    1     4    dictSize (little endian).
         */

        /*
         * LzmaCompress
         * ------------
         *
         * outPropsSize -
         *   In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
         *   Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
         *
         * LZMA Encoder will use defult values for any parameter, if it is
         * -1  for any from: level, loc, lp, pb, fb, numThreads
         * 0  for dictSize
         *
         * level - compression level: 0 <= level <= 9;
         *
         * level dictSize algo  fb
         *  0:    16 KB   0    32
         *  1:    64 KB   0    32
         *  2:   256 KB   0    32
         *  3:     1 MB   0    32
         *  4:     4 MB   0    32
         *  5:    16 MB   1    32
         *  6:    32 MB   1    32
         *  7+:   64 MB   1    64
         *
         * The default value for "level" is 5.
         *
         * algo = 0 means fast method
         * algo = 1 means normal method
         *
         * dictSize - The dictionary size in bytes. The maximum value is
         *      128 MB = (1 << 27) bytes for 32-bit version
         *        1 GB = (1 << 30) bytes for 64-bit version
         *   The default value is 16 MB = (1 << 24) bytes.
         *   It's recommended to use the dictionary that is larger than 4 KB and
         *   that can be calculated as (1 << N) or (3 << N) sizes.
         *
         * lc - The number of literal context bits (high bits of previous literal).
         *   It can be in the range from 0 to 8. The default value is 3.
         *   Sometimes lc=4 gives the gain for big files.
         *
         * lp - The number of literal pos bits (low bits of current position for literals).
         *   It can be in the range from 0 to 4. The default value is 0.
         *   The lp switch is intended for periodical data when the period is equal to 2^lp.
         *   For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
         *   better to set lc=0, if you change lp switch.
         *
         * pb - The number of pos bits (low bits of current position).
         *   It can be in the range from 0 to 4. The default value is 2.
         *   The pb switch is intended for periodical data when the period is equal 2^pb.
         *
         * fb - Word size (the number of fast bytes).
         *   It can be in the range from 5 to 273. The default value is 32.
         *   Usually, a big number gives a little bit better compression ratio and
         *   slower compression process.
         *
         * numThreads - The number of thereads. 1 or 2. The default value is 2.
         *   Fast mode (algo = 0) can use only 1 thread.
         *
         * Out:
         * destLen  - processed output size
         * Returns:
         * SZ_OK               - OK
         * SZ_ERROR_MEM        - Memory allocation error
         * SZ_ERROR_PARAM      - Incorrect paramater
         * SZ_ERROR_OUTPUT_EOF - output buffer overflow
         * SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
         */

        public static SRes LzmaCompress(
            P <byte> dest, ref long destLen,
            P <byte> src, long srcLen,
            P <byte> outProps, ref long outPropsSize, /* *outPropsSize must be = 5 */
            int level,                                /* 0 <= level <= 9, default = 5 */
            uint dictSize,                            /* default = (1 << 24) */
            int lc,                                   /* 0 <= lc <= 8, default = 3  */
            int lp,                                   /* 0 <= lp <= 4, default = 0  */
            int pb,                                   /* 0 <= pb <= 4, default = 2  */
            int fb,                                   /* 5 <= fb <= 273, default = 32 */
            int numThreads)                           /* 1 or 2, default = 2 */
        {
            var props = CLzmaEncProps.LzmaEncProps_Init();

            props.mLevel      = level;
            props.mDictSize   = dictSize;
            props.mLC         = lc;
            props.mLP         = lp;
            props.mPB         = pb;
            props.mFB         = fb;
            props.mNumThreads = numThreads;

            return(LzmaEncode(dest, ref destLen, src, srcLen, props, outProps, ref outPropsSize, false, null, ISzAlloc.SmallAlloc, ISzAlloc.BigAlloc));
        }
Beispiel #8
0
 internal uint LzmaEncProps_GetDictSize()
 {
     CLzmaEncProps props = new CLzmaEncProps(this);
     props.LzmaEncProps_Normalize();
     return props.mDictSize;
 }
Beispiel #9
0
 public CLzmaEncProps(CLzmaEncProps other)
 {
     this.mLevel = other.mLevel;
     this.mDictSize = other.mDictSize;
     this.mReduceSize = other.mReduceSize;
     this.mLC = other.mLC;
     this.mLP = other.mLP;
     this.mPB = other.mPB;
     this.mAlgo = other.mAlgo;
     this.mFB = other.mFB;
     this.mBtMode = other.mBtMode;
     this.mNumHashBytes = other.mNumHashBytes;
     this.mMC = other.mMC;
     this.mWriteEndMark = other.mWriteEndMark;
     this.mNumThreads = other.mNumThreads;
 }
Beispiel #10
0
            public SRes LzmaEnc_SetProps(CLzmaEncProps props2)
            {
                TR("LzmaEnc_SetProps:level", props2.mLevel);
                TR("LzmaEnc_SetProps:dictSize", props2.mDictSize);
                TR("LzmaEnc_SetProps:lc", props2.mLC);
                TR("LzmaEnc_SetProps:lp", props2.mLP);
                TR("LzmaEnc_SetProps:pb", props2.mPB);
                TR("LzmaEnc_SetProps:algo", props2.mAlgo);
                TR("LzmaEnc_SetProps:fb", props2.mFB);
                TR("LzmaEnc_SetProps:btMode", props2.mBtMode);
                TR("LzmaEnc_SetProps:numHashBytes", props2.mNumHashBytes);
                TR("LzmaEnc_SetProps:mc", props2.mMC);
                TR("LzmaEnc_SetProps:writeEndMark", props2.mWriteEndMark);
                TR("LzmaEnc_SetProps:numThreads", props2.mNumThreads);

                CLzmaEncProps props = new CLzmaEncProps(props2);
                props.LzmaEncProps_Normalize();

                if (props.mLC > LZMA_LC_MAX
                    || props.mLP > LZMA_LP_MAX
                    || props.mPB > LZMA_PB_MAX
                    || props.mDictSize > (1u << kDicLogSizeMaxCompress)
                    || props.mDictSize > (1u << 30))
                    return SZ_ERROR_PARAM;

                mDictSize = props.mDictSize;

                uint fb = (uint)props.mFB;
                if (fb < 5)
                    fb = 5;
                if (fb > LZMA_MATCH_LEN_MAX)
                    fb = LZMA_MATCH_LEN_MAX;
                mNumFastBytes = fb;

                mLC = props.mLC;
                mLP = props.mLP;
                mPB = props.mPB;
                mFastMode = (props.mAlgo == 0);
                mMatchFinderBase.mBtMode = (props.mBtMode != 0);

                uint numHashBytes = 4;
                if (props.mBtMode != 0)
                {
                    if (props.mNumHashBytes < 2)
                        numHashBytes = 2;
                    else if (props.mNumHashBytes < 4)
                        numHashBytes = (uint)props.mNumHashBytes;
                }
                mMatchFinderBase.mNumHashBytes = numHashBytes;

                mMatchFinderBase.mCutValue = props.mMC;

                mWriteEndMark = (props.mWriteEndMark != 0);

#if !_7ZIP_ST
                mMultiThread = (props.mNumThreads > 1);
#endif

                return SZ_OK;
            }
Beispiel #11
0
            public void Lzma2EncProps_Normalize()
            {
                CLzmaEncProps normalizedLzmaProps = new CLzmaEncProps(mLzmaProps);

                normalizedLzmaProps.LzmaEncProps_Normalize();
                int tempThreadsNormalized = normalizedLzmaProps.mNumThreads;
                int tempThreads           = mLzmaProps.mNumThreads;
                int tempBlockThreads      = mNumBlockThreads;
                int tempTotalThreads      = mNumTotalThreads;

                if (tempBlockThreads > NUM_MT_CODER_THREADS_MAX)
                {
                    tempBlockThreads = NUM_MT_CODER_THREADS_MAX;
                }

                if (tempTotalThreads <= 0)
                {
                    if (tempBlockThreads <= 0)
                    {
                        tempBlockThreads = 1;
                    }

                    tempTotalThreads = tempThreadsNormalized * tempBlockThreads;
                }
                else if (tempBlockThreads <= 0)
                {
                    tempBlockThreads = tempTotalThreads / tempThreadsNormalized;

                    if (tempBlockThreads == 0)
                    {
                        tempThreads      = 1;
                        tempBlockThreads = tempTotalThreads;
                    }

                    if (tempBlockThreads > NUM_MT_CODER_THREADS_MAX)
                    {
                        tempBlockThreads = NUM_MT_CODER_THREADS_MAX;
                    }
                }
                else if (tempThreads <= 0)
                {
                    tempThreads = tempTotalThreads / tempBlockThreads;
                    if (tempThreads == 0)
                    {
                        tempThreads = 1;
                    }
                }
                else
                {
                    tempTotalThreads = tempThreadsNormalized * tempBlockThreads;
                }

                mLzmaProps.mNumThreads = tempThreads;
                mNumBlockThreads       = tempBlockThreads;
                mNumTotalThreads       = tempTotalThreads;
                mLzmaProps.LzmaEncProps_Normalize();

                if (mBlockSize == 0)
                {
                    uint dictSize  = mLzmaProps.mDictSize;
                    long blockSize = (long)dictSize << 2;

                    const uint kMinSize = 1 << 20;
                    const uint kMaxSize = 1 << 28;

                    if (blockSize < kMinSize)
                    {
                        blockSize = kMinSize;
                    }

                    if (blockSize > kMaxSize)
                    {
                        blockSize = kMaxSize;
                    }

                    if (blockSize < dictSize)
                    {
                        blockSize = dictSize;
                    }

                    mBlockSize = blockSize;
                }
            }
Beispiel #12
0
            public SRes Lzma2Enc_SetProps(CLzma2EncProps props)
            {
                TR("Lzma2Enc_SetProps:level", props.mLzmaProps.mLevel);
                TR("Lzma2Enc_SetProps:dictSize", props.mLzmaProps.mDictSize);
                TR("Lzma2Enc_SetProps:lc", props.mLzmaProps.mLC);
                TR("Lzma2Enc_SetProps:lp", props.mLzmaProps.mLP);
                TR("Lzma2Enc_SetProps:pb", props.mLzmaProps.mPB);
                TR("Lzma2Enc_SetProps:algo", props.mLzmaProps.mAlgo);
                TR("Lzma2Enc_SetProps:fb", props.mLzmaProps.mFB);
                TR("Lzma2Enc_SetProps:btMode", props.mLzmaProps.mBtMode);
                TR("Lzma2Enc_SetProps:numHashBytes", props.mLzmaProps.mNumHashBytes);
                TR("Lzma2Enc_SetProps:mc", props.mLzmaProps.mMC);
                TR("Lzma2Enc_SetProps:writeEndMark", props.mLzmaProps.mWriteEndMark);
                TR("Lzma2Enc_SetProps:numThreads", props.mLzmaProps.mNumThreads);
                TR("Lzma2Enc_SetProps:blockSize", checked((int)props.mBlockSize));
                TR("Lzma2Enc_SetProps:numBlockThreads", props.mNumBlockThreads);
                TR("Lzma2Enc_SetProps:numTotalThreads", props.mNumTotalThreads);

                CLzmaEncProps lzmaProps = new CLzmaEncProps(props.mLzmaProps);
                lzmaProps.LzmaEncProps_Normalize();
                if (lzmaProps.mLC + lzmaProps.mLP > LZMA2_LCLP_MAX)
                    return SZ_ERROR_PARAM;

                mProps = new CLzma2EncProps(props);
                mProps.Lzma2EncProps_Normalize();
                return SZ_OK;
            }
Beispiel #13
0
            public void Lzma2EncProps_Normalize()
            {
                CLzmaEncProps normalizedLzmaProps = new CLzmaEncProps(mLzmaProps);
                normalizedLzmaProps.LzmaEncProps_Normalize();
                int tempThreadsNormalized = normalizedLzmaProps.mNumThreads;
                int tempThreads = mLzmaProps.mNumThreads;
                int tempBlockThreads = mNumBlockThreads;
                int tempTotalThreads = mNumTotalThreads;

                if (tempBlockThreads > NUM_MT_CODER_THREADS_MAX)
                    tempBlockThreads = NUM_MT_CODER_THREADS_MAX;

                if (tempTotalThreads <= 0)
                {
                    if (tempBlockThreads <= 0)
                        tempBlockThreads = 1;

                    tempTotalThreads = tempThreadsNormalized * tempBlockThreads;
                }
                else if (tempBlockThreads <= 0)
                {
                    tempBlockThreads = tempTotalThreads / tempThreadsNormalized;

                    if (tempBlockThreads == 0)
                    {
                        tempThreads = 1;
                        tempBlockThreads = tempTotalThreads;
                    }

                    if (tempBlockThreads > NUM_MT_CODER_THREADS_MAX)
                        tempBlockThreads = NUM_MT_CODER_THREADS_MAX;
                }
                else if (tempThreads <= 0)
                {
                    tempThreads = tempTotalThreads / tempBlockThreads;
                    if (tempThreads == 0)
                        tempThreads = 1;
                }
                else
                {
                    tempTotalThreads = tempThreadsNormalized * tempBlockThreads;
                }

                mLzmaProps.mNumThreads = tempThreads;
                mNumBlockThreads = tempBlockThreads;
                mNumTotalThreads = tempTotalThreads;
                mLzmaProps.LzmaEncProps_Normalize();

                if (mBlockSize == 0)
                {
                    uint dictSize = mLzmaProps.mDictSize;
                    long blockSize = (long)dictSize << 2;

                    const uint kMinSize = 1 << 20;
                    const uint kMaxSize = 1 << 28;

                    if (blockSize < kMinSize)
                        blockSize = kMinSize;

                    if (blockSize > kMaxSize)
                        blockSize = kMaxSize;

                    if (blockSize < dictSize)
                        blockSize = dictSize;

                    mBlockSize = blockSize;
                }
            }