当前位置: 首页>>代码示例>>C++>>正文


C++ compressBound函数代码示例

本文整理汇总了C++中compressBound函数的典型用法代码示例。如果您正苦于以下问题:C++ compressBound函数的具体用法?C++ compressBound怎么用?C++ compressBound使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了compressBound函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: writeCompressedPeaks

    void writeCompressedPeaks(SpectrumPtr s, ostream& os)
    {
        // Build arrays to hold peaks prior to compression
        int numPeaks = (int) s->defaultArrayLength;
        double *pD = new double[numPeaks];
        float *pF = new float[numPeaks];

        const BinaryDataArray& mzArray = *s->getMZArray();
        const BinaryDataArray& intensityArray = *s->getIntensityArray();
        for(int j = 0; j < numPeaks; j++)
        {
            pD[j] = mzArray.data[j];
            pF[j] = (float) intensityArray.data[j];
        }

        // compress mz
        uLong sizeM = (uLong) (numPeaks * sizeDoubleMSn);
        uLong comprLenM = compressBound(sizeM);
        Byte *comprM = (Byte*)calloc((uInt)comprLenM, 1);
        int retM = compress(comprM, &comprLenM, (const Bytef*)pD, sizeM);
        
        // compress intensity
        uLong sizeI = (uLong) (numPeaks * sizeFloatMSn);
        uLong comprLenI = compressBound(sizeI);
        Byte *comprI = (Byte*)calloc((uInt)comprLenI, 1);
        int retI = compress(comprI, &comprLenI, (const Bytef*)pF, sizeI);

        // Write the compressed peaks if all is well
        if ((Z_OK == retM) && (Z_OK == retI))
        {
            // write length of compressed array of m/z
            os.write(reinterpret_cast<char *>(&comprLenM), sizeIntMSn);

            // write length of compressed array of intensities
            os.write(reinterpret_cast<char *>(&comprLenI), sizeIntMSn);

            // write compressed array of m/z
            os.write(reinterpret_cast<char *>(comprM), comprLenM);

            // write compressed array of intensities
            os.write(reinterpret_cast<char *>(comprI), comprLenI);
        }

        // Clean up memory
        free(comprM);
        free(comprI);
        delete [] pD;
        delete [] pF;
        
        // In case of error, throw exception AFTER cleaning up memory
        if (Z_OK != retM || Z_OK != retI)
        {
            throw runtime_error("[Serializer_MSn::writeCompressedPeaks] Error compressing peaks.");
        }
    }
开发者ID:zjjyyang,项目名称:ftdr,代码行数:55,代码来源:Serializer_MSn.cpp

示例2: 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

示例3: compress

	//	圧縮
	std::vector<byte> compress(ArrayRef<byte> src, int level) {
		//	レベルを[1, 9]にクリップ
		level = clamp(level, 1, 9);

		//	データを格納するバッファの確保
		std::vector<byte> data;
		data.resize(compressBound(static_cast<uLong>(src.size())));

		//	初期化
		z_stream zs		= {};
		zs.next_in		= const_cast<byte*>(src.data());	//	データは書き換えられない
		zs.avail_in		= static_cast<uInt>(src.size());
		zs.next_out		= &data[0];
		zs.avail_out	= data.size();

		if(deflateInit2(&zs, level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY))
			BELL_THROW(DeflateError, "Failed to initialize compress stream.");

		//	圧縮
		int res = ::deflate(&zs, Z_FINISH);

		data.resize(zs.total_out);

		//	片付け
		deflateEnd(&zs);
		if(res != Z_STREAM_END)
			BELL_THROW(DeflateError, "Failed to compress.");

		return data;
	}
开发者ID:unvBell,项目名称:Bell,代码行数:31,代码来源:Deflate.cpp

示例4: lumberjack_init

struct lumberjack *lumberjack_new(const char *host, unsigned short port, size_t window_size) {
  struct lumberjack *lumberjack;
  lumberjack_init(); /* global one-time init */

  lumberjack = malloc(sizeof(struct lumberjack));
  lumberjack->host = host;
  lumberjack->port = port;
  lumberjack->fd = -1;
  lumberjack->sequence = 0; //rand();
  lumberjack->ssl = NULL;
  lumberjack->connected = 0;

