Example #1
0
    def __init__(self, src, targ, dx, dy):
        """Initialize with source and target.

        :param dict src: compressed strokemap, RW {xy: bytes}
        :param dict targ: uncompressed tiledict, RW {xy: array}
        :param int dx: x offset for the translation, in pixels
        :param int dy: y offset for the translation, in pixels

        """
        self._src = src
        self._targ = targ
        self._dx = int(dx)
        self._dy = int(dy)
        self._slices_x = tiledsurface.calc_translation_slices(self._dx)
        self._slices_y = tiledsurface.calc_translation_slices(self._dy)
Example #2
0
    def __init__(self, src, targ, dx, dy):
        """Initialize with source and target.

        :param dict src: compressed strokemap, RW {xy: bytes}
        :param dict targ: uncompressed tiledict, RW {xy: array}
        :param int dx: x offset for the translation, in pixels
        :param int dy: y offset for the translation, in pixels

        """
        self._src = src
        self._targ = targ
        self._dx = int(dx)
        self._dy = int(dy)
        self._slices_x = tiledsurface.calc_translation_slices(self._dx)
        self._slices_y = tiledsurface.calc_translation_slices(self._dy)
Example #3
0
 def translate(self, dx, dy):
     """Translate the shape by (dx, dy)"""
     # Finish any previous translations or handling of painted strokes
     self.tasks.finish_all()
     # Source data
     src_strokemap = self.strokemap
     self.strokemap = {}
     slices_x = tiledsurface.calc_translation_slices(int(dx))
     slices_y = tiledsurface.calc_translation_slices(int(dy))
     # Temporary working strokemap, uncompressed
     tmp_strokemap = {}
     # Queue moves
     for (src_tx, src_ty), src in src_strokemap.iteritems():
         self.tasks.add_work(self._translate_tile, src, src_tx, src_ty,
                             slices_x, slices_y, tmp_strokemap)
     # Recompression of any tile can only start after all the above is
     # complete. Luckily the idle-processor does things in order.
     self.tasks.add_work(self._start_tile_recompression, tmp_strokemap)
Example #4
0
    def translate(self, dx, dy):
        """Translate the shape by (dx, dy).
        """
        # Finish any previous translations or handling of painted strokes
        self.tasks.finish_all()
        src_strokemap = self.strokemap
        self.strokemap = {}
        slices_x = tiledsurface.calc_translation_slices(int(dx))
        slices_y = tiledsurface.calc_translation_slices(int(dy))
        tmp_strokemap = {}
        is_integral = len(slices_x) == 1 and len(slices_y) == 1
        for (src_tx, src_ty), src in src_strokemap.iteritems():

            def __translate_tile(src_tx=src_tx, src_ty=src_ty, src=src):
                src = fromstring(zlib.decompress(src), dtype="uint8")
                src.shape = (N, N)
                for (src_x0, src_x1), (tmp_tdx, tmp_x0, tmp_x1) in slices_x:
                    for (src_y0, src_y1), (tmp_tdy, tmp_y0, tmp_y1) in slices_y:
                        tmp_tx = src_tx + tmp_tdx
                        tmp_ty = src_ty + tmp_tdy
                        if is_integral:
                            tmp_strokemap[tmp_tx, tmp_ty] = src
                        else:
                            tmp = tmp_strokemap.get((tmp_tx, tmp_ty), None)
                            if tmp is None:
                                tmp = zeros((N, N), "uint8")
                                tmp_strokemap[tmp_tx, tmp_ty] = tmp
                            tmp[tmp_y0:tmp_y1, tmp_x0:tmp_x1] = src[src_y0:src_y1, src_x0:src_x1]

            self.tasks.add_work(__translate_tile, weight=0.1 / len(src_strokemap))
        # Recompression of any tile can only start after all the above is
        # complete. Luckily the idle-processor does things in order.
        def __start_tile_recompression():
            for (tx, ty), data in tmp_strokemap.iteritems():

                def __recompress_tile(tx=tx, ty=ty, data=data):
                    if not data.any():
                        return
                    data_compressed = zlib.compress(data.tostring())
                    self.strokemap[tx, ty] = data_compressed

                self.tasks.add_work(__recompress_tile, weight=0.1 / len(tmp_strokemap))

        self.tasks.add_work(__start_tile_recompression, weight=0)
Example #5
0
 def translate(self, dx, dy):
     """Translate the shape by (dx, dy)"""
     # Finish any previous translations or handling of painted strokes
     self.tasks.finish_all()
     # Source data
     src_strokemap = self.strokemap
     self.strokemap = {}
     slices_x = tiledsurface.calc_translation_slices(int(dx))
     slices_y = tiledsurface.calc_translation_slices(int(dy))
     # Temporary working strokemap, uncompressed
     tmp_strokemap = {}
     # Queue moves
     for (src_tx, src_ty), src in src_strokemap.iteritems():
         self.tasks.add_work(self._translate_tile, src,
                             src_tx, src_ty, slices_x, slices_y,
                             tmp_strokemap)
     # Recompression of any tile can only start after all the above is
     # complete. Luckily the idle-processor does things in order.
     self.tasks.add_work(self._start_tile_recompression, tmp_strokemap)