Exemple #1
0
        public void UpdatePath()
        {
            var bitmap = new RawBitmap(1024, 1024);

            if (mesh != null)
            {
                if (mesh.uv != null && mesh.uv.Count == mesh.vertices.Count)
                {
                    Parallel.For(0, mesh.triangles.Count, i =>
                    {
                        Triangle t = mesh.triangles[i];

                        Vector2 uv0 = mesh.uv[t.u0];
                        Vector2 uv1 = mesh.uv[t.u1];
                        Vector2 uv2 = mesh.uv[t.u2];

                        Point p  = new Point(uv0.X * 1024, uv0.Y * 1024);
                        Point p2 = new Point(uv1.X * 1024, uv1.Y * 1024);
                        Point p3 = new Point(uv2.X * 1024, uv2.Y * 1024);

                        bitmap.DrawLine((int)p.X, (int)p.Y, (int)p2.X, (int)p2.Y, 0, 255, 255, 255);
                        bitmap.DrawLine((int)p2.X, (int)p2.Y, (int)p3.X, (int)p3.Y, 0, 255, 255, 255);
                        bitmap.DrawLine((int)p3.X, (int)p3.Y, (int)p.X, (int)p.Y, 0, 255, 255, 255);
                    });
                }
            }
            Preview.Source = bitmap.ToImageSource();
        }
Exemple #2
0
        protected static void CreateCharacter(Font f, CharData data, string fontFamily, float fontSize, string ch, FontStyle style)
        {
            using (var ghelper = Graphics.FromImage(fontHelper))
            {
                StringFormat format = StringFormat.GenericTypographic;

                var size = ghelper.MeasureString(ch, f, 0, format);
                data.size     = new Vector2(size.Width, size.Height);
                data.bearing  = f.GetHeight();
                data.style    = style;
                data.fontSize = fontSize;

                if (Math.Ceiling(size.Width) <= 0 || Math.Ceiling(size.Height) <= 0)
                {
                    return;
                }

                using (Bitmap b = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    using (var g = Graphics.FromImage(b))
                    {
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                        g.DrawString(ch, f, WhiteColor, new PointF(0, 0), format);
                    }

                    RawBitmap bit = RawBitmap.FromBitmap(b);
                    data.texture = bit;
                }
            }
        }
Exemple #3
0
        public IRawBitmap Decode(TcbImage image)
        {
            var result     = new RawBitmap(image.Width, image.Height);
            var resultData = result.Data;
            var imageData  = image.Image;
            var pixelCount = image.Width * image.Height;

            int[] palette = null;

            //if (image.Palette.Length > 0x50)
            {
                var palSpan = MemoryMarshal.Cast <byte, int>(image.Palette.AsSpan());
                palette = FilterPalette(palSpan);
            }

            int ConvertPixel(int px)
            {
                // fill the upper 8 bits with the alpha bit with this one cheap hack
                px = ((px >> 7) & ~0xFFFFFF) | (px & 0xFFFFFF);
                // swap red and blue
                px = (px & ~0xFF00FF) | ((px & 0xFF) << 16) | ((px & 0xFF0000) >> 16);
                return(px);
            }

            switch (image.PaletteType)
            {
            case 0x05:
            {
                for (var i = 0; i < pixelCount; i++)
                {
                    var pixel = palette[imageData[i]];
                    resultData[i] = ConvertPixel(pixel);
                }
                break;
            }

            case 0x04:
            {
                var imageIndex = 0;
                for (var i = 0; i < pixelCount / 2; i++)
                {
                    var image0 = imageData[i] & 0xF;
                    var image1 = imageData[i] >> 4;

                    var pixel = palette[image0];
                    resultData[imageIndex++] = ConvertPixel(pixel);
                    pixel = palette[image1];
                    resultData[imageIndex++] = ConvertPixel(pixel);
                }
                break;
            }

            default:
            {
                return(null);
            }
            }

            return(result);
        }
Exemple #4
0
 public static void Clear(RawBitmap dst)
 {
     Parallel.For(0, dst.Image.Length, i =>
     {
         dst.Image[i] = 0;
     });
 }
Exemple #5
0
        private void ExportAsPng()
        {
            var dialog = new Microsoft.Win32.SaveFileDialog();

            dialog.Filter          = "PNG|*.png";
            dialog.CheckFileExists = false;
            dialog.CheckPathExists = true;

            if (dialog.ShowDialog() == true)
            {
                string path = dialog.FileName;
                byte[] bits = Node.GetPreview(Node.Width, Node.Height);

                Task.Run(() =>
                {
                    RawBitmap bmp = null;
                    if (bits != null)
                    {
                        bmp     = new RawBitmap(Node.Width, Node.Height, bits);
                        var src = bmp.ToImageSource();
                        PngBitmapEncoder encoder = new PngBitmapEncoder();
                        BitmapFrame frame        = BitmapFrame.Create(src);
                        encoder.Frames.Add(frame);

                        using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
                        {
                            encoder.Save(fs);
                        }
                    }
                });
            }
        }
