Giter VIP home page Giter VIP logo

colourful's Introduction

Colourful logo Colourful .NET

Build status Tests codecov NuGet version NuGet downloads API documentation

Open source .NET library for working with color spaces.

The library is written in C# and released with an MIT license, so feel free to fork or use commercially.

Any feedback is appreciated, please visit the issues page or send me an e-mail.

Download

Binaries of the last build can be downloaded on the AppVeyor CI page of the project.

The library is also published on NuGet.org, install using:

PM> Install-Package Colourful

Colourful is CLS Compliant (to allow use in VB.NET etc.) and is built for these target frameworks:

  • .NET 6 or newer
  • .NET Framework 4.5
  • .NET Standard 2.0
  • .NET Standard 1.1
  • For older .NET Framework 4.0 see version 1 of the library.

Usage

Example "hello world" usage that converts a color from sRGB to XYZ (keeping the D65 white point):

IColorConverter<RGBColor, XYZColor> converter = new ConverterBuilder()
    .FromRGB(RGBWorkingSpaces.sRGB)
    .ToXYZ(Illuminants.D65)
    .Build();

RGBColor rgbColor = new RGBColor(1, 0, 0.5);
XYZColor xyzColor = converter.Convert(rgbColor); // XYZ [X=0.45, Y=0.23, Z=0.22]

Documentation

Please see the docs pages below for various topics:

  • Conversion between color spaces
    • also handles chromatic adaptation with multiple possible LMS transformation matrices:
      • Bradford (default)
      • Von Kries (Hunt-Pointer-Estevez adjusted for D65)
      • Von Kries (Hunt-Pointer-Estevez for equal energy)
      • XYZ scaling
      • Spectral-sharpened Bradford
      • CMCCAT2000
      • CAT02
      • (user-defined chromatic adaptation matrix)
  • Correlated color temperature (CCT)
    • Planckian locus approximation method
  • Ranges of channel values and clamping
  • Computing color difference
    • multiple algorithms supported:
      • CIE Delta-E 1976
      • CMC l:c (1984)
      • CIE Delta-E 1994
      • CIE Delta-E 2000
      • JzCzhz Delta-Ez
      • Euclidean distance
  • Cylindrical color spaces
  • Illuminants and white points
    • white points are handled correctly throughout the conversions
    • multiple illuminant are built-in:
      • A (Incandescent / Tungsten)
      • B (Direct sunlight at noon (obsolete))
      • C (Average / North sky Daylight (obsolete))
      • D50 (Horizon Light. ICC profile PCS)
      • D55 (Mid-morning / Mid-afternoon Daylight)
      • D65 (Noon Daylight: Television, sRGB color space)
      • D75 (North sky Daylight)
      • E (Equal energy)
      • F2 (Cool White Fluorescent)
      • F7 (D65 simulator, Daylight simulator)
      • F11 (Philips TL84, Ultralume 40)
      • (user-defined white points)
  • Macbeth ColorChecker chart
  • Changes between v2 and v3

For information about specific color spaces, see the following docs pages:

  • RGB color spaces
    • support for both ordinary RGB and linear RGB
    • multiple working spaces supported:
      • sRGB
      • Simplified sRGB
      • ECI RGB v2
      • Adobe RGB (1998)
      • Apple sRGB
      • Best RGB
      • Beta RGB
      • Bruce RGB
      • CIE RGB
      • ColorMatch RGB
      • Don RGB 4
      • Ekta Space PS5
      • NTSC RGB
      • PAL/SECAM RGB
      • ProPhoto RGB
      • SMPTE-C RGB
      • Wide Gamut RGB
      • Rec. 709 (ITU-R Recommendation BT.709 โ€“ HDTV)
      • Rec. 2020 (ITU-R Recommendation BT.2020 โ€“ UHDTV)
      • (user-defined RGB working spaces)
  • Lab color spaces
    • CIE L*a*b* (1976) (CIELAB)
    • CIE L*C*hยฐab (CIELCH)
    • Hunter Lab
  • Luv color spaces
    • CIE L*u*v* (1976) (CIELUV)
    • CIE L*C*hยฐuv (CIELCH)
  • XYZ color space
    • CIE XYZ (1931)
    • CIE xyY (derived from XYZ)
  • Jzazbz color spaces
    • Jzazbz (Safdar & al., 2017)
    • JzCzhz (polar of Jzazbz)
  • LMS color space
  • xy chromaticity

colourful's People

Contributors

chausner avatar dependabot[bot] avatar iamcarbon avatar ibebbs avatar tompazourek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colourful's Issues

ColorConverter class name conflict

