コード例 #1
0
 public JuliaRationalPlot(Control4NonLineairSystems c, int dt, DirectBitmap m) : this(c, dt)
 {
     UseOwnBitmap = true;
     map          = m;
     ResetMaxSquared();
 }
コード例 #2
0
        public void neighborhoodOperationHSV(int[] mask, DirectBitmap directBitmapPre, DirectBitmap directBitmapPost, KernelMethod _method = KernelMethod.NoBorders, SccalingMethod sccalingMethod = SccalingMethod.Cut, Boolean directionEdge = false)
        {
            int    maskSize         = (int)Math.Sqrt(mask.Length);
            int    calculatedPixel  = 0;
            HSVBit calculatedHSVBit = new HSVBit();
            int    maskSum          = mask.Min() < 0 ? 1 : mask.Sum();
            int    maskSumInner     = 0;

            List <float> angles = new List <float>();

            int[] bitMapToScale = null;

            int minPixel = directBitmapPre.getMin();
            int maxPixel = directBitmapPre.getMax();

            int maskValue;

            int xo;
            int yo;

            int lowerXOverlap  = 0;
            int higherXOverlap = 0;
            int lowerYOverlap  = 0;
            int higherYOverlap = 0;

            int yiInner = 0;

            int calculatedPixelIndexX = 0;
            int calculatedPixelIndexY = 0;

            Color  helpColor;
            HSVBit helperhSVBit;

            int overlap     = 0; // = maskSize / 2;
            int maskOverlap = maskSize / 2;

            switch (_method)
            {
            case KernelMethod.NoBorders:
                overlap = maskSize / 2;
                break;

            case KernelMethod.CloneBorder:
                overlap = 0;
                break;

            case KernelMethod.UseExisting:
                overlap = 0;
                break;
            }



            //Iterate through image
            for (int x = overlap; x < directBitmapPre.Width - overlap; ++x)
            {
                for (int y = overlap; y < directBitmapPre.Height - overlap; ++y)
                {
                    //Iterate through image

                    //Iterate through mask
                    for (int xi = 0; xi < maskSize; xi++)
                    {
                        for (int yi = 0; yi < maskSize; yi++)
                        {
                            maskValue = mask[xi + (yi * maskSize)];
                            xo        = x + xi - maskOverlap;
                            yo        = y + yi - maskOverlap;

                            calculatedPixelIndexX = x + xi - maskOverlap;
                            calculatedPixelIndexY = y + yi - maskOverlap;

                            if ((x == 0 && y == 0) || (x == directBitmapPre.Width && y == directBitmapPre.Height))
                            {
                                higherXOverlap = 0;
                            }


                            if (_method == KernelMethod.UseExisting && (calculatedPixelIndexX < 0 || calculatedPixelIndexY < 0 || calculatedPixelIndexX >= directBitmapPre.Width || calculatedPixelIndexY >= directBitmapPre.Height))
                            {
                                continue;
                            }

                            if (_method == KernelMethod.CloneBorder && (calculatedPixelIndexX < 0 || calculatedPixelIndexY < 0 || calculatedPixelIndexX >= directBitmapPre.Width || calculatedPixelIndexY >= directBitmapPre.Height))
                            {
                                var cloneIndexValue = mask[xi + (yi * maskSize)];



                                for (int i = 0; i < cloneIndexValue; i++)
                                {
                                    angles.Add(directBitmapPre.GetPixelHSV(x, y).HUE);
                                }

                                calculatedHSVBit.value += (directBitmapPre.GetPixelHSV(xi, yi).saturation *cloneIndexValue);
                                continue;
                            }

                            var cloneIndexValueMain = mask[xi + (yi * maskSize)];
                            maskSumInner += cloneIndexValueMain;


                            for (int i = 0; i < cloneIndexValueMain; i++)
                            {
                                angles.Add(directBitmapPre.GetPixelHSV(calculatedPixelIndexX, calculatedPixelIndexY).HUE);
                            }

                            //calculatedHSVBit.HUE += (directBitmapPre.GetPixelHSV(x, y).HUE * cloneIndexValueMain);
                            calculatedHSVBit.saturation += (directBitmapPre.GetPixelHSV(calculatedPixelIndexX, calculatedPixelIndexY).saturation *cloneIndexValueMain);
                            calculatedHSVBit.value      += (directBitmapPre.GetPixelHSV(calculatedPixelIndexX, calculatedPixelIndexY).value *cloneIndexValueMain);
                        }
                    }

                    if (_method == KernelMethod.UseExisting)
                    {
                        calculatedHSVBit.HUE        = this.MeanAngle(angles.ToArray());
                        calculatedHSVBit.saturation = maskSum == 1 ? calculatedHSVBit.saturation : calculatedHSVBit.saturation / maskSumInner;
                        calculatedHSVBit.value      = maskSum == 1 ? calculatedHSVBit.value : calculatedHSVBit.value / maskSumInner;
                        //calculatedPixel = maskSum == 1 ? calculatedPixel : calculatedPixel / maskSumInner;
                    }
                    else
                    {
                        var bit = directBitmapPost.GetPixelHSV(x, y);
                        // calculatedPixel /= maskSum;
                        calculatedHSVBit.HUE        = this.MeanAngle(angles.ToArray());
                        calculatedHSVBit.saturation = maskSum == 1 ? calculatedHSVBit.saturation : calculatedHSVBit.saturation / maskSumInner;
                        calculatedHSVBit.value      = maskSum == 1 ? calculatedHSVBit.value : calculatedHSVBit.value / maskSumInner;
                    }

                    int newPixel = calculatedPixel;

                    if (sccalingMethod != SccalingMethod.Scale)
                    {
                        newPixel = this.ScalePixelValue(newPixel, sccalingMethod, sccalingMethod == SccalingMethod.Scale ? minPixel : 0, sccalingMethod == SccalingMethod.Scale ? maxPixel : 255);
                    }


                    if (sccalingMethod != SccalingMethod.Scale)
                    {
                        var bit = directBitmapPost.GetPixelHSV(x, y);

                        calculatedHSVBit.saturation = bit.saturation;

                        calculatedHSVBit.HUE = bit.HUE;
                        //apply cut scalling
                        if (calculatedHSVBit.value > 1)
                        {
                            calculatedHSVBit.value = 1;
                        }

                        if (calculatedHSVBit.value < 0)
                        {
                            calculatedHSVBit.value = 0;
                        }

                        directBitmapPost.SetPixel(x, y, calculatedHSVBit.getColor());
                    }
                    else
                    {
                        bitMapToScale[x + (y * directBitmapPre.Width)] = newPixel;
                    }
                    maskSumInner                = 0;
                    calculatedPixel             = 0;
                    calculatedHSVBit.HUE        = 0;
                    calculatedHSVBit.saturation = 0;
                    calculatedHSVBit.value      = 0;
                    angles.Clear();
                }
            }
        }
コード例 #3
0
        public int BuildStuff(Bitmap aMask, Settings TheSettings)
        {
            DirectBitmap Mask = new DirectBitmap(aMask.Width, aMask.Height);
            Graphics     mg   = Graphics.FromImage(Mask.Bitmap);

            mg.DrawImage(aMask, 0, 0);


            int i = Math.Max(Mask.Width, Mask.Height);
            int R = 1;

            while (R < i)
            {
                R *= 2;
            }
            ArtTree = null;
            float ThresholdLevel = TheSettings.Threshold * 0.01f;

            switch (TheSettings.Mode)
            {
            case Settings.ArtMode.QuadTree:
            {
                DateTime rR = DateTime.Now;

                ArtTree = new QuadTreeNode()
                {
                    xstart = -1000, ystart = -1000, xend = R, yend = R
                };
                float hoek = (float)((6.283 * TheSettings.DegreesOff) / 360.0);
                for (int x = 0; x < Mask.Width; x++)
                {
                    for (int y = 0; y < Mask.Height; y++)
                    {
                        var  C    = Mask.GetPixelFast(x, y);
                        bool doit = false;
                        if (TheSettings.InvertSource)
                        {
                            doit = C.GetBrightness() > ThresholdLevel;
                        }
                        else
                        {
                            doit = C.GetBrightness() < ThresholdLevel;
                        }
                        if (doit)
                        {
                            double cx = Math.Cos(hoek) * x + Math.Sin(hoek) * y;
                            double cy = Math.Sin(hoek) * -x + Math.Cos(hoek) * y;
                            ArtTree.Insert((int)cx, (int)cy, new SolidQuadTreeItem()
                                {
                                    x = (int)cx, y = (int)cy
                                }, TheSettings.MaxSubDiv);
                        }
                    }
                }
                var Elapsed = DateTime.Now - rR;
                return((int)Elapsed.TotalMilliseconds);
            }

            case Settings.ArtMode.Delaunay:
            {
                DateTime rR = DateTime.Now;
                ArtTree = new QuadTreeNode()
                {
                    xstart = -1000, ystart = -1000, xend = R, yend = R
                };
                float hoek = (float)((6.283 * TheSettings.DegreesOff) / 360.0);
                for (int x = 0; x < Mask.Width; x++)
                {
                    for (int y = 0; y < Mask.Height; y++)
                    {
                        var  C    = Mask.GetPixelFast(x, y);
                        bool doit = false;
                        if (TheSettings.InvertSource)
                        {
                            doit = C.GetBrightness() > ThresholdLevel;
                        }
                        else
                        {
                            doit = C.GetBrightness() < ThresholdLevel;
                        }
                        if (doit)
                        {
                            double cx = Math.Cos(hoek) * x + Math.Sin(hoek) * y;
                            double cy = Math.Sin(hoek) * -x + Math.Cos(hoek) * y;
                            ArtTree.Insert((int)cx, (int)cy, new SolidQuadTreeItem()
                                {
                                    x = (int)cx, y = (int)cy
                                }, TheSettings.MaxSubDiv);
                        }
                    }
                }

                Delaunay.Build(ArtTree, TheSettings.DegreesOff);

                var Elapsed = DateTime.Now - rR;
                return((int)Elapsed.TotalMilliseconds);
            };

            case Settings.ArtMode.Tiling:
            {
                TD.Create(TheSettings.TileType);
                var P  = TD.CreateBaseTriangle(TheSettings.BaseTile, 1000);
                var P2 = TD.CreateBaseTriangle(TheSettings.BaseTile, 1000);
                P.Rotate(TheSettings.DegreesOff);
                P.AlterToFit(Mask.Width, Mask.Height);
                P2.Rotate(TheSettings.DegreesOff);
                P2.AlterToFit(Mask.Width, Mask.Height);

                if (TheSettings.Symmetry)
                {
                    P.ShiftToEdge(Mask.Width / 2, Mask.Height / 2);
                    P2.ShiftToEdge(Mask.Width / 2, Mask.Height / 2);
                    P2.Flip(Mask.Width / 2, Mask.Height / 2);
                    if (TheSettings.SuperSymmetry)
                    {
                        P2.MirrorAround(Mask.Width / 2, Mask.Height / 2);
                    }
                }

                DateTime rR = DateTime.Now;
                SubDivPoly = TD.SubdivideAdaptive(P, TheSettings.MaxSubDiv, MaskTree, TheSettings.alwayssubdivide);

                if (TheSettings.Symmetry)
                {
                    SubDivPoly.AddRange(TD.SubdivideAdaptive(P2, TheSettings.MaxSubDiv, MaskTree, TheSettings.alwayssubdivide));
                }

                if (TheSettings.xscalesmallerlevel != 0)
                {
                    float midx  = Mask.Width / 2.0f;
                    float width = Mask.Width;
                    float offs  = TheSettings.xscalecenter * 0.01f * width;
                    foreach (var A in SubDivPoly)
                    {
                        var   M      = A.Mid();
                        float scaler = 1.0f - ((float)(M.x - offs) / width) * TheSettings.xscalesmallerlevel * 0.01f;
                        //scaler = Math.Max(0, Math.Min(1.0f, scaler));
                        A.ScaleDown(TheSettings.scalingMode, scaler);
                    }
                }
                if (TheSettings.scalesmallerfactor != 1.0f)
                {
                    foreach (var A in SubDivPoly)
                    {
                        A.ScaleDown(Settings.TriangleScaleMode.Balanced, TheSettings.scalesmallerfactor);
                    }
                }

                if (TheSettings.scalesmaller != 0)
                {
                    float scaler = Math.Abs(TheSettings.scalesmaller);
                    if (TheSettings.scalesmaller > 0)
                    {
                        scaler = scaler / 10.0f;
                    }
                    else
                    {
                        scaler = -scaler / 10.0f;
                    }
                    foreach (var A in SubDivPoly)
                    {
                        if (A.depth - TheSettings.scalesmallerlevel <= 1)
                        {
                        }
                        else
                        {
                            A.ScaleDown(TheSettings.scalingMode, (1 + scaler * (1.0f / (A.depth - TheSettings.scalesmallerlevel))));
                        }
                    }
                }
                if (TheSettings.distanceToMaskScale != 0)
                {
                    float scaler = Math.Abs(TheSettings.distanceToMaskScale);
                    if (TheSettings.distanceToMaskScale > 0)
                    {
                        scaler = scaler / 10.0f;
                    }
                    else
                    {
                        scaler = -scaler / 10.0f;
                    }


                    float aThresholdLevel = TheSettings.Threshold * 0.01f;

                    foreach (var A in SubDivPoly)
                    {
                        var   m   = A.Mid();
                        float sum = GetPixelSum(m, Mask, TheSettings.distanceToMaskRange, aThresholdLevel, TheSettings.InvertSource);
                        //if (sum > 1) sum = 1;
                        A.ScaleDown(TheSettings.scalingMode, (scaler * sum));
                    }
                }


                if (TheSettings.MarcelPlating)
                {
                    List <Tiling.Polygon> MarcelShapes = new List <Tiling.Polygon>();
                    foreach (var A in SubDivPoly)
                    {
                        MarcelShape MS  = new MarcelShape();
                        MarcelShape MS2 = new MarcelShape();

                        foreach (var v in A.Vertices)
                        {
                            MS2.Vertices.Add(new ClipperLib.IntPoint((long)((v.x + 1000) * 1000), (long)((v.y + 1000) * 1000)));
                        }

                        MS.ShrinkFromShape(MS2.Vertices, TheSettings.Gap / 2 + TheSettings.Rounding / 2);
                        Paths Ps = new Paths();

                        Ps.AddRange(MS.BuildOutlines(TheSettings.Rounding / 2.0f));
                        if (TheSettings.BallRadius > 0)
                        {
                            Ps.AddRange(MS.BuildHoles(TheSettings.BallRadius));
                        }

                        foreach (var p in Ps)
                        {
                            Tiling.Polygon Poly = new Tiling.Polygon();
                            Poly.Vertices.AddRange(from a in p select new vec2((a.X) * 0.001f - 1000, (a.Y) * 0.001f - 1000));
                            MarcelShapes.Add(Poly);
                        }
                    }
                    SubDivPoly.Clear();
                    SubDivPoly = MarcelShapes;
                }

                var Elapsed = DateTime.Now - rR;
                return((int)Elapsed.TotalMilliseconds);
            }
            }
            ;
            return(0);
        }
