示例#1
0
int main(int argc, char *argv[]){
	char*gcf_name;
	archive_t gcf=NULL;
	RTinitPopt(&argc,&argv,options,1,-1,&gcf_name,NULL,"([-c] <gcf> (<dir>|<file>)*) | (-x <gcf> [<dir>|<pattern>])",
		"Tool for creating and extracting GCF archives\n\nOptions");
	compression_policy_compile(policy);
	if (operation==GCF_EXTRACT) {
		char *out_name=RTinitNextArg();
		archive_t dir;
		if(out_name){
			if(RTinitNextArg()){
				Fatal(1,error,"extraction uses gcf -x <gcf> [<dir>|<pattern>]");
			}
			if (strstr(out_name,"%s")) {
				dir=arch_fmt(out_name,file_input,file_output,blocksize);
			} else {
				dir=arch_dir_create(out_name,blocksize,force?DELETE_ALL:DELETE_NONE);
			}
		} else {
			dir=arch_dir_open(".",blocksize);
		}
		if (is_a_dir(gcf_name)){
			gcf=arch_dir_open(gcf_name,blocksize);
		} else {
			gcf=arch_gcf_read(raf_unistd(gcf_name));
		}
		archive_copy(gcf,"auto",dir,NULL,blocksize);
		arch_close(&dir);
		arch_close(&gcf);
	} else {
		if (operation==GCF_FILE){
			gcf=arch_gcf_create(raf_unistd(gcf_name),blocksize,blocksize*blockcount,0,1);
		} else {
			gcf=arch_dir_create(gcf_name,blocksize,force?DELETE_ALL:DELETE_NONE);
		}
		for(;;){
			char *input_name=RTinitNextArg();
			if (!input_name) break;
			if (is_a_dir(input_name)){
				Warning(info,"copying contents of %s",input_name);
				archive_t dir=arch_dir_open(input_name,blocksize);
				archive_copy(dir,NULL,gcf,get_compression,blocksize);
				arch_close(&dir);
			} else {
				Warning(info,"copying %s",input_name);
				stream_t is=file_input(input_name);
				stream_t os=arch_write(gcf,input_name,get_compression(input_name),1);
				char buf[blocksize];
				for(;;){
					int len=stream_read_max(is,buf,blocksize);
					if (len) stream_write(os,buf,len);
					if(len<blocksize) break;
				}
				stream_close(&is);
				stream_close(&os);	
			}
		}
		arch_close(&gcf);
	}
}
示例#2
0
    bool is_valid_vcf_file(std::istream &input,
                           const std::string &sourceName,
                           ValidationLevel validationLevel,
                           std::vector<std::unique_ptr<ebi::vcf::ReportWriter>> &outputs)
    {
        std::vector<char> line;
        get_magic_num(input, line);
        std::string file_extension = get_compression(sourceName, line);
        check_readability_of_file(file_extension);

        if (file_extension == NO_EXT) {
            return process_vcf_stream(input, sourceName, validationLevel, outputs);
        } else {
            boost::iostreams::filtering_istream uncompressed_input;
            create_uncompressed_stream(input, file_extension, uncompressed_input);
            return process_vcf_stream(uncompressed_input, sourceName, validationLevel, outputs);
        }
    }
