Esempio n. 1
0
        static PNGFile CreatePNGFileFromPSDFile(PSDFile psd)
        {
            MemoryStream ms = new MemoryStream();

            psd.Bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            ms.Seek(0, SeekOrigin.Begin);

            PNGFile png = new PNGFile();

            png.Load(ms);

            return(png);
        }
Esempio n. 2
0
    public void ValidateSignature_InvalidPngFile_DoesNotLoad()
    {
        string fileName = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "shovel.jpeg");

        try
        {
            PNGFile pngChunkCol = PNGFile.Load(fileName);
            Assert.Fail();
        }
        catch (ArgumentException)
        {
        }
    }
Esempio n. 3
0
    public void Load_ValidPNG_ChunksLoadedCorrectly()
    {
        string fileName = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "ice.png");

        string[] chunkNames = new string[] { "IHDR", "gAMA", "bKGD", "IDAT", "IDAT", "IDAT", "tEXt", "tEXt", "tEXt", "IEND" };

        PNGFile pngChunkCol = PNGFile.Load(fileName);

        Assert.True(pngChunkCol.PngChunks.Count == 10);
        for (int i = 0; i < pngChunkCol.PngChunks.Count; i++)
        {
            Assert.True(pngChunkCol.PngChunks[i].ChunkType == chunkNames[i]);
        }
    }
Esempio n. 4
0
        public List <string> GetCategoryList(string file_name)
        {
            string[] category =
            {
                "身体",
                "前髪",
                "後髪",
                "頭皮",
                "瞳",
                "ブラ",
                "全身下着・水着",
                "パンツ",
                "靴下",
                "上衣",
                "全身衣装",
                "上着オプション",
                "下衣",
                "尻尾",
                "靴",
                "頭部装備",
                "眼鏡",
                "首輪",
                "手首",
                "背中",
                "アホ毛類",
                "眼帯",
                "タイツ・ガーター",
                "腕装備",
                "リボン",
                "手持ちの小物or背景",
                "眉毛",
                "ほくろ",
                "八重歯",
                "イヤリング類"
            };

            List <string> opt = new List <string>();
            PNGFile       png = new PNGFile();

            png.Ftso += delegate(Stream dest, int extract_length, byte[] opt1)
            {
                opt.Add(category[(int)opt1[0]]);
            };
            png.Load(file_name);

            return(opt);
        }
