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 Contrast : AbstractOperation
    {
        public static readonly string OperationName = typeof(Contrast).FullName;

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

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

        public float Value
        {
            set;
            get;
        }

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

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

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

            contrast.AppendChild(value);

            return contrast;
        }

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

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


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