Esempio n. 1
0
    def process_image(self, img, palette_text, bg_color_mask, bg_color_fill,
                      traversal, is_sprite, is_locked_tiles, lock_sprite_flips,
                      allow_overflow):
        """Process an image, creating the ppu_memory necessary to display it.

    img: Pixel art image.
    palette_text: Optional string representing a palette to be parsed.
    bg_color_mask: Background color mask, if a mask is begin used.
    bg_color_fill: Background color fill.
    traversal: Strategy for traversing the nametable.
    is_sprite: Whether the image is of sprites.
    is_locked_tiles: Whether tiles are locked into place. If so, do not
        merge duplicates, and only handle first 256 tiles.
    lock_sprite_flips: Whether to only lock sprite flip bits.
    allow_overflow: Characters representing components. Only 's' is supported.
    """
        self.initialize()
        self.load_image(img)
        self.blocks_y = NUM_BLOCKS_Y
        self.blocks_x = NUM_BLOCKS_X
        # Assign configuration.
        config = ppu_memory.PpuMemoryConfig(
            is_sprite=is_sprite,
            is_locked_tiles=is_locked_tiles,
            lock_sprite_flips=lock_sprite_flips,
            allow_overflow=allow_overflow)
        if 'c' in config.allow_overflow:
            self._ppu_memory.upgrade_chr_set_to_bank()
        # TODO: Not being used anywhere.
        self._ppu_memory.nt_width = NUM_BLOCKS_X * 2
        # If image is exactly 128x128 and uses locked tiles, treat it as though it
        # represents CHR memory.
        if self.image_x == self.image_y == SMALL_SQUARE and config.is_locked_tiles:
            self.blocks_y = NUM_BLOCKS_SMALL_SQUARE
            self.blocks_x = NUM_BLOCKS_SMALL_SQUARE
            self._ppu_memory.nt_width = NUM_BLOCKS_SMALL_SQUARE * 2
        # In order to auto detect the background color, have to count color needs.
        if config.is_sprite and bg_color_fill is None:
            self._color_manifest = id_manifest.CountingIdManifest()
        # Process each block and tile to build artifacts.
        self.process_to_artifacts(bg_color_mask, bg_color_fill, config)
        if self._err.has():
            return
        # Make the palette, and store it.
        pal = self.make_palette(palette_text, bg_color_fill, config.is_sprite)
        if not pal:
            return
        if not config.is_sprite:
            self._ppu_memory.palette_nt = pal
        else:
            self._ppu_memory.palette_spr = pal
        # Replace mask with fill.
        self.replace_mask_with_fill(bg_color_mask, bg_color_fill)
        # Make colorization for each block and tile.
        self.make_colorization(pal, config)
        if self._err.has():
            return
        # Traverse the artifacts, building chr and other ppu_memory.
        self.traverse_artifacts(traversal, pal, config)
        if self._err.has():
            return
        # Build spritelist if necessary.
        if config.is_sprite:
            self.make_spritelist(traversal, pal, config)
Esempio n. 2
0
 def __init__(self):
     image_processor.ImageProcessor.__init__(self)
     self._vert_color_manifest = id_manifest.CountingIdManifest()
Esempio n. 3
0
    def process_image(self, img, palette_text, bg_color_mask, bg_color_fill,
                      traversal, is_sprite, is_locked_tiles, lock_sprite_flips,
                      allow_overflow):
        """Process an image, creating the ppu_memory necessary to display it.

    img: Pixel art image.
    palette_text: Optional string representing a palette to be parsed.
    bg_color_mask: Background color mask, if a mask is being used.
    bg_color_fill: Background color fill.
    traversal: Strategy for traversing the nametable.
    is_sprite: Whether the image is of sprites.
    is_locked_tiles: Whether tiles are locked into place. If so, do not
        merge duplicates, and only handle first 256 tiles.
    lock_sprite_flips: Whether to only lock sprite flip bits.
    allow_overflow: Characters representing components. Only 'c' and 's'
        are supported.
    """
        self.initialize()
        self.load_image(img)
        # Assign configuration.
        config = ppu_memory.PpuMemoryConfig(
            is_sprite=is_sprite,
            is_locked_tiles=is_locked_tiles,
            lock_sprite_flips=lock_sprite_flips,
            allow_overflow=allow_overflow)
        if 'c' in config.allow_overflow:
            self._ppu_memory.upgrade_chr_set_to_bank()
        # Parse the palette if provided.
        pal = None
        if palette_text or self.img.palette:
            pal = self.parse_palette(palette_text, bg_color_fill)
        # In order to auto detect the background color, have to count color needs.
        # Counting is slower, so don't do it by default.
        if config.is_sprite and bg_color_fill is None:
            self._color_manifest = id_manifest.CountingIdManifest()
        # Process each block and tile to build artifacts.
        self.process_to_artifacts(bg_color_mask, bg_color_fill, config)
        if self._err.has():
            return
        # Make the palette, if it doesn't already exist.
        if not pal:
            pal = self.make_palette(bg_color_fill, config.is_sprite)
        if not pal:
            self.maybe_find_palette_subset_errors()
            return
        if not config.is_sprite:
            self._ppu_memory.palette_nt = pal
        else:
            self._ppu_memory.palette_spr = pal
        # Replace mask with fill.
        self.replace_mask_with_fill(bg_color_mask, bg_color_fill)
        # Make colorization for each block and tile.
        self.make_colorization(pal, config)
        if self._err.has():
            return
        # Traverse the artifacts, building chr and other ppu_memory.
        self.traverse_artifacts(traversal, pal, config)
        if self._err.has():
            return
        # Build spritelist if necessary.
        if config.is_sprite:
            self.make_spritelist(traversal, pal, config)