public List<string> GetHashCode(BitmapImage bitmap)
        {//takes a bitmap and translates it into the hashcode list
            List<string> hashCode= new List<string>();

            int stride = bitmap.PixelWidth * (bitmap.Format.BitsPerPixel / 8);
            for (int i = 0; i < bitmap.PixelHeight; i++)//divides an image into rows 
            {
                string row="";
                for (int x = 0; x < bitmap.PixelWidth; x++)//iterates through each pixel in the row
                {
                    byte[] pixel = new byte[bitmap.PixelHeight];//holds color values of a single pixel
                    bitmap.CopyPixels(new Int32Rect(x, i, 1, 1), pixel, stride, 0);//assigns color values of a single pixel to the pixel array
                    Color singlePixel = new Color();//creates new color objects and assigns the color values found in pixel array to it
                    singlePixel.B = pixel[0];
                    singlePixel.G = pixel[1];
                    singlePixel.R = pixel[2];
                    singlePixel.A = pixel[3];
                    row += singlePixel.GetHashCode().ToString();//converst the color value into the hashcode and converts it to the string
                }
                hashCode.Add(row);
                if (i % 20 == 0)//Updates programm only after each tenth iteration, this makes program run a bit faster
                UpdatePRogress();
            }
            return hashCode;
        }
Example #2
0
 /// <summary>
 /// Initializes a new TextEntity class.
 /// </summary>
 /// <param name="text">The Text.</param>
 /// <param name="font">The Font.</param>
 /// <param name="color">The Color.</param>
 /// <param name="wrapWidth">The Wordwrap Width.</param>
 public TextEntity(string text, OpenGLFont font, Color color, int wrapWidth = 0)
 {
     if (wrapWidth > 0) text = text.WordWrap(wrapWidth);
     var gdiFont = OpenGLHelper.ConvertFont(font);
     Id = text.GetHashCode() + gdiFont.GetHashCode() + color.GetHashCode();
     _text = text;
     _font = gdiFont;
     _color = color;
 }
Example #3
0
        public void Equals()
        {
            var color1 = new Color(10, 20, 30, 40);
            var color2 = new Color(20, 30, 40, 50);

            Assert.AreNotEqual(color1, color2);
            Assert.AreEqual(color1, new Color(10, 20, 30, 40));

            Assert.IsTrue(color1 == new Color(10, 20, 30, 40));
            Assert.IsTrue(color1 != color2);
            Assert.IsTrue(color1.Equals((object)new Color(10, 20, 30, 40)));
            Assert.AreEqual(color1.PackedArgb, color1.GetHashCode());
        }
 public void Ensure_that_hash_code_can_be_generated()
 {
     var color = new Color(0, 1, 0);
     Assert.AreEqual(1, color.GetHashCode());
 }
Example #5
0
        /*
         * CreateTexture
         * Returns the texture2D to use for each GoL cell
         * can be any size, but is pixelScale * pixelScale by default
         */
        private Texture2D CreateTexture(Color colour)
        {
            Texture2D newTexture = new Texture2D(GraphicsDevice, pixelScale, pixelScale);

            int[] pixelTexture = new int[pixelScale * pixelScale];

            int whiteColour = colour.GetHashCode();
            for (int i = 0; i < pixelScale * pixelScale; i++)
            {
                pixelTexture[i] = whiteColour;
            }

            newTexture.SetData<int>(pixelTexture);
            return newTexture;
        }