Accord.Imaging.Filters.CombineChannel.ProcessFilter C# (CSharp) Method

ProcessFilter() protected method

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage image ) : void
image Accord.Imaging.UnmanagedImage Source image data.
return void
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            int pixelSize = System.Drawing.Image.GetPixelFormatSize(image.PixelFormat) / 8;

            // get source image size
            int width = image.Width;
            int height = image.Height;

            // check is the same size
            if (image.Height != baseHeight || image.Width != baseWidth)
                throw new InvalidImagePropertiesException("Image does not have expected dimensions.", "image");

            if (pixelSize == 8)
            {
                // for each channel
                for (int c = 0; c < channels.Length; c++)
                {
                    byte* dst = (byte*)((int)image.ImageData + c);
                    byte* src = (byte*)channels[c].ImageData;

                    // copy channel to image
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            *(dst += pixelSize) = *(src++);
                        }
                    }
                }
            }
            else if (pixelSize == 16)
            {
                // for each channel
                for (int c = 0; c < channels.Length; c++)
                {
                    short* dst = (short*)((int)image.ImageData + c);
                    short* src = (short*)channels[c].ImageData;

                    // copy channel to image
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            *(dst += pixelSize) = *(src++);
                        }
                    }
                }
            }
            else
            {
                throw new UnsupportedImageFormatException("Unsupported pixel size.");
            }
        }