Just fills in the background with one color and the foreground with another
| 91 | |
| 92 | |
| 93 | class 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 | |
| 121 | class RadialGradiantColorMask(QRColorMask): |