コード例 #4
0
 public PolygonFiller(DirectBitmap _directBitmap, SurfaceRenderer _surfaceRenderer, List <Polygon> _polygons)
 {
     directBitmap    = _directBitmap;
     surfaceRenderer = _surfaceRenderer;
     polygons        = _polygons;
 }
コード例 #5
0
 public override BasePlotter Clone(DirectBitmap m)
 {
     return(new MandelbarPlot(combinedControl, m));
 }
コード例 #6
0
 public OutputState(List <CalculatorCore> calcs, GraphRange xRange, GraphRange yRange, GraphRange zRange, DirectBitmap bitmap)
 {
     Calcs  = calcs;
     XRange = xRange;
     YRange = yRange;
     ZRange = zRange;
     Bitmap = bitmap;
 }
コード例 #7
0
        public static DirectBitmap RGBTextureToBitmap(Texture2D texture, byte[] data)
        {
            int          width  = texture.Width;
            int          height = texture.Height;
            DirectBitmap bitmap = new DirectBitmap(width, height);

            try
            {
                switch (texture.TextureFormat)
                {
                case TextureFormat.Alpha8:
                    RgbConverter.A8ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.ARGB4444:
                    RgbConverter.ARGB16ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.RGB24:
                    RgbConverter.RGB24ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.RGBA32:
                    RgbConverter.RGBA32ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.ARGB32:
                    RgbConverter.ARGB32ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.RGB565:
                    RgbConverter.RGB16ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.R16:
                    RgbConverter.R16ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.RGBA4444:
                    RgbConverter.RGBA16ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.BGRA32:
                    Buffer.BlockCopy(data, 0, bitmap.Bits, 0, bitmap.Bits.Length);
                    break;

                case TextureFormat.RG16:
                    RgbConverter.RG16ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                case TextureFormat.R8:
                    RgbConverter.R8ToBGRA32(data, width, height, bitmap.Bits);
                    break;

                default:
                    throw new Exception(texture.TextureFormat.ToString());
                }
                bitmap.FlipY();
                return(bitmap);
            }
            catch
            {
                bitmap.Dispose();
                throw;
            }
        }
コード例 #8
0
 public static void Draw(this Point p, DirectBitmap bmp)
 {
     p.Draw(bmp, _color);
 }
コード例 #9
0
 public LevelBinarization(DirectBitmap bitmap, Histogram histogram) : base(bitmap, histogram)
 {
 }
コード例 #10
0
ファイル: Histogram.cs プロジェクト: mh-cad/vistarsier
        public Bitmap GenerateSlide()
        {
            // Init 2-D histo matrix
            double[][] diffMatrix = new double[1024][];
            for (int i = 0; i < 1024; ++i)
            {
                diffMatrix[i] = new double[1024];
            }
            double[][] increaseMatrix = new double[1024][];
            for (int i = 0; i < 1024; ++i)
            {
                increaseMatrix[i] = new double[1024];
            }
            double[][] decreaseMatrix = new double[1024][];
            for (int i = 0; i < 1024; ++i)
            {
                decreaseMatrix[i] = new double[1024];
            }

            var max = double.MinValue;
            var min = double.MaxValue;

            var rangeStart = Math.Min(Prior.Voxels.Min(), Current.Voxels.Min());
            var rangeEnd   = Math.Max(Prior.Voxels.Max(), Current.Voxels.Max());
            var range      = rangeEnd - rangeStart;
            var diff       = Subtract(Prior.Voxels, Current.Voxels);

            for (int i = 0; i < diff.Length; ++i)
            {
                diff[i] = Math.Abs(diff[i]);
            }

            for (int i = 0; i < diff.Length; ++i)
            {
                int x = Math.Min(1023, (int)((Prior.Voxels[i] - rangeStart) / range * 1024));
                int y = Math.Min(1023, (int)((Current.Voxels[i] - rangeStart) / range * 1024));
                diffMatrix[x][y] += 1;
                if (Increase != null && Increase.Voxels[i] != 0)
                {
                    increaseMatrix[x][y] += 1;                                             //(double)Increase.Voxels[i];
                }
                if (Decrease != null && Decrease.Voxels[i] != 0)
                {
                    decreaseMatrix[x][y] += 1;                                             //(double)Decrease.Voxels[i];
                }
                if (diffMatrix[x][y] > max && x > 10 && y > 10)
                {
                    max = diffMatrix[x][y];
                }
                if (diffMatrix[x][y] < min)
                {
                    min = diffMatrix[x][y];
                }
            }

            // We could normalise to the given range, but a flat multiplier will
            // help us compare between scans.
            var bmp = new DirectBitmap(1024, 1024);

            Log.GetLogger().Info($"Min {min}, Max {max}, Range = { max - min}, ideal multi={255.0 / (max - min)}");
            var multiplier = 3;//255.0 / (max - min);

            for (int x = 0; x < 1024; ++x)
            {
                for (int y = 0; y < 1024; ++y)
                {
                    var grey = Math.Min((int)((diffMatrix[x][y] - min) * multiplier), 255);
                    grey = Math.Max(grey, 0);
                    bmp.SetPixel(x, y, Color.FromArgb(grey, grey, grey));
                    if (increaseMatrix[x][y] != 0)
                    {
                        bmp.SetPixel(x, y, Color.FromArgb(Math.Min(255, (int)(grey * 1.5)), (int)(grey / 1.5), 0));
                    }
                    if (decreaseMatrix[x][y] != 0)
                    {
                        bmp.SetPixel(x, y, Color.FromArgb(0, Math.Min(255, (int)(grey * 1.5)), 0));
                    }
                    if (x == y)
                    {
                        bmp.SetPixel(x, y, Color.FromArgb(128, grey, grey));
                    }
                }
            }

            return(bmp.Bitmap);
        }
コード例 #11
0
ファイル: Separator.cs プロジェクト: Virus887/Image-converter
 public Separator(DirectBitmap mainBitmap)
 {
     this.mainBitmap = mainBitmap;
     w = mainBitmap.Width;
     h = mainBitmap.Height;
 }
コード例 #12
0
 public PolygonDrawer(DirectBitmap _directBitmap, List <Polygon> _polygons)
 {
     directBitmap = _directBitmap;
     polygons     = _polygons;
 }
コード例 #13
0
 private void PolygonFillForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     DirectBitmap.Dispose();
 }
コード例 #14
0
 public override BasePlotter Clone(DirectBitmap m)
 {
     return(new JuliaRationalPlot(combinedControl, definedTYype, m));
 }
