int64_t lzbench_lzo1x_compress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t level, size_t, char* workmem) { lzo_uint lzo_complen = 0; int res; if (!workmem) return 0; switch (level) { default: case 1: res = lzo1x_1_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &lzo_complen, (void*)workmem); break; case 11: res = lzo1x_1_11_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &lzo_complen, (void*)workmem); break; case 12: res = lzo1x_1_12_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &lzo_complen, (void*)workmem); break; case 15: res = lzo1x_1_15_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &lzo_complen, (void*)workmem); break; case 999: res = lzo1x_999_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &lzo_complen, (void*)workmem); break; } if (res != LZO_E_OK) return 0; return lzo_complen; }
enum ral_status f_lzo_compress(char *dest, size_t *destLen, const char *source, size_t sourceLen, void *param){ enum ral_status ret; if (lzo_init() != LZO_E_OK){ return RAL_EUNKNOWN; } unsigned char *workingMemory = (unsigned char*)malloc(LZO1X_1_11_MEM_COMPRESS); if( workingMemory == NULL ){ return RAL_ENOT_ENOUGH_MEM; } int res = lzo1x_1_11_compress((const unsigned char *)source, sourceLen, (unsigned char *)dest, destLen, workingMemory); switch (res){ case LZO_E_OK: ret = RAL_OK; break; default: ret = RAL_EUNKNOWN; break; } free(workingMemory); return ret; }
//--------------------------------------------------------------------------- LZO1X & LZO1X::compress(AutoPtrBuffer & buf,uint8_t * & p,int32_t & len) { int r = 0; lzo_uint dst_len = 0; if( level_ > 0 ){ buf.realloc(wBufPos_ + wBufPos_ / 16 + 64 + 3 + sizeof(int32_t) * 2 + (crc_ != CRCNone) * sizeof(uint32_t)); switch( method_ ){ case LZO1X_1 : r = lzo1x_1_compress( (const lzo_bytep) (wBuf_.ptr() + sizeof(int32_t)), wBufPos_, (lzo_bytep) (buf.ptr() + sizeof(int32_t) * 2), &dst_len, (lzo_voidp) wWrkMem_.ptr() ); break; case LZO1X_1_11 : r = lzo1x_1_11_compress( (const lzo_bytep) (wBuf_.ptr() + sizeof(int32_t)), wBufPos_, (lzo_bytep) (buf.ptr() + sizeof(int32_t) * 2), &dst_len, (lzo_voidp) wWrkMem_.ptr() ); break; case LZO1X_1_12 : r = lzo1x_1_11_compress( (const lzo_bytep) (wBuf_.ptr() + sizeof(int32_t)), wBufPos_, (lzo_bytep) (buf.ptr() + sizeof(int32_t) * 2), &dst_len, (lzo_voidp) wWrkMem_.ptr() ); break; case LZO1X_1_15 : r = lzo1x_1_15_compress( (const lzo_bytep) (wBuf_.ptr() + sizeof(int32_t)), wBufPos_, (lzo_bytep) (buf.ptr() + sizeof(int32_t) * 2), &dst_len, (lzo_voidp) wWrkMem_.ptr() ); break; case LZO1X_999 : r = lzo1x_999_compress_level( (const lzo_bytep) (wBuf_.ptr() + sizeof(int32_t)), wBufPos_, (lzo_bytep) (buf.ptr() + sizeof(int32_t) * 2), &dst_len, (lzo_voidp) wWrkMem_.ptr(), NULL, 0, NULL, level_ ); break; default : assert( 0 ); } assert( r == LZO_E_OK ); if( r != LZO_E_OK ) newObjectV1C2<Exception>(EINVAL,__PRETTY_FUNCTION__)->throwSP(); if( dst_len >= wBufPos_ ) goto l1; if( optimize_ ){ lzo_uint orig_len = wBufPos_; r = lzo1x_optimize( (lzo_bytep) (buf.ptr() + sizeof(int32_t) * 2), dst_len, (lzo_bytep) (wBuf_.ptr() + sizeof(int32_t)), &orig_len, NULL ); assert( r == LZO_E_OK ); } if( crc_ != CRCNone ){ lzo_uint32 checksum = 0; if( crc_ == CRC32 ){ checksum = lzo_crc32(0,NULL,0); checksum = lzo_crc32(checksum,buf.ptr() + sizeof(int32_t) * 2,dst_len); } else if( crc_ == ADLER32 ){ checksum = lzo_adler32(0,NULL,0); checksum = lzo_adler32(checksum,buf.ptr() + sizeof(int32_t) * 2,dst_len); } *(uint32_t *)(buf.ptr() + sizeof(int32_t) * 2 + dst_len) = checksum; } dst_len += sizeof(int32_t) * 2 + (crc_ != CRCNone) * sizeof(uint32_t); ((int32_t *) buf.ptr())[0] = (int32_t) dst_len; ((int32_t *) buf.ptr())[1] = wBufPos_; p = buf; len = (int32_t) dst_len; } else { l1: ((int32_t *) wBuf_.ptr())[0] = -int32_t(wBufPos_); p = wBuf_; len = (int32_t) (wBufPos_ + sizeof(int32_t)); } return *this; }