c_cpp 一组函数和结构,用于将rgb颜色空间转换为rgbw,具有不同的颜色校正和速度。如果你有rgbw led是有用的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 一组函数和结构,用于将rgb颜色空间转换为rgbw,具有不同的颜色校正和速度。如果你有rgbw led是有用的相关的知识,希望对你有一定的参考价值。

struct colorRgbw {
  unsigned int   red;
  unsigned int   green;
  unsigned int   blue;
  unsigned int   white;
};
 
// The saturation is the colorfulness of a color relative to its own brightness.
unsigned int saturation(colorRgbw rgbw) {
    // Find the smallest of all three parameters.
    float low = min(rgbw.red, min(rgbw.green, rgbw.blue));
    // Find the highest of all three parameters.
    float high = max(rgbw.red, max(rgbw.green, rgbw.blue));
    // The difference between the last two variables
    // divided by the highest is the saturation.
    return round(100 * ((high - low) / high));
}
 
// Returns the value of White
unsigned int getWhite(colorRgbw rgbw) {
    return (255 - saturation(rgbw)) / 255 * (rgbw.red + rgbw.green + rgbw.blue) / 3;
}
 
// Use this function for too bright emitters. It corrects the highest possible value.
unsigned int getWhite(colorRgbw rgbw, int redMax, int greenMax, int blueMax) {
    // Set the maximum value for all colors.
    rgbw.red = (float)rgbw.red / 255.0 * (float)redMax;
    rgbw.green = (float)rgbw.green / 255.0 * (float)greenMax;
    rgbw.blue = (float)rgbw.blue / 255.0 * (float)blueMax;
    return (255 - saturation(rgbw)) / 255 * (rgbw.red + rgbw.green + rgbw.blue) / 3;
    return 0;
}
 
// Example function.
colorRgbw rgbToRgbw(unsigned int red, unsigned int green, unsigned int blue) {
    unsigned int white = 0;
    colorRgbw rgbw = {red, green, blue, white};
    rgbw.white = getWhite(rgbw);
    return rgbw;
}
 
// Example function with color correction.
colorRgbw rgbToRgbw(unsigned int red, unsigned int redMax,
                    unsigned int green, unsigned int greenMax,
                    unsigned int blue, unsigned int blueMax) {
    unsigned int white = 0;
    colorRgbw rgbw = {red, green, blue, white};
    rgbw.white = getWhite(rgbw, redMax, greenMax, blueMax);
    return rgbw;
}
 

以上是关于c_cpp 一组函数和结构,用于将rgb颜色空间转换为rgbw,具有不同的颜色校正和速度。如果你有rgbw led是有用的的主要内容,如果未能解决你的问题,请参考以下文章

rgb转换为cmyk颜色空间的举例

颜色空间

RGB色彩空间和HSV色彩空间的理解

视频ToneMapping(HDR转SDR)中的颜色空间转换问题(BT2020转BT709,YCbCrYUV和RGB)

rgb转化到hsv图像外观会变吗opencv

opencv中cvCvtColor函数在哪个库