Exemple #6
0
        void Process()
        {
            if (brush == null)
            {
                return;
            }

            CreateBufferIfNeeded();

            buffer.Bind();
            GLInterfaces.PixelFormat format = GLInterfaces.PixelFormat.Bgra;

            if (brush.BPP == 24)
            {
                format = GLInterfaces.PixelFormat.Bgr;
            }
            else if (brush.BPP == 16)
            {
                format = GLInterfaces.PixelFormat.Rg;
            }
            else if (brush.BPP == 8)
            {
                format = GLInterfaces.PixelFormat.Red;
            }

            buffer.SetData(brush.Image, format, width, height);
            GLTextuer2D.Unbind();

            brush       = null;
            Output.Data = buffer;
            TriggerTextureChange();
        }
Exemple #7
0
        static RawBitmap desaturate(BitmapSource bitmap)
        {
            var raw = new RawBitmap(bitmap);
            var hsl = Hsla32.FromPbra32(raw.Data, raw.Width).Desaturate(0.87F, 1e-2F);

            return(raw.CloneWithData(Rgba32.FromHsl(hsl)));
        }
Exemple #8
0
 public CharData(float fSize, Vector2 s, float b, RawBitmap tex, FontStyle styl)
 {
     fontSize = fSize;
     size     = s;
     bearing  = b;
     texture  = tex;
     style    = styl;
 }
Exemple #9
0
        public override void Dispose()
        {
            base.Dispose();

            if (brush != null)
            {
                brush = null;
            }
        }
Exemple #10
0
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     screenScale = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice.M11;
     hueBitmap   = new RawBitmap((int)GHue.ActualWidth, (int)GHue.ActualHeight);
     svBitmap    = new RawBitmap((int)GSatVal.ActualWidth, (int)GSatVal.ActualHeight);
     RedrawHue();
     RedrawSatVal();
     UpdatePreview();
     UpdateTextFields();
     UpdateSliders();
     UpdateSliders();
 }
        private static async Task <BitmapImage> ToBitmapSource(RawBitmap rawBitmap)
        {
            var raw     = rawBitmap.Data.ToArray();
            var width   = rawBitmap.Width;
            var height  = rawBitmap.Height;
            var channel = rawBitmap.Channel;
            var data    = new byte[width * height * 4];

            unsafe
            {
                fixed(byte *pRaw = &raw[0])
                fixed(byte *dst = &data[0])
                {
                    var src = pRaw;

                    for (var y = 0; y < height; y++)
                    {
                        var index = y * width * 4;
                        for (var x = 0; x < width; x++)
                        {
                            dst[index]     = src[2];
                            dst[index + 1] = src[1];
                            dst[index + 2] = src[0];
                            index         += 4;
                            src           += channel;
                        }
                    }
                }
            }

            var writeableBitmap = new WriteableBitmap((int)width, (int)height);

            using (var imras = new InMemoryRandomAccessStream())
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, imras);

                encoder.SetPixelData(BitmapPixelFormat.Rgba8,
                                     BitmapAlphaMode.Ignore,
                                     (uint)writeableBitmap.PixelWidth,
                                     (uint)writeableBitmap.PixelHeight,
                                     96.0,
                                     96.0,
                                     data);

                await encoder.FlushAsync();

                var bitmapImage = new BitmapImage();
                bitmapImage.SetSource(imras);

                return(bitmapImage);
            }
        }
Exemple #12
0
        public UILevels(RawBitmap fromBitmap, object owner, PropertyInfo p)
        {
            InitializeComponent();
            mode          = LevelMode.RGB;
            property      = p;
            propertyOwner = owner;
            range         = (MultiRange)p.GetValue(owner);

            fromBit = fromBitmap;
            MultiSlider.Set(range.min[0], range.mid[0], range.max[0]);

            inputFromUser = false;
        }
Exemple #13
0
        public static Bitmap ToBitmap(this RawBitmap b)
        {
            Bitmap map = null;

            unsafe
            {
                fixed(byte *r_ptr = &b.Image[0])
                {
                    IntPtr ptr = new IntPtr(r_ptr);

                    map = new Bitmap(b.Width, b.Height, 4 * b.Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, ptr);
                }
            }
            return(map);
        }
