/[Sims3RigEditor]/trunk/gr2lib_typedefs/typedefs/TextureCreator/bink_texture_creator.cs
ViewVC logotype

Diff of /trunk/gr2lib_typedefs/typedefs/TextureCreator/bink_texture_creator.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib_typedefs/typedefs/TextureCreator/bink_texture_creator.cs	2010/08/11 10:59:40	54
+++ trunk/gr2lib_typedefs/typedefs/TextureCreator/bink_texture_creator.cs	2010/08/12 08:37:47	55
@@ -121,19 +121,19 @@
                     {
                         fixed (byte* dest = this.PixelBytes)
                         {
-                            int bink_compress = 0;
-                            uint bink_flags = (uint)(granny_bink_texture_flags.GrannyBinkEncodeAlpha | granny_bink_texture_flags.GrannyBinkUseBink1);
-                            bink_compress = coreapi.TextureSupport.GrannyBinkCompressTexture(
+                            int bink_compressed_size = 0;
+                            uint bink_texture_flags = (uint)(granny_bink_texture_flags.GrannyBinkEncodeAlpha | granny_bink_texture_flags.GrannyBinkUseBink1);
+                            bink_compressed_size = coreapi.TextureSupport.GrannyBinkCompressTexture(
                                 this.TextureWidth,
                                 this.TextureHeight,
                                 this.TextureStride,
                                 this.PixelBytesPointer,
-                                bink_flags,
+                                bink_texture_flags,
                                 (int)granny_compression_type.GrannyNoCompression,
                                 new IntPtr(dest));
-                            byte[] _compressed_pixel_bytes = new byte[bink_compress];
+                            byte[] _compressed_pixel_bytes = new byte[bink_compressed_size];
 
-                            for (int i = 0; i < bink_compress; i++)
+                            for (int i = 0; i < bink_compressed_size; i++)
                             {
                                 _compressed_pixel_bytes[i] = this.PixelBytes[i];
                             }
@@ -151,7 +151,7 @@
             {
                 this.HaveBindableTexture = false;
                 //Debug.WriteLine(ex.ToString());
-                throw new InvalidOperationException("Failed to read texture using: " + new bink_texture_creator().TextureCreatorName, ex);
+                throw new InvalidOperationException("Failed to read texture using: " + this.TextureCreatorName, ex);
             }
         }
         protected override MemoryStream UnParse()
@@ -163,8 +163,8 @@
         {
             Color[] _ColorData;
             this.PixelBytesCount = _texture.Width * _texture.Height;
-          
-
+            MemoryStream ms = new MemoryStream();
+            BinaryWriter w = new BinaryWriter(ms);
             switch ((SurfaceFormat)this.TextureRawPixelFormat)
             {
                 case SurfaceFormat.Color:
@@ -175,18 +175,17 @@
                     _ColorData = new Color[this.PixelBytesCount];
                     _texture.GetData(_ColorData);
                     this.PixelBytes = new byte[this.PixelBytesCount];
-                    MemoryStream _ColorData_Stream = new MemoryStream(this.PixelBytesCount);
-                    BinaryWriter _ColorData_Stream_Writer = new BinaryWriter(_ColorData_Stream);
+                    ms = new MemoryStream(this.PixelBytesCount);
                     for (int i = 0; i < _ColorData.Length; i++)
                     {
-                        Microsoft.Xna.Framework.Graphics.Color _color = new Microsoft.Xna.Framework.Graphics.Color(_ColorData[i].ToVector3());
+                        Microsoft.Xna.Framework.Graphics.Color _color = new Microsoft.Xna.Framework.Graphics.Color(_ColorData[i].ToVector4());
                         // write value in format: RGB, because the source is BGR
                         Color _repack = new Color((float)_color.B / 255, (float)_color.G / 255, (float)_color.R / 255, (float)_color.A / 255);
-                        _ColorData_Stream_Writer.Write(_repack.PackedValue);
+                        w.Write(_repack.PackedValue);
                     }
-                    _ColorData_Stream_Writer.Flush();
-                    this.PixelBytes = _ColorData_Stream.ToArray();
-                    _ColorData_Stream_Writer.Close();
+                    w.Flush();
+                    this.PixelBytes = ms.ToArray();
+                    w.Close();
                     break;
                 default: 
                     throw new InvalidOperationException("Attempted to read pixel data for a non-supported pixel format.");

 

  ViewVC Help
Powered by ViewVC 1.1.22