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

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

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

--- trunk/gr2lib_typedefs/typedefs/CustomTextureCreator.cs	2010/08/05 13:15:23	34
+++ trunk/gr2lib_typedefs/typedefs/TextureCreator/s3tc_texture_creator.cs	2010/08/05 19:00:37	36
@@ -1,255 +1,54 @@
-´╗┐using System;
+´╗┐#define IS_NOT_BINDABLE // when defined, will always return false for An IBindableTexture
+using System;
 using System.Collections.Generic;
 using System.Text;
-using gr2lib_typedefs.interfaces;
-using gr2lib.core.ui.helpers;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
+using gr2lib_typedefs.typedefs.TextureCreator.interfaces;
 using System.IO;
-using gr2lib.core.typedefs;
-using gr2lib.core;
-using System.Drawing.Imaging;
-using Microsoft.Xna.Framework.Graphics;
-using System.Windows.Forms;
-using Microsoft.Xna.Framework.Graphics.PackedVector;
 
-namespace gr2lib_typedefs.typedefs
+namespace gr2lib_typedefs.typedefs.TextureCreator
 {
-    public class CustomTextureCreator : UserControl, ICustomTextureCreator
+    public class s3tc_texture_creator : BaseTextureCreator, IBindableTexture
     {
+        protected override string TextureCreatorName { get { return "s3tc Texture Creator"; } }
         #region Constructors
-        public CustomTextureCreator()
-        {
-            this.init();
-        }
-        public CustomTextureCreator(string filename)
+        public s3tc_texture_creator() : base() { this.init(); }
+        public s3tc_texture_creator(string filename) : base(filename) { this.init(); }
+        public s3tc_texture_creator(byte[] data) : base(data) { this.init(); }
+        public s3tc_texture_creator(MemoryStream ms) : base(ms) { this.init(); }
+        private void init()
         {
-            this.init();
-            this.Name = new FilePath(filename);
-
-            this.GetImageType();
-            this.GetImageData();
+            this.IsAnIBindableTexture = false;
         }
         #endregion
 
-        #region Constructor Initializer
-        private void init()
+        #region IBindableTexture Members
+        public bool CheckForBindableTexture(string filename)
         {
-            this.Name = new FilePath();
-            this.Width = 0;
-            this.Height = 0;
-            this.BytesPerPixel = 0;
-            this.MipMapCount = 1;
-            this.RawPixelFormat = System.Drawing.Imaging.PixelFormat.Undefined;
-            this.TexturePixelFormat = new object();
-            this.ImageType = TextureCreator_ImageType.Undefined;
-            //this.SubImageType = TextureCreator_SubImageType.Undefined;
-            this.PixelBytesCount = 0;
-            this.PixelBytes = new byte[this.PixelBytesCount];
-
-            //this.IsST3C = false;
-
-            // initialize private members
-            //this._ddsFile = new DdsFileTypePlugin.DdsFile();
-            this._image = null;
-
-            // Create Presentation Parameters
-            PresentationParameters pp = new PresentationParameters();
-            pp.BackBufferCount = 1;
-            pp.IsFullScreen = false;
-            pp.SwapEffect = SwapEffect.Discard;
-            pp.BackBufferWidth = this.Width;
-            pp.BackBufferHeight = this.Height;
-            pp.AutoDepthStencilFormat = DepthFormat.Depth24Stencil8;
-            pp.EnableAutoDepthStencil = true;
-            pp.PresentationInterval = PresentInterval.Default;
-            pp.BackBufferFormat = SurfaceFormat.Unknown;
-            pp.MultiSampleType = MultiSampleType.None;
-            // Create Graphics device
-            this.mGraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, this.Handle, pp);
-            
+            if (!this.IsAnIBindableTexture) return false;
+#if IS_NOT_BINDABLE
+            return false;
+#else
+            // check if this texture can be bound to this texture creator
+#endif
         }
-        #endregion
-
-        #region Private Members
-        //private DdsFileTypePlugin.DdsFile _ddsFile;
-        GraphicsDevice mGraphicsDevice;
-        private Texture2D _texture;
-        private System.Drawing.Image _image;
-        #endregion
-
-        #region Texture Initialization Methods
-        #region  private void GetImageType()
-        private void GetImageType()
+        public bool CheckForBindableTexture(byte[] data)
         {
-            try
-            {
-                this._texture = Texture2D.FromFile(mGraphicsDevice, this.Name.FullPath);
-
-                this.Width = this._texture.Width;
-                this.Height = this._texture.Height;
-
-                this.RawPixelFormat = this._texture.Format;
-                this.TexturePixelFormat = new object();
-                switch (this._texture.Format)
-                {
-                    case SurfaceFormat.Color:
-                        Color[] _color_bytes = new Color[this._texture.Width * this._texture.Height];
-                        this.mGraphicsDevice.SetRenderTarget(0, null);
-                        this._texture.GetData<Color>(_color_bytes);
-
-                        this.PixelBytes = new byte[this._texture.Width * this._texture.Height * 4];
-                        this.BytesPerPixel = 4;
-                        for (int i = 0; i < _color_bytes.Length; i++)
-                        {
-                            this.PixelBytes[i + 0] = _color_bytes[i].R;
-                            this.PixelBytes[i + 1] = _color_bytes[i].G;
-                            this.PixelBytes[i + 2] = _color_bytes[i].B;
-                            this.PixelBytes[i + 3] = _color_bytes[i].A;
-                            i += 4;
-                        }
-                        break;
-                    case SurfaceFormat.Bgr565:
-                        this.TexturePixelFormat = granny_s3tc_texture_format.GrannyS3TCBGR565;
-                        Bgr565[] _bgr565_bytes = new Bgr565[this._texture.Width * this._texture.Height];
-                        this.mGraphicsDevice.SetRenderTarget(0, null);
-                        this._texture.GetData<Bgr565>(_bgr565_bytes);
-
-                        this.PixelBytes = new byte[this._texture.Width * this._texture.Height * 2];
-                        this.BytesPerPixel = 2;
-                        for (int i = 0; i < _bgr565_bytes.Length; i++)
-                        {
-                            byte[] data = new byte[this.BytesPerPixel];
-                            data = BitConverter.GetBytes(_bgr565_bytes[i].PackedValue);
-                            this.PixelBytes[i + 0] = data[1];
-                            this.PixelBytes[i + 1] = data[0];    
-                            i += 2;
-                        }                        
-                        break;
-                    case SurfaceFormat.Bgra5551:
-                        this.TexturePixelFormat = granny_s3tc_texture_format.GrannyS3TCBGRA5551;
-                        Bgra5551[] _bgra5551_bytes = new Bgra5551[this._texture.Width * this._texture.Height];
-                        this.mGraphicsDevice.SetRenderTarget(0, null);
-                        this._texture.GetData<Bgra5551>(_bgra5551_bytes);
-
-                        this.PixelBytes = new byte[this._texture.Width * this._texture.Height * 4];
-                        this.BytesPerPixel = 4;
-                        for (int i = 0; i < _bgra5551_bytes.Length; i++)
-                        {
-                            this.PixelBytes[i + 0] = (byte)_bgra5551_bytes[i].ToVector4().X;
-                            this.PixelBytes[i + 1] = (byte)_bgra5551_bytes[i].ToVector4().Y;
-                            this.PixelBytes[i + 2] = (byte)_bgra5551_bytes[i].ToVector4().Z;
-                            this.PixelBytes[i + 3] = (byte)_bgra5551_bytes[i].ToVector4().W;
-                        }
-                        break;
-                        break;
-                }
-
-            }
-            catch
-            {
-                //this.ImageType = TextureCreator_ImageType.Undefined;
-            }
+            if (!this.IsAnIBindableTexture) return false;
+#if IS_NOT_BINDABLE
+            return false;
+#else
+            // check if this texture can be bound to this texture creator
+#endif
         }
-        #endregion
-
-        #region private void GetImageData()
-        private void GetImageData()
+        public bool CheckForBindableTexture(MemoryStream ms)
         {
-            //this.Width = _image.Width;
-            //this.Height = _image.Height;
-            //this.BytesPerPixel = System.Drawing.Image.GetPixelFormatSize(_image.PixelFormat) / 8;
-            //this.MipMapCount = 1;
-
-            //this.RawPixelFormat = _image.PixelFormat;
-            //this.TexturePixelFormat = new object();
-
-            //this.PixelBytes = new byte[this.Width * this.Height * this.BytesPerPixel];
-            //try { using (MemoryStream ms = new MemoryStream(this.Width * this.Height * this.BytesPerPixel)) { _image.Save(ms, ImageFormat.Png); this.PixelBytes = ms.ToArray(); } }
-            //catch (Exception) { throw; }
-
-            //// get Texure Pixel Format;
-            //if ((PixelFormat)this.RawPixelFormat == PixelFormat.Format16bppRgb555)
-            //{
-            //    this.TexturePixelFormat = granny_pixel_layout.GrannyRGB555PixelFormat;
-            //}
-            //else if ((PixelFormat)this.RawPixelFormat == PixelFormat.Format16bppRgb565)
-            //{
-            //    this.TexturePixelFormat = granny_pixel_layout.GrannyRGB565PixelFormat;
-            //}
-            //else if ((PixelFormat)this.RawPixelFormat == PixelFormat.Format16bppArgb1555)
-            //{
-            //    this.TexturePixelFormat = granny_pixel_layout.GrannyRGBA5551PixelFormat;
-            //}
-
-            ////GrannyRGBA4444PixelFormat
-            ////else if ((PixelFormat)this.RawPixelFormat == PixelFormat.Format16bppArgb1555)
-            ////{
-            ////    this.TexturePixelFormat = granny_pixel_layout.GrannyRGBA5551PixelFormat;
-            ////}
-
-            //else if ((PixelFormat)this.RawPixelFormat == PixelFormat.Format24bppRgb)
-            //{
-            //    this.TexturePixelFormat = granny_pixel_layout.GrannyRGB888PixelFormat;
-            //}
-            //else if ((PixelFormat)this.RawPixelFormat == PixelFormat.Format32bppArgb)
-            //{
-            //    this.TexturePixelFormat = granny_pixel_layout.GrannyRGBA8888PixelFormat;
-            //}
-            //else
-            //{
-            //    this.TexturePixelFormat = new object();
-            //}
-
+            if (!this.IsAnIBindableTexture) return false;
+#if IS_NOT_BINDABLE
+            return false;
+#else
+            // check if this texture can be bound to this texture creator
+#endif
         }
         #endregion
-        #endregion
-        #region ICustomTextureCreator Members
-
-        #region ICustomTextureCreatorTextureData Members
-        private FilePath _Name;
-        public FilePath Name { get { return _Name; } private set { _Name = value; } }
-        private int _Width;
-        public int Width { get { return _Width; } private set { _Width = value; } }
-        private int _Height;
-        public int Height { get { return _Height; } private set { _Height = value; } }
-        private int _BytesPerPixel;
-        public int BytesPerPixel { get { return _BytesPerPixel; } private set { _BytesPerPixel = value; } }
-
-        public int Stride { get { return this.Width * this.BytesPerPixel; } }
-
-        private int _MipMapCount;
-        public int MipMapCount { get { return _MipMapCount; } private set { _MipMapCount = value; } }
-
-        private object _RawPixelFormat;
-        public object RawPixelFormat { get { return _RawPixelFormat; } private set { _RawPixelFormat = value; } }
-        private object _TexturePixelFormat;
-        public object TexturePixelFormat { get { return _TexturePixelFormat; } private set { _TexturePixelFormat = value; } }
-
-        private TextureCreator_ImageType _ImageType;
-        public TextureCreator_ImageType ImageType { get { return _ImageType; } private set { _ImageType = value; } }
-
-        //private TextureCreator_SubImageType _SubImageType;
-        //public TextureCreator_SubImageType SubImageType { get { return _SubImageType; } private set { _SubImageType = value; } }
-        #endregion
-
-        #region ICustomTextureCreatorPixelData Members
-        private int _PixelBytesCount;
-        public int PixelBytesCount { get { return _PixelBytesCount; } private set { _PixelBytesCount = value; } }
-        public IntPtr PixelBytesPointer { get { unsafe { fixed (byte* p = this.PixelBytes) { return (IntPtr)p; } } } }
-        private byte[] _PixelBytes;
-        public byte[] PixelBytes { get { return _PixelBytes; } private set { _PixelBytes = value; } }
-        #endregion
-
-        #endregion
-
-        //#region ICustomTextureCreatorTextureType Members
-        //private bool _IsST3C;
-        //public bool IsST3C { get { return _IsST3C; } private set { _IsST3C = value; } }
-        //#endregion
-
-        //#region Private Sub-Classes
-        //#endregion
-
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22