• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ decompress函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: decompressResource

void decompressResource()
{
	for(bool bDone = false;!bDone;)	//Loop until we're done
	{
		ThreadConvertHelper dh;
		wstring sFilename;
		std::lock_guard<std::mutex> lock(g_Mutex);

		if(!g_lThreadedResources.size())	//Done
		{
			bDone = true;
		}
		else
		{
			//Grab the top item off the list
			dh = g_lThreadedResources.front();
			sFilename = getName(dh.id);	//Mutex on this too, since getName() isn't really threadsafe
			makeFolder(dh.id);	//Also create folder (not threadsafe, either)
			g_lThreadedResources.pop_front();	//Done with this element
		}
		
		//Let user know which resource we're converting now
		if(!bDone)
		{
			g_iCurResource++;
			if(!(sFilename == RESIDMAP_NAME && g_iCurResource == 1))
			{
				if(g_bProgressOverwrite)
				{
					cout << "\rDecompressing file " << g_iCurResource << " out of " << g_iNumResources;
					cout.flush();
				}
				else
					cout << "Decompressing file " << g_iCurResource << " out of " << g_iNumResources << ": " << ws2s(sFilename) << endl;
			}
		}
		
		// Release ownership of the mutex object
		if(sFilename == RESIDMAP_NAME && g_iCurResource == 1)	//Don't release residmap.dat mutex until we've read in all the filenames
		{
			g_iNumResources--;
		}

		if(bDone)
		{
			continue;	//Stop here if done
		}
			
		if(dh.bCompressed)	//Compressed
		{
			uint8_t* tempData = decompress(&dh.data);
			if(tempData == NULL)
			{
				cout << "Error decompressing file " << ws2s(sFilename) << endl;
				return;
			}
			free(dh.data.data);	//Free this compressed memory
			dh.data.data = tempData;	//Now we have the decompressed data
		}
		
		//See if this was a PNG image. Convert PNG images from the data in RAM
		if(sFilename.find(L".png") != wstring::npos ||
		   sFilename.find(L".PNG") != wstring::npos ||
		   sFilename.find(L"coloritemicon") != wstring::npos ||
		   sFilename.find(L"colorbgicon") != wstring::npos ||
		   sFilename.find(L"greybgicon") != wstring::npos)			//Also would include .png.normal files as well
		{
			convertToPNG(sFilename.c_str(), dh.data.data, dh.data.decompressedSize);	//Do the conversion to PNG
		}
		else	//For other file types, go ahead and write to the file before converting
		{
			//Write this out to the file
			FILE* fOut = fopen(ws2s(sFilename).c_str(), "wb");
			if(fOut == NULL)
			{
				cout << "Unable to open output file " << ws2s(sFilename) << endl;
				return;
			}
			fwrite(dh.data.data, 1, dh.data.decompressedSize, fOut);
			fclose(fOut);
		}
		free(dh.data.data);	//Free memory from this file
		
		/*
		//Convert wordPackDict.dat to XML
		if(sFilename.find(L"wordPackDict.dat") != wstring::npos)
		{
			wordPackToXML(sFilename.c_str());
			unlink(ws2s(sFilename).c_str());
		}
		
		//Convert sndmanifest.dat to XML
		else if(sFilename.find(L"sndmanifest.dat") != wstring::npos)
		{
			sndManifestToXML(sFilename.c_str());
			unlink(ws2s(sFilename).c_str());
		}
		
		//Convert itemmanifest.dat to XML
		else if(sFilename.find(L"itemmanifest.dat") != wstring::npos)
//.........这里部分代码省略.........
开发者ID:amolloy,项目名称:liTools,代码行数:101,代码来源:threadDecompress.cpp


示例2: decompress

bool mvt_tile::decode(std::string &message) {
	layers.clear();
	std::string src;

	if (is_compressed(message)) {
		std::string uncompressed;
		decompress(message, uncompressed);
		src = uncompressed;
	} else {
		src = message;
	}

	protozero::pbf_reader reader(src);

	while (reader.next()) {
		switch (reader.tag()) {
		case 3: /* layer */
		{
			protozero::pbf_reader layer_reader(reader.get_message());
			mvt_layer layer;

			while (layer_reader.next()) {
				switch (layer_reader.tag()) {
				case 1: /* name */
					layer.name = layer_reader.get_string();
					break;

				case 3: /* key */
					layer.keys.push_back(layer_reader.get_string());
					break;

				case 4: /* value */
				{
					protozero::pbf_reader value_reader(layer_reader.get_message());
					mvt_value value;

					while (value_reader.next()) {
						switch (value_reader.tag()) {
						case 1: /* string */
							value.type = mvt_string;
							value.string_value = value_reader.get_string();
							break;

						case 2: /* float */
							value.type = mvt_float;
							value.numeric_value.float_value = value_reader.get_float();
							break;

						case 3: /* double */
							value.type = mvt_double;
							value.numeric_value.double_value = value_reader.get_double();
							break;

						case 4: /* int */
							value.type = mvt_int;
							value.numeric_value.int_value = value_reader.get_int64();
							break;

						case 5: /* uint */
							value.type = mvt_uint;
							value.numeric_value.uint_value = value_reader.get_uint64();
							break;

						case 6: /* sint */
							value.type = mvt_sint;
							value.numeric_value.sint_value = value_reader.get_sint64();
							break;

						case 7: /* bool */
							value.type = mvt_bool;
							value.numeric_value.bool_value = value_reader.get_bool();
							break;

						default:
							value_reader.skip();
							break;
						}
					}

					layer.values.push_back(value);
					break;
				}

				case 5: /* extent */
					layer.extent = layer_reader.get_uint32();
					break;

				case 15: /* version */
					layer.version = layer_reader.get_uint32();
					break;

				case 2: /* feature */
				{
					protozero::pbf_reader feature_reader(layer_reader.get_message());
					mvt_feature feature;
					std::vector<uint32_t> geoms;

					while (feature_reader.next()) {
						switch (feature_reader.tag()) {
						case 1: /* id */
//.........这里部分代码省略.........
开发者ID:mtoon,项目名称:tippecanoe,代码行数:101,代码来源:mvt.cpp


示例3: decompress_as

output_t decompress_as (const compressed_data& in)
{
    output_t out;
    decompress(in, out);
    return out;
}
开发者ID:friederschueler,项目名称:hexahedra,代码行数:6,代码来源:compression.hpp


示例4: databuf_nodelist

void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)
{
	u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE;

	// Initialize default flags
	is_underground = false;
	m_day_night_differs = false;
	m_lighting_expired = false;
	m_generated = true;

	// Make a temporary buffer
	u32 ser_length = MapNode::serializedLength(version);
	SharedBuffer<u8> databuf_nodelist(nodecount * ser_length);

	// These have no compression
	if(version <= 3 || version == 5 || version == 6)
	{
		char tmp;
		is.read(&tmp, 1);
		if(is.gcount() != 1)
			throw SerializationError
					("MapBlock::deSerialize: no enough input data");
		is_underground = tmp;
		is.read((char*)*databuf_nodelist, nodecount * ser_length);
		if(is.gcount() != nodecount * ser_length)
			throw SerializationError
					("MapBlock::deSerialize: no enough input data");
	}
	else if(version <= 10)
	{
		u8 t8;
		is.read((char*)&t8, 1);
		is_underground = t8;

		{
			// Uncompress and set material data
			std::ostringstream os(std::ios_base::binary);
			decompress(is, os, version);
			std::string s = os.str();
			if(s.size() != nodecount)
				throw SerializationError
						("MapBlock::deSerialize: invalid format");
			for(u32 i=0; i<s.size(); i++)
			{
				databuf_nodelist[i*ser_length] = s[i];
			}
		}
		{
			// Uncompress and set param data
			std::ostringstream os(std::ios_base::binary);
			decompress(is, os, version);
			std::string s = os.str();
			if(s.size() != nodecount)
				throw SerializationError
						("MapBlock::deSerialize: invalid format");
			for(u32 i=0; i<s.size(); i++)
			{
				databuf_nodelist[i*ser_length + 1] = s[i];
			}
		}
	
		if(version >= 10)
		{
			// Uncompress and set param2 data
			std::ostringstream os(std::ios_base::binary);
			decompress(is, os, version);
			std::string s = os.str();
			if(s.size() != nodecount)
				throw SerializationError
						("MapBlock::deSerialize: invalid format");
			for(u32 i=0; i<s.size(); i++)
			{
				databuf_nodelist[i*ser_length + 2] = s[i];
			}
		}
	}
	// All other versions (newest)
	else
	{
		u8 flags;
		is.read((char*)&flags, 1);
		is_underground = (flags & 0x01) ? true : false;
		m_day_night_differs = (flags & 0x02) ? true : false;
		m_lighting_expired = (flags & 0x04) ? true : false;
		if(version >= 18)
			m_generated = (flags & 0x08) ? false : true;

		// Uncompress data
		std::ostringstream os(std::ios_base::binary);
		decompress(is, os, version);
		std::string s = os.str();
		if(s.size() != nodecount*3)
			throw SerializationError
					("MapBlock::deSerialize: decompress resulted in size"
					" other than nodecount*3");

		// deserialize nodes from buffer
		for(u32 i=0; i<nodecount; i++)
		{
			databuf_nodelist[i*ser_length] = s[i];
//.........这里部分代码省略.........
开发者ID:f1337m4573r,项目名称:minetest,代码行数:101,代码来源:mapblock.cpp


示例5: main

int main(int argc, char **argv)
{
	if (argc < 2)
	{
		return 1;
	}

	{
		// Queue
		fileQueue = new PathQueue();

		for (int i = 1; i < argc; ++i)
		{
			boost::filesystem::path argPath(argv[i]);
			if (boost::filesystem::exists(argPath)) // Does the file exist?
			{
				if (boost::filesystem::is_regular_file(argPath))
				{
					// TODO: NOT YET IMPLEMENTED
					// Execute file process
#ifdef FILEIO
					std::cout << std::endl << "Reading file" << argPath << std::endl;
#endif
					fileQueue->push(argPath);
				}
				else if (boost::filesystem::is_directory(argPath))
				{
					// TODO: NOT YET IMPLEMENTED
					// Execute on all files in the directory
					recurseProcessor(argPath);
				}
				else
				{
					return -1;
				}
			}
		}
	}

	auto lz4Proc = new LZ4::Processor();

	std::ifstream fIn;
	std::ofstream fOut;
	size_t fBeg, fEnd;
	std::string oName;
	std::string::size_type pAt;
	bool bIsCompressed;
	char *data;

	while (fileQueue->size() > 0)
	{
		// FIRST THINGS
		oName = fileQueue->accPop().string();
		bIsCompressed = boost::algorithm::ends_with(oName,".lz4");
	

		fIn.open(oName,std::ios::binary);
		if (!fIn.is_open())
		{
			continue;
		}
		fIn.seekg(0, std::ios::end);
		fEnd = fIn.tellg();
		fIn.seekg(0, std::ios::beg);
		fBeg = fIn.tellg();

		data = new char[(fEnd - fBeg)];
		fIn.read(data, fEnd - fBeg);
		fIn.close();

		std::cout << "File is " << fEnd - fBeg << std::endl;
		if (bIsCompressed)
		{
			lz4Proc->decompress(data, int(fEnd - fBeg));
			pAt = oName.find_last_of('.');
			oName = oName.substr(0, pAt);
		}
		else
		{
			lz4Proc->compress(data, int(fEnd - fBeg));
			oName = oName + ".lz4";
		}
		delete data;
		if (lz4Proc->len() == 0) continue;
		std::cout << lz4Proc->len() << std::endl;

		fOut.open(oName, std::ios::binary);
		if (!fOut.is_open()) continue;
		fOut.write(lz4Proc->ptr(), lz4Proc->len());
		fOut.close();

	}

	delete fileQueue;


	getchar();
	return 0;
}
开发者ID:CasperTheCat,项目名称:LZ4-DLL,代码行数:99,代码来源:Source.cpp


示例6: main

int main(void)
{
	aplist *head = NULL;
	aplist *cur;
	
	bool attached = true;
	// change this to false if you are only testing servos
	bool wifi_scan = true;
	// change this for emulator 
	bool emulate = false;

	float pain = 0.9f;
	time_t update = 0;
	uint8 num;
	uint8 servo_pos = 0;
	uint8 current_servo = 1;
	unsigned char SERVO_PINS[3] = { SERVO_PIN1 ,SERVO_PIN2 ,SERVO_PIN3 } ;

	uint16 val[3] = { 0 };
	uint8 i;

	touchPosition touch;
	
	videoSetMode(MODE_4_2D);
	vramSetBankA(VRAM_A_MAIN_BG);

	// set up our bitmap background
	bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);
	decompress(cclogoBitmap, BG_GFX,  LZ77Vram);

	// initialise lower screen for textoutput
	consoleDemoInit();

	if (emulate == false) {	

	  iprintf("Initializing WiFi.. ");
	  Wifi_InitDefault(false);
	  while (Wifi_CheckInit() != 1) {
	  }
	  Wifi_ScanMode();
	  iprintf("done\n");
	  
	  iprintf("Initializing DS brut.. ");
	  uart_init();
	  uart_set_spi_rate(1000);
	  iprintf("done\n\n\n");

	  iprintf("Using servo pins: %u %u %u\n\n", SERVO_PIN1, SERVO_PIN2, SERVO_PIN3);
	  iprintf("Default pain multiplier: %.2f\n\n", pain);
	  swiDelay(60000000);
	  while (1) {
		  
		  scanKeys();
		  touchRead(&touch);	
		  if (keysDown() & KEY_X) {
			  if (attached) {
				  servo_detach(SERVO_PIN1);
				  servo_detach(SERVO_PIN2);
				  servo_detach(SERVO_PIN3);
				  attached = false;
			  } else {
				  attached = true;
			  }
		  }
		  if (keysDown() & KEY_A) {
			  if (attached) {
				uint8 i = 0;
				for (i=0;i<3;i++) {
					servo_set(SERVO_PINS[i],0);
				}
			  }
			  //servo_set(SERVO_PIN1, 180-((rand() % 100)+(rand() % 50)+(rand() % 25)));
			  //servo_set(SERVO_PIN2, 180-((rand() % 100)+(rand() % 50)+(rand() % 25)));
			  //servo_set(SERVO_PIN3, 180-((rand() % 100)+(rand() % 50)+(rand() % 25)));
		  }
		  if (keysDown() & KEY_B) {
			  if (wifi_scan == true)	{
				  wifi_scan = false;
			  }
			  else {
				  wifi_scan = true;
			  }
		  }
		  if (keysDown() & KEY_DOWN) {
			  pain -= 0.1f;
			  if (pain < 0.0f) {
				  pain = 0.0f;
			  }
			  update = time(NULL);
		  }
		  if (keysDown() & KEY_UP) {
			  pain += 0.1f;
			  if (2.0f < pain) {
				  pain = 2.0f;
			  }
			  update = time(NULL);
		  }
		  if (keysDown() & KEY_L) {
			  current_servo += 1;
			  if (current_servo > 3) {
//.........这里部分代码省略.........
开发者ID:fleshgordo,项目名称:constraintcity,代码行数:101,代码来源:main.c


示例7: MemoryFile

void ZlibFile::createDecompressedMemoryFile()
{
	MemoryFile * memoryFile = new MemoryFile(decompress(), m_uncompressedLength);
	close();
	m_decompressedMemoryFile = memoryFile;
}
开发者ID:Mesagoppinmypants,项目名称:NGELinux,代码行数:6,代码来源:ZlibFile.cpp


示例8: do_decompress

int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
{
	return decompress(input, len, NULL, NULL, output, NULL, error);
}
开发者ID:anewkirk,项目名称:AJK,代码行数:4,代码来源:decompress.c


示例9: main

int main(void)
{

    int n,
        cport_nr = 4,        /* 6 (COM5 on windows) */
        bdrate = 38400;       /* 9600 baud */

    uint8_t buf[BUF_SIZE + 1];
    uint8_t data[MAX_DATA_SIZE];

    char mode[] = {'8','N','1',0};

    if (RS232_OpenComport(cport_nr, bdrate, mode)) {
        printf("Can not open comport\n");
        return(0);
    }
    int received_cnt = 0;

    while (1) {

      	n = RS232_PollComport(cport_nr, buf, BUF_SIZE);

	    if (n > 0) {
	    	/* always put a "null" at the end of a string! */
		    buf[n] = 0;   
		
		    printf("Received %i bytes: %s\n", n, (char *) buf);

		    if (arr_search("TKENDTKENDTKENDTKEND", BUF_SIZE, buf, n) > 0) {
		    	printf("%s\n", "Starting reception...");
		    	memset(data, 0, MAX_DATA_SIZE);	/* Initialize the array */
		    	received_cnt = 0;
		    }

		    else {
			    int pos = -1;
			    /* If receiving the end of current compressed buffer, send & reinitialize */
			    if ((pos = arr_search("TKENDTKENDTKENDTKE", DELIMITER_LEN, buf, n)) >= 0) {	
			    	int eff_len = pos - DELIMITER_LEN + 1;
			    	uint8_t temp[eff_len];
			    	memcpy(temp, buf, eff_len);
			    	memcpy(data + received_cnt, temp, eff_len);
			    	received_cnt += eff_len;
			    	/* Discard the last five bytes of indicators*/
			    	char size_buf[2];
			    	memcpy(size_buf, buf + pos + 1, 2);
			    	int size = size_buf[1] + (size_buf[0] << 4);
			    	printf("Received data total size: %d\n", size);

			    	uint8_t comp[size];
			    	memcpy(comp, data, size);
			    	decompress(comp, size);

			    	/* Clean up */
			    	memset(data, 0, MAX_DATA_SIZE);
			    	received_cnt = 0;	
			    	/* Also need to store rest of the data to avoid loss */
			    	// uint8_t lost[n - eff_len - 5];
			    	// memcpy(lost, buf + pos + 1, n - pos - 1);
			    	// memcpy(data, lost, n - pos - 1);
			    	// received_cnt += n - pos - 1;
			    } else {	/* If regular data packets, store it*/
			    	memcpy(data + received_cnt, buf, n);
			    	received_cnt = received_cnt + n;
			    }
			}
    	}
		#ifdef _WIN32
		    Sleep(100);
		#else
		    usleep(100000);  /* sleep for 100 milliSeconds */
		#endif
	}
    return (0);
}
开发者ID:JulianYG,项目名称:WNR,代码行数:75,代码来源:receiver.c


示例10: fread

int PFSLoader::Open(FILE *fp) {
  struct_header s3d_header;
  struct_directory_header s3d_dir_header;
  struct_directory s3d_dir;
  struct_data_block s3d_data;
  struct_fn_header *s3d_fn_header;
  struct_fn_entry *s3d_fn_entry;

  uint32 *offsets;

  char *temp, *temp2;
  int i, j, pos, inf, tmp, running = 0;

  fread(&s3d_header, sizeof(struct_header), 1, fp);
  if(s3d_header.magicCookie[0] != 'P' || s3d_header.magicCookie[1] != 'F' || s3d_header.magicCookie[2] != 'S' || s3d_header.magicCookie[3] != ' ')
    return 0;

  this->fp = fp;

  fseek(fp, s3d_header.offset, SEEK_SET);
  fread(&s3d_dir_header, sizeof(struct_directory_header), 1, fp);
  
  this->count = s3d_dir_header.count - 1;
  this->filenames = new char *[s3d_dir_header.count];
  this->files = new uint32[s3d_dir_header.count - 1];
  offsets = new uint32[s3d_dir_header.count - 1];

  for(i = 0; i < (int)s3d_dir_header.count; ++i) {
    fread(&s3d_dir, sizeof(struct_directory), 1, fp);

    if(s3d_dir.crc == ntohl(0xC90A5861)) {
      pos = ftell(fp);
      fseek(fp, s3d_dir.offset, SEEK_SET);
      temp = new char[s3d_dir.size];
      memset(temp, 0, s3d_dir.size);
      inf = 0;
      while(inf < (int)s3d_dir.size) {
        fread(&s3d_data, sizeof(struct_data_block), 1, fp);
        temp2 = new char[s3d_data.deflen];
        fread(temp2, s3d_data.deflen, 1, fp);
        decompress(temp2, temp + inf, s3d_data.deflen, s3d_data.inflen);
        delete[] temp2;
        inf += s3d_data.inflen;
      }
      fseek(fp, pos, SEEK_SET);
      s3d_fn_header = (struct_fn_header *) temp;
      pos = sizeof(struct_fn_header);
      for(j = 0; j < (int)s3d_fn_header->fncount; ++j) {
        s3d_fn_entry = (struct_fn_entry *) &temp[pos];
        this->filenames[j] = new char[s3d_fn_entry->fnlen + 1];
        this->filenames[j][s3d_fn_entry->fnlen] = 0;
        memcpy(this->filenames[j], &temp[pos + sizeof(struct_fn_entry)], s3d_fn_entry->fnlen);
        pos += sizeof(struct_fn_entry) + s3d_fn_entry->fnlen;
      }
    }

    else {
      this->files[running] = ftell(fp) - 12;
      offsets[running] = s3d_dir.offset;
      ++running;
    }

  }

  for(i = s3d_dir_header.count - 2; i > 0; i--) {
    for(j = 0; j < i; j++) {
      if(offsets[j] > offsets[j+1]) {
        tmp = offsets[j];
        offsets[j] = offsets[j + 1];
        offsets[j + 1] = tmp;
        tmp = this->files[j];
        this->files[j] = this->files[j + 1];
        this->files[j + 1] = tmp;
      }
    }
  }

  return 1;
}
开发者ID:9thsector,项目名称:Server,代码行数:79,代码来源:pfs.cpp


示例11: decompress

	std::vector<uint8_t> decompress(const std::vector<uint8_t>& data)
	{
		return decompress(&data[0], data.size());
	}
开发者ID:sweetkristas,项目名称:swiftly,代码行数:4,代码来源:decompress.cpp


示例12: decompress

void BitVector::rleANDnon(BitVector& bv) {
    // decompress
    // run nonANDnon
    decompress();
    nonANDnon(bv);
}
开发者ID:gingi,项目名称:snapdragon,代码行数:6,代码来源:bvec.cpp


示例13: main

/* Entry point for the program. Opens the file, and executes the mode specified by command line args */
int main(int argc, char* argv[])
{
    if(argc != 3 || (strcmp(argv[1], "-c") != 0 && strcmp(argv[1], "-d") != 0 && strcmp(argv[1], "-t") != 0))
    {
        printf("usage: huff [-c | -d | -t] file\n");
        return -1;
    }


    /* Execute the correct mode */
    if(strcmp(argv[1], "-c") == 0)
    {
        //append the extension to the name
        const char * extension = ".temp";
        char *tempFile = malloc(strlen(argv[2])+strlen(extension) + 1);
        strncpy(tempFile, argv[2], strlen(argv[2]));
        strcat(tempFile, extension);

        //RLE encode the file
        rle_encode(argv[2], tempFile);

        //create a vairiable to hold hold the file length
        unsigned long long fileLength = 0;

        //get a buffer of the contents of the file as a unsigned char*
        unsigned char *file_pointer = openFile(tempFile, &fileLength);

        //huff compress the output.
        compress(file_pointer, fileLength, argv[2]);
        free(file_pointer);
        //free(tempFile);
        remove(tempFile);

    }
    else if(strcmp(argv[1], "-d") == 0)
    {
        unsigned long long fileLength = 0;
        unsigned char *file_pointer = openFile(argv[2], &fileLength);
        decompress(file_pointer, fileLength, argv[2]);

        //remove the .hurl extension from the fileName;

        char *tempFileName = calloc(strlen(argv[2]), sizeof(char));
        strncpy(tempFileName, argv[2], strlen(argv[2]) - strlen(".hurl"));
        strncat(tempFileName, ".temp", sizeof(".temp"));

        char *outputFileName = calloc(sizeof(char), strlen(argv[2]));
        strncpy(outputFileName, argv[2], strlen(argv[2]));
        outputFileName[strlen(outputFileName) -5] = '\0';

        rle_decode(tempFileName, outputFileName);
        free(file_pointer);
        remove(tempFileName);
    }
    else if(strcmp(argv[1], "-t") == 0)
    {
        unsigned long long fileLength = 0;
        unsigned char *file_pointer = openFile(argv[2], &fileLength);
        print_table(file_pointer, fileLength, argv[2]);
        free(file_pointer);

    }

    // free(file_pointer);
    return 0;
}
开发者ID:regehr,项目名称:solid_code_class,代码行数:67,代码来源:huff.c


示例14: next_size

  std::pair<char*, size_t> LZ4RunReader::next()
  {
    // Is there a complete key in the buffer?
    if( decomp_.fill() >= sizeof(size_t) &&
        decomp_.fill() >= (sizeof(size_t) + next_size()) )
    {
      auto ret = std::make_pair(decomp_.base() + decomp_.lo() + sizeof(size_t),
                                next_size());

      decomp_.advance_lo(ret.second + sizeof(size_t));

      return ret;
    }
    // No key. Did we hit eof?
    else if( eof_ )
    {
      if( decomp_.fill() )
      {
        WARNING("Run file had " << decomp_.fill() << " extraneous bytes at end");
      }

      if( comp_.fill() )
      {
        WARNING("Run file consumed with " << comp_.fill() << " compressed"
                " bytes remaining");
      }

      return std::pair<char*, size_t>(nullptr, 0);
    }
    // We need some more data
    else
    {
      // Fill buffer until we have hit the trigger point, and we have a
      // a complete key
      while( !eof_ &&
             ( decomp_.fill() < trigger_ || 
               decomp_.fill() < (sizeof(size_t) + next_size()) ) )
      {
        // First try to decompress that which we have
        if( comp_.fill() )
        {
          decompress();

          // Skip read if we got enough data
          if( decomp_.fill() >= trigger_ && 
              decomp_.fill() >= (sizeof(size_t) + next_size()) )
          {
            continue;
          }
        }

        if( poll(fds_, 1, -1) < 0 )
        {
          WARNING("poll() failed, input may have terminated prematurely.");
          eof_ = true;
        }

        // Read into the compressed buffer
        int bytes_read = read(fds_[0].fd, comp_.base() + comp_.hi(),
                                          comp_.size() - comp_.fill());

        if( bytes_read <= 0 )
        {
          eof_ = true;

          if( bytes_read < 0 )
          {
            WARNING("read() failed, input may have terminated prematurely.");
          }
        }
        else
        {
          comp_.advance_hi(bytes_read);
          decompress();
        }
      }

      // Warn if eof without a complete key
      if( eof_ && ( decomp_.fill() < sizeof(size_t) ||
                    decomp_.fill() < (sizeof(size_t) + next_size()) ) )
      {
        WARNING("Run file had " << decomp_.fill() << " extraneous bytes at end");
        return std::pair<char*, size_t>(nullptr, 0);
      }
      
      // We now have at least one key in the buffer. Return the first.
      auto ret = std::make_pair(decomp_.base() + decomp_.lo() + sizeof(size_t),
                                next_size());

      decomp_.advance_lo(ret.second + sizeof(size_t));

      return ret;
    }
  }
开发者ID:bschofield,项目名称:fort,代码行数:94,代码来源:LZ4RunReader.cpp


示例15: assert

void TPC::fixupCubeMap() {
	/* Do various fixups to the cube maps. This includes rotating and swapping a
	 * few sides around. This is done by the original games as well.
	 */

	if (!isCubeMap())
		return;

	for (size_t j = 0; j < getMipMapCount(); j++) {
		assert(getLayerCount() > 0);

		const size_t index0 = 0 * getMipMapCount() + j;
		assert(index0 < _mipMaps.size());

		const  int32 width  = _mipMaps[index0]->width;
		const  int32 height = _mipMaps[index0]->height;
		const uint32 size   = _mipMaps[index0]->size;

		for (size_t i = 1; i < getLayerCount(); i++) {
			const size_t index = i * getMipMapCount() + j;
			assert(index < _mipMaps.size());

			if ((width  != _mipMaps[index]->width ) ||
			    (height != _mipMaps[index]->height) ||
			    (size   != _mipMaps[index]->size  ))
				throw Common::Exception("Cube map layer dimensions mismatch");
		}
	}

	// Since we need to rotate the individual cube sides, we need to decompress them all
	decompress();

	// Swap the first two sides of the cube maps
	for (size_t j = 0; j < getMipMapCount(); j++) {
		const size_t index0 = 0 * getMipMapCount() + j;
		const size_t index1 = 1 * getMipMapCount() + j;
		assert((index0 < _mipMaps.size()) && (index1 < _mipMaps.size()));

		MipMap &mipMap0 = *_mipMaps[index0];
		MipMap &mipMap1 = *_mipMaps[index1];

		SWAP(mipMap0.data, mipMap1.data);
	}

	const int bpp = (_formatRaw == kPixelFormatRGB8) ? 3 : ((_formatRaw == kPixelFormatRGBA8) ? 4 : 0);
	if (bpp == 0)
		return;

	// Rotate the cube sides so that they're all oriented correctly
	for (size_t i = 0; i < getLayerCount(); i++) {
		for (size_t j = 0; j < getMipMapCount(); j++) {
			const size_t index = i * getMipMapCount() + j;
			assert(index < _mipMaps.size());

			MipMap &mipMap = *_mipMaps[index];

			static const int rotation[6] = { 1, 3, 0, 2, 2, 0 };

			rotate90(mipMap.data, mipMap.width, mipMap.height, bpp, rotation[i]);
		}
	}

}
开发者ID:ehalls,项目名称:xoreos,代码行数:63,代码来源:tpc.cpp


示例16: copy_one_extent

static int copy_one_extent(struct btrfs_root *root, int fd,
			   struct extent_buffer *leaf,
			   struct btrfs_file_extent_item *fi, u64 pos)
{
	struct btrfs_multi_bio *multi = NULL;
	struct btrfs_device *device;
	char *inbuf, *outbuf = NULL;
	ssize_t done, total = 0;
	u64 bytenr;
	u64 ram_size;
	u64 disk_size;
	u64 length;
	u64 size_left;
	u64 dev_bytenr;
	u64 count = 0;
	int compress;
	int ret;
	int dev_fd;

	compress = btrfs_file_extent_compression(leaf, fi);
	bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
	disk_size = btrfs_file_extent_disk_num_bytes(leaf, fi);
	ram_size = btrfs_file_extent_ram_bytes(leaf, fi);
	size_left = disk_size;

	/* we found a hole */
	if (disk_size == 0)
		return 0;

	inbuf = malloc(disk_size);
	if (!inbuf) {
		fprintf(stderr, "No memory\n");
		return -1;
	}

	if (compress != BTRFS_COMPRESS_NONE) {
		outbuf = malloc(ram_size);
		if (!outbuf) {
			fprintf(stderr, "No memory\n");
			free(inbuf);
			return -1;
		}
	}
again:
	length = size_left;
	ret = btrfs_map_block(&root->fs_info->mapping_tree, READ,
			      bytenr, &length, &multi, 0, NULL);
	if (ret) {
		free(inbuf);
		free(outbuf);
		fprintf(stderr, "Error mapping block %d\n", ret);
		return ret;
	}
	device = multi->stripes[0].dev;
	dev_fd = device->fd;
	device->total_ios++;
	dev_bytenr = multi->stripes[0].physical;
	kfree(multi);

	if (size_left < length)
		length = size_left;
	size_left -= length;

	done = pread(dev_fd, inbuf+count, length, dev_bytenr);
	if (done < length) {
		free(inbuf);
		free(outbuf);
		fprintf(stderr, "Short read %d\n", errno);
		return -1;
	}

	count += length;
	bytenr += length;
	if (size_left)
		goto again;


	if (compress == BTRFS_COMPRESS_NONE) {
		while (total < ram_size) {
			done = pwrite(fd, inbuf+total, ram_size-total,
				      pos+total);
			if (done < 0) {
				free(inbuf);
				fprintf(stderr, "Error writing: %d %s\n", errno, strerror(errno));
				return -1;
			}
			total += done;
		}
		free(inbuf);
		return 0;
	}

	ret = decompress(inbuf, outbuf, disk_size, ram_size);
	free(inbuf);
	if (ret) {
		free(outbuf);
		return ret;
	}

	while (total < ram_size) {
//.........这里部分代码省略.........
开发者ID:clockfort,项目名称:btrfs-progs,代码行数:101,代码来源:cmds-restore.c


示例17: repo_add_deb


//.........这里部分代码省略.........
	{
	  pool_error(pool, -1, "%s: unexpected EOF", deb);
	  solv_free(ctgz);
	  fclose(fp);
	  return 0;
	}
    }
  fclose(fp);
  gotpkgid = 0;
  if (flags & DEBS_ADD_WITH_PKGID)
    {
      Chksum *chk = solv_chksum_create(REPOKEY_TYPE_MD5);
      solv_chksum_add(chk, ctgz, clen);
      solv_chksum_free(chk, pkgid);
      gotpkgid = 1;
    }
  if (ctgz[0] != 0x1f || ctgz[1] != 0x8b)
    {
      pool_error(pool, -1, "%s: control.tar.gz is not gzipped", deb);
      solv_free(ctgz);
      return 0;
    }
  if (ctgz[2] != 8 || (ctgz[3] & 0xe0) != 0)
    {
      pool_error(pool, -1, "%s: control.tar.gz is compressed in a strange way", deb);
      solv_free(ctgz);
      return 0;
    }
  bp = ctgz + 4;
  bp += 6;	/* skip time, xflags and OS code */
  if (ctgz[3] & 0x04)
    {
      /* skip extra field */
      l = bp[0] | bp[1] << 8;
      bp += l + 2;
      if (bp >= ctgz + clen)
	{
          pool_error(pool, -1, "%s: control.tar.gz is corrupt", deb);
	  solv_free(ctgz);
	  return 0;
	}
    }
  if (ctgz[3] & 0x08)	/* orig filename */
    while (*bp)
      bp++;
  if (ctgz[3] & 0x10)	/* file comment */
    while (*bp)
      bp++;
  if (ctgz[3] & 0x02)	/* header crc */
    bp += 2;
  if (bp >= ctgz + clen)
    {
      pool_error(pool, -1, "%s: control.tar.gz is corrupt", deb);
      solv_free(ctgz);
      return 0;
    }
  ctar = decompress(bp, ctgz + clen - bp, &ctarlen);
  solv_free(ctgz);
  if (!ctar)
    {
      pool_error(pool, -1, "%s: control.tar.gz is corrupt", deb);
      return 0;
    }
  bp = ctar;
  l = ctarlen;
  while (l > 512)
    {
      int j;
      l2 = 0;
      for (j = 124; j < 124 + 12; j++)
	if (bp[j] >= '0' && bp[j] <= '7')
	  l2 = l2 * 8 + (bp[j] - '0');
      if (!strcmp((char *)bp, "./control") || !strcmp((char *)bp, "control"))
	break;
      l2 = 512 + ((l2 + 511) & ~511);
      l -= l2;
      bp += l2;
    }
  if (l <= 512 || l - 512 - l2 <= 0 || l2 <= 0)
    {
      pool_error(pool, -1, "%s: control.tar.gz contains no control file", deb);
      free(ctar);
      return 0;
    }
  memmove(ctar, bp + 512, l2);
  ctar = solv_realloc(ctar, l2 + 1);
  ctar[l2] = 0;
  s = pool_id2solvable(pool, repo_add_solvable(repo));
  control2solvable(s, data, (char *)ctar);
  if (!(flags & REPO_NO_LOCATION))
    repodata_set_location(data, s - pool->solvables, 0, 0, deb);
  if (S_ISREG(stb.st_mode))
    repodata_set_num(data, s - pool->solvables, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
  if (gotpkgid)
    repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, pkgid);
  solv_free(ctar);
  if (!(flags & REPO_NO_INTERNALIZE))
    repodata_internalize(data);
  return s - pool->solvables;
}
开发者ID:bmwiedemann,项目名称:libsolv,代码行数:101,代码来源:repo_deb.c


示例18: addterm

term_ps_zzn* Ps_ZZn::addterm(const ZZn& a,int power,term_ps_zzn* pos)
{
    term_ps_zzn* newone;  
    term_ps_zzn* ptr;
    term_ps_zzn *t,*iptr;
    int dc,pw;
    ptr=start;
    iptr=NULL;

//
// intelligently determine the most compressed form to use
// for example if coefficient a=1 always, and power = -7 -5 -3 -1 1 3....
// then set pwr=2, offset=7  and PS = 1 + x + x^2
//
    pw=power+offset;
    if (one_term() && pw!=0)
    { // when PS has only one term, pwr is undefined
        if (pw<0)
            pwr=-pw;
        else pwr=pw; 
    }   

    dc=igcd(pw,pwr);

    if (dc != pwr) decompress(pwr/dc);
    power=pw/pwr;
// quick scan through to detect if term exists already
// and to find insertion point
   if (pos!=NULL) ptr=pos;
    while (ptr!=NULL) 
    { 
        if (ptr->n==power)
        {
            ptr->an+=a;

            if (ptr->an.iszero()) 
            { // delete term
                if (ptr==start)
                { // delete first one
                    start=ptr->next;
                    delete ptr;
                    norm();
                    return start;
                }
                iptr=ptr;
                ptr=start;
                while (ptr->next!=iptr)ptr=ptr->next;
                ptr->next=iptr->next;
                delete iptr;
                return ptr;
            }
            return ptr;
        }
        if (ptr->n<power) iptr=ptr;   // determines order
        else break;
        ptr=ptr->next;
    }
    newone=new term_ps_zzn;
    newone->next=NULL;
    newone->an=a;
    newone->n=power;
    pos=newone;
    if (start==NULL)
    {
        start=newone;
        norm();
        return pos;
    }

// insert at the start

    if (iptr==NULL)
    { 
        t=start;
        start=newone;
        newone->next=t;
        norm();
        return pos;
    }

// insert new term

    t=iptr->next;
    iptr->next=newone;
    newone->next=t;
    return pos;    
}
开发者ID:BingyZhang,项目名称:CommutEnc,代码行数:87,代码来源:ps_zzn.cpp


示例19: decompress

Ps_ZZn& Ps_ZZn::operator*=(Ps_ZZn& b)
{
    term_ps_zzn *ptr,*bptr;
    int g,d,deg,ka,kb;
    if (IsInt())
    {
        if (start!=NULL) *this = start->an*b;
        return *this;
    }
    if (b.IsInt())
    {
        if (b.start==NULL) clear();
        else *this *=(b.start->an);
        return *this;
    }
    g=igcd(pwr,b.pwr);
    deg=psN/g;


#ifdef FFT
    if (deg>=FFT_BREAK_EVEN)
    {
        big *A,*B;
        A=(big *)mr_alloc(deg,sizeof(big));
        B=(big *)mr_alloc(deg,sizeof(big));
        ka=pwr/g;
        decompress(ka);
        pad();
        ptr=start;
        while (ptr!=NULL)
        {
            d=ptr->n;
            if (d>=deg) break;
            A[d]=getbig(ptr->an);
            ptr=ptr->next;
        }
        kb=b.pwr/g;
        b.decompress(kb);
        bptr=b.start;
        while (bptr!=NULL)
        {
            d=bptr->n;
            if (d>=deg) break;
            B[d]=getbig(bptr->an);
            bptr=bptr->next;
       } 
       mr_ps_zzn_mul(deg,A,B,A);
       mr_free(B); mr_free(A);
       b.compress(kb);
    }
    else
    {
#endif
        *this=*this*b;
        return *this;
#ifdef FFT
    }
#endif
    norm();
    offset+=b.offset;
    return *this;
}
开发者ID:BingyZhang,项目名称:CommutEnc,代码行数:62,代码来源:ps_zzn.cpp


示例20: ParseXpck

void ParseXpck(FILE *infile, bool quietMode)
{
	ArchiveHeaderXpck header = { 0 };
	int archiveSize = 0;

	fseek(infile,0,SEEK_END);
	archiveSize = ftell(infile);
	rewind(infile);

	fread(header.magic, 1, 4, infile);
	fread(&header.fileCount, 1, 1, infile);
	fread(&header.unknown, 1, 1, infile);
	fread(&header.fileInfoOffset, 1, 2, infile);
	fread(&header.filenameTableOffset, 1, 2, infile);
	fread(&header.dataOffset, 1, 2, infile);
	fread(&header.fileInfoSize, 1, 2, infile);
	fread(&header.filenameTableSize, 1, 2, infile);
	fread(&header.dataSize, 1, 4, infile);

	header.fileInfoOffset *= 4;
	header.filenameTableOffset *= 4;
	header.dataOffset *= 4;
	header.fileInfoSize *= 4;
	header.filenameTableSize *= 4;
	header.dataSize *= 4;

	ParseFilenames(infile, header);
	ParseFileEntries(infile, header);

	// Create all of the possible directory paths in one go instead of trying to create 
	// each full path during the file dumping loop
	for(int i = 0; i < foldernames.size(); i++)
	{
		CreateFullPath(foldernames[i]);
	}

	std::string currentFolder = "";
	int dumped = 0;
	char *buffer = NULL;
	int bufferSize = 0;
	for(int i = 0; i < filenames.size(); i++)
	{
		if(filenames[i][filenames[i].size() - 1] == '/')
		{
			currentFolder = filenames[i];
		}
		else
		{
			std::string fullpath = currentFolder + filenames[i];
			unsigned int crc32 = CalculateCrc32((char*)filenames[i].c_str(), filenames[i].size());

			if(file_index.find(crc32) != file_index.end())
			{
				int idx = file_index[crc32];

				if(file_entries[idx].filesize > bufferSize)
				{
					bufferSize = file_entries[idx].filesize * 2;

					if(buffer == NULL)					
					{
						buffer = (char*)calloc(bufferSize, sizeof(char));
					}
					else
					{
						buffer = (char*)realloc(buffer, bufferSize);
					}
				}

				if(header.dataOffset + file_entries[idx].offset > archiveSize)
				{
					//printf("Couldn't seek passed end of file\n");
					continue;
				}

				fseek(infile,header.dataOffset + file_entries[idx].offset,SEEK_SET);
				fread(buffer, 1, file_entries[idx].filesize, infile);

				// Try to decompress data
				if(memcmp(buffer + 4, "\0DVLB", 5) == 0 || 
					memcmp(buffer + 4, "\0XPCK", 5) == 0 || 
					memcmp(buffer + 4, "\0CHRC", 5) == 0 || 
					memcmp(buffer + 4, "\0RESC", 5) == 0)
				{
					int length = *(int*)buffer;
					length /= 8;

					int output_len = 0;
					char *data = decompress(buffer, file_entries[idx].filesize, &output_len);

					// Replace the running buffer with the decompressed data's buffer.
					// Lazy way to hand 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ deconstruct_array函数代码示例发布时间:2022-05-30
下一篇:
C++ decompose函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap