def animation_length(self):
     ani_pal_lengths = [
         self.dpla.get_frame_count_for_palette(x) for x in (0, 1)
         if self.dpla.has_for_palette(x)
     ]
     if len(ani_pal_lengths) < 1:
         return 0
     if len(ani_pal_lengths) < 2:
         len_pal_ani = ani_pal_lengths[0]
     else:
         len_pal_ani = lcm(*ani_pal_lengths)
     return len_pal_ani
Пример #2
0
    def _init_chunk_imgs(self):
        """(Re)-draw the chunk images"""
        self.chunks_surfaces = []

        # For each chunk...
        for chunk_idx in range(0, len(self.dpc.chunks)):
            # For each frame of palette animation... ( applicable for this chunk )
            pal_ani_frames = []
            self.chunks_surfaces.append(pal_ani_frames)

            chunk_data = self.dpc.chunks[chunk_idx]
            chunk_image = self.dpc.single_chunk_to_pil(chunk_idx, self.dpci,
                                                       self.dpl.palettes)
            has_pal_ani = any(chunk.pal_idx >= 10
                              and self.dpla.has_for_palette(chunk.pal_idx - 10)
                              for chunk in chunk_data)

            if not has_pal_ani:
                len_pal_ani = 1
            else:
                ani_pal_lengths = [
                    self.dpla.get_frame_count_for_palette(x) for x in (0, 1)
                    if self.dpla.has_for_palette(x)
                ]
                if len(ani_pal_lengths) < 2:
                    len_pal_ani = ani_pal_lengths[0]
                else:
                    len_pal_ani = lcm(*ani_pal_lengths)

            for pal_ani in range(0, len_pal_ani):
                # We don't have animated tiles, so ani_frames just has one entry.
                ani_frames = []
                pal_ani_frames.append(ani_frames)
                # Switch out the palette with that from the palette animation
                if has_pal_ani:
                    pal_for_frame = itertools.chain.from_iterable(
                        self.dpla.apply_palette_animations(
                            self.dpl.palettes, pal_ani))
                    chunk_image.putpalette(pal_for_frame)
                ani_frames.append(
                    pil_to_cairo_surface(chunk_image.convert('RGBA')))

        # TODO: No DPLA animations at different speeds supported at the moment
        ani_pal11 = 9999
        ani_pal12 = 9999
        if self.dpla.has_for_palette(0):
            ani_pal11 = self.dpla.get_duration_for_palette(0)
        if self.dpla.has_for_palette(1):
            ani_pal12 = self.dpla.get_duration_for_palette(1)

        self.pal_ani_durations = min(ani_pal11, ani_pal12)