Beispiel #1
0
        public static Color[,] Solve(Color[,] input, int v, int h)
        {
            int row    = input.GetUpperBound(0) + 1;
            int col    = input.GetUpperBound(1) + 1;
            var energy = ComputeEnergy(input, row, col);

            //remove v
            for (int i = 0; i < v; i++)
            {
                var seam   = findVerticalSeam(energy, row, col);
                var result = removeVerticalSeam(energy, input, seam, row, col);
                energy = result.Item1;
                input  = result.Item2;
                col--;
            }
            //remove h
            for (int i = 0; i < h; i++)
            {
                var seam   = findHorizontalSeam(energy, row, col);
                var result = removeHorizontalSeam(energy, input, seam, row, col);
                energy = result.Item1;
                input  = result.Item2;
                row--;
            }
            return(input);
        }
        public static Bitmap ConvertToBitmap(Color[,] seedGrowthState)
        {
            int    iBound     = seedGrowthState.GetUpperBound(0);
            int    jBound     = seedGrowthState.GetUpperBound(1);
            int    width      = jBound + 1;
            int    height     = iBound + 1;
            Bitmap bitmap     = new Bitmap(width, height);
            var    bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            IntPtr ptr        = bitmapData.Scan0;

            Parallel.For(0, iBound, index =>
            {
                Color color;
                for (int j = 0; j <= jBound; j++)
                {
                    int offset = index * 4 + j * bitmapData.Stride;
                    color      = seedGrowthState[index, j];
                    Marshal.WriteByte(ptr, offset, color.R);
                    Marshal.WriteByte(ptr, offset + 1, color.G);
                    Marshal.WriteByte(ptr, offset + 2, color.B);
                    Marshal.WriteByte(ptr, offset + 3, color.A);
                }
            });
            bitmap.UnlockBits(bitmapData);
            return(bitmap);
        }
Beispiel #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //this method draws the transformed picture
            //what ever is stored in transformedPic array will
            //be displayed on the form

            base.OnPaint(e);

            Graphics g = e.Graphics;

            //only draw if picture is transformed
            if (transformedPic != null)
            {
                //get height and width of the transfrormedPic array
                int height = transformedPic.GetUpperBound(0) + 1;
                int width  = transformedPic.GetUpperBound(1) + 1;

                //create a new Bitmap to be dispalyed on the form
                Bitmap newBmp = new Bitmap(width, height);
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        //loop through each element transformedPic and set the
                        //colour of each pixel in the bitmalp
                        newBmp.SetPixel(j, i, transformedPic[i, j]);
                    }
                }
                //call DrawImage to draw the bitmap
                g.DrawImage(newBmp, 0, 20, width, height);
            }
        }
Beispiel #4
0
    void Start()
    {
        mainCamera  = GetComponent <Camera>();
        currentPair = Random.Range(0, colorPairs.GetUpperBound(0) + 1);

        mainCamera.backgroundColor = colorPairs[currentPair, 0];
        levelMaterial.SetVector("_Level_Color", GetLevelColor());
    }
Beispiel #5
0
        /// <summary>
        /// 从指定的颜色数组创建像素数据
        /// </summary>
        public static PixelData CreateFromColors(Color[,] colors)
        {
            int w = colors.GetUpperBound(0) + 1;
            int h = colors.GetUpperBound(1) + 1;

            return(new PixelData(w, h)
            {
                Colors = colors
            });
        }
 private static void changeColorAt(int x, int y, Color colour)
 {
     if (x > imageArray.GetUpperBound(0) || x < imageArray.GetLowerBound(0) ||
         y > imageArray.GetUpperBound(1) || y < imageArray.GetLowerBound(1))
     {
         Console.WriteLine("Exception: changeColorAt: outOfBounds: {0}, {1}", x, y);
         return;
     }
     imageArray[x, y] = colour;
 }