コード例 #15
0
        private Tuple <DirectBitmap, SimpleDatum> getData(COLORTYPE ct, int nWid, int nHt, int nOffset, int nDownsample, byte[] rg, bool bPreprocess, bool bGetAction)
        {
            int  nChannels = (bPreprocess) ? 1 : 3;
            int  nSize     = Math.Min(nWid, nHt);
            int  nDsSize   = nSize / nDownsample;
            int  nX        = 0;
            int  nY        = 0;
            bool bY        = false;
            bool bX        = false;

            if (m_bmpRaw != null && (m_bmpRaw.Width != nWid || m_bmpRaw.Height != nHt))
            {
                m_bmpRaw.Dispose();
                m_bmpRaw = null;
            }

            if (m_bmpActionRaw != null && (m_bmpActionRaw.Width != nDsSize || m_bmpActionRaw.Height != nDsSize))
            {
                m_bmpActionRaw.Dispose();
                m_bmpActionRaw = null;
            }

            if (m_bmpRaw == null)
            {
                m_bmpRaw = new DirectBitmap(nWid, nHt);
            }

            if (m_bmpActionRaw == null)
            {
                m_bmpActionRaw = new DirectBitmap(nDsSize, nDsSize);
            }

            DirectBitmap bmp   = m_bmpRaw;
            Valuemap     dataV = null;
            Bytemap      dataB = null;

            if (bGetAction)
            {
                if (m_bPreprocess)
                {
                    dataV = new Valuemap(nChannels, nDsSize, nDsSize);
                }
                else
                {
                    dataB = new Bytemap(nChannels, nDsSize, nDsSize);
                }
            }

            for (int y = 0; y < nHt; y++)
            {
                if (y % nDownsample == 0 && y > nOffset && y < nOffset + nSize)
                {
                    bY = true;
                }
                else
                {
                    bY = false;
                }

                for (int x = 0; x < nWid; x++)
                {
                    int nIdx = (y * nWid) + x;
                    int nR   = rg[nIdx];
                    int nG   = nR;
                    int nB   = nR;

                    if (x % nDownsample == 0)
                    {
                        bX = true;
                    }
                    else
                    {
                        bX = false;
                    }

                    if (ct == COLORTYPE.CT_COLOR)
                    {
                        nG = rg[nIdx + (nWid * nHt * 1)];
                        nB = rg[nIdx + (nWid * nHt * 2)];
                    }

                    Color clr = Color.FromArgb(nR, nG, nB);
                    bmp.SetPixel(x, y, clr);

                    if (bY && bX && (dataB != null || dataV != null))
                    {
                        if (bPreprocess)
                        {
                            if (nR != 144 && nR != 109 && nR != 0)
                            {
                                dataV.SetPixel(nX, nY, 1.0);
                            }
                        }
                        else
                        {
                            dataB.SetPixel(x, y, clr);
                        }

                        nX++;
                    }
                }

                if (bY)
                {
                    nX = 0;
                    nY++;
                }
            }

            SimpleDatum sd = null;

            if (m_bPreprocess)
            {
                if (dataV != null)
                {
                    sd = new SimpleDatum(dataV);
                }
            }
            else
            {
                if (dataB != null)
                {
                    sd = new SimpleDatum(dataB);
                }
            }

            return(new Tuple <DirectBitmap, SimpleDatum>(bmp, sd));
        }
コード例 #16
0
 public GraphicsModeRenderer(byte[] Memory, ushort VideoMemoryStartAddress)
     : base(Memory, VideoMemoryStartAddress)
 {
     _GraphicsBitmap = new DirectBitmap(Width, Height);
 }
コード例 #17
0
        public void Render(World world, Camera camera, DirectBitmap screen)
        {
            Vector3f light = new Vector3f(0, 1, 0);

            light.MultiplySelf(1 / light.Length);

            // Матрица вида = матрице перемещения камеры
            var viewMatrix = camera.TranslationMatrix.Inverse();

            // матрица проекции
            var projectionMatrix = camera.ProjectionMatrix;

            foreach (var mesh in world.Meshes)
            {
                var random = new Random(0);
                foreach (var triangle in mesh.Triangles)
                {
                    // Duplicate triangle to not accidentally corrupt any data
                    triangle.Duplicate(_tri);

                    #region Calculate Triangle To Camera Ray

                    bool preciseCameraRay = false;
                    if (preciseCameraRay)
                    {
                        var triWorldCenterX = (_tri[0].X + _tri[1].X + _tri[2].X) / 3f;
                        var triWorldCenterY = (_tri[0].Y + _tri[1].Y + _tri[2].Y) / 3f;
                        var triWorldCenterZ = (_tri[0].Z + _tri[1].Z + _tri[2].Z) / 3f;

                        _cameraRay.X = camera.Position.X - triWorldCenterX;
                        _cameraRay.Y = camera.Position.Y - triWorldCenterY;
                        _cameraRay.Z = camera.Position.Z - triWorldCenterZ;
                    }
                    else
                    {
                        _cameraRay.X = camera.Position.X - _tri[0].X;
                        _cameraRay.Y = camera.Position.Y - _tri[0].Y;
                        _cameraRay.Z = camera.Position.Z - _tri[0].Z;
                    }

                    #endregion

                    #region Calculate Triangle Normal

                    // CounterClockWise Model
                    // https://stackoverflow.com/questions/22171776/order-of-vector-cross-product-for-a-ccw-triangle

                    var normal = SomeMaths.Cross(_tri[0], _tri[1], _tri[2]);
                    normal.MultiplySelf(1 / normal.Length); // normalize

                    #endregion

                    #region Clip Invisible Triangles

                    if (normal.Dot(_cameraRay) < 0)
                    {
                        // clip invisible triangles
                        continue;
                    }

                    #endregion

                    #region Calculate Model Matrix

                    // !!! IMPORTANT http://opengl-tutorial.blogspot.com/p/3.html
                    // Сначала нужно изменить размер, потом прокрутить и лишь потом сдвинуть.
                    modelMatrix.MakeIdentity();
                    modelMatrix.MultiplySelf(mesh.ScaleMatrix);
                    modelMatrix.MultiplySelf(mesh.RotationMatrix);
                    modelMatrix.MultiplySelf(mesh.TranslationMatrix);

                    #endregion

                    #region Project From 3D To 2D

                    // проецируем точки треугольника по правилу MVP (model view project)
                    for (int i = 0; i < 3; i++)
                    {
                        _tri[i].MultiplySelf(modelMatrix);
                        _tri[i].MultiplySelf(viewMatrix);
                        _tri[i].MultiplySelf(projectionMatrix);
                    }

                    #endregion

                    #region Translate To Screen Center

                    // Сдвигаем точки в центр экрана
                    for (int i = 0; i < 3; i++)
                    {
                        _tri[i].X += 1.0f;
                        _tri[i].Y += 1.0f;
                        _tri[i].X *= screen.Width / 2f;
                        _tri[i].Y *= screen.Height / 2f;
                    }

                    #endregion

                    #region Calculate Light Alignment

                    float lightAlignment = light.Dot(normal);

                    #endregion

                    #region Calculate Color

                    uint luminance = (uint)(Math.Max(0.3f, Math.Min(lightAlignment, 0.95f)) * 0xFF) & 0xFF;
                    uint color     = 0xFFu << 24 | luminance << 16 | luminance << 8 | luminance;
                    // int color = 0xFF << 24 | random.Next(0, 255) << 16 | random.Next(0, 255) << 8 | random.Next(0, 255);

                    #endregion

                    #region Fill Solid

                    // SOLID
                    SomeDrawing.FillTriangle(screen, _tri[0], _tri[1], _tri[2], color);

                    #endregion

                    #region Draw Wireframe

                    // WIREFRAME
                    for (int i = 0; i < 3; i++)
                    {
                        SomeDrawing.Line(screen, _tri[i], _tri[(i + 1) % 3], 0xFFFFFFFF);
                    }

                    #endregion

                    #region Calculate Screen Space Triangle Center

                    var triScreenCenterX = (_tri[0].X + _tri[1].X + _tri[2].X) / 3f;
                    var triScreenCenterY = (_tri[0].Y + _tri[1].Y + _tri[2].Y) / 3f;
                    var triScreenCenterZ = (_tri[0].Z + _tri[1].Z + _tri[2].Z) / 3f;

                    #endregion

                    #region Draw Vertex To Center Line

                    // VERTEX TO CENTER
                    for (int i = 0; i < 3; i++)
                    {
                        SomeDrawing.Line(screen, _tri[i].X, _tri[i].Y, triScreenCenterX, triScreenCenterY, 0xFFFF0000);
                    }

                    #endregion

                    #region Draw Normal

                    float normalLength = 40;

                    // NORMAL
                    SomeDrawing.Line(screen, triScreenCenterX, triScreenCenterY,
                                     triScreenCenterX + normal.X * normalLength,
                                     triScreenCenterY + normal.Y * normalLength,
                                     0xFF0000FF);

                    #endregion
                }
            }
        }
