protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance) { Texture2D texture = null; SurfaceFormat surfaceFormat = (SurfaceFormat)reader.ReadInt32(); int width = (reader.ReadInt32()); int height = (reader.ReadInt32()); int levelCount = (reader.ReadInt32()); SetDataOptions compressionType = (SetDataOptions)reader.ReadInt32(); int imageLength = width * height * 4; if (surfaceFormat == SurfaceFormat.Dxt3) { ESTexture2D temp = ESTexture2D.InitiFromDxt3File(reader, imageLength, width, height); texture = new Texture2D(new ESImage(temp)); } else { byte[] imageBytes = reader.ReadBytes(imageLength); IntPtr ptr = Marshal.AllocHGlobal(imageLength); try { Marshal.Copy(imageBytes, 0, ptr, imageLength); ESTexture2D temp = new ESTexture2D(ptr, SurfaceFormat.Rgba32, width, height, new Size(width, height), All.Linear); texture = new Texture2D(new ESImage(temp)); } finally { Marshal.FreeHGlobal(ptr); } } return(texture); }
protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance) { Texture2D texture = null; SurfaceFormat surfaceFormat = (SurfaceFormat)reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); int levelCount = reader.ReadInt32(); int imageLength = reader.ReadInt32(); byte[] imageData = reader.ReadBytes(imageLength); switch (surfaceFormat) { case SurfaceFormat.Dxt1: imageData = DxtUtil.DecompressDxt1(imageData, width, height); break; case SurfaceFormat.Dxt3: imageData = DxtUtil.DecompressDxt3(imageData, width, height); break; } IntPtr imagePtr = IntPtr.Zero; // Changed to load the raw data // currentony only ARGB8888 is supported ESTexture2D esTexture = new ESTexture2D(imageData, surfaceFormat, width, height, new Size(width, height), All.Linear); texture = new Texture2D(reader.GraphicsDevice, new ESImage(esTexture)); return(texture); }
protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance) { Texture2D texture = null; SurfaceFormat surfaceFormat = (SurfaceFormat)reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); int levelCount = reader.ReadInt32(); int imageLength = reader.ReadInt32(); byte[] imageData = reader.ReadBytes(imageLength); switch (surfaceFormat) { case SurfaceFormat.Dxt1: imageData = DxtUtil.DecompressDxt1(imageData, width, height); break; case SurfaceFormat.Dxt3: imageData = DxtUtil.DecompressDxt3(imageData, width, height); break; } IntPtr imagePtr = IntPtr.Zero; try { imagePtr = Marshal.AllocHGlobal(imageData.Length); Marshal.Copy(imageData, 0, imagePtr, imageData.Length); ESTexture2D esTexture = new ESTexture2D(imagePtr, surfaceFormat, width, height, new Size(width, height), All.Linear); texture = new Texture2D(new ESImage(esTexture)); } finally { Marshal.FreeHGlobal(imagePtr); } return(texture); }
protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance) { Texture2D texture = null; SurfaceFormat surfaceFormat = (SurfaceFormat)reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); /*int levelCount =*/ reader.ReadInt32(); int imageLength = reader.ReadInt32(); byte[] imageData = reader.ReadBytes(imageLength); #if NO_DXT35 System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch(); sw2.Reset(); sw2.Start(); // GG TODO need to remove this manual decompression KTHX switch (surfaceFormat) { case SurfaceFormat.Dxt1: imageData = DxtUtil.DecompressDxt1(imageData, width, height); surfaceFormat = SurfaceFormat.Rgba32; break; case SurfaceFormat.Dxt3: imageData = DxtUtil.DecompressDxt3(imageData, width, height); surfaceFormat = SurfaceFormat.Rgba32; break; } if (sw2.ElapsedMilliseconds > 16) { GSGE.Debug.logMessage("Surface Format decompression took " + sw2.ElapsedMilliseconds); } #endif unsafe { fixed(byte *pData = imageData) { ESTexture2D esTexture = new ESTexture2D((IntPtr)pData, imageData.Length, surfaceFormat, width, height, new Size(width, height), All.Linear); texture = new Texture2D(new ESImage(esTexture)); } } return(texture); }