  /* I tried with 128, 256, 512, 1024, 2048, and 16384,
   * in a local network, an window size of 1024 seemed to have the best
   * performance (equal to 2048 and 16384) for the least memory cost. */
  if (window_size < 1024) {
    flog(stdout, "Window size less than 1024 (%d) isn't shown to have " \
         "speed-performance benefits", window_size);
  }

  lumberjack->ring_size = window_size;
  lumberjack->ring = ring_new_size(lumberjack->ring_size);

  /* Create this once. */
  lumberjack->ssl_context = SSL_CTX_new(SSLv23_client_method());
  SSL_CTX_set_verify(lumberjack->ssl_context, SSL_VERIFY_PEER, NULL);

  lumberjack->io_buffer = str_new_size(16384); /* TODO(sissel): tunable */

  /* zlib provides compressBound() to give a 'worst case' compressed
   * payload size on a input payload of a given size. */
  lumberjack->compression_buffer = str_new_size(compressBound(16384));
  return lumberjack;
} /* lumberjack_new */
开发者ID:ChimeraCoder,项目名称:golang-stuff,代码行数:34,代码来源:proto.c

示例5: LUA_C_zlib_compress

static int LUA_C_zlib_compress(lua_State* ls)
  {
  size_t l = 0;
  auto s = luaL_checklstring(ls, 1, &l);

  if(l == 0)
    {
    lua_pushstring(ls, "");
    return 1;
    }
  string cp;
  cp.reserve(compressBound(l));
  while(true)
    {
    size_t size = cp.capacity();
    const intptr_t rets = compress(
      (Bytef*)cp.end()._Ptr,
      (uLongf*)&size,
      (const Bytef*)s,
      (uLongf)l);
    switch(rets)
      {
      case Z_OK:
        lua_pushlstring(ls, cp.end()._Ptr, size);
        return 1;
      case Z_BUF_ERROR:
        cp.reserve(cp.capacity() + 0x10);
        continue;
      default:
        break;
      }
    lua_pushstring(ls, (xmsg() << "zlibѹËõʧ°Ü : " << rets).c_str());
    return lua_error(ls);
    }
  }
开发者ID:tempbottle,项目名称:xlualib,代码行数:35,代码来源:lzlib.cpp

示例6: ASSERT

//! Compresses another packet and stores it in self (source left intact)
void WorldPacket::Compress(z_stream* compressionStream, WorldPacket const* source)
{
    ASSERT(source != this);

    Opcodes uncompressedOpcode = source->GetOpcode();
    if (uncompressedOpcode & COMPRESSED_OPCODE_MASK)
    {
        sLog->outError(LOG_FILTER_NETWORKIO, "Packet with opcode 0x%04X is already compressed!", uncompressedOpcode);
        return;
    }

    Opcodes opcode = Opcodes(uncompressedOpcode | COMPRESSED_OPCODE_MASK);
    uint32 size = source->size();
    uint32 destsize = compressBound(size);

    size_t sizePos = 0;
    resize(destsize + sizeof(uint32));

    _compressionStream = compressionStream;
    Compress(static_cast<void*>(&_storage[0] + sizeof(uint32)), &destsize, static_cast<const void*>(source->contents()), size);
    if (destsize == 0)
        return;

    put<uint32>(sizePos, size);
    resize(destsize + sizeof(uint32));

    SetOpcode(opcode);

	sLog->outInfo(LOG_FILTER_NETWORKIO, "%s (len %u) successfully compressed to %04X (len %u)", GetOpcodeNameForLogging(uncompressedOpcode, true).c_str(), size, opcode, destsize);
}
开发者ID:cooler-SAI,项目名称:PandaFire,代码行数:31,代码来源:WorldPacket.cpp

示例7: GetOpcode

//! Compresses packet in place
void WorldPacket::Compress(z_stream* compressionStream)
{
    Opcodes uncompressedOpcode = GetOpcode();
    if (uncompressedOpcode & COMPRESSED_OPCODE_MASK)
    {
        sLog->outError(LOG_FILTER_NETWORKIO, "Packet with opcode 0x%04X is already compressed!", uncompressedOpcode);
        return;
    }

    Opcodes opcode = Opcodes(uncompressedOpcode | COMPRESSED_OPCODE_MASK);
    uint32 size = wpos();
    uint32 destsize = compressBound(size);

    std::vector<uint8> storage(destsize);

    _compressionStream = compressionStream;
    Compress(static_cast<void*>(&storage[0]), &destsize, static_cast<const void*>(contents()), size);
    if (destsize == 0)
        return;

    clear();
    reserve(destsize + sizeof(uint32));
    *this << uint32(size);
    append(&storage[0], destsize);
    SetOpcode(opcode);

	sLog->outInfo(LOG_FILTER_NETWORKIO, "%s (len %u) successfully compressed to %04X (len %u)", GetOpcodeNameForLogging(uncompressedOpcode, true).c_str(), size, opcode, destsize);
}
开发者ID:cooler-SAI,项目名称:PandaFire,代码行数:29,代码来源:WorldPacket.cpp

