public Extract ( string ExtractPath, bool ToMemory = false ) : byte[] | ||
ExtractPath | string | Path to extract image to. |
ToMemory | bool | OPTIONAL: If true, byte[] of image data returned. |
Résultat | byte[] |
private void PreviewObject(TPFTexInfo tex) { // KFreon: Clear old image ClearPreview(); // Clean cache if required if (Previews.Keys.Count > 10) { var img = Previews.First(); img.Value.Dispose(); Previews.Remove(img.Key); } // KFreon: Gather from cache if available if (Previews.ContainsKey(tex.PreviewKey)) { Bitmap img = Previews[tex.PreviewKey]; try { this.Invoke(new Action(() => PreviewBox.Image = img)); } catch (ObjectDisposedException) { } // DOn't care - it's when the form is closing. The form can become disposed while the preview is trying to be shown. DisappearTextBox(true); return; } // KFreon: Get data byte[] data = tex.Extract(null, true); if (data == null) return; // KFreon: Load new one if (tex.isDef) { DisappearTextBox(false); try { string message = Encoding.UTF8.GetString(data); this.Invoke(new Action(() => texmodPreviewBox.Text = message)); } catch (Exception e) { DebugOutput.PrintLn("Unable to get text from data: " + e.Message); } } else { Bitmap img = null; using (MemoryStream ms = new MemoryStream(data)) using (ImageEngineImage image = new ImageEngineImage(ms, null, 512, false)) img = image.GetGDIBitmap(true, false, 512); this.Invoke(new Action(() => PreviewBox.Image = img)); Previews.Add(tex.PreviewKey, img); DisappearTextBox(true); } }
private bool AutofixInternal(TPFTexInfo tex) { bool retval = false; TPFTexInfo backup = tex.Clone(); string path = tex.Autofixedpath(TemporaryPath); Directory.CreateDirectory(Path.GetDirectoryName(path)); byte[] imgData = tex.Extract(Path.GetDirectoryName(path), true); using (ImageEngineImage img = new ImageEngineImage(imgData)) { var destFormat = tex.ExpectedFormat; img.Resize(UsefulThings.General.RoundToNearestPowerOfTwo(img.Width), false); retval = img.Save(path, destFormat, tex.ExpectedMips > 1 ? MipHandling.Default : MipHandling.KeepTopOnly); } if (!retval) { tex.AutofixSuccess = false; return false; } tex.FilePath = Path.GetDirectoryName(tex.Autofixedpath(TemporaryPath)); tex.FileName = Path.GetFileName(path); // Heff: Cancellation check if (cts.IsCancellationRequested) return false; tex.EnumerateDetails(); // Heff: if fix was successfull, but the number of mips are still wrong, // force it and let texplorer skip the lowest resolutions // Heff: this should no longer happen, but keeping this as it might help in some real odd case. if (tex.ExpectedMips > 1 && (tex.NumMips < tex.ExpectedMips || tex.NumMips < TPFTexInfo.CalculateMipCount(tex.Width, tex.Height))) tex.NumMips = Math.Max(tex.ExpectedMips, TPFTexInfo.CalculateMipCount(tex.Width, tex.Height)); if (!tex.Valid) { tex = backup; tex.AutofixSuccess = false; } else tex.AutofixSuccess = true; return tex.AutofixSuccess; }
private void Extractor(string ExtractPath, TPFTexInfo tex, Predicate<TPFTexInfo> predicate) { // Heff: Cancellation check if (cts.IsCancellationRequested) return; // KFreon: Move to backbone if necessary if (!MainTreeView.InvokeRequired) { backbone.AddToBackBone(b => { Extractor(ExtractPath, tex, predicate); return true; }); return; } DebugOutput.PrintLn("Extracting textures to somewhere like: " + ExtractPath); OverallProg.ChangeProgressBar(0, 1); // KFreon: Extract single texture if (tex != null && tex.Files != null) { DebugOutput.PrintLn("Extracting single texture: " + tex.TexName); tex.Extract(ExtractPath); } else { // KFreon: Filter out duplicates so multiples of the same texture under different names don't get extracted List<TPFTexInfo> filteredDupsOut = new List<TPFTexInfo>(); for (int i = 0; i < LoadedTexes.Count; i++) { var filt = LoadedTexes[i]; if (filt.TreeDuplicates != null && filt.TreeDuplicates.Count > 0) { // KFreon: Any dup that refers to a previous index has already been added as that previous index. if (filt.TreeDuplicates.Any(ind => ind < i)) continue; } filteredDupsOut.Add(filt); } // KFreon: Extract many based on predicate List<TPFTexInfo> filtered = new List<TPFTexInfo>(filteredDupsOut.Where(texn => predicate(texn))); OverallProg.ChangeProgressBar(0, filtered.Count); foreach (TPFTexInfo texn in filtered) { texn.Extract(ExtractPath); OverallProg.IncrementBar(); } } OverallProg.ChangeProgressBar(1, 1); }
private void PreviewObject(TPFTexInfo tex) { // KFreon: Clear old image ClearPreview(); // KFreon: Get data byte[] data = tex.Extract(null, true); if (data == null) return; // KFreon: Load new one if (tex.isDef) { DisappearTextBox(false); try { string message = Encoding.UTF8.GetString(data); this.Invoke(new Action(() => texmodPreviewBox.Text = message)); } catch (Exception e) { DebugOutput.PrintLn("Unable to get text from data: " + e.Message); } } else { //KFreonLib.Textures.Methods.GetImage(tex.Format, data); Bitmap img = null; using (ResILImage kfimg = new ResILImage(data)) img = new Bitmap(new MemoryStream(kfimg.ToArray(ResIL.Unmanaged.ImageType.Jpg))); if (img == null) return; try { this.Invoke(new Action(() => PreviewBox.Image = KFreonLib.Textures.Creation.GenerateThumbImage(img, 512))); } catch { } DisappearTextBox(true); img.Dispose(); } }
private void Extractor(string ExtractPath, TPFTexInfo tex, Predicate<TPFTexInfo> predicate) { DebugOutput.PrintLn("Extracting textures to somewhere like: " + ExtractPath); OverallProg.ChangeProgressBar(0, 1); // KFreon: Extract single texture if (tex != null && tex.Files != null) { DebugOutput.PrintLn("Extracting single texture: " + tex.TexName); tex.Extract(ExtractPath); } else { // KFreon: Extract many based on predicate List<TPFTexInfo> filtered = new List<TPFTexInfo>(LoadedTexes.Where(texn => predicate(texn))); OverallProg.ChangeProgressBar(0, filtered.Count); foreach (TPFTexInfo texn in filtered) { var tpfName = texn.zippy._filename.Substring(ExtractPath.Length + 1, texn.zippy._filename.Length - ExtractPath.Length - 5); var dir = System.IO.Directory.CreateDirectory(ExtractPath + "\\" + tpfName); texn.Extract(dir.FullName); OverallProg.IncrementBar(); } } OverallProg.ChangeProgressBar(1, 1); }
private void Extractor(string ExtractPath, TPFTexInfo tex, Predicate<TPFTexInfo> predicate) { // Heff: Cancellation check if (cts.IsCancellationRequested) return; // KFreon: Move to backbone if necessary if (!MainTreeView.InvokeRequired) { backbone.AddToBackBone(b => { Extractor(ExtractPath, tex, predicate); return true; }); return; } DebugOutput.PrintLn("Extracting textures to somewhere like: " + ExtractPath); OverallProg.ChangeProgressBar(0, 1); // KFreon: Extract single texture if (tex != null && tex.Files != null) { DebugOutput.PrintLn("Extracting single texture: " + tex.TexName); tex.Extract(ExtractPath); } else { // KFreon: Extract many based on predicate List<TPFTexInfo> filtered = new List<TPFTexInfo>(LoadedTexes.Where(texn => predicate(texn))); OverallProg.ChangeProgressBar(0, filtered.Count); foreach (TPFTexInfo texn in filtered) { texn.Extract(ExtractPath); OverallProg.IncrementBar(); } } OverallProg.ChangeProgressBar(1, 1); }