E
E
efremovaleksey2013-02-10 11:34:07
CMS
efremovaleksey, 2013-02-10 11:34:07

Help me decide on the architecture of the color management library in C#

I am writing my library that works with color (operations in different color spaces), I write in C #, including with the aim of mastering the language (new to me), and understanding the details in Color Management.

That's just still in thought, how to implement it, where to start. For some tasks, it will be better to use RGB colors as the main representation, in others LAB, in others LCh (for those who are not in the subject, this is, primitively speaking, “Lab with color in polar coordinates”). This is a library. The user must choose for himself what is more important to him, which operations on color in which format eat up the most time.

Maybe just take it and do something like in the body of the class?

#if LAB_MAIN_FORMAT
    //...
#elif RGB_MAIN_FORMAT
    //...
#elif LCh_MAIN_FORMAT
    //...
#endif


Yes, I would be happy to provide specific links to articles, literature, where you can find a description of the solution of similar problems.
If the question seems stupid to you, please do not kick, but clearly explain.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
ostapbender, 2013-02-11
@ostapbender

A single immutable class Colorthat converts to all views on the fly

class color
{
    private Rgb rgb;
    private Lab lab;

    public Rgb Rgb
    {
        get { return rgb ?? (rgb == ToRgb(this)); }
    }

    public Lab Lab
    {
        get { return lab ?? (lab == ToLab(this)); }
    }

    public static Color FromRgb(int r, int g, int b)
    {	
    }

    public static ColorFromHsv(...)
    {	
    }

    public static ColorFromLab(...)
    {	
    }

    private static Rgb ToRgb(Color c)
    {	
    }

    private static Lab ToLab(Color c)
    {	
    }
}

And then the implementations of any operations use the representation in which it is more convenient for them to work:
class ColorOperations
{
    public static Color Darken(Color c, float amount)
    {
        // It's better to use c.Hsv here
    }

    public static Color Sharpen(Color c, float amount)
    {
        // And here it's more profitable to use c.Lab
    }
}

E
efremovaleksey, 2013-02-10
@efremovaleksey

I agree, I stepped a little, that's why I'm asking.
The problem is the ability to select the internal color representation according to the type that will be used in the main program.
Example. If the same operations are often used, then encoding the color inside the library as the main "carrier" in RGB will be advantageous. If others, then LAB. Do not drive the color back and forth.
How to make a similar choice before compilation?

G
gleb_kudr, 2013-02-11
@gleb_kudr

1. Classes of colors - separately for each color. For converters are not exact and absolute. At least because Lab are floating point numbers, and RGB is an integer. Plus, the conversion depends on hardwired constants.
2. Parameter constants for conversion (eg white point, constant D).
3. An abstract class with conversion methods.
I can share the source code of the c# converter class from RGB to LAB and back via XYZ. Write in private.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question