Exemple #14
0
        public RawBitmap Snip(RawBitmap bitmap, Rectangle rect)
        {
            var target = new RawBitmap(rect.Width, rect.Height);

            using (var sourceAdapter = _gdiFactory.CreateAdapter(bitmap))
                using (var targetAdapter = _gdiFactory.CreateAdapter(target))
                    using (var targetGraphics = _gdiFactory.CreateGraphics(targetAdapter.Bitmap))
                    {
                        targetGraphics.DrawImage(
                            sourceAdapter.Bitmap,
                            new Rectangle(0, 0, rect.Width, rect.Height),
                            rect,
                            GraphicsUnit.Pixel);
                    }

            return(target);
        }
Exemple #15
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (fromBit != null)
            {
                Histogram.GenerateHistograph(fromBit);
                fromBit = null;
            }

            Channels.SelectedIndex = 0;
            inputFromUser          = false;

            Task.Delay(10).ContinueWith(t =>
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    Histogram.BuildHistogramImage();
                });
            });
        }
Exemple #16
0
        public void GenerateHistograph(RawBitmap fromBitmap)
        {
            if (fromBitmap == null)
            {
                return;
            }

            int[,] hist = new int[3, 256];

            if (ctk != null)
            {
                ctk.Cancel();
            }

            ctk = new CancellationTokenSource();

            Task.Run(() =>
            {
                for (int y = 0; y < fromBitmap.Height; y++)
                {
                    byte r = 0, g = 0, b = 0, a = 0;
                    for (int x = 0; x < fromBitmap.Width; x++)
                    {
                        fromBitmap.GetPixel(x, y, out r, out g, out b, out a);

                        hist[0, r]++;
                        hist[1, g]++;
                        hist[2, b]++;
                    }
                }
            }, ctk.Token).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    return;
                }

                App.Current.Dispatcher.Invoke(() =>
                {
                    Histograph = hist;
                });
            });
        }
        private RawBitmap CropImage(RawBitmap bitmap)
        {
            if (Args.Options.ContainsKey("+crop_ddr"))
            {
                if (bitmap.Width == 512 && bitmap.Height == 256)
                {
                    bitmap = _graphicDsp.Snip(bitmap, new Rectangle(0, 0, 320, 200));
                }
                else if (bitmap.Width == 256 && bitmap.Height == 128)
                {
                    bitmap = _graphicDsp.Snip(bitmap, new Rectangle(0, 0, 256, 80));
                }
                else if (bitmap.Width == 1024 && bitmap.Height == 512)
                {
                    bitmap = _graphicDsp.Snip(bitmap, new Rectangle(0, 0, 640, 480));
                }
            }

            return(bitmap);
        }
Exemple #18
0
        public RawBitmap Read(Stream stream)
        {
            using (var source = new Bitmap(stream))
            {
                var result = new RawBitmap
                {
                    Width  = source.Width,
                    Height = source.Height,
                    Data   = new int[source.Width * source.Height]
                };

                using (var adapter = _gdiFactory.CreateAdapter(result))
                    using (var g = _gdiFactory.CreateGraphics(adapter.Bitmap))
                    {
                        g.DrawImage(source, 0, 0);
                    }

                return(result);
            }
        }
Exemple #19
0
        public void OnUpdate(object obj)
        {
            if (!inputFromUser)
            {
                Nodes.Node n = obj as Nodes.Node;

                if (n != null)
                {
                    byte[] result = n.GetPreview(512, 512);

                    if (result != null)
                    {
                        fromBit = new RawBitmap(512, 512, result);

                        Histogram.GenerateHistograph(fromBit);
                    }
                }
            }

            inputFromUser = false;
        }
Exemple #20
0
        void UpdatePointsForResize()
        {
            if (!inited)
            {
                return;
            }

            display = new RawBitmap((int)CurveView.ActualWidth, (int)CurveView.ActualHeight);

            for (int i = 0; i < 3; i++)
            {
                var pts = Points[i];

                foreach (CurvePoint cp in pts)
                {
                    cp.UpdateViewPosition();
                    cp.Relayout();
                }
            }

            UpdatePath();
        }
Exemple #21
0
 public IGdiAdapter CreateAdapter(RawBitmap bitmap) =>
 new GdiAdapter(bitmap.Data, bitmap.Width, bitmap.Height, bitmap.Width * 4);
