コード例 #1
0
 public Byte[] ToBytes(IMAGE32 image)
 {
     using (var processed = _PreProcess(image))
     {
         return((processed ?? image).SaveAsBytes(Encoder));
     }
 }
コード例 #2
0
        /*
         * public static ImageSharp.Formats.IImageFormat GetImageformat(this ImageSharp.IEncoderOptions options)
         * {
         *  HL.IconPro.Lib.Core.IconFormat.Use();
         *
         *  var fmts = ImageSharp.Configuration.Default.ImageFormats;
         *
         *  if (options is ImageSharp.Formats.IPngEncoderOptions) return fmts.OfType<ImageSharp.Formats.PngFormat>().FirstOrDefault();
         *  if (options is ImageSharp.Formats.IBmpEncoderOptions) return fmts.OfType<ImageSharp.Formats.BmpFormat>().FirstOrDefault();
         *  if (options is ImageSharp.Formats.JpegEncoderOptions) return fmts.OfType<ImageSharp.Formats.JpegFormat>().FirstOrDefault();
         *  if (options is HL.IconPro.Lib.Core.IconEncoderOptions) return fmts.OfType<HL.IconPro.Lib.Core.IconFormat>().FirstOrDefault();
         *
         *  throw new NotSupportedException();
         * }*/


        public static Byte[] GetBufferBytes(this IMAGE32 srcImage)
        {
            if (srcImage == null)
            {
                return(null);
            }

            var srcBytes = new Byte[srcImage.Width * srcImage.Height * 4];

            for (int y = 0; y < srcImage.Height; ++y)
            {
                for (int x = 0; x < srcImage.Width; ++x)
                {
                    var pix = srcImage[x, y];

                    var idx = (y * srcImage.Width + x) * 4;

                    srcBytes[idx + 0] = pix.B;
                    srcBytes[idx + 1] = pix.G;
                    srcBytes[idx + 2] = pix.R;
                    srcBytes[idx + 3] = pix.A;
                }
            }

            return(srcBytes);
        }
コード例 #3
0
 public void WriteImage(IMAGE32 image, System.IO.Stream stream)
 {
     using (var processed = _PreProcess(image))
     {
         (processed ?? image).Save(stream, Encoder);
     }
 }
コード例 #4
0
ファイル: Image.Extras.cs プロジェクト: vpenades/UberFactory
        protected override IMAGE32 Evaluate()
        {
            var size = new SixLabors.Primitives.Size(Width, Height);

            var result = new IMAGE32(size.Width, size.Height);

            using (var target = new IMAGE32(size.Width, size.Height))
            {
                var substrate = Epsylon.ImageSharp.Procedural.Processing.Substrate.Create(target, RandomSeed.GetRandomSeedHash(), Palette);

                for (int i = 0; i < Iterations; ++i)
                {
                    this.SetProgressPercent(i * 100 / Iterations);

                    substrate.DrawStep();
                }

                result.Mutate
                (
                    dc =>
                {
                    dc.Fill(Rgba32.White);
                    dc.DrawImage(target, 1);
                }
                );

                return(result);
            }
        }
コード例 #5
0
ファイル: Image.Globals.cs プロジェクト: vpenades/UberFactory
        public void WriteImage(SDK.ExportContext stream, IMAGE32 image, IMAGEENCODER encoder)
        {
            if (image == null)
            {
                return;
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            if (PostProcessing != null)
            {
                foreach (var xform in PostProcessing)
                {
                    image.Mutate(dc => xform(dc));
                }
            }

            encoder?.Invoke(stream, image);
        }
コード例 #6
0
ファイル: Image.Extras.cs プロジェクト: vpenades/UberFactory
        protected override IMAGE32 Evaluate()
        {
            var img = new IMAGE32(this.Width, this.Height);

            img.Mutate(dc => dc.FillCheckers(this.CellWidth, this.CellHeight, new PIXEL32(OddColor), new PIXEL32(EvenColor)));

            return(img);
        }
コード例 #7
0
ファイル: Image.Extras.cs プロジェクト: vpenades/UberFactory
        protected override IMAGE32 Evaluate()
        {
            var img = new IMAGE32(this.Width, this.Height);

            img.Mutate(dc => dc.BackgroundColor(new PIXEL32(Color)));

            return(img);
        }
コード例 #8
0
        public static void Flatten(this IMAGE32 target, IMAGE32 source, int sx, int sy, Func <COLOR, COLOR, Single, COLOR> func, int opacity)
        {
            if (opacity < 0 || opacity > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(opacity));
            }

            if (opacity == 0)
            {
                return;
            }

            float fOpacity = (float)opacity / 100.0f;


            var dx = sx;
            var dy = sy;

            if (dx < 0)
            {
                dx = 0;
            }
            if (dy < 0)
            {
                dy = 0;
            }

            sx = -sx;
            sy = -sy;

            if (sx < 0)
            {
                sx = 0;
            }
            if (sy < 0)
            {
                sy = 0;
            }

            var w = Math.Min(target.Width - dx, source.Width - sx);
            var h = Math.Min(target.Height - dy, source.Height - sy);

            for (int y = 0; y < h; ++y)
            {
                for (int x = 0; x < w; ++x)
                {
                    var d = target[x + dx, y + dy];
                    var s = source[x + sx, y + sy];

                    if (s.A > 0)
                    {
                        d = func(d, s, fOpacity);
                    }

                    target[x + dx, y + dy] = d;
                }
            }
        }
