admin 管理员组文章数量: 1184232
2024年1月24日发(作者:变量作用范围c语言)
void HSVtoRGB(unsigned char *r, unsigned char *g, unsigned char *b, int h, int s, int v){ // convert from HSV/HSB to RGB color // R,G,B from 0-255, H from 0-260, S,V from 0-100 // ref / // The hue (H) of a color refers to which pure color it resembles // The saturation (S) of a color describes how white the color is // The value (V) of a color, also called its lightness, describes how dark the color is float RGB_min, RGB_max; RGB_max = v*2.55f; RGB_min = RGB_max*(100 - s)/ 100.0f; int i = h / 60; int difs = h % 60; // factorial part of h // RGB adjustment amount by hue
float RGB_Adj = (RGB_max - RGB_min)*difs / 60.0f; switch (i) { case 0: *r = RGB_max; *g = RGB_min + RGB_Adj; *b = RGB_min; break; case 1: *r = RGB_max - RGB_Adj; *g = RGB_max; *b = RGB_min; break; case 2: *r = RGB_min; *g = RGB_max; *b = RGB_min + RGB_Adj; break; case 3: *r = RGB_min; *g = RGB_max - RGB_Adj; *b = RGB_max; break; case 4: *r = RGB_min + RGB_Adj; *g = RGB_min; *b = RGB_max; break; default: // case 5: *r = RGB_max; *g = RGB_min; *b = RGB_max - RGB_Adj; break; }}代码测试结果
版权声明:本文标题:HSV颜色到RGB的转换C++代码直接可用 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1706059658a500141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论