public static ModEnvironmentConfiguration Load(System.IO.FileInfo xmlConfigFile)
 {
     var dcserializer = new System.Runtime.Serialization.DataContractSerializer(typeof(ModEnvironmentConfiguration));
     //var serializer = new System.Xml.Serialization.XmlSerializer(typeof(ModEnvironmentConfiguration));
     using (var fstream = xmlConfigFile.OpenRead())
     {
         var mec = (ModEnvironmentConfiguration)dcserializer.ReadObject(fstream);
         return mec;
     }
 }
Ejemplo n.º 2
0
        public BImage( System.IO.FileInfo _FileName )
        {
            using ( FileStream S = _FileName.OpenRead() )
                using ( BinaryReader R = new BinaryReader( S ) ) {

                    m_sourceFileTime = R.ReadUInt32();
                    m_Magic = R.ReadUInt32();
                    if ( m_Magic != MAGIC )
                        throw new Exception( "Image has unsupported magic!" );

                    m_Opts.Read( R );

                    uint	mipsCountInFile = m_Opts.m_minNumLevels;
                    uint	mipsCountTotal = m_Opts.m_maxNumLevels;

                    List<ImageSlice>	Slices = new List<ImageSlice>();
                    if ( mipsCountInFile < mipsCountTotal ) {
                        // This means the largest mips are stored elsewhere, for streaming purpose...
                        List<string>	MipFileNames = new List<string>();
                        MipFileNames.AddRange( Directory.EnumerateFiles( _FileName.DirectoryName, _FileName.Name + "_mip*" ) );
                        MipFileNames.Sort();
                        foreach ( string MipFileName in MipFileNames ) {
                            using ( FileStream MipS = new FileInfo( MipFileName ).OpenRead() )
                                using ( BinaryReader MipR = new BinaryReader( MipS ) )
                                    Slices.Add( new ImageSlice( this, MipR, 0U ) );
                        }
                    }

                    m_Opts.SetFixedNumLevels( mipsCountTotal );
                    m_Opts.SetFixedWidth( Math.Max( 1U, m_Opts.m_maxWidth ) );
                    m_Opts.SetFixedHeight( Math.Max( 1U, m_Opts.m_maxHeight ) );

                    uint	totalSlicesInFile = mipsCountInFile * m_Opts.m_arraySize;
                    if ( m_Opts.m_type == ImageOptions.TYPE.TT_3D ) {
                        if ( mipsCountInFile != mipsCountTotal )
                            throw new Exception( "Min & Max mips count are the same! Can't compute depth reduction on texture 3D!" );

                        // ARKANE: bmayaux (2013-07-15) We need to account for depth reduction with each new mip level...
                        totalSlicesInFile = 0;
                        uint	depth = m_Opts.m_depth;
                        for ( int mipLevelIndex = 0; mipLevelIndex < mipsCountInFile; mipLevelIndex++ ) {
                            totalSlicesInFile += depth;
                            depth = Math.Max( 1, depth >> 1 );
                        }
                    } else if ( m_Opts.m_type == ImageOptions.TYPE.TT_CUBIC ) {
                        totalSlicesInFile *= 6;
                    }

                    uint	mipOffset = (uint) Slices.Count;
                    for ( uint i = 0; i < totalSlicesInFile; i++ )
                        Slices.Add( new ImageSlice( this, R, mipOffset ) );

                    m_Slices = Slices.ToArray();
                }
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Parses the specified file and process the events over the specified handler.
		/// </summary>
		/// <param name="filepath">The file to be used.</param>
		/// <param name="handler">The handler that manages the parser events.</param>
		public virtual void parse(System.IO.FileInfo filepath, XmlSaxContentHandler handler)
		{
			try
			{
				if (handler is XmlSaxDefaultHandler)
				{
					this.errorHandler = (XmlSaxDefaultHandler) handler;
					this.entityResolver =  (XmlSaxDefaultHandler) handler;
				}
				if (!(this is XmlSaxParserAdapter))
					this.callBackHandler = handler;
				else
				{
					if(this.callBackHandler == null)
						this.callBackHandler = handler;
				}
				System.Xml.XmlTextReader tempTextReader = new System.Xml.XmlTextReader(filepath.OpenRead());
				System.Xml.XmlValidatingReader tempValidatingReader = new System.Xml.XmlValidatingReader(tempTextReader);
				parserFileName = filepath.FullName;
				tempValidatingReader.ValidationType = (this.isValidating) ? System.Xml.ValidationType.DTD : System.Xml.ValidationType.None;
				tempValidatingReader.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(this.ValidationEventHandle);
				this.reader = tempValidatingReader;
				this.DoParsing();
			}
			catch (System.Xml.XmlException e)
			{
				if (this.errorHandler != null)
					this.errorHandler.fatalError(e);
				throw e;
			}
		}
Ejemplo n.º 4
0
 private XmlReader CreateXmlReader(System.IO.FileInfo filePath)
 {
     parserFileName = filePath.FullName;
     return CreateXmlReader(new System.Xml.XmlTextReader(filePath.OpenRead()));
 }
Ejemplo n.º 5
0
 public static void Compress(System.IO.FileInfo fi)
 {
     // Get the stream of the source file.
     using (System.IO.FileStream inFile = fi.OpenRead())
     {
         // Prevent compressing hidden and 
         // already compressed files.
         if ((System.IO.File.GetAttributes(fi.FullName) & System.IO.FileAttributes.Hidden) != System.IO.FileAttributes.Hidden && fi.Extension != ".gz")
         {
             // Create the compressed file.
             using (System.IO.FileStream outFile = System.IO.File.Create(fi.FullName + ".gz"))
             {
                 CompressStream(inFile, outFile);
             }
         }
     }
 }
Ejemplo n.º 6
0
		private void	BuildPhaseQuantileBuffer( System.IO.FileInfo _PhaseQuantileFileName )
		{
			const int	QUANTILES_COUNT = 65536;

			Reg( m_SB_PhaseQuantile = new StructuredBuffer<float>( m_Device, 2*QUANTILES_COUNT, true ) );
			using ( System.IO.FileStream S = _PhaseQuantileFileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) )
				{
					for ( int i=0; i < m_SB_PhaseQuantile.m.Length; i++ )
						m_SB_PhaseQuantile.m[i] = R.ReadSingle();
				}
			m_SB_PhaseQuantile.Write();
		}