コード例 #18
0
 public EntropySelectionBinarization(DirectBitmap bitmap, Histogram histogram) : base(bitmap, histogram)
 {
     _levelBinarization = new LevelBinarization(bitmap, histogram);
 }
コード例 #19
0
        public static Model Read(string modelPath, string texturePath, string normalMapPath, string specularMapPath)
        {
            var lines = File.ReadLines(modelPath);

            var model = new Model();


            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            provider.NumberGroupSeparator   = ",";

            foreach (var line in lines)
            {
                // vertices line have the following form:  v 0.23 0.45 0.67
                if (line.Length > 2 && line[0] == 'v' && line[1] != 't' && line[1] != 'n')
                {
                    var spl = line.Split(' ').Skip(1).ToArray();
                    var vec = new Vector3
                              (
                        Convert.ToSingle(spl[0], provider),
                        Convert.ToSingle(spl[1], provider),
                        Convert.ToSingle(spl[2], provider)
                              );
                    model.Verteces.Add(vec);
                }

                // texture vertices line have the following form:  vt 0.23 0.45 0.00 (the third coordinate is not needed)
                if (line.StartsWith("vt"))
                {
                    var spl = line.Split(' ').Skip(2).ToArray();
                    var arr = new List <float>();
                    foreach (var item in spl)
                    {
                        var val = Convert.ToSingle(item, provider);
                        arr.Add(val);
                    }
                    var vec = new Vector2(arr[0], arr[1]);
                    model.TextureVerteces.Add(vec);
                }

                // normal vertices line have the following form: vn 0.23 0.45 0.67

                if (line.StartsWith("vn"))
                {
                    var spl = line.Split(' ').Skip(2).ToArray();
                    var vec = new Vector3
                              (
                        Convert.ToSingle(spl[0], provider),
                        Convert.ToSingle(spl[1], provider),
                        Convert.ToSingle(spl[2], provider)
                              );
                    model.Normals.Add(vec);
                }

                // lines starting with f indicate which points make up a triangle in verteces, tex vert and normal vert
                // for example:
                // first line is "f 24/1/24 25/2/25 26/3/26"
                // therefore, the first triangle is described in "v" lines 24, 25 and 26 and
                // has coordinates:
                // 1 => X: 0,134781, Y: -0,14723, Z: 0,48805
                // 2 => X: 0,131261, Y: -0,132153, Z: 0,49872
                // 3 => X: 0,14749, Y: -0,135105, Z: 0,489565
                // the second indices are the triangles of the texture space
                // the third indeces are the normals
                if (line.StartsWith("f"))
                {
                    var faceV = new int[3];
                    var faceT = new int[3];
                    var faceN = new int[3];

                    var spl = line.Split(' ').Skip(1).ToArray();

                    for (int i = 0; i < spl.Length; i++)
                    {
                        var spl1  = spl[i].Split('/').ToArray();
                        var facev = Convert.ToInt32(spl1[0]);
                        var facet = Convert.ToInt32(spl1[1]);
                        var facen = Convert.ToInt32(spl1[2]);
                        faceV[i] = facev;
                        faceT[i] = facet;
                        faceN[i] = facen;
                    }

                    model.FacesV.Add(faceV);
                    model.FacesT.Add(faceT);
                    model.FacesN.Add(faceN);
                }
            }

            DirectBitmap texture     = new DirectBitmap(1, 1);
            DirectBitmap normalMap   = new DirectBitmap(1, 1);
            DirectBitmap specularMap = new DirectBitmap(1, 1);

            Parallel.Invoke
            (
                () => LoadTexture(texturePath, out texture),
                () => LoadTexture(normalMapPath, out normalMap),
                () => LoadTexture(specularMapPath, out specularMap)
            );

            model.Texture     = texture;
            model.NormalMap   = normalMap;
            model.SpecularMap = specularMap;
            return(model);
        }
コード例 #20
0
        /*
         * Find all black pixels that touch (seedrow,seedcol).
         * (seedrow,seedcol) should be black, otherwise an empty image and an area of 0 are returned.
         *
         * @param srcImg The image in which to look for contigous black pixels
         *      NOTE: srcImg is changed. Do not pass *this
         *      TODO: Check that the code works correctly with srcImg being changed
         * @param seedrow the row of the (row,col) pair at which to start
         * @param seedcol the column of the (row,col) pair at which to start
         * @return a pointer to a Feature containing an BinaryImage of all contigous black pixels touching (seedrow,seedcol)
         */
        public static Feature FindBlob(DirectBitmap srcImg, int seedrow, int seedcol)
        {
            //Based on code from deburekr
            Stack <Darwin.PointF> nbr_stack = new Stack <Darwin.PointF>();
            int cr, cc;     // removed done & j
            int l, r, t, b; /*left, right, top , bottom neighbor */
            int area;
            int map_val = 0;

            DirectBitmap map = new DirectBitmap(srcImg.Width, srcImg.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);

            for (int x = 0; x < map.Width; x++)
            {
                for (int y = 0; y < map.Height; y++)
                {
                    map.SetPixelByte(x, y, ColorExtensions.WhiteByte);
                }
            }

            //using (var graphics = Graphics.FromImage(map.Bitmap))
            //{
            //    graphics.FillRectangle(Brushes.White, 0, 0, map.Width, map.Height);
            //}

            nbr_stack.Push(new Darwin.PointF(seedcol, seedrow));
            area = 0;
            while (nbr_stack.Count > 0)
            {
                Darwin.PointF pt = nbr_stack.Pop();
                cr = (int)Math.Round(pt.Y);
                cc = (int)Math.Round(pt.X);

                if (srcImg.GetPixel(cc, cr).GetIntensity() != 255)
                {  /* may already have been pushed & processed */
                    srcImg.SetPixel(cc, cr, Color.White);

                    var mapPixel = Color.FromArgb(map_val, map_val, map_val);
                    map.SetPixel(cc, cr, mapPixel);

                    area++;
                    r = cc + 1;
                    l = cc - 1;
                    t = cr - 1;
                    b = cr + 1;
                    /* process 4 neighbors in R,B,L,T (ESWN) order */
                    if (r < srcImg.Width)
                    { /* border? */
                        if (srcImg.GetPixel(r, cr).GetIntensity() != 255)
                        {
                            nbr_stack.Push(new Darwin.PointF(r, cr));
                        }
                    }
                    if (b < srcImg.Height)
                    {
                        if (srcImg.GetPixel(cc, b).GetIntensity() != 255)
                        {
                            nbr_stack.Push(new Darwin.PointF(cc, b));
                        }
                    }
                    if (l >= 0)
                    {
                        if (srcImg.GetPixel(l, cr).GetIntensity() != 255)
                        {
                            nbr_stack.Push(new Darwin.PointF(l, cr));
                        }
                    }
                    if (t >= 0)
                    {
                        if (srcImg.GetPixel(cc, t).GetIntensity() != 255)
                        {
                            nbr_stack.Push(new Darwin.PointF(cc, t));
                        }
                    }
                }
            } /* end while */
              //printf("Area = %d\n", area);

            return(new Feature
            {
                Area = area,
                Mask = map
            });
        }
コード例 #21
0
 private void CreateBuffers(Size size)
 {
     BackBuffer = new DirectBitmap(size);
 }