示例#3
0
文件: conffile.c 项目: EmisFR/burp
static int load_conf_field_and_value(struct conf **c,
	const char *f, // field
	const char *v, // value
	const char *conf_path,
	int line)
{
	if(!strcmp(f, "compression"))
	{
		int compression=get_compression(v);
		if(compression<0) return -1;
		set_int(c[OPT_COMPRESSION], compression);
	}
	else if(!strcmp(f, "ssl_compression"))
	{
		int compression=get_compression(v);
		if(compression<0) return -1;
		set_int(c[OPT_SSL_COMPRESSION], compression);
	}
	else if(!strcmp(f, "ratelimit"))
	{
		float f=0;
		f=atof(v);
		// User is specifying Mega bits per second.
		// Need to convert to bytes per second.
		f=(f*1024*1024)/8;
		if(!f)
		{
			logp("ratelimit should be greater than zero\n");
			return -1;
		}
		set_float(c[OPT_RATELIMIT], f);
	}
	else
	{
		int i=0;
		for(i=0; i<OPT_MAX; i++)
		{
			if(strcmp(c[i]->field, f)) continue;
			switch(c[i]->conf_type)
			{
				case CT_STRING:
					return set_string(c[i], v);
				case CT_UINT:
					return set_int(c[i], atoi(v));
				case CT_FLOAT:
					return set_float(c[i], atof(v));
					break;
				case CT_MODE_T:
					return set_mode_t(c[i],
						strtol(v, NULL, 8));
				case CT_SSIZE_T:
				{
					uint64_t s=0;
					return
					 get_file_size(v, &s, conf_path, line)
					  || set_uint64_t(c[i], s);
				}
				case CT_E_BURP_MODE:
					return set_e_burp_mode(c[i],
						str_to_burp_mode(v));
				case CT_E_PROTOCOL:
					return set_e_protocol(c[i],
						str_to_protocol(v));
				case CT_E_RECOVERY_METHOD:
					return set_e_recovery_method(c[i],
						str_to_recovery_method(v));
				case CT_STRLIST:
					return add_to_strlist(c[i], v,
					  !strcmp(c[i]->field, "include"));
				case CT_E_RSHASH:
					break;
				case CT_CNTR:
					break;
				// No default so we get a warning if something
				// was missed;
			}
		}
	}
	return 0;
}
示例#4
0
/* Make and init a Write.
 */
