コード例 #1
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;
                }
            }
        }
コード例 #2
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);
                    }
                }
            }
        }