Beispiel #1
0
        public virtual void SetColor(int x, int y, ColorRGBA color)
        {
            // Create a pixel for the color
            Pixel pel = new Pixel(PixRectInfo.GetPixelInformation(), Pixel.GetBytesForColor(PixRectInfo.GetPixelInformation(), color));

            SetPixel(x, y, pel);
        }
Beispiel #2
0
 public virtual void Clear(Pixel color)
 {
     for (uint i = 0; i < Data.Length; i++)
     {
         Data[i] = color;
     }
 }
Beispiel #3
0
        public LonLat getLonLatFromViewPortPx(Pixel viewPortPx)
        {
            LonLat lonlat = null;
            if (viewPortPx != null)
            {
                Size size = _map.getSize();
                LonLat center = _map.getCenter();
                if (center != null)
                {
                    float res = _map.getResolution().Value;

                    float delta_x = (float)(viewPortPx.x - (size.Width / 2));
                    float delta_y = (float)(viewPortPx.y - (size.Height / 2));

                    lonlat = new LonLat(center.lon + delta_x * res,
                                                center.lat - delta_y * res);

                    if (_wrapDateLine)
                    {
                        lonlat = lonlat.wrapDateLine(_maxExtent);
                    }
                }
            }
            return lonlat;
        }
Beispiel #4
0
    public void Test_IEquatable()
    {
      Pixel first = new Pixel(0, 0, 3);
      first.SetChannel(0, 100);
      first.SetChannel(1, 100);
      first.SetChannel(2, 100);

      Assert.IsFalse(first == null);
      Assert.IsFalse(first.Equals(null));
      Assert.IsTrue(first.Equals(first));
      Assert.IsTrue(first.Equals((object)first));

      Pixel second = new Pixel(10, 10, 3);
      second.SetChannel(0, 100);
      second.SetChannel(1, 0);
      second.SetChannel(2, 100);

      Assert.IsTrue(first != second);
      Assert.IsTrue(!first.Equals(second));
      Assert.IsTrue(!first.Equals((object)second));

      second.SetChannel(1, 100);

      Assert.IsTrue(first == second);
      Assert.IsTrue(first.Equals(second));
      Assert.IsTrue(first.Equals((object)second));
    }
Beispiel #5
0
        public RawImage Unshade32( int zoom, Rectangle bounds, int[] colorbuffer, int[] idbuffer, int[] borderbuffer )
        {
            if ( bounds.Width*bounds.Height != colorbuffer.Length )
                throw new ArgumentOutOfRangeException( "colorbuffer", "The colorbuffer and bounds parameters have mismatching sizes" );
            if ( colorbuffer.Length != idbuffer.Length || colorbuffer.Length != borderbuffer.Length )
                throw new ArgumentOutOfRangeException( "colorbuffer", "The various buffers have mismatching sizes." );

            int bufidx = 0;
            Pixel[,] memory = new Pixel[bounds.Width, bounds.Height];
            for ( int y=0; y<bounds.Height; ++y ) {
                for ( int x=0; x<bounds.Width; ++x ) {
                    // Shading
                    memory[x,y].Color = (byte)((0xFF-((colorbuffer[bufidx] >> 16) & 0xFF))>>2);

                    // ID
                    memory[x,y].ID = idc.ConvertRGB( idbuffer[bufidx] );

                    // Border
                    unchecked {
                        memory[x,y].Border = (byte)((borderbuffer[bufidx] & (int)0xFF0000) > 0 ? 2 : 0);
                    }

                    bufidx++;
                }
            }

            return new RawImage( zoom, bounds, memory );
        }
Beispiel #6
0
 public RawImage( int zoom, Rectangle bounds, Pixel[,] memory )
 {
     this.zoom = zoom;
     this.bounds = bounds;
     if ( memory.GetLength(0) != bounds.Width || memory.GetLength(1) != bounds.Height ) throw new ArgumentOutOfRangeException( "memory" );
     this.memory = memory;
 }
		public TransparencyColor AddColor(Pixel color)
		{
			TransparencyColor transparencyColor = new TransparencyColor(color, 2, 0);
			this._colorList.Add(transparencyColor);
			this.SetDirty();
			return transparencyColor;
		}
        public void BackNForth()
        {
            Pixel[] start = new Pixel[]
            {
                Pixel.Colour.Red,
                Pixel.Colour.Red,
                Pixel.Colour.Red,
                Pixel.Colour.Red,
                Pixel.Colour.Green,
                Pixel.Colour.Green,
                Pixel.Colour.Green,
                Pixel.Colour.Green,
                Pixel.Colour.Blue,
                Pixel.Colour.Blue,
                Pixel.Colour.Blue,
                Pixel.Colour.Blue
            };

            Update(start);
            Thread.Sleep(200);
            for (int j = 1; j < 5; j++) {
                for (int i = 0; i < 20; i++) {
                    RotateDisplay();
                    Thread.Sleep(100);
                }
                for (int h = 0; h < 20; h++) {
                    RotateDisplay(-1);
                    Thread.Sleep(100);
                }
            }
        }
Beispiel #9
0
        private void updateSize()
        {
            Size newSize = getCurrentSize();
            Size oldSize = getSize();

            if (oldSize == Size.Empty)
            {
                _size = oldSize = newSize;                
            }
            if (!newSize.Equals(oldSize))
            {
                _size = newSize;
                
                // @@@ notify layers on resize?

                if (_baseLayer != null)
                {
                    Pixel center = new Pixel((float)(newSize.Width / 2), (float)(newSize.Height / 2));
                    LonLat lonlat = getLonLatFromViewPortPx(center);
                    int zoom = getZoom().Value;
                    _zoom = null;
                    setCenter(getCenter(), zoom, null, null);
                }
            }
        }
Beispiel #10
0
        private double s = 0; // Superpixel Intervall Int

        #endregion Fields

        #region Constructors

        // =============== Konstruktor ===============
        public Superpixels(Image<Bgr, Byte> imageBgr, int superpixelCount)
        {
            // Werte setzen
            k = superpixelCount;
            n = imageBgr.Width * imageBgr.Height;
            s = Math.Sqrt((double)n / (double)k);
            area = Convert.ToInt32(2 * s * 2 * s);
            m = 12;

            // BGR to LAB Umrechnung und Vektormatrix erstellen
            imageLab = imageBgr.Convert<Lab, Byte>();
            pixels = new Pixel[imageBgr.Width, imageBgr.Height];
            for (int r = 0; r < imageLab.Height; r++)
            {
                for (int c = 0; c < imageLab.Width; c++)
                {
                    double l = (double)imageLab.Data[r, c, 0] * 100 / 255;
                    double a = (double)imageLab.Data[r, c, 1] - 128;
                    double b = (double)imageLab.Data[r, c, 2] - 128;

                    Bgr bgr = new Bgr(imageBgr.Data[r, c, 0], imageBgr.Data[r, c, 1], imageBgr.Data[r, c, 2]);

                    pixels[c, r] = new Pixel(new Vector5(l, a, b, c, r), bgr);

                    //Console.WriteLine("BGR = " + imageBgr.Data[r, c, 0] + " " + imageBgr.Data[r, c, 1] + " " + imageBgr.Data[r, c, 2]);
                    //Console.WriteLine("RGB = " + imageBgr.Data[r, c, 2] + " " + imageBgr.Data[r, c, 1] + " " + imageBgr.Data[r, c, 0]);
                    //Console.WriteLine("LAB = " + labValues[r, c].X + " " + labValues[r, c].Y + " " + labValues[r, c].Z);
                }
            }
        }
 private static Pixel GenerateRandomPixel(int xMax, int yMax, Random random)
 {
     var randomX = random.Next(xMax);
     var randomY = random.Next(yMax);
     var pixel = new Pixel(randomX, randomY);
     return pixel;
 }
