├── .gitattributes ├── .gitignore ├── .idea ├── ColorRNA.iml ├── encodings.xml ├── misc.xml ├── modules.xml ├── vcs.xml ├── watcherTasks.xml └── workspace.xml ├── bin ├── ColorRNA.js └── ColorRNA.min.js ├── build-min.js ├── logo ├── ColorRNA_LOGO_PNG_ONLY_256.png ├── ColorRNA_LOGO_PNG_ONLY_512.png ├── ColorRNA_LOGO_PNG_Word_128.png ├── ColorRNA_LOGO_PNG_Word_256 - 副本.png ├── ColorRNA_LOGO_PNG_Word_256.png ├── ColorRNA_LOGO_PNG_Word_512.png ├── ColorRNA_LOGO_PNG_Word_512.psd └── ColorRNA_LOGO_PSD.psd ├── package.json ├── readme.MD ├── rollup-min.config.js ├── rollup.config.js ├── src └── ColorRNA.js └── test ├── test.html ├── test_1.js └── test_node.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | 5 | # Custom for Visual Studio 6 | *.cs diff=csharp 7 | 8 | # Standard to msysgit 9 | *.doc diff=astextplain 10 | *.DOC diff=astextplain 11 | *.docx diff=astextplain 12 | *.DOCX diff=astextplain 13 | *.dot diff=astextplain 14 | *.DOT diff=astextplain 15 | *.pdf diff=astextplain 16 | *.PDF diff=astextplain 17 | *.rtf diff=astextplain 18 | *.RTF diff=astextplain 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | .idea 5 | node_modules 6 | 7 | # Folder config file 8 | Desktop.ini 9 | 10 | # Recycle Bin used on file shares 11 | $RECYCLE.BIN/ 12 | 13 | # Windows Installer files 14 | *.cab 15 | *.msi 16 | *.msm 17 | *.msp 18 | 19 | # Windows shortcuts 20 | *.lnk 21 | 22 | # ========================= 23 | # Operating System Files 24 | # ========================= 25 | 26 | # OSX 27 | # ========================= 28 | 29 | .DS_Store 30 | .AppleDouble 31 | .LSOverride 32 | 33 | # Thumbnails 34 | ._* 35 | 36 | # Files that might appear on external disk 37 | .Spotlight-V100 38 | .Trashes 39 | 40 | # Directories potentially created on remote AFP share 41 | .AppleDB 42 | .AppleDesktop 43 | Network Trash Folder 44 | Temporary Items 45 | .apdisk 46 | src/test.js 47 | test.min.js 48 | test.js 49 | -------------------------------------------------------------------------------- /.idea/ColorRNA.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | JSON 15 | 16 | 17 | JavaScript 18 | 19 | 20 | 21 | 22 | JsonDuplicatePropertyKeys 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/watcherTasks.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 124 | 125 | 126 | 128 | 129 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | true 151 | 152 | false 153 | true 154 | 155 | 156 | true 157 | DEFINITION_ORDER 158 | 159 | 160 | 161 | 162 | 163 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 192 | 193 | 196 | 197 | 198 | 199 | 202 | 203 | 206 | 207 | 210 | 211 | 212 | 213 | 216 | 217 | 220 | 221 | 224 | 225 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 38 | ``` 39 | 40 | 安装后就可以在你的代码里使用 ColorRNA.js 了: 41 | 42 | ### 在浏览器端 43 | 44 | ```js 45 | ColorRNA(); //ColorRNA.js 载入后可以直接使用 46 | ``` 47 | 48 | ### 在 Node.js 端 49 | ```js 50 | var ColorRNA = require('color-rna'); 51 | ``` 52 | 53 | ### ES6 module 54 | ```js 55 | import ColorRNA from 'color-rna'; 56 | ``` 57 | 使用包管理工具时,你可以简单的用 import。 如果你是直接复制文件,你需要复制 `scr` 目录下的 `ColorRNA.js`,它是 ES6 module 格式的。 58 | 59 | 60 | ## 1. 功能 61 | #### 各种色彩空间转换 62 | 支持以下色彩空间之间颜色值的互换 :`sRGB`, `Adobe RGB`, `Apple RGB`, `Best RGB`, `Beta RGB`, `BruceRGB`, `CIERGB`, `ColorMatchRGB`, `ECIRGBv2`, `DonRGB4`, `EktaSpacePS5`, `NTSC RGB`, `PALSECAM RGB`, `ProPhotoRGB`, `SMPTEC RGB`, `WideGamut RGB`, ` CIE Lab`, `CIE Luv`, `CIE XYZ`, `CIE xyY`, `CIE LCHab`。 63 | 内部色彩使用 `CIE XYZ` 存储。 64 | 65 | 并且支持白点校正与指定伽马参数。支持以下白点参考光照:`A`, `B`, `C`, `D50`, `D55`, `D65`, `D75`, `E`, `F2`, `F7`, `F11`。 66 | 67 | #### 基于 RGB 的色彩模型之间颜色值的互换 : 68 | 支持以下色彩模型的转换:`HSL`, `HSL240` (Windows 拾色器), `HSL255` (MS Office拾色器), `HSV`(HSB), `HWB`, `CMY`, `CMYK`, `YPbPr`, `JpegYCbCr`, `YCbCr`, `YIQ`, `YUV` 。 69 | 70 | 71 | 72 | 73 | #### 色差与辉度计算 74 | 支持以下色差计算方法:`DeltaE 1976`, `DeltaE 1994`, `DeltaE 2000`, `DeltaE CMC`; 75 | 支持以下辉度计算方法:`CCIR 601`, `Rec 709`, `HSP`, `WCAGluma`; 76 | 支持 `WCAG contrast` 对比度计算; 77 | 78 | #### 其他 79 | 计算颜色的光谱主波长。 80 | 81 | 82 | ## 2. 使用 83 | 84 | 85 | ```js 86 | var color1 = new ColorRNA(); 87 | ```` 88 | 89 | 每一个 ColorRNA 对象实例代表一个颜色,ColorRNA 内部使用 CIE XYZ 存储颜色值。 90 | 91 | 92 | ###指定颜色 93 | 94 | 95 | ```js 96 | var color1 = new ColorRNA("#FF0101"); // 16 进制 RGB 色彩值(00~FF)字符串 97 | var color2 = new ColorRNA(255,1,1); // RGB 色彩值(0~255)参数 98 | var color3 = new ColorRNA([255,1,1]); // RGB 色彩值(0~255)数组 99 | 100 | color1.rgb([10, 20, 107]); 101 | color1.rgb("#2F4101"); 102 | color1.rgb(44,21,211); 103 | ``` 104 | 105 | 在 ColorRNA 对象实例创建时可用传递参数给它指定颜色,可传递 RGB (默认为 sRGB 色彩空间)值,也可以传递 RGB 值的数组或者 16 进制代码字符串。 106 | 107 | 创建后可用 `ColorRNA.rgb(r,g,b)` 重新指定颜色,用法和创建时一样。 108 | 109 | #### 指定色彩空间中的颜色 110 | ```js 111 | //支持的 RGB 色彩空间: 112 | color1.sRGB ([10, 20, 107]); 113 | color1.AdobeRGB (44, 21, 211); 114 | color1.AppleRGB (44, 21, 211); 115 | color1.BestRGB (44, 21, 211); 116 | color1.BetaRGB (44, 21, 211); 117 | color1.BruceRGB (44, 21, 211); 118 | color1.CIERGB (44, 21, 211); 119 | color1.ColorMatchRGB (44, 21, 211); 120 | color1.DonRGB4 (44, 21, 211); 121 | color1.ECIRGBv2 (44, 21, 211); 122 | color1.EktaSpacePS5 (44, 21, 211); 123 | color1.NTSCRGB (44, 21, 211); 124 | color1.PALSECAMRGB (44, 21, 211); 125 | color1.ProPhotoRGB (44, 21, 211); 126 | color1.SMPTECRGB (44, 21, 211); 127 | color1.WideGamutRGB (44, 21, 211); 128 | ``` 129 | 130 | 和使用 `ColorRNA.rgb(r,g,b)` 一样,还有以上 16 个指定色彩空间颜色值的方法,用法和 `ColorRNA.rgb(r,g,b)` 完全一样。另外 `ColorRNA.rgb (r,g,b)` 与 `ColorRNA.sRGB (r,g,b)` 效果是一样的,`ColorRNA.rgb (r,g,b)` 使用 `sRGB` 色彩空间。 131 | 132 | 133 | ### 返回色彩 134 | 135 | ```js 136 | var color1 = new ColorRNA(10,235,245); 137 | 138 | color1.rgb () // [10, 235, 245] 139 | color1.sRGB () // [10, 235, 245] 140 | color1.getHex () // #0AEBF5 141 | 142 | color1.AdobeRGB () // [133, 234, 244] 143 | color1.getHex () // #85EAF4 144 | 145 | color1.AppleRGB () // [52, 233, 243] 146 | color1.getHex () // #34E9F3 147 | 148 | color1.ProPhotoRGB () // [154, 218, 239] 149 | color1.getHex () // #9ADAEF 150 | 151 | ``` 152 | 153 | 像上面这样不指定参数的使用 `ColorRNA.rgb()` 和其他色彩空间方法,会返回 ColorRNA 存储的颜色用相应色彩空间表示的色彩值;另外用 `ColorRNA.getHex ()` 会返回最后一次计算的 RGB 值的 16 进制代码,如果没有计算过则使用 sRGB 色彩空间的 RGB 值。 154 | 155 | 156 | ### 色彩空间转换 157 | ```js 158 | var color1 = new ColorRNA(); 159 | 160 | // 转换色彩空间 sRGB -> AdobeRGB: 161 | color1.sRGB (10, 235, 245); 162 | color1.AdobeRGB (); // [133, 234, 244] 163 | 164 | // 转换色彩空间 ProPhotoRGB -> AdobeRGB 165 | color1.ProPhotoRGB (154, 218, 239); 166 | color1.AdobeRGB (); // [133,235,244] 167 | 168 | // 转换色彩空间 AppleRGB -> ProPhotoRGB 169 | color1.AppleRGB(52, 233, 243).ProPhotoRGB (); //[154,218,239] 170 | 171 | ``` 172 | 通过给 ColorRNA 对象实例指定颜色,再返回颜色就可以进行颜色值色彩空间的转换。为了简洁也可以使用 `color1.AppleRGB(52, 233, 243).ProPhotoRGB ()` 这样的链式语句。 173 | 174 | 175 | ### 参考色彩空间 176 | 177 | ```js 178 | 179 | color1.rgb(52, 233, 243).Lab(); // [84.7269, -39.5516, -17.4109] 180 | color1.rgb(52, 233, 243).LabPS(); // [84,-42,-18] 181 | color1.rgb(52, 233, 243).LCHab(); // [84.7269,43.2142,203.7594] 182 | color1.rgb(52, 233, 243).Luv(); // [84.7269,-61.2033,-21.7867] 183 | color1.rgb(52, 233, 243).xyY(); // [0.2256,0.3161,0.6547] 184 | color1.rgb(52, 233, 243).XYZ(); // [0.4672539339338757,0.6547307056620336,0.9495155562423543] 185 | 186 | color1.xyY(0.2256,0.3161,0.6547).rgb(); //[52,233,243] 187 | ``` 188 | 189 | ColorRNA 除了支持各种 RGB 色彩空间之间的互相转换,还支持 `XYZ`、`xyY`、`XYZ`、`Luv`、`LCHab`、色彩空间的转换,使用方法和 RGB 色彩空间的方法一样,也可以与不同的 RGB 色彩空间互相转换。 190 | 191 | 值得注意的是 Lab 色彩空间,PhotoShop 中的 Lab 出于历史原因使用的是 `D50` 参考白点而不是通常的 `D65` ,所以想得到 PhotoShop 里的 Lab 值应该使用 `ColorRNA.LabPS()` ,这个方法的计算的结果和 PhotoShop 一致。 192 | 193 | ### 基于 RGB 的色彩模型 194 | 195 | ```js 196 | color1.rgb (52, 233, 243); 197 | 198 | color1.HSB (); // [183, 79, 95] 199 | color1.HSL (); // [183, 89, 58] 200 | color1.HSL240 (); // [122, 213, 139] 201 | color1.HSL255 (); // [130, 227, 147] 202 | color1.HWB (); // [183, 20, 5] 203 | color1.CMY (); // [80,9,5] 204 | color1.CMYK (); // [79,4,0,5] 205 | color1.YUV (); // [0.7059647058823528, 0.12143921568627458, -0.44045098039215685] 206 | color1.YIQ (); // [0.7059647058823528, -0.43544010196078436, -0.1378909254901961] 207 | color1.YCbCr (); // [170.60627058823528, 159.2206156862745, 47.78768627450981] 208 | color1.JpegYCbCr (); // [0.7059647058823528, 0.6393771749019608, 0.14190933333333333] 209 | color1.YPbPr (); // [0.7059647058823528, 0.13937717490196078, -0.35809066666666667] 210 | 211 | 212 | 213 | color1.HSB(183,79,95).rgb (); // [51,233,242] 214 | color1.HSL(183,89,58).rgb (); // [53,234,243] 215 | color1.HSL240(122,213,139).rgb (); // [53,231,243] 216 | color1.HSL255(130,227,147).rgb (); // [53,231,243] 217 | color1.HWB(183,20,5).rgb (); // [51,233,242] 218 | color1.CMY(80,9,5).rgb (); // [51,232,242] 219 | color1.CMYK(79,4,0,5).rgb (); // [51,232,242] 220 | color1.YUV(0.7059647058823528,0.12143921568627458,-0.44045098039215685).rgb (); // [52,233,243] 221 | color1.YIQ(0.7059647058823528,-0.43544010196078436,-0.1378909254901961).rgb (); // [52,233,243] 222 | color1.YCbCr(170.60627058823528,159.2206156862745,47.78768627450981).rgb (); // [52,233,243] 223 | color1.JpegYCbCr(0.7059647058823528,0.6393771749019608,0.14190933333333333).rgb (); // [52,233,243] 224 | color1.YPbPr(0.7059647058823528,0.13937717490196078,-0.35809066666666667).rgb (); // [52,233,243] 225 | ``` 226 | 除了前面色彩空间之间的转换, ColorRNA 还支持各种基于 RGB 值的色彩模型之间的转换(前面的各种色彩空间基于 `CIE XYZ` 进行转换)。 227 | 228 | 默认是基于 `sRGB` 色彩空间来计算,比如使用 `color1.HSB(183,79,95)` 将认为这是一个基于 `sRGB` 的 `HSB` 值,并返回一个 `sRGB` 色彩空间的 RGB 值:`[51,233,242]`; 可以在色彩模型方法最后一个参数传递指定的色彩空间如 :`color1.HSB(183,79,95,"AdobeRGB")`; 229 | 230 | 另外 231 | `HSL240` 是 Windows 系统拾色器使用的模型,出现在“画图”和各种使用系统 API 的程序中,它与通常 `HSL` (比如 Photoshop 和 网页标准)取值范围:`0~360, 0~100, 0~100`不同,`HSL240` 的取值范围是: `0~239, 0~240 ,0~240`。 232 | 233 | `HSL255` 是微软 Office 中拾色器使用的模型,`HSL255` 的取值范围是: `0~255, 0~255 ,0~255`。 234 | 235 | 这里的 `CMY` 和 `CMYK` 是单纯基于 RGB 色彩值用补色原理计算的色彩模型,与 PhotoShop 中基于 `CIE XYZ` 的各种 CMYK 色彩空间并不相同 。 236 | 237 | ### 其他色彩信息计算 238 | 239 | #### 主波长 240 | ```js 241 | color1.rgb(255, 255, 0).getWavelength() // 570.4668 (nm) 242 | ``` 243 | 244 | #### 辉度 245 | ```js 246 | color1.rgb(112, 255, 0); 247 | color1.getLuma(); // 0.8085772549019608 248 | color1.getLuma("709"); // 0.8085772549019608 249 | color1.getLuma("601"); // 0.7183254901960784 250 | color1.getLuma("HSP"); // 0.8587732011397251 251 | color1.getWCAGluma(); // 0.7496474452608749 252 | 253 | ``` 254 | `ColorRNA.getLuma()` 方法能得到颜色的辉度,也就是视觉亮度,可用 `CCIR 601`, `Rec 709`, `HSP`, 三种计算方法,如果不在参数中指定计算方法,默认使用 `Rec 709` 计算。 255 | 256 | `ColorRNA.getWCAGluma()` 是互联网无障碍标准中的视觉亮度计算方法。 257 | 258 | #### 色差与对比度计算 259 | 260 | ```js 261 | color1.rgb(123, 124, 21); 262 | color2.rgb(44, 22, 33); 263 | 264 | color1.diff_DE1976_Than(color2); // 71.42 265 | color2.diff_DE1976_Than(color1); // 71.42 266 | color1.diff_DE1994_GraphicArts_Than(color2); // 48.35 267 | color2.diff_DE1994_GraphicArts_Than(color1); // 59.65 268 | color1.diff_DE1994_Textiles_Than(color2); // 34.46 269 | color2.diff_DE1994_Textiles_Than(color1); // 48.83 270 | color1.diff_DE2000_Than(color2); // 48.63 271 | color2.diff_DE2000_Than(color1); // 48.63 272 | color1.diff_ECMC11_Than(color2); // 47.01 273 | color2.diff_ECMC11_Than(color1); // 93.92 274 | color1.diff_ECMC11_Than(color2); // 47.01 275 | color2.diff_ECMC11_Than(color1); // 93.92 276 | color1.diff_ECMC21_Than(color2); // 34.96 277 | color2.diff_ECMC21_Than(color1); // 65.67 278 | color1.getWCAGcontrastThan(color2); // 3.8076911332106675 279 | color2.getWCAGcontrastThan(color1); // 3.8076911332106675 280 | 281 | ``` 282 | 可用使用 283 | `ColorRNA.diff_DE1976_Than()`、`ColorRNA.diff_DE1994_GraphicArts_Than()`、`ColorRNA.diff_DE1994_Textiles_Than()`、`ColorRNA.diff_DE2000_Than()`、`ColorRNA.diff_ECMC11_Than()`、`ColorRNA.diff_ECMC21_Than()` 这些计算方法得到一个颜色相对于另一个颜色的色差 ,注意颜色有前景背景之分,顺序不同结果可能会不一样。 284 | 285 | `ColorRNA.getWCAGcontrastThan()` 可用得到互联网无障碍标准中一个颜色相对于另一个颜色的的对比度,其结果取值范围: `0~21`。 286 | 287 | 288 | ## 高级功能 289 | 290 | ### 指定参考白点 291 | 292 | ```js 293 | color1.setRefWhite("A"); 294 | color1.setRefWhite("B"); 295 | color1.setRefWhite("C"); 296 | color1.setRefWhite("D50"); 297 | color1.setRefWhite("D55"); 298 | color1.setRefWhite("D65"); 299 | color1.setRefWhite("D75"); 300 | color1.setRefWhite("E"); 301 | color1.setRefWhite("F2"); 302 | color1.setRefWhite("F7"); 303 | color1.setRefWhite("F11"); 304 | 305 | ``` 306 | 307 | `ColorRNA.setRefWhite()` , ` ColorRNA.getRefWhite()` 可用分别用来设置和返回的参考白点参数,这会对色彩空间转换有影响。 308 | 309 | 310 | -------------------------------------------------------------------------------- /rollup-min.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by nullice on 2017/4/5. 3 | */ 4 | 5 | import uglify from 'rollup-plugin-uglify'; 6 | export default { 7 | entry: 'src/ColorRNA.js', 8 | format: 'umd', 9 | moduleName:"ColorRNA", 10 | dest: 'bin/ColorRNA.min.js', // equivalent to --output, 11 | plugins: [ 12 | uglify() 13 | ] 14 | }; 15 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by nullice on 2017/4/5. 3 | */ 4 | 5 | export default { 6 | entry: 'src/ColorRNA.js', 7 | format: 'umd', 8 | moduleName:"ColorRNA", 9 | dest: 'bin/ColorRNA.js', // equivalent to --output, 10 | }; 11 | -------------------------------------------------------------------------------- /src/ColorRNA.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by 语冰 on 2015/9/22. 3 | */ 4 | 5 | 6 | function ColorRNA() 7 | { 8 | //---私有 9 | 10 | this._xyz = {X: 0, Y: 0, Z: 0}; 11 | 12 | this._gamma = -2.2; //gamma 变换值; _gamma < 0 表示 sRGB 模式 13 | this._colorSpace = "sRGB"; 14 | this._refWhiteName = "D65"; 15 | this._refWhiteNameUSER = "";//强制制度值 16 | this._adtAlg = "Bradford"; 17 | this._doAdapta = true; 18 | this._doAdaptaUSER = 0;// 0 默认,1 强制使用,-1 强制不使用 19 | 20 | 21 | this._dLV = 1; //计算精度 2:16位, 1:7位, 0:4位; 22 | 23 | this._COLORSPACES = 24 | { 25 | sRGB: "sRGB", 26 | AdobeRGB: "AdobeRGB", 27 | AppleRGB: "AppleRGB", 28 | BestRGB: "BestRGB", 29 | BetaRGB: "BetaRGB", 30 | BruceRGB: "BruceRGB", 31 | CIERGB: "CIERGB", 32 | ColorMatchRGB: "ColorMatchRGB", 33 | ECIRGBv2: "ECIRGBv2", 34 | DonRGB4: "DonRGB4", 35 | EktaSpacePS5: "EktaSpacePS5", 36 | NTSCRGB: "NTSCRGB", 37 | PALSECAMRGB: "PALSECAMRGB", 38 | ProPhotoRGB: "ProPhotoRGB", 39 | SMPTECRGB: "SMPTECRGB", 40 | WideGamutRGB: "WideGamutRGB" 41 | } 42 | this._REFWHITES = 43 | { 44 | A: "A", 45 | B: "B", 46 | C: "C", 47 | D50: "D50", 48 | D55: "D55", 49 | D65: "D65", 50 | D75: "D75", 51 | E: "E", 52 | F2: "F2", 53 | F7: "F7", 54 | F11: "F11" 55 | } 56 | 57 | 58 | this._adt_refWhite = {X: 0, Y: 0, Z: 0};// 参考白 59 | this._adt_refWhiteRGB = {X: 0, Y: 0, Z: 0};// RGB 色彩空间参考白 60 | this._adt_mtxAdaptMa = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; 61 | this._adt_mtxAdaptMaI = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; 62 | 63 | 64 | //---in RGB----------------------- 65 | this._rgbX(arguments, this._COLORSPACES.sRGB) 66 | 67 | } 68 | 69 | //---原型函数-------------------------------------------------------------------------------------------------- 70 | 71 | 72 | //取 RGB 值,如:#ffffff 73 | ColorRNA.prototype._RGBstring = function () 74 | { 75 | return "#" + this.r.toString(16) + this.g.toString(16) + this.b.toString(16) 76 | } 77 | 78 | ColorRNA.prototype._arrayProduct = function (inArray, inArray2) 79 | { 80 | var sum = 0; 81 | for (var z = 0; z < inArray.length; z++) 82 | { 83 | sum += inArray[z] * inArray2[z]; 84 | } 85 | 86 | return sum; 87 | } 88 | 89 | 90 | //把一个数 inNumber 归一化;inMax,inMin 为原最大最小区间,newMax 为新最大值;如果只有一个参数将按[0,255] 归一化到 [0,1] 91 | ColorRNA.prototype._normaliz = function (inNumber, inMin, inMax, newMax) 92 | { 93 | var newNumber = 0; 94 | 95 | if (arguments.length == 4) 96 | { 97 | newNumber = (inNumber - inMin) / (inMax - inMin); 98 | newNumber = newNumber * newMax; 99 | } 100 | else 101 | { 102 | newNumber = arguments[0] / 255; 103 | } 104 | 105 | return newNumber; 106 | } 107 | 108 | ColorRNA.prototype._normalizArray = function (inArray, inMin, inMax, newMax) 109 | { 110 | for (var i = 0; i < inArray.length; i++) 111 | { 112 | inArray[i] = this._normaliz(inArray[i], inMin, inMax, newMax); 113 | } 114 | return inArray; 115 | } 116 | 117 | 118 | ColorRNA.prototype._arrayFixed = function (inArray, Number) 119 | { 120 | for (var z = 0; z < inArray.length; z++) 121 | { 122 | inArray[z] = +inArray[z].toFixed(Number); 123 | } 124 | } 125 | 126 | ColorRNA.prototype._arrayRound = function (inArray) 127 | { 128 | for (var z = 0; z < inArray.length; z++) 129 | { 130 | 131 | inArray[z] = Math.round(inArray[z]); 132 | } 133 | } 134 | 135 | 136 | //对已经归一化的 RGB 值进行 Gamma 2.2 的变换, 137 | ColorRNA.prototype._enGamma = function (rgb) 138 | { 139 | var newRGB = 0; 140 | var sign = 1; 141 | 142 | if (rgb < 0)//处理负数情况 143 | { 144 | sign = -1; 145 | rgb = -rgb; 146 | } 147 | 148 | 149 | if (this._gamma < 0)//----sRGB----------- 150 | { 151 | 152 | if (rgb <= 0.0031306684425005883) 153 | { 154 | newRGB = sign * rgb * 12.92; 155 | } 156 | else 157 | { 158 | newRGB = sign * 1.055 * Math.pow(rgb, 0.416666666666666667) - 0.055 //0.416666666666666667 = 1/2.4; 159 | } 160 | } 161 | if (this._gamma == 0)//-----L*----------- 162 | { 163 | 164 | if (rgb <= (216.0 / 24389.0)) 165 | { 166 | newRGB = sign * (rgb * 24389.0 / 2700.0); 167 | } 168 | else 169 | { 170 | newRGB = sign * (1.16 * Math.pow(rgb, 1.0 / 3.0) - 0.16); 171 | } 172 | } 173 | if (this._gamma > 0)//-----普通 Gamma----------- 174 | { 175 | 176 | newRGB = sign * Math.pow(rgb, 1 / this._gamma); 177 | } 178 | 179 | 180 | return newRGB; 181 | 182 | } 183 | 184 | 185 | ColorRNA.prototype._adt_adaptation = function (lightName, algName) 186 | { 187 | 188 | this._adt_setRefWhite(lightName); 189 | this._adt_setAdaptMa(algName); 190 | 191 | 192 | var Ad = this._adt_refWhite.X * this._adt_mtxAdaptMa[0][0] + this._adt_refWhite.Y * this._adt_mtxAdaptMa[1][0] + this._adt_refWhite.Z * this._adt_mtxAdaptMa[2][0]; 193 | var Bd = this._adt_refWhite.X * this._adt_mtxAdaptMa[0][1] + this._adt_refWhite.Y * this._adt_mtxAdaptMa[1][1] + this._adt_refWhite.Z * this._adt_mtxAdaptMa[2][1]; 194 | var Cd = this._adt_refWhite.X * this._adt_mtxAdaptMa[0][2] + this._adt_refWhite.Y * this._adt_mtxAdaptMa[1][2] + this._adt_refWhite.Z * this._adt_mtxAdaptMa[2][2]; 195 | 196 | 197 | var As = this._adt_refWhiteRGB.X * this._adt_mtxAdaptMa[0][0] + this._adt_refWhiteRGB.Y * this._adt_mtxAdaptMa[1][0] + this._adt_refWhiteRGB.Z * this._adt_mtxAdaptMa[2][0]; 198 | var Bs = this._adt_refWhiteRGB.X * this._adt_mtxAdaptMa[0][1] + this._adt_refWhiteRGB.Y * this._adt_mtxAdaptMa[1][1] + this._adt_refWhiteRGB.Z * this._adt_mtxAdaptMa[2][1]; 199 | var Cs = this._adt_refWhiteRGB.X * this._adt_mtxAdaptMa[0][2] + this._adt_refWhiteRGB.Y * this._adt_mtxAdaptMa[1][2] + this._adt_refWhiteRGB.Z * this._adt_mtxAdaptMa[2][2]; 200 | 201 | var X = this._xyz.X * this._adt_mtxAdaptMa[0][0] + this._xyz.Y * this._adt_mtxAdaptMa[1][0] + this._xyz.Z * this._adt_mtxAdaptMa[2][0]; 202 | var Y = this._xyz.X * this._adt_mtxAdaptMa[0][1] + this._xyz.Y * this._adt_mtxAdaptMa[1][1] + this._xyz.Z * this._adt_mtxAdaptMa[2][1]; 203 | var Z = this._xyz.X * this._adt_mtxAdaptMa[0][2] + this._xyz.Y * this._adt_mtxAdaptMa[1][2] + this._xyz.Z * this._adt_mtxAdaptMa[2][2]; 204 | 205 | X *= (Ad / As); 206 | Y *= (Bd / Bs); 207 | Z *= (Cd / Cs); 208 | 209 | var X2 = X * this._adt_mtxAdaptMaI[0][0] + Y * this._adt_mtxAdaptMaI[1][0] + Z * this._adt_mtxAdaptMaI[2][0]; 210 | var Y2 = X * this._adt_mtxAdaptMaI[0][1] + Y * this._adt_mtxAdaptMaI[1][1] + Z * this._adt_mtxAdaptMaI[2][1]; 211 | var Z2 = X * this._adt_mtxAdaptMaI[0][2] + Y * this._adt_mtxAdaptMaI[1][2] + Z * this._adt_mtxAdaptMaI[2][2]; 212 | 213 | return [X2, Y2, Z2]; 214 | } 215 | 216 | ColorRNA.prototype._adt_invAdaptation = function (xyz, lightName, algName) 217 | { 218 | 219 | this._adt_setRefWhite(lightName); 220 | this._adt_setAdaptMa(algName); 221 | 222 | 223 | var As = this._adt_refWhite.X * this._adt_mtxAdaptMa[0][0] + this._adt_refWhite.Y * this._adt_mtxAdaptMa[1][0] + this._adt_refWhite.Z * this._adt_mtxAdaptMa[2][0]; 224 | var Bs = this._adt_refWhite.X * this._adt_mtxAdaptMa[0][1] + this._adt_refWhite.Y * this._adt_mtxAdaptMa[1][1] + this._adt_refWhite.Z * this._adt_mtxAdaptMa[2][1]; 225 | var Cs = this._adt_refWhite.X * this._adt_mtxAdaptMa[0][2] + this._adt_refWhite.Y * this._adt_mtxAdaptMa[1][2] + this._adt_refWhite.Z * this._adt_mtxAdaptMa[2][2]; 226 | 227 | var Ad = this._adt_refWhiteRGB.X * this._adt_mtxAdaptMa[0][0] + this._adt_refWhiteRGB.Y * this._adt_mtxAdaptMa[1][0] + this._adt_refWhiteRGB.Z * this._adt_mtxAdaptMa[2][0]; 228 | var Bd = this._adt_refWhiteRGB.X * this._adt_mtxAdaptMa[0][1] + this._adt_refWhiteRGB.Y * this._adt_mtxAdaptMa[1][1] + this._adt_refWhiteRGB.Z * this._adt_mtxAdaptMa[2][1]; 229 | var Cd = this._adt_refWhiteRGB.X * this._adt_mtxAdaptMa[0][2] + this._adt_refWhiteRGB.Y * this._adt_mtxAdaptMa[1][2] + this._adt_refWhiteRGB.Z * this._adt_mtxAdaptMa[2][2]; 230 | 231 | var X1 = xyz[0] * this._adt_mtxAdaptMa[0][0] + xyz[1] * this._adt_mtxAdaptMa[1][0] + xyz[2] * this._adt_mtxAdaptMa[2][0]; 232 | var Y1 = xyz[0] * this._adt_mtxAdaptMa[0][1] + xyz[1] * this._adt_mtxAdaptMa[1][1] + xyz[2] * this._adt_mtxAdaptMa[2][1]; 233 | var Z1 = xyz[0] * this._adt_mtxAdaptMa[0][2] + xyz[1] * this._adt_mtxAdaptMa[1][2] + xyz[2] * this._adt_mtxAdaptMa[2][2]; 234 | 235 | X1 *= (Ad / As); 236 | Y1 *= (Bd / Bs); 237 | Z1 *= (Cd / Cs); 238 | 239 | var X2 = X1 * this._adt_mtxAdaptMaI[0][0] + Y1 * this._adt_mtxAdaptMaI[1][0] + Z1 * this._adt_mtxAdaptMaI[2][0]; 240 | var Y2 = X1 * this._adt_mtxAdaptMaI[0][1] + Y1 * this._adt_mtxAdaptMaI[1][1] + Z1 * this._adt_mtxAdaptMaI[2][1]; 241 | var Z2 = X1 * this._adt_mtxAdaptMaI[0][2] + Y1 * this._adt_mtxAdaptMaI[1][2] + Z1 * this._adt_mtxAdaptMaI[2][2]; 242 | 243 | return [X2, Y2, Z2]; 244 | } 245 | 246 | 247 | ColorRNA.prototype._adt_setRefWhite = function (lightname) 248 | { 249 | if (this._refWhiteNameUSER.length > 0)//强制使用用户指定参考白 250 | { 251 | lightname = this._refWhiteNameUSER 252 | } 253 | 254 | 255 | this._adt_refWhite.Y = 1.0; 256 | switch (lightname) 257 | { 258 | case "A" ://(ASTM E308-01) 259 | { 260 | this._adt_refWhite.X = 1.09850; 261 | this._adt_refWhite.Z = 0.35585; 262 | break; 263 | } 264 | case "B" ://(Wyszecki & Stiles, p. 769) 265 | { 266 | this._adt_refWhite.X = 0.99072; 267 | this._adt_refWhite.Z = 0.85223; 268 | break; 269 | } 270 | case "C" :// (ASTM E308-01) 271 | { 272 | this._adt_refWhite.X = 0.98074; 273 | this._adt_refWhite.Z = 1.18232; 274 | break; 275 | } 276 | case "D50" : 277 | { 278 | this._adt_refWhite.X = 0.96422; 279 | this._adt_refWhite.Z = 0.82521; 280 | break; 281 | } 282 | case "D55" : 283 | { 284 | this._adt_refWhite.X = 0.95682; 285 | this._adt_refWhite.Z = 0.92149; 286 | break; 287 | } 288 | case "D65" : 289 | { 290 | this._adt_refWhite.X = 0.95047; 291 | this._adt_refWhite.Z = 1.08883; 292 | break; 293 | } 294 | case "D75" : 295 | { 296 | this._adt_refWhite.X = 0.94972; 297 | this._adt_refWhite.Z = 1.22638; 298 | break; 299 | } 300 | case "E" : 301 | { 302 | this._adt_refWhite.X = 1.00000; 303 | this._adt_refWhite.Z = 1.00000; 304 | break; 305 | } 306 | case "F2" : 307 | { 308 | this._adt_refWhite.X = 0.99186; 309 | this._adt_refWhite.Z = 0.67393; 310 | break; 311 | } 312 | case "F7" : 313 | { 314 | this._adt_refWhite.X = 0.95041; 315 | this._adt_refWhite.Z = 1.08747; 316 | break; 317 | } 318 | case "F11" : 319 | { 320 | this._adt_refWhite.X = 1.00962; 321 | this._adt_refWhite.Z = 0.64350; 322 | break; 323 | } 324 | } 325 | } 326 | 327 | ColorRNA.prototype._adt_setAdaptMa = function (aglName) 328 | { 329 | switch (aglName) 330 | { 331 | case "Bradford" : 332 | { 333 | this._adt_mtxAdaptMa = [ 334 | [0.8951, -0.7502, 0.0389], 335 | [0.2664, 1.7135, -0.0685], 336 | [-0.1614, 0.0367, 1.0296]]; 337 | 338 | this._adt_mtxAdaptMaI = [ 339 | [0.9869929054667123, 0.43230526972339456, -0.008528664575177328], 340 | [-0.14705425642099013, 0.5183602715367776, 0.04004282165408487], 341 | [0.15996265166373125, 0.0492912282128556, 0.9684866957875502]]; 342 | break; 343 | } 344 | case "vonKries" : //von Kries 345 | { 346 | this._adt_mtxAdaptMa = [ 347 | [0.40024, -0.2263, 0], 348 | [0.7076, 1.16532, 0], 349 | [-0.08081, 0.0457, 0.91822]]; 350 | 351 | this._adt_mtxAdaptMaI = [ 352 | [1.8599363874558397, 0.3611914362417676, -0], 353 | [-1.1293816185800916, 0.6388124632850422, -0], 354 | [0.21989740959619328, -0.000006370596838650885, 1.0890636230968613]]; 355 | break; 356 | } 357 | case "none": 358 | { 359 | this._adt_mtxAdaptMa = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; 360 | this._adt_mtxAdaptMaI = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; 361 | break; 362 | } 363 | 364 | } 365 | 366 | 367 | } 368 | 369 | 370 | //让经过 Gamma 的变换 RGB 归一化值还原 371 | ColorRNA.prototype._deGamma = function (rgb) 372 | { 373 | var newRGB = 0; 374 | var sign = 1; 375 | 376 | if (rgb < 0)//处理负数情况 377 | { 378 | sign = -1; 379 | rgb = -rgb; 380 | } 381 | 382 | 383 | if (this._gamma < 0)//----sRGB----------- 384 | { 385 | 386 | if (rgb <= 0.0404482362771076) 387 | { 388 | newRGB = sign * rgb / 12.92; 389 | } 390 | else 391 | { 392 | newRGB = sign * Math.pow((rgb + 0.055) / 1.055, 2.4); 393 | } 394 | } 395 | if (this._gamma == 0)//-----L*----------- 396 | { 397 | 398 | if (rgb <= 0.08) 399 | { 400 | newRGB = sign * 2700.0 * rgb / 24389.0; 401 | } 402 | else 403 | { 404 | newRGB = sign * ((((1000000.0 * rgb + 480000.0) * rgb + 76800.0) * rgb + 4096.0) / 1560896.0); 405 | } 406 | } 407 | if (this._gamma > 0)//-----普通 Gamma----------- 408 | { 409 | 410 | newRGB = sign * Math.pow(rgb, this._gamma); 411 | } 412 | 413 | return newRGB; 414 | } 415 | 416 | 417 | ColorRNA.prototype._getRGBnucleotids = function (rabColorSpaceName, XYZtoRGB) 418 | { 419 | this._adt_refWhiteRGB.Y = 1.0; 420 | 421 | this._refWhiteName = "D65";//设置缺省值 422 | this._doAdapta = true;//设置缺省 423 | 424 | switch (rabColorSpaceName) 425 | { 426 | 427 | //sRGB--------------------------------------- 428 | case "sRGB": 429 | { 430 | this._gamma = -2.2; 431 | this._adt_refWhiteRGB.X = 0.95047; 432 | this._adt_refWhiteRGB.Z = 1.08883; 433 | 434 | if (XYZtoRGB == true) 435 | { 436 | if (this._dLV == 2) 437 | { 438 | return [[3.2404541621141045, -1.5371385127977166, -0.498531409556016], 439 | [-0.9692660305051868, 1.8760108454466942, 0.041556017530349834], 440 | [0.055643430959114726, -0.2040259135167538, 1.0572251882231791]]; 441 | } 442 | else 443 | { 444 | return [[3.2404542, -1.5371385, -0.4985314], 445 | [-0.969266, 1.8760108, 0.041556], 446 | [0.0556434, -0.2040259, 1.0572252]]; 447 | } 448 | break; 449 | } 450 | 451 | 452 | if (this._dLV == 2) 453 | { 454 | return [[0.4124564390896922, 0.357576077643909, 0.18043748326639894], 455 | [0.21267285140562253, 0.715152155287818, 0.07217499330655958], 456 | [0.0193338955823293, 0.11919202588130297, 0.9503040785363679]]; 457 | } 458 | else 459 | { 460 | return [[0.4124564, 0.3575761, 0.1804375], 461 | [0.2126729, 0.7151522, 0.072175], 462 | [0.0193339, 0.119192, 0.9503041]]; 463 | } 464 | break; 465 | } 466 | //Adobe RGB (1998)------------------------------------- 467 | case "AdobeRGB": 468 | { 469 | this._gamma = 2.2; 470 | this._adt_refWhiteRGB.X = 0.95047; 471 | this._adt_refWhiteRGB.Z = 1.08883; 472 | 473 | if (XYZtoRGB == true) 474 | { 475 | if (this._dLV == 2) 476 | { 477 | return [[2.041368979260079, -0.5649463871751954, -0.3446943843778483], 478 | [-0.9692660305051861, 1.876010845446693, 0.041556017530349786], 479 | [0.013447387216170255, -0.11838974235412553, 1.0154095719504164]]; 480 | } 481 | else 482 | { 483 | return [[2.041369, -0.5649464, -0.3446944], 484 | [-0.969266, 1.8760108, 0.041556], 485 | [0.0134474, -0.1183897, 1.0154096]]; 486 | } 487 | break; 488 | } 489 | 490 | 491 | if (this._dLV == 2) 492 | { 493 | return [[0.5767308871981477, 0.18555395071121408, 0.18818516209063843], 494 | [0.29737686371154487, 0.6273490714522, 0.07527406483625537], 495 | [0.027034260337413143, 0.0706872193185578, 0.9911085203440292]]; 496 | } 497 | else 498 | { 499 | return [[0.5767309, 0.185554, 0.1881852], 500 | [0.2973769, 0.6273491, 0.0752741], 501 | [0.0270343, 0.0706872, 0.9911085]]; 502 | } 503 | break; 504 | } 505 | //Apple RGB ------------------------------------- 506 | case "AppleRGB": 507 | { 508 | this._gamma = 1.8; 509 | this._adt_refWhiteRGB.X = 0.95047; 510 | this._adt_refWhiteRGB.Z = 1.08883; 511 | 512 | 513 | if (XYZtoRGB == true) 514 | { 515 | if (this._dLV == 2) 516 | { 517 | return [[2.951537290948746, -1.2894115658994107, -0.473844478043996], 518 | [-1.0851093382231771, 1.9908566080903682, 0.037202561107440836], 519 | [0.08549335448914223, -0.26949635273220945, 1.0912975249496382]]; 520 | } 521 | else 522 | { 523 | return [[2.9515373, -1.2894116, -0.4738445], 524 | [-1.0851093, 1.9908566, 0.0372026], 525 | [0.0854934, -0.2694964, 1.0912975]]; 526 | } 527 | break; 528 | } 529 | 530 | if (this._dLV == 2) 531 | { 532 | return [[0.4497288365610329, 0.31624860938967136, 0.1844925540492957], 533 | [0.24465248708920193, 0.6720282949530516, 0.08331921795774647], 534 | [0.025184814847417827, 0.14118241490610328, 0.9224627702464786]]; 535 | } 536 | else 537 | { 538 | return [[0.4497288, 0.3162486, 0.1844926], 539 | [0.2446525, 0.6720283, 0.0833192], 540 | [0.0251848, 0.1411824, 0.9224628]]; 541 | } 542 | break; 543 | } 544 | //Best RGB ------------------------------------- 545 | case "BestRGB": 546 | { 547 | this._gamma = 2.2; 548 | this._adt_refWhiteRGB.X = 0.96422; 549 | this._adt_refWhiteRGB.Z = 0.82521; 550 | 551 | if (XYZtoRGB == true) 552 | { 553 | if (this._dLV == 2) 554 | { 555 | return [[1.7552599329466554, -0.4836785613998958, -0.25300004986116026], 556 | [-0.5441336296844771, 1.5068789209543363, 0.021552825898898505], 557 | [0.00634673971374007, -0.01757613896601896, 1.225695866021057]]; 558 | } 559 | else 560 | { 561 | return [[1.7552599, -0.4836786, -0.253], 562 | [-0.5441336, 1.5068789, 0.0215528], 563 | [0.0063467, -0.0175761, 1.2256959]]; 564 | } 565 | break; 566 | } 567 | 568 | 569 | if (this._dLV == 2) 570 | { 571 | return [[0.6326696499956765, 0.20455579792131387, 0.12699455208300955], 572 | [0.22845686422193134, 0.7373522948326431, 0.034190840945425655], 573 | [0, 0.009514223159130886, 0.8156957768408691]]; 574 | } 575 | else 576 | { 577 | return [[0.6326696, 0.2045558, 0.1269946], 578 | [0.2284569, 0.7373523, 0.0341908], 579 | [0, 0.0095142, 0.8156958]]; 580 | } 581 | break; 582 | } 583 | //Beta RGB ------------------------------------- 584 | case "BetaRGB": 585 | { 586 | 587 | this._gamma = 2.2; 588 | this._adt_refWhiteRGB.X = 0.96422; 589 | this._adt_refWhiteRGB.Z = 0.82521; 590 | 591 | 592 | if (XYZtoRGB == true) 593 | { 594 | if (this._dLV == 2) 595 | { 596 | return [[1.6832269542614402, -0.4282362832078967, -0.2360184809079736], 597 | [-0.7710228944287557, 1.7065571005222588, 0.04468995133824896], 598 | [0.04000128943944507, -0.08853755837368198, 1.272364022576533]]; 599 | } 600 | else 601 | { 602 | return [[1.683227, -0.4282363, -0.2360185], 603 | [-0.7710229, 1.7065571, 0.04469], 604 | [0.0400013, -0.0885376, 1.272364]]; 605 | } 606 | break; 607 | } 608 | 609 | if (this._dLV == 2) 610 | { 611 | return [[0.671253700292543, 0.17458338980154234, 0.11838290990591456], 612 | [0.30327257771637545, 0.6637860908315439, 0.03294133145208057], 613 | [5.409707559738789e-17, 0.040700961469342455, 0.7845090385306573]]; 614 | } 615 | else 616 | { 617 | return [[0.6712537, 0.1745834, 0.1183829], 618 | [0.3032726, 0.6637861, 0.0329413], 619 | [0, 0.040701, 0.784509]]; 620 | } 621 | break; 622 | } 623 | //Bruce RGB ------------------------------------- 624 | case "BruceRGB": 625 | { 626 | this._gamma = 2.2; 627 | this._adt_refWhiteRGB.X = 0.95047; 628 | this._adt_refWhiteRGB.Z = 1.08883; 629 | 630 | if (XYZtoRGB == true) 631 | { 632 | if (this._dLV == 2) 633 | { 634 | return [[2.745466866559799, -1.1358136045241505, -0.4350268528006593], 635 | [-0.9692660305051869, 1.8760108454466942, 0.04155601753034985], 636 | [0.011272295190850611, -0.1139754291519338, 1.0132540899331266]]; 637 | } 638 | else 639 | { 640 | return [[2.7454669, -1.1358136, -0.4350269], 641 | [-0.969266, 1.8760108, 0.041556], 642 | [0.0112723, -0.1139754, 1.0132541]]; 643 | } 644 | break; 645 | } 646 | 647 | if (this._dLV == 2) 648 | { 649 | return [[0.4674161637795275, 0.2944512299212599, 0.18860260629921258], 650 | [0.24101145944881885, 0.6835474980314961, 0.07544104251968503], 651 | [0.021910132677165326, 0.0736128074803149, 0.9933070598425197]]; 652 | } 653 | else 654 | { 655 | return [[0.4674162, 0.2944512, 0.1886026], 656 | [0.2410115, 0.6835475, 0.075441], 657 | [0.0219101, 0.0736128, 0.9933071]]; 658 | } 659 | break; 660 | } 661 | //CIE RGB ------------------------------------- 662 | case "CIERGB": 663 | { 664 | this._gamma = 2.2; 665 | this._adt_refWhiteRGB.X = 1.00000; 666 | this._adt_refWhiteRGB.Z = 1.00000; 667 | 668 | 669 | if (XYZtoRGB == true) 670 | { 671 | if (this._dLV == 2) 672 | { 673 | return [[2.370674329102138, -0.9000405327854051, -0.4706337963167336], 674 | [-0.513884966581945, 1.42530358655747, 0.08858138002447524], 675 | [0.005298175073030407, -0.0146949384101032, 1.0093967633370728]]; 676 | } 677 | else 678 | { 679 | return [[2.3706743, -0.9000405, -0.4706338], 680 | [-0.513885, 1.4253036, 0.0885814], 681 | [0.0052982, -0.0146949, 1.0093968]]; 682 | } 683 | break; 684 | } 685 | 686 | 687 | if (this._dLV == 2) 688 | { 689 | return [[0.48871796548117163, 0.31068034326701394, 0.20060169125181454], 690 | [0.1762044365340279, 0.8129846938775509, 0.010810869588421142], 691 | [0, 0.010204828793442072, 0.9897951712065579]]; 692 | } 693 | else 694 | { 695 | return [[0.488718, 0.3106803, 0.2006017], 696 | [0.1762044, 0.8129847, 0.0108109], 697 | [0, 0.0102048, 0.9897952]]; 698 | } 699 | 700 | break; 701 | } 702 | //ColorMatch RGB ------------------------------------- 703 | case "ColorMatchRGB": 704 | { 705 | this._gamma = 1.8; 706 | this._adt_refWhiteRGB.X = 0.96422; 707 | this._adt_refWhiteRGB.Z = 0.82521; 708 | 709 | if (XYZtoRGB == true) 710 | { 711 | if (this._dLV == 2) 712 | { 713 | return [[2.6422874096694384, -1.2234270341709754, -0.39301430179044206], 714 | [-1.1119762771300263, 2.059018273920192, 0.01596138196837363], 715 | [0.08216985846755141, -0.2807254155216341, 1.4559876814266082]]; 716 | } 717 | else 718 | { 719 | return [[2.6422874, -1.223427, -0.3930143], 720 | [-1.1119763, 2.0590183, 0.0159614], 721 | [0.0821699, -0.2807254, 1.4559877]]; 722 | } 723 | break; 724 | } 725 | 726 | if (this._dLV == 2) 727 | { 728 | return [[0.509343853397384, 0.3209070884940387, 0.13396905810857737], 729 | [0.2748839843731914, 0.6581314865725201, 0.06698452905428869], 730 | [0.024254469209399214, 0.1087820638962844, 0.6921734668943165]]; 731 | } 732 | else 733 | { 734 | return [[0.5093439, 0.3209071, 0.1339691], 735 | [0.274884, 0.6581315, 0.0669845], 736 | [0.0242545, 0.1087821, 0.6921735]]; 737 | } 738 | break; 739 | } 740 | //ECI RGB v2 ------------------------------------- 741 | case "ECIRGBv2": 742 | { 743 | this._gamma = 0; 744 | this._adt_refWhiteRGB.X = 0.96422; 745 | this._adt_refWhiteRGB.Z = 0.82521; 746 | 747 | if (XYZtoRGB == true) 748 | { 749 | if (this._dLV == 2) 750 | { 751 | return [[1.7827617697270912, -0.49698473887532724, -0.2690100880150854], 752 | [-0.9593623286322266, 1.9477962429805813, -0.027580735166583017], 753 | [0.08593169513496947, -0.17446738103160447, 1.322827306926194]]; 754 | } 755 | else 756 | { 757 | return [[1.7827618, -0.4969847, -0.2690101], 758 | [-0.9593623, 1.9477962, -0.0275807], 759 | [0.0859317, -0.1744674, 1.3228273]]; 760 | } 761 | break; 762 | } 763 | 764 | 765 | if (this._dLV == 2) 766 | { 767 | return [[0.650204257079646, 0.1780773570796461, 0.13593838584070797], 768 | [0.32024985796460176, 0.6020710644121368, 0.07767907762326169], 769 | [-5.3871025143217717e-17, 0.06783899317319857, 0.7573710068268015]]; 770 | } 771 | else 772 | { 773 | return [[0.6502043, 0.1780774, 0.1359384], 774 | [0.3202499, 0.6020711, 0.0776791], 775 | [-0, 0.067839, 0.757371]]; 776 | } 777 | 778 | break; 779 | } 780 | //Don RGB 4 ------------------------------------- 781 | case "DonRGB4": 782 | { 783 | this._gamma = 2.2; 784 | this._adt_refWhiteRGB.X = 0.96422; 785 | this._adt_refWhiteRGB.Z = 0.82521; 786 | 787 | 788 | if (XYZtoRGB == true) 789 | { 790 | if (this._dLV == 2) 791 | { 792 | return [[1.7603902333031187, -0.48811980100639313, -0.25361261951399006], 793 | [-0.7126287844544976, 1.6527431594729967, 0.041671534607820124], 794 | [0.00782073858032594, -0.03474110403369325, 1.244774289550262]]; 795 | } 796 | else 797 | { 798 | return [[1.7603902, -0.4881198, -0.2536126], 799 | [-0.7126288, 1.6527432, 0.0416715], 800 | [0.0078207, -0.0347411, 1.2447743]]; 801 | } 802 | break; 803 | } 804 | 805 | if (this._dLV == 2) 806 | { 807 | return [[0.645771138436728, 0.19335110357732524, 0.12509775798594666], 808 | [0.2783496286365207, 0.6879702057518782, 0.033680165611601025], 809 | [0.0037113283818203304, 0.01798614916998376, 0.8035125224481958]]; 810 | } 811 | else 812 | { 813 | return [[0.6457711, 0.1933511, 0.1250978], 814 | [0.2783496, 0.6879702, 0.0336802], 815 | [0.0037113, 0.0179861, 0.8035125]]; 816 | } 817 | 818 | break; 819 | } 820 | //Ekta Space PS5 ------------------------------------- 821 | case "EktaSpacePS5": 822 | { 823 | this._gamma = 2.2; 824 | this._adt_refWhiteRGB.X = 0.96422; 825 | this._adt_refWhiteRGB.Z = 0.82521; 826 | 827 | 828 | if (XYZtoRGB == true) 829 | { 830 | if (this._dLV == 2) 831 | { 832 | return [[2.0043819420638203, -0.7304844248729281, -0.24500518813859393], 833 | [-0.7110285484718862, 1.6202125940588885, 0.07922268628430854], 834 | [0.038126311068521795, -0.0868779875167958, 1.2725437595985338]]; 835 | } 836 | else 837 | { 838 | return [[2.0043819, -0.7304844, -0.2450052], 839 | [-0.7110285, 1.6202126, 0.0792227], 840 | [0.0381263, -0.086878, 1.2725438]]; 841 | } 842 | break; 843 | } 844 | 845 | 846 | if (this._dLV == 2) 847 | { 848 | return [[0.5938913615570769, 0.2729801227546152, 0.09734851568830809], 849 | [0.26062858312936465, 0.7349464843393485, 0.004424932531286731], 850 | [4.743538587961513e-17, 0.04199694196224853, 0.7832130580377514]]; 851 | } 852 | else 853 | { 854 | return [[0.5938914, 0.2729801, 0.0973485], 855 | [0.2606286, 0.7349465, 0.0044249], 856 | [0, 0.0419969, 0.7832131]]; 857 | } 858 | 859 | break; 860 | } 861 | //NTSC RGB ------------------------------------- 862 | case "NTSCRGB": 863 | { 864 | this._gamma = 2.2; 865 | this._adt_refWhiteRGB.X = 0.98074; 866 | this._adt_refWhiteRGB.Z = 1.18232; 867 | 868 | if (XYZtoRGB == true) 869 | { 870 | if (this._dLV == 2) 871 | { 872 | return [[1.9099960989184541, -0.5324541554529706, -0.2882091300158282], 873 | [-0.9846663050051847, 1.9991709828893145, -0.02830819991079395], 874 | [0.0583056402155416, -0.11837811801337218, 0.8975534918028807]]; 875 | } 876 | else 877 | { 878 | return [[1.9099961, -0.5324542, -0.2882091], 879 | [-0.9846663, 1.999171, -0.0283082], 880 | [0.0583056, -0.1183781, 0.8975535]]; 881 | } 882 | break; 883 | } 884 | 885 | if (this._dLV == 2) 886 | { 887 | return [[0.6068909212389378, 0.1735011212389381, 0.20034795752212392], 888 | [0.2989164238938052, 0.5865990289506955, 0.11448454715549937], 889 | [-5.028240852204785e-17, 0.06609566523388125, 1.116224334766119]]; 890 | } 891 | else 892 | { 893 | return [[0.6068909, 0.1735011, 0.200348], 894 | [0.2989164, 0.586599, 0.1144845], 895 | [-0, 0.0660957, 1.1162243]]; 896 | } 897 | break; 898 | } 899 | 900 | //PAL/SECAM RGB ------------------------------------- 901 | case "PALSECAMRGB": 902 | { 903 | this._gamma = 2.2; 904 | this._adt_refWhiteRGB.X = 0.95047; 905 | this._adt_refWhiteRGB.Z = 1.08883; 906 | 907 | if (XYZtoRGB == true) 908 | { 909 | if (this._dLV == 2) 910 | { 911 | return [[3.0628971232226965, -1.393179136493678, -0.4757516712579541], 912 | [-0.9692660305051867, 1.876010845446694, 0.04155601753034983], 913 | [0.06787750995175175, -0.22885477399033227, 1.0693489682562851]]; 914 | } 915 | else 916 | { 917 | return [[3.0628971, -1.3931791, -0.4757517], 918 | [-0.969266, 1.8760108, 0.041556], 919 | [0.0678775, -0.2288548, 1.069349]]; 920 | } 921 | break; 922 | } 923 | 924 | 925 | if (this._dLV == 2) 926 | { 927 | return [[0.4306190335097004, 0.3415419122574957, 0.17830905423280421], 928 | [0.22203793915343925, 0.7066384391534394, 0.07132362169312169], 929 | [0.020185267195767184, 0.12955038051146386, 0.9390943522927689]]; 930 | } 931 | else 932 | { 933 | return [[0.430619, 0.3415419, 0.1783091], 934 | [0.2220379, 0.7066384, 0.0713236], 935 | [0.0201853, 0.1295504, 0.9390944]]; 936 | } 937 | break; 938 | } 939 | //ProPhoto RGB ------------------------------------- 940 | case "ProPhotoRGB": 941 | { 942 | this._gamma = 1.8; 943 | this._adt_refWhiteRGB.X = 0.96422; 944 | this._adt_refWhiteRGB.Z = 0.82521; 945 | 946 | if (XYZtoRGB == true) 947 | { 948 | if (this._dLV == 2) 949 | { 950 | return [[1.3459433009386654, -0.25560750931676696, -0.05111176587088495], 951 | [-0.544598869458717, 1.508167317720767, 0.020535141586646915], 952 | [0, -0, 1.2118127506937628]]; 953 | } 954 | else 955 | { 956 | return [[1.3459433, -0.2556075, -0.0511118], 957 | [-0.5445989, 1.5081673, 0.0205351], 958 | [0, 0, 1.2118128]]; 959 | } 960 | break; 961 | } 962 | 963 | 964 | if (this._dLV == 2) 965 | { 966 | return [[0.7976749444306044, 0.13519170147409815, 0.031353354095297416], 967 | [0.2880402378623102, 0.7118740972357901, 0.00008566490189971971], 968 | [0, 0, 0.82521]]; 969 | } 970 | else 971 | { 972 | return [[0.7976749, 0.1351917, 0.0313534], 973 | [0.2880402, 0.7118741, 0.0000857], 974 | [0, 0, 0.82521]]; 975 | } 976 | break; 977 | } 978 | //SMPTE-C RGB ------------------------------------- 979 | case "SMPTECRGB": 980 | { 981 | this._gamma = 2.2; 982 | this._adt_refWhiteRGB.X = 0.95047; 983 | this._adt_refWhiteRGB.Z = 1.08883; 984 | 985 | if (XYZtoRGB == true) 986 | { 987 | if (this._dLV == 2) 988 | { 989 | return [[3.505395974670056, -1.7394893606633242, -0.543964026874098], 990 | [-1.0690722072799321, 1.9778244814100043, 0.035172230231857005], 991 | [0.056320014767146896, -0.1970226122130985, 1.0502026283050325]]; 992 | } 993 | else 994 | { 995 | return [[3.505396, -1.7394894, -0.543964], 996 | [-1.0690722, 1.9778245, 0.0351722], 997 | [0.05632, -0.1970226, 1.0502026]]; 998 | } 999 | break; 1000 | } 1001 | 1002 | if (this._dLV == 2) 1003 | { 1004 | return [[0.3935890809541021, 0.365249655704132, 0.19163126334176603], 1005 | [0.21241315480062656, 0.7010436940127694, 0.08654315118660402], 1006 | [0.018742337188290558, 0.11193134610287912, 0.9581563167088301]]; 1007 | } 1008 | else 1009 | { 1010 | return [[0.3935891, 0.3652497, 0.1916313], 1011 | [0.2124132, 0.7010437, 0.0865432], 1012 | [0.0187423, 0.1119313, 0.9581563]]; 1013 | } 1014 | break; 1015 | } 1016 | //Wide Gamut RGB ------------------------------------- 1017 | case "WideGamutRGB": 1018 | { 1019 | this._gamma = 2.2; 1020 | this._adt_refWhiteRGB.X = 0.96422; 1021 | this._adt_refWhiteRGB.Z = 0.82521; 1022 | 1023 | if (XYZtoRGB == true) 1024 | { 1025 | if (this._dLV == 2) 1026 | { 1027 | return [[1.4628067131216802, -0.18406234137547003, -0.27436064462466103], 1028 | [-0.5217933153765428, 1.447238063402864, 0.06772274590650387], 1029 | [0.034934211112166366, -0.09689300063185764, 1.2884099024409357]]; 1030 | } 1031 | else 1032 | { 1033 | return [[1.4628067, -0.1840623, -0.2743606], 1034 | [-0.5217933, 1.4472381, 0.0677227], 1035 | [0.0349342, -0.096893, 1.2884099]]; 1036 | } 1037 | break; 1038 | } 1039 | 1040 | 1041 | if (this._dLV == 2) 1042 | { 1043 | return [[0.7161045686144476, 0.10092960102210317, 0.1471858303634494], 1044 | [0.25818736147323623, 0.7249378299500627, 0.016874808576701202], 1045 | [0, 0.05178127356786167, 0.7734287264321384]]; 1046 | } 1047 | else 1048 | { 1049 | return [[0.7161046, 0.1009296, 0.1471858], 1050 | [0.2581874, 0.7249378, 0.0168748], 1051 | [0, 0.0517813, 0.7734287]]; 1052 | } 1053 | break; 1054 | } 1055 | } 1056 | } 1057 | 1058 | 1059 | ColorRNA.prototype._RGB_to_YPbPr = function (rgb) 1060 | { 1061 | 1062 | rgb = this._normalizArray(rgb, 0, 255, 1); 1063 | 1064 | var 1065 | Y = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2], 1066 | Pb = -0.1687367 * rgb[0] - 0.331264 * rgb[1] + 0.5 * rgb[2], 1067 | Pr = 0.5 * rgb[0] - 0.418688 * rgb[1] - 0.081312 * rgb[2]; 1068 | 1069 | return [Y, Pb, Pr]; 1070 | } 1071 | 1072 | ColorRNA.prototype._YPbPr_to_RGB_ = function (YPbPr) 1073 | { 1074 | var 1075 | r = 0.99999999999914679361 * YPbPr[0] - 1.2188941887145875e-06 * YPbPr[1] + 1.4019995886561440468 * YPbPr[2], 1076 | g = 0.99999975910502514331 * YPbPr[0] - 0.34413567816504303521 * YPbPr[1] - 0.71413649331646789076 * YPbPr[2], 1077 | b = 1.00000124040004623180 * YPbPr[0] + 1.77200006607230409200 * YPbPr[1] + 2.1453384174593273e-06 * YPbPr[2]; 1078 | 1079 | 1080 | return this._normalizArray([r, g, b], 0, 1, 255); 1081 | } 1082 | 1083 | 1084 | ColorRNA.prototype._RGB_to_YCbCr = function (rgb) 1085 | { 1086 | 1087 | rgb = this._normalizArray(rgb, 0, 255, 1); 1088 | var 1089 | Y = 65.481 * rgb[0] + 128.553 * rgb[1] + 24.966 * rgb[2] + 16, 1090 | Cb = -37.797 * rgb[0] - 74.203 * rgb[1] + 112.0 * rgb[2] + 128, 1091 | Cr = 112.0 * rgb[0] - 93.786 * rgb[1] - 18.214 * rgb[2] + 128; 1092 | 1093 | return [Y, Cb, Cr]; 1094 | } 1095 | 1096 | ColorRNA.prototype._YCbCr_to_RGB = function (YCbCr) 1097 | { 1098 | YCbCr[0] -= 16.0 1099 | YCbCr[1] -= 128.0 1100 | YCbCr[2] -= 128.0 1101 | 1102 | var 1103 | r = 0.00456621004566210107 * YCbCr[0] + 1.1808799897946415e-09 * YCbCr[1] + 0.00625892896994393634 * YCbCr[2], 1104 | g = 0.00456621004566210107 * YCbCr[0] - 0.00153632368604490212 * YCbCr[1] - 0.00318811094965570701 * YCbCr[2], 1105 | b = 0.00456621004566210107 * YCbCr[0] + 0.00791071623355474145 * YCbCr[1] + 1.1977497040190077e-08 * YCbCr[2]; 1106 | 1107 | 1108 | return this._normalizArray([r, g, b], 0, 1, 255); 1109 | } 1110 | 1111 | 1112 | ColorRNA.prototype._RGB_to_JpegYCbCr = function (rgb) 1113 | { 1114 | 1115 | var YPbPr = this._RGB_to_YPbPr(rgb); 1116 | var 1117 | Y = YPbPr[0], 1118 | Cb = YPbPr[1] + 0.5, 1119 | Cr = YPbPr[2] + 0.5; 1120 | 1121 | return [Y, Cb, Cr]; 1122 | } 1123 | 1124 | ColorRNA.prototype._JpegYCbCr_to_RGB = function (YCbCr) 1125 | { 1126 | var rgb = this._YPbPr_to_RGB_([YCbCr[0], YCbCr[1] - 0.5, YCbCr[2] - 0.5]); 1127 | return rgb; 1128 | } 1129 | 1130 | 1131 | ColorRNA.prototype._RGB_to_YIQ = function (rgb) 1132 | { 1133 | rgb = this._normalizArray(rgb, 0, 255, 1); 1134 | 1135 | var 1136 | Y = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2], 1137 | I = 0.595716 * rgb[0] - 0.274453 * rgb[1] - 0.321263 * rgb[2], 1138 | Q = 0.211456 * rgb[0] - 0.522591 * rgb[1] + 0.311135 * rgb[2]; 1139 | return [Y, I, Q]; 1140 | } 1141 | 1142 | ColorRNA.prototype._YIQ_to_RGB = function (YIQ) 1143 | { 1144 | var 1145 | r = YIQ[0] + 0.9562957197589482261 * YIQ[1] + 0.6210244164652610754 * YIQ[2], 1146 | g = YIQ[0] - 0.2721220993185104464 * YIQ[1] - 0.6473805968256950427 * YIQ[2], 1147 | b = YIQ[0] - 1.1069890167364901945 * YIQ[1] + 1.7046149983646481374 * YIQ[2]; 1148 | 1149 | return this._normalizArray([r, g, b], 0, 1, 255); 1150 | } 1151 | 1152 | ColorRNA.prototype._RGB_to_YUV = function (rgb) 1153 | { 1154 | rgb = this._normalizArray(rgb, 0, 255, 1); 1155 | 1156 | var 1157 | Y = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2], 1158 | U = -0.147 * rgb[0] - 0.289 * rgb[1] + 0.436 * rgb[2], 1159 | V = 0.615 * rgb[0] - 0.515 * rgb[1] - 0.100 * rgb[2]; 1160 | 1161 | return [Y, U, V]; 1162 | } 1163 | 1164 | 1165 | ColorRNA.prototype._YUV_to_RGB = function (YUV) 1166 | { 1167 | 1168 | var 1169 | r = YUV[0] - 3.945707070708279e-05 * YUV[1] + 1.1398279671717170825 * YUV[2], 1170 | g = YUV[0] - 0.3946101641414141437 * YUV[1] - 0.5805003156565656797 * YUV[2], 1171 | b = YUV[0] + 2.0319996843434342537 * YUV[1] - 4.813762626262513e-04 * YUV[2]; 1172 | 1173 | 1174 | return this._normalizArray([r, g, b], 0, 1, 255); 1175 | } 1176 | 1177 | 1178 | ColorRNA.prototype._RGB_to_HSL = function (rgb, outFloat) 1179 | { 1180 | rgb = this._normalizArray(rgb, 0, 255, 1); 1181 | 1182 | var r, g, b, h, s, l, d, max, min; 1183 | 1184 | r = rgb[0]; 1185 | g = rgb[1]; 1186 | b = rgb[2]; 1187 | 1188 | max = Math.max(r, g, b); 1189 | min = Math.min(r, g, b); 1190 | l = (max + min) / 2; 1191 | 1192 | if (max === min) 1193 | { 1194 | h = s = 0; // achromatic 1195 | } 1196 | else 1197 | { 1198 | d = max - min; 1199 | s = l > 0.5 ? d / (2 - max - min) : d / (max + min); 1200 | 1201 | switch (max) 1202 | { 1203 | case r: 1204 | h = (g - b) / d + (g < b ? 6 : 0); 1205 | break; 1206 | case g: 1207 | h = (b - r) / d + 2; 1208 | break; 1209 | case b: 1210 | h = (r - g) / d + 4; 1211 | break; 1212 | } 1213 | 1214 | h /= 6; 1215 | } 1216 | 1217 | h = h * 360; 1218 | s = s * 100; 1219 | l = l * 100; 1220 | 1221 | 1222 | if (outFloat != true) 1223 | { 1224 | h = Math.round(h); 1225 | s = Math.round(s); 1226 | l = Math.round(l); 1227 | } 1228 | 1229 | return [h, s, l]; 1230 | } 1231 | 1232 | 1233 | ColorRNA.prototype._HSL_to_RGB = function (HSL) 1234 | { 1235 | var 1236 | h = HSL[0], 1237 | s = this._normaliz(HSL[1], 0, 100, 1), 1238 | l = this._normaliz(HSL[2], 0, 100, 1); 1239 | 1240 | if (h == 360) 1241 | { 1242 | h = 0; 1243 | } 1244 | 1245 | if (h == undefined) 1246 | { 1247 | return [0, 0, 0]; 1248 | } 1249 | 1250 | var C = (1 - Math.abs((2 * l) - 1)) * s; 1251 | var hh = h / 60; 1252 | var temp = C * (1 - Math.abs((hh % 2) - 1)); 1253 | 1254 | hh = Math.floor(hh); 1255 | var r; 1256 | var g; 1257 | var b; 1258 | 1259 | if (hh === 0) 1260 | { 1261 | r = C; 1262 | g = temp; 1263 | b = 0; 1264 | } 1265 | else if (hh === 1) 1266 | { 1267 | r = temp; 1268 | g = C; 1269 | b = 0; 1270 | } 1271 | else if (hh === 2) 1272 | { 1273 | r = 0; 1274 | g = C; 1275 | b = temp; 1276 | } 1277 | else if (hh === 3) 1278 | { 1279 | r = 0; 1280 | g = temp; 1281 | b = C; 1282 | } 1283 | else if (hh === 4) 1284 | { 1285 | r = temp; 1286 | g = 0; 1287 | b = C; 1288 | } 1289 | else if (hh === 5) 1290 | { 1291 | r = C; 1292 | g = 0; 1293 | b = temp; 1294 | } 1295 | 1296 | var CC = l - (C / 2); 1297 | r += CC; 1298 | g += CC; 1299 | b += CC; 1300 | 1301 | return this._normaOutRGB(this._normalizArray([r, g, b], 0, 1, 255)); 1302 | } 1303 | 1304 | ColorRNA.prototype._RGB_to_HSL_255 = function (rgb) 1305 | { 1306 | var hsl = this._RGB_to_HSL(rgb, true); 1307 | hsl[0] = Math.round(this._normaliz(hsl[0], 0, 360, 255)); 1308 | hsl[1] = Math.round(this._normaliz(hsl[1], 0, 100, 255)); 1309 | hsl[2] = Math.round(this._normaliz(hsl[2], 0, 100, 255)); 1310 | 1311 | return hsl; 1312 | } 1313 | 1314 | ColorRNA.prototype._HSL_to_RGB_255 = function (inHSL) 1315 | { 1316 | var hsl = [0, 0, 0]; 1317 | 1318 | hsl[0] = Math.round(this._normaliz(inHSL[0], 0, 255, 360)), 1319 | hsl[1] = Math.round(this._normaliz(inHSL[1], 0, 255, 100)), 1320 | hsl[2] = Math.round(this._normaliz(inHSL[2], 0, 255, 100)); 1321 | var rgb = this._HSL_to_RGB(hsl); 1322 | 1323 | return rgb; 1324 | } 1325 | 1326 | 1327 | ColorRNA.prototype._RGB_to_HSL_win239 = function (rgb) 1328 | { 1329 | var hsl = this._RGB_to_HSL(rgb, true); 1330 | hsl[0] = Math.round(this._normaliz(hsl[0], 0, 360, 239)); 1331 | hsl[1] = Math.round(this._normaliz(hsl[1], 0, 100, 240)); 1332 | hsl[2] = Math.round(this._normaliz(hsl[2], 0, 100, 240)); 1333 | 1334 | return hsl; 1335 | } 1336 | 1337 | ColorRNA.prototype._HSL_to_RGB_win240 = function (inHSL) 1338 | { 1339 | var hsl = [0, 0, 0]; 1340 | 1341 | hsl[0] = Math.round(this._normaliz(inHSL[0], 0, 239, 360)), 1342 | hsl[1] = Math.round(this._normaliz(inHSL[1], 0, 240, 100)), 1343 | hsl[2] = Math.round(this._normaliz(inHSL[2], 0, 240, 100)); 1344 | var rgb = this._HSL_to_RGB(hsl); 1345 | 1346 | return rgb; 1347 | } 1348 | 1349 | 1350 | ColorRNA.prototype._RGB_to_HSV = function (rgb) 1351 | { 1352 | var max, min, h, s, v, d, 1353 | r = this._normaliz(rgb[0], 0, 255, 1), 1354 | g = this._normaliz(rgb[1], 0, 255, 1), 1355 | b = this._normaliz(rgb[2], 0, 255, 1); 1356 | 1357 | max = Math.max(r, g, b); 1358 | min = Math.min(r, g, b); 1359 | v = max; 1360 | 1361 | d = max - min; 1362 | s = max === 0 ? 0 : d / max; 1363 | 1364 | if (max === min) 1365 | { 1366 | h = 0; 1367 | } 1368 | else 1369 | { 1370 | switch (max) 1371 | { 1372 | case r: 1373 | h = (g - b) / d + (g < b ? 6 : 0); 1374 | break; 1375 | case g: 1376 | h = (b - r) / d + 2; 1377 | break; 1378 | case b: 1379 | h = (r - g) / d + 4; 1380 | break; 1381 | } 1382 | h /= 6; 1383 | } 1384 | 1385 | h = Math.round(h * 360); 1386 | s = Math.round(s * 100); 1387 | v = Math.round(v * 100); 1388 | 1389 | return [h, s, v]; 1390 | } 1391 | 1392 | ColorRNA.prototype._HSV_to_RGB = function (HSV) 1393 | { 1394 | var r, g, b, i, f, p, q, t; 1395 | 1396 | // h = h / 360; 1397 | if (v === 0) 1398 | { 1399 | return [0, 0, 0]; 1400 | } 1401 | 1402 | var 1403 | s = this._normaliz(HSV[1], 0, 100, 1), 1404 | v = this._normaliz(HSV[2], 0, 100, 1), 1405 | h = HSV[0] / 60; 1406 | 1407 | i = Math.floor(h); 1408 | f = h - i; 1409 | p = v * (1 - s); 1410 | q = v * (1 - (s * f)); 1411 | t = v * (1 - (s * (1 - f))); 1412 | 1413 | switch (i) 1414 | { 1415 | case 0 : 1416 | { 1417 | r = v; 1418 | g = t; 1419 | b = p; 1420 | break; 1421 | } 1422 | case 1 : 1423 | { 1424 | r = q; 1425 | g = v; 1426 | b = p; 1427 | break; 1428 | } 1429 | case 2: 1430 | { 1431 | r = p; 1432 | g = v; 1433 | b = t; 1434 | break; 1435 | } 1436 | case 3: 1437 | { 1438 | r = p; 1439 | g = q; 1440 | b = v; 1441 | break; 1442 | } 1443 | case 4: 1444 | { 1445 | r = t; 1446 | g = p; 1447 | b = v; 1448 | break; 1449 | } 1450 | case 5: 1451 | { 1452 | r = v; 1453 | g = p; 1454 | b = q; 1455 | break; 1456 | } 1457 | } 1458 | 1459 | 1460 | return this._normaOutRGB(this._normalizArray([r, g, b], 0, 1, 255)); 1461 | } 1462 | 1463 | ColorRNA.prototype._RGB_to_HWB = function (rgb) 1464 | { 1465 | var HSV = this._RGB_to_HSV(rgb); 1466 | 1467 | var H, W, B; 1468 | 1469 | H = HSV[0]; 1470 | W = Math.round(((100 - HSV[1]) * HSV[2]) / 100); 1471 | B = Math.round(100 - HSV[2]); 1472 | 1473 | return [H, W, B]; 1474 | } 1475 | 1476 | ColorRNA.prototype._HWB_to_RGB = function (HWB) 1477 | { 1478 | 1479 | 1480 | var H, S, V; 1481 | 1482 | H = HWB[0]; 1483 | S = 100 - (HWB[1] / (100 - HWB[2]) * 100); 1484 | V = 100 - HWB[2]; 1485 | 1486 | var rgb = this._HSV_to_RGB([H, S, V]); 1487 | 1488 | 1489 | return rgb; 1490 | } 1491 | 1492 | 1493 | ColorRNA.prototype._RGB_to_CMY = function (rgb) 1494 | { 1495 | var 1496 | C = 1 - (rgb[0] / 255), 1497 | M = 1 - (rgb[1] / 255), 1498 | Y = 1 - (rgb[2] / 255); 1499 | 1500 | C = Math.round(C * 100); 1501 | M = Math.round(M * 100); 1502 | Y = Math.round(Y * 100); 1503 | 1504 | return [C, M, Y]; 1505 | 1506 | } 1507 | 1508 | ColorRNA.prototype._CMY_to_RGB = function (CMY) 1509 | { 1510 | var 1511 | C = CMY[0] / 100, 1512 | M = CMY[1] / 100, 1513 | Y = CMY[2] / 100; 1514 | 1515 | var 1516 | R = Math.round(Math.max(0, (1 - C) * 255)), 1517 | G = Math.round(Math.max(0, (1 - M) * 255)), 1518 | B = Math.round(Math.max(0, (1 - Y) * 255)); 1519 | return [R, G, B]; 1520 | } 1521 | 1522 | ColorRNA.prototype._CMY_to_CMYK = function (CMY) 1523 | { 1524 | var C = CMY[0] / 100; 1525 | var M = CMY[1] / 100; 1526 | var Y = CMY[2] / 100; 1527 | var K = Math.min(Y, Math.min(M, Math.min(C, 1))); 1528 | C = Math.round((C - K) / (1 - K) * 100); 1529 | M = Math.round((M - K) / (1 - K) * 100); 1530 | Y = Math.round((Y - K) / (1 - K) * 100); 1531 | K = Math.round(K * 100); 1532 | return [C, M, Y, K]; 1533 | } 1534 | 1535 | ColorRNA.prototype._CMYK_to_CMY = function (CMYK) 1536 | { 1537 | 1538 | var 1539 | C = CMYK[0] / 100 * (1 - CMYK[3] / 100) + CMYK[3] / 100, 1540 | M = CMYK[1] / 100 * (1 - CMYK[3] / 100) + CMYK[3] / 100, 1541 | Y = CMYK[2] / 100 * (1 - CMYK[3] / 100) + CMYK[3] / 100; 1542 | 1543 | 1544 | return [Math.round(C * 100), Math.round(M * 100), Math.round(Y * 100)]; 1545 | } 1546 | 1547 | 1548 | ColorRNA.prototype._RGB_to_CMYK = function (rgb) 1549 | { 1550 | return this._CMY_to_CMYK(this._RGB_to_CMY(rgb)); 1551 | } 1552 | 1553 | ColorRNA.prototype._CMYK_to_RGB = function (CMYK) 1554 | { 1555 | return this._CMY_to_RGB(this._CMYK_to_CMY(CMYK)); 1556 | 1557 | } 1558 | 1559 | ColorRNA.prototype._RGB_to_XYZ = function () 1560 | { 1561 | var x, y, z; 1562 | var nucleotids = this._getRGBnucleotids(this._colorSpace); 1563 | 1564 | 1565 | var rgbs = 1566 | [ 1567 | this._deGamma(this._normaliz(this.r)), 1568 | this._deGamma(this._normaliz(this.g)), 1569 | this._deGamma(this._normaliz(this.b)) 1570 | ]; 1571 | 1572 | 1573 | x = this._arrayProduct(rgbs, nucleotids[0]); 1574 | y = this._arrayProduct(rgbs, nucleotids[1]); 1575 | z = this._arrayProduct(rgbs, nucleotids[2]); 1576 | 1577 | this._xyz.X = x; 1578 | this._xyz.Y = y; 1579 | this._xyz.Z = z; 1580 | 1581 | if ((this._doAdapta == true || this._doAdaptaUSER == 1 ) && this._doAdaptaUSER != -1) 1582 | { 1583 | var xyz2 = this._adt_adaptation(this._refWhiteName, this._adtAlg); 1584 | this._xyz.X = xyz2[0]; 1585 | this._xyz.Y = xyz2[1]; 1586 | this._xyz.Z = xyz2[2]; 1587 | 1588 | } 1589 | 1590 | return [this._xyz.X, this._xyz.Y, this._xyz.Z] 1591 | } 1592 | 1593 | ColorRNA.prototype._XYZ_to_RGB = function () 1594 | { 1595 | var nucleotids = this._getRGBnucleotids(this._colorSpace, true); 1596 | var xyzs = [this._xyz.X, this._xyz.Y, this._xyz.Z]; 1597 | 1598 | 1599 | if ((this._doAdapta == true || this._doAdaptaUSER == 1 ) && this._doAdaptaUSER != -1) 1600 | { 1601 | 1602 | xyzs = this._adt_invAdaptation(xyzs, this._refWhiteName, this._adtAlg); 1603 | } 1604 | 1605 | var _r, _g, _b; 1606 | 1607 | _r = this._arrayProduct(xyzs, nucleotids[0]); 1608 | _g = this._arrayProduct(xyzs, nucleotids[1]); 1609 | _b = this._arrayProduct(xyzs, nucleotids[2]); 1610 | 1611 | var rgbs = 1612 | [ 1613 | this._normaliz(this._enGamma(_r), 0, 1, 255), 1614 | this._normaliz(this._enGamma(_g), 0, 1, 255), 1615 | this._normaliz(this._enGamma(_b), 0, 1, 255) 1616 | ]; 1617 | 1618 | this._arrayRound(rgbs); 1619 | return rgbs; 1620 | } 1621 | 1622 | 1623 | ColorRNA.prototype._XYZ_to_Lab = function (psMod) 1624 | { 1625 | var xyz = [this._xyz.X, this._xyz.Y, this._xyz.Z]; 1626 | 1627 | var kE = 0.008856451679 //216.0 / 24389.0; 1628 | var kK = 903.2962962963 //24389.0 / 27.0; 1629 | 1630 | 1631 | this._adt_setRefWhite("D65"); 1632 | 1633 | if (psMod === true)//ps 1634 | { 1635 | this._getRGBnucleotids("sRGB"); 1636 | xyz = this._adt_adaptation("D50", this._adtAlg); 1637 | } 1638 | 1639 | 1640 | var xr = xyz[0] / this._adt_refWhite.X; 1641 | var yr = xyz[1] / this._adt_refWhite.Y; 1642 | var zr = xyz[2] / this._adt_refWhite.Z; 1643 | 1644 | var fx = (xr > kE) ? Math.pow(xr, 1.0 / 3.0) : ((kK * xr + 16.0) / 116.0); 1645 | var fy = (yr > kE) ? Math.pow(yr, 1.0 / 3.0) : ((kK * yr + 16.0) / 116.0); 1646 | var fz = (zr > kE) ? Math.pow(zr, 1.0 / 3.0) : ((kK * zr + 16.0) / 116.0); 1647 | 1648 | var Lab = [116.0 * fy - 16.0, 500.0 * (fx - fy), 200.0 * (fy - fz)]; 1649 | 1650 | return Lab; 1651 | } 1652 | 1653 | 1654 | ColorRNA.prototype._LCHab_to_XYZ = function (LCH) 1655 | { 1656 | var Lab = [0, 0, 0]; 1657 | 1658 | Lab[0] = LCH[0]; 1659 | Lab[1] = LCH[1] * Math.cos(LCH[2] * Math.PI / 180.0); 1660 | Lab[2] = LCH[1] * Math.sin(LCH[2] * Math.PI / 180.0); 1661 | 1662 | return this._Lab_to_XYZ(Lab, false); 1663 | } 1664 | 1665 | 1666 | ColorRNA.prototype._XYZ_to_LCHab = function () 1667 | { 1668 | var Lab = this._XYZ_to_Lab(Lab, false); 1669 | var LCH = [0, 0, 0]; 1670 | 1671 | LCH[0] = Lab[0]; 1672 | LCH[1] = Math.sqrt(Lab[1] * Lab[1] + Lab[2] * Lab[2]); 1673 | LCH[2] = 180.0 * Math.atan2(Lab[2], Lab[1]) / Math.PI; 1674 | if (LCH[2] < 0.0) 1675 | { 1676 | LCH[2] += 360.0; 1677 | } 1678 | 1679 | 1680 | return LCH; 1681 | } 1682 | 1683 | 1684 | ColorRNA.prototype._Lab_to_XYZ = function (Labs, psMod) 1685 | { 1686 | 1687 | var xyz = [0, 0, 0]; 1688 | 1689 | var kE = 0.008856451679 //216.0 / 24389.0; 1690 | var kK = 903.2962962963 //24389.0 / 27.0; 1691 | var kKE = 8.0; 1692 | 1693 | 1694 | var Lab = 1695 | { 1696 | L: Labs[0], 1697 | a: Labs[1], 1698 | b: Labs[2], 1699 | } 1700 | 1701 | var fy = (Lab.L + 16.0) / 116.0; 1702 | var fx = 0.002 * Lab.a + fy; 1703 | var fz = fy - 0.005 * Lab.b; 1704 | 1705 | var fx3 = fx * fx * fx; 1706 | var fz3 = fz * fz * fz; 1707 | 1708 | var xr = (fx3 > kE) ? fx3 : ((116.0 * fx - 16.0) / kK); 1709 | var yr = (Lab.L > kKE) ? Math.pow((Lab.L + 16.0) / 116.0, 3.0) : (Lab.L / kK); 1710 | var zr = (fz3 > kE) ? fz3 : ((116.0 * fz - 16.0) / kK); 1711 | 1712 | 1713 | //if (psMod === true) 1714 | //{ 1715 | // this._adt_setRefWhite("D65"); 1716 | //} 1717 | 1718 | 1719 | if (psMod === true) 1720 | { 1721 | this._adt_setRefWhite("D50"); 1722 | } 1723 | else 1724 | { 1725 | this._adt_setRefWhite("D65"); 1726 | } 1727 | 1728 | 1729 | xyz[0] = xr * this._adt_refWhite.X; 1730 | xyz[1] = yr * this._adt_refWhite.Y; 1731 | xyz[2] = zr * this._adt_refWhite.Z; 1732 | 1733 | this._xyz.X = xyz[0]; 1734 | this._xyz.Y = xyz[1]; 1735 | this._xyz.Z = xyz[2]; 1736 | 1737 | if (psMod === true) 1738 | { 1739 | this._getRGBnucleotids("sRGB") 1740 | // xyz = this._adt_adaptation("D65", this._adtAlg); 1741 | xyz = this._adt_invAdaptation(xyz, "D50", this._adtAlg); 1742 | } 1743 | 1744 | this._xyz.X = xyz[0]; 1745 | this._xyz.Y = xyz[1]; 1746 | this._xyz.Z = xyz[2]; 1747 | 1748 | 1749 | return [this._xyz.X, this._xyz.Y, this._xyz.Z]; 1750 | } 1751 | 1752 | 1753 | ColorRNA.prototype._XYZ_to_xyY = function () 1754 | { 1755 | var xyY = [0, 0, 0]; 1756 | var Den = this._xyz.X + this._xyz.Y + this._xyz.Z; 1757 | if (Den > 0.0) 1758 | { 1759 | xyY[0] = this._xyz.X / Den; 1760 | xyY[1] = this._xyz.Y / Den; 1761 | } 1762 | else 1763 | { 1764 | this._adt_setRefWhite(this._refWhiteName); 1765 | xyY[0] = this._adt_refWhite.X / (this._adt_refWhite.X + this._adt_refWhite.Y + this._adt_refWhite.Z); 1766 | xyY[1] = this._adt_refWhite.Y / (this._adt_refWhite.X + this._adt_refWhite.Y + this._adt_refWhite.Z); 1767 | } 1768 | 1769 | xyY[2] = this._xyz.Y; 1770 | 1771 | return xyY; 1772 | } 1773 | 1774 | 1775 | ColorRNA.prototype._xyY_to_XYZ = function (xyY) 1776 | { 1777 | var XYZ = [0, 0, 0]; 1778 | if (xyY[1] < 0.000001) 1779 | { 1780 | XYZ[0] = XYZ[1] = XYZ[2] = 0.0; 1781 | } 1782 | else 1783 | { 1784 | XYZ[0] = (xyY[0] * xyY[2]) / xyY[1]; 1785 | XYZ[1] = xyY[2]; 1786 | XYZ[2] = ((1.0 - xyY[0] - xyY[1]) * xyY[2]) / xyY[1]; 1787 | } 1788 | 1789 | 1790 | this._xyz.X = XYZ[0]; 1791 | this._xyz.Y = XYZ[1]; 1792 | this._xyz.Z = XYZ[2]; 1793 | return XYZ; 1794 | } 1795 | 1796 | ColorRNA.prototype._xyY_to_Wavelength = function (xyY) 1797 | { 1798 | 1799 | var x = xyY[0], 1800 | y = xyY[1], 1801 | xr = this._adt_refWhite.X / ( this._adt_refWhite.X + this._adt_refWhite.Y + this._adt_refWhite.Z), 1802 | yr = this._adt_refWhite.Y / (this._adt_refWhite.X + this._adt_refWhite.Y + this._adt_refWhite.Z); 1803 | 1804 | 1805 | var dominantWavelength; 1806 | var count = 0; 1807 | var tArray = [0.0, 0.0]; // t 1808 | var wArray = [0.0, 0.0]; // wavelength 1809 | var cArray = [0, 0]; // cycle 1810 | 1811 | var nm; 1812 | 1813 | var a = x - xr; 1814 | var b = y - yr; 1815 | 1816 | if ((a >= -0.000001) && (a <= 0.000001) && (b >= -0.000001) && (b <= 0.000001)) 1817 | { 1818 | return (0.0); // cannot compute the dominant wavelength, because (x, y) is the same as (xr, yr) 1819 | } 1820 | 1821 | for (nm = 360; nm <= 830; nm += 5) 1822 | { 1823 | var i1 = (nm - 360) / 5; 1824 | var i2 = (nm == 830) ? 0 : i1 + 1; 1825 | var nm2 = 5 * i2 + 360; 1826 | 1827 | var CIE1931StdObs_x = [ 1828 | 0.000129900000, 0.000232100000, 0.000414900000, 0.000741600000, 0.001368000000, 0.002236000000, 1829 | 0.004243000000, 0.007650000000, 0.014310000000, 0.023190000000, 0.043510000000, 0.077630000000, 0.134380000000, 0.214770000000, 0.283900000000, 0.328500000000, 1830 | 0.348280000000, 0.348060000000, 0.336200000000, 0.318700000000, 0.290800000000, 0.251100000000, 0.195360000000, 0.142100000000, 0.095640000000, 0.057950010000, 1831 | 0.032010000000, 0.014700000000, 0.004900000000, 0.002400000000, 0.009300000000, 0.029100000000, 0.063270000000, 0.109600000000, 0.165500000000, 0.225749900000, 1832 | 0.290400000000, 0.359700000000, 0.433449900000, 0.512050100000, 0.594500000000, 0.678400000000, 0.762100000000, 0.842500000000, 0.916300000000, 0.978600000000, 1833 | 1.026300000000, 1.056700000000, 1.062200000000, 1.045600000000, 1.002600000000, 0.938400000000, 0.854449900000, 0.751400000000, 0.642400000000, 0.541900000000, 1834 | 0.447900000000, 0.360800000000, 0.283500000000, 0.218700000000, 0.164900000000, 0.121200000000, 0.087400000000, 0.063600000000, 0.046770000000, 0.032900000000, 1835 | 0.022700000000, 0.015840000000, 0.011359160000, 0.008110916000, 0.005790346000, 0.004109457000, 0.002899327000, 0.002049190000, 0.001439971000, 0.000999949300, 1836 | 0.000690078600, 0.000476021300, 0.000332301100, 0.000234826100, 0.000166150500, 0.000117413000, 0.000083075270, 0.000058706520, 0.000041509940, 0.000029353260, 1837 | 0.000020673830, 0.000014559770, 0.000010253980, 0.000007221456, 0.000005085868, 0.000003581652, 0.000002522525, 0.000001776509, 0.000001251141]; 1838 | var CIE1931StdObs_y = [ 1839 | 0.000003917000, 0.000006965000, 0.000012390000, 0.000022020000, 0.000039000000, 0.000064000000, 1840 | 0.000120000000, 0.000217000000, 0.000396000000, 0.000640000000, 0.001210000000, 0.002180000000, 0.004000000000, 0.007300000000, 0.011600000000, 0.016840000000, 1841 | 0.023000000000, 0.029800000000, 0.038000000000, 0.048000000000, 0.060000000000, 0.073900000000, 0.090980000000, 0.112600000000, 0.139020000000, 0.169300000000, 1842 | 0.208020000000, 0.258600000000, 0.323000000000, 0.407300000000, 0.503000000000, 0.608200000000, 0.710000000000, 0.793200000000, 0.862000000000, 0.914850100000, 1843 | 0.954000000000, 0.980300000000, 0.994950100000, 1.000000000000, 0.995000000000, 0.978600000000, 0.952000000000, 0.915400000000, 0.870000000000, 0.816300000000, 1844 | 0.757000000000, 0.694900000000, 0.631000000000, 0.566800000000, 0.503000000000, 0.441200000000, 0.381000000000, 0.321000000000, 0.265000000000, 0.217000000000, 1845 | 0.175000000000, 0.138200000000, 0.107000000000, 0.081600000000, 0.061000000000, 0.044580000000, 0.032000000000, 0.023200000000, 0.017000000000, 0.011920000000, 1846 | 0.008210000000, 0.005723000000, 0.004102000000, 0.002929000000, 0.002091000000, 0.001484000000, 0.001047000000, 0.000740000000, 0.000520000000, 0.000361100000, 1847 | 0.000249200000, 0.000171900000, 0.000120000000, 0.000084800000, 0.000060000000, 0.000042400000, 0.000030000000, 0.000021200000, 0.000014990000, 0.000010600000, 1848 | 0.000007465700, 0.000005257800, 0.000003702900, 0.000002607800, 0.000001836600, 0.000001293400, 0.000000910930, 0.000000641530, 0.000000451810]; 1849 | var CIE1931StdObs_z = [ 1850 | 0.000606100000, 0.001086000000, 0.001946000000, 0.003486000000, 0.006450001000, 0.010549990000, 1851 | 0.020050010000, 0.036210000000, 0.067850010000, 0.110200000000, 0.207400000000, 0.371300000000, 0.645600000000, 1.039050100000, 1.385600000000, 1.622960000000, 1852 | 1.747060000000, 1.782600000000, 1.772110000000, 1.744100000000, 1.669200000000, 1.528100000000, 1.287640000000, 1.041900000000, 0.812950100000, 0.616200000000, 1853 | 0.465180000000, 0.353300000000, 0.272000000000, 0.212300000000, 0.158200000000, 0.111700000000, 0.078249990000, 0.057250010000, 0.042160000000, 0.029840000000, 1854 | 0.020300000000, 0.013400000000, 0.008749999000, 0.005749999000, 0.003900000000, 0.002749999000, 0.002100000000, 0.001800000000, 0.001650001000, 0.001400000000, 1855 | 0.001100000000, 0.001000000000, 0.000800000000, 0.000600000000, 0.000340000000, 0.000240000000, 0.000190000000, 0.000100000000, 0.000049999990, 0.000030000000, 1856 | 0.000020000000, 0.000010000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 1857 | 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 1858 | 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 1859 | 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000, 0.000000000000]; 1860 | 1861 | 1862 | var x1 = CIE1931StdObs_x[i1] / (CIE1931StdObs_x[i1] + CIE1931StdObs_y[i1] + CIE1931StdObs_z[i1]); 1863 | var y1 = CIE1931StdObs_y[i1] / (CIE1931StdObs_x[i1] + CIE1931StdObs_y[i1] + CIE1931StdObs_z[i1]); 1864 | var x2 = CIE1931StdObs_x[i2] / (CIE1931StdObs_x[i2] + CIE1931StdObs_y[i2] + CIE1931StdObs_z[i2]); 1865 | var y2 = CIE1931StdObs_y[i2] / (CIE1931StdObs_x[i2] + CIE1931StdObs_y[i2] + CIE1931StdObs_z[i2]); 1866 | 1867 | var c = x1 - xr; 1868 | var d = y1 - yr; 1869 | var e = x2 - x1; 1870 | var f = y2 - y1; 1871 | 1872 | var s = (a * d - b * c) / (b * e - a * f); 1873 | if ((s < 0.0) || (s >= 1.0)) 1874 | { 1875 | continue; 1876 | } 1877 | 1878 | var t = (Math.abs(a) >= Math.abs(b)) ? ((e * s + c) / a) : ((f * s + d) / b); 1879 | tArray[count] = t; 1880 | cArray[count] = nm; 1881 | wArray[count] = (nm2 - nm) * s + nm; 1882 | count += 1; 1883 | } 1884 | 1885 | if ((cArray[1] == 830) && (tArray[1] > 0.0)) 1886 | { 1887 | dominantWavelength = -wArray[0]; 1888 | } 1889 | else 1890 | { 1891 | dominantWavelength = (tArray[0] >= 0.0) ? wArray[0] : wArray[1]; 1892 | } 1893 | 1894 | return (dominantWavelength); 1895 | 1896 | 1897 | } 1898 | 1899 | 1900 | ColorRNA.prototype._XYZ_to_Luv = function () 1901 | { 1902 | 1903 | var Luv = [0, 0, 0] 1904 | var kE = 216.0 / 24389.0; 1905 | var kK = 24389.0 / 27.0; 1906 | var kKE = 8.0; 1907 | this._adt_setRefWhite("D65"); 1908 | 1909 | 1910 | var Den = this._xyz.X + 15.0 * this._xyz.Y + 3.0 * this._xyz.Z; 1911 | var up = (Den > 0.0) ? ((4.0 * this._xyz.X) / (this._xyz.X + 15.0 * this._xyz.Y + 3.0 * this._xyz.Z)) : 0.0; 1912 | var vp = (Den > 0.0) ? ((9.0 * this._xyz.Y) / (this._xyz.X + 15.0 * this._xyz.Y + 3.0 * this._xyz.Z)) : 0.0; 1913 | 1914 | var urp = (4.0 * this._adt_refWhite.X) / (this._adt_refWhite.X + 15.0 * this._adt_refWhite.Y + 3.0 * this._adt_refWhite.Z); 1915 | var vrp = (9.0 * this._adt_refWhite.Y) / (this._adt_refWhite.X + 15.0 * this._adt_refWhite.Y + 3.0 * this._adt_refWhite.Z); 1916 | 1917 | var yr = this._xyz.Y / this._adt_refWhite.Y; 1918 | 1919 | Luv[0] = (yr > kE) ? (116.0 * Math.pow(yr, 1.0 / 3.0) - 16.0) : (kK * yr); 1920 | Luv[1] = 13.0 * Luv[0] * (up - urp); 1921 | Luv[2] = 13.0 * Luv[0] * (vp - vrp); 1922 | 1923 | return Luv; 1924 | 1925 | } 1926 | 1927 | 1928 | ColorRNA.prototype._Luv_to_XYZ = function (Luv) 1929 | { 1930 | 1931 | var kK = 24389.0 / 27.0; 1932 | var kKE = 8.0; 1933 | var XYZ = {X: 0, Y: 0, Z: 0}; 1934 | this._adt_setRefWhite("D65"); 1935 | 1936 | 1937 | XYZ.Y = (Luv[0] > kKE) ? Math.pow((Luv[0] + 16.0) / 116.0, 3.0) : (Luv[0] / kK); 1938 | var u0 = (4.0 * this._adt_refWhite.X) / (this._adt_refWhite.X + 15.0 * this._adt_refWhite.Y + 3.0 * this._adt_refWhite.Z); 1939 | var v0 = (9.0 * this._adt_refWhite.Y) / (this._adt_refWhite.X + 15.0 * this._adt_refWhite.Y + 3.0 * this._adt_refWhite.Z); 1940 | 1941 | var a = (((52.0 * Luv[0]) / (Luv[1] + 13.0 * Luv[0] * u0)) - 1.0) / 3.0; 1942 | var b = -5.0 * XYZ.Y; 1943 | var c = -1.0 / 3.0; 1944 | var d = XYZ.Y * (((39.0 * Luv[0]) / (Luv[2] + 13.0 * Luv[0] * v0)) - 5.0); 1945 | 1946 | XYZ.X = (d - b) / (a - c); 1947 | XYZ.Z = XYZ.X * a + b; 1948 | 1949 | this._xyz.X = XYZ.X; 1950 | this._xyz.Y = XYZ.Y; 1951 | this._xyz.Z = XYZ.Z; 1952 | } 1953 | 1954 | 1955 | ColorRNA.prototype._hex_to_rgb = function (hex) 1956 | { 1957 | var r, g, b; 1958 | if (hex.length == 3) 1959 | { 1960 | r = parseInt((hex.slice(0, 1) + hex.slice(0, 1)), 16); 1961 | g = parseInt((hex.slice(1, 2) + hex.slice(1, 2)), 16); 1962 | b = parseInt((hex.slice(2, 3) + hex.slice(2, 3)), 16); 1963 | } 1964 | else if (hex.length == 6) 1965 | { 1966 | r = parseInt((hex.slice(0, 2) ), 16); 1967 | g = parseInt((hex.slice(2, 4)), 16); 1968 | b = parseInt((hex.slice(4, 6) ), 16); 1969 | } 1970 | 1971 | return [r, g, b]; 1972 | } 1973 | 1974 | 1975 | ColorRNA.prototype._rgb_to_hex = function (rgb) 1976 | { 1977 | var hex = rgb[0] * 65536 + rgb[1] * 256 + rgb[2]; 1978 | 1979 | hex = hex.toString(16).toUpperCase(); 1980 | 1981 | 1982 | while (hex.length < 6) 1983 | { 1984 | hex = "0" + hex; 1985 | } 1986 | 1987 | return hex.toString(16).toUpperCase(); 1988 | 1989 | 1990 | } 1991 | 1992 | 1993 | // 检查输入的 RGB 值,如果是 0~1 的小数形式将转化为 0~255 的形式 1994 | ColorRNA.prototype._normaInputRGB = function (inArray) 1995 | { 1996 | var modeFloat = false; 1997 | var z = 0 1998 | var flTest = ""; 1999 | 2000 | if (inArray.length == 3) 2001 | { 2002 | if (inArray[1] > 1 && inArray[1] > 1 && inArray[1] > 1) 2003 | { 2004 | return inArray; 2005 | } 2006 | 2007 | for (z = 0; z < inArray.length; z++) 2008 | { 2009 | if (String(inArray[z]).indexOf(".") > -1) 2010 | { 2011 | modeFloat = true; 2012 | } 2013 | } 2014 | if (modeFloat == true) 2015 | { 2016 | for (z = 0; z < inArray.length; z++) 2017 | { 2018 | inArray[z] = this._normaliz(inArray[z], 0, 1, 255); 2019 | } 2020 | } 2021 | 2022 | } 2023 | 2024 | return inArray; 2025 | } 2026 | 2027 | 2028 | // 检查输出的 RGB 值,将小于 0 和 -0 的值转换为 0; 2029 | ColorRNA.prototype._normaOutRGB = function (inArray) 2030 | { 2031 | 2032 | var z = 0 2033 | for (z = 0; z < inArray.length; z++) 2034 | { 2035 | inArray[z] = Math.round(inArray[z]); 2036 | if (inArray[z] < 0 || inArray[z] == -0) 2037 | { 2038 | inArray[z] = 0; 2039 | } 2040 | } 2041 | return inArray; 2042 | } 2043 | 2044 | // 检查输出的 Lab 值,四舍五入舍到 1 位小数,PS(PhotoShop)模式完全舍去小数位; 2045 | ColorRNA.prototype._normaOutLab = function (inArray, PSMod) 2046 | { 2047 | var z = 0 2048 | for (z = 0; z < inArray.length; z++) 2049 | { 2050 | if (PSMod) 2051 | { 2052 | inArray[z] = Math.round(inArray[z]); 2053 | } 2054 | else 2055 | { 2056 | inArray[z] = +inArray[z].toFixed(4); 2057 | } 2058 | 2059 | } 2060 | return inArray; 2061 | } 2062 | 2063 | // 检查输出的值数组,四舍五入舍到 X 位小数; 2064 | ColorRNA.prototype._normaOutX = function (inArray, X) 2065 | { 2066 | var z = 0 2067 | for (z = 0; z < inArray.length; z++) 2068 | { 2069 | inArray[z] = +inArray[z].toFixed(X); 2070 | 2071 | } 2072 | return inArray; 2073 | } 2074 | 2075 | 2076 | // 检查输入的 XYZ 值,如果有非 0~1 形式的值,将把所有值除以 100 2077 | ColorRNA.prototype._normaInputXYZ = function (inArray) 2078 | { 2079 | 2080 | var z = 0 2081 | 2082 | if (inArray[0] > 1 || inArray[1] > 1 || inArray[2] > 1) 2083 | { 2084 | for (z = 0; z < inArray.length; z++) 2085 | { 2086 | inArray[z] = inArray[z] / 100; 2087 | 2088 | } 2089 | } 2090 | return inArray; 2091 | } 2092 | 2093 | 2094 | // 设置指定的参考白色(光照条件),没有参数将设置为缺省值(RGB 默认 D65) 2095 | ColorRNA.prototype.setRefWhite = function (inRefWhiteName) 2096 | { 2097 | if (arguments.length == 0) 2098 | { 2099 | this._refWhiteNameUSER = ""; 2100 | } 2101 | else 2102 | { 2103 | this._refWhiteNameUSER = inRefWhiteName; 2104 | } 2105 | 2106 | return this; 2107 | } 2108 | 2109 | // 返回当前参考白色设置(光照条件) 2110 | ColorRNA.prototype.getRefWhite = function () 2111 | { 2112 | 2113 | if (this._refWhiteNameUSER.length > 0) 2114 | { 2115 | return this._refWhiteNameUSER; 2116 | } 2117 | return this._refWhiteName; 2118 | } 2119 | 2120 | //默认以 sRGB 设置 RGB 的值, 2121 | ColorRNA.prototype.rgb = function () 2122 | { 2123 | return (this._rgbX(arguments, this._COLORSPACES.sRGB)); 2124 | } 2125 | 2126 | 2127 | //供各种色彩空间设置取值函数调用的模板---------------------------------- 2128 | ColorRNA.prototype._rgbX = function (argus, colorSpace) 2129 | { 2130 | var rgb = [0, 0, 0]; 2131 | this._colorSpace = colorSpace; 2132 | 2133 | if (argus.length == 0) 2134 | { 2135 | rgb = this._XYZ_to_RGB(); 2136 | return this._normaOutRGB(rgb); 2137 | } 2138 | 2139 | if (argus.length == 1) 2140 | { 2141 | if (Array.isArray(argus[0])) 2142 | { 2143 | if (argus[0].length == 3) 2144 | { 2145 | rgb = argus[0]; 2146 | } 2147 | } 2148 | else if (argus[0].slice(0, 1) == "#") 2149 | { 2150 | rgb = this._hex_to_rgb(argus[0].slice(1, argus[0].length)); 2151 | } 2152 | 2153 | } 2154 | if (argus.length == 3) 2155 | { 2156 | rgb[0] = argus[0]; 2157 | rgb[1] = argus[1]; 2158 | rgb[2] = argus[2]; 2159 | } 2160 | 2161 | this._normaInputRGB(rgb); 2162 | this.r = rgb[0]; 2163 | this.g = rgb[1]; 2164 | this.b = rgb[2]; 2165 | this._RGB_to_XYZ(); 2166 | 2167 | return this; 2168 | } 2169 | 2170 | ColorRNA.prototype._LabX = function (argus, PhotoShopMod) 2171 | { 2172 | var Lab = [0, 0, 0]; 2173 | 2174 | if (argus.length == 0) 2175 | { 2176 | Lab = this._XYZ_to_Lab(PhotoShopMod); 2177 | this._normaOutLab(Lab, PhotoShopMod); 2178 | return Lab; 2179 | } 2180 | 2181 | if (argus.length == 1) 2182 | { 2183 | if (Array.isArray(argus[0])) 2184 | { 2185 | if (argus[0].length == 3) 2186 | { 2187 | Lab = argus[0]; 2188 | } 2189 | } 2190 | } 2191 | if (argus.length == 3) 2192 | { 2193 | Lab[0] = argus[0]; 2194 | Lab[1] = argus[1]; 2195 | Lab[2] = argus[2]; 2196 | } 2197 | 2198 | this._Lab_to_XYZ(Lab, PhotoShopMod); 2199 | return this; 2200 | } 2201 | 2202 | ColorRNA.prototype._xyYX = function (argus) 2203 | { 2204 | var xyY = [0, 0, 0]; 2205 | 2206 | if (argus.length == 0) 2207 | { 2208 | xyY = this._XYZ_to_xyY(); 2209 | this._normaOutX(xyY, 4); 2210 | return xyY; 2211 | } 2212 | 2213 | if (argus.length == 1) 2214 | { 2215 | if (Array.isArray(argus[0])) 2216 | { 2217 | if (argus[0].length == 3) 2218 | { 2219 | xyY = argus[0]; 2220 | } 2221 | } 2222 | } 2223 | if (argus.length == 3) 2224 | { 2225 | xyY[0] = argus[0]; 2226 | xyY[1] = argus[1]; 2227 | xyY[2] = argus[2]; 2228 | } 2229 | 2230 | this._xyY_to_XYZ(xyY); 2231 | return this; 2232 | } 2233 | 2234 | 2235 | ColorRNA.prototype._LCHabX = function (argus) 2236 | { 2237 | 2238 | var LCH = [0, 0, 0]; 2239 | 2240 | if (argus.length == 0) 2241 | { 2242 | LCH = this._XYZ_to_LCHab(); 2243 | this._normaOutX(LCH, 4); 2244 | return LCH; 2245 | } 2246 | 2247 | if (argus.length == 1) 2248 | { 2249 | if (Array.isArray(argus[0])) 2250 | { 2251 | if (argus[0].length == 3) 2252 | { 2253 | LCH = argus[0]; 2254 | } 2255 | } 2256 | } 2257 | if (argus.length == 3) 2258 | { 2259 | LCH[0] = argus[0]; 2260 | LCH[1] = argus[1]; 2261 | LCH[2] = argus[2]; 2262 | } 2263 | this._LCHab_to_XYZ(LCH) 2264 | return this; 2265 | } 2266 | 2267 | 2268 | ColorRNA.prototype._LuvX = function (argus) 2269 | { 2270 | 2271 | var Luv = [0, 0, 0]; 2272 | 2273 | if (argus.length == 0) 2274 | { 2275 | Luv = this._XYZ_to_Luv(); 2276 | this._normaOutX(Luv, 4); 2277 | return Luv; 2278 | } 2279 | 2280 | if (argus.length == 1) 2281 | { 2282 | if (Array.isArray(argus[0])) 2283 | { 2284 | if (argus[0].length == 3) 2285 | { 2286 | Luv = argus[0]; 2287 | } 2288 | } 2289 | } 2290 | if (argus.length == 3) 2291 | { 2292 | Luv[0] = argus[0]; 2293 | Luv[1] = argus[1]; 2294 | Luv[2] = argus[2]; 2295 | } 2296 | this._Luv_to_XYZ(Luv) 2297 | return this; 2298 | } 2299 | 2300 | 2301 | ColorRNA.prototype._baseRGB_XXXx = function (argus, mode) 2302 | { 2303 | var XXX = [0, 0, 0]; 2304 | 2305 | 2306 | if (argus.length == 0 || typeof argus[0] == "string") 2307 | { 2308 | if (typeof argus[0] == "string") this._colorSpace = argus[0]; 2309 | 2310 | var rgb = this._XYZ_to_RGB(); 2311 | 2312 | if (mode == "HSL") 2313 | { 2314 | return this._RGB_to_HSL(rgb); 2315 | } 2316 | else if (mode == "HSL255") 2317 | { 2318 | return this._RGB_to_HSL_255(rgb); 2319 | } 2320 | else if (mode == "HSLwin") 2321 | { 2322 | return this._RGB_to_HSL_win239(rgb); 2323 | } 2324 | else if (mode == "HSV" || mode == "HSB") 2325 | { 2326 | return this._RGB_to_HSV(rgb); 2327 | } 2328 | else if (mode == "HWB") 2329 | { 2330 | return this._RGB_to_HWB(rgb); 2331 | } 2332 | else if (mode == "YUV") 2333 | { 2334 | return this._RGB_to_YUV(rgb); 2335 | } 2336 | else if (mode == "YCbCr") 2337 | { 2338 | return this._RGB_to_YCbCr(rgb); 2339 | } 2340 | else if (mode == "JpegYCbCr") 2341 | { 2342 | return this._RGB_to_JpegYCbCr(rgb); 2343 | } 2344 | else if (mode == "YIQ") 2345 | { 2346 | return this._RGB_to_YIQ(rgb); 2347 | } 2348 | else if (mode == "YPbPr") 2349 | { 2350 | return this._RGB_to_YPbPr(rgb); 2351 | } 2352 | 2353 | else if (mode == "CMY") 2354 | { 2355 | return this._RGB_to_CMY(rgb); 2356 | } 2357 | else if (mode == "CMYK") 2358 | { 2359 | return this._RGB_to_CMYK(rgb); 2360 | } 2361 | 2362 | } 2363 | 2364 | if (argus.length == 1 || argus.length == 2) 2365 | { 2366 | 2367 | this._colorSpace = "sRGB"; 2368 | if (typeof argus[1] == "string") this._colorSpace = argus[3]; 2369 | 2370 | if (Array.isArray(argus[0])) 2371 | { 2372 | if (argus[0].length == 3) 2373 | { 2374 | XXX = argus[0]; 2375 | } 2376 | } 2377 | 2378 | } 2379 | 2380 | 2381 | if (argus.length >= 3 || typeof argus[3] == "string") 2382 | { 2383 | this._colorSpace = "sRGB"; 2384 | if (typeof argus[3] == "string") this._colorSpace = argus[3]; 2385 | 2386 | XXX[0] = argus[0]; 2387 | XXX[1] = argus[1]; 2388 | XXX[2] = argus[2]; 2389 | if (typeof argus[3] == "number") XXX[3] = argus[3]; 2390 | } 2391 | 2392 | 2393 | var rgb2 = [0, 0, 0]; 2394 | if (mode == "HSL") 2395 | { 2396 | rgb2 = this._HSL_to_RGB([XXX[0], XXX[1], XXX[2]]); 2397 | } 2398 | else if (mode == "HSL255") 2399 | { 2400 | rgb2 = this._HSL_to_RGB_255([XXX[0], XXX[1], XXX[2]]); 2401 | } 2402 | else if (mode == "HSLwin") 2403 | { 2404 | rgb2 = this._HSL_to_RGB_win240([XXX[0], XXX[1], XXX[2]]); 2405 | } 2406 | else if (mode == "HSV" || mode == "HSB") 2407 | { 2408 | rgb2 = this._HSV_to_RGB([XXX[0], XXX[1], XXX[2]]); 2409 | } 2410 | else if (mode == "HWB") 2411 | { 2412 | rgb2 = this._HWB_to_RGB([XXX[0], XXX[1], XXX[2]]); 2413 | } 2414 | else if (mode == "CMY") 2415 | { 2416 | rgb2 = this._CMY_to_RGB([XXX[0], XXX[1], XXX[2]]); 2417 | } 2418 | else if (mode == "YUV") 2419 | { 2420 | rgb2 = this._YUV_to_RGB([XXX[0], XXX[1], XXX[2]]); 2421 | } 2422 | else if (mode == "YCbCr") 2423 | { 2424 | rgb2 = this._YCbCr_to_RGB([XXX[0], XXX[1], XXX[2]]); 2425 | } 2426 | else if (mode == "JpegYCbCr") 2427 | { 2428 | rgb2 = this._JpegYCbCr_to_RGB([XXX[0], XXX[1], XXX[2]]); 2429 | } 2430 | else if (mode == "YIQ") 2431 | { 2432 | rgb2 = this._YIQ_to_RGB([XXX[0], XXX[1], XXX[2]]); 2433 | } 2434 | else if (mode == "YPbPr") 2435 | { 2436 | rgb2 = this._YPbPr_to_RGB_([XXX[0], XXX[1], XXX[2]]); 2437 | } 2438 | else if (mode == "CMYK") 2439 | { 2440 | rgb2 = this._CMYK_to_RGB([XXX[0], XXX[1], XXX[2], XXX[3]]); 2441 | } 2442 | 2443 | this.r = rgb2[0]; 2444 | this.g = rgb2[1]; 2445 | this.b = rgb2[2]; 2446 | 2447 | this._RGB_to_XYZ(); 2448 | 2449 | return this; 2450 | } 2451 | 2452 | 2453 | //----------------------------------- 2454 | 2455 | ColorRNA.prototype.Luv = function () 2456 | { 2457 | return (this._LuvX(arguments)); 2458 | } 2459 | 2460 | 2461 | ColorRNA.prototype.xyY = function () 2462 | { 2463 | return (this._xyYX(arguments)); 2464 | } 2465 | 2466 | 2467 | ColorRNA.prototype.LabPS = function () 2468 | { 2469 | return (this._LabX(arguments, true)); 2470 | } 2471 | 2472 | ColorRNA.prototype.Lab = function () 2473 | { 2474 | return (this._LabX(arguments, false)); 2475 | } 2476 | 2477 | 2478 | ColorRNA.prototype.LCHab = function () 2479 | { 2480 | return (this._LCHabX(arguments, false)); 2481 | } 2482 | 2483 | ColorRNA.prototype.HSL = function () 2484 | { 2485 | return (this._baseRGB_XXXx(arguments, "HSL")); 2486 | } 2487 | 2488 | ColorRNA.prototype.HSL255 = function () 2489 | { 2490 | return (this._baseRGB_XXXx(arguments, "HSL255")); 2491 | } 2492 | 2493 | ColorRNA.prototype.HSL240 = function () 2494 | { 2495 | return (this._baseRGB_XXXx(arguments, "HSLwin")); 2496 | } 2497 | 2498 | 2499 | ColorRNA.prototype.HSV = function () 2500 | { 2501 | return (this._baseRGB_XXXx(arguments, "HSV")); 2502 | } 2503 | 2504 | ColorRNA.prototype.HSB = function () 2505 | { 2506 | return (this._baseRGB_XXXx(arguments, "HSV")); 2507 | } 2508 | 2509 | ColorRNA.prototype.HWB = function () 2510 | { 2511 | return (this._baseRGB_XXXx(arguments, "HWB")); 2512 | } 2513 | 2514 | ColorRNA.prototype.YPbPr = function () 2515 | { 2516 | return (this._baseRGB_XXXx(arguments, "YPbPr")); 2517 | } 2518 | 2519 | ColorRNA.prototype.YIQ = function () 2520 | { 2521 | return (this._baseRGB_XXXx(arguments, "YIQ")); 2522 | } 2523 | 2524 | ColorRNA.prototype.JpegYCbCr = function () 2525 | { 2526 | return (this._baseRGB_XXXx(arguments, "JpegYCbCr")); 2527 | } 2528 | 2529 | ColorRNA.prototype.YCbCr = function () 2530 | { 2531 | return (this._baseRGB_XXXx(arguments, "YCbCr")); 2532 | } 2533 | 2534 | ColorRNA.prototype.YUV = function () 2535 | { 2536 | return (this._baseRGB_XXXx(arguments, "YUV")); 2537 | } 2538 | 2539 | 2540 | ColorRNA.prototype.CMYK = function () 2541 | { 2542 | return (this._baseRGB_XXXx(arguments, "CMYK")); 2543 | } 2544 | 2545 | ColorRNA.prototype.CMY = function () 2546 | { 2547 | return (this._baseRGB_XXXx(arguments, "CMY")); 2548 | } 2549 | 2550 | // 颜色设置、取值器,带参数调用设置颜色,不带参数调用取颜色 2551 | // 各种 RGB 色彩空间 --------------------------------------------------------------- 2552 | ColorRNA.prototype.sRGB = function () 2553 | { 2554 | return (this._rgbX(arguments, this._COLORSPACES.sRGB)); 2555 | } 2556 | 2557 | 2558 | ColorRNA.prototype.AdobeRGB = function () 2559 | { 2560 | return (this._rgbX(arguments, this._COLORSPACES.AdobeRGB)); 2561 | } 2562 | 2563 | ColorRNA.prototype.AppleRGB = function () 2564 | { 2565 | return (this._rgbX(arguments, this._COLORSPACES.AppleRGB)); 2566 | } 2567 | 2568 | ColorRNA.prototype.BestRGB = function () 2569 | { 2570 | return (this._rgbX(arguments, this._COLORSPACES.BestRGB)); 2571 | } 2572 | 2573 | ColorRNA.prototype.BetaRGB = function () 2574 | { 2575 | return (this._rgbX(arguments, this._COLORSPACES.BetaRGB)); 2576 | } 2577 | 2578 | ColorRNA.prototype.BruceRGB = function () 2579 | { 2580 | return (this._rgbX(arguments, this._COLORSPACES.BruceRGB)); 2581 | } 2582 | 2583 | ColorRNA.prototype.CIERGB = function () 2584 | { 2585 | return (this._rgbX(arguments, this._COLORSPACES.CIERGB)); 2586 | } 2587 | 2588 | ColorRNA.prototype.ColorMatchRGB = function () 2589 | { 2590 | return (this._rgbX(arguments, this._COLORSPACES.ColorMatchRGB)); 2591 | } 2592 | 2593 | ColorRNA.prototype.DonRGB4 = function () 2594 | { 2595 | return (this._rgbX(arguments, this._COLORSPACES.DonRGB4)); 2596 | } 2597 | 2598 | ColorRNA.prototype.ECIRGBv2 = function () 2599 | { 2600 | return (this._rgbX(arguments, this._COLORSPACES.ECIRGBv2)); 2601 | } 2602 | 2603 | ColorRNA.prototype.EktaSpacePS5 = function () 2604 | { 2605 | return (this._rgbX(arguments, this._COLORSPACES.EktaSpacePS5)); 2606 | } 2607 | 2608 | ColorRNA.prototype.NTSCRGB = function () 2609 | { 2610 | return (this._rgbX(arguments, this._COLORSPACES.NTSCRGB)); 2611 | } 2612 | 2613 | ColorRNA.prototype.PALSECAMRGB = function () 2614 | { 2615 | return (this._rgbX(arguments, this._COLORSPACES.PALSECAMRGB)); 2616 | } 2617 | 2618 | ColorRNA.prototype.ProPhotoRGB = function () 2619 | { 2620 | return (this._rgbX(arguments, this._COLORSPACES.ProPhotoRGB)); 2621 | } 2622 | 2623 | ColorRNA.prototype.SMPTECRGB = function () 2624 | { 2625 | return (this._rgbX(arguments, this._COLORSPACES.SMPTECRGB)); 2626 | } 2627 | 2628 | ColorRNA.prototype.WideGamutRGB = function () 2629 | { 2630 | return (this._rgbX(arguments, this._COLORSPACES.WideGamutRGB)); 2631 | } 2632 | 2633 | // --------------------------------------------------------------- 2634 | 2635 | ColorRNA.prototype.getWavelength = function (alg) 2636 | { 2637 | return +this._xyY_to_Wavelength(this.xyY()).toFixed(4); 2638 | 2639 | } 2640 | 2641 | ColorRNA.prototype.getLuma = function (alg) 2642 | { 2643 | var luma = 0; 2644 | var rgb = this._XYZ_to_RGB(); 2645 | this._normalizArray(rgb, 0, 255, 1); 2646 | 2647 | if (alg == "601") 2648 | { 2649 | luma = rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114; 2650 | } 2651 | else if (alg == "HSP") 2652 | { 2653 | 2654 | luma = Math.sqrt(.241 * Math.pow(rgb[0], 2) + 0.691 * Math.pow(rgb[1], 2) + 0.068 * Math.pow(rgb[2], 2)); 2655 | 2656 | } 2657 | else //709 2658 | { 2659 | luma = rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722; 2660 | } 2661 | 2662 | return luma; 2663 | //0~1 2664 | } 2665 | 2666 | ColorRNA.prototype.getWCAGluma = function () 2667 | {// http://www.w3.org/TR/WCAG20/#relativeluminancedef 2668 | 2669 | var rgb = this._XYZ_to_RGB(); 2670 | var luma = []; 2671 | for (var i = 0; i < rgb.length; i++) 2672 | { 2673 | var chan = rgb[i] / 255; 2674 | luma[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4) 2675 | } 2676 | return 0.2126 * luma[0] + 0.7152 * luma[1] + 0.0722 * luma[2]; 2677 | } 2678 | 2679 | 2680 | ColorRNA.prototype.getWCAGcontrastThan = function (inColor) 2681 | {//http://www.w3.org/TR/WCAG20/#contrast-ratiodef 2682 | 2683 | var luma1 = this.getWCAGluma(), 2684 | luma2 = inColor.getWCAGluma(); 2685 | 2686 | if (luma1 > luma2) 2687 | { 2688 | return (luma1 + 0.05) / (luma2 + 0.05) 2689 | } 2690 | ; 2691 | return (luma2 + 0.05) / (luma1 + 0.05); 2692 | 2693 | } 2694 | 2695 | ColorRNA.prototype.getHex = function () 2696 | {//get RGB Hex 2697 | 2698 | var rgb = 2699 | this._XYZ_to_RGB(); 2700 | var hex = this._rgb_to_hex([rgb[0], rgb[1], rgb[2]]); 2701 | return "#" + hex; 2702 | } 2703 | 2704 | // XYZ 色彩空间--------------------------------------------------------------- 2705 | 2706 | ColorRNA.prototype.XYZ = function () 2707 | { 2708 | var xyz = [0, 0, 0]; 2709 | 2710 | 2711 | if (arguments.length == 0) 2712 | { 2713 | xyz = [this._xyz.X, this._xyz.Y, this._xyz.Z]; 2714 | return xyz; 2715 | } 2716 | 2717 | if (arguments.length == 1) 2718 | { 2719 | if (Array.isArray(arguments[0])) 2720 | { 2721 | if (arguments[0].length == 3) 2722 | { 2723 | xyz = arguments[0]; 2724 | } 2725 | } 2726 | } 2727 | if (arguments.length == 3) 2728 | { 2729 | xyz[0] = arguments[0]; 2730 | xyz[1] = arguments[1]; 2731 | xyz[2] = arguments[2]; 2732 | } 2733 | 2734 | this._normaInputXYZ(xyz); 2735 | this._xyz.X = xyz[0]; 2736 | this._xyz.Y = xyz[1]; 2737 | this._xyz.Z = xyz[2]; 2738 | return this; 2739 | } 2740 | 2741 | //-------------------------------------------- 2742 | ColorRNA.prototype.colorDiff = function (color1, color2, alg) 2743 | { 2744 | var ca1 = color1.Lab(); 2745 | var Lab1 = {L: ca1[0], a: ca1[1], b: ca1[2]}; 2746 | 2747 | var ca2 = color2.Lab(); 2748 | var Lab2 = {L: ca2[0], a: ca2[1], b: ca2[2]}; 2749 | 2750 | 2751 | var deltaE = 0; 2752 | 2753 | if (alg == "DeltaE1976") 2754 | { 2755 | var delL = Lab1.L - Lab2.L; 2756 | var dela = Lab1.a - Lab2.a; 2757 | var delb = Lab1.b - Lab2.b; 2758 | deltaE = Math.sqrt(delL * delL + dela * dela + delb * delb); 2759 | } 2760 | 2761 | 2762 | // textiles OR Graphic Arts 2763 | if (alg == "DeltaE1994_T" || alg == "DeltaE1994_G") 2764 | { 2765 | var k1 = (alg == "DeltaE1994_T") ? 0.048 : 0.045; 2766 | var k2 = (alg == "DeltaE1994_T") ? 0.014 : 0.015; 2767 | var kL = (alg == "DeltaE1994_T") ? 2.0 : 1.0; 2768 | var kC = 1.0; 2769 | var kH = 1.0; 2770 | 2771 | var C1 = Math.sqrt(Lab1.a * Lab1.a + Lab1.b * Lab1.b); 2772 | var C2 = Math.sqrt(Lab2.a * Lab2.a + Lab2.b * Lab2.b); 2773 | 2774 | var delA = Lab1.a - Lab2.a; 2775 | var delB = Lab1.b - Lab2.b; 2776 | var delC = C1 - C2; 2777 | var delH2 = delA * delA + delB * delB - delC * delC; 2778 | var delH = (delH2 > 0.0) ? Math.sqrt(delH2) : 0.0; 2779 | var delL = Lab1.L - Lab2.L; 2780 | 2781 | var sL = 1.0; 2782 | var sC = 1.0 + k1 * C1; 2783 | var sH = 1.0 + k2 * C1; 2784 | 2785 | var vL = delL / (kL * sL); 2786 | var vC = delC / (kC * sC); 2787 | var vH = delH / (kH * sH); 2788 | 2789 | if (alg == "DeltaE1994_T") 2790 | { 2791 | deltaE = Math.sqrt(vL * vL + vC * vC + vH * vH); 2792 | } 2793 | else 2794 | { 2795 | deltaE = Math.sqrt(vL * vL + vC * vC + vH * vH); 2796 | } 2797 | } 2798 | 2799 | 2800 | if (alg == "DeltaE2000") 2801 | { 2802 | var kL = 1.0; 2803 | var kC = 1.0; 2804 | var kH = 1.0; 2805 | var lBarPrime = 0.5 * (Lab1.L + Lab2.L); 2806 | var c1 = Math.sqrt(Lab1.a * Lab1.a + Lab1.b * Lab1.b); 2807 | var c2 = Math.sqrt(Lab2.a * Lab2.a + Lab2.b * Lab2.b); 2808 | var cBar = 0.5 * (c1 + c2); 2809 | var cBar7 = cBar * cBar * cBar * cBar * cBar * cBar * cBar; 2810 | var g = 0.5 * (1.0 - Math.sqrt(cBar7 / (cBar7 + 6103515625.0))); 2811 | /* 6103515625 = 25^7 */ 2812 | var a1Prime = Lab1.a * (1.0 + g); 2813 | var a2Prime = Lab2.a * (1.0 + g); 2814 | var c1Prime = Math.sqrt(a1Prime * a1Prime + Lab1.b * Lab1.b); 2815 | var c2Prime = Math.sqrt(a2Prime * a2Prime + Lab2.b * Lab2.b); 2816 | var cBarPrime = 0.5 * (c1Prime + c2Prime); 2817 | var h1Prime = (Math.atan2(Lab1.b, a1Prime) * 180.0) / Math.PI; 2818 | if (h1Prime < 0.0) 2819 | h1Prime += 360.0; 2820 | var h2Prime = (Math.atan2(Lab2.b, a2Prime) * 180.0) / Math.PI; 2821 | if (h2Prime < 0.0) 2822 | h2Prime += 360.0; 2823 | var hBarPrime = (Math.abs(h1Prime - h2Prime) > 180.0) ? (0.5 * (h1Prime + h2Prime + 360.0)) : (0.5 * (h1Prime + h2Prime)); 2824 | var t = 1.0 - 2825 | 0.17 * Math.cos(Math.PI * ( hBarPrime - 30.0) / 180.0) + 2826 | 0.24 * Math.cos(Math.PI * (2.0 * hBarPrime ) / 180.0) + 2827 | 0.32 * Math.cos(Math.PI * (3.0 * hBarPrime + 6.0) / 180.0) - 2828 | 0.20 * Math.cos(Math.PI * (4.0 * hBarPrime - 63.0) / 180.0); 2829 | if (Math.abs(h2Prime - h1Prime) <= 180.0) 2830 | { 2831 | var dhPrime = h2Prime - h1Prime; 2832 | } 2833 | 2834 | else 2835 | { 2836 | var dhPrime = (h2Prime <= h1Prime) ? (h2Prime - h1Prime + 360.0) : (h2Prime - h1Prime - 360.0); 2837 | } 2838 | var dLPrime = Lab2.L - Lab1.L; 2839 | var dCPrime = c2Prime - c1Prime; 2840 | var dHPrime = 2.0 * Math.sqrt(c1Prime * c2Prime) * Math.sin(Math.PI * (0.5 * dhPrime) / 180.0); 2841 | var sL = 1.0 + ((0.015 * (lBarPrime - 50.0) * (lBarPrime - 50.0)) / Math.sqrt(20.0 + (lBarPrime - 50.0) * (lBarPrime - 50.0))); 2842 | var sC = 1.0 + 0.045 * cBarPrime; 2843 | var sH = 1.0 + 0.015 * cBarPrime * t; 2844 | var dTheta = 30.0 * Math.exp(-((hBarPrime - 275.0) / 25.0) * ((hBarPrime - 275.0) / 25.0)); 2845 | var cBarPrime7 = cBarPrime * cBarPrime * cBarPrime * cBarPrime * cBarPrime * cBarPrime * cBarPrime; 2846 | var rC = Math.sqrt(cBarPrime7 / (cBarPrime7 + 6103515625.0)); 2847 | var rT = -2.0 * rC * Math.sin(Math.PI * (2.0 * dTheta) / 180.0); 2848 | deltaE = Math.sqrt( 2849 | (dLPrime / (kL * sL)) * (dLPrime / (kL * sL)) + 2850 | (dCPrime / (kC * sC)) * (dCPrime / (kC * sC)) + 2851 | (dHPrime / (kH * sH)) * (dHPrime / (kH * sH)) + 2852 | (dCPrime / (kC * sC)) * (dHPrime / (kH * sH)) * rT); 2853 | } 2854 | 2855 | 2856 | if (alg == "DeltaECMC_11" || alg == "DeltaECMC_21") 2857 | { 2858 | if (alg == "DeltaECMC_11") 2859 | { 2860 | var L = 1.0, C = 1.0; 2861 | } 2862 | else if (alg == "DeltaECMC_21") 2863 | { 2864 | var L = 2.0, C = 1.0; 2865 | } 2866 | 2867 | var c1 = Math.sqrt(Lab1.a * Lab1.a + Lab1.b * Lab1.b); 2868 | var c2 = Math.sqrt(Lab2.a * Lab2.a + Lab2.b * Lab2.b); 2869 | var sl = (Lab1.L < 16.0) ? (0.511) : ((0.040975 * Lab1.L) / (1.0 + 0.01765 * Lab1.L)); 2870 | var sc = (0.0638 * c1) / (1.0 + 0.0131 * c1) + 0.638; 2871 | var h1 = (c1 < 0.000001) ? 0.0 : ((Math.atan2(Lab1.b, Lab1.a) * 180.0) / Math.PI); 2872 | while (h1 < 0.0) 2873 | h1 += 360.0; 2874 | while (h1 >= 360.0) 2875 | h1 -= 360.0; 2876 | var t = ((h1 >= 164.0) && (h1 <= 345.0)) ? (0.56 + Math.abs(0.2 * Math.cos((Math.PI * (h1 + 168.0)) / 180.0))) : (0.36 + Math.abs(0.4 * Math.cos((Math.PI * (h1 + 35.0)) / 180.0))); 2877 | var c4 = c1 * c1 * c1 * c1; 2878 | var f = Math.sqrt(c4 / (c4 + 1900.0)); 2879 | var sh = sc * (f * t + 1.0 - f); 2880 | var delL = Lab1.L - Lab2.L; 2881 | var delC = c1 - c2; 2882 | var delA = Lab1.a - Lab2.a; 2883 | var delB = Lab1.b - Lab2.b; 2884 | var dH2 = delA * delA + delB * delB - delC * delC; 2885 | var v1 = delL / (L * sl); 2886 | var v2 = delC / (C * sc); 2887 | var v3 = sh; 2888 | if (L == 2.0) 2889 | { 2890 | deltaE = Math.sqrt(v1 * v1 + v2 * v2 + (dH2 / (v3 * v3))); 2891 | } 2892 | else 2893 | { 2894 | deltaE = Math.sqrt(v1 * v1 + v2 * v2 + (dH2 / (v3 * v3))); 2895 | } 2896 | } 2897 | 2898 | return +deltaE.toFixed(2); 2899 | } 2900 | 2901 | 2902 | ColorRNA.prototype.diff_ECMC11_Than = function (color2) 2903 | { 2904 | return this.colorDiff(this, color2, "DeltaECMC_11"); 2905 | } 2906 | 2907 | ColorRNA.prototype.diff_ECMC21_Than = function (color2) 2908 | { 2909 | return this.colorDiff(this, color2, "DeltaECMC_21"); 2910 | } 2911 | 2912 | ColorRNA.prototype.diff_DE2000_Than = function (color2) 2913 | { 2914 | return this.colorDiff(this, color2, "DeltaE2000"); 2915 | } 2916 | 2917 | ColorRNA.prototype.diff_DE1976_Than = function (color2) 2918 | { 2919 | return this.colorDiff(this, color2, "DeltaE1976"); 2920 | } 2921 | 2922 | ColorRNA.prototype.diff_DE1994_GraphicArts_Than = function (color2) 2923 | { 2924 | return this.colorDiff(this, color2, "DeltaE1994_G"); 2925 | } 2926 | 2927 | ColorRNA.prototype.diff_DE1994_Textiles_Than = function (color2) 2928 | { 2929 | return this.colorDiff(this, color2, "DeltaE1994_T"); 2930 | } 2931 | 2932 | 2933 | export default ColorRNA; 2934 | 2935 | 2936 | 2937 | 2938 | 2939 | 2940 | 2941 | 2942 | 2943 | 2944 | 2945 | 2946 | 2947 | 2948 | 2949 | 2950 | 2951 | 2952 | 2953 | 2954 | -------------------------------------------------------------------------------- /test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 测试 7 | 8 | 9 | 10 |