Exemple #22
0
        public void BuildHistogramImage()
        {
            if (!isLoaded)
            {
                return;
            }

            if (ActualHeight == 0 || ActualWidth == 0)
            {
                return;
            }

            RawBitmap bmp = new RawBitmap((int)ActualWidth, (int)ActualHeight);

            if (ctk != null)
            {
                ctk.Cancel();
            }

            ctk = new CancellationTokenSource();

            Task.Run(() =>
            {
                if (histograph != null && maxValue != null)
                {
                    if (mode == LevelMode.RGB)
                    {
                        for (int g = 0; g < 3; g++)
                        {
                            if (maxValue[g] != 0)
                            {
                                //gather initial points
                                List <Vector2> points = new List <Vector2>();

                                for (int x = 0; x < 256; x++)
                                {
                                    int t   = histograph[g, x];
                                    float w = (float)x / 255.0f;
                                    int ax  = (int)Math.Floor(w * ActualWidth);

                                    float p = (float)t / (float)maxValue[g];
                                    int may = (int)Math.Min((int)ActualHeight, Math.Floor(p * (int)ActualHeight));

                                    points.Add(new Vector2(ax, may));
                                }

                                List <Vector2> spline = CatmullRomSpline.GetSpline(points, 8);

                                Parallel.For(0, spline.Count, i =>
                                {
                                    Vector2 p = spline[i];

                                    for (int k = 0; k < p.Y; k++)
                                    {
                                        bmp.SetPixel((int)p.X, bmp.Height - 1 - k, 175, 175, 175, 255);
                                    }
                                });
                            }
                        }
                    }
                    else
                    {
                        int g = (int)mode;

                        if (maxValue[g] != 0)
                        {
                            List <Vector2> points = new List <Vector2>();

                            //gather initial points
                            for (int x = 0; x < 256; x++)
                            {
                                int t   = histograph[g, x];
                                float w = (float)x / 255.0f;
                                int ax  = (int)Math.Floor(w * ActualWidth);

                                float p = (float)t / (float)maxValue[g];
                                int may = (int)Math.Min(ActualHeight, Math.Floor(p * ActualHeight));

                                points.Add(new Vector2(ax, may));
                            }

                            List <Vector2> spline = CatmullRomSpline.GetSpline(points, 8);

                            Parallel.For(0, spline.Count, i =>
                            {
                                Vector2 p = spline[i];

                                for (int k = 0; k < p.Y; k++)
                                {
                                    bmp.SetPixel((int)p.X, bmp.Height - 1 - k, 175, 175, 175, 255);
                                }
                            });
                        }
                    }
                }
            }, ctk.Token).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    return;
                }

                if (bmp == null)
                {
                    return;
                }

                Application.Current.Dispatcher.Invoke(() =>
                {
                    PreviewView.Source = bmp.ToImageSource();
                });
            });
        }
