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(
                (double)Red / 10000.0,
                (double)Green / 10000.0,
                (double)Blue / 10000.0
                );
            try
            {
                return SetPixelFormat(filter.Apply(bitmap), PixelFormat.Format16bppRgb565);
            }
            catch
            {
                return SetPixelFormat(filter.Apply(bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format24bppRgb)), PixelFormat.Format24bppRgb);
            }
        }
    }
}