ColorConverter class name directly conflicts with System.Drawing.ColorConverter. It might be better to change its name for easier integration.

Support Out of Gamut RGBColor

RGBColor currently enforces values to be 0..1. I would like to work with colors that are outside of the sRGB color gamut but still valid.

Is there a way to do that?

ColourFulConverter Question

Hello,

I am trying to get the converter working with VB.net but I can't for the life of me figure out what is to go in the new constructor of the ColourfulConverter? Anyone that could help. When I run it like this I get the following error: System.ArgumentOutOfRangeException: 'The maximum value is 1'

Dim input As RGBColor = New RGBColor(Px.R, Px.G, Px.B)
Dim LAB As LabColor
Dim conver = New ColourfulConverter()
LAB = conver.ToLab(input)

Replicating Photoshop's LAB Mode

Hello,

If you take RGB values (Let's say sRGB) and convert to LAB with D50, do you get exact values like in Photoshop?

Thank You.

[BUG] Convert XYZColor to RGBColor throw an StackOverflowException exception

I use the latest version 2.0.3 in .NETFramework 4.7.2, when convert XYZColor to RGBColor throw an StackOverflowException exception. The exception message 'System.StackOverflowException was unhandled Message: An unhandled exception of type 'System.StackOverflowException' occurred in Colourful.dll'.

Test code:

                // arange
                var input = new XYZColor(0.96422, 1.00000, 0.82521);
                var converter = new ColourfulConverter { WhitePoint = Illuminants.D50, TargetRGBWorkingSpace = RGBWorkingSpaces.sRGB };

                // act
                var output = converter.ToRGB(input);

Question: CIELab to RGB

Hello,
This isn't a question about Colourful; I am trying to understand some code I have inherited that does conversion from CIELab to RGB after decompressing an JPEG 2000 file. I don't know a lot about colour spaces or colour conversions.

If you have a moment, I'm trying to grok the color_cielab_to_rgb method in
this file:

https://github.com/GrokImageCompression/grok/blob/master/src/bin/common/color.cpp

I am trying to understand the code

if(default_type == 0x44454600) { /* DEF : default */
    rl = 100;
    ra = 170;
    rb = 200;
    ol = 0;
    oa = pow(2, prec1 - 1);
    ob = pow(2, prec2 - 2) +  pow(2, prec2 - 3);
} else {
    rl = row[2];
    ra = row[4];
    rb = row[6];
    ol = row[3];
    oa = row[5];
    ob = row[7];
}

Is the code in the else branch a custom CIELab space, and the code above is based on a standard CIELab space ?

If you have time, interested in knowing your take on this.

Thanks,
Aaron

Unity3D requires .NET version <=4.6

Any chance that the code could be down-ported back to .NET 4.6? Unity requires at most .NET 4.6 and this code utilizes .NET 7 functions like "type pattern matching".
The 'in' and 'readonly' keyword can be left out, "get=>" can easily be rewritten and a throw after a double questionmark is easily fixed, but "type pattern matching" needs some rework.

Maybe add unity support in a separate branch? Would you accept a pull request?I could add some extra's to calculate averages from textures etc...

Conversion to CIELAB doesn't match other converters

Maybe I'm doing something wrong, but when I try a basic RGB -> Lab conversion I'm getting a different answer than other converters out there.

var c1 = Color.FromArgb(0, 255, 0);
var c2 = new RGBColor(c1);
var converter = new ColourfulConverter();
var c4 = converter.ToLab(c2);

This gives me Lab [L=87.82, a=-79.29, b=80.99]

But when I try the same conversion on http://colormine.org/convert/rgb-to-lab I get: L = 87.74, a = -86.18, b = 83.18.

Any idea what I'm doing wrong here?

Thanks,
Mike

Example of processing video frames from video file

Hi there,

Thanks a lot for working on this project. I am trying to process video frames from a Rec2020 ST2084 video file and plot a brightness waveform (Y axis is nits) like I am used to seeing in DaVinci Resolve.

Do you have any end to end example of using your library to access individual frames from a video file?

Thanks!

RGB Result in 0-255

Sorry for this newbie question but;
Is it possible to get the RGB Result in 0-255?
Thanks Lars

Build for older .NET versions

One of the features that require .NET 4.5 are IReadOnlyList vectors and matrices. These might be substituted with IList or arrays for older .NET versions. Of course, there might also be more problems.

NullReferenceException when using default Color

var defaultColor= default(LinearRGBColor);
var converter = new ColourfulConverter();
var actual = converter.Adapt(defaultColor);

Produces an NRE. This also happens with arrays of LinearRGBColor.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.