Beispiel #12
0
        public Image(Bitmap bmp)
        {
            //load code
            Pixel np=new Pixel();
            m_width = (uint)bmp.Width;
            m_height = (uint)bmp.Height;
            m_needFlush = false;

            if (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                m_components = 3;
            }
            else if (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed ||
                     bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed ||
                     bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                m_components = 4;
            }
            else if (bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                m_components = 1;
            }

            ImageConverter imageConverter = new ImageConverter();
             m_buffer = (byte[])imageConverter.ConvertTo(bmp, typeof(byte[]));
        }
Beispiel #13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Random rnd = new Random();
            for (int i = 0; i < 1; i++)
            {
                Pixel p = new Pixel(new Position(rnd.Next(WidthRender * 1000) / 1000f,
                                                    rnd.Next(HeightRender * 1000) / 1000f,
                                                    rnd.Next(1000000) / 1000f));
                p.color = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));
                pixels.Add(p);
            }
            for (int i = 0; i < 10000; i++)
            {
                Pixel p = new MovingPixel(new Position(rnd.Next(WidthRender * 1000) / 1000f,
                                                    rnd.Next(HeightRender * 1000) / 1000f,
                                                    rnd.Next(1000000) / 1000f),
                                    new Position((rnd.Next(100) - 50) / 100f,
                                                (rnd.Next(100) - 50) / 100f,
                                                (rnd.Next(100) - 50) / 100f));
                p.color = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));

                pixels.Add(p);
                updates.Add(p as IUpdate);
            }
        }
Beispiel #14
0
    public static void AreNotEqual(Pixel expected, Pixel actual)
    {
      Assert.IsNotNull(expected);
      Assert.IsNotNull(actual);

      AreNotEqual(expected.ToColor(), actual.ToColor());
    }
Beispiel #15
0
 public DataInfo(int dataSize, XRayInfoIDStruct xrayInfo, byte numberOfBytesPerPixel)
 {
     LineData = new Pixel[dataSize];
     NumberOfBytesPerPixel = numberOfBytesPerPixel;
     XRayInfo = xrayInfo;
     TotalBytesReceived = 0;
 }
        public double GetDrawingFitness(DnaDrawing newDrawing, Pixel[] sourcePixels)
        {
            double error = 0;

            Renderer.Render(newDrawing, _g, 1);

            BitmapData bd = _bmp.LockBits(
                new Rectangle(0, 0, Tools.MaxWidth, Tools.MaxHeight),
                ImageLockMode.ReadOnly,
                PixelFormat.Format32bppArgb);

            unchecked
            {
                unsafe
                {
                    fixed (Pixel* psourcePixels = sourcePixels)
                    {
                        Pixel* p1 = (Pixel*)bd.Scan0.ToPointer();
                        Pixel* p2 = psourcePixels;
                        for (int i = sourcePixels.Length; i > 0; i--, p1++, p2++)
                        {
                            int a = p1->A - p2->A; //delete
                            int r = p1->R - p2->R;
                            int g = p1->G - p2->G;
                            int b = p1->B - p2->B;
                            error += r * r + g * g + b * b;
                        }
                    }
                }
            }
            _bmp.UnlockBits(bd);

            return error;
        }
Beispiel #17
0
 public static void PixelToBytes(Pixel[] src, int srcIndex, ref byte[] bytes, ref int destIndex, int bytesPerPixel)
 {
     for (int index = 0; index < bytesPerPixel; index++)
     {
         bytes[destIndex++] = (byte)(src[srcIndex].Value >> (index * 8));
     }
 }
 protected override void changeQueue(Pixel p)
 {
     for (int i = 0; i < p.Neighbors.Length; i++)
     {
         Pixel np = p.Neighbors[i];
         if (np.Empty)
         {
             // if p has an empty neighbor, it belongs in the queue
             if (p.QueueIndex == -1)
             {
                 queue.Add(p);
             }
         }
         else
         {
             // p has a filled neighbor, and p was just filled
             // so that neighbor may not belong in the queue anymore
             bool stillok = false;
             for (int j = 0; j < np.Neighbors.Length; j++)
             {
                 if (np.Neighbors[j].Empty)
                 {
                     stillok = true;
                     break;
                 }
             }
             if (!stillok)
                 queue.Remove(np);
         }
     }
 }
Beispiel #19
0
        public static Pixel[] start()
        {
            Pixel[] pixels = new Pixel[Constants.WIN_X * Constants.WIN_Y];
             Point3 viewPlane = new Point3(-Constants.WIN_X / 2, -Constants.WIN_X / 2, 0);

             createScene();

             for (int y = 0; y < Constants.WIN_Y; y++)
             {
            for (int x = 0; x < Constants.WIN_X; x++)
            {
               Pixel p = new Pixel();
               p.rect.X = x;
               p.rect.Y = Constants.WIN_Y - 1 - y;

               Point3 viewPixel = new Point3();
               viewPixel.x = viewPlane.x + x;
               viewPixel.y = viewPlane.y + y;
               viewPixel.z = viewPlane.z;

               Ray r = new Ray();
               r.direction = Point3.vectorize(layout.Cam.Eye, viewPixel);
               r.start = layout.Cam.Eye;

               p.color = fireRay(r, Constants.MIN_DEPTH, null);

               pixels[y * Constants.WIN_X + x] = p;
            }
             }

             return pixels;
        }
 public static bool IsBlack(Pixel p)
 {
     if (p.R == 0 && p.G == 0 && p.B == 0)
         return true;
     else
         return false;
 }
Beispiel #21
0
        public override void Map(Pixel[] image)
        {
            List<Pixel[]> tiles = new List<Pixel[]>();
            List<MapInfo> infos = new List<MapInfo>();
            int tileLength = this.TileSize.Width * this.TileSize.Height;

            // Get tiles
            for (int i = 0; i < mappedImage.Length; i += tileLength) {
                Pixel[] tile = new Pixel[tileLength];
                Array.Copy(mappedImage, i, tile, 0, tileLength);
                tiles.Add(tile);
            }

            // Perfom search
            for (int i = 0; i < image.Length; i += tileLength) {
                // Get tile
                Pixel[] tile = new Pixel[tileLength];
                Array.Copy(image, i, tile, 0, tileLength);

                bool flipX;
                bool flipY;
                int index = CompressMapping.Search(tile, tiles, this.TileSize, out flipX, out flipY);

                if (index == -1)
                    throw new Exception("Tile not found.");

                // Finally create map info
                infos.Add(new MapInfo(index, 0, flipX, flipY));
            }

            this.mapInfo = infos.ToArray();
        }
