mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 6613974e95dea97465c0252e785cd80b6f1f33bc Former-commit-id: 17648f2923890ff36fe4fd2f3bc0223835fd4db7 Former-commit-id: 63c6fa184d0e73dade3f06952b84ef33dd86393faf/merge-core
8 changed files with 10 additions and 104 deletions
@ -1,92 +0,0 @@ |
|||
// <copyright file="PixelOperations.cs" company="James South">
|
|||
// Copyright (c) James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor |
|||
{ |
|||
using System; |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Performs per-pixel operations.
|
|||
/// </summary>
|
|||
public static class PixelOperations |
|||
{ |
|||
/// <summary>
|
|||
/// Converts an pixel from an sRGB color-space to the equivalent linear color-space.
|
|||
/// </summary>
|
|||
/// <param name="composite">
|
|||
/// The <see cref="Bgra32"/> to convert.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The <see cref="Bgra32"/>.
|
|||
/// </returns>
|
|||
public static Color ToLinear(Color composite) |
|||
{ |
|||
// TODO: Figure out a way to either cache these values quickly or perform the calcuations together.
|
|||
composite.R = SrgbToLinear(composite.R); |
|||
composite.G = SrgbToLinear(composite.G); |
|||
composite.B = SrgbToLinear(composite.B); |
|||
|
|||
return composite; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts a pixel from a linear color-space to the equivalent sRGB color-space.
|
|||
/// </summary>
|
|||
/// <param name="linear">
|
|||
/// The <see cref="Bgra32"/> to convert.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The <see cref="Bgra32"/>.
|
|||
/// </returns>
|
|||
public static Color ToSrgb(Color linear) |
|||
{ |
|||
// TODO: Figure out a way to either cache these values quickly or perform the calcuations together.
|
|||
linear.R = LinearToSrgb(linear.R); |
|||
linear.G = LinearToSrgb(linear.G); |
|||
linear.B = LinearToSrgb(linear.B); |
|||
|
|||
return linear; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the correct linear value from an sRGB signal.
|
|||
/// <see href="http://www.4p8.com/eric.brasseur/gamma.html#formulas"/>
|
|||
/// <see href="http://entropymine.com/imageworsener/srgbformula/"/>
|
|||
/// </summary>
|
|||
/// <param name="signal">The signal value to convert.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="float"/>.
|
|||
/// </returns>
|
|||
private static float SrgbToLinear(float signal) |
|||
{ |
|||
if (signal <= 0.04045f) |
|||
{ |
|||
return signal / 12.92f; |
|||
} |
|||
|
|||
return (float)Math.Pow((signal + 0.055f) / 1.055f, 2.4f); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the correct sRGB value from an linear signal.
|
|||
/// <see href="http://www.4p8.com/eric.brasseur/gamma.html#formulas"/>
|
|||
/// <see href="http://entropymine.com/imageworsener/srgbformula/"/>
|
|||
/// </summary>
|
|||
/// <param name="signal">The signal value to convert.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="float"/>.
|
|||
/// </returns>
|
|||
private static float LinearToSrgb(float signal) |
|||
{ |
|||
if (signal <= 0.0031308f) |
|||
{ |
|||
return signal * 12.92f; |
|||
} |
|||
|
|||
return (1.055f * (float)Math.Pow(signal, 0.41666666f)) - 0.055f; |
|||
} |
|||
} |
|||
} |
|||
@ -1 +1 @@ |
|||
eb00c54ee74016c2b70f81963e7e8f83cb2dd54b |
|||
3f05708641eb3ed085d4689aae4a960eb067fd16 |
|||
Loading…
Reference in new issue