File size: 2,965 Bytes
f2dbf59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from comfy.utils import common_upscale

from .utils.mask_utils import mask_floor, mask_unsqueeze

_CATEGORY = 'fnodes/misc'


class DisplayAny:
    def __init__(self):
        pass

    @classmethod
    def INPUT_TYPES(cls):
        return {
            'required': {
                'input': (('*', {})),
            },
        }

    @classmethod
    def VALIDATE_INPUTS(cls, input_types):
        return True

    RETURN_TYPES = ('STRING',)
    FUNCTION = 'execute'
    OUTPUT_NODE = True

    CATEGORY = _CATEGORY

    def execute(self, input):
        text = str(input)

        return {'ui': {'text': text}, 'result': (text,)}


class PrimitiveText:
    def __init__(self):
        pass

    @classmethod
    def INPUT_TYPES(cls):
        return {
            'required': {
                'string': ('STRING', {'multiline': True, 'default': ''}),
            }
        }

    CATEGORY = _CATEGORY
    RETURN_TYPES = ('STRING',)
    RETURN_NAMES = ('text',)

    FUNCTION = 'execute'

    def execute(self, string=''):
        return (string,)


class FillMaskedImageArea:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            'required': {
                'image': ('IMAGE',),
                'mask': ('MASK',),
                'fill': ('FLOAT', {'default': 0, 'min': 0, 'max': 1, 'step': 0.01}),
            }
        }

    RETURN_TYPES = ('IMAGE',)
    CATEGORY = _CATEGORY
    FUNCTION = 'fill'
    DESCRIPTION = '填充图像区域'

    def fill(self, image, mask, fill):
        image = image.detach().clone()
        alpha = mask_unsqueeze(mask_floor(mask))
        assert alpha.shape[0] == image.shape[0], 'Image and mask batch size does not match'

        if image.shape[1] != mask.shape[1] or image.shape[2] != mask.shape[2]:
            samples = image.movedim(-1, 1)
            image = common_upscale(samples, mask.shape[2], mask.shape[1], 'lanczos', 'disabled')
            image = image.movedim(1, -1)

        m = (1.0 - alpha).squeeze(1)
        for i in range(3):
            image[:, :, :, i] -= fill
            image[:, :, :, i] *= m
            image[:, :, :, i] += fill

        return (image,)


class Seed:
    @classmethod
    def INPUT_TYPES(cls):
        return {'required': {'seed': ('INT', {'default': 0, 'min': 0, 'max': 0xFFFFFFFFFFFFFFFF})}}

    RETURN_TYPES = ('FLOAT', 'INT')
    RETURN_NAMES = ('seed_float', 'seed_int')
    FUNCTION = 'execute'

    CATEGORY = _CATEGORY

    def execute(self, seed):
        return (float(seed), int(seed))


MISC_CLASS_MAPPINGS = {
    'DisplayAny-': DisplayAny,
    'PrimitiveText-': PrimitiveText,
    'FillMaskedImageArea-': FillMaskedImageArea,
    'Seed-': Seed,
}

MISC_NAME_MAPPINGS = {
    'DisplayAny-': 'Display Any',
    'PrimitiveText-': 'Primitive Text',
    'FillMaskedImageArea-': 'Fill Masked Image Area',
    'Seed-': 'Seed',
}