コード例 #22
0
        private void bgwMain_DoWork(object sender, DoWorkEventArgs e)
        {
            int startTime;

            int nextFireTime;

            PlayerWeapon[] playerWeapons = new PlayerWeapon[2] {
                new PlayerWeapon(), new PlayerWeapon()
            };



            startTime    = 0;
            nextFireTime = 0;

            runMode = RunMode.RUN;

            bool doingNade = false;

            bool slept = false;

            int nextWindowTime = Environment.TickCount;

            IntPtr lastForegroundWindow = IntPtr.Zero;

            bool isGameActive = false;

            float brightnessMinimum;


            Point scopeStart1 = new Point(1586, 115);
            Point scopeStart2 = new Point(1586, 345);

            Point start = new Point(890, 920);

            Size area = new Size(140, 45);

            Size scopeArea = new Size(48, 43);


            List <ScopeMask> scopeMasks;

            int currentWeaponGameIndex = 1;

            SpeechSynthesizer speaker = new SpeechSynthesizer();

            speaker.Volume = 100;

            brightnessMinimum = 0.80f;

            float scopeBrightnessMaximum = 0.15f;

            bool firedGun = false;


            int lastWeaponSlot    = 1,
                currentWeaponSlot = 1;

            List <string> singleFireWeapons = new List <string>(new string[] { "awm", "crossbow", "kar98k", "m24" });

            weaponMasks = new List <WeaponMask>();
            scopeMasks  = new List <ScopeMask>();



            // Load the scope masks into objects
            foreach (string s in Directory.GetFiles("input images\\raw\\menu scopes"))
            {
                ScopeMask mask;

                Bitmap bmp;


                bmp = new Bitmap(s);

                mask          = new ScopeMask();
                mask.filename = s.Split("\\").Last().Split(".").First();
                mask.points   = new List <MaskPoint>();

                for (int y = 0; y < bmp.Height; y++)
                {
                    for (int x = 0; x < bmp.Width; x += 10)
                    {
                        Color pixel = bmp.GetPixel(x, y);

                        if ((pixel.R == Color.Magenta.R && pixel.G == Color.Magenta.G && pixel.B == Color.Magenta.B) == false)
                        {
                            mask.points.Add(new MaskPoint(x, y, ((pixel.R + pixel.G + pixel.B) / 3.0f)));
                        }
                    }
                }

                mask.strength = int.Parse(mask.filename.Split(".").First().Split("-").First().Replace("x", ""));

                setStatus("Point count: " + mask.points.Count);

                bmp.Dispose();
                scopeMasks.Add(mask);
            }

            scopeMasks = scopeMasks.OrderBy(x => x.points.Count).ToList();

            scopeMasks.Reverse();



            // Load the gun masks into objects
            foreach (string s in Directory.GetFiles("input images\\raw\\menu guns"))
            {
                WeaponMask mask;

                Bitmap bmp;


                bmp = new Bitmap(s);


                mask          = new WeaponMask();
                mask.filename = s.Split("\\").Last().Split(".").First().ToLower();
                mask.points   = new List <MaskPoint>();

                for (int y = 0; y < bmp.Height; y += 1)
                {
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        Color pixel = bmp.GetPixel(x, y);

                        if ((pixel.R == Color.Magenta.R && pixel.G == Color.Magenta.G && pixel.B == Color.Magenta.B) == false)
                        {
                            mask.points.Add(new MaskPoint(x, y, ((pixel.R + pixel.G + pixel.B) / 3.0f)));
                        }
                    }
                }

                mask.points.Sort((x, y) =>
                {
                    if (x.averagePixel == y.averagePixel)
                    {
                        return(0);
                    }
                    else if (x.averagePixel < y.averagePixel)
                    {
                        return(-1);
                    }
                    else
                    {
                        return(1);
                    }
                });

                mask.points.Reverse();

                List <MaskPoint> final = new List <MaskPoint>();

                for (int i = 0; i < mask.points.Count; i += mask.points.Count / 20)
                {
                    final.Add(mask.points[i]);
                }

                mask.points = final;

                setStatus("Weapon Point count: " + mask.points.Count);


                bmp.Dispose();
                weaponMasks.Add(mask);
            }

            weaponMasks = weaponMasks.OrderBy(x => x.points.Count).ToList();

            weaponMasks.Reverse();



            // Create the weapon profiles
            foreach (WeaponMask a in weaponMasks)
            {
                // If the profile doesn't exist yet
                if (weaponProfiles.Where(x => x.name == a.filename).FirstOrDefault() == null)
                {
                    WeaponProfile p = new WeaponProfile();

                    p.name = a.filename;

                    weaponProfiles.Add(p);
                }
            }

            // Add the scope profiles to each weapon
            foreach (WeaponProfile p in weaponProfiles)
            {
                foreach (ScopeMask s in scopeMasks)
                {
                    // If it doesn't have an entry for that scope strength, then create one
                    if (p.scopeEntries.Where(x => x.strength == s.strength).FirstOrDefault() == null)
                    {
                        ScopeEntry se = new ScopeEntry();

                        se.strength = s.strength;

                        p.scopeEntries.Add(se);
                    }
                }
            }



            Point ptGunMaskStart1 = new Point(1445, 158);
            Point ptGunMaskStart2 = new Point(1445, 388);

            Point ptScopeMaskStart1 = new Point(1585, 114);
            Point ptScopeMaskStart2 = new Point(1585, 344);

            List <string> screenshots;



            int lastScreenshotTime = 0;

            int nextCompensationTime = 0;

            bool requestingScreenshot = false;


            while (true)
            {
                try
                {
                    if ((GetAsyncKeyState(Keys.Up) & 1) == 1)
                    {
                        nudIndex--;

                        if (nudIndex < 0)
                        {
                            nudIndex = 0;
                        }

                        this.ActiveControl = null;


                        foreach (NumericUpDown a in nudOptions)
                        {
                            a.BackColor = SystemColors.Control;
                        }

                        nudOptions[nudIndex].BackColor = Color.LightGray;
                    }
                    else if ((GetAsyncKeyState(Keys.Down) & 1) == 1)
                    {
                        nudIndex++;

                        if (nudIndex > 3)
                        {
                            nudIndex = 3;
                        }

                        this.ActiveControl = null;

                        foreach (NumericUpDown a in nudOptions)
                        {
                            a.BackColor = SystemColors.Control;
                        }

                        nudOptions[nudIndex].BackColor = Color.LightGray;
                    }
                    else if ((GetAsyncKeyState(Keys.Left) & 1) == 1)
                    {
                        if (nudOptions[nudIndex].Value > nudOptions[nudIndex].Minimum)
                        {
                            if (GetAsyncKeyState(Keys.LShiftKey) != 0)
                            {
                                nudOptions[nudIndex].Value = Math.Max(0, nudOptions[nudIndex].Value - 100);
                            }
                            else
                            {
                                nudOptions[nudIndex].Value -= 1;
                            }
                        }
                    }
                    else if ((GetAsyncKeyState(Keys.Right) & 1) == 1)
                    {
                        if (nudOptions[nudIndex].Value < nudOptions[nudIndex].Maximum)
                        {
                            if (GetAsyncKeyState(Keys.LShiftKey) != 0)
                            {
                                nudOptions[nudIndex].Value = Math.Min(nudOptions[nudIndex].Maximum, nudOptions[nudIndex].Value + 100);
                            }
                            else
                            {
                                nudOptions[nudIndex].Value += 1;
                            }
                        }
                    }
                    else if ((GetAsyncKeyState(Keys.D1) & 1) == 1)
                    {
                        currentWeaponSlot = 0;

                        WeaponProfile p = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault();

                        ScopeEntry s = null;

                        if (p != null)
                        {
                            s = p.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault();
                        }

                        DisplayCurrentWeapon(p, s);
                    }
                    else if ((GetAsyncKeyState(Keys.D2) & 1) == 1)
                    {
                        currentWeaponSlot = 1;

                        WeaponProfile p = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault();

                        ScopeEntry s = null;

                        if (p != null)
                        {
                            s = p.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault();
                        }

                        DisplayCurrentWeapon(p, s);
                    }
                    else if ((GetAsyncKeyState(Keys.D5) & 1) == 1 || (GetAsyncKeyState(Keys.G) & 1) == 1)
                    {
                        currentWeaponSlot = 4;

                        DisplayCurrentWeapon(null, null);
                    }
                    else if ((GetAsyncKeyState(Keys.Tab) & 1) == 1)
                    {
                        AccurateSleep(0.3f);
                        requestingScreenshot = true;
                    }


                    if (Environment.TickCount > nextWindowTime)
                    {
                        isGameActive = IsGameActive();

                        nextWindowTime = Environment.TickCount + 2000;
                    }

                    if (isGameActive == true || skipWindowCheck == true)
                    {
                        if (requestingScreenshot == true)
                        {
                            if (Environment.TickCount - lastScreenshotTime > 1000)
                            {
                                setStatus("Taking screenshot");
                                keybd_event((int)Keys.F12, 0x9e, 0, UIntPtr.Zero);
                                Thread.Sleep(10);
                                keybd_event((int)Keys.F12, 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero);
                                Thread.Sleep(10);

                                requestingScreenshot = false;
                            }
                        }


                        // Process any screenshots in the folder
                        screenshots = Directory.GetFiles("input images\\screenshots").ToList();

                        if (screenshots.Count > 0)
                        {
                            DirectBitmap rawTest = null;

                            Thread.Sleep(25);

                            screenshots[0] = screenshots[screenshots.Count - 1];

                            setStatus("Screenshot found");

                            for (int i = 0; i < 100; i++)
                            {
                                try
                                {
                                    rawTest = new DirectBitmap(screenshots[0]);

                                    break;
                                }
                                catch (Exception x)
                                {
                                    x.ToString();
                                    Thread.Sleep(10);
                                }
                            }

                            if (rawTest != null)
                            {
                                if (IsScreenshotInTabMenu(rawTest) == true)
                                {
                                    // While the tab is open, keep screenshotting

                                    requestingScreenshot = true;

                                    WeaponProfile p;

                                    for (int i = 0; i < 2; i++)
                                    {
                                        p = null;

                                        setStatus("Checking slot: " + i);
                                        Point ptCurrentGunMaskStart,
                                              ptCurrentScopeMaskStart;

                                        if (i == 0)
                                        {
                                            ptCurrentGunMaskStart   = ptGunMaskStart1;
                                            ptCurrentScopeMaskStart = ptScopeMaskStart1;
                                        }
                                        else
                                        {
                                            ptCurrentGunMaskStart   = ptGunMaskStart2;
                                            ptCurrentScopeMaskStart = ptScopeMaskStart2;
                                        }


                                        //Image compare for a weapon match
                                        foreach (WeaponMask m in weaponMasks)
                                        {
                                            if (DoesMaskMatch(rawTest, ptCurrentGunMaskStart, m.points) == true)
                                            {
                                                p = WeaponMaskToProfile(m);

                                                int index = weaponMasks.IndexOf(m);

                                                weaponMasks.Insert(0, m);
                                                weaponMasks.RemoveAt(index + 1);

                                                break;
                                            }

                                            Thread.Sleep(1);
                                        }

                                        // if a weapon was matched
                                        if (p != null)
                                        {
                                            int  scopeStrength = 1;
                                            bool updateDisplay = false;

                                            setStatus("Matched: " + p.name);

                                            if (playerWeapons[i].name != p.name)
                                            {
                                                //Process.Start(screenshots[0]);
                                                playerWeapons[i].name = p.name;

                                                string name = playerWeapons[i].name;
                                                if (name == "pp-19 bizon")
                                                {
                                                    name = "P. P. Bizon";
                                                }
                                                else if (name == "sks")
                                                {
                                                    name = "S. K. S.";
                                                }
                                                else if (name == "aug")
                                                {
                                                    name = "A. U. G.";
                                                }
                                                else if (name == "awm")
                                                {
                                                    name = "A. W. M.";
                                                }
                                                else if (name == "slr")
                                                {
                                                    name = "S. L. R.";
                                                }
                                                else if (name == "ak47")
                                                {
                                                    name = "A. K. 47";
                                                }

                                                speaker.SpeakAsync(name + " " + (i == 0 ? "first" : "second") + " slot");
                                                updateDisplay = true;
                                            }

                                            foreach (ScopeMask s in scopeMasks)
                                            {
                                                if (DoesMaskMatch(rawTest, ptCurrentScopeMaskStart, s.points) == true)
                                                {
                                                    setStatus("Matched scope: " + s.strength);

                                                    scopeStrength = s.strength;


                                                    int index = scopeMasks.IndexOf(s);

                                                    scopeMasks.Insert(0, s);
                                                    scopeMasks.RemoveAt(index + 1);

                                                    if (cbBabyMode.Checked == true)
                                                    {
                                                        if (scopeStrength > 2)
                                                        {
                                                            scopeStrength = 2;
                                                        }
                                                    }

                                                    break;
                                                }

                                                Thread.Sleep(1);
                                            }

                                            if (playerWeapons[i].scopeStrength != scopeStrength)
                                            {
                                                playerWeapons[i].scopeStrength = scopeStrength;

                                                speaker.SpeakAsync(playerWeapons[i].scopeStrength + " X. " + (i == 0 ? "first" : "second") + " slot");
                                                updateDisplay = true;
                                            }

                                            if (updateDisplay == true)
                                            {
                                                WeaponProfile p2 = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault();

                                                ScopeEntry s2 = null;

                                                if (p2 != null)
                                                {
                                                    s2 = p2.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault();
                                                }

                                                DisplayCurrentWeapon(p2, s2);
                                            }
                                        }
                                    }
                                }
                            }

                            if (rawTest != null)
                            {
                                rawTest.Dispose();
                            }

                            setStatus("Deleting screenshots");

                            foreach (string s in screenshots)
                            {
                                try
                                {
                                    File.Delete(s);
                                }
                                catch (Exception x)
                                {
                                    x.ToString();
                                }
                            }

                            setStatus("Finished deleting");
                        }



                        if ((GetAsyncKeyState(Keys.LButton) != 0) && GetAsyncKeyState(Keys.RButton) == 0 && doingNade == false)
                        {
                            keybd_event((int)'L', 0x9e, 0, UIntPtr.Zero);
                            doingNade = true;
                        }

                        // if its attempt to do a nade
                        if (doingNade == true)
                        {
                            if ((GetAsyncKeyState(Keys.LButton) == 0) && GetAsyncKeyState(Keys.RButton) == 0)
                            {
                                keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero);
                                doingNade = false;
                            }
                        }

                        // If its attempting to spray or is simulating a spray
                        if (GetAsyncKeyState(Keys.LButton) != 0 && GetAsyncKeyState(Keys.RButton) != 0 && currentWeaponSlot < 2)
                        {
                            if (startTime == 0)
                            {
                                startTime = Environment.TickCount;
                            }

                            //If the fire button has been held long enough to activate compensation
                            if (Environment.TickCount - startTime > nudActivationDelay.Value)
                            {
                                WeaponProfile currentWeaponProfile;


                                currentWeaponProfile = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault();

                                // If there is a weapon selected
                                if (currentWeaponProfile != null)
                                {
                                    ScopeEntry currentScopeEntry;


                                    currentScopeEntry = currentWeaponProfile.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault();

                                    // If there is a scope available
                                    if (currentScopeEntry != null)
                                    {
                                        if (Environment.TickCount >= nextCompensationTime)
                                        {
                                            mouse_event(MOUSEEVENTF_MOVE, 0, currentScopeEntry.compensationAmount, 0, UIntPtr.Zero);

                                            nextCompensationTime = Environment.TickCount + currentScopeEntry.compensationDelay;
                                        }


                                        if (Environment.TickCount >= nextFireTime)
                                        {
                                            keybd_event((int)'L', 0x9e, 0, UIntPtr.Zero);
                                            nextFireTime = Environment.TickCount + (int)currentScopeEntry.fireDelay;
                                            Thread.Sleep(25);
                                        }
                                        else
                                        {
                                            // Do not try to auto fire on a gun that cannot be autofired
                                            if (singleFireWeapons.IndexOf(currentWeaponProfile.name) == -1)
                                            {
                                                keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            // if it didn't shoot
                            if (startTime != 0 && nextFireTime == 0)
                            {
                                keybd_event((int)'L', 0x9e, 0, UIntPtr.Zero);
                                Thread.Sleep(25);
                                keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero);
                            }
                            // If it did shoot, reset the fire key just in case
                            else if (nextFireTime != 0)
                            {
                                keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero);
                            }

                            startTime    = 0;
                            nextFireTime = 0;
                        }
                    }
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.ToString());
                }

                Thread.Sleep(1);
            }
        }