Esempio n. 5
0
        public PNGFile CreatePNGFile()
        {
            MemoryStream ms = new MemoryStream();

            using (Bitmap bmp = new Bitmap(180, 180, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
            {
                Graphics g     = Graphics.FromImage(bmp);
                Brush    brush = new SolidBrush(Color.FromArgb(0xfb, 0xc6, 0xc6));
                g.FillRectangle(brush, 0, 0, 180, 180);
                Font font = new Font(FontFamily.GenericSerif, 36, FontStyle.Bold);
                g.DrawString("morph", font, Brushes.Black, 0, 0);
                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            }
            ms.Seek(0, SeekOrigin.Begin);

            PNGFile png = new PNGFile();

            png.Load(ms);

            return(png);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            //Check length of argument
            if (args.Length != 1)
            {
                Console.WriteLine("\nYou did not supply an appropriate filename. Usage: <programName> <fileName>");
                Environment.Exit(1);
            }

            string thisFileName = args[0];

            //Check to see if file exists
            if (!File.Exists(thisFileName))
            {
                Console.WriteLine("The file you provided does not exist in the current directory.");
                Environment.Exit(1);
            }

            try {
                //guarding the file potentially not being a png file

                PNGFile fileChunks = PNGFile.Load(thisFileName);

                //Now display the metadata
                Console.WriteLine("\nMetadata in {0}:\n", thisFileName);
                foreach (PNGChunk pngChunk in fileChunks.PngChunks)
                {
                    string metadata;
                    if (pngChunk.ChunkType == "tEXt")
                    {
                        metadata = pngChunk.ExtractMData();
                        Console.WriteLine(metadata);
                    }
                }
            }
            catch (ArgumentException argExcep)
            {
                Console.WriteLine(argExcep.Message);
            }
        }
Esempio n. 7
0
        public int Compose(string dest_path)
        {
            this.dest_path = dest_path;
            PNGFile png = new PNGFile();

            string source_type = ReadSourceType(dest_path + @"\TDCG.txt");

            Console.WriteLine("This is {0} Save File", source_type);

            png.WriteTaOb += delegate(BinaryWriter bw)
            {
                PNGWriter pw = new PNGWriter(bw);
                WriteHsavOrPoseOrScne(pw, source_type);
            };

            png.Load(dest_path + @"\thumbnail.png");
            string dest_file = Path.ChangeExtension(dest_path, @".new" + Path.GetExtension(dest_path) + @".png");

            Console.WriteLine("Save File: " + dest_file);
            png.Save(dest_file);
            return(0);
        }
Esempio n. 8
0
        public static TMOFile LoadPNGFile(string source_file)
        {
            TMOFile tmo = new TMOFile();

            if (File.Exists(source_file))
            {
                try
                {
                    PNGFile png = new PNGFile();

                    png.Ftmo += delegate(Stream dest, int extract_length)
                    {
                        tmo.Load(dest);
                    };
                    png.Load(source_file);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex);
                }
            }
            return(tmo);
        }
Esempio n. 9
0
        public bool Process(string source_file)
        {
            List <TSOFigure> fig_list = new List <TSOFigure>();

            Console.WriteLine("Load File: " + source_file);
            PNGFile source      = new PNGFile();
            string  source_type = "";

            try
            {
                TSOFigure fig = null;
                TMOFile   tmo = null;

                source.Hsav += delegate(string type)
                {
                    source_type = type;

                    fig = new TSOFigure();
                    fig_list.Add(fig);
                };
                source.Pose += delegate(string type)
                {
                    source_type = type;
                };
                source.Scne += delegate(string type)
                {
                    source_type = type;
                };
                source.Cami += delegate(Stream dest, int extract_length)
                {
                    cami = new byte[extract_length];
                    dest.Read(cami, 0, extract_length);
                };
                source.Lgta += delegate(Stream dest, int extract_length)
                {
                    byte[] lgta = new byte[extract_length];
                    dest.Read(lgta, 0, extract_length);

                    fig      = new TSOFigure();
                    fig.lgta = lgta;
                    fig_list.Add(fig);
                };
                source.Ftmo += delegate(Stream dest, int extract_length)
                {
                    tmo = new TMOFile();
                    tmo.Load(dest);
                    fig.tmo = tmo;
                };
                source.Figu += delegate(Stream dest, int extract_length)
                {
                    byte[] figu = new byte[extract_length];
                    dest.Read(figu, 0, extract_length);

                    fig.figu = figu;
                };
                source.Ftso += delegate(Stream dest, int extract_length, byte[] opt1)
                {
                    byte[] ftso = new byte[extract_length];
                    dest.Read(ftso, 0, extract_length);

                    TSOData tso = new TSOData();
                    tso.opt1 = BitConverter.ToUInt32(opt1, 0);
                    tso.ftso = ftso;
                    fig.TSOList.Add(tso);
                };

                source.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }

            foreach (TSOFigure fig in fig_list)
            {
                TSOFigureList.Add(fig);
            }

            TDCG.TMOFlip.TMOFlipProcessor processor = new TDCG.TMOFlip.TMOFlipProcessor();

            foreach (TSOFigure fig in TSOFigureList)
            {
                if (fig.tmo != null)
                {
                    if (fig.tmo.nodes[0].Path == "|W_Hips")
                    {
                        processor.Process(fig.tmo);
                    }
                }
            }

            string dest_path = Path.GetDirectoryName(source_file);
            string dest_file = Path.GetFileNameWithoutExtension(source_file) + @".new.png";

            Console.WriteLine("Save File: " + dest_file);
            source.WriteTaOb += delegate(BinaryWriter bw)
            {
                PNGWriter pw = new PNGWriter(bw);
                switch (source_type)
                {
                case "HSAV":
                    WriteHsav(pw);
                    break;

                case "POSE":
                    WritePose(pw);
                    break;

                case "SCNE":
                    WriteScne(pw);
                    break;
                }
            };
            source.Save(dest_file);

            return(true);
        }
Esempio n. 10
0
        public bool Process(Stream png_stream, Stream ret_stream)
        {
            List <TSOFigure> fig_list = new List <TSOFigure>();

            PNGFile png         = new PNGFile();
            string  source_type = "";

            {
                TSOFigure fig = null;
                TMOFile   tmo = null;

                png.Hsav += delegate(string type)
                {
                    source_type = type;

                    fig = new TSOFigure();
                    fig_list.Add(fig);
                };
                png.Pose += delegate(string type)
                {
                    source_type = type;
                };
                png.Scne += delegate(string type)
                {
                    source_type = type;
                };
                png.Cami += delegate(Stream dest, int extract_length)
                {
                    cami = new byte[extract_length];
                    dest.Read(cami, 0, extract_length);
                };
                png.Lgta += delegate(Stream dest, int extract_length)
                {
                    byte[] lgta = new byte[extract_length];
                    dest.Read(lgta, 0, extract_length);

                    fig      = new TSOFigure();
                    fig.lgta = lgta;
                    fig_list.Add(fig);
                };
                png.Ftmo += delegate(Stream dest, int extract_length)
                {
                    tmo = new TMOFile();
                    tmo.Load(dest);
                    if (fig == null)
                    {
                        source_type = "PTMO";
                        fig         = new TSOFigure();
                        fig.lgta    = null;
                        fig_list.Add(fig);
                    }
                    fig.tmo = tmo;
                };
                png.Figu += delegate(Stream dest, int extract_length)
                {
                    byte[] figu = new byte[extract_length];
                    dest.Read(figu, 0, extract_length);

                    fig.figu = figu;
                };
                png.Ftso += delegate(Stream dest, int extract_length, byte[] opt1)
                {
                    byte[] ftso = new byte[extract_length];
                    dest.Read(ftso, 0, extract_length);

                    TSOData tso = new TSOData();
                    tso.opt1 = BitConverter.ToUInt32(opt1, 0);
                    tso.ftso = ftso;
                    fig.TSOList.Add(tso);
                };

                png.Load(png_stream);
                png_stream.Close();
            }

            foreach (TSOFigure fig in fig_list)
            {
                TSOFigureList.Add(fig);
            }

            foreach (TSOFigure fig in TSOFigureList)
            {
                if (fig.tmo != null)
                {
                    if (fig.tmo.nodes[0].Path == "|W_Hips")
                    {
                        tmo_Transform(fig.tmo);
                    }
                }
            }

            png.WriteTaOb += delegate(BinaryWriter bw)
            {
                PNGWriter pw = new PNGWriter(bw);
                switch (source_type)
                {
                case "HSAV":
                    WriteHsav(pw);
                    break;

                case "POSE":
                    WritePose(pw);
                    break;

                case "SCNE":
                    WriteScne(pw);
                    break;

                case "PTMO":
                    WritePtmo(pw);
                    break;
                }
            };
            png.Save(ret_stream);

            TSOFigureList.Clear();
            return(true);
        }
Esempio n. 11
0
        public int Extract(string source_file, string dest_path)
        {
            try
            {
                Directory.CreateDirectory(dest_path);
            }
            catch (Exception)
            {
                Console.WriteLine("Error: Cannot prepare destination directory for file writing.");
                return(-1);
            }
            PNGFile png = new PNGFile();

            string source_type = null;

            png.Hsav += delegate(string type)
            {
                Console.WriteLine("This is {0} Save File", type);
                DumpSourceType(dest_path + @"\TDCG.txt", type);
                source_type = type;

                string figure_path = dest_path + @"\" + numTMO;
                if (!System.IO.Directory.Exists(figure_path))
                {
                    System.IO.Directory.CreateDirectory(figure_path);
                }
            };
            png.Pose += delegate(string type)
            {
                Console.WriteLine("This is {0} Save File", type);
                DumpSourceType(dest_path + @"\TDCG.txt", type);
                source_type = type;
            };
            png.Scne += delegate(string type)
            {
                Console.WriteLine("This is {0} Save File", type);
                DumpSourceType(dest_path + @"\TDCG.txt", type);
                source_type = type;
            };
            png.Cami += delegate(Stream dest, int extract_length)
            {
                byte[] buf = new byte[extract_length];
                dest.Read(buf, 0, extract_length);

                string dest_file = dest_path + @"\Camera.txt";
                Console.WriteLine("CAMI Save File: " + dest_file);

                using (StreamWriter sw = new StreamWriter(dest_file))
                    for (int offset = 0; offset < extract_length; offset += sizeof(float))
                    {
                        float flo = BitConverter.ToSingle(buf, offset);
                        sw.WriteLine(flo);
                    }
            };
            png.Lgta += delegate(Stream dest, int extract_length)
            {
                numTMO++;

                byte[] buf = new byte[extract_length];
                dest.Read(buf, 0, extract_length);

                string dest_file = dest_path + @"\LightA" + numTMO + ".txt";
                Console.WriteLine("LGTA Save File: " + dest_file);

                using (StreamWriter sw = new StreamWriter(dest_file))
                    for (int offset = 0; offset < extract_length; offset += sizeof(float))
                    {
                        float flo = BitConverter.ToSingle(buf, offset);
                        sw.WriteLine(flo);
                    }
            };
            png.Figu += delegate(Stream dest, int extract_length)
            {
                byte[] buf = new byte[extract_length];
                dest.Read(buf, 0, extract_length);

                string dest_file = dest_path + @"\Figure" + numTMO + ".txt";
                Console.WriteLine("FIGU Save File: " + dest_file);

                using (StreamWriter sw = new StreamWriter(dest_file))
                    for (int offset = 0; offset < extract_length; offset += sizeof(float))
                    {
                        float flo = BitConverter.ToSingle(buf, offset);
                        sw.WriteLine(flo);
                    }

                string figure_path = dest_path + @"\" + numTMO;
                if (!System.IO.Directory.Exists(figure_path))
                {
                    System.IO.Directory.CreateDirectory(figure_path);
                }
            };
            png.Ftmo += delegate(Stream dest, int extract_length)
            {
                string dest_file = dest_path + @"\" + numTMO + ".tmo";
                Console.WriteLine("TMO Save File: " + dest_file);

                using (FileStream file = File.Create(dest_file))
                {
                    byte[] buf = new byte[4096];
                    StreamUtils.Copy(dest, file, buf);
                }
            };
            png.Ftso += delegate(Stream dest, int extract_length, byte[] opt1)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < 1; i++)
                {
                    sb.Append(string.Format("{0:X2}", opt1[i]));
                }
                string code = sb.ToString();

                string dest_file = dest_path + @"\" + numTMO + @"\" + code + ".tso";
                Console.WriteLine("TSO Save File: " + dest_file);

                using (FileStream file = File.Create(dest_file))
                {
                    byte[] buf = new byte[4096];
                    StreamUtils.Copy(dest, file, buf);
                }
            };

            png.Load(source_file);
            png.Save(dest_path + @"\thumbnail.png");

            if (source_type == "HSAV")
            {
                BMPSaveData data = new BMPSaveData();

                using (Stream stream = File.OpenRead(dest_path + @"\thumbnail.png"))
                    data.Read(stream);

                string dest_file = dest_path + @"\thumbnail.txt";
                Console.WriteLine("dump bmp save data: " + dest_file);
                DumpBmpSaveData(data, dest_file);
            }

            return(0);
        }
