Пример #1
0
        private static void Texture2PNG(string input_name, string output_name)
        {
            byte[] input   = File.ReadAllBytes(input_name);
            PVR    texture = new PVR(input);

            if (texture.isTexture == false)
            {
                return;
            }
            PVR.Header header = texture.header;
            Console.WriteLine("Reading: {0}\n Width: {1}\n Height: {2}\n Format: {3}\n ColorSpace: {4}\n ChannelType: {5}\n " +
                              "Depth: {6}\n Mipmap: {7}\n Data Offset: {8:X8}",
                              Path.GetFileName(input_name),
                              header.Width,
                              header.Height,
                              header.Format.ToString(),
                              header.ColorSpace,
                              header.ChannelType,
                              header.Depth,
                              header.MipMapCount,
                              texture.DataPosition);
            MagickReadSettings settings = new MagickReadSettings();

            settings.Format = MagickFormat.Rgba;
            settings.Width  = (int)header.Width;
            settings.Height = (int)header.Height;

            ImageMagick.MagickImage im = new MagickImage(texture.GetPixelBytes(), settings);
            im.ToBitmap().Save(output_name);
        }
Пример #2
0
        static void Main(string[] args)
        {
            string filename    = null;
            string outputName  = null;
            bool   bDecompress = false;
            bool   bCompress   = false;
            bool   bShowInfo   = false;
            bool   bShowHelp   = false;

            if (args.Length == 0)
            {
                ShowArgsMsg();
                Program.ShowMsgBox(string.Format("Error: no args \n  Please use this program in console!\n"));

                return;
            }
            #region check args
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].StartsWith("-"))
                    {
                        switch (args[i].TrimStart('-'))
                        {
                        case "h":
                        case "help":
                            bShowHelp = true;
                            break;

                        case "I":
                        case "info":
                            bShowInfo = true;
                            break;

                        case "d":
                        case "dump":
                            bDecompress = true;
                            break;

                        case "o":
                        case "output":
                            outputName = args[++i];
                            break;

                        case "c":
                        case "compress":
                            bCompress = true;
                            break;

                        case "i":
                        case "input":
                            filename = args[++i];
                            break;
                        }
                    }
                }
            }
            #endregion
            #region show help
            if (bShowHelp)
            {
                ShowArgsMsg();
                return;
            }

            #endregion

            if (bShowInfo && (filename != null))
            {
                try
                {
                    PVR texture = new PVR(File.ReadAllBytes(filename));
                    if (texture.isTexture == false)
                    {
                        return;
                    }
                    PVR.Header header = texture.header;
                    Console.WriteLine("Reading: {0}\n Width: {1}\n Height: {2}\n Format: {3}\n ColorSpace: {4}\n ChannelType: {5}\n " +
                                      "Depth: {6}\n Mipmap: {7}\n Data Offset: {8:X8}",
                                      filename,
                                      header.Width,
                                      header.Height,
                                      header.Format.ToString(),
                                      header.ColorSpace,
                                      header.ChannelType,
                                      header.Depth,
                                      header.MipMapCount,
                                      texture.DataPosition);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                return;
            }
            if (filename == outputName)
            {
                Console.WriteLine("Error: can't overwrite input file");
                return;
            }
            if ((filename != null) && (outputName != null))
            {
                if (bDecompress)
                {
                    Texture2PNG(filename, outputName);
                }
                if (bCompress)
                {
                    PNG2Texture(filename, outputName);
                }
            }
#if DEBUG
            Console.ReadKey();
#endif
        }