Exemple #1
0
    def make_colorization(self, pal, config):
        """Select colorization for each position in the image.

    pal: Palette for this image.
    config: Configuration of ppu_memory
    """
        if not config.is_sprite:
            # For each block, get the attribute aka the palette.
            for block_y in xrange(self.blocks_y):
                for block_x in xrange(self.blocks_x):
                    y = block_y * 2
                    x = block_x * 2
                    (cid, did, bcid) = self._artifacts[y][x]
                    color_needs = self._needs_provider.at(bcid)
                    try:
                        (pid, palette_option) = pal.select(color_needs)
                    except IndexError:
                        self._err.add(
                            errors.PaletteNoChoiceError(y, x, color_needs))
                        pid = 0
                    for a, b in itertools.product(range(2), range(2)):
                        self._ppu_memory.gfx_0.colorization[y + a][x + b] = pid
        else:
            # For each tile, get the attribute aka the palette.
            for y in xrange(self.blocks_y * 2):
                for x in xrange(self.blocks_x * 2):
                    (cid, did, bcid) = self._artifacts[y][x]
                    color_needs = self._needs_provider.at(cid)
                    try:
                        (pid, palette_option) = pal.select(color_needs)
                    except IndexError:
                        self._err.add(
                            errors.PaletteNoChoiceError(y, x, color_needs))
                        pid = 0
                    self._ppu_memory.gfx_0.colorization[y][x] = pid
 def write_data(self, regions, all_tiles, picdata):
   self.image_y = self.image_x = 8
   self.mask_rgb_color = rgb.nc_to_rgb(self.bg_mask)
   # Create color_needs for each tile's non-overlapping pixels
   for i, g in enumerate(regions):
     b_y = g.min_y
     b_x = g.min_x
     picture = picdata[i]
     for j, elem in enumerate(picture):
       dots = self.calculate_overlap(elem, j, picture)
       tile = all_tiles[elem.tile_idx]
       self.pixels = tile.copy().load()
       self.apply_dots_overlap(dots, self.pixels)
       try:
         color_needs, dot_profile = self.process_tile(0, 0)
       except errors.CouldntConvertRGB as e:
         self._err.add(e)
         continue
       cid = self._color_manifest.id(color_needs)
       elem.cid = cid
   self._needs_provider = self._color_manifest
   # Calculate the palette
   pal = None
   if self.palette_text:
     pal = self.parse_palette(self.palette_text, self.bg_mask)
   if not pal:
     pal = self.make_palette(self.bg_mask, True)
   if self._err.has():
     return
   # Set palette
   self._ppu_memory.palette_spr = pal
   # Create chr and picdata
   result = []
   chrdata_cache = {}
   for i, _ in enumerate(regions):
     accum = []
     for _, elem in enumerate(picdata[i]):
       tile_pixels = all_tiles[elem.tile_idx]
       color_needs = self._color_manifest.at(elem.cid)
       try:
         (pid, popt) = pal.select(color_needs)
       except IndexError:
         self._err.add(errors.PaletteNoChoiceError(elem.y, elem.x,
                                                   color_needs))
         continue
       tile = self.build_tile_from_pixels_ignoring_unknown(tile_pixels, popt)
       key = str(tile)
       if key in chrdata_cache:
         chr_num, flips = chrdata_cache[key]
       else:
         chr_num = self._ppu_memory.chr_set.add(tile)
         flips = 0
         self.assign_tile_flips(tile, [chr_num], chrdata_cache)
       accum.append({'y': elem.y, 'x': elem.x, 'attr': flips | pid,
                     'tile': chr_num})
     g = regions[i]
     result.append({'top': g.min_y, 'left': g.min_x,
                    'bottom': g.max_y, 'right': g.max_x,
                    'elems': accum})
   self._ppu_memory.sprite_picdata = result
Exemple #3
0
    def make_colorization(self, pal, config):
        """Select colorization for each position in the image.

    pal: Palette for this image.
    config: Configuration of ppu_memory
    """
        for g, gfx in enumerate(self._ppu_memory.gfx):
            nt_y, nt_x = (gfx.nt_y, gfx.nt_x)
            page_y = (g // self.screen_x) * nt_y
            page_x = (g % self.screen_x) * nt_x
            if not config.is_sprite:
                # For each block, get the attribute aka the palette.
                for block_x in range(nt_x // 2):
                    for block_y in range(nt_y // 2):
                        y = block_y * 2
                        x = block_x * 2
                        (cid, did,
                         bcid) = self._artifacts[y + page_y][x + page_x]
                        color_needs = self._needs_provider.at(bcid)
                        try:
                            (pid, palette_option) = pal.select(color_needs)
                        except IndexError:
                            self._err.add(
                                errors.PaletteNoChoiceError(y, x, color_needs))
                            pid = 0
                        for a, b in itertools.product(range(2), range(2)):
                            gfx.colorization[y + a][x + b] = pid
            else:
                # For each tile, get the attribute aka the palette.
                for x in range(nt_x):
                    for y in range(nt_y):
                        (cid, did,
                         bcid) = self._artifacts[y + page_y][x + page_x]
                        color_needs = self._needs_provider.at(cid)
                        try:
                            (pid, palette_option) = pal.select(color_needs)
                        except IndexError:
                            self._err.add(
                                errors.PaletteNoChoiceError(y, x, color_needs))
                            pid = 0
                        gfx.colorization[y][x] = pid
Exemple #4
0
 def make_colorization(self, pal, config):
     """Colorization for each vertical pair."""
     for (y, x) in self.get_generator('8x16'):
         # Upper and lower have the same color. Ignore the lower position.
         (cid, did, vcid) = self._artifacts[y][x]
         color_needs = self._vert_color_manifest.at(vcid)
         try:
             (pid, palette_option) = pal.select(color_needs)
         except IndexError:
             self._err.add(errors.PaletteNoChoiceError(y, x, color_needs))
             pid = 0
         self._ppu_memory.gfx_0.colorization[y][x] = pid
         self._ppu_memory.gfx_0.colorization[y + 1][x] = pid