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();
}
}