public static ImageTexture FromMRC(string path) { ImageTexture NewTexture = new ImageTexture(); HeaderMRC Header = HeaderMRC.ReadFromFile(path) as HeaderMRC; NewTexture.Size = Header.Dimensions; NewTexture.Scale = new Vector2(Header.Pixelsize.X, Header.Pixelsize.Y); NewTexture.Offset = new Vector2(Header.Origin.X, Header.Origin.Y); float[] Data = IOHelper.ReadSmallMapFloat(path, new int2(1, 1), 0, typeof(float)); float DataMin = float.MaxValue, DataMax = -float.MaxValue; for (int i = 0; i < Data.Length; i++) { DataMin = Math.Min(DataMin, Data[i]); DataMax = Math.Max(DataMax, Data[i]); } float Range = 255f / (DataMax - DataMin); byte[] DataByte = new byte[Data.Length]; for (int i = 0; i < Data.Length; i++) { DataByte[i] = (byte)((Data[i] - DataMin) * Range); } NewTexture.Data = DataByte; return(NewTexture); }
public static VolumeTexture FromMRC(string path) { VolumeTexture NewTexture = new VolumeTexture(); HeaderMRC Header = HeaderMRC.ReadFromFile(path) as HeaderMRC; NewTexture.Size = Header.Dimensions; NewTexture.Scale = new Vector3(Header.Pixelsize.X, Header.Pixelsize.Y, Header.Pixelsize.Z); NewTexture.Offset = new Vector3(Header.Origin.X, Header.Origin.Y, Header.Origin.Z); unsafe { float[] OriginalData = IOHelper.ReadSmallMapFloat(path, new int2(1, 1), 0, typeof(float)); float DataMin = float.MaxValue, DataMax = float.MinValue; fixed(float *DataPtr = OriginalData) { float *DataP = DataPtr; for (int i = 0; i < OriginalData.Length; i++) { DataMin = Math.Min(DataMin, *DataP); DataMax = Math.Max(DataMax, *DataP++); } float Range = (DataMax - DataMin) / 255f; byte[] DataByte = new byte[OriginalData.Length]; fixed(byte *DataBytePtr = DataByte) { byte *DataByteP = DataBytePtr; DataP = DataPtr; for (int i = 0; i < OriginalData.Length; i++) { *DataByteP++ = (byte)((*DataP++ - DataMin) / Range); } } NewTexture.Data = DataByte; } NewTexture.OriginalData = OriginalData; } return(NewTexture); }