本文整理汇总了C++中compress2函数的典型用法代码示例。如果您正苦于以下问题:C++ compress2函数的具体用法?C++ compress2怎么用?C++ compress2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compress2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: run
static void
run (int format, gboolean alpha)
{
guint8 data[2000] = { 0, };
guint8 compressed[2000] = { 0, };
gsize len;
gulong clen;
int ret;
char *s;
switch (format) {
case 3:
len = create_palletized (data, alpha);
g_print ("%u\n", len);
break;
default:
g_assert_not_reached ();
return;
}
if (alpha) {
clen = sizeof (compressed);
ret = compress2 (compressed, &clen, data, len, 9);
} else {
clen = sizeof (compressed) - 1;
ret = compress2 (compressed + 1, &clen, data + 1, len - 1, 9);
compressed[0] = data[0];
}
g_assert (ret == Z_OK);
s = g_base64_encode (compressed, clen + 1);
g_print ("%s\n\n", s);
g_free (s);
}
开发者ID:fengye,项目名称:swfdec,代码行数:34,代码来源:definebits-palette-base64.c
示例2: compress2_cmd
static TACommandVerdict compress2_cmd(TAThread thread,TAInputStream stream)
{
Bytef * dest, *source;
uLongf destLen, sourceLen;
int res, level;
dest = readPointer(&stream);
destLen = readULong(&stream);
source = readPointer(&stream);
sourceLen = readULong(&stream);
level = readInt(&stream);
ta_debug_printf("level==%d\n", level);
ta_debug_printf("source==%s\n", source);
START_TARGET_OPERATION(thread);
if(level==-1)
res = compress2(dest, &destLen, source, sourceLen,
Z_DEFAULT_COMPRESSION);
else
res = compress2(dest, &destLen, source, sourceLen, level);
END_TARGET_OPERATION(thread);
ta_debug_printf("dest==%s\n", dest);
writePointer(thread, dest);
writeULong(thread, destLen);
writeInt(thread, res);
sendResponse(thread);
return taDefaultVerdict;
}
开发者ID:levenkov,项目名称:olver,代码行数:35,代码来源:compress_agent.c
示例3: compress
bool compress(uint8 *dst, size_t &dst_size, const uint8 *src, size_t src_size,
level l)
{
return Z_OK == compress2(reinterpret_cast<Bytef*>(dst), reinterpret_cast<uLongf*>(&dst_size),
reinterpret_cast<const Bytef*>(src), static_cast<uLong>(src_size),
static_cast<int>(l));
}
开发者ID:Exodius,项目名称:chuspi,代码行数:7,代码来源:Compress.cpp
示例4: rdwr_writeRaw
//Deryabin Andrew: vst chunks support
template <typename T> void
rdwr_writeRaw(T fd, std::vector<char> rawdata, const char *file, int line)
{
unsigned long complen = compressBound(rawdata.size());
char *compressed = new char [complen];
if(!compressed)
{
fprintf(stderr, "Failed to allocate %lu bytes of memory at %s:%d\n", complen, file, line);
throw RemotePluginClosedException();
}
std::vector<char>::pointer ptr = &rawdata [0];
if(compress2((Bytef *)compressed, &complen, (Bytef *)ptr, rawdata.size(), 9) != Z_OK)
{
delete compressed;
fprintf(stderr, "Failed to compress source buffer at %s:%d\n", file, line);
throw RemotePluginClosedException();
}
fprintf(stderr, "compressed source buffer. size=%lu bytes\n", complen);
int len = complen;
rdwr_tryWrite(fd, &len, sizeof(int), file, line);
len = rawdata.size();
rdwr_tryWrite(fd, &len, sizeof(int), file, line);
rdwr_tryWrite(fd, compressed, complen, file, line);
delete [] compressed;
}
开发者ID:GomesMarcos,项目名称:dssi-vst,代码行数:31,代码来源:rdwrops.cpp
示例5: compress_buffer
/*
* Function: compress_buffer
* Purpose: Compress the buffer.
* Returns: Z_OK - success
* Z_MEM_ERROR - not enough memory
* Z_BUF_ERROR - not enough room in the output buffer
* Z_STREAM_ERROR - level parameter is invalid
* Programmer: Bill Wendling, 05. June 2002
* Modifications:
*/
static void
compress_buffer(Bytef *dest, uLongf *destLen, const Bytef *source,
uLong sourceLen)
{
int rc = compress2(dest, destLen, source, sourceLen, compress_level);
if (rc != Z_OK) {
/* compress2 failed - cleanup and tell why */
cleanup();
switch (rc) {
case Z_MEM_ERROR:
error("not enough memory");
break;
case Z_BUF_ERROR:
error("not enough room in the output buffer");
break;
case Z_STREAM_ERROR:
error("level parameter (%d) is invalid", compress_level);
break;
default:
error("unknown compression error");
break;
}
}
}
开发者ID:FilipeMaia,项目名称:hdf5,代码行数:36,代码来源:zip_perf.c
示例6: compress_packet
static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
if(level == 0) {
memcpy(dest, source, len);
return len;
} else if(level == 10) {
#ifdef HAVE_LZO
lzo_uint lzolen = MAXSIZE;
lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem);
return lzolen;
#else
return -1;
#endif
} else if(level < 10) {
#ifdef HAVE_ZLIB
unsigned long destlen = MAXSIZE;
if(compress2(dest, &destlen, source, len, level) == Z_OK)
return destlen;
else
#endif
return -1;
} else {
#ifdef HAVE_LZO
lzo_uint lzolen = MAXSIZE;
lzo1x_999_compress(source, len, dest, &lzolen, lzo_wrkmem);
return lzolen;
#else
return -1;
#endif
}
return -1;
}
开发者ID:dtaht,项目名称:tinc,代码行数:32,代码来源:net_packet.c
示例7: gzip_compress_buf
static void gzip_compress_buf(struct stream *s, int *c_type, i64 *c_len)
{
uchar *c_buf;
unsigned long dlen = s->buflen;
c_buf = malloc(dlen);
if (!c_buf)
return;
if (compress2(c_buf, &dlen, s->buf, s->buflen, control.compression_level) != Z_OK) {
free(c_buf);
return;
}
if ((i64)dlen >= *c_len) {
/* Incompressible, leave as CTYPE_NONE */
free(c_buf);
return;
}
*c_len = dlen;
free(s->buf);
s->buf = c_buf;
*c_type = CTYPE_GZIP;
}
开发者ID:epa,项目名称:lrzip,代码行数:25,代码来源:stream.c
示例8: writeDat
static void writeDat( std::ofstream & os, const std::vector<char> & data ) {
std::vector<char> cdata( data.size() );
uLongf len = data.size();
compress2( (Bytef*)cdata.data(), &len, (const Bytef*)data.data(), data.size(), 9 );
cdata.resize( len );
writeChunk( os, "IDAT", cdata );
}
开发者ID:ClarkWang12,项目名称:object-proposals,代码行数:7,代码来源:apng.cpp
示例9: TestCompress
void
TestCompress(CuTest * tc)
{
char input[] =
{
"This is a test input string. I like to test inputThis is a test input string. I like to test input."
};
uLongf output_len = 2000;
void *output = malloc(output_len);
uLongf input_len = (uLongf) strlen(input);
/**
* Attempt the compression.
*/
int ret =
compress2(output, &output_len, (void *)input, input_len,
Z_BEST_SPEED);
/**
* Assert it 1. Worked.
*/
CuAssertTrue(tc, ret == Z_OK);
/**
* The output size is smaller than the input size.
*/
CuAssertTrue(tc, output_len < input_len);
free(output);
}
开发者ID:novakovic,项目名称:redis-fs,代码行数:31,代码来源:zlib_test.c
示例10: TestDecompress
/**
* Attempt to compress and decompress.
*/
void
TestDecompress(CuTest * tc)
{
char input[] =
{
"This is a test input string. I like to test inputThis is a test input string. I like to test input."
};
uLongf input_len = (uLongf) strlen(input);
uLongf compressed_len = 2000;
void *compressed = malloc(compressed_len);
uLongf decompressed_len = 2000;
void *decompressed = malloc(decompressed_len);
/**
* Attempt the compression.
*/
int ret =
compress2(compressed, &compressed_len, (void *)input, input_len,
Z_BEST_SPEED);
/**
* Assert it 1. Worked.
*/
CuAssertTrue(tc, ret == Z_OK);
/**
* The output size is smaller than the input size.
*/
CuAssertTrue(tc, compressed_len < input_len);
/**
* OK now we decompress.
*/
ret =
uncompress(decompressed, &decompressed_len, (void *)compressed,
compressed_len);
/**
* Assert: 1. it worked.
*/
CuAssertTrue(tc, ret == Z_OK);
/**
* 2. Output is longer than the input.
*/
CuAssertTrue(tc, compressed_len < decompressed_len);
/**
* 3. Ouptut is equal to original starting point.
*/
CuAssertTrue(tc, decompressed_len == input_len);
CuAssertTrue(tc, (strcmp(decompressed, input) == 0));
free(compressed);
free(decompressed);
}
开发者ID:novakovic,项目名称:redis-fs,代码行数:63,代码来源:zlib_test.c
示例11: compressBound
void ZlibCompressor::Compress(std::string& compressed,
const void* uncompressed,
size_t uncompressedSize)
{
if (uncompressedSize == 0)
{
compressed.clear();
return;
}
uLongf compressedSize = compressBound(uncompressedSize) + 1024 /* security margin */;
if (compressedSize == 0)
{
compressedSize = 1;
}
uint8_t* target;
if (HasPrefixWithUncompressedSize())
{
compressed.resize(compressedSize + sizeof(uint64_t));
target = reinterpret_cast<uint8_t*>(&compressed[0]) + sizeof(uint64_t);
}
else
{
compressed.resize(compressedSize);
target = reinterpret_cast<uint8_t*>(&compressed[0]);
}
int error = compress2(target,
&compressedSize,
const_cast<Bytef *>(static_cast<const Bytef *>(uncompressed)),
uncompressedSize,
GetCompressionLevel());
if (error != Z_OK)
{
compressed.clear();
switch (error)
{
case Z_MEM_ERROR:
throw OrthancException(ErrorCode_NotEnoughMemory);
default:
throw OrthancException(ErrorCode_InternalError);
}
}
// The compression was successful
if (HasPrefixWithUncompressedSize())
{
uint64_t s = static_cast<uint64_t>(uncompressedSize);
memcpy(&compressed[0], &s, sizeof(uint64_t));
compressed.resize(compressedSize + sizeof(uint64_t));
}
else
{
compressed.resize(compressedSize);
}
}
开发者ID:milhcbt,项目名称:OrthancMirror,代码行数:60,代码来源:ZlibCompressor.cpp
示例12: dbg_assert
int CDataFileWriter::AddData(int Size, void *pData)
{
if(!m_File) return 0;
dbg_assert(m_NumDatas < 1024, "too much data");
CDataInfo *pInfo = &m_pDatas[m_NumDatas];
unsigned long s = compressBound(Size);
void *pCompData = mem_alloc(s, 1); // temporary buffer that we use during compression
int Result = compress2((Bytef*)pCompData, &s, (Bytef*)pData, Size, CompressionLevel); // ignore_convention
if(Result != Z_OK)
{
dbg_msg("datafile", "compression error %d", Result);
dbg_assert(0, "zlib error");
}
pInfo->m_UncompressedSize = Size;
pInfo->m_CompressedSize = (int)s;
pInfo->m_pCompressedData = mem_alloc(pInfo->m_CompressedSize, 1);
mem_copy(pInfo->m_pCompressedData, pCompData, pInfo->m_CompressedSize);
mem_free(pCompData);
m_NumDatas++;
return m_NumDatas-1;
}
开发者ID:ftk,项目名称:XXLDDRace,代码行数:26,代码来源:datafile.cpp
示例13: segment_compress
int segment_compress(int *source, int size, char *compress_source, long int *compress_size)
{
int err;
uLong sourceLen = (uLongf)size;
uLongf destLen = (uLongf)(*compress_size);
Bytef *byte_source;
Bytef *byte_dest;
byte_source = (Bytef *)source;
byte_dest = (Bytef *)compress_source;
err = compress2(byte_dest, &destLen, byte_source, sourceLen, COMPRESS_LEVEL);
if(err != Z_OK) {
printf("ERROR: Error compress!\n");
if(err == Z_BUF_ERROR)
printf("ERROR: The buffer was not large enough to hold the uncompressed data.\n");
if(err == Z_MEM_ERROR)
printf("ERROR: Insufficient memory.\n");
if(err == Z_STREAM_ERROR)
printf("ERROR: The compressed data (referenced by source) was corrupted.\n");
}
*compress_size = (long int)destLen;
return 0;
}
开发者ID:elena-ivanova,项目名称:colomnindices,代码行数:28,代码来源:cicompress.c
示例14: compress
std::vector<uint8_t> compress(const std::vector<uint8_t> & input, int level)
{
uLongf destlen = input.size();
std::vector<uint8_t> output;
output.resize(2 * input.size());
Bytef* dest = reinterpret_cast<Bytef*>(&output.front());
uLongf srclen = input.size();
const Bytef* src = input.data();
int ret = ::compress2(dest, &destlen, src, srclen, level);
// realloc a larger buffer if the current one is too small
while (ret == Z_BUF_ERROR)
{
output.resize(2 * output.size());
dest = reinterpret_cast<Bytef*>(&output.front());
destlen = output.size();
dest = reinterpret_cast<Bytef*>(&output.front());
ret = compress2(dest, &destlen, src, srclen, level);
}
output.resize(destlen);
output.shrink_to_fit();
return output;
}
开发者ID:CCJY,项目名称:coliru,代码行数:27,代码来源:main.cpp
示例15: nekoAssert
/// Compress data by Zlib
bool nekoByteBuffer::Compress(int32 level)
{
nekoAssert(level >= 0 && level <= 9, "압축 레벨은 0과 9 사이의 정수 입니다.");
// No data
if(!length)
return false;
// Compress it.
int32 destLen;
char8 *destData = nekoNew char8[(destLen = (int32)((length + 12) * 1.1)) + sizeof(int32)];
if(compress2((Bytef *)(destData + sizeof(int32)), (uLongf *)&destLen, (Bytef *)buf, (uLongf)length, level) != Z_OK)
{
delete []destData;
return false;
}
SafeDeleteArray(buf);
// 앞부분에 원래 길이 넣어두기
memcpy(destData, &length, sizeof(int32));
buf = destData;
length = destLen + sizeof(int32);
writePos = length;
return true;
}
开发者ID:ZHANITEST,项目名称:nekonovel,代码行数:27,代码来源:nekoByteBuffer.cpp
示例16: try_compression
/**
* Try to compress the given block of data.
*
* @param data block to compress; if compression
* resulted in a smaller block, the first
* bytes of data are updated to the compressed
* data
* @param oldSize number of bytes in data
* @param result set to the compressed data
* @param newSize set to size of result
* @return GNUNET_YES if compression reduce the size,
* GNUNET_NO if compression did not help
*/
static int
try_compression (const char *data, size_t oldSize, char **result,
size_t * newSize)
{
char *tmp;
uLongf dlen;
#ifdef compressBound
dlen = compressBound (oldSize);
#else
dlen = oldSize + (oldSize / 100) + 20;
/* documentation says 100.1% oldSize + 12 bytes, but we
* should be able to overshoot by more to be safe */
#endif
tmp = GNUNET_malloc (dlen);
if (Z_OK ==
compress2 ((Bytef *) tmp, &dlen, (const Bytef *) data, oldSize, 9))
{
if (dlen < oldSize)
{
*result = tmp;
*newSize = dlen;
return GNUNET_YES;
}
}
GNUNET_free (tmp);
return GNUNET_NO;
}
开发者ID:h4ck3rm1k3,项目名称:gnunet-debian,代码行数:41,代码来源:container_meta_data.c
示例17: compress_str2
/**
* Compress two strings and return the length of the compressed data
* @param x String x
* @param y String y
* @return length of the compressed data.
*/
static float compress_str2(hstring_t x, hstring_t y)
{
unsigned long tmp, width;
unsigned char *src, *dst;
assert(x.type == y.type);
width = x.type == TYPE_SYM ? sizeof(sym_t) : sizeof(char);
tmp = compressBound((x.len + y.len) * width);
dst = malloc(tmp);
src = malloc(tmp);
if (!src || !dst) {
error("Failed to allocate memory for compression");
return -1;
}
/* Concatenate sequences y and x */
memcpy(src, y.str.s, y.len * width);
memcpy(src + y.len * width, x.str.s, x.len * width);
compress2(dst, &tmp, src, (x.len + y.len) * width, level);
free(dst);
free(src);
return (float) tmp;
}
开发者ID:MLDroid,项目名称:harry,代码行数:33,代码来源:dist_compression.c
示例18: packet_add_tlv_raw_compressed
/*
* Add an arbitrary TLV whose data is to be compressed with zlib.
*/
DWORD packet_add_tlv_raw_compressed(Packet *packet, TlvType type, LPVOID buf, DWORD length)
{
DWORD result = ERROR_SUCCESS;
DWORD headerLength = sizeof( TlvHeader );
PUCHAR newPayload = NULL;
BYTE * compressed_buf = NULL;
DWORD realLength = 0;
DWORD newPayloadLength = 0;
DWORD compressed_length = (DWORD)( 1.01 * ( length + 12 ) + 1 );
do
{
compressed_buf = (BYTE *)malloc( compressed_length );
if( !compressed_buf )
{
result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
if( compress2( compressed_buf, &compressed_length, buf, length, Z_BEST_COMPRESSION ) != Z_OK )
{
result = ERROR_UNSUPPORTED_COMPRESSION;
break;
}
realLength = compressed_length + headerLength;
newPayloadLength = packet->payloadLength + realLength;
// Allocate/Reallocate the packet's payload
if( packet->payload )
newPayload = (PUCHAR)realloc(packet->payload, newPayloadLength);
else
newPayload = (PUCHAR)malloc(newPayloadLength);
if( !newPayload )
{
result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
// Populate the new TLV
((LPDWORD)(newPayload + packet->payloadLength))[0] = htonl(realLength);
((LPDWORD)(newPayload + packet->payloadLength))[1] = htonl((DWORD)type);
memcpy(newPayload + packet->payloadLength + headerLength, compressed_buf, compressed_length );
// Update the header length and payload length
packet->header.length = htonl(ntohl(packet->header.length) + realLength);
packet->payload = newPayload;
packet->payloadLength = newPayloadLength;
result = ERROR_SUCCESS;
} while( 0 );
if( compressed_buf )
free( compressed_buf );
return result;
}
开发者ID:2uro,项目名称:metasploit-4.-.-,代码行数:63,代码来源:core.c
示例19: CompressBinaryDump
// -----------------------------------------------------------------------------------
// Compress a binary dump file (beginning at offset head_size)
void CompressBinaryDump(const char* file, unsigned int head_size)
{
// for simplicity ... copy the file into memory again and compress it there
FILE* p = fopen(file,"r");
fseek(p,0,SEEK_END);
const uint32_t size = ftell(p);
fseek(p,0,SEEK_SET);
if (size<head_size) {
fclose(p);
return;
}
uint8_t* data = new uint8_t[size];
fread(data,1,size,p);
uLongf out_size = (uLongf)((size-head_size) * 1.001 + 12.);
uint8_t* out = new uint8_t[out_size];
compress2(out,&out_size,data+head_size,size-head_size,9);
fclose(p);
p = fopen(file,"w");
fwrite(data,head_size,1,p);
fwrite(&out_size,4,1,p); // write size of uncompressed data
fwrite(out,out_size,1,p);
fclose(p);
delete[] data;
delete[] out;
}
开发者ID:tonttu,项目名称:assimp,代码行数:33,代码来源:WriteDumb.cpp
示例20: CompressZLIB
// Quality comes in 0-100, while the zlib param needs to be 0-9
CPLErr CompressZLIB(buf_mgr &dst, buf_mgr &src, const ILImage &img)
{
if (Z_OK==compress2((Bytef *)dst.buffer,(uLongf *)&dst.size,
(Bytef *)src.buffer,src.size,img.quality/10)) return CE_None;
CPLError(CE_Failure,CPLE_AppDefined,"MRF: Error during zlib compression");
return CE_Failure;
}
开发者ID:mike-mcgann,项目名称:onearth,代码行数:8,代码来源:ZLIB_band.cpp
注:本文中的compress2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论