MCPcopy Index your code
hub / github.com/plotly/plotly.py / asRGB

Method asRGB

_plotly_utils/png.py:2065–2105  ·  view source on GitHub ↗

Return image as RGB pixels. RGB colour images are passed through unchanged; greyscales are expanded into RGB triplets (there is a small speed overhead for doing this). An alpha channel in the source image will raise an exception. The return values a

(self)

Source from the content-addressed store, hash-verified

2063 return self._as_rescale(self.asRGBA, 8)
2064
2065 def asRGB(self):
2066 """
2067 Return image as RGB pixels.
2068 RGB colour images are passed through unchanged;
2069 greyscales are expanded into RGB triplets
2070 (there is a small speed overhead for doing this).
2071
2072 An alpha channel in the source image will raise an exception.
2073
2074 The return values are as for the :meth:`read` method except that
2075 the *info* reflect the returned pixels, not the source image.
2076 In particular,
2077 for this method ``info['greyscale']`` will be ``False``.
2078 """
2079
2080 width, height, pixels, info = self.asDirect()
2081 if info["alpha"]:
2082 raise Error("will not convert image with alpha channel to RGB")
2083 if not info["greyscale"]:
2084 return width, height, pixels, info
2085 info["greyscale"] = False
2086 info["planes"] = 3
2087
2088 if info["bitdepth"] > 8:
2089
2090 def newarray():
2091 return array("H", [0])
2092
2093 else:
2094
2095 def newarray():
2096 return bytearray([0])
2097
2098 def iterrgb():
2099 for row in pixels:
2100 a = newarray() * 3 * width
2101 for i in range(3):
2102 a[i::3] = row
2103 yield a
2104
2105 return width, height, iterrgb(), info
2106
2107 def asRGBA(self):
2108 """

Callers

nothing calls this directly

Calls 2

asDirectMethod · 0.95
ErrorClass · 0.85

Tested by

no test coverage detected