コード例 #1
0
 public static Type GetImageFileTypeFromSignature(byte[] buffer)
 {
     if (TEXN.IsValid(buffer))
     {
         return(typeof(TEXN));
     }
     if (PVRT.IsValid(buffer))
     {
         return(typeof(PVRT));
     }
     if (DDS.IsValid(buffer))
     {
         return(typeof(DDS));
     }
     if (BMP.IsValid(buffer))
     {
         return(typeof(BMP));
     }
     if (JPEG.IsValid(buffer))
     {
         return(typeof(JPEG));
     }
     if (PNG.IsValid(buffer))
     {
         return(typeof(PNG));
     }
     return(null);
 }
コード例 #2
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!");
            }
        }
コード例 #3
0
ファイル: TEXN.cs プロジェクト: psyouloveme/ShenmueDKSharp
        protected override void _Read(BinaryReader reader)
        {
            Offset = (uint)reader.BaseStream.Position;

            Identifier = reader.ReadUInt32();
            EntrySize  = reader.ReadUInt32();

            TextureID        = new TextureID(reader);
            FileName         = String.Format("{0}.{1}.TEXN", Helper.ByteArrayToString(BitConverter.GetBytes(TextureID.Data)), TextureID.Name.Replace("\0", "_"));
            Texture          = new PVRT(reader);
            Texture.FileName = String.Format("{0}.{1}.PVR", Helper.ByteArrayToString(BitConverter.GetBytes(TextureID.Data)), TextureID.Name.Replace("\0", "_"));

            reader.BaseStream.Seek(Offset + EntrySize, SeekOrigin.Begin);
        }
コード例 #4
0
        public SaveDialogSettingsState ShowSetupDialogBox(PVRT shendkPvr, Bitmap preview)
        {
            SaveDialogSettings setupDlg;

            uint?gbixCase = null;

            try
            {
                // Who was so smart to report a empty gbix over HasGlobalIndex in ShenmueDK as true
                // when there is none in file...  oh right that was me
                // TODO: fix it in ShenmueDKSharp...
                if (shendkPvr.GlobalIndex[0] != 0x00 || shendkPvr.GlobalIndex[1] != 0x00 ||
                    shendkPvr.GlobalIndex[2] != 0x00 || shendkPvr.GlobalIndex[3] != 0x00)
                {
                    gbixCase = BitConverter.ToUInt32(new byte[] {
                        shendkPvr.GlobalIndex[0], shendkPvr.GlobalIndex[1], shendkPvr.GlobalIndex[2], shendkPvr.GlobalIndex[3],
                    }, 0);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("ShenmueDK could not parse the GBIX ID. Please enter your own or use PuyoTools Load engine."
                                + Environment.NewLine + e);
            }

            if (shendkPvr != null)
            {
                setupDlg = new SaveDialogSettings(shendkPvr.DataFormat, shendkPvr.PixelFormat, true, gbixCase);
            }
            else
            {
                setupDlg = new SaveDialogSettings(
                    ShenmueDKSharp.Files.Images._PVRT.PvrDataFormat.VECTOR_QUANTIZATION,
                    ShenmueDKSharp.Files.Images._PVRT.PvrPixelFormat.ARGB1555, false, null); //default when no file
            }
            setupDlg._img = preview;
            setupDlg.ShowDialog();
            setupDlg.Dispose();

            SaveDialogSettingsState info = setupDlg._state;

            return(info);
        }
コード例 #5
0
        private void button_Convert_Click(object sender, EventArgs e)
        {
            string outputFolder = textBox_OutputFolder.Text;

            if (String.IsNullOrEmpty(outputFolder))
            {
                return;
            }
            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            List <BaseImage> images = new List <BaseImage>();

            if (checkBox_ConvertSelected.Checked)
            {
                foreach (BaseImage img in listBox_Images.SelectedItems)
                {
                    images.Add(img);
                }
            }
            else
            {
                foreach (BaseImage img in listBox_Images.Items)
                {
                    images.Add(img);
                }
            }

            if ((Type)comboBox_ImageFormat.SelectedItem == typeof(PVRT))
            {
                PVRTSettings settings = pvrtControl.Settings;
                foreach (BaseImage image in images)
                {
                    PVRT pvrt = new PVRT(image);
                    pvrt.PixelFormat = settings.PixelFormat;
                    pvrt.DataFormat  = settings.DataFormat;

                    if (settings.CreateTEXN)
                    {
                        string   srcFilename = Path.GetFileName(image.FilePath);
                        string[] splitted    = srcFilename.Split('.');
                        string   texIDString = splitted[0];
                        UInt64   texID       = Convert.ToUInt64(texIDString, 16);

                        TEXN texn = new TEXN();
                        texn.TextureID.Data = texID;

                        string filename = String.Format("{0}.{1}.TEXN", Helper.ByteArrayToString(BitConverter.GetBytes(texn.TextureID.Data)), texn.TextureID.Name.Replace("\0", "_"));
                        string filepath = outputFolder + "\\" + filename;

                        using (FileStream fileStream = new FileStream(filepath, FileMode.Create))
                        {
                            using (BinaryWriter writer = new BinaryWriter(fileStream))
                            {
                                long offset = fileStream.Position;
                                texn.WriteHeader(writer);
                                if (settings.InsertDDS && typeof(DDS).IsAssignableFrom(image.GetType()))
                                {
                                    pvrt.WriteDDSRaw(writer, (DDS)image);
                                }
                                else
                                {
                                    pvrt.Write(writer);
                                }
                                texn.EntrySize = (uint)(fileStream.Position - offset);
                                fileStream.Seek(offset, SeekOrigin.Begin);
                                texn.WriteHeader(writer);
                            }
                        }
                    }
                    else
                    {
                        string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".PVR");

                        using (FileStream fileStream = new FileStream(filepath, FileMode.Create))
                        {
                            using (BinaryWriter writer = new BinaryWriter(fileStream))
                            {
                                if (settings.InsertDDS && typeof(DDS).IsAssignableFrom(image.GetType()))
                                {
                                    pvrt.WriteDDSRaw(writer, (DDS)image);
                                }
                                else
                                {
                                    pvrt.Write(writer);
                                }
                            }
                        }
                    }
                }
            }
            else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(DDS))
            {
                DDSSettings settings = ddsControl.Settings;
                foreach (BaseImage image in images)
                {
                    string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".dds");
                    DDS    dds      = new DDS(image);
                    dds.AlphaSettings = settings.AlphaSettings;
                    dds.MipHandling   = settings.MipHandling;
                    dds.FormatDetails = new DDSFormats.DDSFormatDetails(settings.DDSFormat, settings.DXGIFormat);
                    dds.Write(filepath);
                }
            }
            else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(PNG))
            {
                foreach (BaseImage image in images)
                {
                    string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".png");
                    PNG    png      = new PNG(image);
                    png.Write(filepath);
                }
            }
            else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(BMP))
            {
                foreach (BaseImage image in images)
                {
                    string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".bmp");
                    BMP    bmp      = new BMP(image);
                    bmp.Write(filepath);
                }
            }
            else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(JPEG))
            {
                foreach (BaseImage image in images)
                {
                    string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".jpg");
                    JPEG   jpg      = new JPEG(image);
                    jpg.Write(filepath);
                }
            }
        }
コード例 #6
0
        public static string GetExtensionFromBuffer(byte[] buffer)
        {
            //Archives
            if (AFS.IsValid(buffer))
            {
                return("AFS");
            }
            if (GZ.IsValid(buffer))
            {
                return("GZ");
            }
            if (IDX.IsValid(buffer))
            {
                return("IDX");
            }
            if (IPAC.IsValid(buffer))
            {
                return("IPAC");
            }
            if (PKF.IsValid(buffer))
            {
                return("PKF");
            }
            if (PKS.IsValid(buffer))
            {
                return("PKS");
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return("TAD");
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return("TEXN");
            }
            if (PVRT.IsValid(buffer))
            {
                return("PVRT");
            }
            if (DDS.IsValid(buffer))
            {
                return("DDS");
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return("MT5");
            }
            if (MT7.IsValid(buffer))
            {
                return("MT7");
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return("SUB");
            }

            return("UNKNOWN");
        }
コード例 #7
0
        /// <summary>
        /// Trys to find the fitting file type for the given file with the file signature.
        /// </summary>
        public static Type GetFileTypeFromSignature(Stream stream)
        {
            byte[] buffer = new byte[8];
            stream.Read(buffer, 0, buffer.Length);

            //Archives
            if (AFS.IsValid(buffer))
            {
                return(typeof(AFS));
            }
            if (GZ.IsValid(buffer))
            {
                return(typeof(GZ));
            }
            if (IDX.IsValid(buffer))
            {
                return(typeof(IDX));
            }
            if (IPAC.IsValid(buffer))
            {
                return(typeof(IPAC));
            }
            if (PKF.IsValid(buffer))
            {
                return(typeof(PKF));
            }
            if (PKS.IsValid(buffer))
            {
                return(typeof(PKS));
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return(typeof(TAD));
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return(typeof(TEXN));
            }
            if (PVRT.IsValid(buffer))
            {
                return(typeof(PVRT));
            }
            if (DDS.IsValid(buffer))
            {
                return(typeof(DDS));
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return(typeof(MT5));
            }
            if (MT7.IsValid(buffer))
            {
                return(typeof(MT7));
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return(typeof(SUB));
            }

            return(null);
        }