Ejemplo n.º 7
0
/*	https://knarkowicz.wordpress.com/2014/12/27/analytical-dfg-term-for-ibl/
uint32_t ReverseBits( uint32_t v )
{
    v = ( ( v >> 1 ) & 0x55555555 ) | ( ( v & 0x55555555 ) << 1 );
    v = ( ( v >> 2 ) & 0x33333333 ) | ( ( v & 0x33333333 ) << 2 );
    v = ( ( v >> 4 ) & 0x0F0F0F0F ) | ( ( v & 0x0F0F0F0F ) << 4 );
    v = ( ( v >> 8 ) & 0x00FF00FF ) | ( ( v & 0x00FF00FF ) << 8 );
    v = (   v >> 16               ) | (   v                << 16 );
    return v;
}

float GSmith( float roughness, float ndotv, float ndotl )
{
    float const m2   = roughness * roughness;
    float const visV = ndotv + sqrt( ndotv * ( ndotv - ndotv * m2 ) + m2 );
    float const visL = ndotl + sqrt( ndotl * ( ndotl - ndotl * m2 ) + m2 );

    return 1.0f / ( visV * visL );
}

int main()
{
    float const MATH_PI         = 3.14159f;
    unsigned const LUT_WIDTH    = 128;
    unsigned const LUT_HEIGHT   = 128;
    unsigned const sampleNum    = 128;

    float lutData[ LUT_WIDTH * LUT_HEIGHT * 4 ];

    for ( unsigned y = 0; y < LUT_HEIGHT; ++y )
    {
        float const ndotv = ( y + 0.5f ) / LUT_WIDTH;

        for ( unsigned x = 0; x < LUT_WIDTH; ++x )
        {
            float const gloss       = ( x + 0.5f ) / LUT_HEIGHT;
            float const roughness   = powf( 1.0f - gloss, 4.0f );

            float const vx = sqrtf( 1.0f - ndotv * ndotv );
            float const vy = 0.0f;
            float const vz = ndotv;

            float scale = 0.0f;
            float bias  = 0.0f;

            
            for ( unsigned i = 0; i < sampleNum; ++i )
            {
                float const e1 = (float) i / sampleNum;
                float const e2 = (float) ( (double) ReverseBits( i ) / (double) 0x100000000LL );

                float const phi         = 2.0f * MATH_PI * e1;
                float const cosPhi      = cosf( phi );
                float const sinPhi      = sinf( phi );
                float const cosTheta    = sqrtf( ( 1.0f - e2 ) / ( 1.0f + ( roughness * roughness - 1.0f ) * e2 ) );
                float const sinTheta    = sqrtf( 1.0f - cosTheta * cosTheta );

                float const hx  = sinTheta * cosf( phi );
                float const hy  = sinTheta * sinf( phi );
                float const hz  = cosTheta;

                float const vdh = vx * hx + vy * hy + vz * hz;
                float const lx  = 2.0f * vdh * hx - vx;
                float const ly  = 2.0f * vdh * hy - vy;
                float const lz  = 2.0f * vdh * hz - vz;

                float const ndotl = std::max( lz,   0.0f );
                float const ndoth = std::max( hz,   0.0f );
                float const vdoth = std::max( vdh,  0.0f );

                if ( ndotl > 0.0f )
                {
                    float const gsmith      = GSmith( roughness, ndotv, ndotl );
                    float const ndotlVisPDF = ndotl * gsmith * ( 4.0f * vdoth / ndoth );
                    float const fc          = powf( 1.0f - vdoth, 5.0f );

                    scale   += ndotlVisPDF * ( 1.0f - fc );
                    bias    += ndotlVisPDF * fc;
                }
            }
            scale /= sampleNum;
            bias  /= sampleNum;

            lutData[ x * 4 + y * LUT_WIDTH * 4 + 0 ] = scale;
            lutData[ x * 4 + y * LUT_WIDTH * 4 + 1 ] = bias;
            lutData[ x * 4 + y * LUT_WIDTH * 4 + 2 ] = 0.0f;
            lutData[ x * 4 + y * LUT_WIDTH * 4 + 3 ] = 0.0f;
        }
    }   

} */