Exemple #23
0
        public Bitmap ProcessImage(Image inputImage)
        {
            //Image inputImage = new Bitmap(iImage, (int)(iImage.Width * 0.5), (int)(iImage.Height * 0.5));

            Bitmap origin  = new Bitmap(inputImage);
            Bitmap blurred = new Bitmap(inputImage.Width, inputImage.Height);

            using (RawBitmap src = new RawBitmap(origin))
            {
                using (RawBitmap dest = new RawBitmap(blurred))
                {
                    int pixelCount = src.Width * src.Height;
                    //Stopwatch sw = new Stopwatch();
                    //sw.Start();
                    int[] b = new int[pixelCount];
                    int[] g = new int[pixelCount];
                    int[] r = new int[pixelCount];

                    int[] b2 = new int[pixelCount];
                    int[] g2 = new int[pixelCount];
                    int[] r2 = new int[pixelCount];
                    //sw.Stop();
                    //t1 = sw.ElapsedMilliseconds;

                    int offset = src.GetOffset();
                    int index  = 0;
                    unsafe
                    {
                        //sw.Reset();
                        //sw.Start();

                        byte *ptr = src.Begin;
                        for (int i = 0; i < src.Height; i++)
                        {
                            for (int j = 0; j < src.Width; j++)
                            {
                                b[index] = *ptr;
                                ptr++;
                                g[index] = *ptr;
                                ptr++;
                                r[index] = *ptr;
                                ptr++;

                                ++index;
                            }
                            ptr += offset;
                        }

                        //sw.Stop();
                        //t2 = sw.ElapsedMilliseconds;

                        int bsum;
                        int gsum;
                        int rsum;
                        int read;
                        int start = 0;
                        index = 0;

                        //sw.Reset();
                        //sw.Start();

                        if (_blurType != BlurType.VerticalOnly)
                        {
                            for (int i = 0; i < src.Height; i++)
                            {
                                for (int j = 0; j < src.Width; j++)
                                {
                                    bsum = gsum = rsum = 0;
                                    read = index - _radius;

                                    for (int z = 0; z < _kernel.Length; z++)
                                    {
                                        //if (read >= start && read < start + src.Width)
                                        //{
                                        //    bsum += _multable[z, b[read]];
                                        //    gsum += _multable[z, g[read]];
                                        //    rsum += _multable[z, r[read]];
                                        //    sum += _kernel[z];
                                        //}

                                        if (read < start)
                                        {
                                            bsum += _multable[z, b[start]];
                                            gsum += _multable[z, g[start]];
                                            rsum += _multable[z, r[start]];
                                        }
                                        else if (read > start + src.Width - 1)
                                        {
                                            int idx = start + src.Width - 1;
                                            bsum += _multable[z, b[idx]];
                                            gsum += _multable[z, g[idx]];
                                            rsum += _multable[z, r[idx]];
                                        }
                                        else
                                        {
                                            bsum += _multable[z, b[read]];
                                            gsum += _multable[z, g[read]];
                                            rsum += _multable[z, r[read]];
                                        }
                                        ++read;
                                    }

                                    //b2[index] = (bsum / sum);
                                    //g2[index] = (gsum / sum);
                                    //r2[index] = (rsum / sum);

                                    b2[index] = (bsum / _kernelSum);
                                    g2[index] = (gsum / _kernelSum);
                                    r2[index] = (rsum / _kernelSum);

                                    if (_blurType == BlurType.HorizontalOnly)
                                    {
                                        //byte* pcell = dest[j, i];
                                        //*pcell = (byte)(bsum / sum);
                                        //pcell++;
                                        //*pcell = (byte)(gsum / sum);
                                        //pcell++;
                                        //*pcell = (byte)(rsum / sum);
                                        //pcell++;

                                        byte *pcell = dest[j, i];
                                        *     pcell = (byte)(bsum / _kernelSum);
                                        pcell++;
                                        *pcell = (byte)(gsum / _kernelSum);
                                        pcell++;
                                        *pcell = (byte)(rsum / _kernelSum);
                                        pcell++;
                                    }

                                    ++index;
                                }
                                start += src.Width;
                            }
                        }
                        if (_blurType == BlurType.HorizontalOnly)
                        {
                            return(blurred);
                        }

                        //sw.Stop();
                        //t3 = sw.ElapsedMilliseconds;

                        //sw.Reset();
                        //sw.Start();

                        int tempy;
                        for (int i = 0; i < src.Height; i++)
                        {
                            int y = i - _radius;
                            start = y * src.Width;
                            for (int j = 0; j < src.Width; j++)
                            {
                                bsum  = gsum = rsum = 0;
                                read  = start + j;
                                tempy = y;
                                for (int z = 0; z < _kernel.Length; z++)
                                {
                                    //if (tempy >= 0 && tempy < src.Height)
                                    //{
                                    //    if (_blurType == BlurType.VerticalOnly)
                                    //    {
                                    //        bsum += _multable[z, b[read]];
                                    //        gsum += _multable[z, g[read]];
                                    //        rsum += _multable[z, r[read]];
                                    //    }
                                    //    else
                                    //    {
                                    //        bsum += _multable[z, b2[read]];
                                    //        gsum += _multable[z, g2[read]];
                                    //        rsum += _multable[z, r2[read]];
                                    //    }
                                    //    sum += _kernel[z];
                                    //}

                                    if (_blurType == BlurType.VerticalOnly)
                                    {
                                        if (tempy < 0)
                                        {
                                            bsum += _multable[z, b[j]];
                                            gsum += _multable[z, g[j]];
                                            rsum += _multable[z, r[j]];
                                        }
                                        else if (tempy > src.Height - 1)
                                        {
                                            int idx = pixelCount - (src.Width - j);
                                            bsum += _multable[z, b[idx]];
                                            gsum += _multable[z, g[idx]];
                                            rsum += _multable[z, r[idx]];
                                        }
                                        else
                                        {
                                            bsum += _multable[z, b[read]];
                                            gsum += _multable[z, g[read]];
                                            rsum += _multable[z, r[read]];
                                        }
                                    }
                                    else
                                    {
                                        if (tempy < 0)
                                        {
                                            bsum += _multable[z, b2[j]];
                                            gsum += _multable[z, g2[j]];
                                            rsum += _multable[z, r2[j]];
                                        }
                                        else if (tempy > src.Height - 1)
                                        {
                                            int idx = pixelCount - (src.Width - j);
                                            bsum += _multable[z, b2[idx]];
                                            gsum += _multable[z, g2[idx]];
                                            rsum += _multable[z, r2[idx]];
                                        }
                                        else
                                        {
                                            bsum += _multable[z, b2[read]];
                                            gsum += _multable[z, g2[read]];
                                            rsum += _multable[z, r2[read]];
                                        }
                                    }


                                    read += src.Width;
                                    ++tempy;
                                }

                                byte *pcell = dest[j, i];

                                //pcell[0] = (byte)(bsum / sum);
                                //pcell[1] = (byte)(gsum / sum);
                                //pcell[2] = (byte)(rsum / sum);

                                pcell[0] = (byte)(bsum / _kernelSum);
                                pcell[1] = (byte)(gsum / _kernelSum);
                                pcell[2] = (byte)(rsum / _kernelSum);
                            }
                        }
                        //sw.Stop();
                        //t4 = sw.ElapsedMilliseconds;
                    }
                }
            }

            return(blurred);
        }
        /// <summary>
        /// Возвращает размер области, необходимой для вывода текста.
        /// </summary>
        /// <param name="gfx">Graphics.</param>
        /// <param name="font">Шрифт.</param>
        /// <param name="str">Строка.</param>
        /// <returns>Размер области, необходимой для вывода текста.</returns>
        public static Size CalcSize(this string str, Graphics gfx, Font font)
        {
            var fSize     = gfx.MeasureString(str, font);
            var startSize = new Size((int)fSize.Width * 2, (int)fSize.Height * 2);

            using (var bmp = new Bitmap(startSize.Width, startSize.Height))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.Clear(Color.Black);

                    var pt = new PointF(
                        (bmp.Width - fSize.Width) / 2f,
                        (bmp.Height - fSize.Height) / 2f);
                    g.DrawString(str, font, Brushes.White, pt);
                }

                int left   = 0;
                int top    = 0;
                int right  = bmp.Width;
                int bottom = bmp.Height;

                using (var raw = new RawBitmap(bmp))
                {
                    for (int i = 0; i < raw.Width; i++)
                    {
                        for (int j = 0; j < raw.Height; j++)
                        {
                            if (raw[i, j].R != 0)
                            {
                                left = i;
                                goto label0;
                            }
                        }
                    }

label0:
                    for (int i = raw.Width - 1; i >= 0; i--)
                    {
                        for (int j = 0; j < raw.Height; j++)
                        {
                            if (raw[i, j].R != 0)
                            {
                                right = i;
                                goto label1;
                            }
                        }
                    }

label1:
                    for (int j = 0; j < raw.Height; j++)
                    {
                        for (int i = 0; i < raw.Width; i++)
                        {
                            if (raw[i, j].R != 0)
                            {
                                top = j;
                                goto label2;
                            }
                        }
                    }

label2:
                    for (int j = raw.Height - 1; j >= 0; j--)
                    {
                        for (int i = 0; i < raw.Width; i++)
                        {
                            if (raw[i, j].R != 0)
                            {
                                bottom = j;
                                goto label3;
                            }
                        }
                    }

label3:
                    int width = right - left;
                    int height = bottom - top;

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

                    return(new Size(width, height));
                }
            }
        }
