Answer the question
In order to leave comments, you need to log in
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
Answer the question
In order to leave comments, you need to log in
A single immutable class Color
that 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) { } }
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 } }
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?
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 questionAsk a Question
731 491 924 answers to any question