static Write *
write_new( VipsImage *im, const char *filename,
	VipsForeignTiffCompression compression, int Q, 
		VipsForeignTiffPredictor predictor,
	char *profile,
	gboolean tile, int tile_width, int tile_height,
	gboolean pyramid,
	gboolean squash,
	gboolean miniswhite,
	VipsForeignTiffResunit resunit, double xres, double yres,
	gboolean bigtiff,
	gboolean rgbjpeg,
	gboolean properties,
	gboolean strip )
{
	Write *write;

	if( !(write = VIPS_NEW( im, Write )) )
		return( NULL );
	write->im = im;
	write->filename = vips_strdup( VIPS_OBJECT( im ), filename );
	write->layer = NULL;
	write->tbuf = NULL;
	write->compression = get_compression( compression );
	write->jpqual = Q;
	write->predictor = predictor;
	write->tile = tile;
	write->tilew = tile_width;
	write->tileh = tile_height;
	write->pyramid = pyramid;
	write->onebit = squash;
	write->miniswhite = miniswhite;
	write->icc_profile = vips_strdup( NULL, profile );
	write->bigtiff = bigtiff;
	write->rgbjpeg = rgbjpeg;
	write->properties = properties;
	write->strip = strip;

	write->resunit = get_resunit( resunit );
	write->xres = xres;
	write->yres = yres;

	/* In strip mode we use tileh to set rowsperstrip, and that does not
	 * have the multiple-of-16 restriction.
	 */
	if( tile ) { 
		if( (write->tilew & 0xf) != 0 || 
			(write->tileh & 0xf) != 0 ) {
			vips_error( "vips2tiff", 
				"%s", _( "tile size not a multiple of 16" ) );
			return( NULL );
		}
	}

	/* We can only pyramid LABQ and non-complex images. 
	 */
	if( write->pyramid ) {
		if( im->Coding == VIPS_CODING_NONE && 
			vips_band_format_iscomplex( im->BandFmt ) ) {
			vips_error( "vips2tiff", 
				"%s", _( "can only pyramid LABQ and "
				"non-complex images" ) );
			return( NULL );
		}
	}

	/* Only 1-bit-ize 8 bit mono images.
	 */
	if( write->onebit &&
		(im->Coding != VIPS_CODING_NONE || 
			im->BandFmt != VIPS_FORMAT_UCHAR ||
			im->Bands != 1) ) {
		vips_warn( "vips2tiff", 
			"%s", _( "can only squash 1 band uchar images -- "
				"disabling squash" ) );
		write->onebit = 0;
	}

	if( write->onebit && 
		write->compression == COMPRESSION_JPEG ) {
		vips_warn( "vips2tiff", 
			"%s", _( "can't have 1-bit JPEG -- disabling JPEG" ) );
		write->compression = COMPRESSION_NONE;
	}
 
	/* We can only MINISWHITE non-complex images of 1 or 2 bands.
	 */
	if( write->miniswhite &&
		(im->Coding != VIPS_CODING_NONE || 
			vips_band_format_iscomplex( im->BandFmt ) ||
			im->Bands > 2) ) {
		vips_warn( "vips2tiff", 
			"%s", _( "can only save non-complex greyscale images "
				"as miniswhite -- disabling miniswhite" ) );
		write->miniswhite = FALSE;
	}

	/* Sizeof a line of bytes in the TIFF tile.
	 */
	if( im->Coding == VIPS_CODING_LABQ )
		write->tls = write->tilew * 3;
	else if( write->onebit )
		write->tls = VIPS_ROUND_UP( write->tilew, 8 ) / 8;
	else
		write->tls = VIPS_IMAGE_SIZEOF_PEL( im ) * write->tilew;

	/* Build the pyramid framework.
	 */
	write->layer = pyramid_new( write, NULL, im->Xsize, im->Ysize );

	/* Fill all the layers.
	 */
	if( pyramid_fill( write ) ) {
		write_free( write );
		return( NULL );
	}

	if( tile ) 
		write->tbuf = vips_malloc( NULL, 
			TIFFTileSize( write->layer->tif ) );
	else
		write->tbuf = vips_malloc( NULL, 
			TIFFScanlineSize( write->layer->tif ) );
	if( !write->tbuf ) {
		write_free( write );
		return( NULL );
	}

	return( write );
}
示例#5
0
void ReadBinaryRaster(
char *file,
IHEAD **head,
unsigned char **data,
int *bpi,int *width,int *height)
{
   FILE *fp;
   IHEAD *ihead;
   int outbytes, depth, comp, filesize, complen, n;
   unsigned char *indata, *outdata;

   /* open the image file */
   fp = fopen(file,"rb");
   if (fp == NULL)
      syserr("ReadBinaryRaster",file,"fopen");

   /* read in the image header */
   (*head) = readihdr(fp);
   ihead = *head;

   depth = get_depth(ihead);
   if(depth != 1)
      fatalerr("ReadBinaryRaster",file,"not a binary file");
   (*width) = get_width(ihead);
   (*height) = get_height(ihead);
   (*bpi) = get_density(ihead);
   comp = get_compression(ihead);
   complen = get_complen(ihead);

   /* allocate a raster data buffer */
   filesize = SizeFromDepth(*width, *height, depth);
   malloc_uchar(&outdata, filesize, "ReadIheadRaster : outdata");

   /* read in the raster data */
   if(comp == UNCOMP) {   /* file is uncompressed */
      n = fread(outdata,1,filesize,fp);
      if (n != filesize) {
	 (void) fprintf(stderr,
		"ReadBinaryRaster: %s: fread returned %d (expected %d)\n",
		file,n,filesize);
         exit(1);
      } /* IF */
   } else {
      malloc_uchar(&indata, complen, "ReadBinaryRaster : indata");
      n = fread(indata,1,complen,fp); /* file compressed */
      if (n != complen) {
         (void) fprintf(stderr,
		"ReadBinaryRaster: %s: fread returned %d (expected %d)\n",
		file,n,complen);
      } /* IF */
   }

   switch (comp) {
      case RL:
	 rldecomp(indata,complen,outdata,&outbytes,filesize);
         set_compression(ihead, UNCOMP);
         set_complen(ihead, 0);
         free((char *)indata);
         break;
      case CCITT_G4:
         if((*head)->sigbit == LSBF) {
           inv_bytes(indata, complen);
           (*head)->sigbit = MSBF;
           (*head)->byte_order = HILOW;
         }
	 grp4decomp(indata,complen,*width,*height,outdata,&outbytes);
         set_compression(ihead, UNCOMP);
         set_complen(ihead, 0);
         free((char *)indata);
         break;
      case UNCOMP:
         break;
      default:
         fatalerr("ReadBinaryRaster",file,"Invalid compression code");
      break;
   }

   *data = outdata;
   /* close the image file */
   (void) fclose(fp);
}