Exemplo n.º 1
0
        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!");
            }
        }
Exemplo n.º 2
0
        public SaveDialogSettingsState ShowSetupDialogBox(PvrTextureDecoder puyoPvr, Bitmap preview)
        {
            SaveDialogSettings setupDlg;

            if (puyoPvr != null)
            {
                setupDlg = new SaveDialogSettings((PvrDataFormatEncodeOnly)puyoPvr.DataFormat, puyoPvr.PixelFormat, true, puyoPvr.GlobalIndex);
            }
            else
            {
                setupDlg = new SaveDialogSettings(PvrDataFormatEncodeOnly.Vq, PvrPixelFormat.Argb1555, false, null); //default when no file
            }
            setupDlg._img = preview;
            setupDlg.ShowDialog();
            setupDlg.Dispose();

            SaveDialogSettingsState info = setupDlg._state;

            return(info);
        }
        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();
            }
        }
        private void LoadExtraPVRStuff(bool md)
        {
            //HACK: because PDN plugin is capsulated and OpenFileDialog creates a new thread and other memes, it will crash
            // So we go full madlad and make our own openfiledialog from Comdlg32.dll
            // i bet this works 100% fine on all those .NET platforms out there that are not windows believe :^)
            OpenFileName gbixDialog = new OpenFileName();

            gbixDialog.structSize = Marshal.SizeOf(gbixDialog);
            gbixDialog.file       = new String(new char[256]);
            gbixDialog.maxFile    = gbixDialog.file.Length;
            gbixDialog.filter     = "PVR file\0*.PVR";
            gbixDialog.defExt     = "PVR";
            gbixDialog.title      = "Load GBIX from PVR file";
            //TODO: this does not work because handle is generated at init but the function waits for return
            // internet says to create a dummy handle and then assign  it to  the ofn but whatever good enough
            //SetWindowPos(gbixDialog.instance, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);

            this.Enabled = false; // disable plugin dialog
            if (GetOpenFileName(gbixDialog) == true)
            {
                try
                {
                    PvrTextureDecoder puyoPvr;
                    using (FileStream fs = File.Open(gbixDialog.file, FileMode.Open))
                    {
                        puyoPvr = new PvrTextureDecoder(fs);
                    }

                    uint?gbixCase = puyoPvr.GlobalIndex;

                    try
                    {
                        if (md)
                        {
                            comboBox_DataFormat.SelectedItem  = (PvrDataFormatEncodeOnly)puyoPvr.DataFormat;
                            comboBox_PixelFormat.SelectedItem = (PvrPixelFormat)puyoPvr.PixelFormat;
                        }

                        //try to update gbix case
                        if (gbixCase != null)
                        {
                            numericUpDown_GBIX.Value = (decimal)gbixCase;
                            checkBox_GBIX.Checked    = true;
                        }
                        else
                        {
                            // reset when file had no gbix
                            numericUpDown_GBIX.Value = 0;
                            checkBox_GBIX.Checked    = false;
                        }
                    }
                    catch (Exception f)
                    {
                        MessageBox.Show("ShenmueDK could not parse the GBIX ID. Abort."
                                        + Environment.NewLine + f);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }

            this.Enabled = true;  // enable plugin dialog
        }