Skip to content

Commit 35d4898

Browse files
committed
Add image quantization to the (limited) palette of the e-paper module
1 parent dffc5ac commit 35d4898

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/drivers_color.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
from drivers.drivers_full import WaveshareFull
18+
from PIL import Image
1819

1920

2021
class WaveshareColor(WaveshareFull):
@@ -313,7 +314,13 @@ def init(self, **kwargs):
313314

314315
def get_frame_buffer(self, image, reverse=False):
315316
buf = [0x00] * int(self.width * self.height / 2)
316-
image_rgb = image.convert('RGB')
317+
318+
# quantize image with palette of possible colors
319+
image_palette = Image.new('P', (1, 1))
320+
image_palette.putpalette(([0, 0, 0, 255, 255, 255, 0, 255, 0, 0, 0, 255, 255, 0, 0, 255, 255, 0, 255, 128, 0]
321+
+ [0, 0, 0]) * 32) # multiply by 32 to pad palette to reach required length of 768
322+
image_rgb = image.quantize(palette=image_palette).convert('RGB')
323+
317324
imwidth, imheight = image_rgb.size
318325

319326
if imwidth != self.width or imheight != self.height:

0 commit comments

Comments
 (0)