Exemple #1
0
        public void TestExceptionForUnsupportedBitMapType()
        {
            FileStream fileIn;

            try
            {
                fileIn = new FileStream("../../../images/error_type.bmp", FileMode.Open, FileAccess.ReadWrite);
            }
            catch (FileNotFoundException)
            {
                throw new FileNotFoundException("Ошибка! Входной файл не был найден!");
            }

            bool isValidFile = true;

            try
            {
                BitMapFile file = new BitMapFile(fileIn);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Неподдерживаемая битность BMP-файла."))
                {
                    isValidFile = false;
                }
            }
            Assert.IsFalse(isValidFile);
        }
Exemple #2
0
        public void Setup()
        {
            FileStream openingFile;

            try
            {
                openingFile = new FileStream("../../../TestImages/testing_file.bmp", FileMode.Open, FileAccess.ReadWrite);
            }
            catch (FileNotFoundException)
            {
                throw new Exception("Invalid file path specified");
            }

            try
            {
                savingFile = new FileStream("../../../TestImages/save.bmp", FileMode.Create, FileAccess.ReadWrite);
            }
            catch (Exception)
            {
                openingFile.Close();
                throw new Exception("Failed to open the output file.");
            }
            file = new(openingFile);
            openingFile.Close();
        }
Exemple #3
0
        public static void ApplyFilter(BitMapFile image)
        {
            for (int color = 0; color < 3; ++color)
            {
                for (int i = 1; i < image.Height - 1; ++i)
                {
                    for (int j = image.Channels; j < image.RowByteSize - image.Channels; j += image.Channels)
                    {
                        double result = 0;
                        for (int n = -1; n < 2; ++n)
                        {
                            for (int m = -1; m < 2; ++m)
                            {
                                double coefficient;
                                if (m == 0 && n == 0)
                                {
                                    coefficient = GaussCoefficients[0];
                                }
                                else if (m != 0 && n != 0)
                                {
                                    coefficient = GaussCoefficients[2];
                                }
                                else
                                {
                                    coefficient = GaussCoefficients[1];
                                }
                                result += image.ImageBytes[i + n][j + color + image.Channels * m] * coefficient;
                            }
                        }

                        image.ImageBytes[i][j + color] = (byte)result;
                    }
                }
            }
        }
 public static void ApplyFilter(BitMapFile image)
 {
     for (int i = 0; i < image.Height; ++i)
     {
         for (int j = 0; j < image.RowByteSize; j += image.Channels)
         {
             // Colors are stored in BGR order
             byte color = (byte)(BlueCoefficient * image.ImageBytes[i][j] +
                                 GreenCoefficient * image.ImageBytes[i][j + 1] +
                                 RedCoefficient * image.ImageBytes[i][j + 2]);
             image.ImageBytes[i][j]     = color;
             image.ImageBytes[i][j + 1] = color;
             image.ImageBytes[i][j + 2] = color;
         }
     }
 }
        public static void ApplyFilter(BitMapFile image, SobelFilter.Type type)
        {
            GrayFilter.ApplyFilter(image);

            byte[][] copyImageBytes = new byte[image.Height][];

            for (int i = 0; i < image.Height; ++i)
            {
                copyImageBytes[i] = new byte[image.RowByteSize];
                for (int j = 0; j < image.RowByteSize; ++j)
                {
                    copyImageBytes[i][j] = image.ImageBytes[i][j];
                }
            }

            for (int i = 1; i < image.Height - 1; ++i)
            {
                for (int j = image.Channels; j < image.RowByteSize - image.Channels; j += image.Channels)
                {
                    int result = 0;
                    for (int n = -1; n < 2; ++n)
                    {
                        for (int m = -1; m < 2; ++m)
                        {
                            if (type == Type.Y)
                            {
                                result += (int)(copyImageBytes[i + n][j + image.Channels * m] * SobelYCoefficients[n + 1, m + 1]);
                            }
                            else
                            {
                                result += (int)(copyImageBytes[i + n][j + image.Channels * m] * SobelXCoefficients[n + 1, m + 1]);
                            }
                        }
                    }

                    for (int k = 0; k < 3; ++k)
                    {
                        image.ImageBytes[i][j + k] = Math.Abs(result) < SobelEdgeLimit ? (byte)0 : (byte)255;
                    }
                }
            }
        }
 public static void ApplyFilter(BitMapFile image)
 {
     for (int color = 0; color < 3; ++color)
     {
         for (int i = 1; i < image.Height - 1; ++i)
         {
             for (int j = image.Channels; j < image.RowByteSize - image.Channels; j += image.Channels)
             {
                 int[] nearColors = new int[9];
                 for (int n = -1; n < 2; ++n)
                 {
                     for (int m = -1; m < 2; ++m)
                     {
                         nearColors[(n + 1) * 3 + m + 1] = image.ImageBytes[i + n][j + color + image.Channels * m];
                     }
                 }
                 Array.Sort(nearColors);
                 image.ImageBytes[i][j + color] = (byte)nearColors[4];
             }
         }
     }
 }
Exemple #7
0
        public void Setup()
        {
            FileStream fileIn;

            try
            {
                fileIn = new FileStream("../../../images/in.bmp", FileMode.Open, FileAccess.ReadWrite);
            }
            catch (FileNotFoundException)
            {
                throw new FileNotFoundException("Ошибка! Входной файл не был найден!");
            }
            try
            {
                fileOut = new FileStream("../../../images/out.bmp", FileMode.Create, FileAccess.ReadWrite);
            }
            catch (Exception)
            {
                fileIn.Close();
                throw new Exception("Ошибка! Возникла проблема с открытием/созданием выходного файла!");
            }
            file = new(fileIn);
            fileIn.Close();
        }
Exemple #8
0
        public void TestBrokenBitMapFile()
        {
            FileStream openingFile;
            bool       isFoundException = false;

            try
            {
                openingFile = new FileStream("../../../TestImages/error.bmp", FileMode.Open, FileAccess.ReadWrite);
            }
            catch
            {
                throw new Exception("Invalid file path specified");
            }

            try
            {
                BitMapFile file = new BitMapFile(openingFile);
            }
            catch (Exception exception)
            {
                isFoundException = exception.Message.Contains("Unsupported bitness of file.");
            }
            Assert.IsTrue(isFoundException);
        }