* @function LevelRenderer.Tool.Color.prototype.convert * @description 颜色格式转化。 * @param {Array} data - 颜色值数组。 * @param {string} format - 格式,默认'rgb' * @returns {string} 颜色。
(color, format)
| 470 | * @returns {string} 颜色。 |
| 471 | */ |
| 472 | convert(color, format) { |
| 473 | if (!this.isCalculableColor(color)) { |
| 474 | return color; |
| 475 | } |
| 476 | var data = this.getData(color); |
| 477 | var alpha = data[3]; |
| 478 | if (typeof alpha === 'undefined') { |
| 479 | alpha = 1; |
| 480 | } |
| 481 | |
| 482 | if (color.indexOf('hsb') > -1) { |
| 483 | data = this._HSV_2_RGB(data); |
| 484 | } else if (color.indexOf('hsl') > -1) { |
| 485 | data = this._HSL_2_RGB(data); |
| 486 | } |
| 487 | |
| 488 | if (format.indexOf('hsb') > -1 || format.indexOf('hsv') > -1) { |
| 489 | data = this._RGB_2_HSB(data); |
| 490 | } else if (format.indexOf('hsl') > -1) { |
| 491 | data = this._RGB_2_HSL(data); |
| 492 | } |
| 493 | |
| 494 | data[3] = alpha; |
| 495 | |
| 496 | return this.toColor(data, format); |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * @function LevelRenderer.Tool.Color.prototype.toRGBA |
no test coverage detected