我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用colorsys.yiq_to_rgb()。
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
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))
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))
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)) )
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: