MCPcopy Index your code
hub / github.com/lincolnloop/python-qrcode / SolidFillColorMask

Class SolidFillColorMask

qrcode/image/styles/colormasks.py:93–118  ·  view source on GitHub ↗

Just fills in the background with one color and the foreground with another

Source from the content-addressed store, hash-verified

91
92
93class SolidFillColorMask(QRColorMask):
94 """
95 Just fills in the background with one color and the foreground with another
96 """
97
98 def __init__(self, back_color=(255, 255, 255), front_color=(0, 0, 0)):
99 self.back_color = back_color
100 self.front_color = front_color
101 self.has_transparency = len(self.back_color) == 4
102
103 def apply_mask(self, image):
104 if self.back_color == (255, 255, 255) and self.front_color == (0, 0, 0):
105 # Optimization: the image is already drawn by QRModuleDrawer in
106 # black and white, so if these are also our mask colors we don't
107 # need to do anything. This is much faster than actually applying a
108 # mask.
109 pass
110 else:
111 # TODO there's probably a way to use PIL.ImageMath instead of doing
112 # the individual pixel comparisons that the base class uses, which
113 # would be a lot faster. (In fact doing this would probably remove
114 # the need for the B&W optimization above.)
115 QRColorMask.apply_mask(self, image, use_cache=True)
116
117 def get_fg_pixel(self, image, x, y):
118 return self.front_color
119
120
121class RadialGradiantColorMask(QRColorMask):

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected