Beispiel #1
0
 private Standart[] GenerateRandomStandartSequence(int length)
 {
     var standartObjects = new Standart[length];
     for (int i = 0; i < length; i++)
     {
         standartObjects[i] = _standarts.StandartConstants[
             RandomHelper.RandomNumber(0, _standarts.StandartConstants.Length)];
     }
     return standartObjects;
 }
Beispiel #2
0
        private Bitmap GenerateBitmapFromStandart(Standart standart)
        {
            var bmp = new Bitmap(standart.IdealStandart.Width, standart.IdealStandart.Height);
            Graphics.FromImage(bmp).FillRectangle(
                new SolidBrush(Color.White),
                0, 0, standart.IdealStandart.Width, standart.IdealStandart.Height);

            unsafe
            {
                BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite,
                    bmp.PixelFormat);

                int bytesPerPixel = Image.GetPixelFormatSize(bmp.PixelFormat)/8;
                int heightInPixels = bitmapData.Height;
                int widthInBytes = bitmapData.Width*bytesPerPixel;
                var ptrFirstPixel = (byte*) bitmapData.Scan0;

                for (int y = 0; y < heightInPixels; y++)
                {
                    byte* currentLine = ptrFirstPixel + (y*bitmapData.Stride);
                    for (int x = 0, cell = 0; x < widthInBytes; x = x + bytesPerPixel, cell++)
                    {
                        int blue = 0;
                        int green = 0;
                        int red = 0;

                        if (standart.Mask.Matrix[cell, y])
                        {
                            int randomNumber = RandomHelper.RandomNumber(0, 1000);
                            if (randomNumber < 500)
                            {
                                blue = 255;
                                green = 255;
                                red = 255;
                            }
                        }
                        else
                        {
                            if (!standart.IdealStandart.Matrix[cell, y])
                            {
                                blue = 255;
                                green = 255;
                                red = 255;
                            }
                        }
                        currentLine[x] = (byte) blue;
                        currentLine[x + 1] = (byte) green;
                        currentLine[x + 2] = (byte) red;
                    }
                }
                bmp.UnlockBits(bitmapData);
            }

            return bmp;
        }
Beispiel #3
0
        private bool CompareImageWithStandart(Bitmap bmp, int x, int y, Standart standart)
        {
            bool ret = true;

            unsafe
            {
                BitmapData bitmapData = bmp.LockBits(
                    new Rectangle(x, y, standart.IdealStandart.Width, standart.IdealStandart.Height),
                    ImageLockMode.ReadWrite, bmp.PixelFormat);

                int bytesPerPixel = Image.GetPixelFormatSize(bmp.PixelFormat)/8;
                int heightInPixels = bitmapData.Height;
                int widthInBytes = bitmapData.Width*bytesPerPixel;
                var ptrFirstPixel = (byte*) bitmapData.Scan0;

                for (int row = 0; row < heightInPixels; row++)
                {
                    byte* currentLine = ptrFirstPixel + (row*bitmapData.Stride);
                    for (int startByte = 0, cell = 0;
                        startByte < widthInBytes;
                        startByte = startByte + bytesPerPixel, cell++)
                    {
                        int blue = currentLine[startByte];
                        int green = currentLine[startByte + 1];
                        int red = currentLine[startByte + 2];

                        if (!standart.Mask.Matrix[cell, row])
                        {
                            if (standart.IdealStandart.Matrix[cell, row] != (blue + green + red == 0))
                            {
                                ret = false;
                                break;
                            }
                        }
                    }
                    if (!ret) break;
                }
                bmp.UnlockBits(bitmapData);
            }

            return ret;
        }
Beispiel #4
0
 public Processor(Standart[] standarts)
 {
     Standarts = standarts;
 }