AForge.Imaging.Filters.StereoAnaglyph.ProcessFilter C# (CSharp) Метод

ProcessFilter() защищенный Метод

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage image, UnmanagedImage overlay ) : void
image UnmanagedImage Source image data (left image).
overlay UnmanagedImage Overlay image data (right image).
Результат void
        protected override unsafe void ProcessFilter( UnmanagedImage image, UnmanagedImage overlay )
        {
            // get image dimension
            int width  = image.Width;
            int height = image.Height;

            // initialize other variables
            int offset    = image.Stride - width * 3;
            int ovrOffset = overlay.Stride - width * 3;

            // do the job
            byte * ptr = (byte*) image.ImageData.ToPointer( );
            byte * ovr = (byte*) overlay.ImageData.ToPointer( );

            switch ( anaglyphAlgorithm )
            {
                case Algorithm.TrueAnaglyph:
                    // for each line
                    for ( int y = 0; y < height; y++ )
                    {
                        // for each pixel
                        for ( int x = 0; x < width; x++, ptr += 3, ovr += 3 )
                        {
                            ptr[RGB.R] = (byte) ( ptr[RGB.R] * 0.299 + ptr[RGB.G] * 0.587 + ptr[RGB.B] * 0.114 );
                            ptr[RGB.G] = 0;
                            ptr[RGB.B] = (byte) ( ovr[RGB.R] * 0.299 + ovr[RGB.G] * 0.587 + ovr[RGB.B] * 0.114 );
                        }
                        ptr += offset;
                        ovr += ovrOffset;
                    }
                    break;

                case Algorithm.GrayAnaglyph:
                    // for each line
                    for ( int y = 0; y < height; y++ )
                    {
                        // for each pixel
                        for ( int x = 0; x < width; x++, ptr += 3, ovr += 3 )
                        {
                            ptr[RGB.R] = (byte) ( ptr[RGB.R] * 0.299 + ptr[RGB.G] * 0.587 + ptr[RGB.B] * 0.114 );
                            ptr[RGB.G] = (byte) ( ovr[RGB.R] * 0.299 + ovr[RGB.G] * 0.587 + ovr[RGB.B] * 0.114 );
                            ptr[RGB.B] = ptr[RGB.G];
                        }
                        ptr += offset;
                        ovr += ovrOffset;
                    }
                    break;
                
                case Algorithm.ColorAnaglyph:
                    // for each line
                    for ( int y = 0; y < height; y++ )
                    {
                        // for each pixel
                        for ( int x = 0; x < width; x++, ptr += 3, ovr += 3 )
                        {
                            // keep Red as it is and take only Green and Blue from the second image
                            ptr[RGB.G] = ovr[RGB.G];
                            ptr[RGB.B] = ovr[RGB.B];
                        }
                        ptr += offset;
                        ovr += ovrOffset;
                    }
                    break;

                case Algorithm.HalfColorAnaglyph:
                    // for each line
                    for ( int y = 0; y < height; y++ )
                    {
                        // for each pixel
                        for ( int x = 0; x < width; x++, ptr += 3, ovr += 3 )
                        {
                            ptr[RGB.R] = (byte) ( ptr[RGB.R] * 0.299 + ptr[RGB.G] * 0.587 + ptr[RGB.B] * 0.114 );
                            ptr[RGB.G] = ovr[RGB.G];
                            ptr[RGB.B] = ovr[RGB.B];
                        }
                        ptr += offset;
                        ovr += ovrOffset;
                    }
                    break;

                case Algorithm.OptimizedAnaglyph:
                    // for each line
                    for ( int y = 0; y < height; y++ )
                    {
                        // for each pixel
                        for ( int x = 0; x < width; x++, ptr += 3, ovr += 3 )
                        {
                            ptr[RGB.R] = (byte) ( ptr[RGB.G] * 0.7 + ptr[RGB.B] * 0.3 );
                            ptr[RGB.G] = ovr[RGB.G];
                            ptr[RGB.B] = ovr[RGB.B];
                        }
                        ptr += offset;
                        ovr += ovrOffset;
                    }
                    break;
            }
        }
    }