Skip to content

Commit

Permalink
Add image quantization to the (limited) palette of the e-paper module
Browse files Browse the repository at this point in the history
  • Loading branch information
fpammer committed Aug 9, 2020
1 parent dffc5ac commit 35d4898
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/drivers_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from drivers.drivers_full import WaveshareFull
from PIL import Image


class WaveshareColor(WaveshareFull):
Expand Down Expand Up @@ -313,7 +314,13 @@ def init(self, **kwargs):

def get_frame_buffer(self, image, reverse=False):
buf = [0x00] * int(self.width * self.height / 2)
image_rgb = image.convert('RGB')

# quantize image with palette of possible colors
image_palette = Image.new('P', (1, 1))
image_palette.putpalette(([0, 0, 0, 255, 255, 255, 0, 255, 0, 0, 0, 255, 255, 0, 0, 255, 255, 0, 255, 128, 0]
+ [0, 0, 0]) * 32) # multiply by 32 to pad palette to reach required length of 768
image_rgb = image.quantize(palette=image_palette).convert('RGB')

imwidth, imheight = image_rgb.size

if imwidth != self.width or imheight != self.height:
Expand Down

0 comments on commit 35d4898

Please sign in to comment.