#endif

		Texture2D	BuildBRDFTexture( System.IO.FileInfo _TableFileName, uint _TableSize ) {

			float2[,]	Table = new float2[_TableSize,_TableSize];

			float	MinA = 1, MaxA = 0;
			float	MinB = 1, MaxB = 0;
			using ( System.IO.FileStream S = _TableFileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) )
					for ( int Y=0; Y < _TableSize; Y++ )
						for ( int X=0; X < _TableSize; X++ ) {
							float	A = R.ReadSingle();
							float	B = R.ReadSingle();
							Table[X,Y].x = A;
							Table[X,Y].y = B;
							MinA = Math.Min( MinA, A );
							MaxA = Math.Max( MaxA, A );
							MinB = Math.Min( MinB, B );
							MaxB = Math.Max( MaxB, B );
						}

			// MaxA = 1
			// MaxB = 0.00014996325546887346

// MaxA = 1.0;
// MaxB = 1.0;

			// Create the texture
//			PixelsBuffer	Content = new PixelsBuffer( _TableSize*_TableSize*4 );
			PixelsBuffer	Content = new PixelsBuffer( (uint) (_TableSize*_TableSize*2*4) );
			using ( System.IO.BinaryWriter W = Content.OpenStreamWrite() )
			for ( int Y=0; Y < _TableSize; Y++ )
				for ( int X=0; X < _TableSize; X++ ) {
// 					W.Write( (ushort) (65535.0 * Table[X,Y].x / MaxA) );
// 					W.Write( (ushort) (65535.0 * Table[X,Y].y / MaxB) );
					W.Write( Table[X,Y].x );
					W.Write( Table[X,Y].y );
				}


//			Texture2D	Result = new Texture2D( m_Device, _TableSize, _TableSize, 1, 1, PIXEL_FORMAT.RG16_UNORM, false, false, new PixelsBuffer[] { Content } );
			Texture2D	Result = new Texture2D( m_Device, _TableSize, _TableSize, 1, 1, PIXEL_FORMAT.RG32_FLOAT, false, false, new PixelsBuffer[] { Content } );
			return Result;
		}