コード例 #23
0
 public MandelbarPlot(Control4NonLineairSystems c, DirectBitmap m) : this(c) {
     UseOwnBitmap = true;
     map          = m;
     ResetMaxSquared();
 }
コード例 #24
0
ファイル: HelperFunctions.cs プロジェクト: tomek1kk/Triller
        public static void FillPolygon(List <Point> points, Triller triller, Triangle t = null, DirectBitmap bitmap = null)
        {
            List <Point> pointsSorted = new List <Point>(points);

            pointsSorted.Sort((p1, p2) => p1.Y > p2.Y ? 1 : -1);
            List <int> ind = new List <int>();

            for (int i = 0; i < pointsSorted.Count; i++)
            {
                ind.Add(points.FindIndex(p => p == pointsSorted[i]));
            }

            int ymin = pointsSorted[0].Y;
            int ymax = pointsSorted[pointsSorted.Count - 1].Y;

            List <Edge> AET = new List <Edge>();

            for (int y = ymin; y <= ymax; y++)
            {
                for (int k = 0; k < points.Count; k++)
                {
                    if (points[ind[k]].Y == y - 1)
                    {
                        if (points[ind[k] - 1 >= 0 ? ind[k] - 1 : points.Count - 1].Y > points[ind[k]].Y)
                        {
                            AET.Add(new Edge
                            {
                                A = points[ind[k] - 1 >= 0 ? ind[k] - 1 : points.Count - 1],
                                B = points[ind[k]]
                            });
                        }
                        else
                        {
                            AET.Remove(AET.Find(e => e.A == points[ind[k]]));
                        }

                        if (points[(ind[k] + 1) % points.Count].Y > points[ind[k]].Y)
                        {
                            AET.Add(new Edge
                            {
                                A = points[(ind[k] + 1) % points.Count],
                                B = points[ind[k]]
                            });
                        }
                        else
                        {
                            AET.Remove(AET.Find(e => e.A == points[ind[k]]));
                        }
                    }
                }
                AET.Sort((e1, e2) => e1.GetX(y) > e2.GetX(y) ? 1 : -1);
                for (int j = 0; j < AET.Count / 2; j++)
                {
                    for (int p = AET[2 * j + 1].GetX(y); p >= AET[2 * j].GetX(y); p--)
                    {
                        if (p >= 0)
                        {
                            bitmap.SetPixel(p, y, GetColor(p, y, t));
                        }
                    }
                }
            }
        }
