/// <summary> /// Constructor /// </summary> public ImageData(Rcol parent) : base(parent) { texturesize = new Size(1, 1); mipmapblocks = new MipMapBlock[1]; mipmapblocks[0] = new MipMapBlock(this); mipmaplevels = 1; sgres = new SGResource(null); BlockID = 0x1c4a276c; filenamerep = ""; this.version = 0x09; unknown_0 = (float)1.0; format = SimPe.Plugin.ImageLoader.TxtrFormats.ExtRaw24Bit; }
/// <summary> /// Unserializes a BinaryStream into the Attributes of this Instance /// </summary> /// <param name="reader">The Stream that contains the FileData</param> public override void Unserialize(System.IO.BinaryReader reader) { version = reader.ReadUInt32(); /*byte len = reader.ReadByte(); * string s = Helper.ToString(reader.ReadBytes(len));*/ string s = reader.ReadString(); sgres.BlockID = reader.ReadUInt32(); sgres.Unserialize(reader); if (Parent.Fast) { texturesize = new Size(0, 0); mipmapblocks = new MipMapBlock[0]; return; } int w = reader.ReadInt32(); int h = reader.ReadInt32(); texturesize = new Size(w, h); format = (ImageLoader.TxtrFormats)reader.ReadUInt32(); mipmaplevels = reader.ReadUInt32(); unknown_0 = reader.ReadSingle(); mipmapblocks = new MipMapBlock[reader.ReadUInt32()]; unknown_1 = reader.ReadUInt32(); if (version == 0x09) { filenamerep = reader.ReadString(); } for (int i = 0; i < mipmapblocks.Length; i++) { mipmapblocks[i] = new MipMapBlock(this); mipmapblocks[i].Unserialize(reader); } }
/// <summary> /// Assemble a Picture File /// </summary> /// <param name="data"></param> public static void LoadDDS(ImageData id, DDSData[] data) { if (data == null) { return; } if (data.Length > 0) { try { id.TextureSize = data[0].ParentSize; id.Format = data[0].Format; id.MipMapLevels = (uint)data.Length; MipMap[] maps = new MipMap[data.Length]; int ct = 0; for (int i = data.Length - 1; i >= 0; i--) { DDSData item = data[i]; MipMap mm = new MipMap(id); mm.Texture = item.Texture; mm.Data = item.Data; maps[ct++] = mm; } MipMapBlock[] mmps = new MipMapBlock[1]; mmps[0] = new MipMapBlock(id); mmps[0].MipMaps = maps; id.MipMapBlocks = mmps; } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } } }
/// <summary> /// Assemble a Picture File /// </summary> /// <param name="data"></param> public static void LoadTXTR(ImageData id, System.Drawing.Image src, System.Drawing.Size sz, int levels, SimPe.Plugin.ImageLoader.TxtrFormats format) { try { id.TextureSize = sz; id.Format = format; id.MipMapLevels = (uint)levels; System.Drawing.Image img = new Bitmap(sz.Width, sz.Height); Graphics gr = Graphics.FromImage(img); gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gr.DrawImage(src, new Rectangle(new Point(0, 0), img.Size), new Rectangle(new Point(0, 0), src.Size), GraphicsUnit.Pixel); MipMap[] maps = new MipMap[levels]; int wd = 1; int hg = 1; //build default Sizes for (int i = 0; i < levels; i++) { MipMap mm = new MipMap(id); mm.Texture = new Bitmap(wd, hg); if ((wd == hg) && (wd == 1)) { if (id.TextureSize.Width > id.TextureSize.Height) { wd = id.TextureSize.Width / id.TextureSize.Height; hg = 1; } else { hg = id.TextureSize.Height / id.TextureSize.Width; wd = 1; } if ((wd == hg) && (wd == 1)) { wd *= 2; hg *= 2; } } else { wd *= 2; hg *= 2; } maps[i] = mm; } //create a Scaled Version for each testure for (int i = 0; i < maps.Length; i++) { MipMap mm = maps[i]; if (img != null) { Image bm = mm.Texture; gr = Graphics.FromImage(bm); gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gr.DrawImage(img, new Rectangle(new Point(0, 0), bm.Size), new Rectangle(new Point(0, 0), img.Size), GraphicsUnit.Pixel); id.TextureSize = new Size(bm.Width, bm.Height); } } // for i MipMapBlock[] mmps = new MipMapBlock[1]; mmps[0] = new MipMapBlock(id); mmps[0].MipMaps = maps; id.MipMapBlocks = mmps; } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } }