<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using OpenTK.Graphics;
using System;

namespace osu.Framework.Extensions.Color4Extensions
{
    public static class Color4Extensions
    {
        public const double GAMMA = 2.4;

        public static double ToLinear(double color)
        {
            return color <= 0.04045 ? (color / 12.92) : Math.Pow((color + 0.055) / 1.055, GAMMA);
        }

        public static double ToSRGB(double color)
        {
            return color < 0.0031308 ? (12.92 * color) : (1.055 * Math.Pow(color, 1.0 / GAMMA) - 0.055);
        }

        public static Color4 ToLinear(this Color4 colour)
        {
            return new Color4(
                (float)ToLinear(colour.R),
                (float)ToLinear(colour.G),
                (float)ToLinear(colour.B),
                colour.A);
        }

        public static Color4 ToSRGB(this Color4 colour)
        {
            return new Color4(
                (float)ToSRGB(colour.R),
                (float)ToSRGB(colour.G),
                (float)ToSRGB(colour.B),
                colour.A);
        }

        public static Color4 MultiplySRGB(Color4 first, Color4 second)
        {
            if (first.Equals(Color4.White))
                return second;
            else if (second.Equals(Color4.White))
                return first;

            first = first.ToLinear();
            second = second.ToLinear();

            return new Color4(
                first.R * second.R,
                first.G * second.G,
                first.B * second.B,
                first.A * second.A).ToSRGB();
        }

        public static Color4 Multiply(Color4 first, Color4 second)
        {
            if (first.Equals(Color4.White))
                return second;
            else if (second.Equals(Color4.White))
                return first;

            return new Color4(
                first.R * second.R,
                first.G * second.G,
                first.B * second.B,
                first.A * second.A);
        }

        /// <summary>
        /// Returns a lightened version of the colour.
        /// </summary>
        /// <param name="colour">Original colour</param>
        /// <param name="amount">Decimal light addition</param>
        public static Color4 Lighten(this Color4 colour, float amount)
        {
            return new Color4(
                Math.Min(1, colour.R * (1 + amount)),
                Math.Min(1, colour.G * (1 + amount)),
                Math.Min(1, colour.B * (1 + amount)),
                colour.A);
        }

        /// <summary>
        /// Lightens a colour in a way more friendly to dark or strong colours.
        /// </summary>
        public static Color4 Lighten2(this Color4 colour, float amount)
        {
            amount *= 0.5f;
            return new Color4(
                Math.Min(1, colour.R * (1 + 0.5f * amount) + amount),
                Math.Min(1, colour.G * (1 + 0.5f * amount) + amount),
                Math.Min(1, colour.B * (1 + 0.5f * amount) + amount),
                colour.A);
        }

        /// <summary>
        /// Returns a darkened version of the colour.
        /// </summary>
        /// <param name="colour">Original colour</param>
        /// <param name="amount">Percentage light reduction</param>
        public static Color4 Darken(this Color4 colour, float amount)
        {
            return new Color4(
                Math.Max(0, colour.R / (1 + amount)),
                Math.Max(0, colour.G / (1 + amount)),
                Math.Max(0, colour.B / (1 + amount)),
                colour.A);
        }
    }
}<commit_msg>Remove Lighten2 for now.<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using OpenTK.Graphics;
using System;

namespace osu.Framework.Extensions.Color4Extensions
{
    public static class Color4Extensions
    {
        public const double GAMMA = 2.4;

        public static double ToLinear(double color)
        {
            return color <= 0.04045 ? (color / 12.92) : Math.Pow((color + 0.055) / 1.055, GAMMA);
        }

        public static double ToSRGB(double color)
        {
            return color < 0.0031308 ? (12.92 * color) : (1.055 * Math.Pow(color, 1.0 / GAMMA) - 0.055);
        }

        public static Color4 ToLinear(this Color4 colour)
        {
            return new Color4(
                (float)ToLinear(colour.R),
                (float)ToLinear(colour.G),
                (float)ToLinear(colour.B),
                colour.A);
        }

        public static Color4 ToSRGB(this Color4 colour)
        {
            return new Color4(
                (float)ToSRGB(colour.R),
                (float)ToSRGB(colour.G),
                (float)ToSRGB(colour.B),
                colour.A);
        }

        public static Color4 MultiplySRGB(Color4 first, Color4 second)
        {
            if (first.Equals(Color4.White))
                return second;
            else if (second.Equals(Color4.White))
                return first;

            first = first.ToLinear();
            second = second.ToLinear();

            return new Color4(
                first.R * second.R,
                first.G * second.G,
                first.B * second.B,
                first.A * second.A).ToSRGB();
        }

        public static Color4 Multiply(Color4 first, Color4 second)
        {
            if (first.Equals(Color4.White))
                return second;
            else if (second.Equals(Color4.White))
                return first;

            return new Color4(
                first.R * second.R,
                first.G * second.G,
                first.B * second.B,
                first.A * second.A);
        }

        /// <summary>
        /// Returns a lightened version of the colour.
        /// </summary>
        /// <param name="colour">Original colour</param>
        /// <param name="amount">Decimal light addition</param>
        public static Color4 Lighten(this Color4 colour, float amount)
        {
            return new Color4(
                Math.Min(1, colour.R * (1 + amount)),
                Math.Min(1, colour.G * (1 + amount)),
                Math.Min(1, colour.B * (1 + amount)),
                colour.A);
        }

        /// <summary>
        /// Returns a darkened version of the colour.
        /// </summary>
        /// <param name="colour">Original colour</param>
        /// <param name="amount">Percentage light reduction</param>
        public static Color4 Darken(this Color4 colour, float amount)
        {
            return new Color4(
                Math.Max(0, colour.R / (1 + amount)),
                Math.Max(0, colour.G / (1 + amount)),
                Math.Max(0, colour.B / (1 + amount)),
                colour.A);
        }
    }
}
{'fraction_non_alphanumeric': 0.11820128479657388, 'fraction_numerical': 0.027837259100642397, 'mean_word_length': 1.4150293002412961, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5450129', 'n_tokens_mistral': 2118, 'n_tokens_neox': 1933, 'n_words': 494}