Beispiel #7
0
 public void writeAllPixel(Color c)
 {
     for (int x = 0; x <= buffer.GetUpperBound(0); x++)
     {
         for (int y = 0; y <= buffer.GetUpperBound(1); y++)
         {
             Color c_tmp = this.buffer[x, y];
             c_tmp.setColor(c);
         }
     }
 }
Beispiel #8
0
    public Canvas(int width, int height)
    {
        this.width  = width;
        this.height = height;
        this.buffer = new Color[width, height];

        for (int x = 0; x <= buffer.GetUpperBound(0); x++)
        {
            for (int y = 0; y <= buffer.GetUpperBound(1); y++)
            {
                this.buffer[x, y] = new Color(0, 0, 0);
            }
        }
    }
Beispiel #9
0
        /// <summary>
        /// Scales a image with a given interpolation method
        /// </summary>
        /// <param name="im">Interpolation method</param>
        /// <param name="image">Image to scale</param>
        /// <param name="scaleFactor">Factor to scale</param>
        /// <returns>Scaled image</returns>
        public static Color[,] Scale(InterpolationMethod im, Color[,] image, float scaleFactor)
        {
            int width  = (int)Math.Floor(image.GetUpperBound(0) * scaleFactor);
            int height = (int)Math.Floor(image.GetUpperBound(1) * scaleFactor);

            Color[,] scaledImage = new Color[width, height];
            for (int x = 0; x < scaledImage.GetLength(0); x++)
            {
                for (int y = 0; y < scaledImage.GetLength(1); y++)
                {
                    scaledImage[x, y] = im(image, x, y, scaleFactor);
                }
            }

            return(scaledImage);
        }
Beispiel #10
0
        public static void FlipScreen(Color[,] source, Color[,] dest)
        {
            if (source.GetUpperBound(0) != dest.GetUpperBound(0) ||
                source.GetUpperBound(1) != dest.GetUpperBound(1))
            {
                return;
            }

            for (int x = 0; x < source.GetUpperBound(0); x++)
            {
                for (int y = 0; y < source.GetUpperBound(1); y++)
                {
                    dest[x, y] = source[x, y];
                }
            }
        }
Beispiel #11
0
        public static Texture2D TextureTo2DArray(Texture2D texture, Color[,] data)
        {
            int Width  = data.GetUpperBound(0);
            int Height = data.GetUpperBound(1);

            Color[] colorsOne = new Color[Width * Height]; //The new, hard to read,1D array
            Color[,] colorsTwo = new Color[Width, Height]; //The easy to read 2D array
            for (int x = 0; x < Width; x++)                //Convert!
            {
                for (int y = 0; y < Height; y++)
                {
                    colorsOne[x + y * Width] = colorsTwo[x, y];
                }
            }
            texture.SetData <Color>(colorsOne);
            return(texture);
        }
Beispiel #12
0
        /// <summary>
        /// 返回指定颜色数组生成的位图
        /// </summary>
        public static Bitmap GetBitmapFromColors(Color[,] colors)
        {
            int    w      = colors.GetUpperBound(0) + 1;
            int    h      = colors.GetUpperBound(1) + 1;
            Bitmap result = new Bitmap(w, h);
            var    loopTo = w - 1;

            for (var i = 0; i <= loopTo; i++)
            {
                var loopTo1 = h - 1;
                for (var j = 0; j <= loopTo1; j++)
                {
                    result.SetPixel(i, j, colors[i, j]);
                }
            }
            return(result);
        }
        }// Clear

        public static void ChangeScreen(Color[,] location, Color[,] change)
        {
            // Will return the upperbounds to neutral
            if (location.GetUpperBound(0) != change.GetUpperBound(0) ||
                location.GetUpperBound(1) != location.GetUpperBound(1))
            {
                return;
            }

            for (int i = 0; i < location.GetUpperBound(0); i++)
            {
                for (int j = 0; j < location.GetUpperBound(1); j++)
                {
                    change[i, j] = location[i, j];
                }
            }
        }// Change
Beispiel #14
0
        protected Texture2D GetNumberTexture(int numberValue, int digit_size_x = 128, int digit_size_y = 256)
        {
            // From number value, calculate the ones and tens place positions
            int ones = numberValue % 10;
            int tens = (numberValue / 10) % 10;

            //int digit_size_x = 128;
            //int digit_size_y = 256;
            // Using the refernce grid of digits, extract the pixel values for given digits
            pixelColorsOnes = GetPixelColorArray(ones, baseTexture, digit_size_x, digit_size_y);
            pixelColorsTens = GetPixelColorArray(tens, baseTexture, digit_size_x, digit_size_y);

            // Build target texture from pixel color arrays of tens and ones (Processed left-to-right, respectively)
            outputTexture = new Texture2D(digit_size_x * 2, digit_size_y);
            for (int y = 0; y < outputTexture.height; y++)
            {
                // First half of target texture image (tens place digit)
                for (int x = 0; x < digit_size_x; x++)
                {
                    if ((y <= pixelColorsTens.GetUpperBound(1)) && (x <= pixelColorsTens.GetUpperBound(0)))
                    {
                        outputTexture.SetPixel(x, y, pixelColorsTens[x, y]);
                    }
                    else
                    {
                        outputTexture.SetPixel(x, y, new Color(0, 0, 0, 0));
                    }
                }
                // Second half of target texture image (ones place digit)
                for (int x = digit_size_x; x < digit_size_x * 2; x++)
                {
                    if ((y <= pixelColorsOnes.GetUpperBound(1)) && (x - digit_size_x <= pixelColorsOnes.GetUpperBound(0)))
                    {
                        outputTexture.SetPixel(x, y, pixelColorsOnes[x - digit_size_x, y]);
                    }
                    else
                    {
                        outputTexture.SetPixel(x, y, new Color(0, 0, 0, 0));
                    }
                }
            }
            // Apply changes and return a reference to this texture
            outputTexture.Apply();
            return(outputTexture);
        }
        }// Change

        public static bool Check(Color[,] c1, Color[,] c2)
        {
            // Will return the upperbounds to neutral
            if (c1.GetUpperBound(0) != c2.GetUpperBound(0) ||
                c1.GetUpperBound(1) != c2.GetUpperBound(1))
            {
                return(false);
            }

            for (int i = 0; i < c1.GetUpperBound(0); i++)
            {
                for (int j = 0; j < c1.GetUpperBound(1); j++)
                {
                    if (c1[i, j] != c2[i, j])
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }// Check
Beispiel #16
0
        public static bool Identical(Color[,] s1, Color[,] s2)
        {
            if (s1.GetUpperBound(0) != s2.GetUpperBound(0) ||
                s1.GetUpperBound(1) != s2.GetUpperBound(1))
            {
                return(false);
            }

            for (int x = 0; x < s1.GetUpperBound(0); x++)
            {
                for (int y = 0; y < s1.GetUpperBound(1); y++)
                {
                    if (s1[x, y] != s2[x, y])
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #17
0
        /// <summary>
        /// Writes a 2D array of color structs to the output.
        /// </summary>
        /// <param name="name">Name of the value</param>
        /// <param name="value">2D array of colors</param>
        public void Write(string name, Color[,] value)
        {
            if (value == null)
            {
                _output.Write(NULL_OBJECT);
                return;
            }
            else
            {
                _output.Write(A_OK);
            }
            int row = value.GetUpperBound(0);
            int col = value.GetUpperBound(1);

            _output.Write(row);
            _output.Write(col);
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    this.Write(null, value[i, j]);
                }
            }
        }
Beispiel #18
0
        public bool IsValidClick()
        {
            var mx = (int)ArchaicGame.Input.Mouse.CurrentPosition.X;
            var my = (int)ArchaicGame.Input.Mouse.CurrentPosition.Y;

            if (mx < 0 || my < 0 || mx > _pixels.GetUpperBound(0) || my > _pixels.GetUpperBound(1))
            {
                return(false);
            }

            var pixel = _pixels[mx, my];

            return(pixel.A == 0);
        }