Exemple #25
0
        private void LoadBitmap()
        {
            try
            {
                if (archive != null && !string.IsNullOrEmpty(relativePath) && Resource)
                {
                    archive.Open();
                    List <MTGArchive.ArchiveFile> files = archive.GetAvailableFiles();

                    var m = files.Find(f => f.path.Equals(relativePath));
                    if (m != null)
                    {
                        using (Stream ms = m.GetStream())
                            using (Bitmap bmp = (Bitmap)Bitmap.FromStream(ms))
                            {
                                if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                                {
                                    width  = bmp.Width;
                                    height = bmp.Height;
                                    brush  = RawBitmap.FromBitmap(bmp);
                                    archive.Close();
                                    return;
                                }
                            }
                    }

                    archive.Close();
                }

                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    using (Bitmap bmp = (Bitmap)Bitmap.FromFile(path))
                    {
                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = RawBitmap.FromBitmap(bmp);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(relativePath) && ParentGraph != null && !string.IsNullOrEmpty(ParentGraph.CWD) && File.Exists(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                {
                    using (Bitmap bmp = (Bitmap)Bitmap.FromFile(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                    {
                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = RawBitmap.FromBitmap(bmp);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemple #26
0
        protected override void Init()
        {
            base.Init();
            GlobalOffset  = new Point(0, 0);
            TargetAppName = "Epic Battle Fantasy 5";

            // TODO: add firsttime;

            // 63 x 49;
            // x = 1        1250    1
            // y = 1    25  699     1

            StealMore = false;
            firsttime = false;
            escPoint  = new Point(540, 560);



#if true
            // init battle: (375, 249, 437, 298);
            AddMove(406, 274);
            AddClick(0U);
            AddDelay(2200);

            // move to "Skill" button: (299, 505, 433, 541);
            AddMove(366, 523);
            AddClick(() => { return(firsttime); }, 0U);

            // move to "Recently Used" area, or move to scan skill;
            AddMove(() =>
            {
                if (firsttime)
                {
                    // TODO: scan skill;
                    return(new Point(0, 0));
                }
                else
                {
                    return(new Point(490, 600));
                }
            });
            AddClick(0U);

            // move to foe 1: ();
            AddMove(1018, 156);
            AddClick();
            AddDelay(1900);

            // move to "Limit" button: (299, 429, 433, 465);

            // move to "Recently Used" area, or move to scan skill;
            AddMove(() =>
            {
                if (StealMore && firsttime)
                {
                    // TODO: scan skill;
                    return(new Point(0, 0));
                }
                else
                {
                    return(new Point(490, 600));
                }
            });
            AddClick(() => { return(StealMore); }, 0U);

            // move to foe 2: ();
            AddMove(1068, 331);
            AddClick(() => { return(StealMore); });
            AddDelay(() =>
            {
                if (StealMore)
                {
                    return(1900);
                }
                return(0);
            });

            // move to "Tactics" button: (299, 467, 433, 503);
            AddMove(366, 485);
            AddClick(0U);

            // move to "Escape": ();
            AddMove(() =>
            {
                if (firsttime)
                {
                    // TODO: scan Ecscape;
                    // 446, 339, 580, 595 (135 x 257);
                    escPoint = new Point(0, 0);
                }
                return(escPoint);
            });
            AddClick(0U);

            // move to party: ();
            AddMove(252, 256);
            AddClick(0U);
            AddDelay(4300);

            //AddCustom(() => { Pause(); });
            //AddCustom(() =>
            //{
            //// failsafe;
            //if (firsttime) {
            //    firsttime = false;
            //    Remove(3);
            //    Remove(3);
            //    Remove(3);
            //    Remove(Sequence.Count - 1);
            //}
            //});
#else
            RawBitmap rbm = new RawBitmap(466, 399, 135, 257);

            // this should spam cursor on the four corner;
            int x1 = 299, y1 = 467;
            int x2 = 433, y2 = 503;
            //AddMove(() =>
            //{
            //    if (firsttime)
            //    {
            //        firsttime = false;
            //        return new Point(x1, y1);
            //    }
            //    else
            //    {
            //        firsttime = true;
            //        return new Point(0, 0);
            //    }
            //});
            AddMove(x1, y1);
            AddDelay(500);
            AddMove(x2, y1);
            AddDelay(500);
            AddMove(x2, y2);
            AddDelay(500);
            AddMove(x1, y2);
            AddDelay(500);


            Bitmap stealitem;
#endif

            //firsttime = true;
        }
Exemple #27
0
        public override void ExportSync(string path)
        {
            string name = graph.Name;

            foreach (var s in graph.OutputNodes)
            {
                Node n = null;

                if (graph.NodeLookup.TryGetValue(s, out n))
                {
                    if (n is OutputNode)
                    {
                        OutputNode on = n as OutputNode;

                        if (on.OutType == OutputType.basecolor)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_color.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.normal)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_normal.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.metallic)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_metallic.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.roughness)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_roughness.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.occlusion)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_occlusion.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.height)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_height.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.thickness)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_thickness.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.emission)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_emission.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                    }
                }
            }
        }
Exemple #28
0
        public override Task Export(string path)
        {
            int i = 0;

            string name = graph.Name;

            Queue <Task> runningTasks = new Queue <Task>();

            foreach (var s in graph.OutputNodes)
            {
                Node n = null;

                if (graph.NodeLookup.TryGetValue(s, out n))
                {
                    if (n is OutputNode)
                    {
                        OutputNode on = n as OutputNode;

                        if (on.OutType == OutputType.basecolor)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_color.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.normal)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_normal.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.metallic)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_metallic.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.roughness)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_roughness.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.occlusion)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_occlusion.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.height)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_height.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.thickness)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_thickness.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                    }
                }
            }

            int totalTasks = runningTasks.Count;

            ProgressChanged(0, totalTasks, 0);

            return(Task.Run(async() =>
            {
                while (runningTasks.Count > 0)
                {
                    i = totalTasks - runningTasks.Count + 1;

                    Task t = runningTasks.Dequeue();

                    ProgressChanged(i, totalTasks, (float)i / (float)totalTasks);

                    if (!t.IsCompleted && !t.IsCanceled)
                    {
                        await t;
                    }
                }
            }));
        }