Beispiel #22
0
 public ColorClose(Pixel key, int tola, int tolb)
 {
     _key = key.YCbCr();
     _tola = tola;
     _tolb = tolb;
     _tolba = _tolb - _tola;
 }
Beispiel #23
0
 public Node( Pixel data, int level )
 {
     // This creates a leaf by default.
     //location = (NodeLocation)(-1);
     this.level = level;
     BecomeLeaf( data );
 }
Beispiel #24
0
 public Node( Pixel data )
 {
     // This creates a leaf by default.
     //location = (NodeLocation)(-1);
     level = Lightmap.BlockFactor;
     BecomeLeaf( data );
 }
Beispiel #25
0
        public double Dispersion { get; set; } // Величина разброса точек регионов для сегментируемого изображения

        /// <summary>
        /// Конструктор класса создает начальное разбиение изображения на сегменты заданного размера
        /// </summary>
        /// <param name="rgbData">Матрица цветов пикселей, в каждой строке которой записаны компоненты r, g и b</param>
        /// <param name="imageHeight">Высота изображения</param>
        /// <param name="imageWidth">Ширина изображения</param>
        /// <param name="defaultSegmentSize">Начальный размер квадратного сегмента</param>
        public SegmentedImage(int[][] rgbData, int imageHeight, int imageWidth, int defaultSegmentSize)
        {
            Height = imageHeight;
            Width = imageWidth;
            Regions = new List<Region>();

            // создание начальных регионов размером defaultSegmentSize х defaultSegmentSize
            for (int i = 0; i < imageHeight; i += defaultSegmentSize)
            {
                for (int j = 0; j < imageWidth; j += defaultSegmentSize)
                {
                    int regionHeight = imageHeight - i < defaultSegmentSize ? imageHeight - i : defaultSegmentSize;
                    int regionWidth = imageWidth - j < defaultSegmentSize ? imageWidth - j : defaultSegmentSize;
                    Pixel[] pixels = new Pixel[regionHeight * regionWidth];
                    for (int x = 0; x < regionHeight; x++)
                    {
                        for (int y = 0; y < regionWidth; y++)
                        {
                            int[] pixelId = { i + x, j + y };
                            pixels[(x * regionWidth) + y] = new Pixel(pixelId, rgbData[((i + x) * imageWidth) + (j + y)]);
                        }
                    }
                    Region region = new Region(pixels);
                    Regions.Add(region);
                }
            }
        }
Beispiel #26
0
 public ArtNetData(short universe, byte physical, byte sequence, short len, Pixel[] Pixels, byte[] raw)
 {
     this.universe = universe;
     this.physical = physical;
     this.sequence = sequence;
     this.length = len;
     this.Pixels = Pixels;
 }
 /// <summary>
 /// Quantize pixel intensity to two levels.
 /// Intensity and pixel coordinates are given separately.
 /// Intensity can include diffused error, so it's of double type.
 /// </summary>
 /// <param name="intensity">Intensity to be quantized (0.0-255.0)
 /// </param>
 /// <param name="x">Pixel X coordinate</param>
 /// <param name="y">Pixel Y coordinate</param>
 /// <returns>Pixel with quantized intensity (0-255)</returns>
 public Pixel quantize(double intensity, int x, int y)
 {
     Pixel pixel = new Pixel(1) { X = x, Y = y};
     pixel[0] = (intensity < threshold((int)intensity, x, y)) ? 0 : 255;
     //pixel[0] = ((int)Math.Floor((intensity - threshold((int)intensity, x, y))/256.0 + 1)) * 255;
     //pixel[0] = threshold((int)intensity, x, y); // DEBUG
     return pixel;
 }
 public Targa(String file, Pixel[] pix, short w, short h, byte bpp)
 {
     pixels = pix;
     width = w;
     height = h;
     bitsPerPixel = bpp;
     filename = file;
 }
        public Pixel GetPixelPos(int x, int y)
        {
            pixelData = (PixelData*)(pBase + y * width + x * sizeof(PixelData));

            Color c =  Color.FromArgb(pixelData->alpha, pixelData->red, pixelData->green, pixelData->blue);
            Pixel p = new Pixel(x,y,c);
            return p;
        }
 public static Pixel FromColor(Color c)
 {
     Pixel res = new Pixel();
     res.R = c.R;
     res.G = c.G;
     res.B = c.B;
     res.A = c.A;
     return res;
 }
Beispiel #31
0
 public void setDoublePlant(PixelPos lowerPos, Pixel doublePlant, int flag)
 {
     this.world.setPixelState(lowerPos, doublePlant.withProperty(0));
     this.world.setPixelState(lowerPos.up(), doublePlant.withProperty(1)); //PixelDoublePlant.HALF  || PixelDoublePlant.UPPER));
 }
Beispiel #32
0
 public void RemovePixel(Pixel pixel)
 {
     pixels.Remove(pixel);
     pixel.RemoveGroup();
 }
Beispiel #33
0
    public static Sprite GetSpriteSlice(Sprite sprite, int slices, int index, bool horizontal)
    {
        if (horizontal)
        {
            Sprite[] sprites    = new Sprite[slices];
            int      sliceWidth = sprite.width / slices;
            for (var i = 0; i < sprites.Length; i++)
            {
                sprites[i]        = new Sprite();
                sprites[i].sprite = new Pixel[sprite.height * sliceWidth];
            }

            for (var i = 0; i < sprites.Length; i++)
            {
                sprites[i].width  = sliceWidth;
                sprites[i].height = sprite.height;

                for (var x = 0; x < sliceWidth; x++)
                {
                    for (var y = 0; y < sprite.height; y++)
                    {
                        Pixel pixel = sprite.sprite[Index((i * sliceWidth) + x, y, sprite.width)];

                        sprites[i].sprite[Index(x, y, sliceWidth)].Attributes       = pixel.Attributes;
                        sprites[i].sprite[Index(x, y, sliceWidth)].Char.UnicodeChar = pixel.Char.UnicodeChar;
                    }
                }
            }

            if (index < 0 || index > sprites.Length)
            {
                index = 0;
            }
            return(sprites[index]);
        }
        else
        {
            Sprite[] sprites     = new Sprite[slices];
            int      sliceHeight = sprite.height / slices;
            for (var i = 0; i < sprites.Length; i++)
            {
                sprites[i]        = new Sprite();
                sprites[i].sprite = new Pixel[sprite.width * sliceHeight];
            }

            for (var i = 0; i < sprites.Length; i++)
            {
                sprites[i].width  = sprite.width;
                sprites[i].height = sliceHeight;

                for (var x = 0; x < sprite.width; x++)
                {
                    for (var y = 0; y < sliceHeight; y++)
                    {
                        Pixel pixel = sprite.sprite[Index(x, (i * sliceHeight) + y, sprite.width)];

                        sprites[i].sprite[Index(x, y, sprite.width)].Attributes       = pixel.Attributes;
                        sprites[i].sprite[Index(x, y, sprite.width)].Char.UnicodeChar = pixel.Char.UnicodeChar;
                    }
                }
            }

            if (index < 0 || index > sprites.Length)
            {
                index = 0;
            }
            return(sprites[index]);
        }
    }
 /// <summary>
 /// Interpolates color value for a missing pixel <paramref name="x"/> using the set of boundary pixels <paramref name="y"/>,
 /// according to the <paramref name="colorInterpolator"/> algorithm.
 /// </summary>
 /// <param name="missingPixel">Pixel that missing color in the image.</param>
 /// <param name="boundaryPixels">Set of boundary pixels.</param>
 /// <param name="colorInterpolator">Color interpolation algorithm.</param>
 /// <returns></returns>
 public static float InterpolateColor(Pixel missingPixel, ICollection <Pixel> boundaryPixels, ColorInterpolatorBase colorInterpolator)
 {
     return(colorInterpolator.InterpolateColor(missingPixel, boundaryPixels));
 }