Esempio n. 12
0
        public bool CopyNode(string source_file, string motion_file, string node_name)
        {
            List <TSOFigure> fig_list = new List <TSOFigure>();

            Console.WriteLine("Load File: " + source_file);
            PNGFile source      = new PNGFile();
            string  source_type = "";

            try
            {
                TSOFigure fig = null;
                TMOFile   tmo = null;

                source.Hsav += delegate(string type)
                {
                    source_type = type;

                    fig = new TSOFigure();
                    fig_list.Add(fig);
                };
                source.Pose += delegate(string type)
                {
                    source_type = type;
                };
                source.Scne += delegate(string type)
                {
                    source_type = type;
                };
                source.Cami += delegate(Stream dest, int extract_length)
                {
                    cami = new byte[extract_length];
                    dest.Read(cami, 0, extract_length);
                };
                source.Lgta += delegate(Stream dest, int extract_length)
                {
                    byte[] lgta = new byte[extract_length];
                    dest.Read(lgta, 0, extract_length);

                    fig      = new TSOFigure();
                    fig.lgta = lgta;
                    fig_list.Add(fig);
                };
                source.Ftmo += delegate(Stream dest, int extract_length)
                {
                    tmo = new TMOFile();
                    tmo.Load(dest);
                    fig.tmo = tmo;
                };
                source.Figu += delegate(Stream dest, int extract_length)
                {
                    byte[] figu = new byte[extract_length];
                    dest.Read(figu, 0, extract_length);

                    fig.figu = figu;
                };
                source.Ftso += delegate(Stream dest, int extract_length, byte[] opt1)
                {
                    byte[] ftso = new byte[extract_length];
                    dest.Read(ftso, 0, extract_length);

                    TSOData tso = new TSOData();
                    tso.opt1 = BitConverter.ToUInt32(opt1, 0);
                    tso.ftso = ftso;
                    fig.TSOList.Add(tso);
                };

                source.Load(source_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }

            foreach (TSOFigure fig in fig_list)
            {
                TSOFigureList.Add(fig);
            }

            Console.WriteLine("Load File: " + motion_file);
            PNGFile motion     = new PNGFile();
            TMOFile motion_tmo = null;

            try
            {
                motion.Ftmo += delegate(Stream dest, int extract_length)
                {
                    motion_tmo = new TMOFile();
                    motion_tmo.Load(dest);
                };

                motion.Load(motion_file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }

            if (motion_tmo != null)
            {
                foreach (TSOFigure fig in TSOFigureList)
                {
                    if (fig.tmo != null)
                    {
                        fig.tmo.CopyNodeFrom(motion_tmo, node_name);
                    }
                }
            }

            string dest_file = source_file + ".tmp";

            Console.WriteLine("Save File: " + dest_file);
            source.WriteTaOb += delegate(BinaryWriter bw)
            {
                PNGWriter pw = new PNGWriter(bw);
                switch (source_type)
                {
                case "HSAV":
                    WriteHsav(pw);
                    break;

                case "POSE":
                    WritePose(pw);
                    break;

                case "SCNE":
                    WriteScne(pw);
                    break;
                }
            };
            source.Save(dest_file);

            File.Delete(source_file);
            File.Move(dest_file, source_file);
            Console.WriteLine("updated " + source_file);

            return(true);
        }