コード例 #1
0
        public void TestEncryptedWatermark()
        {
            EncryptedWatermark.Algorithm = aes;

            TextWatermark      mark      = new TextWatermark("This should be encrypted");
            EncryptedWatermark encrypted = new EncryptedWatermark(mark, "super-secret");

            Watermarker.EmbedWatermark(file, encrypted, "password", "results/EncryptedMark.png");


            PNGFile            file2   = new PNGFile("results/EncryptedMark.png");
            EncryptedWatermark extract = (EncryptedWatermark)Watermarker.ExtractWatermark(file2, "password");

            mark = extract.Decrypt <TextWatermark>("super-secret");

            Expect(mark, Is.Not.Null);

            Expect(mark.Text, Is.EqualTo("This should be encrypted"));
        }
コード例 #2
0
        public void TestCompositeWatermark()
        {
            EncryptedWatermark.Algorithm = aes;

            CompositeWatermark comp  = new CompositeWatermark();
            TextWatermark      mark1 = new TextWatermark("This is mark #1");
            TextWatermark      mark2 = new TextWatermark("This is mark #2");

            EncryptedWatermark enc = new EncryptedWatermark(mark1, "supersecret");

            comp.AddWatermark(mark1);
            comp.AddWatermark(mark2);
            Expect(comp.Watermarks.Count, Is.EqualTo(2));

            comp.AddWatermark(enc);
            Expect(comp.Watermarks.Count, Is.EqualTo(3));

            Watermarker.EmbedWatermark(file, comp, "password", "results/CompositeMark.png");


            PNGFile file2 = new PNGFile("results/CompositeMark.png");

            CompositeWatermark extract = (CompositeWatermark)Watermarker.ExtractWatermark(file2, "password");


            System.Collections.Generic.List <Watermark> marks = extract.Watermarks;

            Expect(marks.Count, Is.EqualTo(3));

            Assert.IsInstanceOf <TextWatermark>(marks[0]);

            Assert.IsInstanceOf <TextWatermark>(marks[1]);

            Assert.IsInstanceOf <EncryptedWatermark>(marks[2]);



            ((EncryptedWatermark)marks[2]).Decrypt("supersecret");

            Expect(((TextWatermark)marks[0]).Text, Is.EqualTo("This is mark #1"));
            Expect(((TextWatermark)marks[1]).Text, Is.EqualTo("This is mark #2"));
            Expect(((EncryptedWatermark)marks[2]).Decrypt <TextWatermark>("supersecret").Text, Is.EqualTo("This is mark #1"));
        }
コード例 #3
0
        public void TestDoubleEncrypt()
        {
            EncryptedWatermark.Algorithm = aes;

            TextWatermark      mark = new TextWatermark("This will be encrypted twice");
            EncryptedWatermark enc1 = new EncryptedWatermark(mark, "password1");
            EncryptedWatermark enc2 = new EncryptedWatermark(enc1, "password2");

            Watermarker.EmbedWatermark(file, enc2, "password", "results/DoubleEncrypt.png");

            PNGFile file2 = new PNGFile("results/DoubleEncrypt.png");

            EncryptedWatermark extract = Watermarker.ExtractWatermark <EncryptedWatermark>(file, "password");

            extract = extract.Decrypt <EncryptedWatermark>("password2");


            mark = extract.Decrypt <TextWatermark>("password1");

            Expect(mark.Text, Is.EqualTo("This will be encrypted twice"));
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: xvok16/TDCGExplorer
        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);
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        public void TestSeperateMarks()
        {
            // This will only pass if the marks do not overlap on any pixels.

            TextWatermark text1 = new TextWatermark("text1");
            TextWatermark text2 = new TextWatermark("text2");

            Watermarker.EmbedWatermark(file, text1, "password", "results/Embed1.png");

            file = new PNGFile("results/Embed1.png");

            Watermarker.EmbedWatermark(file, text2, "foobar", "results/Embed2Marks.png");

            PNGFile file2 = new PNGFile("results/Embed2Marks.png");

            TextWatermark extract1 = (TextWatermark)Watermarker.ExtractWatermark(file2, "password");

            TextWatermark extract2 = (TextWatermark)Watermarker.ExtractWatermark(file2, "foobar");

            Expect(extract1.Text, Is.EqualTo("text1"));
            Expect(extract2.Text, Is.EqualTo("text2"));
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: xvok16/TDCGExplorer
        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);
        }
