using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;
using ImageBlockz.Operations.InOut;
using ImageBlockz.Api;
using ImageBlockz.Core;
using AForge.Imaging.Filters;

namespace ImageBlockz.Operations.Filters
{
    public class Saturation : AbstractOperation
    {
        public static readonly string OperationName = typeof(Saturation).FullName;

        public Saturation()
            : base(OperationType.Filter)
        {
        
        }

        public Saturation(float value)
            : this()
        {
            Value = value;
        }

        public float Value
        {
            set;
            get;
        }

        public override Bitmap Do(Bitmap bmp)
        {
            SaturationCorrection filter = new SaturationCorrection(Value / 200);            
            return filter.Apply(bmp);
        }

        public override XmlNode ToXml(XmlDocument xmlDoc)
        {
            XmlElement saturation = xmlDoc.CreateElement(OperationName);

            XmlElement value = XmlOperation.FloatToXml("value", Value, xmlDoc);

            saturation.AppendChild(value);

            return saturation;
        }

        public override void FromXml(XmlNode node)
        {
            Value = XmlOperation.FloatFromXml(node["value"]);
        }

        public override string GetFormattedName()
        {
            return "Saturation";
        }


        public override string GetInfo()
        {
            return "Value: " + Value ;
        }
    }
}
