using System.Drawing;
using System.Drawing.Imaging;

namespace ZionGraphics.Filtering
{
    class Grayscale : IFilter
    {
        public override Bitmap Apply(Bitmap bitmap)
        {
            AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(
                //0.2125, 0.7154, 0.0721);
                (double)Red / 10000.0,
                (double)Green / 10000.0,
                (double)Blue / 10000.0
                );
            try
            {
                //Correçao do Grayscale que nao estava funcionando, Tiago Carvalho
                //SetPixelFormat(filter.Apply(bitmap), PixelFormat.Format24bppRgb).Save("c:\\Trabalho\\test.png", ImageFormat.Png);
                return SetPixelFormat(filter.Apply(bitmap), PixelFormat.Format24bppRgb);//, PixelFormat.Format24bppRgb);
            }
            catch
            {
                //Correçao do Grayscale que nao estava funcionando, Tiago Carvalho
                //SetPixelFormat(filter.Apply(bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format24bppRgb)), PixelFormat.Format24bppRgb).Save("c:\\Trabalho\\test.png", ImageFormat.Png);
                return SetPixelFormat(filter.Apply(bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format24bppRgb)), PixelFormat.Format24bppRgb);
            }
        }
    }
}
