コード例 #1
0
ファイル: tiledsurface.py プロジェクト: vendettaboom/mypaint
    def __init__(self, surface, x, y, sort=True):
        """Starts the move, recording state in the Move object

        :param x: Where to start, model X coordinate
        :param y: Where to start, model Y coordinate
        :param sort: If true, sort tiles to move by distance from (x,y)

        Sorting tiles by distance makes the move look nicer when moving
        interactively, but it's pointless for non-interactive moves.

        """
        object.__init__(self)
        self.surface = surface
        self.snapshot = surface.save_snapshot()
        self.chunks = self.snapshot.tiledict.keys()
        self.sort = sort
        tx = x // N
        ty = y // N
        self.start_pos = (x, y)
        if self.sort:
            manhattan_dist = lambda p: abs(tx - p[0]) + abs(ty - p[1])
            self.chunks.sort(key=manhattan_dist)
        # High water mark of chunks processed so far.
        # This is reset on every call to update().
        self.chunks_i = 0
        # Tile state tracking for individual update cycles
        self.written = set()
        self.blank_queue = []
        # Tile offsets which we'll be applying,
        # initially the move is zero.
        self.slices_x = calc_translation_slices(0)
        self.slices_y = calc_translation_slices(0)
コード例 #2
0
    def __init__(self, surface, x, y, sort=True):
        """Starts the move, recording state in the Move object

        :param x: Where to start, model X coordinate
        :param y: Where to start, model Y coordinate
        :param sort: If true, sort tiles to move by distance from (x,y)

        Sorting tiles by distance makes the move look nicer when moving
        interactively, but it's pointless for non-interactive moves.

        """
        object.__init__(self)
        self.surface = surface
        self.snapshot = surface.save_snapshot()
        self.chunks = self.snapshot.tiledict.keys()
        self.sort = sort
        tx = x // N
        ty = y // N
        self.start_pos = (x, y)
        if self.sort:
            manhattan_dist = lambda p: abs(tx - p[0]) + abs(ty - p[1])
            self.chunks.sort(key=manhattan_dist)
        # High water mark of chunks processed so far.
        # This is reset on every call to update().
        self.chunks_i = 0
        # Tile state tracking for individual update cycles
        self.written = set()
        self.blank_queue = []
        # Tile offsets which we'll be applying,
        # initially the move is zero.
        self.slices_x = calc_translation_slices(0)
        self.slices_y = calc_translation_slices(0)
コード例 #3
0
 def __init__(self,
              surface,
              filename,
              rect,
              alpha,
              single_tile_pattern=False,
              save_srgb_chunks=False,
              **kwargs):
     super(PNGFileUpdateTask, self).__init__()
     self._final_filename = filename
     # Sizes. Save at least one tile to allow empty docs to be written
     if not rect:
         rect = surface.get_bbox()
     x, y, w, h = rect
     if w == 0 or h == 0:
         x, y, w, h = (0, 0, 1, 1)
         rect = (x, y, w, h)
     # Snapshot and recreate
     clone_surface = Surface(
         looped=surface.looped,
         looped_size=surface.looped_size,
     )
     clone_surface.load_snapshot(surface.save_snapshot())
     # Open a tempfile for writing
     tmp_filename = filename + ".tmp"
     if os.path.exists(tmp_filename):
         os.unlink(tmp_filename)
     tmp_fp = open(tmp_filename, "wb")
     self._png_writer = mypaintlib.ProgressivePNGWriter(
         tmp_fp,
         w,
         h,
         alpha,
         save_srgb_chunks,
     )
     self._tmp_filename = tmp_filename
     self._tmp_fp = tmp_fp
     # What to write
     self._strips_iter = lib.surface.scanline_strips_iter(
         clone_surface,
         rect,
         alpha=alpha,
         single_tile_pattern=single_tile_pattern,
         **kwargs)
     logger.debug("autosave: scheduled update of %r", self._final_filename)
コード例 #4
0
ファイル: tiledsurface.py プロジェクト: vendettaboom/mypaint
 def __init__(self, surface, filename, rect, alpha,
              single_tile_pattern=False,
              save_srgb_chunks=False,
              **kwargs):
     super(PNGFileUpdateTask, self).__init__()
     self._final_filename = filename
     # Sizes. Save at least one tile to allow empty docs to be written
     if not rect:
         rect = surface.get_bbox()
     x, y, w, h = rect
     if w == 0 or h == 0:
         x, y, w, h = (0, 0, 1, 1)
         rect = (x, y, w, h)
     # Snapshot and recreate
     clone_surface = Surface(
         looped=surface.looped,
         looped_size=surface.looped_size,
     )
     clone_surface.load_snapshot(surface.save_snapshot())
     # Open a tempfile for writing
     tmp_filename = filename + ".tmp"
     if os.path.exists(tmp_filename):
         os.unlink(tmp_filename)
     tmp_fp = open(tmp_filename, "wb")
     self._png_writer = mypaintlib.ProgressivePNGWriter(
         tmp_fp,
         w, h,
         alpha,
         save_srgb_chunks,
     )
     self._tmp_filename = tmp_filename
     self._tmp_fp = tmp_fp
     # What to write
     self._strips_iter = lib.surface.scanline_strips_iter(
         clone_surface, rect, alpha=alpha,
         single_tile_pattern=single_tile_pattern,
         **kwargs
     )
     logger.debug("autosave: scheduled update of %r", self._final_filename)