Example #1
0
        public void ApplySobelFilterFromFileTest()
        {
            // preperation

            FileStream inputFile          = new FileStream("..\\..\\..\\Resources\\OriginalCat.bmp", FileMode.Open, FileAccess.Read);
            FileStream expectedOutputFile = new FileStream("..\\..\\..\\Resources\\SobelFilterCat.bmp", FileMode.Open, FileAccess.Read);

            byte[] temp = new byte[54];
            inputFile.Read(temp, 0, 54);
            BMPFileHeader bmpInfo = new BMPFileHeader(temp);
            SobelFilter   image   = new SobelFilter(bmpInfo, inputFile);

            // checking SobelFilter

            image.ApplySobelFilter(SobelFilter.FilterType.SobelFilter);
            byte[] outputFile = new byte[bmpInfo.FileSize];
            image.WriteImage(outputFile);

            for (uint i = 0; i < bmpInfo.FileSize; i++)
            {
                Assert.IsTrue(outputFile[i] == (byte)expectedOutputFile.ReadByte());
            }

            inputFile.Close();
            expectedOutputFile.Close();
        }
Example #2
0
        public void ReadAndWriteImageFromFileTest()
        {
            // preperation

            FileStream inputAndOutFile = new FileStream("..\\..\\..\\Resources\\OriginalCat.bmp", FileMode.Open, FileAccess.Read);

            // checking that Read and Write methods work correctly

            byte[] temp = new byte[54];
            inputAndOutFile.Read(temp, 0, 54);

            BMPFileHeader fileInfo = new BMPFileHeader(temp);

            Image image = new Image(fileInfo, inputAndOutFile);

            byte[] data = new byte[fileInfo.FileSize];

            image.WriteImage(data);
            inputAndOutFile.Seek(0, SeekOrigin.Begin);

            for (int i = 0; i < fileInfo.FileSize; i++)
            {
                Assert.IsTrue(data[i] == inputAndOutFile.ReadByte());
            }

            inputAndOutFile.Close();
        }
Example #3
0
        public void AssignmentTest()
        {
            // preparation

            FileStream inputFile = new FileStream("..\\..\\..\\Resources\\OriginalCat.bmp", FileMode.Open, FileAccess.Read);

            byte[] temp = new byte[54];
            inputFile.Read(temp, 0, 54);
            BMPFileHeader file = new BMPFileHeader(temp);

            string expectedFileType        = "BM";
            uint   expectedFileSize        = 4500054;
            ushort expectedReserved1       = 0;
            ushort expectedReserved2       = 0;
            uint   expectedImageOffset     = 54;
            uint   expectedHeaderSize      = 40;
            uint   expectedWidth           = 1000;
            uint   expectedHeight          = 1500;
            ushort expectedPlanes          = 1;
            ushort expectedBitPerPixel     = 24;
            uint   expectedCompression     = 0;
            uint   expectedSizeImage       = 4500000;
            uint   expectedXPelsPerMeter   = 2835;
            uint   expectedYPelsPerMeter   = 2835;
            uint   expectedColorsUsed      = 0;
            uint   expectedColorsImportant = 0;

            byte[] expectedByteReprezentation = new byte[expectedImageOffset];
            Array.Copy(temp, expectedByteReprezentation, expectedImageOffset);

            // checking for properties' value

            Assert.AreEqual(file.FileType, expectedFileType);
            Assert.AreEqual(file.FileSize, expectedFileSize);
            Assert.AreEqual(file.Reserved1, expectedReserved1);
            Assert.AreEqual(file.Reserved2, expectedReserved2);
            Assert.AreEqual(file.ImageOffset, expectedImageOffset);
            Assert.AreEqual(file.HeaderSize, expectedHeaderSize);
            Assert.AreEqual(file.Width, expectedWidth);
            Assert.AreEqual(file.Height, expectedHeight);
            Assert.AreEqual(file.Planes, expectedPlanes);
            Assert.AreEqual(file.BitPerPixel, expectedBitPerPixel);
            Assert.AreEqual(file.Compression, expectedCompression);
            Assert.AreEqual(file.SizeImage, expectedSizeImage);
            Assert.AreEqual(file.XPelsPerMeter, expectedXPelsPerMeter);
            Assert.AreEqual(file.YPelsPerMeter, expectedYPelsPerMeter);;
            Assert.AreEqual(file.ColorsUsed, expectedColorsUsed);
            Assert.AreEqual(file.ColorsImportant, expectedColorsImportant);

            for (int i = 0; i < expectedImageOffset; i++)
            {
                Assert.AreEqual(expectedByteReprezentation[i], file.ByteRepresentation[i]);
            }
        }
