Ejemplo n.º 1
0
SWORD_NAMESPACE_START

/******************************************************************************
 * XzCompress Constructor - Initializes data for instance of XzCompress
 *
 */

XzCompress::XzCompress() : SWCompress() {
	level = 3;
	
	// start with the estimated memory usage for our preset
	memlimit = lzma_easy_decoder_memusage(level | LZMA_PRESET_EXTREME);
	
	// and round up to a power of 2--
	// bit twiddle hack to determine next greatest power of 2 from:
	// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
	memlimit--;
	memlimit |= memlimit >> 1;
	memlimit |= memlimit >> 2;
	memlimit |= memlimit >> 4;
	memlimit |= memlimit >> 8;
	memlimit |= memlimit >> 16;
	memlimit++;

	// double that for safety's sake
	memlimit <<= 1;
}
Ejemplo n.º 2
0
    int LzmaConnectorReader::resetConnectorReader (void)
    {
        lzma_end (&_lzmaDecompStream);

        resetDecompStream();

        if (LZMA_OK != lzma_stream_decoder (&_lzmaDecompStream, lzma_easy_decoder_memusage (getCompressionLevel()), DECODER_FLAGS)) {
            return -1;
        }

        return 0;
    }
Ejemplo n.º 3
0
    LzmaConnectorReader::LzmaConnectorReader (const CompressionSettings & compressionSettings, unsigned int ulInBufSize, unsigned int ulOutBufSize) :
        ConnectorReader{compressionSettings}
    {
         if ((ulOutBufSize == 0) || (ulInBufSize == 0) ||
             (nullptr == (_pOutputBuffer = new unsigned char[ulOutBufSize])) ||
             (nullptr == (_pInputBuffer = new unsigned char[ulInBufSize]))) {
            // throw a c++ exception here
        }
        _ulInBufSize = ulInBufSize;
        _ulOutBufSize = ulOutBufSize;

        resetDecompStream();

        if (LZMA_OK != lzma_stream_decoder (&_lzmaDecompStream, lzma_easy_decoder_memusage (getCompressionLevel()), DECODER_FLAGS)) {
            // throw a c++ exception here
        }
    }
Ejemplo n.º 4
0
void XzCompress::setLevel(int l) {
	level = l;

	// having changed the compression level, we need to adjust our memlimit accordingly,
	// as in the constructor:

	// start with the estimated memory usage for our preset
	memlimit = lzma_easy_decoder_memusage(level | LZMA_PRESET_EXTREME);
	
	// and round up to a power of 2--
	// bit twiddle hack to determine next greatest power of 2 from:
	// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
	memlimit--;
	memlimit |= memlimit >> 1;
	memlimit |= memlimit >> 2;
	memlimit |= memlimit >> 4;
	memlimit |= memlimit >> 8;
	memlimit |= memlimit >> 16;
	memlimit++;

	// double that for safety's sake
	memlimit <<= 1;
};
Ejemplo n.º 5
0
Handle<Value> lzmaEasyDecoderMemusage(const Arguments& args) {
	HandleScope scope;
	Local<Integer> arg = Local<Integer>::Cast(args[0]);
	
	return scope.Close(Uint64ToNumberMaxNull(lzma_easy_decoder_memusage(arg->Value())));
}