Python colorsys 模块,yiq_to_rgb() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用colorsys.yiq_to_rgb()

项目:springboard    作者:tingbot    | 项目源码 | 文件源码
def background_color(self):
        try:
            hex_color = self.info['background_color']
        except KeyError:
            return TingApp.default_background_color

        try:
            color = _hex_color_to_tuple(hex_color)
        except:
            logging.exception('Failed to parse hex color, using default')
            return TingApp.default_background_color

        # colorsys works with colors between 0 and 1
        fractional_color = _color_multiply(color, 1/255.0)
        y, i, q = colorsys.rgb_to_yiq(*fractional_color)

        if y > 0.6:
            y = 0.6
            fractional_color = colorsys.yiq_to_rgb(y, i, q)
            color = _color_multiply(fractional_color, 255)
            logging.warning(
                'Background color was too bright (white text must be visible on top of this '
                'color), color "%s" was darkened to "%s"' % (hex_color, _tuple_to_hex_color(color)))

        return color
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_yiq_values(self):
        values = [
            # rgb, yiq
            ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), # black
            ((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), # blue
            ((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), # green
            ((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), # cyan
            ((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), # red
            ((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), # purple
            ((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), # yellow
            ((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), # white
            ((0.5, 0.5, 0.5), (0.5, 0.0, 0.0)), # grey
        ]
        for (rgb, yiq) in values:
            self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb))
            self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_yiq_values(self):
        values = [
            # rgb, yiq
            ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), # black
            ((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), # blue
            ((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), # green
            ((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), # cyan
            ((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), # red
            ((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), # purple
            ((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), # yellow
            ((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), # white
            ((0.5, 0.5, 0.5), (0.5, 0.0, 0.0)), # grey
        ]
        for (rgb, yiq) in values:
            self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb))
            self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq))
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def from_yiq(cls, y, i, q):
        """
        Construct a :class:`Color` from three `Y'IQ`_ float values. Y' can be
        between 0.0 and 1.0, while I and Q can be between -1.0 and 1.0.
        """
        return super(Color, cls).__new__(cls, *colorsys.yiq_to_rgb(y, i, q))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_yiq_roundtrip(self):
        for r in frange(0.0, 1.0, 0.2):
            for g in frange(0.0, 1.0, 0.2):
                for b in frange(0.0, 1.0, 0.2):
                    rgb = (r, g, b)
                    self.assertTripleEqual(
                        rgb,
                        colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
                    )
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_yiq_roundtrip(self):
        for r in frange(0.0, 1.0, 0.2):
            for g in frange(0.0, 1.0, 0.2):
                for b in frange(0.0, 1.0, 0.2):
                    rgb = (r, g, b)
                    self.assertTripleEqual(
                        rgb,
                        colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
                    )
项目:rvmi-rekall    作者:fireeye    | 项目源码 | 文件源码
def YIQToRGB(y, i, q):
    red, green, blue = colorsys.yiq_to_rgb(y, i, q)
    return int(red * 0xff), int(green * 0xff), int(blue * 0xff)


# Text-color heuristics: