summaryrefslogtreecommitdiff
path: root/lib/extensions/png_realistic.py
blob: 24ebce552bf14517ced6c67f72c3f00cc00c1a8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Authors: see git history
#
# Copyright (c) 2024 Authors
# Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details.

import sys

from ..stitch_plan import stitch_groups_to_stitch_plan
from ..svg import render_stitch_plan
from ..threads import ThreadCatalog
from .base import InkstitchExtension
from .png_simple import write_png_output


class PngRealistic(InkstitchExtension):
    def effect(self):
        if not self.get_elements():
            return

        self.metadata = self.get_inkstitch_metadata()
        collapse_len = self.metadata['collapse_len_mm']
        min_stitch_len = self.metadata['min_stitch_len_mm']
        stitch_groups = self.elements_to_stitch_groups(self.elements)
        stitch_plan = stitch_groups_to_stitch_plan(stitch_groups, collapse_len=collapse_len, min_stitch_len=min_stitch_len)
        ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette'])

        layer = render_stitch_plan(self.svg, stitch_plan, True, visual_commands=False, render_jumps=False)

        write_png_output(self.svg, layer)

        # don't let inkex output the SVG!
        sys.exit(0)