Beispiel #35
0
        static void Main(string[] args)
        {
            ReadBMP("title.txt", ref title);
            ReadBMP("gameOver.txt", ref gameOver);

            for (int i = 0; i < background.GetLength(0); i++)
            {
                for (int j = 0; j < background.GetLength(1); j++)
                {
                    if (i < background.GetLength(0) - 2)
                    {
                        background[i, j] = dullerRainbow[j];
                        board[i, j]      = dullerRainbow[j];
                    }
                    else
                    {
                        background[i, j] = new Pixel(0, 0, 0);
                        board[i, j]      = new Pixel(0, 0, 0);
                    }
                }
            }

            IDisplay display = new ArduinoDisplay();

            state = State.Title;

            while (true)
            {
                if (state == State.Playing)
                {
                    UpdateCats();
                    UpdateLasers();
                    UpdateFallingStuff();
                    UpdateBat();

                    Thread.Sleep(50);

                    int catsAlive = 0;

                    foreach (int c in cats)
                    {
                        if (c == 1)
                        {
                            catsAlive++;
                        }
                    }

                    display.DisplayInts(catsAlive, score);

                    bool allCatsDead = true;

                    foreach (int i in cats)
                    {
                        if (i == 1)
                        {
                            allCatsDead = false;
                            break;
                        }
                    }

                    if (allCatsDead)
                    {
                        state = State.GameOver;
                    }
                }
                else if (state == State.Title)
                {
                    UpdateTitle();
                }
                else if (state == State.GameOver)
                {
                    UpdateGameOver();
                }
                display.Draw(board);
            }
        }
Beispiel #36
0
 public SurfaceMountainPolar(BiomeConfig config, Pixel top, Pixel fill, float minCliff) : base(config, top, fill)
 {
     min = minCliff;
 }
 private static void AreNotEqual(MagickColor expected, Pixel actual)
 {
     AreNotEqual(expected, actual.ToColor());
 }
        public static void Generate(
            ImageMeta image,
            float maxInside,
            float maxOutside,
            float postProcessDistance)
        {
            width  = image.width;
            height = image.height;

            img = image;

            pixels = new Pixel[width, height];
            int   x, y;
            float scale;

            //Color c = Color.black;

            for (y = 0; y < height; y++)
            {
                for (x = 0; x < width; x++)
                {
                    pixels[x, y] = new Pixel();
                }
            }

            if (maxInside > 0f)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        pixels[x, y].originalValue = 1f - image.PixelUnSafe(x, y).grayscale;
                    }
                }

                ComputeEdgeGradients();
                GenerateDistanceTransform();
                if (postProcessDistance > 0f)
                {
                    PostProcess(postProcessDistance);
                }

                scale = 1f / maxInside;

                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        SetColor(x, y, Mathf.Clamp01(pixels[x, y].distance * scale), scale);
                    }
                }
            }

            if (maxOutside > 0f)
            {
                for (y = 0; y < height; y++)
                {
                    for (x = 0; x < width; x++)
                    {
                        pixels[x, y].originalValue = image.PixelUnSafe(x, y).r;
                    }
                }

                ComputeEdgeGradients();
                GenerateDistanceTransform();
                if (postProcessDistance > 0f)
                {
                    PostProcess(postProcessDistance);
                }

                scale = 1f / maxOutside;
                if (maxInside > 0f)
                {
                    for (y = 0; y < height; y++)
                    {
                        for (x = 0; x < width; x++)
                        {
                            float value = 0.5f + (image.PixelUnSafe(x, y).r - Mathf.Clamp01(pixels[x, y].distance * scale)) * 0.5f;
                            SetColor(x, y, value, scale);
                        }
                    }
                }
                else
                {
                    for (y = 0; y < height; y++)
                    {
                        for (x = 0; x < width; x++)
                        {
                            var value = Mathf.Clamp01(1f - pixels[x, y].distance * scale);
                            SetColor(x, y, value, scale);
                        }
                    }
                }
            }


            pixels = null;
        }
        private void EdgeDetection()
        {
            var dialog = new OpenFileDialog
            {
                InitialDirectory = @"D:\OneDrive",
                Filter           = "Bitmap|*.bmp;*.jpg;*.jpeg;*.png;"
            };

            if (dialog.ShowDialog() == true)
            {
                var scale = 0.4;
                var path  = dialog.FileName;

                var sources = new PixelMap[2];

                GetPixelMap(path, sources);

                var source = sources[0];

                var imaging = new ImagingManager(source);
                imaging.AddFilter(new BicubicFilter(scale)); //Downscaling
                imaging.Render();

                imaging.AddFilter(new CannyEdgeDetector());
                imaging.Render();

                var blobCounter = new BlobCounter
                {
                    ObjectsOrder = ObjectsOrder.Size
                };
                imaging.AddFilter(blobCounter);

                imaging.Render();

                List <Point> corners = null;
                var          blobs   = blobCounter.GetObjectsInformation();
                foreach (var blob in blobs)
                {
                    var points = blobCounter.GetBlobsEdgePoints(blob);

                    var shapeChecker = new SimpleShapeChecker();

                    if (shapeChecker.IsQuadrilateral(points, out corners))
                    {
                        break;
                    }
                }

                var edgePoints = new EdgePoints();
                edgePoints.SetPoints(corners.ToArray());

                var line1 = new Line
                {
                    X1 = edgePoints.TopLeft.X,
                    Y1 = edgePoints.TopLeft.Y,
                    X2 = edgePoints.BottomLeft.X,
                    Y2 = edgePoints.BottomLeft.Y
                };
                var line2 = new Line
                {
                    X1 = edgePoints.BottomLeft.X,
                    Y1 = edgePoints.BottomLeft.Y,
                    X2 = edgePoints.BottomRight.X,
                    Y2 = edgePoints.BottomRight.Y
                };
                var line3 = new Line
                {
                    X1 = edgePoints.BottomRight.X,
                    Y1 = edgePoints.BottomRight.Y,
                    X2 = edgePoints.TopRight.X,
                    Y2 = edgePoints.TopRight.Y
                };
                var line4 = new Line
                {
                    X1 = edgePoints.TopRight.X,
                    Y1 = edgePoints.TopRight.Y,
                    X2 = edgePoints.TopLeft.X,
                    Y2 = edgePoints.TopLeft.Y
                };
                var pixel = new Pixel(255, 255, 0, 0);
                imaging.AddFilter(new LineDrawFilter(line1, pixel));
                imaging.AddFilter(new LineDrawFilter(line2, pixel));
                imaging.AddFilter(new LineDrawFilter(line3, pixel));
                imaging.AddFilter(new LineDrawFilter(line4, pixel));

                imaging.Render();
                image.Source = LoadFromPixelMap(imaging.Output);

                imaging.UndoAll();

                edgePoints = edgePoints.ZoomIn(scale);
                imaging.AddFilter(new QuadrilateralTransformation(edgePoints, true));

                imaging.Render();
                image2.Source = LoadFromPixelMap(imaging.Output);

                SaveImageToFile(LoadFromPixelMap(imaging.Output), @"D:\Desktop\2.jpg");
            }
        }
