]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blobdiff - displayio/tilegrid.py
Merge branch 'master' of https://github.com/adafruit/Adafruit_Blinka_Displayio
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / tilegrid.py
index c68fe9d370fca1e83cd5a7badbc833e8c03c5555..7308342e105bf741261d8f0727b5a1fc11cf4c7e 100644 (file)
@@ -82,9 +82,13 @@ class TileGrid:
         bitmap_width = bitmap.width
         bitmap_height = bitmap.height
 
         bitmap_width = bitmap.width
         bitmap_height = bitmap.height
 
-        if not isinstance(pixel_shader, (ColorConverter, Palette)):
+        if pixel_shader is not None and not isinstance(
+            pixel_shader, (ColorConverter, Palette)
+        ):
             raise ValueError("Unsupported Pixel Shader type")
         self._pixel_shader = pixel_shader
             raise ValueError("Unsupported Pixel Shader type")
         self._pixel_shader = pixel_shader
+        if isinstance(self._pixel_shader, ColorConverter):
+            self._pixel_shader._rgba = True  # pylint: disable=protected-access
         self._hidden = False
         self._x = x
         self._y = y
         self._hidden = False
         self._x = x
         self._y = y
@@ -93,6 +97,8 @@ class TileGrid:
         self._transpose_xy = False
         self._flip_x = False
         self._flip_y = False
         self._transpose_xy = False
         self._flip_x = False
         self._flip_y = False
+        self._top_left_x = 0
+        self._top_left_y = 0
         if tile_width is None:
             tile_width = bitmap_width
         if tile_height is None:
         if tile_width is None:
             tile_width = bitmap_width
         if tile_height is None:
@@ -184,6 +190,13 @@ class TileGrid:
                     self._current_area.y1,
                 )
 
                     self._current_area.y1,
                 )
 
+    def _shade(self, pixel_value):
+        if isinstance(self._pixel_shader, Palette):
+            return self._pixel_shader[pixel_value]["rgba"]
+        if isinstance(self._pixel_shader, ColorConverter):
+            return self._pixel_shader.convert(pixel_value)
+        return pixel_value
+
     # pylint: disable=too-many-locals
     def _fill_area(self, buffer):
         """Draw onto the image"""
     # pylint: disable=too-many-locals
     def _fill_area(self, buffer):
         """Draw onto the image"""
@@ -200,22 +213,20 @@ class TileGrid:
         x = self._x
         y = self._y
 
         x = self._x
         y = self._y
 
-        for tile_x in range(0, self._width):
-            for tile_y in range(0, self._height):
+        for tile_x in range(self._width):
+            for tile_y in range(self._height):
                 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
                 for pixel_x in range(self._tile_width):
                     for pixel_y in range(self._tile_height):
                 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
                 for pixel_x in range(self._tile_width):
                     for pixel_y in range(self._tile_height):
-                        image_x = tile_x * self._tile_width + pixel_x
-                        image_y = tile_y * self._tile_height + pixel_y
-                        bitmap_x = tile_index_x * self._tile_width + pixel_x
-                        bitmap_y = tile_index_y * self._tile_height + pixel_y
-                        pixel_color = self._pixel_shader[
-                            self._bitmap[bitmap_x, bitmap_y]
-                        ]
-                        if not pixel_color["transparent"]:
-                            image.putpixel((image_x, image_y), pixel_color["rgb888"])
+                        image_x = (tile_x * self._tile_width) + pixel_x
+                        image_y = (tile_y * self._tile_height) + pixel_y
+                        bitmap_x = (tile_index_x * self._tile_width) + pixel_x
+                        bitmap_y = (tile_index_y * self._tile_height) + pixel_y
+                        pixel_color = self._shade(self._bitmap[bitmap_x, bitmap_y])
+                        image.putpixel((image_x, image_y), pixel_color)
+
         if self._absolute_transform is not None:
             if self._absolute_transform.scale > 1:
                 image = image.resize(
         if self._absolute_transform is not None:
             if self._absolute_transform.scale > 1:
                 image = image.resize(