示例#1
0
        public int[][] MapTone(int[][] source, int[][] map)
        {
            int imgWidth     = source.Length;
            int imgHeight    = source[0].Length;
            int filterHeight = map[0].Length;

            for (int x = 0; x < imgWidth; x++)
            {
                for (int y = 0; y < imgHeight; y++)
                {
                    int color        = source[x][y];
                    int channelRed   = PhotoUtilities.Red(color);
                    int channelGreen = PhotoUtilities.Green(color);
                    int channelBlue  = PhotoUtilities.Blue(color);

                    if (filterHeight == 1)
                    {
                        channelRed   = map[channelRed][0];
                        channelGreen = map[channelGreen][0];
                        channelBlue  = map[channelBlue][0];
                    }
                    else
                    {
                        channelRed   = map[channelRed][0];
                        channelGreen = map[channelGreen][1];
                        channelBlue  = map[channelBlue][2];
                    }
                    source[x][y] = PhotoUtilities.Color(PhotoUtilities.Red(channelRed), PhotoUtilities.Green(channelGreen), PhotoUtilities.Blue(channelBlue));
                }
            }
            return(source);
        }
示例#2
0
        private int[][] GreyScaleImage(int[][] source)
        {
            double greyScaleRed   = 0.299;
            double greyScaleGreen = 0.587;
            double greyScaleBlue  = 0.114;

            int red, green, blue;
            int pixel;

            int imgWidth  = source.Length;
            int imgHeight = source[0].Length;

            for (int x = 0; x < imgWidth; x++)
            {
                for (int y = 0; y < imgHeight; y++)
                {
                    pixel = source[x][y];

                    red   = PhotoUtilities.Red(pixel);
                    green = PhotoUtilities.Green(pixel);
                    blue  = PhotoUtilities.Blue(pixel);

                    red = green = blue = (int)(greyScaleRed * red + greyScaleGreen * green + greyScaleBlue * blue);

                    source[x][y] = PhotoUtilities.Color(red, green, blue);
                }
            }

            return(source);
        }
示例#3
0
        public int[][] FilterApply(int[][] source, double[][] filter, double factor, double offset)
        {
            int imgWidth  = source.Length;
            int imgHeight = source[0].Length;

            int filterHeight = filter.Length;
            int filterWidth  = filter[0].Length;

            for (int x = 0; x < imgWidth; x++)
            {
                for (int y = 0; y < imgHeight; y++)
                {
                    int red   = 0;
                    int green = 0;
                    int blue  = 0;

                    for (int filterX = 0; filterX < filterWidth; filterX++)
                    {
                        for (int filterY = 0; filterY < filterHeight; filterY++)
                        {
                            int imageX = (x - (filterWidth / 2) + filterX + imgWidth) % imgWidth;
                            int imageY = (y - (filterHeight / 2) + filterY + imgHeight) % imgHeight;

                            int color = source[imageX][imageY];

                            double maskValue = filter[filterX][filterY];

                            red   += (int)(PhotoUtilities.Red(color) * maskValue);
                            green += (int)(PhotoUtilities.Green(color) * maskValue);
                            blue  += (int)(PhotoUtilities.Blue(color) * maskValue);
                        }
                    }

                    red   = Math.Min(Math.Max((int)(factor * red + offset), 0), 255);
                    green = Math.Min(Math.Max((int)(factor * green + offset), 0), 255);
                    blue  = Math.Min(Math.Max((int)(factor * blue + offset), 0), 255);

                    source[x][y] = PhotoUtilities.Color(red, green, blue);
                }
            }

            return(source);
        }
示例#4
0
        private int[][] ColorDodgeBlendOptimized(int[][] source, int[][] layer)
        {
            int imgWidth  = source.Length;
            int imgHeight = source[0].Length;

            for (int i = 0; i < imgHeight; i++)
            {
                for (int j = 0; j < imgWidth; j++)
                {
                    int filterInt = layer[j][i];
                    int srcInt    = source[j][i];

                    int redValueFinal   = Colordodge(PhotoUtilities.Red(filterInt), PhotoUtilities.Red(srcInt));
                    int greenValueFinal = Colordodge(PhotoUtilities.Green(filterInt), PhotoUtilities.Green(srcInt));
                    int blueValueFinal  = Colordodge(PhotoUtilities.Blue(filterInt), PhotoUtilities.Blue(srcInt));

                    source[j][i] = PhotoUtilities.Color(redValueFinal, greenValueFinal, blueValueFinal);
                }
            }

            return(source);
        }
示例#5
0
        private int[][] InvertColors(int[][] source)
        {
            int pixelColor;
            int red, green, blue;

            int imgWidth  = source.Length;
            int imgHeight = source[0].Length;

            for (int y = 0; y < imgHeight; y++)
            {
                for (int x = 0; x < imgWidth; x++)
                {
                    pixelColor = source[x][y];

                    red   = 255 - PhotoUtilities.Red(pixelColor);
                    green = 255 - PhotoUtilities.Green(pixelColor);
                    blue  = 255 - PhotoUtilities.Blue(pixelColor);

                    source[x][y] = PhotoUtilities.Color(red, green, blue);
                }
            }
            return(source);
        }