Beispiel #40
0
        override public void paintTerrain(Chunk primer, int i, int j, int x, int z, int depth, RTGWorld rtgWorld, float[] noise, float river, Biome[] _base)
        {
            Random rand  = rtgWorld.rand;
            float  c     = CliffCalculator.calc(x, z, noise);
            bool   cliff = c > 1.3f;

            for (int k = 255; k > -1; k--)
            {
                Pixel b = primer.getPixelState(x, k, z).getPixel();
                if (b == Pixels.AIR)
                {
                    depth = -1;
                }
                else if (b == Pixels.STONE)
                {
                    depth++;

                    if (depth > -1 && depth < 12)
                    {
                        if (cliff)
                        {
                            primer.setPixelState(x, k, z, CanyonColour.MESA.getPixelForHeight(i, k, j));
                        }
                        else
                        {
                            if (depth > 4)
                            {
                                primer.setPixelState(x, k, z, CanyonColour.MESA.getPixelForHeight(i, k, j));
                            }
                            else if (k > 74 + grassRaise)
                            {
                                if (rand.Next(5) == 0)
                                {
                                    primer.setPixelState(x, k, z, Pixels.DIRT);
                                }
                                else
                                {
                                    if (depth == 0)
                                    {
                                        primer.setPixelState(x, k, z, topPixel);
                                    }
                                    else
                                    {
                                        primer.setPixelState(x, k, z, fillerPixel);
                                    }
                                }
                            }
                            else if (k < 62)
                            {
                                primer.setPixelState(x, k, z, Pixels.DIRT);
                            }
                            else if (k < 62 + grassRaise)
                            {
                                if (depth == 0)
                                {
                                    primer.setPixelState(x, k, z, Pixels.GRASS);
                                }
                                else
                                {
                                    primer.setPixelState(x, k, z, Pixels.DIRT);
                                }
                            }
                            else if (k < 75 + grassRaise)
                            {
                                if (depth == 0)
                                {
                                    int r = (int)((k - (62 + grassRaise)) / 2f);
                                    if (rand.Next(r + 1) == 0)
                                    {
                                        primer.setPixelState(x, k, z, Pixels.GRASS);
                                    }
                                    else if (rand.Next((int)(r / 2f) + 1) == 0)
                                    {
                                        primer.setPixelState(x, k, z, Pixels.DIRT);
                                    }
                                    else
                                    {
                                        primer.setPixelState(x, k, z, topPixel);
                                    }
                                }
                                else
                                {
                                    primer.setPixelState(x, k, z, fillerPixel);
                                }
                            }
                            else
                            {
                                if (depth == 0)
                                {
                                    primer.setPixelState(x, k, z, topPixel);
                                }
                                else
                                {
                                    primer.setPixelState(x, k, z, fillerPixel);
                                }
                            }
                        }
                    }
                    else if (k > 63)
                    {
                        primer.setPixelState(x, k, z, CanyonColour.MESA.getPixelForHeight(i, k, j));
                    }
                }
            }
        }
Beispiel #41
0
 public Image(int width, int height)
 {
     PixelGrid   = new Pixel[height, width];
     AspectRatio = (double)width / height;
 }
Beispiel #42
0
 public override void Render(Image i, BoundingBox clip, AffineTransform trans, string text, Vec2 loc, Pixel color)
 {
     GetTextRenderer().Render(i, clip, trans, text, loc, color);
 }
Beispiel #43
0
 /// <summary>
 /// Add a pixel to the list of participating pixels
 /// </summary>
 /// <param name="pixel"></param>
 public void AddParticipatingPixel(Pixel pixel)
 {
     _pixels.Add(pixel);
 }
        public void FilterTest(string filter)
        {
            string autumnImg;
            string normalPath = TestHelper.GetTestsPath();

            if (filter == "Median")
            {
                autumnImg = normalPath + @"\data\autumnMedian.bmp";
            }
            else if (filter == "GrayScale")
            {
                autumnImg = normalPath + @"\data\autumnGS.bmp";
            }
            else if (filter == "SobelX")
            {
                autumnImg = normalPath + @"\data\autumnSobelX.bmp";
            }
            else if (filter == "SobelY")
            {
                autumnImg = normalPath + @"\data\autumnSobelY.bmp";
            }
            else
            {
                autumnImg = normalPath + @"\data\autumnGauss.bmp";
            }
            string fileName = normalPath + @"\data\tiger.bmp";

            System.Console.WriteLine(fileName);
            string newName = normalPath + @"\data\test.bmp";
            Image  testImage = new Image();
            Image  autumnImage = new Image();
            uint   height = 0, width = 0;

            testImage.ReadImage(fileName);
            testImage.ApplyFilters(newName, filter);
            autumnImage.ReadImage(autumnImg);
            testImage.GetAtrs(ref height, ref width);
            Pixel[][] pixArr = new Pixel[height][];
            for (int i = 0; i < height; i++)
            {
                pixArr[i] = new Pixel[width];
            }
            testImage.GetArr(pixArr);
            Pixel[][] autumnArr = new Pixel[height][];
            for (int i = 0; i < height; i++)
            {
                autumnArr[i] = new Pixel[width];
            }
            autumnImage.GetArr(autumnArr);
            for (uint i = 0; i < height; i++)
            {
                for (uint k = 0; k < width; k++)
                {
                    Assert.AreEqual(autumnArr[i][k].Red, pixArr[i][k].Red);
                    Assert.AreEqual(autumnArr[i][k].Blue, pixArr[i][k].Blue);
                    Assert.AreEqual(autumnArr[i][k].Green, pixArr[i][k].Green);
                    Assert.AreEqual(autumnArr[i][k].Alpha, pixArr[i][k].Alpha);
                }
            }
            Assert.Pass();
        }