示例8: 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

示例9: f_nzcompress

Variant f_nzcompress(CStrRef uncompressed) {
  nzlib_format_t* format = NULL;
  size_t len = 0;
  char *compressed = NULL;
  int rc;

  len = compressBound(uncompressed.size());
  format = (nzlib_format_t*)malloc(sizeof(*format) + len);
  if (format == NULL) {
    goto error;
  }

  format->magic = htonl(NZLIB_MAGIC);
  format->uncompressed_sz = htonl(uncompressed.size());

  rc = compress(format->buf, &len, (uint8_t*)uncompressed.data(),
                uncompressed.size());
  if (rc != Z_OK) {
    goto error;
  }

  compressed = (char*)realloc(format, len + sizeof(*format) + 1);
  if (compressed == NULL) {
    goto error;
  }
  compressed[len + sizeof(*format)] = '\0';
  return String(compressed, len + sizeof(*format), AttachString);

error:
  free(format);
  return false;
}
开发者ID:KWMalik,项目名称:hiphop-php,代码行数:32,代码来源:ext_zlib.cpp

示例10: compressBound

char *catalog_query_compress_update(const char *text, unsigned long *data_length)
{
	unsigned long compress_data_length;
	/* Default to buffer error incase we don't compress. */
	int success = Z_BUF_ERROR;

	/* Estimates the bounds for the compressed data. */
	compress_data_length = compressBound(*data_length);
	char* compress_data= malloc(compress_data_length);

	success = compress((Bytef*)compress_data+1, &compress_data_length, (const Bytef*)text, *data_length);
	/* Prefix the data with 0x1A (Control-Z) to indicate a compressed packet. */
	compress_data[0] = 0x1A;

	/* Copy data over if not compressing or compression failed. */
	if(success!=Z_OK) {
		/* Compression failed, fall back to original uncompressed update. */
		debug(D_DEBUG,"warning: Unable to compress data for update.\n");
		free(compress_data);
		return NULL;
	} else {
		/* Add 1 to the compresed data length to account for the leading 0x1A. */
		*data_length = compress_data_length + 1;
		return compress_data;
	}
}
开发者ID:btovar,项目名称:cctools,代码行数:26,代码来源:catalog_query.c

示例11: compressUtil

void compressUtil(unsigned long originalDataLen) {
	//get compress buffer bound
	int rv;
	int compressBufBound = compressBound(originalDataLen);
	compressedBuf = (unsigned char*) malloc(sizeof(unsigned char)*compressBufBound);
	unsigned long compressedDataLen = compressBufBound;
	//compress
	rv = compress2(compressedBuf, &compressedDataLen, dataBuf, originalDataLen, 6);
	if (Z_OK != rv) {
		LOGE(1, "compression error");
		free(compressedBuf);
		return;
	}
	LOGI(1, "upper bound:%d; input: %d; compressed: %d",
			compressBufBound, originalDataLen, compressedDataLen);
	//decompress and verify result
	unsigned long decompressedDataLen = S_BUF_SIZE;
	rv = uncompress(decompressedBuf, &decompressedDataLen, compressedBuf, compressedDataLen);
	if (Z_OK != rv) {
		LOGE(1, "decompression error");
		free(compressedBuf);
		return;
	}
	LOGI(1, "decompressed: %d", decompressedDataLen);
	if (0 == memcmp(dataBuf, decompressedBuf, originalDataLen)) {
		LOGI(1, "decompressed data same as original data");
	} else {
		LOGI(1, "decompressed data different from original data");
	}
	//free resource
	free(compressedBuf);
}
开发者ID:GitNooby,项目名称:notes,代码行数:32,代码来源:ZlibDemo.cpp

示例12: compressData2