コード例 #25
0
 public static void Line(int x0, int y0, int x1, int y1, DirectBitmap bmp)
 {
     Line(x0, y0, x1, y1, bmp, Color.Black);
 }
コード例 #26
0
 public AlphaMap(DirectBitmap bitmap)
 {
     Ranges = GetRange(bitmap);
 }
コード例 #27
0
 public DynamicOctree(DirectBitmap _originalBitmap, int _colorCount) : base(_originalBitmap, _colorCount)
 {
 }
コード例 #28
0
        private List <SearchRange> GetRange(DirectBitmap bitmap)
        {
            var ranges = new List <SearchRange>(0);

            if (bitmap.Format.ToString().Contains("A", StringComparison.Ordinal) == false)
            {
                ranges.Add(new SearchRange(0, 0, bitmap.Width - 1, bitmap.Height - 1));
                return(ranges);
            }

            //map sequential ranges of solid items
            var  map           = transparentseqmap(bitmap);
            int  pointer       = 0;
            bool istransparent = true;

            //skip till first occurence
            while (map.Length > pointer && map[pointer] == istransparent)
            {
                pointer++;
            }
            if (pointer >= map.Length) //all transparent
            {
                return(ranges);        //return.
            }

            //start collecting
            var points = new List <Point>();

            while (true)
            {
                var p = new Point(pointer, -1);
                while (map.Length > pointer && map[pointer] == !istransparent)
                {
                    pointer++;
                }
                if (map.Length > pointer == false)   //has reached end
                {
                    p.Y = map.Length - 1;
                    points.Add(p);
                    break;
                }
                p.Y = pointer - 1;
                points.Add(p);
                while (map.Length > pointer && map[pointer] == istransparent)   //skip while transparent
                {
                    pointer++;
                }
                if (map.Length > pointer == false)   //has reached end
                {
                    break;
                }
            }

            //map sequential to SearchRanges
            var width = bitmap.Width;

            foreach (var range in points)
            {
                var linear1 = range.X;
                var linear2 = range.Y;
                var r       = new SearchRange(linear1 % width, linear1 / width, linear2 % width, linear2 / width);
                ranges.Add(r);
            }
            return(ranges);
        }
コード例 #29
0
 public IUncompressedImage LoadBitmap(string filePath)
 {
     return(DirectBitmap.CreateFromFile(filePath));
 }
コード例 #30
0
        /// <summary>
        /// Draws the current histogram to the given raster image.
        /// </summary>
        /// <param name="graph">Result image (already scaled to the desired size).</param>
        public static void DrawHistogram(Bitmap graph)
        {
            if (histArray == null)
            {
                return;
            }

            int centerX = graph.Width / 2;
            int centerY = graph.Height / 2;
            int radius  = Math.Min(graph.Height / 2, graph.Width / 2) - 25;

            int hue = histArray.Length;

            DirectBitmap hsv = new DirectBitmap(graph.Width, graph.Height);

            //Color background = Color.FromArgb(255,255,255);
            Color foreground = Color.FromArgb(25, 25, 25);

            if (AutoZoom)
            {
                double Max = histArray.Max();
                Zoom = (1.0f / (float)(Max)) * 0.95f;
            }

            for (int x = 0; x < graph.Width; x++)
            {
                for (int y = 0; y < graph.Height; y++)
                {
                    int dist = (int)Math.Pow((x - centerX) * (x - centerX) + (y - centerY) * (y - centerY), 0.5);

                    if (dist < radius)
                    {
                        var radian  = Math.Atan2(y - centerY, x - centerX);
                        int h_index = (int)(((radian * (180 / Math.PI) + 360) % 360) / 360 * hue);

                        double h = (radian * (180 / Math.PI) + 360) % 360;
                        if (dist < (histArray[h_index] * radius * Zoom) && dist < radius)
                        {
                            hsv.SetPixel(x, y, Arith.HSVToColor(h, 1, 1));
                        }
                        else
                        {
                            hsv.SetPixel(x, y, Arith.HSVToColor(h, 0.1f /** ((float)dist / radius)*/, 1));
                        }
                    }
                    else if (dist < radius + 2)
                    {
                        hsv.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                    }
                    else
                    {
                        hsv.SetPixel(x, y, Color.FromArgb(250, 250, 250));
                    }
                }
            }



            using (Graphics gfx = Graphics.FromImage(graph))
            {
                gfx.Clear(Color.White);
                gfx.DrawImage(hsv.Bitmap, 0, 0);
            }
        }