Beispiel #45
0
 public static WriteableBitmap ToColorGR(this Pixel <int> src, byte[] buf = null, WriteableBitmap dst = null)
 {
     return(ToColor(src, ColorConversionCodes.BayerGR2BGR, buf, dst));
 }
Beispiel #46
0
 public void ZoomOnPixel(Pixel pixel)
 {
     NormalizeCamera(pixel.transform.position);
 }
Beispiel #47
0
        /// <summary>
        /// Allocate pixel data for this Image.
        /// </summary>
        /// <param name="format">
        /// A <see cref="PixelLayout"/> indicating the image pixel format.
        /// </param>
        /// <param name="w">
        /// A <see cref="Int32"/> indicating the image width, in pixels.
        /// </param>
        /// <param name="h">
        /// A <see cref="Int32"/> indicating the image height, in pixels.
        /// </param>
        public void Create(PixelLayout format, uint w, uint h)
        {
            PixelLayoutInfo formatInfo = Pixel.GetPixelFormat(format);

            switch (format)
            {
            // Single plane formats
            case PixelLayout.GRAY8:
            case PixelLayout.GRAY16:
            case PixelLayout.GRAYF:
            case PixelLayout.GRAYHF:
            case PixelLayout.GRAYAF:
            case PixelLayout.RGB8:
            case PixelLayout.RGB15:
            case PixelLayout.RGB16:
            case PixelLayout.RGB24:
            case PixelLayout.RGB48:
            case PixelLayout.RGBF:
            case PixelLayout.RGBHF:
            case PixelLayout.RGBD:
            case PixelLayout.SRGB24:
            case PixelLayout.SBGR24:
            case PixelLayout.RGB30A2:
            case PixelLayout.RGBA32:
            case PixelLayout.RGBA64:
            case PixelLayout.RGBAF:
            case PixelLayout.RGBAHF:
            case PixelLayout.BGR8:
            case PixelLayout.BGR15:
            case PixelLayout.BGR16:
            case PixelLayout.BGR24:
            case PixelLayout.BGR48:
            case PixelLayout.BGRF:
            case PixelLayout.BGRHF:
            case PixelLayout.BGR30A2:
            case PixelLayout.BGRA32:
            case PixelLayout.BGRA64:
            case PixelLayout.BGRAF:
            case PixelLayout.BGRAHF:
            case PixelLayout.CMY24:
            case PixelLayout.CMYK32:
            case PixelLayout.CMYK64:
            case PixelLayout.CMYKA40:
            case PixelLayout.Depth16:
            case PixelLayout.Depth24:
            case PixelLayout.Depth32:
            case PixelLayout.DepthF:
            case PixelLayout.Depth24Stencil8:
            case PixelLayout.Depth32FStencil8:
            case PixelLayout.Integer1:
            case PixelLayout.Integer2:
            case PixelLayout.Integer3:
            case PixelLayout.Integer4:
            case PixelLayout.UInteger1:
            case PixelLayout.UInteger2:
            case PixelLayout.UInteger3:
            case PixelLayout.UInteger4:
                _PixelBuffers = new AlignedMemoryBuffer(w * h * formatInfo.PixelBytes, 16);
                // Define planes
                _PixelPlanes = new IntPtr[] { _PixelBuffers.AlignedBuffer };
                break;

            case PixelLayout.YUYV:
            case PixelLayout.YYUV:
            case PixelLayout.YVYU:
            case PixelLayout.UYVY:
            case PixelLayout.VYUY:
                if (((w % 2) != 0) || ((h % 2) != 0))
                {
                    throw new InvalidOperationException(String.Format("invalid image extents for pixel format {0}", format));
                }
                // Define planes
                _PixelBuffers = new AlignedMemoryBuffer(w * h * formatInfo.PixelBytes, 16);
                _PixelPlanes  = new IntPtr[] { _PixelBuffers.AlignedBuffer };
                break;

            case PixelLayout.YVU410:
            case PixelLayout.YUV410:
                if (((w % 16) != 0) || ((h % 16) != 0))
                {
                    throw new InvalidOperationException(String.Format("invalid image extents for pixel format {0}", format));
                }
                _PixelBuffers = new AlignedMemoryBuffer(w * h + (w * h / 16) * 2, 16);
                // Define planes
                _PixelPlanes    = new IntPtr[3];
                _PixelPlanes[0] = _PixelBuffers.AlignedBuffer;
                _PixelPlanes[1] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h);
                _PixelPlanes[2] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h + (w * h / 16));
                break;

            case PixelLayout.YVU420:
            case PixelLayout.YUV420:
                if (((w % 4) != 0) || ((h % 4) != 0))
                {
                    throw new InvalidOperationException(String.Format("invalid image extents for pixel format {0}", format));
                }
                _PixelBuffers = new AlignedMemoryBuffer(w * h + (w * h / 4), 16);
                // Define planes
                _PixelPlanes    = new IntPtr[3];
                _PixelPlanes[0] = _PixelBuffers.AlignedBuffer;
                _PixelPlanes[1] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h);
                _PixelPlanes[2] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h + (w * h / 4));
                break;

            case PixelLayout.YUV422P:
                if ((w % 2) != 0)
                {
                    throw new InvalidOperationException(String.Format("invalid image extents for pixel format {0}", format));
                }
                _PixelBuffers = new AlignedMemoryBuffer(w * h + (w * h / 2), 16);
                // Define planes
                _PixelPlanes    = new IntPtr[3];
                _PixelPlanes[0] = _PixelBuffers.AlignedBuffer;
                _PixelPlanes[1] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h);
                _PixelPlanes[2] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h + (w * h / 2));
                break;

            case PixelLayout.YUV411P:
                if ((w % 4) != 0)
                {
                    throw new InvalidOperationException(String.Format("invalid image extents for pixel format {0}", format));
                }
                _PixelBuffers = new AlignedMemoryBuffer(w * h + (w * h / 4), 16);
                // Define planes
                _PixelPlanes    = new IntPtr[3];
                _PixelPlanes[0] = _PixelBuffers.AlignedBuffer;
                _PixelPlanes[1] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h);
                _PixelPlanes[2] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h + (w * h / 4));
                break;

            case PixelLayout.Y41P:
                if ((w % 8) != 0)
                {
                    throw new InvalidOperationException(String.Format("invalid image extents for pixel format {0}", format));
                }
                _PixelBuffers = new AlignedMemoryBuffer(w * h * 12 / 8, 16);
                // Define planes
                _PixelPlanes    = new IntPtr[3];
                _PixelPlanes[0] = _PixelBuffers.AlignedBuffer;
                _PixelPlanes[1] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h);
                _PixelPlanes[2] = new IntPtr(_PixelBuffers.AlignedBuffer.ToInt64() + w * h + (w * h / 4));
                break;

            default:
                throw new NotSupportedException(String.Format("pixel format {0} is not supported", format));
            }
            // Set image information
            _ImageInfo.PixelType = formatInfo.DataFormat;
            _ImageInfo.Width     = w;
            _ImageInfo.Height    = h;
            // Store pixel format
            _PixelFormat = formatInfo;

            Debug.Assert(_PixelPlanes != null);
            Debug.Assert(_PixelPlanes.Length != 0);
            Debug.Assert(Array.TrueForAll(_PixelPlanes, delegate(IntPtr pixelPlane) { return(pixelPlane != IntPtr.Zero); }));
        }
 public LineDrawFilter(Line line, Pixel pixel)
 {
     Line  = line;
     Pixel = pixel;
 }