コード例 #9
0
        public static void SetExifPositionOffset(this IMAGE32 image, POINT offset)
        {
            // value should be rational64u

            var x = Rational.FromDouble(offset.X);
            var y = Rational.FromDouble(offset.Y);

            image.MetaData.ExifProfile.SetValue(SixLabors.ImageSharp.MetaData.Profiles.Exif.ExifTag.XPosition, x);
            image.MetaData.ExifProfile.SetValue(SixLabors.ImageSharp.MetaData.Profiles.Exif.ExifTag.YPosition, y);
        }
コード例 #10
0
 public static void MutatePixels(this IMAGE32 image, Func <COLOR, COLOR> pixelfunc)
 {
     for (int y = 0; y < image.Height; ++y)
     {
         for (int x = 0; x < image.Width; ++x)
         {
             image[x, y] = pixelfunc(image[x, y]);
         }
     }
 }
コード例 #11
0
        public static POINT GetExifPositionOffset(this IMAGE32 image)
        {
            // value should be rational64u

            var r = (ushort)image.MetaData.ExifProfile.GetValue(SixLabors.ImageSharp.MetaData.Profiles.Exif.ExifTag.ResolutionUnit).Value;

            // r == 1 pixels
            // r == 2 inch
            // r == 3 cm

            var x = (Rational)image.MetaData.ExifProfile.GetValue(SixLabors.ImageSharp.MetaData.Profiles.Exif.ExifTag.XPosition).Value;
            var y = (Rational)image.MetaData.ExifProfile.GetValue(SixLabors.ImageSharp.MetaData.Profiles.Exif.ExifTag.YPosition).Value;

            return(new POINT((int)x.ToDouble(), (int)y.ToDouble()));
        }
コード例 #12
0
        private IMAGE32 _PreProcess(IMAGE32 original)
        {
            if (_AlphaEncoding == AlphaEncoding.Default)
            {
                return(null);
            }

            var processed = original.Clone();

            if (_AlphaEncoding.HasFlag(AlphaEncoding.EdgePadding))
            {
                processed.Mutate(dc => dc.EdgePaddingAlpha(0));
            }
            if (_AlphaEncoding.HasFlag(AlphaEncoding.Premultiply))
            {
                processed.Mutate(dc => dc.PremultiplyAlpha());
            }

            return(processed);
        }
コード例 #13
0
        public static IMAGE32 RenderText(this SixLabors.Fonts.FontFamily ffamily, string text, float fsize, float padding, COLOR color, TextGraphicsOptions options)
        {
            // http://sixlabors.com/2017/04/08/watermarks/

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            var font     = new SixLabors.Fonts.Font(ffamily, fsize);
            var roptions = new SixLabors.Fonts.RendererOptions(font, 96);
            var size     = SixLabors.Fonts.TextMeasurer.Measure(text, roptions);

            var w   = (int)Math.Ceiling(size.Width + padding * 2);
            var h   = (int)Math.Ceiling(size.Height + padding * 2);
            var img = new IMAGE32(w, h);

            img.Mutate(dc => dc.DrawText(options, text, font, color, new System.Numerics.Vector2(padding, padding)));

            return(img);
        }
コード例 #14
0
        public static Object CreatePreview(this IMAGE32 image, UberFactory.SDK.PreviewContext context)
        {
            if (image == null)
            {
                return(null);
            }

            if (true)
            {
                var sinfo = image.GetSubjectInfo();

                if (sinfo != null)
                {
                    var l0 = sinfo.Center + new Size(3, 0);
                    var l1 = sinfo.Center + new Size(3, 0);
                    image.Mutate(dc => dc.DrawLines(COLOR.Red, 1, l0, l1));

                    l0 = sinfo.Center + new Size(0, 3);
                    l1 = sinfo.Center - new Size(0, 3);
                    image.Mutate(dc => dc.DrawLines(COLOR.Red, 1, l0, l1));

                    if (sinfo.Size.HasValue)
                    {
                        image.Mutate(dc => dc.DrawPolygon(COLOR.Red, 1, sinfo.BoundsFloat.Get4Points()));
                    }
                }
            }

            var date = DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
            var time = DateTime.Now.ToString("hhmmss", System.Globalization.CultureInfo.InvariantCulture);

            var files = context.CreateMemoryFile($"preview-{date}-{time}.png");

            files.WriteStream(s => image.SaveAsPng(s));

            image.Dispose();

            return(files);
        }
コード例 #15
0
 public static double WidthInInches(this IMAGE32 img)
 {
     return((double)img.Width / img.MetaData.HorizontalResolution);
 }
コード例 #16
0
 public static double HeightInInches(this IMAGE32 img)
 {
     return((double)img.Height / img.MetaData.VerticalResolution);
 }
コード例 #17
0
 public void WriteImage(IMAGE32 image, SDK.ExportContext ctx)
 {
     ctx.WriteStream(s => WriteImage(image, s));
 }