Example #1
0
    def __call__(self, maze):
        """
        Encode current maze into one frame and return the encoded data.
        Note the graphics control block is not added here.
        """
        # the image descriptor
        if maze.frame_box is not None:
            left, top, right, bottom = maze.frame_box
        else:
            left, top, right, bottom = 0, 0, maze.width - 1, maze.height - 1

        width = right - left + 1
        height = bottom - top + 1
        descriptor = encoder.image_descriptor(
            maze.scaling * left + maze.translation[0],
            maze.scaling * top + maze.translation[1], maze.scaling * width,
            maze.scaling * height)

        pixels = [
            self.colormap[maze.get_cell(
                (x // maze.scaling + left, y // maze.scaling + top))]
            for y in range(height * maze.scaling)
            for x in range(width * maze.scaling)
        ]

        # the compressed image data of this frame
        data = self.compress(pixels)
        # clear `num_changes` and `frame_box`
        maze.reset()

        return descriptor + data
Example #2
0
    def __call__(self, pcanvas):
        """
        Encode current PixelCanvas into one frame and return the encoded data.
        Note the graphics control block is not added here.
        """
        # the image descriptor
        if pcanvas.frame_box is not None:
            left, top, right, bottom = pcanvas.frame_box
        else:
            left, top, right, bottom = 0, 0, pcanvas.width - 1, pcanvas.height - 1

        width = right - left + 1
        height = bottom - top + 1
        descriptor = encoder.image_descriptor(pcanvas.scaling * left + pcanvas.translation[0],
                                              pcanvas.scaling * top + pcanvas.translation[1],
                                              pcanvas.scaling * width,
                                              pcanvas.scaling * height)

        pixels = [self.colormap[pcanvas.get_pixel(x // pcanvas.scaling + left,
                                                  y // pcanvas.scaling + top)]
                  for y in range(height * pcanvas.scaling)
                  for x in range(width * pcanvas.scaling)]

        # the compressed image data of this frame
        data = self.compress(pixels)
        # clear `num_changes` and `frame_box`
        pcanvas.reset()

        return descriptor + data