Beispiel #49
0
    public static void GenerateSDF(Texture2D source, Texture2D destination)
    {
        int sourceWidth  = source.width;
        int sourceHeight = source.height;
        int targetWidth  = destination.width;
        int targetHeight = destination.height;

        var pixels       = new Pixel[sourceWidth, sourceHeight];
        var targetPixels = new Pixel[targetWidth, targetHeight];

        int   x, y;
        Color targetColor = Color.white;

        for (x = 0; x < sourceWidth; x++)
        {
            for (y = 0; y < sourceHeight; y++)
            {
                pixels[x, y] = new Pixel();
                if (source.GetPixel(x, y).a >= 1f)
                {
                    pixels[x, y].isIn = true;
                }
                else
                {
                    pixels[x, y].isIn = false;
                }
            }
        }


        float gapX = (sourceWidth / (float)targetWidth);
        float gapY = (sourceHeight / (float)targetHeight);

        Debug.Log($"{sourceWidth}_{targetWidth}_{gapX},{sourceHeight}_{targetHeight}_{gapY}");

        int   MAX_SEARCH_DIST = 512;
        int   minx, maxx, miny, maxy;
        float max_distance = -MAX_SEARCH_DIST;
        float min_distance = MAX_SEARCH_DIST;

        for (x = 0; x < targetWidth; x++)
        {
            for (y = 0; y < targetHeight; y++)
            {
                targetPixels[x, y] = new Pixel();
                int sourceX = (int)(x * gapX);
                int sourceY = (int)(y * gapY);
                int min     = MAX_SEARCH_DIST;
                minx = sourceX - MAX_SEARCH_DIST;
                if (minx < 0)
                {
                    minx = 0;
                }

                miny = sourceY - MAX_SEARCH_DIST;
                if (miny < 0)
                {
                    miny = 0;
                }

                maxx = sourceX + MAX_SEARCH_DIST;
                if (maxx > (int)sourceWidth)
                {
                    maxx = sourceWidth;
                }

                maxy = sourceY + MAX_SEARCH_DIST;
                if (maxy > (int)sourceHeight)
                {
                    maxy = sourceHeight;
                }

                int  dx, dy, iy, ix, distance;
                bool sourceIsInside = pixels[sourceX, sourceY].isIn;
                if (sourceIsInside)
                {
                    for (iy = miny; iy < maxy; iy++)
                    {
                        dy  = iy - sourceY;
                        dy *= dy;
                        for (ix = minx; ix < maxx; ix++)
                        {
                            bool targetIsInside = pixels[ix, iy].isIn;
                            if (targetIsInside)
                            {
                                continue;
                            }

                            dx       = ix - sourceX;
                            distance = (int)Mathf.Sqrt(dx * dx + dy);
                            if (distance < min)
                            {
                                min = distance;
                            }
                        }
                    }

                    if (min > max_distance)
                    {
                        max_distance = min;
                    }

                    targetPixels[x, y].distance = min;
                }
                else
                {
                    for (iy = miny; iy < maxy; iy++)
                    {
                        dy  = iy - sourceY;
                        dy *= dy;
                        for (ix = minx; ix < maxx; ix++)
                        {
                            bool targetIsInside = pixels[ix, iy].isIn;
                            if (!targetIsInside)
                            {
                                continue;
                            }

                            dx       = ix - sourceX;
                            distance = (int)Mathf.Sqrt(dx * dx + dy);
                            if (distance < min)
                            {
                                min = distance;
                            }
                        }
                    }

                    if (-min < min_distance)
                    {
                        min_distance = -min;
                    }

                    targetPixels[x, y].distance = -min;
                }
            }
        }

        //EXPORT texture
        float clampDist = max_distance - min_distance;

        for (x = 0; x < targetWidth; x++)
        {
            for (y = 0; y < targetHeight; y++)
            {
                targetPixels[x, y].distance -= min_distance;
                float value = targetPixels[x, y].distance / clampDist;
                destination.SetPixel(x, y, new Color(1, 1, 1, value));
                destination.Apply(true);
            }
        }
    }
Beispiel #50
0
        // WaitForMapToChange() : attend le changement de la Map
        private void WaitForMapToChange()
        {
            Log.Title(Log.Level.Debug, "WaitForMapToChange");

            // on vérifie que si la Map a changée ou pas, en respectant un temp maximum de vérification
            int          checkTime          = 0;
            List <Color> PixelsToCheckColor = Map.GetPixelsToCheckColor(GameHandle); // couleur actuelle des pixels à vérifier

            // informations de débogage
            int i = 0;

            foreach (Point pixel in Map.PixelsToCheck)
            {
                Log.Debug("Map Pixel (X: " + pixel.X + " Y: " + pixel.Y + ") Color (R: " + PixelsToCheckColor[i].R + " G: " + PixelsToCheckColor[i].G + " B: " + PixelsToCheckColor[i].B + ")");
                i++;
            }
            Log.Divider(Log.Level.Debug);

            while (checkTime < Map.MaxLoadTimeout)
            {
                _pauseEvent.WaitOne();
                if (_shutdownEvent.WaitOne(0))
                {
                    break;
                }

                // si la Map a changée
                bool mapChanged = Settings.MapChangeCheckPrecision == 0 ? Pixel.ColorChanged(Map.PixelsToCheck, PixelsToCheckColor, GameHandle) : Pixel.AllColorChanged(Map.PixelsToCheck, PixelsToCheckColor, GameHandle);
                if (mapChanged)
                {
                    Wait(Settings.MapLoadTimeout);
                    return;
                }

                Thread.Sleep(1000);
                checkTime += 1000;
            } // fin while {}

            if (!_shutdownEvent.WaitOne(0)) // si le bot n'a pas été arrêté
            {
                // si on arrive içi c'est qu'il y'a eu un problème (Timeout dépassé, la map n'a pas changée, on est bloqué, beug, ...)
                if (Connection.State())
                {
                    Log.Error("La map ne change pas, veuillez vérifier/modifier le trajet.");
                }
                else // connexion perdue
                {
                    Log.Error("Connexion perdue");
                }

                Suspend();
            }
        }
Beispiel #51
0
        public void Should_have_a_symbol(double value)
        {
            IUnit actual = new Pixel(value);

            Assert.AreEqual(Pixel.Symbol, actual.Symbol);
        }