Ejemplo n.º 8
0
        private bool OpenXmlFile(System.IO.FileInfo fileInfo)
        {
            try
            {
                System.IO.FileStream fileStream = fileInfo.OpenRead();
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(Definition));
                this.definition = xmlSerializer.Deserialize(fileStream) as Definition;
                fileStream.Close();

                // refresh tree view.
                RefreshDefinition();

                UpdateCurrentFile(fileInfo);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Open", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads a ROM file into the memory bytearray
        /// </summary>
        /// <param name="romFile">path to the ROM file</param>
        /// <returns></returns>
        public Boolean LoadRom(System.IO.FileInfo romFile)
        {
            System.IO.FileStream fs = romFile.OpenRead();

            int offset = 512; // 0x200 - start of working RAM
            int remaining = (int)fs.Length;

            while (remaining > 0)
            {
                int read = fs.Read(this.memory, offset, remaining);
                remaining -= read;
                offset += read;
            }

            return true;
        }
Ejemplo n.º 10
0
		/// <summary>
		/// Builds the SAT
		/// </summary>
		/// <param name="_FileName"></param>
		public unsafe void	ComputeSAT( System.IO.FileInfo _FileName, System.IO.FileInfo _TargetFileName ) {
			int		W, H;
			byte[]	Content = null;
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				using ( Bitmap B = Bitmap.FromStream( S ) as Bitmap )
				{
					W = B.Width;
					H = B.Height;
					Content = new byte[W*H*4];

					BitmapData	LockedBitmap = B.LockBits( new Rectangle( 0, 0, W, H ), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb );
					for ( int Y=0; Y < H; Y++ )
					{
						byte*	pScanline = (byte*) LockedBitmap.Scan0 + Y * LockedBitmap.Stride;
						int		Offset = 4*W*Y;
						for ( int X=0; X < W; X++, Offset+=4 )
						{
							Content[Offset+2] = *pScanline++;	// B
							Content[Offset+1] = *pScanline++;	// G
							Content[Offset+0] = *pScanline++;	// R
							Content[Offset+3] = *pScanline++;	// A
						}
					}
					B.UnlockBits( LockedBitmap );
				}

			// Build the float4 image
			float4[,]	Image = new float4[W,H];
			for ( int Y=0; Y < H; Y++ ) {
				for ( int X=0; X < W; X++ ) {
					Image[X,Y] = new float4( Content[4*(W*Y+X)+0] / 255.0f, Content[4*(W*Y+X)+1] / 255.0f, Content[4*(W*Y+X)+2] / 255.0f, 0.0f );

					// Linearize from gamma space
					Image[X,Y].x = (float) Math.Pow( Image[X,Y].x, 2.2 );
					Image[X,Y].y = (float) Math.Pow( Image[X,Y].y, 2.2 );
					Image[X,Y].z = (float) Math.Pow( Image[X,Y].z, 2.2 );
				}
			}

			//////////////////////////////////////////////////////////////////////////
			// Build mips and save as a simple format
			{
				int	MaxSize = Math.Max( W, H );
				int	MipsCount = (int) (Math.Ceiling( Math.Log( MaxSize+1 ) / Math.Log( 2 ) ));
				float4[][,]	Mips = new float4[MipsCount][,];
				Mips[0] = Image;

				int	TargetWidth = W;
				int	TargetHeight = H;
				for ( int MipLevel=1; MipLevel < Mips.Length; MipLevel++ ) {
					TargetWidth = Math.Max( 1, TargetWidth >> 1 );
					TargetHeight = Math.Max( 1, TargetHeight >> 1 );

					float	MipPixelSizeX = W / TargetWidth;	// Size of a mip pixel; in amount of original image pixels (i.e. mip #0)
					float	MipPixelSizeY = H / TargetHeight;	// Size of a mip pixel; in amount of original image pixels (i.e. mip #0)
					int		KernelSize = 2 * (int) Math.Pow( 2, MipLevel );
					float	Sigma = (float) Math.Sqrt( -KernelSize*KernelSize / (2.0 * Math.Log( 0.01 )) );	// So we have a weight of 0.01 at a Kernel Size distance
					float[]	KernelFactors = new float[1+KernelSize];
					float	SumWeights = 0.0f;
					for ( int i=0; i <= KernelSize; i++ ) {
						KernelFactors[i] = (float) (Math.Exp( -i*i / (2.0 * Sigma * Sigma)) / Math.Sqrt( 2 * Math.PI * Sigma * Sigma ) );
						SumWeights += KernelFactors[i];
					}

					// Perform a horizontal blur first
					float4[,]	Source = Image;
					float4[,]	Target = new float4[TargetWidth,H];
					for ( int Y=0; Y < H; Y++ ) {
						for ( int X=0; X < TargetWidth; X++ ) {
							float	CenterX = X * MipPixelSizeX + 0.5f * (MipPixelSizeX-1);
							float4	Sum = KernelFactors[0] * BilinearSample( Source, CenterX, Y );
							for ( int i=1; i <= KernelSize; i++ ) {
								Sum += KernelFactors[i] * BilinearSample( Image, CenterX - i, Y );
								Sum += KernelFactors[i] * BilinearSample( Image, CenterX + i, Y );
							}
							Target[X,Y] = Sum;
						}
					}

					// Perform vertical blur
					Source = Target;
					Mips[MipLevel] = new float4[TargetWidth,TargetHeight];
					Target = Mips[MipLevel];
					for ( int X=0; X < TargetWidth; X++ ) {
						for ( int Y=0; Y < TargetHeight; Y++ ) {
							float	CenterY = Y * MipPixelSizeY + 0.5f * (MipPixelSizeY-1);
							float4	Sum = KernelFactors[0] * BilinearSample( Source, X, CenterY );
							for ( int i=1; i <= KernelSize; i++ ) {
								Sum += KernelFactors[i] * BilinearSample( Source, X, CenterY - i );
								Sum += KernelFactors[i] * BilinearSample( Source, X, CenterY + i );
							}
							Target[X,Y] = Sum;
						}
					}
				}


				string	Pipi = _TargetFileName.FullName;
				Pipi = System.IO.Path.GetFileNameWithoutExtension( Pipi ) + ".pipi";
				System.IO.FileInfo	SimpleTargetFileName2 = new System.IO.FileInfo(  Pipi );
				using ( System.IO.FileStream S = SimpleTargetFileName2.OpenWrite() )
					using ( System.IO.BinaryWriter Wr = new System.IO.BinaryWriter( S ) ) {
						Wr.Write( Mips.Length );
						for ( int MipLevel=0; MipLevel < Mips.Length; MipLevel++ ) {
							float4[,]	Mip = Mips[MipLevel];

							int	MipWidth = Mip.GetLength( 0 );
							int	MipHeight = Mip.GetLength( 1 );
							Wr.Write( MipWidth );
							Wr.Write( MipHeight );

							for ( int Y=0; Y < MipHeight; Y++ ) {
								for ( int X=0; X < MipWidth; X++ ) {
									Wr.Write( Mip[X,Y].x );
									Wr.Write( Mip[X,Y].y );
									Wr.Write( Mip[X,Y].z );
									Wr.Write( Mip[X,Y].w );
								}
							}
						}
					}
			}


// 			//////////////////////////////////////////////////////////////////////////
// 			// Build "3D mips" and save as a simple format
// 			{
// 				int	MaxSize = Math.Max( W, H );
// 				int	MipsCount = (int) (Math.Ceiling( Math.Log( MaxSize+1 ) / Math.Log( 2 ) ));
// 
// 				// 1] Build vertical mips
// 				float4[][,]	VerticalMips = new float4[MipsCount][,];
// 				VerticalMips[0] = Image;
// 
// 				int	TargetHeight = H;
// 				for ( int MipLevel=1; MipLevel < MipsCount; MipLevel++ ) {
// 					int	SourceHeight = TargetHeight;
// 
// 					int	BorderSize = (int) Math.Pow( 2, MipLevel-1 );
// 					TargetHeight = Math.Max( 1, H - 2*BorderSize );
// 
// 					float4[,]	SourceMip = VerticalMips[MipLevel-1];
// 					float4[,]	TargetMip = new float4[W,TargetHeight];
// 					VerticalMips[MipLevel] = TargetMip;
// 					for ( int Y=0; Y < TargetHeight; Y++ ) {
// 						float	fY = (float) (Y+0.5f) * SourceHeight / TargetHeight;
// 						for ( int X=0; X < W; X++ ) {
// 							TargetMip[X,Y] = BilinearSample( SourceMip, X, fY );
// 						}
// 					}
// 				}
// 
// 
// //MipsCount = 6;
// 
// 				// 2] Build smoothed slices
// 				float4[][,]	Slices = new float4[MipsCount][,];
// 				Slices[0] = Image;
// 
// 				for ( int MipLevel=1; MipLevel < Slices.Length; MipLevel++ ) {
// 
// 					int		BorderSize = (int) Math.Pow( 2, MipLevel-1 );		// Each new "mip" has a border twice the size of the previous level
// 
// 					int		InsetWidth = Math.Max( 1, W - 2 * BorderSize );		// The inset image is now reduced to account for borders
// 					int		InsetHeight = Math.Max( 1, H - 2 * BorderSize );
// 
// 					int		WidthWithBorders = W + 2 * BorderSize;				// The larger image with borders that will be stored in the specific mip
// 					int		HeightWithBorders = H + 2 * BorderSize;
// 
// 					int		Y0 = BorderSize;
// 					int		Y1 = H - BorderSize;
// 
// 					// Build gaussian weights
// 					int		KernelSize = 2 * (int) BorderSize;
// 					float	Sigma = (float) Math.Sqrt( -KernelSize*KernelSize / (2.0 * Math.Log( 0.01 )) );	// So we have a weight of 0.01 at a Kernel Size distance
// 					float[]	KernelFactors = new float[1+KernelSize];
// 					float	SumWeights = 0.0f;
// 					for ( int i=0; i <= KernelSize; i++ ) {
// 						KernelFactors[i] = (float) (Math.Exp( -i*i / (2.0 * Sigma * Sigma)) / Math.Sqrt( 2 * Math.PI * Sigma * Sigma ) );
// 						SumWeights += KernelFactors[i];
// 					}
// 
// 					// Perform a horizontal blur first
// 					float4[,]	Source = VerticalMips[MipLevel];
// 					float4[,]	Target = new float4[W,H];
// 					for ( int Y=0; Y < H; Y++ ) {
// 						if ( Y < Y0 || Y >= Y1 ) {
// 							// In the borderlands
// 							for ( int X=0; X < W; X++ ) {
// 								Target[X,Y] = float4.Zero;
// 							}
// 							continue;
// 						}
// 
// 						float	fY = (float) (Y - Y0) * H / InsetHeight;
// 						for ( int X=0; X < W; X++ ) {
// 							float			CenterX = 0.5f * W + ((float) (X+0.5f) / W - 0.5f) * WidthWithBorders;
// 							float4	Sum = KernelFactors[0] * BilinearSample( Source, CenterX, fY );
// 							for ( int i=1; i <= KernelSize; i++ ) {
// 								Sum += KernelFactors[i] * BilinearSample( Image, CenterX - i, fY );
// 								Sum += KernelFactors[i] * BilinearSample( Image, CenterX + i, fY );
// 							}
// 							Target[X,Y] = Sum;
// 						}
// 					}
// 
// 					// Perform vertical blur
// 					Source = Target;
// 					Slices[MipLevel] = new float4[W,H];
// 					Target = Slices[MipLevel];
// 					for ( int X=0; X < W; X++ ) {
// 						for ( int Y=0; Y < H; Y++ ) {
// 							float			CenterY = 0.5f * H + ((float) (Y+0.5f) / H - 0.5f) * HeightWithBorders;
// 							float4	Sum = KernelFactors[0] * BilinearSample( Source, X, CenterY );
// 							for ( int i=1; i <= KernelSize; i++ ) {
// 								Sum += KernelFactors[i] * BilinearSample( Source, X, CenterY - i );
// 								Sum += KernelFactors[i] * BilinearSample( Source, X, CenterY + i );
// 							}
// 							Target[X,Y] = Sum;
// 						}
// 					}
// 				}
// 
// 
// 				string	Pipu = _TargetFileName.FullName;
// 				Pipu = System.IO.Path.GetFileNameWithoutExtension( Pipu ) + ".pipu";
// 				System.IO.FileInfo	SimpleTargetFileName2 = new System.IO.FileInfo(  Pipu );
// 				using ( System.IO.FileStream S = SimpleTargetFileName2.OpenWrite() )
// 					using ( System.IO.BinaryWriter Wr = new System.IO.BinaryWriter( S ) ) {
// 						Wr.Write( Slices.Length );
// 						Wr.Write( W );
// 						Wr.Write( H );
// 
// 						for ( int MipLevel=0; MipLevel < Slices.Length; MipLevel++ ) {
// 							float4[,]	Mip = Slices[MipLevel];
// 							for ( int Y=0; Y < H; Y++ ) {
// 								for ( int X=0; X < W; X++ ) {
// 									Wr.Write( Mip[X,Y].x );
// 									Wr.Write( Mip[X,Y].y );
// 									Wr.Write( Mip[X,Y].z );
// 									Wr.Write( Mip[X,Y].w );
// 								}
// 							}
// 						}
// 					}
// 			}

			//////////////////////////////////////////////////////////////////////////
			// Build the SAT
			for ( int Y=0; Y < H; Y++ ) {
				for ( int X=1; X < W; X++ ) {
					Image[X,Y] += Image[X-1,Y];	// Accumulate along X
				}
			}

			for ( int X=0; X < W; X++ ) {
				for ( int Y=1; Y < H; Y++ ) {
					Image[X,Y] += Image[X,Y-1];	// Accumulate along Y
				}
			}

//			DirectXTexManaged.TextureCreator.CreateRGBA16FFile( _TargetFileName.FullName, Image );
throw new Exception( "Deprecated!" );

			// Save as a simple format
			string	Pipo = _TargetFileName.FullName;
			Pipo = System.IO.Path.GetFileNameWithoutExtension( Pipo ) + ".pipo";
			System.IO.FileInfo	SimpleTargetFileName = new System.IO.FileInfo(  Pipo );
			using ( System.IO.FileStream S = SimpleTargetFileName.OpenWrite() )
				using ( System.IO.BinaryWriter Wr = new System.IO.BinaryWriter( S ) ) {

					Wr.Write( W );
					Wr.Write( H );
					for ( int Y=0; Y < H; Y++ ) {
						for ( int X=0; X < W; X++ ) {
							Wr.Write( Image[X,Y].x );
							Wr.Write( Image[X,Y].y );
							Wr.Write( Image[X,Y].z );
							Wr.Write( Image[X,Y].w );
						}
					}
				}
		} 
Ejemplo n.º 11
0
		public Texture2D	PipoImage2Texture( System.IO.FileInfo _FileName ) {
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) ) {

					int	W, H;
					W = R.ReadInt32();
					H = R.ReadInt32();

					PixelsBuffer	Buff = new PixelsBuffer( (uint) (4 * W * H * 4) );
					using ( System.IO.BinaryWriter Wr = Buff.OpenStreamWrite() )
					{
						float4	C = new float4();
						for ( int Y=0; Y < H; Y++ ) {
							for ( int X=0; X < W; X++ ) {
								C.x = R.ReadSingle();
								C.y = R.ReadSingle();
								C.z = R.ReadSingle();
								C.w = R.ReadSingle();

								Wr.Write( C.x );
								Wr.Write( C.y );
								Wr.Write( C.z );
								Wr.Write( C.w );
							}
						}
					}

					return Image2Texture( (uint) W, (uint) H, PIXEL_FORMAT.RGBA32_FLOAT, Buff );
				}
		}
