コード例 #1
0
ファイル: Util.cs プロジェクト: kirillgla/Spbu-Homework
 internal static void HandleBitMapInfoHeader(byte[] bytes, out BitMapInfoHeader infoHeader)
 {
     infoHeader = new BitMapInfoHeader
     {
         BiWidth    = (bytes[21] << 24) + (bytes[20] << 16) + (bytes[19] << 8) + bytes[18],
         BiHeight   = (bytes[25] << 24) + (bytes[24] << 16) + (bytes[23] << 8) + bytes[22],
         BiBitCount = (ushort)((bytes[29] << 8) + (bytes[28]))
     };
 }
コード例 #2
0
 public BasicImage(byte[] data, BitMapFileHeader fileHeader, BitMapInfoHeader infoHeader)
 {
     Util.CheckSizes(fileHeader, infoHeader, data.Length);
     width         = infoHeader.BiWidth;
     actualWidth   = ((infoHeader.BiBitCount * width + 31) / 32) * 4;
     height        = infoHeader.BiHeight;
     offset        = fileHeader.BfOffBits;
     bytesPerPixel = infoHeader.BiBitCount / 8;
     this.data     = data;
 }
コード例 #3
0
ファイル: Util.cs プロジェクト: kirillgla/Spbu-Homework
        internal static void CheckSizes(BitMapFileHeader fileHeader, BitMapInfoHeader infoHeader, int actualSize)
        {
            if (infoHeader.BiBitCount != 24 && infoHeader.BiBitCount != 32)
            {
                throw new ArgumentException("Error: nuber of bits per pixel other than 24 and 32 are not supported.");
            }

            if (fileHeader.BfSize != actualSize ||
                infoHeader.BiWidth * infoHeader.BiHeight * (infoHeader.BiBitCount / 8) > fileHeader.BfSize)
            {
                throw new ArgumentException("Error: file contents don't match declared size.");
            }
        }
コード例 #4
0
ファイル: Util.cs プロジェクト: kirillgla/Spbu-Homework
        internal static void ApplyGreyen(
            byte[] source,
            byte[] destination,
            BitMapFileHeader fileHeader,
            BitMapInfoHeader infoHeader)
        {
            var sourceImage      = new BasicImage(source, fileHeader, infoHeader);
            var destinationImage = new BasicImage(destination, fileHeader, infoHeader);

            for (int i = 0; i < infoHeader.BiHeight; i++)
            {
                for (int j = 0; j < infoHeader.BiWidth; j++)
                {
                    byte average = ToByte(sourceImage[i, j, ColourPart.Red] * RedLuminance
                                          + sourceImage[i, j, ColourPart.Green] * GreenLuminance
                                          + sourceImage[i, j, ColourPart.Blue] * BlueLuminance);
                    destinationImage[i, j, ColourPart.Red]   = average;
                    destinationImage[i, j, ColourPart.Green] = average;
                    destinationImage[i, j, ColourPart.Blue]  = average;
                }
            }
        }
コード例 #5
0
ファイル: Util.cs プロジェクト: kirillgla/Spbu-Homework
        internal static void ApplyKernel(
            byte[] source,
            byte[] destination,
            double[][] kernel,
            BitMapFileHeader fileHeader,
            BitMapInfoHeader infoHeader)
        {
            var sourceImage      = new BasicImage(source, fileHeader, infoHeader);
            var destinationImage = new BasicImage(destination, fileHeader, infoHeader);
            var lastPart         = ColourPart.Alpha;

            if (infoHeader.BiBitCount == 24)
            {
                lastPart = ColourPart.Blue;
            }

            for (int i = 0; i < infoHeader.BiHeight; i++)
            {
                for (int j = 0; j < infoHeader.BiWidth; j++)
                {
                    for (var part = ColourPart.Red; part <= lastPart; part++)
                    {
                        double value = 0;
                        for (int row = 0; row < 3; row++)
                        {
                            for (int column = 0; column < 3; column++)
                            {
                                value += kernel[row][column] * sourceImage[i - 1 + row, j - 1 + column, part];
                            }
                        }

                        destinationImage[i, j, part] = AbsToByte(value);
                    }
                }
            }
        }