public static byte getChannelSelectionByte(Color color1, ChannelSelection selection)
        {
            switch (selection)
            {
            case ChannelSelection.R:
                return(color1.R);

            case ChannelSelection.G:
                return(color1.G);

            case ChannelSelection.B:
                return(color1.B);

            case ChannelSelection.A:
                return(color1.A);

            case ChannelSelection.RGB:
            {
                double r = color1.R, g = color1.G, b = color1.B;
                r /= 255;
                g /= 255;
                b /= 255;
                double lum = r * 0.22 + g * 0.707 + b * 0.071;
                return((byte)(lum * 255));
            }

            default:
                return(0);
            }
        }
        public static double getChannelSelection(Color color1, ChannelSelection selection)
        {
            switch (selection)
            {
            case ChannelSelection.R:
                return((double)color1.R / 255);

            case ChannelSelection.G:
                return((double)color1.G / 255);

            case ChannelSelection.B:
                return((double)color1.B / 255);

            case ChannelSelection.A:
                return((double)color1.A / 255);

            case ChannelSelection.RGB:
            {
                double r = color1.R, g = color1.G, b = color1.B;
                r /= 255;
                g /= 255;
                b /= 255;
                double lum = r * 0.22 + g * 0.707 + b * 0.071;
                return(lum);
            }

            default:
                return(0);
            }
        }
 public NormGenerator(IBitmap source, IBitmap mask, ChannelSelection sourceChannel, NormParams opts, double workStart, double workDivisor)
 {
     Debug.WriteLine("Worker constructor enter");
     this.src           = source;
     this.mask          = mask;
     this.parameters    = opts;
     this.sourceChannel = sourceChannel;
     this.workStart     = workStart;
     this.workDiv       = workDivisor;
     Debug.WriteLine("Worker constructor exit");
 }
Beispiel #4
0
        private static BitmapSource GetTwoChanneledImage(byte[] src, int width, int height, ChannelSelection cs1, ChannelSelection cs2)
        {
            var result = new WriteableBitmap(width, height, Dpi, Dpi, PixelFormats.Rgb24, null);

            var buf = new byte[width * height * 3];

            for (int i = 0; i < width * height; i++)
            {
                if (cs1 == ChannelSelection.Red)
                {
                    buf[i * 3] = src[i * 2];
                }
                if (cs1 == ChannelSelection.Green)
                {
                    buf[i * 3 + 1] = src[i * 2];
                }
                if (cs1 == ChannelSelection.Blue)
                {
                    buf[i * 3 + 2] = src[i * 2];
                }

                if (cs1 == ChannelSelection.Red)
                {
                    buf[i * 3] = src[i * 2 + 1];
                }
                if (cs1 == ChannelSelection.Green)
                {
                    buf[i * 3 + 1] = src[i * 2 + 1];
                }
                if (cs1 == ChannelSelection.Blue)
                {
                    buf[i * 3 + 2] = src[i * 2 + 1];
                }
            }

            result.WritePixels(new Int32Rect(0, 0, width, height), buf, width, 0);

            result.Freeze();
            return(result);
        }