본문 바로가기

Study/알고리즘

CHROMA RGB 값

프로그램을 하다 보면 어떠한 값을 색상으로 표현할때가 있다.


그렇때 사용하면 좋은 Chroma 라는게 있음


사용하기 편하게 ARGB 값으로 변환해 놓았습니다.

c#에서 사용하느라 ARGB로 만들었는데 RGB만 필요하신 분은 앞자리 FF를 지우시면 됩니다.


uint[] ARGB = new uint[] { 0xFFFF0000, 0xFFFF0400, 0xFFFF0800, 0xFFFF0C00, 0xFFFF1000, 0xFFFF1400, 0xFFFF1800, 0xFFFF1C00, 0xFFFF2000, 0xFFFF2400, 0xFFFF2800, 0xFFFF2C00, 0xFFFF3000, 0xFFFF3400, 0xFFFF3800, 0xFFFF3C00, 0xFFFF4000, 0xFFFF4400, 0xFFFF4800, 0xFFFF4C00, 0xFFFF5000, 0xFFFF5400, 0xFFFF5800, 0xFFFF5C00, 0xFFFF6000, 0xFFFF6400, 0xFFFF6800, 0xFFFF6C00, 0xFFFF7000, 0xFFFF7400, 0xFFFF7800, 0xFFFF7C00, 0xFFFF8000, 0xFFFF8300, 0xFFFF8700, 0xFFFF8B00, 0xFFFF8F00, 0xFFFF9300, 0xFFFF9700, 0xFFFF9B00, 0xFFFF9F00, 0xFFFFA300, 0xFFFFA700, 0xFFFFAB00, 0xFFFFAF00, 0xFFFFB300, 0xFFFFB700, 0xFFFFBB00, 0xFFFFBF00, 0xFFFFC300, 0xFFFFC700, 0xFFFFCB00, 0xFFFFCF00, 0xFFFFD300, 0xFFFFD700, 0xFFFFDB00, 0xFFFFDF00, 0xFFFFE300, 0xFFFFE700, 0xFFFFEB00, 0xFFFFEF00, 0xFFFFF300, 0xFFFFF700, 0xFFFFFB00, 0xFFFFFF00, 0xFFFBFF00, 0xFFF7FF00, 0xFFF3FF00, 0xFFEFFF00, 0xFFEBFF00, 0xFFE7FF00, 0xFFE3FF00, 0xFFDFFF00, 0xFFDBFF00, 0xFFD7FF00, 0xFFD3FF00, 0xFFCFFF00, 0xFFCBFF00, 0xFFC7FF00, 0xFFC3FF00, 0xFFBFFF00, 0xFFBBFF00, 0xFFB7FF00, 0xFFB3FF00, 0xFFAFFF00, 0xFFABFF00, 0xFFA7FF00, 0xFFA3FF00, 0xFF9FFF00, 0xFF9BFF00, 0xFF97FF00, 0xFF93FF00, 0xFF8FFF00, 0xFF8BFF00, 0xFF87FF00, 0xFF83FF00, 0xFF80FF00, 0xFF7CFF00, 0xFF78FF00, 0xFF74FF00, 0xFF70FF00, 0xFF6CFF00, 0xFF68FF00, 0xFF64FF00, 0xFF60FF00, 0xFF5CFF00, 0xFF58FF00, 0xFF54FF00, 0xFF50FF00, 0xFF4CFF00, 0xFF48FF00, 0xFF44FF00, 0xFF40FF00, 0xFF3CFF00, 0xFF38FF00, 0xFF34FF00, 0xFF30FF00, 0xFF2CFF00, 0xFF28FF00, 0xFF24FF00, 0xFF20FF00, 0xFF1CFF00, 0xFF18FF00, 0xFF14FF00, 0xFF10FF00, 0xFF0CFF00, 0xFF08FF00, 0xFF04FF00, 0xFF00FF00, 0xFF00FF04, 0xFF00FF08, 0xFF00FF0C, 0xFF00FF10, 0xFF00FF14, 0xFF00FF18, 0xFF00FF1C, 0xFF00FF20, 0xFF00FF24, 0xFF00FF28, 0xFF00FF2C, 0xFF00FF30, 0xFF00FF34, 0xFF00FF38, 0xFF00FF3C, 0xFF00FF40, 0xFF00FF44, 0xFF00FF48, 0xFF00FF4C, 0xFF00FF50, 0xFF00FF54, 0xFF00FF58, 0xFF00FF5C, 0xFF00FF60, 0xFF00FF64, 0xFF00FF68, 0xFF00FF6C, 0xFF00FF70, 0xFF00FF74, 0xFF00FF78, 0xFF00FF7C, 0xFF00FF80, 0xFF00FF83, 0xFF00FF87, 0xFF00FF8B, 0xFF00FF8F, 0xFF00FF93, 0xFF00FF97, 0xFF00FF9B, 0xFF00FF9F, 0xFF00FFA3, 0xFF00FFA7, 0xFF00FFAB, 0xFF00FFAF, 0xFF00FFB3, 0xFF00FFB7, 0xFF00FFBB, 0xFF00FFBF, 0xFF00FFC3, 0xFF00FFC7, 0xFF00FFCB, 0xFF00FFCF, 0xFF00FFD3, 0xFF00FFD7, 0xFF00FFDB, 0xFF00FFDF, 0xFF00FFE3, 0xFF00FFE7, 0xFF00FFEB, 0xFF00FFEF, 0xFF00FFF3, 0xFF00FFF7, 0xFF00FFFB, 0xFF00FFFF, 0xFF00FBFF, 0xFF00F7FF, 0xFF00F3FF, 0xFF00EFFF, 0xFF00EBFF, 0xFF00E7FF, 0xFF00E3FF, 0xFF00DFFF, 0xFF00DBFF, 0xFF00D7FF, 0xFF00D3FF, 0xFF00CFFF, 0xFF00CBFF, 0xFF00C7FF, 0xFF00C3FF, 0xFF00BFFF, 0xFF00BBFF, 0xFF00B7FF, 0xFF00B3FF, 0xFF00AFFF, 0xFF00ABFF, 0xFF00A7FF, 0xFF00A3FF, 0xFF009FFF, 0xFF009BFF, 0xFF0097FF, 0xFF0093FF, 0xFF008FFF, 0xFF008BFF, 0xFF0087FF, 0xFF0083FF, 0xFF0080FF, 0xFF007CFF, 0xFF0078FF, 0xFF0074FF, 0xFF0070FF, 0xFF006CFF, 0xFF0068FF, 0xFF0064FF, 0xFF0060FF, 0xFF005CFF, 0xFF0058FF, 0xFF0054FF, 0xFF0050FF, 0xFF004CFF, 0xFF0048FF, 0xFF0044FF, 0xFF0040FF, 0xFF003CFF, 0xFF0038FF, 0xFF0034FF, 0xFF0030FF, 0xFF002CFF, 0xFF0028FF, 0xFF0024FF, 0xFF0020FF, 0xFF001CFF, 0xFF0018FF, 0xFF0014FF, 0xFF0010FF, 0xFF000CFF, 0xFF0008FF, 0xFF0004FF };

        

