/// <summary> /// Returns the Biggest MipMap in the first MipMap Block (null if no Texture was available) /// </summary> /// <param name="zs">The wanted Size for the Texture</param> public MipMap GetLargestTexture(Size zs) { MipMap large = null; foreach (MipMap mm in this.MipMaps) { if (mm.DataType != MipMapType.LifoReference) { Image img = mm.Texture; if (large != null) { if (large.Texture.Size.Width < img.Size.Width) { large = mm; } } else { large = mm; } if ((img.Size.Width > zs.Width) || (img.Size.Height > zs.Height)) { break; } } } return(large); }
/// <summary> /// Creats MipMaps based on the passed Data /// </summary> /// <param name="data">the MipMap Data</param> public void AddDDSData(DDSData[] data) { MipMaps = new MipMap[data.Length]; int ct = 0; for (int i = data.Length - 1; i >= 0; i--) { DDSData item = data[i]; MipMap mm = new MipMap(this.parent); mm.Texture = item.Texture; mm.Data = item.Data; MipMaps[ct++] = mm; } }
private void Select(object sender, System.Windows.Forms.TreeViewEventArgs e) { pb.Image = null; button1.Enabled = false; lbname.Text = ""; last = null; if (e == null) { return; } if (e.Node == null) { return; } if (e.Node.Tag == null) { return; } button1.Enabled = true; last = e.Node; SkinChain sc = new SkinChain((SimPe.PackedFiles.Wrapper.Cpf)e.Node.Tag); GenericRcol rcol = sc.TXTR; if (rcol != null) { ImageData id = (ImageData)rcol.Blocks[0]; MipMap mm = id.GetLargestTexture(pb.Size); if (mm != null) { pb.Image = ImageLoader.Preview(mm.Texture, pb.Size); } } lbname.Text = "Name: " + Helper.lbr + sc.Name + Helper.lbr + Helper.lbr; lbname.Text += "Category: " + Helper.lbr + sc.CategoryNames + Helper.lbr + Helper.lbr; lbname.Text += "Age: " + Helper.lbr + sc.AgeNames + Helper.lbr + Helper.lbr; lbname.Text += "Override: " + Helper.lbr + sc.Cpf.GetSaveItem("override0subset").StringValue + Helper.lbr + Helper.lbr; lbname.Text += "Group: " + Helper.lbr + Helper.HexString(sc.Cpf.FileDescriptor.Group) + Helper.lbr + Helper.lbr; }
/// <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> /// Return the Thumbnail for the mmat with the passed Index /// </summary> /// <param name="index"></param> /// <param name="mmats"></param> /// <param name="sz">Size of the Thumbnail</param> /// <returns>a valid Image</returns> protected Image GetItemThumb(int index, ArrayList mmats, Size sz) { if ((index < 0) || (index >= mmats.Count)) { return(new Bitmap(sz.Width, sz.Height)); } SimPe.Plugin.MmatWrapper mmat = (SimPe.Plugin.MmatWrapper)mmats[index]; GenericRcol txtr = mmat.TXTR; if (txtr != null) { ImageData id = (ImageData)txtr.Blocks[0]; MipMap mm = id.LargestTexture; if (mm != null) { return(ImageLoader.Preview(mm.Texture, sz)); } } return(new Bitmap(sz.Width, sz.Height)); }
/// <summary> /// Unserializes a BinaryStream into the Attributes of this Instance /// </summary> /// <param name="reader">The Stream that contains the FileData</param> public void Unserialize(System.IO.BinaryReader reader) { uint innercount; switch (parent.Version) { case 0x09: { innercount = reader.ReadUInt32(); break; } case 0x07: { innercount = parent.MipMapLevels; break; } default: { throw new Exception("Unknown MipMap version 0x" + Helper.HexString(parent.Version)); } } mipmaps = new MipMap[innercount]; for (int i = 0; i < mipmaps.Length; i++) { mipmaps[i] = new MipMap(parent); mipmaps[i].Unserialize(reader, i, mipmaps.Length); } creator = reader.ReadUInt32(); if ((parent.Version == 0x08) || (parent.Version == 0x09)) { unknown_1 = reader.ReadUInt32(); } }
/// <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); } }
private void SelectFile(object sender, System.EventArgs e) { llcommit.Enabled = false; lldelete.Enabled = false; btup.Enabled = false; btdown.Enabled = false; miAdd.Enabled = false; miRem.Enabled = lldelete.Enabled; if (lblist.SelectedIndex < 0) { return; } llcommit.Enabled = true; lldelete.Enabled = true; btup.Enabled = true; btdown.Enabled = true; miAdd.Enabled = true; miRem.Enabled = lldelete.Enabled; if (tbtype.Tag != null) { return; } try { tbtype.Tag = true; Interfaces.Files.IPackedFileDescriptor pfd = (Interfaces.Files.IPackedFileDescriptor)lblist.Items[lblist.SelectedIndex]; this.tbgroup.Text = "0x" + Helper.HexString(pfd.Group); this.tbinstance.Text = "0x" + Helper.HexString(pfd.Instance); this.tbsubtype.Text = "0x" + Helper.HexString(pfd.SubType); this.tbtype.Text = "0x" + Helper.HexString(pfd.Type); //get Texture if (pfd.GetType() == typeof(RefFileItem)) { RefFile wrp = (RefFile)wrapper; SkinChain sc = ((RefFileItem)pfd).Skin; SimPe.Plugin.GenericRcol txtr = null; if (sc != null) { txtr = sc.TXTR; } //show the Image if (txtr == null) { pb.Image = null; } else { MipMap mm = ((ImageData)txtr.Blocks[0]).GetLargestTexture(pb.Size); if (mm != null) { pb.Image = mm.Texture; } else { pb.Image = null; } } } else { pb.Image = null; } } catch (Exception ex) { Helper.ExceptionMessage(Localization.Manager.GetString("errconvert"), ex); } finally { tbtype.Tag = null; } }
public void ScanPackage(ScannerItem si, SimPe.Cache.PackageState ps, System.Windows.Forms.ListViewItem lvi) { System.Drawing.Size sz = AbstractScanner.ThumbnailSize; if (si.PackageCacheItem.Type == PackageType.Object || si.PackageCacheItem.Type == PackageType.MaxisObject || si.PackageCacheItem.Type == PackageType.Recolor) { SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.OBJD_FILE); uint group = 0; if (pfds.Length > 0) { group = pfds[0].Group; } if (group == Data.MetaData.LOCAL_GROUP) { SimPe.Interfaces.Wrapper.IGroupCacheItem gci = FileTable.GroupCache.GetItem(si.FileName); if (gci != null) { group = gci.LocalGroup; } } string[] modelnames = SimPe.Plugin.Scenegraph.FindModelNames(si.Package); foreach (string modelname in modelnames) { System.Drawing.Image img = SimPe.Plugin.Workshop.GetThumbnail(group, modelname); if (img != null) { si.PackageCacheItem.Thumbnail = img; ps.State = TriState.True; break; } } } //no Thumbnail, do we have a Image File? if (ps.State == TriState.Null) { SimPe.PackedFiles.Wrapper.Picture pic = new Picture(); uint[] types = pic.AssignableTypes; foreach (uint type in types) { SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(type); if (pfds.Length > 0) { //get image with smallest Instance SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0]; foreach (SimPe.Interfaces.Files.IPackedFileDescriptor p in pfds) { if (p.Instance < pfd.Instance) { pfd = p; } } pic.ProcessData(pfd, si.Package, false); si.PackageCacheItem.Thumbnail = pic.Image; if (si.PackageCacheItem.Thumbnail != null) { si.PackageCacheItem.Thumbnail = ImageLoader.Preview(si.PackageCacheItem.Thumbnail, sz); ps.State = TriState.True; } break; } } //foreach } //no Thumbnail generated by the Game? if (ps.State == TriState.Null) { //load the Texture Image SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.TXTR); if (pfds.Length > 0) { SimPe.Plugin.GenericRcol rcol = new GenericRcol(null, false); //get biggest texture SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0]; foreach (SimPe.Interfaces.Files.IPackedFileDescriptor p in pfds) { if (p.Size > pfd.Size) { pfd = p; } } rcol.ProcessData(pfd, si.Package, false); SimPe.Plugin.ImageData id = (SimPe.Plugin.ImageData)rcol.Blocks[0]; SimPe.Plugin.MipMap mm = id.GetLargestTexture(sz); if (mm.Texture != null) { si.PackageCacheItem.Thumbnail = ImageLoader.Preview(mm.Texture, sz); ps.State = TriState.True; } rcol.Dispose(); } } if (si.PackageCacheItem.Thumbnail != null) { if (WaitingScreen.Running) { WaitingScreen.UpdateImage(si.PackageCacheItem.Thumbnail); } } UpdateState(si, ps, lvi); }