Beispiel #52
0
        //=========================================================================================================================
        //                                                  Job méthodes
        //=========================================================================================================================

        #region Job
        // DoJob(...) : gère le métier du bot
        private void DoJob(String AreaFile)
        {
            Log.Title(Log.Level.Debug, "DoJob");
            //Log.Debug("AreaFile Path : " + AreaFile);

            try
            {
                // Lecture du fichier des ressources
                string[] resources = File.ReadAllLines(AreaFile);

                // Parcours des emplacements des ressources
                List <Point> resourceLocations = new List <Point>();
                foreach (string resource in resources)
                {
                    _pauseEvent.WaitOne();
                    if (_shutdownEvent.WaitOne(0))
                    {
                        break;
                    }

                    Log.Debug("Resource : " + resource);

                    // découpage des données de la ressource
                    string[] resourceData = Regex.Split(resource, "::");
                    string[] resourceXY   = Regex.Split(resourceData[1], "x");
                    string[] resourceRGB  = Regex.Split(resourceData[2], ",");

                    int   resourceX        = Int32.Parse(resourceXY[0]);
                    int   resourceY        = Int32.Parse(resourceXY[1]);
                    Point resourceLocation = new Point(resourceX, resourceY);

                    Color ResourceColor      = Color.FromArgb(Int32.Parse(resourceRGB[0]), Int32.Parse(resourceRGB[1]), Int32.Parse(resourceRGB[2]));
                    bool  checkResourceColor = Tools.stringToBool(resourceData[3]);

                    // s'il faut vérifier la couleur de la ressource + le pixel n'a pas la bonne couleur, on saute cette ressource alors
                    if (checkResourceColor && !Pixel.HasColor(resourceLocation, ResourceColor, GameHandle))
                    {
                        continue;
                    }

                    resourceLocations.Add(resourceLocation);
                }

                // si ressource(s) trouvée(s)
                if (resourceLocations.Count > 0)
                {
                    // affichage des positions des ressources sur la Minimap
                    foreach (Point loc in resourceLocations)
                    {
                        Minimap.NewPin(MinimapPictureBox, GamePanel.Size, loc, Minimap.ResourcePinColor);
                    }

                    // Au boulot !
                    foreach (Point location in resourceLocations)
                    {
                        _pauseEvent.WaitOne();
                        if (_shutdownEvent.WaitOne(0))
                        {
                            break;
                        }

                        // vérification de la connexion
                        if (!Connection.State())
                        {
                            Log.Error("Connexion perdue");
                            Suspend();
                            break;
                        }

                        // on s'assure que toutes les fenêtres popup sont fermés
                        CheckPopUps();

                        // on collecte/récolte la ressource si possible
                        if (location.X > 0 && location.Y > 0)
                        {
                            Log.Debug("Collecting Resource (X: " + location.X + " Y: " + location.Y + ")");

                            FakeClick.ClickOnPoint(GameHandle, location);
                            Wait(Job.MaxCollectTime);
                            Minimap.RemovePin(MinimapPictureBox, GamePanel.Size, location);
                            Job.CollectedResourceCount++;
                        }

                        // on vérifie si un combat est en cours
                        CheckFight();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Execption occured : " + ex.Message);
            }

            if (!_shutdownEvent.WaitOne(0)) // si le bot n'a pas été arrêté
            {
                Log.Debug("CollectedResourceCount : " + Job.CollectedResourceCount);

                Log.Divider(Log.Level.Debug);
            }
        }
Beispiel #53
0
 public Pixel(Pixel pixel)
 {
     x = pixel.X;
     y = pixel.Y;
 }
 protected sealed override Pixel ProcessPixel(Pixel original, LighteningParameters parameters)
 {
     return(original * parameters.Coefficient);
 }
Beispiel #55
0
 private static double CalcColor(Pixel pixel) => (0.299 * pixel.R + 0.587 * pixel.G + 0.114 * pixel.B) / 255;
Beispiel #56
0
 public InMaskPixel(Pixel pixel, int x, int y)
 {
     DecoratedPixel = pixel;
     MaskX          = x;
     MaskY          = y;
 }
Beispiel #57
0
        /**
         * Checks a given coordinate to see if it is surrounded by a given pixel, usually air.
         */
        public bool isSurroundedByPixel(Pixel checkPixel, int checkDistance, SurroundCheckType checkType, Random rand, int x, int y, int z)
        {
            switch (checkType)
            {
            case SurroundCheckType.FULL:     // Checks the entire radius around the coord.

                for (int ix = -checkDistance; ix <= checkDistance; ix++)
                {
                    for (int iz = -checkDistance; iz <= checkDistance; iz++)
                    {
                        if (x == ix && z == iz)
                        {
                            continue;
                        }

                        if (this.world.getPixelState(new PixelPos(x + ix, y, z + iz)) != checkPixel)
                        {
                            return(false);
                        }
                    }
                }

                break;

            case SurroundCheckType.CARDINAL:     // Checks the N/E/S/W directions around the coord.

                for (int i = checkDistance; i > 0; i--)
                {
                    if (this.world.getPixelState(new PixelPos(x, y, z + i)) != checkPixel)
                    {
                        return(false);
                    }
                    if (this.world.getPixelState(new PixelPos(x, y, z - i)) != checkPixel)
                    {
                        return(false);
                    }
                    if (this.world.getPixelState(new PixelPos(x + i, y, z)) != checkPixel)
                    {
                        return(false);
                    }
                    if (this.world.getPixelState(new PixelPos(x - i, y, z)) != checkPixel)
                    {
                        return(false);
                    }
                }

                break;

            case SurroundCheckType.ORDINAL:     // Checks the NE/SE/SW/NW directions around the coord.

                for (int i = checkDistance; i > 0; i--)
                {
                    if (this.world.getPixelState(new PixelPos(x + i, y, z + i)) != checkPixel)
                    {
                        return(false);
                    }
                    if (this.world.getPixelState(new PixelPos(x + i, y, z - i)) != checkPixel)
                    {
                        return(false);
                    }
                    if (this.world.getPixelState(new PixelPos(x - i, y, z + i)) != checkPixel)
                    {
                        return(false);
                    }
                    if (this.world.getPixelState(new PixelPos(x - i, y, z - i)) != checkPixel)
                    {
                        return(false);
                    }
                }

                break;

            case SurroundCheckType.UP:     // Checks above coord.

                Pixel b;
                for (int i = checkDistance; i > 0; i--)
                {
                    b = this.world.getPixelState(new PixelPos(x, y + i, z));

                    if (b != checkPixel)
                    {
                        return(false);
                    }
                }

                break;

            default:
                break;
            }

            return(true);
        }
Beispiel #58
0
 void SetPixel(int x, int y, Pixel p)
 {
     m_pixels[y * m_x_dims + x] = p;
 }
Beispiel #59
0
 public void setDoublePlant(PixelPos lowerPos, Pixel doublePlant)
 {
     this.setDoublePlant(lowerPos, doublePlant, 2);
 }
Beispiel #60
0
 public SurfaceCanyon(BiomeConfig config, Pixel top, Pixel fill, int grassHeight) : base(config, top, fill)
 {
     grassRaise = grassHeight;
 }