コード例 #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);
        }
コード例 #9
0
        public void TestLongRSWatermark()
        {
            byte[] data = new byte[300];
            for (var x = 0; x < 300; x++)
            {
                data[x] = (byte)(x % 17);
            }

            BinaryWatermark binMark = new BinaryWatermark(data);

            Watermarker.ReedSolomonProtection = true;

            Watermarker.EmbedWatermark(file, binMark, "password", "results/LongRS.png");

            PNGFile file2 = new PNGFile("results/LongRS.png");

            BinaryWatermark binMark2 = Watermarker.ExtractWatermark <BinaryWatermark>(file2, "password");

            for (var x = 0; x < binMark2.data.Length; x++)
            {
                Expect(binMark2.data[x], Is.EqualTo(binMark.data[x]));
            }
        }
コード例 #10
0
    //Loads the chunks of the PNG file from the `filename` in the parameter and returns PNGFile object
    public static PNGFile Load(string fileName)
    {
        PNGFile pngChunkCol = new PNGFile();

        using (PNGFileReader pngReader = new PNGFileReader(fileName))
        {
            PNGChunk pChunk = pngReader.ReadChunk();;
            while (true)
            {
                if (pChunk.ChunkType == "IEND")
                {
                    pngChunkCol.PngChunks.Add(pChunk);
                    break;
                }
                else
                {
                    pngChunkCol.PngChunks.Add(pChunk);
                    pChunk = pngReader.ReadChunk();
                }
            }
        }
        return(pngChunkCol);
    }
コード例 #11
0
        public void ShouldThrowExceptionGivenNotPNGFile()
        {
            string JPEGfilePath = @"../../../Data/Kleo.jpg";

            Assert.Throws <FormatException>(() => PNGFile.Read(JPEGfilePath));
        }
コード例 #12
0
        public void ShouldReadIHDRChunk()
        {
            string filePath = @"../../../Data/Plan.png";

            Assert.AreEqual("IHDR", PNGFile.Read(filePath)[0].Type);
        }