Exemple #29
0
        protected void UpdatePath()
        {
            List <MathHelpers.Point> normals = new List <MathHelpers.Point>();

            if (display == null)
            {
                display = new RawBitmap((int)CurveView.ActualWidth, (int)CurveView.ActualHeight);
            }

            Utils.Clear(display);

            if (ShowAllCurves)
            {
                for (int i = 0; i < 4; ++i)
                {
                    switch (i)
                    {
                    case 0:
                        normals = RenderPath(Points[i], display);
                        break;

                    case 1:
                        normals = RenderPath(Points[i], display, 255, 0, 0);
                        break;

                    case 2:
                        normals = RenderPath(Points[i], display, 0, 255, 0);
                        break;

                    case 3:
                        normals = RenderPath(Points[i], display, 0, 45, 255);
                        break;
                    }

                    Normalized[i] = normals;
                }
            }
            else
            {
                switch (mode)
                {
                case CurveMode.RGB:
                    normals = RenderPath(Points[0], display);
                    break;

                case CurveMode.Red:
                    normals = RenderPath(Points[1], display, 255, 0, 0);
                    break;

                case CurveMode.Green:
                    normals = RenderPath(Points[2], display, 0, 255, 0);
                    break;

                case CurveMode.Blue:
                    normals = RenderPath(Points[3], display, 0, 45, 255);
                    break;
                }

                Normalized[(int)mode] = normals;
            }

            CurvePixels.Source = display.ToImageSource();
        }
