<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace PhotoEnhancer
{
    public static class Convertors
    {
        public static Photo Bitmap2Photo(Bitmap bmp)
        {
            var result = new Photo(bmp.Width, bmp.Height);

            for(var x = 0; x < bmp.Width; x++)
                for(var y = 0; y < bmp.Height; y++)
                {
                    var pixel = bmp.GetPixel(x, y);

                    //result[x, y].R = (double)pixel.R / 255;
                    //result[x, y].G = (double)pixel.G / 255;
                    //result[x, y].B = (double)pixel.B / 255;

                    result[x, y] = new Pixel(
                        (double)pixel.R / 255,
                        (double)pixel.G / 255,
                        (double)pixel.B / 255
                        );
                }

            return result;
        }

        public static Bitmap Photo2Bitmap(Photo photo)
        {
            var result = new Bitmap(photo.Width, photo.Height);
            
            for(var x = 0; x < photo.Width; x++)
                for(var y = 0; y < photo.Height; y++)
                {
                    result.SetPixel(x, y, Color.FromArgb(
                        (int)(photo[x, y].R * 255),
                        (int)(photo[x, y].G * 255),
                        (int)(photo[x, y].B * 255)
                        ));
                }

            return result;
        }

        public static double GetPixelHue(Pixel p)
        {
            Color color = Pixel2Color(p);
            return color.GetHue();
        }

        public static double GetPixelSaturation(Pixel p)
        {
            var color = Pixel2Color(p);
            return color.GetSaturation();
        }

        public static double GetPixelLightness(Pixel p)
        {
            var color = Pixel2Color(p);
            return color.GetBrightness();
        }

        public static Color Pixel2Color(Pixel p)
        {
            return Color.FromArgb((int)(p.R * 255), (int)(p.G * 255), (int)(p.B * 255));
        }


        public static Pixel HSL2Pixel(double hue, double saturation, double lightness)
        {
            double q;
            if (lightness < 0.5)
                q = lightness * (1 + saturation);
            else
                q = lightness + saturation - lightness * saturation;

            double p = 2 * lightness - q;

            double h = hue / 360;

            var t = new[] { h + 1.0 / 3, h, h - 1.0 / 3 };

            for (var i = 0; i < 3; i++)
                if (t[i] < 0)
                    t[i] += 1;
                else if (t[i] > 1)
                    t[i] -= 1;

            var rgb = new double[3];

            for (var i = 0; i < 3; i++)
                if (t[i] < 1.0 / 6)
                    rgb[i] = p + ((q - p) * 6 * t[i]);
                else if (t[i] < 0.5)
                    rgb[i] = q;
                else if (t[i] < 2.0 / 3)
                    rgb[i] = p + ((q - p) * (2.0 / 3 - t[i]) * 6);
                else
                    rgb[i] = p;

            return new Pixel(rgb[0], rgb[1], rgb[2]);
        }

    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhotoEnhancer
{
    class ReductionInSizeParameters : IParameters
    {
        public double ReductionInSizeParameter { get; set; }
        public ParameterInfo[] GetDescription()
        {
            return new[]
            {
                new ParameterInfo()
                {
                    Name = "Коэффициент уменьшения",
                    MinValue = 1,
                    MaxValue = 10,
                    DefailtValue =1,
                    Increment = 0.5
                }
            };
        }

        public void SetValues(double[] values)
        {
            ReductionInSizeParameter = values[0];
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhotoEnhancer
{
    class GammaCorectionColorsParameters : IParameters
    {
        public double GammaCorectionColorsRByUser { get; set; }
        public double GammaCorectionColorsGByUser { get; set; }
        public double GammaCorectionColorsBByUser { get; set; }


        public ParameterInfo[] GetDescription()
        {
            return new[]
            {
                new ParameterInfo() {
                    Name = "Канал R",
                    MinValue = 0.2,
                    MaxValue = 5,
                    DefailtValue = 1,
                    Increment = 0.01
                },

                new ParameterInfo()
                {
                    Name = "Канал G",
                    MinValue = 0.2,
                    MaxValue = 5,
                    DefailtValue = 1,
                    Increment = 0.01
                },

                 new ParameterInfo()
                {
                    Name = "Канал B",
                    MinValue = 0.2,
                    MaxValue = 5,
                    DefailtValue = 1,
                    Increment = 0.01
                }

            };
        }

        public void SetValues(double[] values)
        {
            GammaCorectionColorsRByUser = values[0];
            GammaCorectionColorsGByUser = values[1];
            GammaCorectionColorsBByUser = values[2];
    }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Variant5
{
    public struct Record
    {
        public int ClientID; // идентификационный номер клиента 
        public int Year;     // год 
        public int Month;    // номер месяца 
        public int Duration; // продолжительность занятий в данном месяце 
        // данного года (в часах) }
    }
}<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhotoEnhancer
{
    class GammaCorectionColorsFilter : PixelFilter
    {
        public GammaCorectionColorsFilter() : base(new GammaCorectionColorsParameters()) {}

        public override string ToString()
        {
            return "Гамма-корекция цвета";
        }
        public override Pixel ProcessPixel(Pixel originalPixel, IParameters parameters)
        {

            var newR = Math.Pow(originalPixel.R, 1 / (parameters as GammaCorectionColorsParameters).GammaCorectionColorsRByUser);
            var newG = Math.Pow(originalPixel.G, 1 / (parameters as GammaCorectionColorsParameters).GammaCorectionColorsGByUser);
            var newB = Math.Pow(originalPixel.R, 1 / (parameters as GammaCorectionColorsParameters).GammaCorectionColorsBByUser);


            return new Pixel(newR, newG, newB);
        }
    }
}
<file_sep>﻿using System;

namespace PhotoEnhancer
{
    public abstract class ParametrizedFilter : IFilter
    {
        IParameters parameters;

        public ParametrizedFilter(IParameters p)
        {
            parameters = p;
        }
        public ParameterInfo[] GetParametersInfo()
        {
            return parameters.GetDescription();
        }

        public Photo Process(Photo original, double[] values)
        {
            parameters.SetValues(values);
            return Process(original, parameters);
        }

        public abstract Photo Process(Photo original, IParameters parameters);
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Variant5
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var text = new[]
            {
                "Текст. представлен. в виде массива строк, слова в которых; разделены: пробелами-и знаками",
                "Новый, массив; должен содержать не: более- n таких слов. Все слова должны быть в нижнем регистре."
            };

            var words = GetLongestWords(text, 5);
            foreach (var word in words)
                Console.WriteLine(word);

            var strs = File.ReadAllLines("db.txt");
            var dataBase = new List<Record>();

            foreach (var str in strs)
            {
                var data = str.Split();

                var record = new Record()
                {
                    ClientID = int.Parse(data[0]),
                    Year = int.Parse(data[1]),
                    Month = int.Parse(data[2]),
                    Duration = int.Parse(data[3])
                };

                dataBase.Add(record);
            }

            PrintYearsLongestDurationOfMonth(dataBase, 2);
            Console.ReadKey();
        }

        public static string[] GetLongestWords(string[] lines, int n)
        {
            return lines.SelectMany(x => x.Split(new[] {'-', ':', ',', '.', ' ', ';'}))
                .OrderBy(x => x)
                .ThenByDescending(x => x.Length)
                .Take(n)
                .ToArray();
        }

        public static void PrintYearsLongestDurationOfMonth(List<Record> data, int id)
        {
            var years = data.Where(x => x.ClientID == id)
                .GroupBy(x => x.Year)
                .Select(x => (x.Max(y => (y.Duration, y.Month)), x.Key))
                .OrderByDescending(x => x.Key)
                .ToArray();
            if (years.Length > 0)
            {
                foreach (var year in years)
                {
                    Console.WriteLine(
                        $"Год: {year.Key}, месяц: {year.Item1.Month}, продолжительность: {year.Item1.Duration}");
                }
            }
            else
            {
                Console.WriteLine("Нет данных о клиенте");
            }
        }
    }
}<file_sep>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhotoEnhancer
{
    public abstract class PixelFilter : ParametrizedFilter
    {
        public PixelFilter(IParameters p) : base(p) { }
        //public abstract ParameterInfo[] GetParametersInfo();
        public override Photo Process(Photo original, IParameters parameters)
        {
            var newPhoto = new Photo(original.Width, original.Height);

            for (int x = 0; x < original.Width; x++)
                for (int y = 0; y < original.Height; y++)
                    newPhoto[x, y] = ProcessPixel(original[x, y],
                            parameters);

            return newPhoto;
        }

        public abstract Pixel ProcessPixel(Pixel originalPixel,
            IParameters parameters);
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhotoEnhancer
{
    class ReductionInSizeTransformers : ITransformer<ReductionInSizeParameters>
    {
        public Size ResultSize { get; private set; }

        Size originalSize;
        double TransformParameter;


        public void Initialize(Size size, ReductionInSizeParameters parameters)
        {
            originalSize = size;
            TransformParameter = parameters.ReductionInSizeParameter;

            ResultSize = new Size(
                (int)(size.Width / TransformParameter),
                (int)(size.Height / TransformParameter));

            if (ResultSize.Width == 0 || ResultSize.Height ==0)
            {
                ResultSize = size;
                TransformParameter = 1;
            }
        }

        public Point? MapPoint(Point point)
        {
            var x = (int)(point.X * TransformParameter);
            var y = (int)(point.Y * TransformParameter);

            return new Point(x, y);
        }
    }
}
<file_sep>﻿using System;

namespace PhotoEnhancer
{
    public class LighteningFilter : PixelFilter       
    {
        public LighteningFilter() : base(new LighteningParameters()) { }

        public override string ToString()
        {
            return "Осветление/затемнение";
        }

        public override Pixel ProcessPixel(Pixel originalPixel, 
            IParameters parameters)
        {
            return originalPixel * (parameters as LighteningParameters).Coefficient;
        }

     
    }
}