コード例 #13
0
        static void Main(string[] args)
        {
            //bool goodArgs = parseArgs(new string[]{"-m=EMBED", "-i=TestImage.png", "-o=Output.png", "-p=password", "-t=Hello", "-t=World", "-f=TestFile.txt", "-f=TestFile.txt", "-b=03,2A,4C,BD", "-e", "-a=AES", "-k=supersecret"});
            //bool goodArgs = parseArgs(new string[] { "-m=EXTRACT","-c","-i=Output.png", "-p=password", "-t=Hello", "-t=World", "-f=TestFile.txt", "-f=TestFile.txt", "-b=03,2A,4C,BD", "-e", "-a=AES", "-k=supersecret" });
            bool goodArgs = parseArgs(args);

            if (goodArgs)
            {
                Watermarker.ReedSolomonProtection = ReedSolomon;

                if (Encrypt)
                {
                    SymmetricAlgorithm algo = null;
                    switch (Algorithm)
                    {
                    case "AES":
                        algo = new RijndaelManaged();
                        break;
                    }
                    if (algo != null)
                    {
                        algo.Padding = PaddingMode.Zeros;
                    }
                    else
                    {
                        Console.WriteLine("Invalid Algorithm specified, valid options are [\"AES\"]");
                        return;
                    }

                    EncryptedWatermark.Algorithm = algo;
                }

                if (Mode.Equals("EMBED"))
                {
                    Watermark finalMark;

                    if (marks.Count > 1)
                    {
                        CompositeWatermark comp = new CompositeWatermark();

                        foreach (Watermark m in marks)
                        {
                            comp.AddWatermark(m);
                        }
                        finalMark = comp;
                    }
                    else
                    {
                        finalMark = marks[0];
                    }

                    if (Encrypt)
                    {
                        finalMark = new EncryptedWatermark(finalMark, EncKey);
                    }

                    PNGFile fileIn = new PNGFile(InputFile);

                    Watermarker.EmbedWatermark(fileIn, finalMark, Password, OutputFile);
                }
                else
                {
                    PNGFile fileIn = new PNGFile(InputFile);

                    Watermark        mark  = Watermarker.ExtractWatermark(fileIn, Password);
                    List <Watermark> marks = new List <Watermark>();

                    // check to see if encrypted
                    if (mark.GetType().Equals(typeof(EncryptedWatermark)))
                    {
                        Console.WriteLine("Detected an encrypted watermark.");
                        if (Encrypt)
                        {
                            Console.WriteLine("Attempting to decrypt the watermark...");
                            mark = ((EncryptedWatermark)mark).Decrypt(EncKey);
                        }
                        else
                        {
                            Console.WriteLine("Encrypt flag was not set, unable to continue. Please try again with the -e flag and appropriate -a and -k values");
                            return;
                        }
                    }

                    // check to see if it is a composite
                    if (mark.GetType().Equals(typeof(CompositeWatermark)))
                    {
                        Console.WriteLine("Composite Watermark detected.");

                        CompositeWatermark comp = (CompositeWatermark)mark;

                        Console.WriteLine("Total of " + comp.Watermarks.Count + " Watermarks found.");

                        foreach (Watermark m in comp.Watermarks)
                        {
                            marks.Add(m);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Found 1 watermark.");
                        marks.Add(mark);
                    }

                    // check to see if only console output
                    if (OnlyConsole)
                    {
                        foreach (Watermark m in marks)
                        {
                            Console.WriteLine(m);
                        }
                    }
                    else
                    {
                        for (var x = 0; x < marks.Count; x++)
                        {
                            marks[x].Save(OutputFile + "\\" + "Watermark" + (x + 1));
                        }
                    }
                }
            }
            Console.ReadKey();
        }
コード例 #14
0
        public void ShouldReadPNGFile()
        {
            string PNGfilePath = @"../../../Data/Plan.png";

            Assert.DoesNotThrow(() => PNGFile.Read(PNGfilePath));
        }
コード例 #15
0
ファイル: PoseFilePage.cs プロジェクト: xvok16/TDCGExplorer
        public void ChangeThumb()
        {
            if (fDisplayed == false)
            {
                DisplayPose();
                TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer.FrameMove();
                TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer.Render();
            }
            // サーフェースからbitmapを作る.
            Bitmap orgbitmap = TDCGExplorer.TDCGExplorer.MainFormWindow.Viewer.GetBitmap();
            // アイコン用bitmapを作る.
            Bitmap savefilebitmap = new Bitmap(128, 128, PixelFormat.Format24bppRgb);

            // 縮小する.
            int x1, y1, x2, y2;

            if (orgbitmap.Width > orgbitmap.Height)
            {// 横に長い
                int div = orgbitmap.Width - orgbitmap.Height;
                x1 = div / 2;
                x2 = orgbitmap.Width - div / 2;
                y1 = 0;
                y2 = orgbitmap.Height;
            }
            else
            {// 縦に長い
                int div = orgbitmap.Height - orgbitmap.Width;
                x1 = 0;
                x2 = orgbitmap.Width;
                y1 = div / 2;
                y2 = orgbitmap.Height - div / 2;
            }
            Graphics  srcG    = Graphics.FromImage(orgbitmap);
            Graphics  dstG    = Graphics.FromImage(savefilebitmap);
            Rectangle dstRect = new Rectangle(0, 0, 128, 128);

            dstG.DrawImage(orgbitmap, dstRect, x1, y1, x2 - x1, y2 - y1, GraphicsUnit.Pixel);

            try
            {
                // ヘビーセーブ形式で保存する.
                if (savefilebitmap == null)
                {
                    return;
                }
                // まずPNG形式のデータを作る.
                using (MemoryStream basepng = new MemoryStream())
                {
                    savefilebitmap.Save(basepng, System.Drawing.Imaging.ImageFormat.Png);
                    // PNGFileクラスにデータを取り込む.
                    using (PNGPOSEStream pngstream = new PNGPOSEStream())
                    {
                        basepng.Seek(0, SeekOrigin.Begin);
                        PNGFile png = pngstream.GetPNG(basepng);
                        //POSEデータを設定する.
                        pngstream.PoseData = posedata;
                        // 保存先を決める.
                        string savefile_dir  = TDCGExplorer.TDCGExplorer.SystemDB.posefile_savedirectory;
                        string savefile_name = Path.GetFileNameWithoutExtension(filename) + ".png";

                        SaveFileDialog dialog = new SaveFileDialog();
                        dialog.FileName         = filename;
                        dialog.InitialDirectory = TDCGExplorer.TDCGExplorer.SystemDB.posefile_savedirectory;
                        dialog.Filter           = TextResource.PNGPoseFileDescription;
                        dialog.FilterIndex      = 0;
                        dialog.Title            = TextResource.SelectSaveFileName;
                        dialog.RestoreDirectory = true;
                        dialog.OverwritePrompt  = true;
                        dialog.CheckPathExists  = true;

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            string destpath = Path.Combine(savefile_dir, dialog.FileName);
                            // 保存先をオープン.
                            //File.Delete(destpath);
                            TDCGExplorer.TDCGExplorer.FileDelete(destpath);
                            using (Stream output = File.Create(destpath))
                            {
                                // PNGを出力する.
                                pngstream.SavePNGFile(png, output);
                            }

                            // 以前表示していたbitmapを捨てる.
#if false
                            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Image  = savefilebitmap;
                            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Width  = savefilebitmap.Width;
                            TDCGExplorer.TDCGExplorer.MainFormWindow.PictureBox.Height = savefilebitmap.Height;
#else
                            TDCGExplorer.TDCGExplorer.MainFormWindow.SetBitmap(savefilebitmap);
#endif
                            // ファイルを追加する.
                            TDCGExplorer.TDCGExplorer.AddFileTree(destpath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TDCGExplorer.TDCGExplorer.SetToolTips(TextResource.Error + ":" + ex.Message);
            }
            srcG.Dispose();
            dstG.Dispose();
            orgbitmap.Dispose();

            //savefilebitmapは表示に使うので捨ててはいけない.
            //savefilebitmap.Dispose();
        }
コード例 #16
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);
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: xvok16/TDCGExplorer
        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);
        }
コード例 #18
0
ファイル: Form1.cs プロジェクト: xvok16/TDCGExplorer
        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);
        }
