{"id":501,"date":"2013-08-21T02:47:57","date_gmt":"2013-08-21T02:47:57","guid":{"rendered":"http:\/\/yoonhada.com\/wp\/?p=501"},"modified":"2013-08-21T02:47:57","modified_gmt":"2013-08-21T02:47:57","slug":"%eb%b3%b4%ec%83%89-%ec%b0%be%ea%b8%b0-rgbhsl-%eb%b3%80%ed%99%98","status":"publish","type":"post","link":"http:\/\/yoonhada.com\/?p=501","title":{"rendered":"\ubcf4\uc0c9(Complementary color) \ubcc0\ud658 (RGB\/HSL \ubcc0\ud658)"},"content":{"rendered":"<p>\t\t\t\t<a href=\"http:\/\/www.devpia.com\/Maeul\/Contents\/Detail.aspx?BoardID=51&amp;MAEULNO=20&amp;no=7249&amp;page=45\">http:\/\/www.devpia.com\/Maeul\/Contents\/Detail.aspx?BoardID=51&amp;MAEULNO=20&amp;no=7249&amp;page=45<\/a><\/p>\n<p>\ubcf4\uc0c9\uc774\ub780 \uc0c9\uc0c1\ud720\uc5d0\uc11c \uc0c9\uc870(hue) \uac12\uc774 180\ub3c4 \ubc18\ub300\ubc29\ud5a5\uc5d0 \uc704\uce58\ud55c\ub2e4\uace0 \ud569\ub2c8\ub2e4.<br \/>\n(\uc5b4\ub834\ud48b \uc608\uc804 \ubbf8\uc220 \uc2dc\uac04\uc5d0 \ubc30\uc6e0\ub358 \uac83\ub3c4 \uac19\uc2b5\ub2c8\ub2e4.)<br \/>\n\uc989 RGB\ub97c HSL\uac12\uc73c\ub85c \ubcc0\ud658\ud55c \ud6c4 HSL\uc5d0\uc11c \uc0c9\uc870(hue)\ub97c 180\ub3c4 \ub3cc\ub824\uc900 \ud6c4 \uc774 HSL \uac12\uc744 RGB \uac12\uc73c\ub85c \ub2e4\uc2dc \ubcc0\ud658\ud558\uba74 \ub429\ub2c8\ub2e4.<\/p>\n<p><b>&#8211; \ubcf4\uc0c9 \uad6c\ud558\ub294 \ud568\uc218<\/b><\/p>\n<p>[code language=&#8221;cpp&#8221;]<br \/>\n\/\/<br \/>\n\/\/ Calculate complementary color<br \/>\n\/\/<br \/>\n\/\/ @param clr : [in] COLORREF, input RGB color from which<br \/>\n\/\/                             complementary color is calculated<br \/>\n\/\/<br \/>\n\/\/ @return RGB color value of complementary color of input RGB color<\/p>\n<p>COLORREF CalcComplemental(COLORREF clr)<br \/>\n{<br \/>\n    long hsl_h = 0, hsl_s = 0, hsl_l = 0;<br \/>\n    RGB2HSL_(clr, hsl_h, hsl_s, hsl_l); \/\/ CONV RGB to HSL<br \/>\n    hsl_h += 0x200; \/\/ HUE, ADD 180 deg (0x200 = 0x400 \/ 2)<br \/>\n    hsl_h &amp;= 0x7ff; \/\/ HUE, MOD 360 deg to HUE<br \/>\n    return HSL2RGB_(hsl_h, hsl_s, hsl_l); \/\/ CONV HSL to RGB<br \/>\n}<br \/>\n[\/code]<\/p>\n<p><b>&#8211; RGB \uc5d0\uc11c HSL \ubcc0\ud658\ud558\ub294 \ud568\uc218<\/b><\/p>\n<p>[code language=&#8221;cpp&#8221;]<br \/>\n\/\/<br \/>\n\/\/ RGB to HSL conversion<br \/>\n\/\/<br \/>\n\/\/ @param clr : [in] COLORREF, input RGB value to be converted<br \/>\n\/\/ @param hue : [out] double &amp;, converted hue value (0 ~ 2*PI)<br \/>\n\/\/ @param saturation : [out] double &amp;, converted saturation value (0%~ 100%)<br \/>\n\/\/ @param lightness : [out] double &amp;, converted lightness value (0% ~ 100%)<br \/>\nvoid RGB2HSL( COLORREF clr,<br \/>\n              double &amp; hue,<br \/>\n              double &amp; saturation,<br \/>\n              double &amp; lightness)<br \/>\n{<br \/>\n    long hsl_h = 0, hsl_s = 0, hsl_l = 0;<br \/>\n    RGB2HSL_(clr, hsl_h, hsl_s, hsl_l);<\/p>\n<p>    \/\/ long to double<br \/>\n    hue = 2.0 * 3.141592 * (double)hsl_h \/ 1024.0;<br \/>\n    saturation = (double)hsl_s \/ 1024.0;<br \/>\n    lightness = (double)hsl_l \/ 1024.0;<br \/>\n}<br \/>\n[\/code]<\/p>\n<p><b>&#8211; HSL \uc5d0\uc11c RGB \ubcc0\ud658\ud558\ub294 \ud568\uc218<\/b><\/p>\n<p>[code language=&#8221;cpp&#8221;]<br \/>\n\/\/<br \/>\n\/\/ HSL to RGB conversion<br \/>\n\/\/<br \/>\n\/\/ @param hue : [in] double, input hue value (0 ~ 2*PI)<br \/>\n\/\/ @param saturation : [in] double, input saturation value (0% ~ 100%)<br \/>\n\/\/ @param lightnelss : [in] double, input lightness value (0% ~ 100%)<br \/>\n\/\/<br \/>\n\/\/ @return converted RGB color value from the input HSL value<br \/>\nCOLORREF HSL2RGB(double hue, double saturation, double lightness)<br \/>\n{<br \/>\n    \/\/ double to long<br \/>\n    const long hsl_h = (long)(hue \/ 2.0 \/ 3.141592 * 1024.0);<br \/>\n    const long hsl_s = (long)(saturation * 1024.0);<br \/>\n    const long hsl_l = (long)(lightness * 1024.0);<\/p>\n<p>    return HSL2RGB_(hsl_h, hsl_s, hsl_l);<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>&#8211; \uc635\ud2f0\ub9c8\uc774\uc9d5<\/p>\n<p>[code language=&#8221;cpp&#8221;]<br \/>\n\/\/<br \/>\n\/\/ Integer version with 2^10(1024) resolution<br \/>\n\/\/<br \/>\n\/\/ @param hsl_h : [out] long &amp;, hue, 0 ~ 1024<br \/>\n\/\/ @param hsl_s : [out] long &amp;, saturation, 0 ~ 1024<br \/>\n\/\/ @param hsl_l : [out] long &amp;, lightness, 0 ~ 1024<br \/>\nvoid RGB2HSL_(COLORREF clr, long &amp; hsl_h, long &amp; hsl_s, long &amp; hsl_l)<br \/>\n{<br \/>\n    const long var_r = GetRValue(clr) &lt;&lt; 2;<br \/>\n    const long var_g = GetGValue(clr) &lt;&lt; 2;<br \/>\n    const long var_b = GetBValue(clr) &lt;&lt; 2;<\/p>\n<p>    const long var_min = min(var_r, min(var_g, var_b));<br \/>\n    const long var_max = max(var_r, max(var_g, var_b));<br \/>\n    const long del_max = var_max &#8211; var_min;<\/p>\n<p>    hsl_l = (var_max + var_min) &gt;&gt; 1;<\/p>\n<p>    if(del_max == 0)<br \/>\n    {<br \/>\n        hsl_h = hsl_s = 0;<br \/>\n    }else<br \/>\n    {<br \/>\n        if(hsl_l &lt; 512)<br \/>\n            hsl_s = (del_max &lt;&lt; 10) \/ (var_max + var_min);<br \/>\n         else<br \/>\n            hsl_s = (del_max &lt;&lt; 10) \/ (2048 &#8211; var_max &#8211; var_min);<br \/>\n    }<\/p>\n<p>    const long temp = (var_max &lt;&lt; 9) \/ 3 \/ del_max + (del_max &lt;&lt; 9) \/ del_max;<\/p>\n<p>    const long del_r = temp &#8211; ((var_r &lt;&lt; 9) \/ 3) \/ del_max;<br \/>\n    const long del_g = temp &#8211; ((var_g &lt;&lt; 9) \/ 3) \/ del_max;<br \/>\n    const long del_b = temp &#8211; ((var_b &lt;&lt; 9) \/ 3) \/ del_max;<\/p>\n<p>    if(var_r == var_max)<br \/>\n        hsl_h = del_b &#8211; del_g;<br \/>\n    else if(var_g == var_max)<br \/>\n        hsl_h = (1024 \/ 3) + del_r &#8211; del_b;<br \/>\n    else if(var_b == var_max)<br \/>\n        hsl_h = (2048 \/ 3) + del_g &#8211; del_r;<\/p>\n<p>     if(hsl_h &lt; 0)<br \/>\n         hsl_h += 1024;<br \/>\n     else if(hsl_h &gt; 1024)<br \/>\n         hsl_h -= 1024;<br \/>\n}<\/p>\n<p>\/\/<br \/>\n\/\/ Integer version with 2^10(1024) resolution<br \/>\n\/\/<br \/>\n\/\/ @param hsl_h : [in] long, hue, 0 ~ 1024<br \/>\n\/\/ @param hsl_s : [in] long, saturation, 0 ~ 1024<br \/>\n\/\/ @param hsl_l : [in] long, lightness, 0 ~ 1024<br \/>\nCOLORREF HSL2RGB_(long hsl_h, long hsl_s, long hsl_l)<br \/>\n{<br \/>\n    BYTE clrR = 0, clrG = 0, clrB = 0;<br \/>\n    long var_1 = 0, var_2 = 0;<\/p>\n<p>    const long var_h = hsl_h;<br \/>\n    const long var_s = hsl_s;<br \/>\n    const long var_l = hsl_l;<\/p>\n<p>    if(hsl_s == 0)<br \/>\n        clrR = clrG = clrB = (BYTE)(var_l &gt;&gt; 2);<br \/>\n    else<br \/>\n    {<br \/>\n        if(var_l &lt; 512)<br \/>\n            var_2 = var_l + ((var_l * var_s) &gt;&gt; 10);<br \/>\n        else<br \/>\n            var_2 = var_l + var_s &#8211; ((var_l * var_s) &gt;&gt; 10);<\/p>\n<p>        var_1 = (var_l &lt;&lt; 1) &#8211; var_2;<\/p>\n<p>        clrR = (BYTE)(HUE2RGB_(var_1, var_2, var_h + (1024 \/ 3)) &gt;&gt; 2);<br \/>\n        clrG = (BYTE)(HUE2RGB_(var_1, var_2, var_h) &gt;&gt; 2);<br \/>\n        clrB = (BYTE)(HUE2RGB_(var_1, var_2, var_h &#8211; (1024 \/ 3)) &gt;&gt; 2);<br \/>\n    }<\/p>\n<p>    return RGB(clrR, clrG, clrB);<br \/>\n}<\/p>\n<p>long HUE2RGB_(long var_1, long var_2, long var_h)<br \/>\n{<br \/>\n    if(var_h &lt; 0)<br \/>\n        var_h += 1024;<br \/>\n    else if(var_h &gt; 1024)<br \/>\n        var_h -= 1024;<\/p>\n<p>    const long temp1 = 3 * var_h;<\/p>\n<p>    if(temp1 &lt; 512)<br \/>\n        return (var_1 + (((3 * var_2 * var_h) &gt;&gt; 9) &#8211;<br \/>\n((3 * var_1 * var_h) &gt;&gt; 9)));<br \/>\n    else if(var_h &lt; 512)<br \/>\n        return var_2;<br \/>\n    else if(temp1 &lt; 2048)<br \/>\n    {<br \/>\n         const long temp2 = 4096 &#8211; (temp1 &lt;&lt; 1);<br \/>\n        return (var_1 + ((var_2 * temp2 &#8211; var_1 * temp2) &gt;&gt; 10));<br \/>\n    }<\/p>\n<p> return var_1;<br \/>\n}<br \/>\n[\/code]\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.devpia.com\/Maeul\/Contents\/Detail.aspx?BoardID=51&amp;MAEULNO=20&amp;no=7249&amp;page=45 \ubcf4\uc0c9\uc774\ub780 \uc0c9\uc0c1\ud720\uc5d0\uc11c \uc0c9\uc870(hue) \uac12\uc774 180\ub3c4 \ubc18\ub300\ubc29\ud5a5\uc5d0 \uc704\uce58\ud55c\ub2e4\uace0 \ud569\ub2c8\ub2e4. (\uc5b4\ub834\ud48b \uc608\uc804 \ubbf8\uc220 \uc2dc\uac04\uc5d0 \ubc30\uc6e0\ub358 \uac83\ub3c4 \uac19\uc2b5\ub2c8\ub2e4.) \uc989 RGB\ub97c HSL\uac12\uc73c\ub85c \ubcc0\ud658\ud55c \ud6c4 HSL\uc5d0\uc11c \uc0c9\uc870(hue)\ub97c 180\ub3c4 \ub3cc\ub824\uc900 \ud6c4 \uc774 HSL \uac12\uc744 RGB \uac12\uc73c\ub85c \ub2e4\uc2dc \ubcc0\ud658\ud558\uba74 \ub429\ub2c8\ub2e4. &#8211; \ubcf4\uc0c9 \uad6c\ud558\ub294 \ud568\uc218 [code language=&#8221;cpp&#8221;] \/\/ \/\/ Calculate complementary color \/\/ \/\/ @param clr : [in] COLORREF, input RGB color [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=501"}],"version-history":[{"count":0,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions"}],"wp:attachment":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}