protected override Document OnLoad(Stream input) { // reset settings cache on fresh loaded files pvrMetaDataCache = null; // Setup loading engine if (LoadEngineMode == PvrEngineEnum.None) { ShowLoadSetupDialogBox(); } if (LoadEngineMode == PvrEngineEnum.PuyoTools) { loadedPvrPuyo = new PvrTextureDecoder(input); var img = loadedPvrPuyo.GetImage(); var imgNative = ImageSharpExtensions.ToBitmap(img); return(Document.FromImage(imgNative)); } else if (LoadEngineMode == PvrEngineEnum.ShenmueDK) { PVRT.EnableBuffering = false; loadedPvr = new PVRT(input); return(Document.FromImage(loadedPvr.CreateBitmap())); } else { throw new Exception("User canceled the operation!"); } }
private void button_genPrev_Click(object sender, EventArgs e) { SixLabors.ImageSharp.Image <Bgra32> tmpImg = ImageSharpExtensions.ToImageSharpImage(_img); var pf = (PvrPixelFormat)comboBox_PixelFormat.SelectedItem; var df = (PvrDataFormat)comboBox_DataFormat.SelectedItem; var dr = comboBox_Dithering.SelectedIndex; var em = checkBox_eyeMode.Checked; using (var ms = new MemoryStream()) { // Temp encode to pvr PvrTextureEncoder tmpImgRaw = new PvrTextureEncoder(tmpImg, pf, df); tmpImgRaw.DitheringMode = dr; if (em == false) { tmpImgRaw.MetricMode = 0; } else { tmpImgRaw.MetricMode = 1; } tmpImgRaw.Save(ms); ms.Seek(0, SeekOrigin.Begin); //Tmp decode for preview var tmpPreview = new PvrTextureDecoder(ms); var img = tmpPreview.GetImage(); var imgNative = ImageSharpExtensions.ToBitmap(img); pictureBox_PVRPreview.Image = imgNative; pictureBox_PVRPreview.Update(); panel1.Update(); } }
protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { RenderArgs ra = new RenderArgs(new Surface(input.Size)); input.Render(ra, true); // Show dialog and setup engine parameters SaveDialogSettingsState pvrMetaData; if (pvrMetaDataCache != null) { pvrMetaData = ShowSetupDialogBox(pvrMetaDataCache, ra.Bitmap); //load from cache when there } else // no cache make clear instance of settings dialog { switch (LoadEngineMode) { case PvrEngineEnum.None: pvrMetaData = ShowSetupDialogBox(loadedPvrPuyo, ra.Bitmap); //null break; case PvrEngineEnum.ShenmueDK: pvrMetaData = ShowSetupDialogBox(loadedPvr, ra.Bitmap); break; case PvrEngineEnum.PuyoTools: pvrMetaData = ShowSetupDialogBox(loadedPvrPuyo, ra.Bitmap); break; default: pvrMetaData = ShowSetupDialogBox(loadedPvrPuyo, ra.Bitmap); //null break; } } using (var ms = new MemoryStream()) { Image <Bgra32> image = ImageSharpExtensions.ToImageSharpImage(ra.Bitmap); var tmpPvrPuyo = new PvrTextureEncoder(image, pvrMetaData.PuyoPixelFormat, (PvrDataFormat)pvrMetaData.PuyoDataFormat); // optiona global id if (pvrMetaData.GbixId != null) { tmpPvrPuyo.GlobalIndex = pvrMetaData.GbixId; } // dithering tmpPvrPuyo.DitheringMode = pvrMetaData.Dithering; // EyeWeightMode if (pvrMetaData.EyeWeightMode) { tmpPvrPuyo.MetricMode = 1; } else { tmpPvrPuyo.MetricMode = 0; } //GuardedStream workaround (forums.getpaint.net/topic/114912-i-can-not-save-my-work/)? tmpPvrPuyo.Save(ms); byte[] tmpBfr = ms.ToArray(); output.Write(tmpBfr, 0, tmpBfr.Length); pvrMetaDataCache = pvrMetaData; // update settings cache } }