Ejemplo n.º 1
0
        static string ConvertSettingsToArguments(TTToolSettings s)
        {
            StringBuilder sb = new StringBuilder();

            if (s.ImageFormat != EnumImageFormat.Default)
            {
                if (s.ImageFormat == EnumImageFormat.SVGPNG)
                {
                    sb.Append($" --image-format SVG+PNG");
                }
                else
                {
                    sb.Append($" --image-format {s.ImageFormat}");
                }
            }
            if (s.CodeDim != Size.Empty)
            {
                sb.Append($" --code-dim {s.CodeDim.Width}x{s.CodeDim.Height}");
            }
            sb.Append($" --dpi {(int)s.DPI}");

            if (s.PixelSize != 0)
            {
                sb.Append($" --pixel-size {(int)s.PixelSize}");
            }
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public static void ExportTTImages(OIDProject oIDProject, Scene scene, TTToolSettings set, bool highquality, bool canvasImage, bool maskimage, EnumNeutralOid enumNeutral)
        {
            if (scene == null || scene.TTImages == null || scene.TTImages.Count == 0)
            {
                return;
            }

            string destDir = Path.Combine(oIDProject.ProjectPath, "Scenes");

            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            if (canvasImage)
            {
                ExportCanvasImage(scene, destDir);
            }

            string workdir = Path.Combine(oIDProject.ProjectPath, "temp");

            if (!Directory.Exists(workdir))
            {
                Directory.CreateDirectory(workdir);
            }
            if (maskimage)
            {
                CreateMaskPicture(oIDProject, scene, set, highquality, destDir, workdir, enumNeutral);
            }
        }
Ejemplo n.º 3
0
        private static void CreateMaskPicture(OIDProject oIDProject, Scene scene, TTToolSettings set, bool highquality, string destDir, string workdir, EnumNeutralOid enumNeutral)
        {
            using (var maskPicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
            {
                using (Graphics graphic = Graphics.FromImage(maskPicture))
                {
                    graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                    if (enumNeutral == EnumNeutralOid.mask)
                    {
                        CreateNeutralMask(maskPicture, scene, set, workdir);
                    }

                    DrawAllOids(oIDProject, scene, set, workdir, maskPicture, graphic, highquality);
                }
                maskPicture.Save(Path.Combine(destDir, $"{scene.Name}_mask.png"), ImageFormat.Png);
            }

            if (enumNeutral == EnumNeutralOid.separate)
            {
                using (var maskPicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
                {
                    using (Graphics graphic = Graphics.FromImage(maskPicture))
                    {
                        graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                        CreateNeutralMask(maskPicture, scene, set, workdir);
                    }
                    maskPicture.Save(Path.Combine(destDir, $"{scene.Name}_neutral.png"), ImageFormat.Png);
                }
            }
        }
Ejemplo n.º 4
0
 private static void DrawStartOids(OIDProject oIDProject, Scene scene, TTToolSettings set, string workdir, Bitmap maskPicture, Graphics graphic, bool highquality)
 {
     if (scene.StartOid != null && scene.StartOid.Polygons != null && scene.StartOid.Polygons.Count > 0)
     {
         set.CodeDim = new Size(1, 1);
         var res       = TTTool.CreateOidCodes(set, oIDProject.ProductID, workdir);
         var MaskImage = Bitmap.FromFile(res);
         DrawPolygons(maskPicture, graphic, scene.StartOid, MaskImage, highquality);
     }
 }
Ejemplo n.º 5
0
 private static void DrawSeceneOids(OIDProject oIDProject, Scene scene, TTToolSettings set, string workdir, Bitmap maskPicture, Graphics graphic, bool highquality)
 {
     foreach (SceneOid sc in scene.SceneOids)
     {
         var ns = oIDProject.nodeSetups.Where(x => x.Name == sc.SetupName).FirstOrDefault();
         set.CodeDim = new Size(1, 1);
         var res       = TTTool.CreateOidCodes(set, (short)ns.OID, workdir);
         var MaskImage = Bitmap.FromFile(res);
         DrawPolygons(maskPicture, graphic, sc, MaskImage, highquality);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Das tttool kann OID-Muster in verschiedenen Formaten erzeugen – das brauchst du dann, wenn du deine eigenen
        ///Tiptoi-Produkte gestalten willst.Es versteht dazu mehrere Befehle, je nach dem woher es wissen soll, zu welche
        /// Codes es die Muster erzeugen soll, und mehrere Optionen, die steuern, wie die Muster auszusehen haben.
        /// </summary>
        /// <param name="tttSettings"></param>
        /// <param name="yamlFile"></param>
        /// <returns></returns>
        public static string CreateOidCodes(TTToolSettings tttSettings, string yamlFile, string outPath = "")
        {
            var path = TTGRegistry.Read("tttoolPath");
            var yf   = yamlFile.EndsWith(".yaml") ? "yamlFile" : $"{yamlFile}.yaml";
            var arg  = $"{ConvertSettingsToArguments(tttSettings)} oid-codes {yf}";

            if (!string.IsNullOrEmpty(outPath))
            {
                arg = $"{arg} \"{outPath}\"";
            }
            return(CMD.GetMultiline(path, arg));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Das tttool kann OID-Muster in verschiedenen Formaten erzeugen – das brauchst du dann, wenn du deine eigenen
        /// Tiptoi-Produkte gestalten willst.Es versteht dazu mehrere Befehle, je nach dem woher es wissen soll, zu welche
        /// Codes es die Muster erzeugen soll, und mehrere Optionen, die steuern, wie die Muster auszusehen haben.
        /// </summary>
        /// <param name="tttSettings"></param>
        /// <param name="code"></param>
        public static string CreateOidCodes(TTToolSettings tttSettings, short code, string workdir = "")
        {
            var path = TTGRegistry.Read("tttoolPath");
            var arg  = $"{ConvertSettingsToArguments(tttSettings)} oid-code {code}";

            if (string.IsNullOrEmpty(workdir))
            {
                CMD.GetMultiline(path, arg);
                return(Path.Combine(Assembly.GetAssembly(typeof(MainForm)).Location, $"oid-{code}.png"));
            }
            else
            {
                CMD.GetMultiline(path, workdir, arg);
                return(Path.Combine(workdir, $"oid-{code}.png"));
            }
        }
Ejemplo n.º 8
0
        public static void CreateImage(OIDProject oIDProject, Scene scene, TTToolSettings set, bool highquality)
        {
            if (scene == null || scene.TTImages == null || scene.TTImages.Count == 0)
            {
                return;
            }

            string destDir = Path.Combine(oIDProject.ProjectPath, "Scenes");

            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            using (var scenePicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
            {
                using (Graphics graphic = Graphics.FromImage(scenePicture))
                {
                    foreach (var img in scene.TTImages)
                    {
                        img.Draw(graphic, 1);
                    }
                }
                scenePicture.Save(Path.Combine(destDir, $"{scene.Name}.png"), ImageFormat.Png);
            }

            string workdir = Path.Combine(oIDProject.ProjectPath, "temp");

            if (!Directory.Exists(workdir))
            {
                Directory.CreateDirectory(workdir);
            }

            using (var maskPicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
            {
                using (Graphics graphic = Graphics.FromImage(maskPicture))
                {
                    DrawSeceneOids(oIDProject, scene, set, workdir, maskPicture, graphic, highquality);
                    DrawStartOids(oIDProject, scene, set, workdir, maskPicture, graphic, highquality);
                }


                maskPicture.Save(Path.Combine(destDir, $"{scene.Name}_mask.png"), ImageFormat.Png);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Das tttool kann OID-Muster in verschiedenen Formaten erzeugen – das brauchst du dann, wenn du deine eigenen
        ///Tiptoi-Produkte gestalten willst.Es versteht dazu mehrere Befehle, je nach dem woher es wissen soll, zu welche
        /// Codes es die Muster erzeugen soll, und mehrere Optionen, die steuern, wie die Muster auszusehen haben.
        /// </summary>
        /// <param name="tttSettings"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static string CreateOidCodes(TTToolSettings tttSettings, short from, short to, string workdir = "")
        {
            if (from < to)
            {
                var t = from;
                from = to;
                to   = t;
            }

            var path = TTGRegistry.Read("tttoolPath");
            var arg  = $"{ConvertSettingsToArguments(tttSettings)} oid-code {from}-{to}";

            if (string.IsNullOrEmpty(workdir))
            {
                return(CMD.GetMultiline(path, arg));
            }
            return(CMD.GetMultiline(path, workdir, arg));
        }
Ejemplo n.º 10
0
        private void TsGenerateLayer_Click(object sender, EventArgs e)
        {
            if (selectedScene != null && MainForm.Project != null)
            {
                TTToolSettings tTToolSettings = new TTToolSettings();


                tTToolSettings.DPI = selectedScene.ResolutionDPI;
                var res = MessageBox.Show(this, "Generate Oid Pixel by Pixel, takes ~2min", "", MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.Yes)
                {
                    MaskPicture.CreateImage(MainForm.Project, selectedScene, tTToolSettings, true);
                }
                else if (res == DialogResult.No)
                {
                    MaskPicture.CreateImage(MainForm.Project, selectedScene, tTToolSettings, false);
                }
            }
        }
Ejemplo n.º 11
0
        private static void DrawAllOids(OIDProject oIDProject, Scene scene, TTToolSettings set, string workdir, Bitmap maskPicture, Graphics graphic, bool highquality)
        {
            var allOids = new List <SceneOid>();

            allOids.AddRange(scene.SceneOids);
            if (scene.StartOid != null && scene.StartOid.Polygons != null && scene.StartOid.Polygons.Count > 0)
            {
                allOids.Add(scene.StartOid);
            }

            foreach (SceneOid sc in allOids)
            {
                var ns = oIDProject.nodeSetups.Where(x => x.Name == sc.SetupName).FirstOrDefault();
                set.CodeDim = new Size(1, 1);
                var res       = TTTool.CreateOidCodes(set, (ushort)(ns != null ? ns.OID: oIDProject.ProductID), workdir);
                var MaskImage = Bitmap.FromFile(res);
                DrawPolygons(maskPicture, graphic, sc, MaskImage, highquality);
            }
        }
        private void TsGenerateLayer_Click(object sender, EventArgs e)
        {
            if (selectedScene != null && MainForm.Project != null)
            {
                TTToolSettings tTToolSettings = new TTToolSettings();


                tTToolSettings.DPI = selectedScene.ResolutionDPI;
                using (var f = new frmImageExport())
                {
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        MaskPicture.ExportTTImages(MainForm.Project, selectedScene, tTToolSettings, f.Highquality, f.ExportCanvasImage, f.ExportMask, f.enumNeutral);

                        Cursor.Current = Cursors.Default;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private static void CreateNeutralMask(Image image, Scene scene, TTToolSettings set, string workdir)
        {
            var bmp = (set.DPI == 1200 ? Resources.oid_65535_high : Resources.oid_65535_low);

            var allPolygons = scene.SceneOids.SelectMany(x => x.Polygons).ToList();

            if (scene.StartOid != null && scene.StartOid.Polygons != null && scene.StartOid.Polygons.Count > 0)
            {
                allPolygons.AddRange(scene.StartOid.Polygons);
            }

            using (Graphics graphic = Graphics.FromImage(image))
            {
                for (float x = 0; x < scene.PixelSize.Width; x += bmp.Width)
                {
                    for (float y = 0; y < scene.PixelSize.Height; y += bmp.Height)
                    {
                        var  broadcastPolygon = allPolygons.Where(z => z.GetBound().Contains(x, y));
                        bool secondPhasehit   = false;
                        foreach (Polygon p in broadcastPolygon)
                        {
                            if (p.PointInPolygon(x, y) || p.PointInPolygon(x + bmp.Width, y + bmp.Height) || p.PointInPolygon(x + bmp.Width, y) || p.PointInPolygon(x, y + bmp.Height))
                            {
                                var ci = CountEdges(p, x, y, bmp.Width, bmp.Height, true);
                                if (ci > 0)
                                {
                                    DrawEdge(p, (Bitmap)bmp, (Bitmap)image, (int)x, (int)y, true);
                                }

                                secondPhasehit = true;
                            }
                        }
                        if (!secondPhasehit)
                        {
                            graphic.DrawImage(bmp, (int)x, (int)y, bmp.Width, bmp.Width);
                        }
                    }
                }
            }
        }