コード例 #19
0
ファイル: SaveFilePage.cs プロジェクト: xvok16/TDCGExplorer
        private void HeavySave()
        {
            try
            {
                // ヘビーセーブ形式で保存する.
                if (savefilebitmap == null)
                {
                    return;
                }

                // まずPNG形式のデータを作る.
                MemoryStream basepng = new MemoryStream();
                savefilebitmap.Save(basepng, System.Drawing.Imaging.ImageFormat.Png);
                // PNGFileクラスにデータを取り込む.
                PNGHSAVStream pngstream = new PNGHSAVStream();
                basepng.Seek(0, SeekOrigin.Begin);
                PNGFile png = pngstream.GetPNG(basepng);

                // TSOデータを読み込んで組み立てる.
                if (fDisplayed == false)
                {
                    DisplayTso();
                }

                //TSOデータを設定する.
                foreach (PNGTsoData tsodata in tsoDataList)
                {
                    pngstream.get.Add(tsodata);
                }
                // 保存先を決める.
                string savefile_dir  = TDCGExplorer.TDCGExplorer.SystemDB.savefile_directory;
                string savefile_name = Path.GetFileNameWithoutExtension(filename) + ".png";

                SaveFileDialog dialog = new SaveFileDialog();
                dialog.FileName         = filename;
                dialog.InitialDirectory = TDCGExplorer.TDCGExplorer.SystemDB.savefile_directory;
                dialog.Filter           = TextResource.PNGSaveFileDescription;
                dialog.FilterIndex      = 0;
                dialog.Title            = TextResource.SelectSaveFileName;
                dialog.RestoreDirectory = true;
                dialog.OverwritePrompt  = true;
                dialog.CheckPathExists  = true;

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    string destpath = dialog.FileName;

                    // 保存先をオープン.
                    //File.Delete(destpath);
                    TDCGExplorer.TDCGExplorer.FileDelete(destpath);
                    using (Stream output = File.Create(destpath))
                    {
                        // PNGを出力する.
                        pngstream.SavePNGFile(png, output);
                    }
                    // ファイルを追加する.
                    TDCGExplorer.TDCGExplorer.AddFileTree(destpath);
                }
            }
            catch (Exception ex)
            {
                TDCGExplorer.TDCGExplorer.SetToolTips(TextResource.Error + ":" + ex.Message);
            }
        }
コード例 #20
0
 public void ShouldReadIFD()
 {
     string       filePath = @"../../../Data/kostkiExif.png";
     List <Chunk> chunks   = PNGFile.Read(filePath);
     eXIf         exif     = new eXIf(chunks[chunks.Count - 2]);
 }
コード例 #21
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);
        }