Ejemplo n.º 12
0
		public Texture3D	Pipu2Texture( System.IO.FileInfo _FileName ) {
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) ) {

					int		SlicesCount = R.ReadInt32();
					int		W = R.ReadInt32();
					int		H = R.ReadInt32();

					PixelsBuffer	Slices = new PixelsBuffer( (uint) (4 * W * H * SlicesCount * 4) );
					using ( System.IO.BinaryWriter Wr = Slices.OpenStreamWrite() ) {
						for ( int SliceIndex=0; SliceIndex < SlicesCount; SliceIndex++ ) {
							float4	C = new float4();
							for ( int Y=0; Y < H; Y++ ) {
								for ( int X=0; X < W; X++ ) {
									C.x = R.ReadSingle();
									C.y = R.ReadSingle();
									C.z = R.ReadSingle();
									C.w = R.ReadSingle();

									Wr.Write( C.x );
									Wr.Write( C.y );
									Wr.Write( C.z );
									Wr.Write( C.w );
								}
							}
						}
					}

					return Image2Texture3D( (uint) W, (uint) H, (uint) SlicesCount, PIXEL_FORMAT.RGBA32_FLOAT, new PixelsBuffer[] { Slices } );
				}
		}
Ejemplo n.º 13
0
		public Texture2D	Pipi2Texture( System.IO.FileInfo _FileName ) {
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				using ( System.IO.BinaryReader R = new System.IO.BinaryReader( S ) ) {

					int				MipLevels = R.ReadInt32();
					PixelsBuffer[]	Mips = new PixelsBuffer[MipLevels];
					int				ImageWidth = 0, ImageHeight = 0;
					for ( int MipLevel=0; MipLevel < MipLevels; MipLevel++ ) {
						int	W, H;
						W = R.ReadInt32();
						H = R.ReadInt32();
						if ( MipLevel == 0 ) {
							ImageWidth = W;
							ImageHeight = H;
						}

						PixelsBuffer	Buff = new PixelsBuffer( (uint) (4 * W * H * 4) );
						Mips[MipLevel] = Buff;
						using ( System.IO.BinaryWriter Wr = Buff.OpenStreamWrite() )
						{
							float4	C = new float4();
							for ( int Y=0; Y < H; Y++ ) {
								for ( int X=0; X < W; X++ ) {
									C.x = R.ReadSingle();
									C.y = R.ReadSingle();
									C.z = R.ReadSingle();
									C.w = R.ReadSingle();

									Wr.Write( C.x );
									Wr.Write( C.y );
									Wr.Write( C.z );
									Wr.Write( C.w );
								}
							}
						}
					}

					return Image2Texture( (uint) ImageWidth, (uint) ImageHeight, PIXEL_FORMAT.RGBA32_FLOAT, Mips );
				}
		}
