예제 #1
0
파일: string.C 프로젝트: kmeaw/phantom
void string_t::ctor_t::flush() {
    log_warning("string buffer overflow");

    size_t _size = max((2 * size), (size_t)1024);
    page_t *_string_page = new(_size) page_t(_size);
    memcpy(_string_page->data, string_page->data, size);
    delete string_page;
    string_page = _string_page;

    setup_out(_size, size);
}
예제 #2
0
//======================================================================================================================
void GetMAXLUN(void)
{
	data	U8 tc_state;

	XBYTE[HOST_BUF_SA+0]=0xA1;
	XBYTE[HOST_BUF_SA+1]=0xFE;
	XBYTE[HOST_BUF_SA+2]=0x00;
	XBYTE[HOST_BUF_SA+3]=0x00;
	XBYTE[HOST_BUF_SA+4]=0x00;
	XBYTE[HOST_BUF_SA+5]=0x00;
	XBYTE[HOST_BUF_SA+6]=0x01;
	XBYTE[HOST_BUF_SA+7]=0x00;
    
	tran_setup(1);
	tc_state = Host_phy_Command_check();
	if(tc_state)
    {
		Syn_Reset();
       	return;
    }
	setup_in(1, 1, 0, 1);
	tc_state = Host_phy_Command_check();
	if(tc_state)
    {
		Syn_Reset();
		return;
    }

   	setup_out(1, 0, 0, 1);
	tc_state = Host_phy_Command_check();
	if(tc_state == 0)
    {
 	   MaxLUN=XBYTE[HOST_BUF_SA];
    }
	else
    {
		Syn_Reset();
		return;
    }    
}
예제 #3
0
파일: irz.c 프로젝트: HarryR/imageresize
int
main( int argc, char **argv ) {	
	irz_config_t *config;
	char *temp_out = tmpnam(NULL);

	FILE *in_fh = NULL;
	FILE *out_fh = NULL;
	
	config = parse_options(argc, argv);
	if( config == NULL ) {
		return EXIT_FAILURE+9;
	}
	
	config->logger = irz_logger_stdio;
	config->logger_cfg = stdout;
	
	in_fh = fopen(config->in_file,"r");
	if( ! in_fh ) {
		char buf[200];
		strerror_r(errno, buf, sizeof(buf));
		irz_log(config, IRZ_ERROR, "Cannot open in-file '%s': %s", config->in_file, buf);
		return EXIT_FAILURE+11;
	}
	
	struct jpeg_compress_struct out_cinfo;
	struct jpeg_decompress_struct in_dinfo;
	struct jpeg_error_mgr       jerr;		
	
	setup_in(&in_dinfo, &jerr, in_fh);

	if( config->debug ) {
		irz_log(config, IRZ_DEBUG, "Image Width: %ipx\n", (int)in_dinfo.image_width);
	        irz_log(config, IRZ_DEBUG, "Image Height: %ipx\n", (int)in_dinfo.image_height);
	        irz_log(config, IRZ_DEBUG, "Tmp Loc: %s\n", temp_out);
	}

	if ( config->out_width != 0 ) {
        	if ( (int)in_dinfo.image_width < (int)config->out_width ) {
            		irz_log(config, IRZ_WARN, "specified width is larger than original image, reducing to %ipx.\n", (int)in_dinfo.image_width);
            		config->out_width = (double)in_dinfo.image_width;
        	}
    	}

    	if ( config->out_height != 0 ) {
        	if ( (int)in_dinfo.image_height < (int)config->out_height ) {
            		irz_log(config, IRZ_WARN, "specified height is larger than original image, reducing to %ipx.\n", (int)in_dinfo.image_height);
            		config->out_height = (double)in_dinfo.image_height;
        	}
    	}
	
	/* Auto-scale width or height if either was not specified */
	if( config->mode == MODE_SCALE ) {		
		if( config->out_height == 0 ) {
			double ratio = (double)config->out_width / (double)in_dinfo.image_width;
			config->out_height = ((double)in_dinfo.image_height * ratio);
		}
		else if( config->out_width == 0 ) {
			double ratio = (double)config->out_height / (double)in_dinfo.image_height;
			config->out_width = ((double)in_dinfo.image_width * ratio);
		}
	}
    	else if( config->mode == MODE_SCALEASPECT ) {
        	double ratio;
        	unsigned int new_width = in_dinfo.image_width;
        	unsigned int new_height = in_dinfo.image_height;

        	if (in_dinfo.image_width > in_dinfo.image_height) {
            		ratio = ( (double)in_dinfo.image_width / (double)in_dinfo.image_height ) ;
        	}
		else {
            		ratio = ( (double)in_dinfo.image_height / (double)in_dinfo.image_width ) ;
        	}

		if( config->debug ) {
        		irz_log(config, IRZ_DEBUG, "Ratio: %f\n", ratio);
		}

        	if (in_dinfo.image_width < in_dinfo.image_height) {
            		if (new_width > config->out_width) {
                		new_width = config->out_width;
                		new_height = ( new_height - ( ( (double)in_dinfo.image_width - (double)config->out_width) * ratio ) );

				if( config->debug ) {
             	   			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}

            		if (new_height > config->out_height) {
                		new_width = ( new_width - ( ( (double)new_height - (double)config->out_height) / ratio ) );
                		new_height = config->out_height;

				if( config->debug ) {
             	   			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}
        	}
		else {
            		if (new_width > config->out_width) {
                		new_width = config->out_width;
                		new_height = ( new_height - ( ( (double)in_dinfo.image_width - (double)config->out_width) / ratio ) );

				if( config->debug ) {
             	   			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}

            		if (new_height > config->out_height) {
                		new_width = ( new_width - ( ( (double)new_height - (double)config->out_height) * ratio ) );
                		new_height = config->out_height;

				if( config->debug ) {
              	  			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}
        	}

        	config->out_width = new_width;
        	config->out_height = new_height;
	}
	else if( config->mode == MODE_SCALEFIT ) {
		if( in_dinfo.image_width > config->out_width ) {
			double ratio = (double)config->out_width / (double)in_dinfo.image_width;
			config->out_height = ((double)in_dinfo.image_height * ratio);
			config->out_width = ((double)in_dinfo.image_width * ratio);
		}
		if( in_dinfo.image_height > config->out_height ) {
			double ratio = (double)config->out_height / (double)in_dinfo.image_height;
			config->out_height = ((double)in_dinfo.image_height * ratio);
			config->out_width = ((double)in_dinfo.image_width * ratio);
		}
	}
	else if( config->mode == MODE_CROPMANUAL ) {
		if( (config->crop_x2 - config->crop_x) < 10 ) {
			irz_log(config, IRZ_ERROR, "source crop width too small\n");
			return EXIT_FAILURE+10;
		}
		else if( (config->crop_y2 - config->crop_y) < 10 ) {
			irz_log(config, IRZ_ERROR, "source crop height too small\n");
			return EXIT_FAILURE+10;
		}
		else if( config->crop_x2 > in_dinfo.image_width || config->crop_y2 > in_dinfo.image_height ) {
			irz_log(config, IRZ_ERROR, "source crop area outside of image dimension\n");
			return EXIT_FAILURE+10;
		}
	}

	if( config->debug ) {
        	irz_log(config, IRZ_DEBUG, "Out Width: %upx\n", config->out_width);
        	irz_log(config, IRZ_DEBUG, "Out Height: %upx\n", config->out_height);
	}
	
	out_fh = fopen(temp_out,"wb");
	if( ! out_fh ) {
		char buf[200];
		strerror_r(errno, buf, sizeof(buf));
		irz_log(config, IRZ_ERROR, "Cannot open output file '%s': %s", temp_out, buf);
		return EXIT_FAILURE+12;
	}

	setup_out(&out_cinfo, &jerr, out_fh, config->out_width, config->out_height, config->out_quality);

	int row_stride = in_dinfo.output_width * in_dinfo.output_components;
	JSAMPARRAY buffer;
	buffer = (in_dinfo.mem->alloc_sarray)((j_common_ptr) &in_dinfo, JPOOL_IMAGE, row_stride, 1);
		
	do_resize(&out_cinfo, &in_dinfo, config);

	jpeg_finish_decompress(&in_dinfo);
	jpeg_destroy_decompress(&in_dinfo);
	
	jpeg_finish_compress(&out_cinfo);
	jpeg_destroy_compress(&out_cinfo);
	
	fclose(in_fh);
	fclose(out_fh);
	
	/* XXX: needs to be refactored as rename() won't work across filesystems
	 * temp_out should be in the same directory as out_file */
	if( rename( temp_out, config->out_file ) != 0 ) {
		char buf[200];
		strerror_r(errno, buf, sizeof(buf));
		irz_log(config, IRZ_ERROR, "Cannot rename temporary file '%s' to real file '%s': %s", temp_out, config->out_file, buf);
		return EXIT_FAILURE+13;
	}
	
	free(config);	
	return EXIT_SUCCESS;
}
예제 #4
0
U8 GetDescriptor(U8 addr,U16 wValue,U16 wIndex,U16 wLength)
{
    data	bit	toggle = 1;
	data	U8	tc_state;
	data	U16	offset=0;

	XBYTE[HOST_BUF_SA]		=0x80;
	XBYTE[HOST_BUF_SA+1]	=0x06;
	XBYTE[HOST_BUF_SA+2]	=(U8)(wValue&0xff);
	XBYTE[HOST_BUF_SA+3]	=(U8)((wValue>>8)&0xff);
	XBYTE[HOST_BUF_SA+4]	=(U8)(wIndex&0xff);
	XBYTE[HOST_BUF_SA+5]	=(U8)((wIndex>>8)&0xff);
	XBYTE[HOST_BUF_SA+6]	=(U8)(wLength&0xff);
	XBYTE[HOST_BUF_SA+7]	=(U8)((wLength>>8)&0xff);

    //trans Descript CMD    
	tran_setup(addr);
   	tc_state = Host_phy_Command_check();
	
	if((tc_state!=0)&&(gb_HostInitial!=1))
	{
		if(tc_state!=HOST_TEST_ERROR1)
		{
			return HOST_TRANSETUP_ERROR;
		}
	}

	gb_shortpack=0;
    if(addr == 0x00) 
	{		
		setup_in(addr, wLength, offset, toggle);
		tc_state = Host_phy_Command_check();

		if(tc_state!=0)
		{
			return HOST_SETUPIN_ERROR;
		}
		else
		{
			if(gb_HostConnect == 0)
			{
				return HOST_PHYCOUNECT_FAIL;
			}
			setup_out(addr, 0, offset, 1);

			tc_state = Host_phy_Command_check();
			if((tc_state==HOST_TEST_ERROR)||(tc_state==HOST_TimeOut_ERROR))		   
			{
			}
	  		else if(tc_state)
			{
	  			return HOST_SETUPOUT_ERROR;
			}
            else 
			{
				return 0;
         	}
        }
	}
    else
    {
		while (wLength>0)
      	{
        	if(gb_HostConnect == 0)
 		 	{
		 		return HOST_PHYCOUNECT_FAIL;
		 	}

         	if(wLength <  Max_Trans_Length) 
		 	{
		 		setup_in(addr, wLength, offset, toggle);
				tc_state = Host_phy_Command_check();
		 	}
         	else 
         	{
		 		setup_in(addr, Max_Trans_Length, offset, toggle);
				tc_state = Host_phy_Command_check();
		 	}

			if(gb_shortpack==1)
			{
				break;
			}
         	if(tc_state != 0)
         	{
            	if(tc_state == 0x20)
				{
            		break;
				}
            	if((tc_state > 0x20)&&(offset>0))
	        	{
					break;
				}

            	return HOST_SETUPIN_ERROR;
         	}

         	if((wValue>0x0300)&(offset == 0))
         	{
				if(wLength > XBYTE[HOST_BUF_SA])
   				{
					wLength = XBYTE[HOST_BUF_SA];
				}
         	}
         	toggle ^= 1;
         	offset  = offset  + Max_Trans_Length;
  
         	if(wLength >= Max_Trans_Length)
	     	{
		 		wLength = wLength - Max_Trans_Length;
     	 	}
         	else
         	{
		 		wLength = 0;
 		 	}
	   	}
	}

    setup_out(addr, 0, offset, 1);
	tc_state = Host_phy_Command_check();

    if(tc_state)
	{
		return HOST_SETUPOUT_ERROR;
	}
    else 
	{
		return 0;
	}
}
예제 #5
0
파일: string.C 프로젝트: kmeaw/phantom
string_t::ctor_t::ctor_t(size_t _size) : out_t(NULL, 0) {
    string_page = new(_size) page_t(_size);

    setup_out(_size, 0);
}