Example #4
0
 private static bool ReadFileHeader(BinaryReader aReader, ref BMPFileHeader aFileHeader)
 {
     aFileHeader.magic = aReader.ReadUInt16();
     if (aFileHeader.magic != MAGIC)
     {
         return(false);
     }
     aFileHeader.filesize = aReader.ReadUInt32();
     aFileHeader.reserved = aReader.ReadUInt32();
     aFileHeader.offset   = aReader.ReadUInt32();
     return(true);
 }
Example #5
0
        public BMP(string path)
        {
            PATH=path;

            if(File.Exists(PATH))
            {
                BinaryReader br=new BinaryReader(File.OpenRead(PATH));
                // Read BMP File Header
                BitmapFileHeader=new BMPFileHeader();
                ReadBMPFileHeader(br);
                br.Close();
            }
        }
Example #6
0
        public BMP(string path)
        {
            PATH = path;

            if (File.Exists(PATH))
            {
                BinaryReader br = new BinaryReader(File.OpenRead(PATH));
                // Read BMP File Header
                BitmapFileHeader = new BMPFileHeader();
                ReadBMPFileHeader(br);
                br.Close();
            }
        }
Example #7
0
        /// <summary>
        /// Loads BMP header from stream.
        /// </summary>
        /// <param name="stream">Fully formatted BMP image.</param>
        /// <returns>Length of header.</returns>
        protected override long Load(Stream stream)
        {
            base.Load(stream);
            byte[] temp = stream.ReadBytes(HeaderSize);

            if (!CheckIdentifier(temp))
            {
                throw new FormatException("Stream is not a BMP Image");
            }

            FileHeader = new BMPFileHeader(temp);
            DIBHeader  = new BMPDIBHeader(temp);

            Width  = DIBHeader.Width;
            Height = DIBHeader.Height;

            return(HeaderSize);
        }
Example #8
0
        /// <summary>
        /// Loads BMP header from stream.
        /// </summary>
        /// <param name="stream">Fully formatted BMP image.</param>
        /// <returns>Length of header.</returns>
        protected override long Load(Stream stream)
        {
            base.Load(stream);
            byte[] temp = stream.ReadBytes(HeaderSize);

            if (!CheckIdentifier(temp))
                throw new FormatException("Stream is not a BMP Image");

            FileHeader = new BMPFileHeader(temp);
            DIBHeader = new BMPDIBHeader(temp);

            Width = DIBHeader.Width;
            Height = DIBHeader.Height;

            return HeaderSize;
        }
 public NegativeFilter(BMPFileHeader fileInfo, byte[] inputFile) : base(fileInfo, inputFile)
 {
 }
 public NegativeFilter(BMPFileHeader fileInfo, FileStream inputFile) : base(fileInfo, inputFile)
 {
 }
Example #11
0
 public SobelFilter(BMPFileHeader fileInfo, byte[] inputFile) : base(fileInfo, inputFile)
 {
 }
Example #12
0
 public SobelFilter(BMPFileHeader fileInfo, FileStream inputFile) : base(fileInfo, inputFile)
 {
 }