0~255 사이의 값으로 만들어 놨습니다. 0은 빨강 255는 파랑입니다.

 

 

아래 코드는 0은 빨강 255는 자주색 코드입니다. 비주얼 스튜디오 에서 작성했습니다.

private Color HSLtoRGB(int num)
        {
            Color result = Color.FromArgb(0);
            if(0 <= num && num <= 51)  // 255, 0, 0
            {
                result = Color.FromArgb(0xFF, num * 5, 0x00);
            }
            else if(51 < num && num <= 102)  // 255, 255, 0
            {
                result = Color.FromArgb(255 - (num - 51) * 5, 0xFF, 0x00);
            }
            else if (102 < num && num <= 153)  // 0, 255, 0
            {
                result = Color.FromArgb(0x00, 0xFF, (num - 102) * 5);
            }
            else if (153 < num && num <= 204)  // 0, 255, 255
            {
                result = Color.FromArgb(0x00, 255 - (num - 153) * 5, 0xFF);
            }
            else if (204 < num && num <= 255)  // 0, 0, 255
            {
                result = Color.FromArgb((num - 204) * 5, 0x00, 0xFF);
            }
            return result;
        }

 

 

참고 : https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV

'Study > 알고리즘' 카테고리의 다른 글

FFT 이해  (0) 2014.01.17
PCA를 돌리는 실제 C코드  (0) 2011.06.27