tile_width = bitmap_width
if tile_height is None:
tile_height = bitmap_height
- if bitmap_width % tile_width != 0:
+ if tile_width > 0 and bitmap_width % tile_width != 0:
raise ValueError("Tile width must exactly divide bitmap width")
self._tile_width = tile_width
- if bitmap_height % tile_height != 0:
+ if tile_height > 0 and bitmap_height % tile_height != 0:
raise ValueError("Tile height must exactly divide bitmap height")
self._tile_height = tile_height
if not 0 <= default_tile <= 255:
return pixel_value
def _apply_palette(self, image):
- if isinstance(self._pixel_shader, Palette):
- image.putpalette(
- self._pixel_shader._get_palette() # pylint: disable=protected-access
- )
- if isinstance(self._pixel_shader, ColorConverter):
- # This will be needed for eInks, grayscale, and monochrome displays
- pass
+ image.putpalette(
+ self._pixel_shader._get_palette() # pylint: disable=protected-access
+ )
def _add_alpha(self, image):
- if isinstance(self._pixel_shader, Palette):
- alpha = self._bitmap._image.copy().convert( # pylint: disable=protected-access
- "P"
- )
- alpha.putpalette(
- self._pixel_shader._get_alpha_palette() # pylint: disable=protected-access
- )
- image.putalpha(alpha.convert("L"))
+ alpha = self._bitmap._image.copy().convert( # pylint: disable=protected-access
+ "P"
+ )
+ alpha.putpalette(
+ self._pixel_shader._get_alpha_palette() # pylint: disable=protected-access
+ )
+ image.putalpha(alpha.convert("L"))
# pylint: disable=too-many-locals
def _fill_area(self, buffer):
tile_index = self._tiles[tile_y * self._width + tile_x]
tile_index_x = tile_index % tile_count_x
tile_index_y = tile_index // tile_count_x
- tile_image = self._bitmap._image.copy().convert( # pylint: disable=protected-access
- "P"
- )
- self._apply_palette(tile_image)
- tile_image = tile_image.convert("RGBA")
- self._add_alpha(tile_image)
+ tile_image = self._bitmap._image # pylint: disable=protected-access
+ if isinstance(self._pixel_shader, Palette):
+ tile_image = tile_image.copy().convert("P")
+ self._apply_palette(tile_image)
+ tile_image = tile_image.convert("RGBA")
+ self._add_alpha(tile_image)
+ elif isinstance(self._pixel_shader, ColorConverter):
+ # This will be needed for eInks, grayscale, and monochrome displays
+ pass
image.alpha_composite(
tile_image,
dest=(tile_x * self._tile_width, tile_y * self._tile_height),