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

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

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

        public float Value
        {
            set;
            get;
        }

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

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

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

            brightness.AppendChild(value);

            return brightness;
        }

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

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


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