Ejemplo n.º 14
0
		public Texture2D	Image2Texture( System.IO.FileInfo _FileName ) {
			using ( System.IO.FileStream S = _FileName.OpenRead() )
				return Image2Texture( S );
		}
Ejemplo n.º 15
0
		/// <summary>
		/// Parses the specified file and process the events over previously specified handler.
		/// </summary>
		/// <param name="filepath">The file with the XML.</param>
		public virtual void parse(System.IO.FileInfo filepath)
		{
			try
			{
				System.Xml.XmlTextReader tempTextReader = new System.Xml.XmlTextReader(filepath.OpenRead());
				System.Xml.XmlValidatingReader tempValidatingReader = new System.Xml.XmlValidatingReader(tempTextReader);
				parserFileName = filepath.FullName;
				tempValidatingReader.ValidationType = (this.isValidating) ? System.Xml.ValidationType.DTD : System.Xml.ValidationType.None;
				tempValidatingReader.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(this.ValidationEventHandle);
				this.reader = tempValidatingReader;
				this.DoParsing();
			}
			catch (System.Xml.XmlException e)
			{
				if (this.errorHandler != null)
					this.errorHandler.fatalError(e);
				throw e;
			}
		}
Ejemplo n.º 16
0
        /// <summary>
        /// 向客户端发送文件(在.ashx文件中使用)
        /// </summary>
        /// <param name="context">上下文信息</param>
        /// <param name="fileName">文件在客户端保存的名称</param>
        /// <param name="fi">文件在服务器上信息</param>
        public static void ResponseFile(HttpContext context, string fileName, System.IO.FileInfo fi)
        {
            context.Response.Clear();
            context.Response.Buffer = false;
            context.Response.ContentType = GetContentType(fi.Extension);
            if (fi != null && fi.Exists)
            {
                if (context.Request.Browser.Browser.ToLower().Contains("ie")) //IE使用编码
                {
                    context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(context.Response.ContentEncoding.GetBytes(fileName)));
                }
                else //其它浏览器不使用编码
                {
                    context.Response.AppendHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", fileName));
                }
                context.Response.AddHeader("Connection", "Keep-Alive");
                context.Response.AddHeader("Accept-Ranges", "bytes");
                context.Response.Buffer = false;


                context.Response.Cache.SetLastModified(fi.LastWriteTime);
                context.Response.Cache.SetETag(fi.LastWriteTime.Ticks.ToString());


                //ETags和If-None-Match是一种常用的判断资源是否改变的方法。
                //类似于Last-Modified和HTTP-IF-MODIFIED-SINCE。
                //所不同的是Last-Modified和HTTP-IF-MODIFIED-SINCE只判断资源的最后修改时间,而ETags和If-None-Match可以是资源任何的任何属性,如资源的MD5等。

                if (context.Request.Headers["If-None-Match"] != null)
                {
                    if (fi.LastWriteTime.Ticks.ToString() == context.Request.Headers["If-None-Match"])
                    {
                        context.Response.StatusCode = 304;
                        context.Response.StatusDescription = "Not Modified";
                        context.Response.End();
                        return;
                    }
                }

                //Last-Modified 与If-Modified-Since 都是用于记录页面最后修改时间的 HTTP 头信息,
                //Last-Modified 是由服务器往客户端发送的 HTTP 头,而 If-Modified-Since 则是由客户端往服务器发送的头
                if (context.Request.Headers["If-Modified-Since"] != null)
                {
                    DateTime fromhttptime;
                    DateTime.TryParse(context.Request.Headers["If-Modified-Since"], out fromhttptime);
                    if (fi.LastWriteTime.ToString() == fromhttptime.ToString())
                    {
                        context.Response.StatusCode = 304;
                        context.Response.StatusDescription = "Not Modified";
                        return;
                    }
                }

                using (FileStream fs = fi.OpenRead())
                {
                    BinaryReader br = new BinaryReader(fs);
                    try
                    {
                        int bufferlength = 5120;
                        int currentlength = 0;
                        byte[] buffer = new byte[bufferlength];
                        context.Response.AddHeader("Content-Length", fs.Length.ToString());
                        if (context.Response.IsClientConnected)
                        {
                            while (currentlength + bufferlength < fs.Length)
                            {
                                currentlength += br.Read(buffer, 0, buffer.Length);
                                context.Response.BinaryWrite(buffer);
                            }
                            if (fs.Length - currentlength > 0)
                            {
                                buffer = new byte[fs.Length - currentlength];
                                br.Read(buffer, 0, buffer.Length);
                                context.Response.BinaryWrite(buffer);
                            }
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                        context.Response.OutputStream.Close();
                        br.Close();
                        fs.Close();
                    }
                    context.Response.Close();
                }
            }
            else
            {
                context.Response.StatusCode = 404;
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Compiles the given msl script file to a Script instance.
 /// </summary>
 /// <param name="file">The file to compile.</param>
 /// <returns>The compiled script.</returns>
 public ScriptContainer Compile(System.IO.FileInfo file, string binPathes)
 {
     ScriptContainer result = new ScriptContainer(binPathes, file.Name);
     Parser mslParser = new Parser();
     StreamReader reader = new StreamReader(file.OpenRead(), System.Text.Encoding.Default, false);
     CodeCompileUnit unit = mslParser.Parse(reader);
     reader.Close();
     result.ScriptDom = unit;
     result.Compile(file.Name, this);
     return result;
 }
Ejemplo n.º 18
0
 /// <summary>
 ///  计算指定文件的SHA1值
 /// </summary>
 /// <param name="fileName">指定文件的完全限定名称</param>
 /// <returns>返回值的字符串形式</returns>
 public String ComputeSHA1(System.IO.FileInfo fileInfo)
 {
     String hashSHA1 = String.Empty;
     //检查文件是否存在,如果文件存在则进行计算,否则返回空值
     if (fileInfo.Exists)
     {
         using (System.IO.FileStream fs = fileInfo.OpenRead())
         {
             //计算文件的SHA1值
             System.Security.Cryptography.SHA1 calculator = System.Security.Cryptography.SHA1.Create();
             Byte[] buffer = calculator.ComputeHash(fs);
             calculator.Clear();
             //将字节数组转换成十六进制的字符串形式
             StringBuilder stringBuilder = new StringBuilder();
             for (int i = 0; i < buffer.Length; i++)
             {
                 stringBuilder.Append(buffer[i].ToString("x2"));
             }
             hashSHA1 = stringBuilder.ToString();
         }//关闭文件流
     }
     return hashSHA1;
 }
Ejemplo n.º 19
0
 public static void LoadFromFile(System.IO.FileInfo file)
 {
     var deserializer = new System.Xml.Serialization.XmlSerializer(typeof(List<Page>));
     using (var fileStream = file.OpenRead())
         pages = deserializer.Deserialize(fileStream) as List<Page>;
 }