Ejemplo n.º 1
0
        public void TestDrawCommon()
        {
            var resPath = Path.Combine(Environment.CurrentDirectory, @"..\..\Res");
            var path    = Path.Combine(resPath, "akira_guide-pure.psb");
            var psb     = new PSB(path);
            var painter = new PsbPainter(psb);
            var bmp     = painter.Draw(2048, 2048);

            bmp.Save("RenderCommon.png", ImageFormat.Png);
        }
Ejemplo n.º 2
0
        public void TestDrawKrkr()
        {
            var resPath = Path.Combine(Environment.CurrentDirectory, @"..\..\Res");
            var path    = Path.Combine(resPath, "澄怜a_裸-pure.psb");
            var psb     = new PSB(path);
            var painter = new PsbPainter(psb);
            var bmp     = painter.Draw(4096, 4096);

            bmp.Save("RenderKrkr.png", ImageFormat.Png);
        }
Ejemplo n.º 3
0
        public void TestDrawWin()
        {
            var resPath = Path.Combine(Environment.CurrentDirectory, @"..\..\Res");
            var path    = Path.Combine(resPath, "emote_logo_d5-pure.psb");
            //var path = Path.Combine(resPath, "vanilla-pure.psb");
            var psb     = new PSB(path);
            var painter = new PsbPainter(psb);
            var bmp     = painter.Draw(4096, 4096);

            bmp.Save("RenderWin.png", ImageFormat.Png);
        }
Ejemplo n.º 4
0
        public MemoryStream ToShell(Stream stream, Dictionary <string, object> context = null)
        {
            Console.WriteLine(
                "[WARN] Exported PSD files should follow CC-BY-NC-SA 4.0. Please keep FreeMote information in PSD files.");
            var psb = new PSB(stream);

            if (psb == null)
            {
                throw new BadImageFormatException("Not a valid PSB file.");
            }

            PsbPainter painter = new PsbPainter(psb);

            if (TryGetCanvasSize)
            {
                if (psb.TryGetCanvasSize(out var cw, out var ch))
                {
                    Width  = (int)(cw * 1.8f);
                    Height = (int)(ch * 1.4f);
                }
                else
                {
                    //Try get from painter, not accurate if the PSB center is not (0,0)
                    Width = (int)(painter.Resources.Max(r => r.OriginX + r.Width / 2.0f) -
                                  painter.Resources.Min(r => r.OriginX - r.Width / 2.0f));
                    Height = (int)(painter.Resources.Max(r => r.OriginY + r.Height / 2.0f) -
                                   painter.Resources.Min(r => r.OriginY - r.Height / 2.0f));

                    Width  = (int)(Width * 1.4f);
                    Height = (int)(Height * 1.4f);
                }

                if (context != null)
                {
                    if (context.ContainsKey("Width") && context["Width"] is int width)
                    {
                        Width = width;
                    }

                    if (context.ContainsKey("Height") && context["Height"] is int height)
                    {
                        Height = height;
                    }
                }
            }

            var psd = ConvertToPsd(painter, Width, Height);
            var ms  = new MemoryStream();

            psd.Save(ms, Encoding.UTF8);
            return(ms);
        }
Ejemplo n.º 5
0
        private static void Draw(string path, int width, int height)
        {
            var psb     = new PSB(path);
            var painter = new PsbPainter(psb);

            if (width < 0 || height < 0)
            {
                psb.TryGetCanvasSize(out var cw, out var ch);
                if (width < 0)
                {
                    width = cw;
                }

                if (height < 0)
                {
                    height = ch;
                }
            }

            var bmp = painter.Draw(width, height);

            bmp.Save(Path.ChangeExtension(path, ".FreeMote.png"), ImageFormat.Png);
        }
Ejemplo n.º 6
0
        private PsdFile ConvertToPsd(PsbPainter painter, int width, int height)
        {
            PsdFile psd = new PsdFile
            {
                Width      = width,
                Height     = height,
                Resolution = new ResolutionInfo
                {
                    HeightDisplayUnit = ResolutionInfo.Unit.Centimeters,
                    WidthDisplayUnit  = ResolutionInfo.Unit.Centimeters,
                    HResDisplayUnit   = ResolutionInfo.ResUnit.PxPerInch,
                    VResDisplayUnit   = ResolutionInfo.ResUnit.PxPerInch,
                    HDpi = new UFixed16_16(0, 350),
                    VDpi = new UFixed16_16(0, 350)
                },
                ImageCompression = ImageCompression.Rle
            };

            psd.ImageResources.Add(new XmpResource("")
            {
                XmpMetaString = Resources.Xmp
            });
            psd.BaseLayer.SetBitmap(new Bitmap(width, height, PixelFormat.Format32bppArgb),
                                    ImageReplaceOption.KeepCenter, psd.ImageCompression);

            string currentGroup = "";
            Layer  beginSection = null;

            foreach (var resMd in painter.Resources)
            {
                if (resMd.Label.StartsWith(painter.GroupMark))
                {
                    resMd.Label = resMd.Label.Substring(1);
                }

                string name = $"{resMd.Label}-{resMd.Name}";

                var layer = psd.MakeImageLayer(resMd.ToImage(), name, (int)(resMd.OriginX + width / 2f - resMd.Width / 2f),
                                               (int)(resMd.OriginY + height / 2f - resMd.Height / 2f));
                layer.Visible = resMd.Visible;
                if (resMd.Opacity <= 0)
                {
                    layer.Opacity = 0;
                }
                else
                {
                    layer.Opacity = (byte)(resMd.Opacity / 10.0f * 255);
                }

                if (resMd.MotionName != currentGroup)
                {
                    currentGroup = resMd.MotionName;
                    if (beginSection != null)
                    {
                        psd.Layers.Add(beginSection);
                        beginSection = null;
                    }

                    if (!string.IsNullOrEmpty(currentGroup))
                    {
                        beginSection = psd.MakeSectionLayers(currentGroup, out var endLayer, false);
                        psd.Layers.Add(endLayer);
                    }
                }

                psd.Layers.Add(layer);
            }

            if (beginSection != null)
            {
                psd.Layers.Add(beginSection);
            }

            psd.Layers.Add(psd.MakeImageLayer(
                               GenerateMarkText("Generated by FreeMote, [email protected] ", width, 200), "FreeMote", 0, 0));
            return(psd);
        }