cv::Mat compressData2(const cv::Mat & data)
{
	cv::Mat bytes;
	if(!data.empty())
	{
		uLong sourceLen = uLong(data.total())*uLong(data.elemSize());
		uLong destLen = compressBound(sourceLen);
		bytes = cv::Mat(1, destLen+3*sizeof(int), CV_8UC1);
		int errCode = compress(
						(Bytef *)bytes.data,
						&destLen,
						(const Bytef *)data.data,
						sourceLen);
		bytes = cv::Mat(bytes, cv::Rect(0,0, destLen+3*sizeof(int), 1));
		*((int*)&bytes.data[destLen]) = data.rows;
		*((int*)&bytes.data[destLen+sizeof(int)]) = data.cols;
		*((int*)&bytes.data[destLen+2*sizeof(int)]) = data.type();

		if(errCode == Z_MEM_ERROR)
		{
			UERROR("Z_MEM_ERROR : Insufficient memory.");
		}
		else if(errCode == Z_BUF_ERROR)
		{
			UERROR("Z_BUF_ERROR : The buffer dest was not large enough to hold the uncompressed data.");
		}
	}
	return bytes;
}
开发者ID:AndriiDSD,项目名称:rtabmap,代码行数:29,代码来源:Compression.cpp

示例13: mongoc_compressor_max_compressed_length

size_t
mongoc_compressor_max_compressed_length (int32_t compressor_id, size_t len)
{
   TRACE ("Getting compression length for '%s' (%d)",
          mongoc_compressor_id_to_name (compressor_id),
          compressor_id);
   switch (compressor_id) {
#ifdef MONGOC_ENABLE_COMPRESSION_SNAPPY
   case MONGOC_COMPRESSOR_SNAPPY_ID:
      return snappy_max_compressed_length (len);
      break;
#endif

#ifdef MONGOC_ENABLE_COMPRESSION_ZLIB
   case MONGOC_COMPRESSOR_ZLIB_ID:
      return compressBound (len);
      break;
#endif

   case MONGOC_COMPRESSOR_NOOP_ID:
      return len;
      break;
   default:
      return 0;
   }
}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:26,代码来源:mongoc-compression.c

示例14: ejszlib_compress

  static
  JSBool
  ejszlib_compress (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) 
  {
    EJS_CHECK_NUM_ARGS(cx,obj,1,argc);
    
    char* ctype;
    size_t len;
    STRING_TO_CHARVEC(argv[0],ctype,len);
    // todo: perhaps simply return an empty string
    if (!len) EJS_THROW_ERROR(cx,obj,"nothing to compress");
    
    uLong destLen=compressBound(len);
    
    Byte* dest=(Byte *)JS_malloc(cx, destLen);
    if (!dest) return JS_FALSE;

    if (compress(dest, &destLen, (Byte*)ctype, len)!=Z_OK) {
      JS_free(cx,dest);
      EJS_THROW_ERROR(cx,obj,"compression failed");
    }

    assert(destLen>0);
    dest=(Byte *)JS_realloc(cx,dest,destLen);

    RETSTR(dest,destLen,rval);
  }
开发者ID:BackupTheBerlios,项目名称:egachine,代码行数:27,代码来源:ejszlib.cpp

示例15: compressData

std::vector<unsigned char> compressData(const cv::Mat & data)
{
	std::vector<unsigned char> bytes;
	if(!data.empty())
	{
		uLong sourceLen = uLong(data.total())*uLong(data.elemSize());
		uLong destLen = compressBound(sourceLen);
		bytes.resize(destLen);
		int errCode = compress(
						(Bytef *)bytes.data(),
						&destLen,
						(const Bytef *)data.data,
						sourceLen);

		bytes.resize(destLen+3*sizeof(int));
		*((int*)&bytes[destLen]) = data.rows;
		*((int*)&bytes[destLen+sizeof(int)]) = data.cols;
		*((int*)&bytes[destLen+2*sizeof(int)]) = data.type();

		if(errCode == Z_MEM_ERROR)
		{
			UERROR("Z_MEM_ERROR : Insufficient memory.");
		}
		else if(errCode == Z_BUF_ERROR)
		{
			UERROR("Z_BUF_ERROR : The buffer dest was not large enough to hold the uncompressed data.");
		}
	}
	return bytes;
}
开发者ID:AndriiDSD,项目名称:rtabmap,代码行数:30,代码来源:Compression.cpp


注:本文中的compressBound函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。