Exemple #30
0
        /// <summary>
        /// Renderes the path to the buffer
        /// and returns the normalized curve data
        /// the path should be a normalized set of points from 0 - 1
        /// </summary>
        /// <param name="path"></param>
        /// <param name="buffer"></param>
        /// <returns></returns>
        protected List <MathHelpers.Point> RenderPath(List <CurvePoint> path, RawBitmap buffer, byte r = 175, byte g = 175, byte b = 175)
        {
            List <MathHelpers.Point> points     = new List <MathHelpers.Point>();
            List <MathHelpers.Point> curve      = new List <MathHelpers.Point>();
            List <MathHelpers.Point> normalized = new List <MathHelpers.Point>();
            double width  = CurveView.ActualWidth;
            double height = CurveView.ActualHeight - 1;

            foreach (CurvePoint p in path)
            {
                MathHelpers.Point n = p.Normalized;
                points.Add(new MathHelpers.Point(n.X * width, n.Y * height));
            }

            Sort(points);

            //make sure we have x points on edges
            if (points.Count >= 2)
            {
                MathHelpers.Point f = points[0];

                if (f.X > 0)
                {
                    points.Insert(0, new MathHelpers.Point(0, f.Y));
                }

                MathHelpers.Point l = points[points.Count - 1];

                if (l.X < width)
                {
                    points.Add(new MathHelpers.Point(width, l.Y));
                }
            }

            double[] sd = Curves.SecondDerivative(points.ToArray());

            for (int i = 0; i < points.Count - 1; ++i)
            {
                MathHelpers.Point cur  = points[i];
                MathHelpers.Point next = points[i + 1];

                for (double x = cur.X; x < next.X; ++x)
                {
                    double t = (double)(x - cur.X) / (next.X - cur.X);

                    double a  = 1 - t;
                    double bt = t;
                    double h  = next.X - cur.X;

                    double y = a * cur.Y + bt * next.Y + (h * h / 6) * ((a * a * a - a) * sd[i] + (bt * bt * bt - bt) * sd[i + 1]);


                    if (y < 0)
                    {
                        y = 0;
                    }
                    if (y > height - 1)
                    {
                        y = height - 1;
                    }

                    curve.Add(new MathHelpers.Point(x, y));
                    normalized.Add(new MathHelpers.Point(x / width, y / height));
                }
            }

            MathHelpers.Point lp = points[points.Count - 1];
            curve.Add(lp);
            normalized.Add(new MathHelpers.Point(lp.X / width, lp.Y / height));

            Parallel.For(0, curve.Count - 1, i =>
            {
                MathHelpers.Point p1 = curve[i];
                MathHelpers.Point p2 = curve[i + 1];
                buffer.DrawLine((int)p1.X, (int)p1.Y, (int)p2.X, (int)p2.Y, r, g, b, 255);
            });

            return(normalized);
        }