Return a tuple with the vt100 values  that represent this color.
193684
def _colors_to_code(self, fg_color, bg_color):
        "  "
        # When requesting ANSI colors only, and both fg/bg color were converted
        # to ANSI, ensure that the foreground and background color are not the
        # same. (Unless they were explicitely defined to be the same color.)
        fg_ansi = [()]

        def get(color, bg):
            table = BG_ANSI_COLORS if bg else FG_ANSI_COLORS

            if color is None:
                return ()

            # 16 ANSI colors. (Given by name.)
            elif color in table:
                return (table[color], )

            # RGB colors. (Defined as 'ffffff'.)
            else:
                try:
                    rgb = self._color_name_to_rgb(color)
                except ValueError:
                    return ()

                # When only 16 colors are supported, use that.
                if self.ansi_colors_only():
                    if bg:  # Background.
                        if fg_color != bg_color:
                            exclude = (fg_ansi[0], )
                        else:
                            exclude = ()
                        code, name = _16_bg_colors.get_code(rgb, exclude=exclude)
                        return (code, )
                    else:  # Foreground.
                        code, name = _16_fg_colors.get_code(rgb)
                        fg_ansi[0] = name
                        return (code, )

                # True colors. (Only when this feature is enabled.)
                elif self.true_color:
                    r, g, b = rgb
                    return (48 if bg else 38, 2, r, g, b)

                # 256 RGB colors.
                else:
                    return (48 if bg else 38, 5, _256_colors[rgb])

        result = []
        result.extend(get(fg_color, False))
        result.extend(get(bg_color, True))

        return map(six.text_type, result)
1326524
def get_color(self):
        """"""
        self.get_status()
        try:
            self.color = self.data['color']
            self.mode = self.data['mode']
        except TypeError:
            self.color = 0
            self.mode = ''

        return {'color': self.color, 'mode': self.mode}
248207
def _assert_is_color(value):
        
        if not isinstance(value, tuple) or len(value) != 3:
            raise ValueError("Color must be a RGB tuple.")

        if not all(0 <= x <= 255 for x in value):
            raise ValueError("RGB values of color must be between 0 and 255.")
1193316
def _cal_color(self, value, color_index):
        """"""
        range_min_p = self._domain[color_index]
        range_p = self._domain[color_index + 1] - range_min_p
        try:
            factor = (value - range_min_p) / range_p
        except ZeroDivisionError:
            factor = 0

        min_color = self.colors[color_index]
        max_color = self.colors[color_index + 1]
        red = round(factor * (max_color.r - min_color.r) + min_color.r)
        green = round(factor * (max_color.g - min_color.g) + min_color.g)
        blue = round(factor * (max_color.b - min_color.b) + min_color.b)

        return Color(red, green, blue)
489970
def clamp(color, min_v, max_v):
    
    h, s, v = rgb_to_hsv(*map(down_scale, color))
    min_v, max_v = map(down_scale, (min_v, max_v))
    v = min(max(min_v, v), max_v)
    return tuple(map(up_scale, hsv_to_rgb(h, s, v)))
1092361
def get_color_name(value):
    """"""
    if not is_known_type(value):
        return CUSTOM_TYPE_COLOR
    for typ, name in list(COLORS.items()):
        if isinstance(value, typ):
            return name
    else:
        np_dtype = get_numpy_dtype(value)
        if np_dtype is None or not hasattr(value, 'size'):
            return UNSUPPORTED_COLOR
        elif value.size == 1:
            return SCALAR_COLOR
        else:
            return ARRAY_COLOR
157951
def rgba_bytes_tuple(self, x):
        
        return tuple(int(u*255.9999) for u in self.rgba_floats_tuple(x))
1049547
def hex_color_to_tuple(hex):
    
    hex = hex[1:]
    length = len(hex) // 2
    return tuple(int(hex[i*2:i*2+2], 16) for i in range(length))
760319
def _compute_iso_color(self):
        
        level_color = []
        colors = self._lc
        for i, index in enumerate(self._li):
            level_color.append(np.zeros((index, 4)) + colors[i])
        self._cl = np.vstack(level_color)
178216
def rgba_floats_tuple(self, x):
        
        if x <= self.index[0]:
            return self.colors[0]
        if x >= self.index[-1]:
            return self.colors[-1]

        i = len([u for u in self.index if u < x])  # 0 < i < n.
        if self.index[i-1] < self.index[i]:
            p = (x - self.index[i-1])*1./(self.index[i]-self.index[i-1])
        elif self.index[i-1] == self.index[i]:
            p = 1.
        else:
            raise ValueError('Thresholds are not sorted.')

        return tuple((1.-p) * self.colors[i-1][j] + p*self.colors[i][j] for j
                     in range(4))
813766
def get_color(value, alpha):
    """"""
    color = QColor()
    for typ in COLORS:
        if isinstance(value, typ):
            color = QColor(COLORS[typ])
    color.setAlphaF(alpha)
    return color
163631
def color_to_tuple(color, opacity=1):
    
    if(type(color) == str and color[0] == "#"):
        color = hex_color_to_tuple(color)

    elif type(color) == str:
        if color in color_dict:
            color = color_dict[color.lower()]
        else:
            print("无法解析颜色:" + color)
            color = (255, 125, 0, int(255*opacity)) 

    while len(color) < 4:
        color += (int(255*opacity),)

    return color
859575
def getColorForValue(self, value):
        
        rampIndex = 0

        if value >= self.min and value <= self.max:
            rampIndex = self.getIndexForValue(value)

        elif value > self.max:
            rampIndex = -1

        elif value < self.min:
            rampIndex = 0

        return self.getColorForIndex(rampIndex)
511249
def get_average_color(colors):
    
    c = reduce(color_reducer, colors)
    total = len(colors)
    return tuple(v / total for v in c)
904754
def _svgcolor(color):
    
    return 'rgb(%d,%d,%d)' % tuple([int(255 * x) for x in [color.r, color.g, color.b]])
241254
def _lightness(color, **kwargs):
    
    l = colorsys.rgb_to_hls(*[x / 255.0 for x in color.value[:3]])[1]
    return NumberValue((l * 100, '%'))
211643
def get_color_dist(c1, c2):
    
    return tuple(abs(v1 - v2) for v1, v2 in itertools.izip(c1, c2))