测试

11 |
转到开发者工具的控制台
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/test_1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by ��� on 2015/10/12. 3 | */ 4 | 5 | //============================================================================================== 6 | console.log("---------TEST---------"); 7 | var color1 = new ColorRNA(10, 235, 245); 8 | var color2 = new ColorRNA(10, 235, 245); 9 | 10 | //console.log(color1.getHex()); 11 | console.log("RGB:" + color1.rgb()); 12 | console.log("sRGB:" + color1.sRGB()); 13 | console.log(color1.getHex()); 14 | console.log("AdobeRGB:" + color1.AdobeRGB()); 15 | console.log(color1.getHex()); 16 | console.log("AppleRGB:" + color1.AppleRGB()); 17 | console.log(color1.getHex()); 18 | console.log("ProPhotoRGB:" + color1.ProPhotoRGB()); 19 | console.log(color1.getHex()); 20 | 21 | 22 | // ת��ɫ�ʿռ� sRGB -> AdobeRGB�� 23 | color1.sRGB(10, 235, 245); 24 | color1.AdobeRGB(); // [133, 234, 244] 25 | 26 | // ת��ɫ�ʿռ� ProPhotoRGB -> AdobeRGB 27 | color1.ProPhotoRGB(154, 218, 239); 28 | console.log("ProPhotoRGB -> sRGB:" + color1.AdobeRGB()); // [10, 235, 245] 29 | 30 | // ת��ɫ�ʿռ� AppleRGB -> ProPhotoRGB 31 | console.log("AppleRGB -> ProPhotoRGB:" + color1.AppleRGB(52, 233, 243).ProPhotoRGB()); 32 | 33 | console.log("------------------------------------------------------------------------------"); 34 | 35 | console.log("Lab:" + color1.rgb(52, 233, 243).Lab()); 36 | console.log("LabPs:" + color1.rgb(52, 233, 243).LabPS()); 37 | console.log("LCHab:" + color1.rgb(52, 233, 243).LCHab()); 38 | console.log("Luv:" + color1.rgb(52, 233, 243).Luv()); 39 | console.log("xyY:" + color1.rgb(52, 233, 243).xyY()); 40 | console.log("XYZ:" + color1.rgb(52, 233, 243).XYZ()); 41 | 42 | console.log("----"); 43 | 44 | 45 | console.log("Lab_to_rgb:" + color1.Lab(84.7269, -39.5516, -17.4109).rgb()); 46 | console.log("LabPs_to_rgb:" + color1.LabPS(84, -42, -18).rgb()); 47 | console.log("LCHab_to_rgb:" + color1.LCHab(84.7269, 43.2142, 203.7594).rgb()); 48 | console.log("xyY_to_rgb:" + color1.xyY(0.2256, 0.3161, 0.6547).rgb()); 49 | console.log("Luv_to_rgb:" + color1.Luv(84.7269, -61.2033, -21.7867).rgb()); 50 | console.log("XYZ_to_rgb:" + color1.XYZ(0.4672539339338757, 0.6547307056620336, 0.9495155562423543).rgb()); 51 | 52 | console.log("----"); 53 | 54 | console.log("HSB:" + color1.rgb(52, 233, 243).HSB()); 55 | console.log("HSL:" + color1.rgb(52, 233, 243).HSL()); 56 | console.log("HSL240:" + color1.rgb(52, 233, 243).HSL240()); 57 | console.log("HSL255:" + color1.rgb(52, 233, 243).HSL255()); 58 | console.log("HWB:" + color1.rgb(52, 233, 243).HWB()); 59 | console.log("YUV:" + color1.rgb(52, 233, 243).YUV()); 60 | console.log("YIQ:" + color1.rgb(52, 233, 243).YIQ()); 61 | console.log("YCbCr:" + color1.rgb(52, 233, 243).YCbCr()); 62 | console.log("JpegYCbCr:" + color1.rgb(52, 233, 243).JpegYCbCr()); 63 | console.log("YPbPr:" + color1.rgb(52, 233, 243).YPbPr()); 64 | console.log("CMY:" + color1.rgb(52, 233, 243).CMY()); 65 | console.log("CMYK:" + color1.rgb(52, 233, 243).CMYK()); 66 | 67 | console.log("----"); 68 | 69 | console.log("HSB:" + color1.HSB(183, 79, 95).rgb()); 70 | console.log("HSL:" + color1.HSL(183, 89, 58).rgb()); 71 | console.log("HSL240:" + color1.HSL240(122, 213, 139).rgb()); 72 | console.log("HSL255:" + color1.HSL255(130, 227, 147).rgb()); 73 | console.log("HWB:" + color1.HWB(183, 20, 5).rgb()); 74 | console.log("YUV:" + color1.YUV(0.7059647058823528, 0.12143921568627458, -0.44045098039215685).rgb()); 75 | console.log("YIQ:" + color1.YIQ(0.7059647058823528, -0.43544010196078436, -0.1378909254901961).rgb()); 76 | console.log("YCbCr:" + color1.YCbCr(170.60627058823528, 159.2206156862745, 47.78768627450981).rgb()); 77 | console.log("JpegYCbCr:" + color1.JpegYCbCr(0.7059647058823528, 0.6393771749019608, 0.14190933333333333).rgb()); 78 | console.log("YPbPr:" + color1.YPbPr(0.7059647058823528, 0.13937717490196078, -0.35809066666666667).rgb()); 79 | console.log("CMY:" + color1.CMY(80,9,5).rgb()); 80 | console.log("CMYK:" + color1.CMYK(79,4,0,5).rgb()); 81 | 82 | console.log("----"); 83 | 84 | 85 | console.log("getWavelength:" + color1.rgb(255, 255, 0).getWavelength() +"nm"); 86 | console.log("getWavelength:" + color1.rgb(0, 222, 255).getWavelength() +"nm"); 87 | 88 | color1.rgb(112, 255, 0); 89 | console.log("getLumi:" + color1.getLuma()); 90 | console.log("getLumi709:" + color1.getLuma("709")); 91 | console.log("getLumi601:" + color1.getLuma("601")); 92 | console.log("getLumiHSP:" + color1.getLuma("HSP")); 93 | console.log("getWCAGluma:" + color1.getWCAGluma()); 94 | console.log("getWCAGluma:" + color1.getWCAGluma()); 95 | 96 | 97 | color1.rgb(123, 124, 21); 98 | color2.rgb(44, 22, 33); 99 | 100 | console.log("color1.diff_DE1976_Than(color2):" + color1.diff_DE1976_Than(color2)); 101 | console.log("color2.diff_DE1976_Than(color1):" + color2.diff_DE1976_Than(color1)); 102 | 103 | console.log("color1.diff_DE1994_GraphicArts_Than(color2):" + color1.diff_DE1994_GraphicArts_Than(color2)); 104 | console.log("color2.diff_DE1994_GraphicArts_Than(color1):" + color2.diff_DE1994_GraphicArts_Than(color1)); 105 | 106 | console.log("color1.diff_DE1994_Textiles_Than(color2):" + color1.diff_DE1994_Textiles_Than(color2)); 107 | console.log("color2.diff_DE1994_Textiles_Than(color1):" + color2.diff_DE1994_Textiles_Than(color1)); 108 | 109 | console.log("color1.diff_DE2000_Than(color2):" + color1.diff_DE2000_Than(color2)); 110 | console.log("color2.diff_DE2000_Than(color1):" + color2.diff_DE2000_Than(color1)); 111 | 112 | console.log("color1.diff_ECMC11_Than(color2):" + color1.diff_ECMC11_Than(color2)); 113 | console.log("color2.diff_ECMC11_Than(color1):" + color2.diff_ECMC11_Than(color1)); 114 | 115 | console.log("color1.diff_ECMC11_Than(color2):" + color1.diff_ECMC11_Than(color2)); 116 | console.log("color2.diff_ECMC11_Than(color1):" + color2.diff_ECMC11_Than(color1)); 117 | 118 | console.log("color1.diff_ECMC21_Than(color2):" + color1.diff_ECMC21_Than(color2)); 119 | console.log("color2.diff_ECMC21_Than(color1):" + color2.diff_ECMC21_Than(color1)); 120 | 121 | console.log("color1.getWCAGcontrastThan(color2):" + color1.getWCAGcontrastThan(color2)); 122 | console.log("color2.getWCAGcontrastThan(color1):" + color2.getWCAGcontrastThan(color1)); 123 | 124 | 125 | 126 | //color1.rgb(10, 20, 17); 127 | // 128 | // 129 | //console.time("����"); 130 | // 131 | //var test_color = new ColorRNA(rr, gg, bb); 132 | //for (var rr = 0; rr < 256; rr++) 133 | //{ 134 | // for (var gg = 0; gg < 256; gg++) 135 | // { 136 | // for (var bb = 0; bb < 256; bb++) 137 | // { 138 | // count++; 139 | // 140 | // color2.rgb(rr, gg, bb); 141 | // color2.AppleRGB(color2.AppleRGB()); 142 | // 143 | // rgb = color2.rgb(); 144 | // 145 | // if (count % 1000000 == 0) 146 | // { 147 | // console.log(count); 148 | // } 149 | // 150 | // if (rgb[0] != rr && rgb[1] != gg && rgb[2] != bb) 151 | // { 152 | // console.log("E>>>" + rgb + ":" + [rr, gg, bb]); 153 | // } 154 | // } 155 | // 156 | // } 157 | //} 158 | //console.timeEnd("����"); 159 | //console.log(count); 160 | -------------------------------------------------------------------------------- /test/test_node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by ��� on 2015/10/12. 3 | */ 4 | 5 | var ColorRNA = require('./../'); 6 | 7 | //============================================================================================== 8 | console.log("---------TEST---------"); 9 | var color1 = new ColorRNA(10, 235, 245); 10 | var color2 = new ColorRNA(10, 235, 245); 11 | 12 | //console.log(color1.getHex()); 13 | console.log("RGB:" + color1.rgb()); 14 | console.log("sRGB:" + color1.sRGB()); 15 | console.log(color1.getHex()); 16 | console.log("AdobeRGB:" + color1.AdobeRGB()); 17 | console.log(color1.getHex()); 18 | console.log("AppleRGB:" + color1.AppleRGB()); 19 | console.log(color1.getHex()); 20 | console.log("ProPhotoRGB:" + color1.ProPhotoRGB()); 21 | console.log(color1.getHex()); 22 | 23 | 24 | // ת��ɫ�ʿռ� sRGB -> AdobeRGB�� 25 | color1.sRGB(10, 235, 245); 26 | color1.AdobeRGB(); // [133, 234, 244] 27 | 28 | // ת��ɫ�ʿռ� ProPhotoRGB -> AdobeRGB 29 | color1.ProPhotoRGB(154, 218, 239); 30 | console.log("ProPhotoRGB -> sRGB:" + color1.AdobeRGB()); // [10, 235, 245] 31 | 32 | // ת��ɫ�ʿռ� AppleRGB -> ProPhotoRGB 33 | console.log("AppleRGB -> ProPhotoRGB:" + color1.AppleRGB(52, 233, 243).ProPhotoRGB()); 34 | 35 | console.log("------------------------------------------------------------------------------"); 36 | 37 | console.log("Lab:" + color1.rgb(52, 233, 243).Lab()); 38 | console.log("LabPs:" + color1.rgb(52, 233, 243).LabPS()); 39 | console.log("LCHab:" + color1.rgb(52, 233, 243).LCHab()); 40 | console.log("Luv:" + color1.rgb(52, 233, 243).Luv()); 41 | console.log("xyY:" + color1.rgb(52, 233, 243).xyY()); 42 | console.log("XYZ:" + color1.rgb(52, 233, 243).XYZ()); 43 | 44 | console.log("----"); 45 | 46 | 47 | console.log("Lab_to_rgb:" + color1.Lab(84.7269, -39.5516, -17.4109).rgb()); 48 | console.log("LabPs_to_rgb:" + color1.LabPS(84, -42, -18).rgb()); 49 | console.log("LCHab_to_rgb:" + color1.LCHab(84.7269, 43.2142, 203.7594).rgb()); 50 | console.log("xyY_to_rgb:" + color1.xyY(0.2256, 0.3161, 0.6547).rgb()); 51 | console.log("Luv_to_rgb:" + color1.Luv(84.7269, -61.2033, -21.7867).rgb()); 52 | console.log("XYZ_to_rgb:" + color1.XYZ(0.4672539339338757, 0.6547307056620336, 0.9495155562423543).rgb()); 53 | 54 | console.log("----"); 55 | 56 | console.log("HSB:" + color1.rgb(52, 233, 243).HSB()); 57 | console.log("HSL:" + color1.rgb(52, 233, 243).HSL()); 58 | console.log("HSL240:" + color1.rgb(52, 233, 243).HSL240()); 59 | console.log("HSL255:" + color1.rgb(52, 233, 243).HSL255()); 60 | console.log("HWB:" + color1.rgb(52, 233, 243).HWB()); 61 | console.log("YUV:" + color1.rgb(52, 233, 243).YUV()); 62 | console.log("YIQ:" + color1.rgb(52, 233, 243).YIQ()); 63 | console.log("YCbCr:" + color1.rgb(52, 233, 243).YCbCr()); 64 | console.log("JpegYCbCr:" + color1.rgb(52, 233, 243).JpegYCbCr()); 65 | console.log("YPbPr:" + color1.rgb(52, 233, 243).YPbPr()); 66 | console.log("CMY:" + color1.rgb(52, 233, 243).CMY()); 67 | console.log("CMYK:" + color1.rgb(52, 233, 243).CMYK()); 68 | 69 | console.log("----"); 70 | 71 | console.log("HSB:" + color1.HSB(183, 79, 95).rgb()); 72 | console.log("HSL:" + color1.HSL(183, 89, 58).rgb()); 73 | console.log("HSL240:" + color1.HSL240(122, 213, 139).rgb()); 74 | console.log("HSL255:" + color1.HSL255(130, 227, 147).rgb()); 75 | console.log("HWB:" + color1.HWB(183, 20, 5).rgb()); 76 | console.log("YUV:" + color1.YUV(0.7059647058823528, 0.12143921568627458, -0.44045098039215685).rgb()); 77 | console.log("YIQ:" + color1.YIQ(0.7059647058823528, -0.43544010196078436, -0.1378909254901961).rgb()); 78 | console.log("YCbCr:" + color1.YCbCr(170.60627058823528, 159.2206156862745, 47.78768627450981).rgb()); 79 | console.log("JpegYCbCr:" + color1.JpegYCbCr(0.7059647058823528, 0.6393771749019608, 0.14190933333333333).rgb()); 80 | console.log("YPbPr:" + color1.YPbPr(0.7059647058823528, 0.13937717490196078, -0.35809066666666667).rgb()); 81 | console.log("CMY:" + color1.CMY(80,9,5).rgb()); 82 | console.log("CMYK:" + color1.CMYK(79,4,0,5).rgb()); 83 | 84 | console.log("----"); 85 | 86 | 87 | console.log("getWavelength:" + color1.rgb(255, 255, 0).getWavelength() +"nm"); 88 | console.log("getWavelength:" + color1.rgb(0, 222, 255).getWavelength() +"nm"); 89 | 90 | color1.rgb(112, 255, 0); 91 | console.log("getLumi:" + color1.getLuma()); 92 | console.log("getLumi709:" + color1.getLuma("709")); 93 | console.log("getLumi601:" + color1.getLuma("601")); 94 | console.log("getLumiHSP:" + color1.getLuma("HSP")); 95 | console.log("getWCAGluma:" + color1.getWCAGluma()); 96 | console.log("getWCAGluma:" + color1.getWCAGluma()); 97 | 98 | 99 | color1.rgb(123, 124, 21); 100 | color2.rgb(44, 22, 33); 101 | 102 | console.log("color1.diff_DE1976_Than(color2):" + color1.diff_DE1976_Than(color2)); 103 | console.log("color2.diff_DE1976_Than(color1):" + color2.diff_DE1976_Than(color1)); 104 | 105 | console.log("color1.diff_DE1994_GraphicArts_Than(color2):" + color1.diff_DE1994_GraphicArts_Than(color2)); 106 | console.log("color2.diff_DE1994_GraphicArts_Than(color1):" + color2.diff_DE1994_GraphicArts_Than(color1)); 107 | 108 | console.log("color1.diff_DE1994_Textiles_Than(color2):" + color1.diff_DE1994_Textiles_Than(color2)); 109 | console.log("color2.diff_DE1994_Textiles_Than(color1):" + color2.diff_DE1994_Textiles_Than(color1)); 110 | 111 | console.log("color1.diff_DE2000_Than(color2):" + color1.diff_DE2000_Than(color2)); 112 | console.log("color2.diff_DE2000_Than(color1):" + color2.diff_DE2000_Than(color1)); 113 | 114 | console.log("color1.diff_ECMC11_Than(color2):" + color1.diff_ECMC11_Than(color2)); 115 | console.log("color2.diff_ECMC11_Than(color1):" + color2.diff_ECMC11_Than(color1)); 116 | 117 | console.log("color1.diff_ECMC11_Than(color2):" + color1.diff_ECMC11_Than(color2)); 118 | console.log("color2.diff_ECMC11_Than(color1):" + color2.diff_ECMC11_Than(color1)); 119 | 120 | console.log("color1.diff_ECMC21_Than(color2):" + color1.diff_ECMC21_Than(color2)); 121 | console.log("color2.diff_ECMC21_Than(color1):" + color2.diff_ECMC21_Than(color1)); 122 | 123 | console.log("color1.getWCAGcontrastThan(color2):" + color1.getWCAGcontrastThan(color2)); 124 | console.log("color2.getWCAGcontrastThan(color1):" + color2.getWCAGcontrastThan(color1)); 125 | 126 | 127 | 128 | //color1.rgb(10, 20, 17); 129 | // 130 | // 131 | //console.time("����"); 132 | // 133 | //var test_color = new ColorRNA(rr, gg, bb); 134 | //for (var rr = 0; rr < 256; rr++) 135 | //{ 136 | // for (var gg = 0; gg < 256; gg++) 137 | // { 138 | // for (var bb = 0; bb < 256; bb++) 139 | // { 140 | // count++; 141 | // 142 | // color2.rgb(rr, gg, bb); 143 | // color2.AppleRGB(color2.AppleRGB()); 144 | // 145 | // rgb = color2.rgb(); 146 | // 147 | // if (count % 1000000 == 0) 148 | // { 149 | // console.log(count); 150 | // } 151 | // 152 | // if (rgb[0] != rr && rgb[1] != gg && rgb[2] != bb) 153 | // { 154 | // console.log("E>>>" + rgb + ":" + [rr, gg, bb]); 155 | // } 156 | // } 157 | // 158 | // } 159 | //} 160 | //console.timeEnd("����"); 161 | //console.log(count); 162 | --------------------------------------------------------------------------------