@@ -48,6 +48,7 @@ public int Height
4848
4949 #region Presentation Props
5050 bool isSelected ;
51+ string textureInfo ;
5152 BitmapSource preview ;
5253 string previewError ;
5354 Visibility previewErrorVisibility ;
@@ -70,6 +71,15 @@ public bool IsSelected
7071 }
7172 }
7273 }
74+ public string TextureInfo
75+ {
76+ get { return textureInfo ; }
77+ set
78+ {
79+ textureInfo = value ;
80+ OnPropertyChanged ( "TextureInfo" ) ;
81+ }
82+ }
7383 public BitmapSource Preview
7484 {
7585 get { return preview ; }
@@ -102,8 +112,6 @@ public void GetPreview()
102112 {
103113 this . Preview = null ;
104114 dds = ExportDDS ( System . AppDomain . CurrentDomain . BaseDirectory + "\\ temp.dds" , true ) ;
105- //dds = GetPreviewDDS();
106- //dds.Write(File.Open(System.AppDomain.CurrentDomain.BaseDirectory + "\\temp.dds", FileMode.Create, FileAccess.ReadWrite, FileShare.Read), -1);
107115 int maxDimension = ( int ) Math . Max ( dds . header . width , dds . header . height ) ;
108116 Width = ( int ) dds . header . width ;
109117 Height = ( int ) dds . header . height ;
@@ -203,7 +211,7 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
203211 DdsFile dds = new DdsFile ( ) ;
204212
205213 string fNameImage ;
206- using ( ErpBinaryReader reader = new ErpBinaryReader ( Texture . Fragments [ 0 ] . GetDataStream ( true ) ) )
214+ using ( ErpBinaryReader reader = new ErpBinaryReader ( Texture . GetFragment ( "temp" , 0 ) . GetDataStream ( true ) ) )
207215 {
208216 reader . Seek ( 24 , SeekOrigin . Begin ) ;
209217 fNameImage = reader . ReadString ( ) ;
@@ -214,7 +222,7 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
214222 uint width ;
215223 uint height ;
216224 uint mipmaps ;
217- using ( ErpBinaryReader reader = new ErpBinaryReader ( imageEntry . Fragments [ 0 ] . GetDataStream ( true ) ) )
225+ using ( ErpBinaryReader reader = new ErpBinaryReader ( imageEntry . GetFragment ( "temp" , 0 ) . GetDataStream ( true ) ) )
218226 {
219227 reader . Seek ( 8 , SeekOrigin . Begin ) ;
220228 imageType = reader . ReadInt32 ( ) ;
@@ -229,9 +237,10 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
229237 uint mipCount = 0 ;
230238 uint mipWidth = 0 , mipHeight = 0 ;
231239 uint mipLinearSize = 0 ;
232- if ( imageEntry . Fragments . Count >= 3 && imageEntry . Fragments [ 2 ] . Name == "mips" )
240+ ErpFragment mipsFragment = imageEntry . TryGetFragment ( "mips" , 0 ) ;
241+ if ( mipsFragment != null )
233242 {
234- using ( ErpBinaryReader reader = new ErpBinaryReader ( imageEntry . Fragments [ 2 ] . GetDataStream ( true ) ) )
243+ using ( ErpBinaryReader reader = new ErpBinaryReader ( mipsFragment . GetDataStream ( true ) ) )
235244 {
236245 byte strLength = reader . ReadByte ( ) ;
237246 mipMapFileName = reader . ReadString ( strLength ) ;
@@ -250,6 +259,7 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
250259
251260 dds . header . width = width ;
252261 dds . header . height = height ;
262+ textureInfo = width + "x" + height + " Mips:" + ( mipmaps ) + " Format:" + imageType + "," ;
253263 switch ( imageType )
254264 {
255265 case 52 : // ferrari_wheel_sfc
@@ -258,19 +268,22 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
258268 dds . header . pitchOrLinearSize = ( width * height ) / 2 ;
259269 dds . header . ddspf . flags |= DdsPixelFormat . Flags . DDPF_FOURCC ;
260270 dds . header . ddspf . fourCC = BitConverter . ToUInt32 ( Encoding . UTF8 . GetBytes ( "DXT1" ) , 0 ) ;
271+ TextureInfo += "DXT1" ;
261272 break ;
262273 case 55 : // ferrari_sfc
263274 case 57 : // ferrari_decal
264275 dds . header . flags |= DdsHeader . Flags . DDSD_LINEARSIZE ;
265276 dds . header . pitchOrLinearSize = ( width * height ) ;
266277 dds . header . ddspf . flags |= DdsPixelFormat . Flags . DDPF_FOURCC ;
267278 dds . header . ddspf . fourCC = BitConverter . ToUInt32 ( Encoding . UTF8 . GetBytes ( "DXT5" ) , 0 ) ;
279+ TextureInfo += "DXT5" ;
268280 break ;
269281 case 65 : // ferrari_wheel_nm
270282 dds . header . flags |= DdsHeader . Flags . DDSD_LINEARSIZE ;
271283 dds . header . pitchOrLinearSize = ( width * height ) ;
272284 dds . header . ddspf . flags |= DdsPixelFormat . Flags . DDPF_FOURCC ;
273285 dds . header . ddspf . fourCC = BitConverter . ToUInt32 ( Encoding . UTF8 . GetBytes ( "ATI2" ) , 0 ) ;
286+ TextureInfo += "ATI2/3Dc" ;
274287 break ;
275288 case 70 : // flow_boot splash_bg_image; tried just about everything, can't figure it out
276289 dds . header . flags |= DdsHeader . Flags . DDSD_LINEARSIZE ;
@@ -288,7 +301,8 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
288301 //dds.header.ddspf.aBitMask = 0xF000;
289302 goto default ;
290303 default :
291- throw new Exception ( "Image type not supported!" ) ;
304+ TextureInfo += "Unknown" ;
305+ throw new Exception ( "Image format not supported!" ) ;
292306 }
293307 if ( mipmaps > 0 )
294308 {
@@ -300,7 +314,7 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
300314 dds . header . ddspf . size = 32 ;
301315 dds . header . caps |= DdsHeader . Caps . DDSCAPS_TEXTURE ;
302316
303- byte [ ] imageData = imageEntry . Fragments [ 1 ] . GetDataArray ( true ) ;
317+ byte [ ] imageData = imageEntry . GetFragment ( "temp" , 1 ) . GetDataArray ( true ) ;
304318
305319 string mipMapFullFileName = Path . Combine ( Properties . Settings . Default . F12016Dir , mipMapFileName ) ;
306320 bool foundMipMapFile = File . Exists ( mipMapFullFileName ) ;
@@ -345,6 +359,7 @@ public DdsFile ExportDDS(string fileName, bool isPreview)
345359 Buffer . BlockCopy ( mipImageData , 0 , dds . bdata , 0 , mipImageData . Length ) ;
346360 Buffer . BlockCopy ( imageData , 0 , dds . bdata , mipImageData . Length , imageData . Length ) ;
347361 dds . Write ( File . Open ( fileName , FileMode . Create , FileAccess . Write , FileShare . Read ) , - 1 ) ;
362+ TextureInfo += Environment . NewLine + mipWidth + "x" + mipHeight + " Mips:" + ( mipCount ) ;
348363 }
349364 else
350365 {
@@ -386,19 +401,20 @@ public void ImportDDS(string fileName, string mipMapSaveLocation)
386401 throw new Exception ( "Image type not supported!" ) ;
387402 }
388403
389- MemoryStream tgaData = Texture . Fragments [ 0 ] . GetDataStream ( true ) ;
404+ MemoryStream tgaData = Texture . GetFragment ( "temp" , 0 ) . GetDataStream ( true ) ;
390405 string fNameImage ;
391406 ErpBinaryReader reader = new ErpBinaryReader ( tgaData ) ;
392407 reader . Seek ( 24 , SeekOrigin . Begin ) ;
393408 fNameImage = reader . ReadString ( ) ;
394409 ErpResource imageEntry = Texture . ParentFile . FindEntry ( fNameImage ) ;
395410
396411 byte [ ] imageByteData ;
397- if ( imageEntry . Fragments . Count >= 3 && imageEntry . Fragments [ 2 ] . Name == "mips" )
412+ ErpFragment mipsFragment = imageEntry . TryGetFragment ( "mips" , 0 ) ;
413+ if ( mipsFragment != null )
398414 {
399415 string mipMapFileName ;
400416 uint mipCount = dds . header . mipMapCount / 4 ;
401- MemoryStream mipsData = imageEntry . Fragments [ 2 ] . GetDataStream ( true ) ;
417+ MemoryStream mipsData = mipsFragment . GetDataStream ( true ) ;
402418 reader = new ErpBinaryReader ( mipsData ) ;
403419 mipMapFileName = reader . ReadString ( reader . ReadByte ( ) ) ;
404420 uint oldMipCount = reader . ReadUInt32 ( ) ;
@@ -456,7 +472,7 @@ public void ImportDDS(string fileName, string mipMapSaveLocation)
456472 //mipHeight /= 4;
457473 }
458474
459- imageEntry . Fragments [ 2 ] . SetData ( newMipsData . ToArray ( ) ) ;
475+ mipsFragment . SetData ( newMipsData . ToArray ( ) ) ;
460476 }
461477
462478 using ( ErpBinaryWriter writer = new ErpBinaryWriter ( EndianBitConverter . Little , File . Open ( mipMapSaveLocation , FileMode . Create , FileAccess . Write , FileShare . Read ) ) )
@@ -490,7 +506,8 @@ public void ImportDDS(string fileName, string mipMapSaveLocation)
490506 }
491507 Texture . Fragments [ 0 ] . SetData ( tgaData . ToArray ( ) ) ;
492508
493- MemoryStream imageData = imageEntry . Fragments [ 0 ] . GetDataStream ( true ) ;
509+ ErpFragment imageFragment = imageEntry . GetFragment ( "temp" , 0 ) ;
510+ MemoryStream imageData = imageFragment . GetDataStream ( true ) ;
494511 using ( ErpBinaryWriter writer = new ErpBinaryWriter ( EndianBitConverter . Little , imageData ) )
495512 {
496513 writer . Seek ( 8 , SeekOrigin . Begin ) ;
@@ -501,8 +518,8 @@ public void ImportDDS(string fileName, string mipMapSaveLocation)
501518 writer . Write ( dds . header . mipMapCount ) ;
502519 }
503520
504- imageEntry . Fragments [ 0 ] . SetData ( imageData . ToArray ( ) ) ;
505- imageEntry . Fragments [ 1 ] . SetData ( imageByteData ) ;
521+ imageFragment . SetData ( imageData . ToArray ( ) ) ;
522+ imageEntry . GetFragment ( "temp" , 1 ) . SetData ( imageByteData ) ;
506523 }
507524 }
508525}
0 commit comments