send to specific bounds
This commit is contained in:
@@ -6,7 +6,7 @@ except ImportError:
|
||||
print("SD-PPP: fastapi not found")
|
||||
try:
|
||||
from aiohttp import web
|
||||
from .data import set_sd_document_data, set_special_get_bound_layer_options, set_special_get_layer_options, set_special_send_layer_options
|
||||
from .data import set_sd_document_data, set_special_get_bound_layer_options, set_special_get_layer_options, set_special_send_layer_options, set_special_send_bound_layer_options
|
||||
except ImportError:
|
||||
print("SD-PPP: aiohttp not found")
|
||||
|
||||
@@ -181,4 +181,5 @@ def registerSocketEvents(sdppp, sio):
|
||||
set_sd_document_data(data['document_data'])
|
||||
set_special_get_layer_options(data['special_get_layer_options'])
|
||||
set_special_get_bound_layer_options(data['special_get_bound_layer_options'])
|
||||
set_special_send_layer_options(data['special_send_layer_options'])
|
||||
set_special_send_layer_options(data['special_send_layer_options'])
|
||||
set_special_send_bound_layer_options(data['special_send_bound_layer_options'])
|
||||
+20
-15
@@ -3,7 +3,7 @@ import time
|
||||
from nodes import LoadImage
|
||||
from PIL import Image
|
||||
from .apis import addImageCache
|
||||
from .data import get_sd_document_data, get_special_get_bound_layer_options, get_special_get_layer_options, get_special_send_layer_options
|
||||
from .data import get_sd_document_data, get_special_get_bound_layer_options, get_special_get_layer_options, get_special_send_layer_options, get_special_send_bound_layer_options
|
||||
|
||||
def define_comfyui_nodes(sdppp):
|
||||
def validate_sdppp():
|
||||
@@ -45,17 +45,17 @@ def define_comfyui_nodes(sdppp):
|
||||
return validate_sdppp()
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(self, layer_or_group, use_layer_bounds):
|
||||
def IS_CHANGED(self, layer_or_group, bounds):
|
||||
if not sdppp.has_ps_instance():
|
||||
return np.random.rand()
|
||||
else:
|
||||
photoshopInstance = sdppp.get_ps_instance()
|
||||
is_changed, history_state_id = call_async_func_in_server_thread(
|
||||
photoshopInstance.check_layer_bounds_combo_changed(layer, use_layer_bounds)
|
||||
photoshopInstance.check_layer_bounds_combo_changed(layer, bounds)
|
||||
)
|
||||
if is_changed and history_state_id is None:
|
||||
return np.random.rand()
|
||||
photoshopInstance.update_comfyui_last_value(layer, use_layer_bounds, history_state_id)
|
||||
photoshopInstance.update_comfyui_last_value(layer, bounds, history_state_id)
|
||||
return history_state_id
|
||||
|
||||
@classmethod
|
||||
@@ -64,14 +64,13 @@ def define_comfyui_nodes(sdppp):
|
||||
document_data_keys = document_data.keys()
|
||||
list_of_list_of_layers = [document_data[key]['layers'] for key in document_data_keys]
|
||||
return {
|
||||
"required": {},
|
||||
"optional": {
|
||||
"required": {
|
||||
"document": (list(document_data_keys), {"default": None}),
|
||||
"layer_or_group": ([
|
||||
*get_special_get_layer_options(),
|
||||
*(item['name'] for sublist in list_of_list_of_layers for item in sublist)
|
||||
], {"default": None}),
|
||||
"use_layer_bounds": ([
|
||||
"bounds": ([
|
||||
*get_special_get_bound_layer_options(),
|
||||
*(item['name'] for sublist in list_of_list_of_layers for item in sublist)
|
||||
], {"default": None}),
|
||||
@@ -79,17 +78,17 @@ def define_comfyui_nodes(sdppp):
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "MASK", "FLOAT")
|
||||
RETURN_NAMES = ("image_out", "mask_out", "layer_opacity")
|
||||
RETURN_NAMES = ("rgb_out", "alpha_out", "layer_opacity")
|
||||
FUNCTION = "get_image"
|
||||
CATEGORY = "Photoshop"
|
||||
|
||||
def get_image(self, document, layer_or_group, use_layer_bounds):
|
||||
def get_image(self, document, layer_or_group, bounds):
|
||||
if validate_sdppp() is not True:
|
||||
raise ValueError('Photoshop is not connected')
|
||||
photoshopInstance = sdppp.get_ps_instance()
|
||||
|
||||
image_id, layer_opacity = call_async_func_in_server_thread(
|
||||
photoshopInstance.get_image(document_identify=document, layer_identify=layer_or_group, bound_layer_identify=use_layer_bounds)
|
||||
photoshopInstance.get_image(document_identify=document, layer_identify=layer_or_group, bounds_identify=bounds)
|
||||
)
|
||||
|
||||
loadImage = LoadImage()
|
||||
@@ -109,8 +108,7 @@ def define_comfyui_nodes(sdppp):
|
||||
document_data_keys = document_data.keys()
|
||||
list_of_list_of_layers = [document_data[key]['layers'] for key in document_data_keys]
|
||||
return {
|
||||
"required": {},
|
||||
"optional": {
|
||||
"required": {
|
||||
"images": ("IMAGE", ),
|
||||
# documents_options
|
||||
"document": (list(document_data), {"default": None}),
|
||||
@@ -118,6 +116,10 @@ def define_comfyui_nodes(sdppp):
|
||||
*get_special_send_layer_options(),
|
||||
*(item['name'] for sublist in list_of_list_of_layers for item in sublist)
|
||||
], {"default": None}),
|
||||
"bounds": ([
|
||||
*get_special_send_bound_layer_options(),
|
||||
*(item['name'] for sublist in list_of_list_of_layers for item in sublist)
|
||||
], {"default": None}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,19 +128,22 @@ def define_comfyui_nodes(sdppp):
|
||||
CATEGORY = "Photoshop"
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def send_image(self, images, document, layer_or_group):
|
||||
def send_image(self, images, document, layer_or_group, bounds):
|
||||
if validate_sdppp() is not True:
|
||||
raise ValueError('Photoshop is not connected')
|
||||
photoshopInstance = sdppp.get_ps_instance()
|
||||
|
||||
image_ids = []
|
||||
for (batch_number, image) in enumerate(images):
|
||||
for (batch_index, image) in enumerate(images):
|
||||
i = 255. * image.cpu().numpy()
|
||||
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
||||
image_ids.append(addImageCache(img))
|
||||
|
||||
call_async_func_in_server_thread(photoshopInstance.send_images(
|
||||
image_ids=image_ids, document_identify=document, layer_identify=layer_or_group
|
||||
image_ids=image_ids,
|
||||
document_identify=document,
|
||||
layer_identify=layer_or_group,
|
||||
bounds_identify=bounds
|
||||
), True)
|
||||
|
||||
return (None,)
|
||||
|
||||
@@ -27,3 +27,10 @@ def set_special_send_layer_options(data):
|
||||
special_send_layer_options = data
|
||||
def get_special_send_layer_options():
|
||||
return special_send_layer_options
|
||||
|
||||
special_send_bound_layer_options = []
|
||||
def set_special_send_bound_layer_options(data):
|
||||
global special_send_bound_layer_options
|
||||
special_send_bound_layer_options = data
|
||||
def get_special_send_bound_layer_options():
|
||||
return special_send_bound_layer_options
|
||||
@@ -8,9 +8,11 @@ class PhotoshopInstance:
|
||||
self.layers = []
|
||||
self.reset_change_tracker()
|
||||
|
||||
async def get_image(self, document_identify, layer_identify, bound_layer_identify):
|
||||
async def get_image(self, document_identify, layer_identify, bounds_identify):
|
||||
result = await self.sdppp.sio.call('s_get_image', data={
|
||||
'document_identify': document_identify, 'layer_identify': layer_identify, 'bound_layer_identify': bound_layer_identify
|
||||
'document_identify': document_identify,
|
||||
'layer_identify': layer_identify,
|
||||
'bounds_identify': bounds_identify
|
||||
}, to=self.sid)
|
||||
if not result:
|
||||
return None, None
|
||||
@@ -21,9 +23,12 @@ class PhotoshopInstance:
|
||||
|
||||
return result['upload_name'], result['layer_opacity']
|
||||
|
||||
async def send_images(self, image_ids, document_identify, layer_identify):
|
||||
async def send_images(self, image_ids, document_identify, layer_identify, bounds_identify):
|
||||
result = await self.sdppp.sio.call('s_send_images', data={
|
||||
'image_ids': image_ids, 'document_identify': document_identify, 'layer_identify': layer_identify
|
||||
'image_ids': image_ids,
|
||||
'document_identify': document_identify,
|
||||
'layer_identify': layer_identify,
|
||||
'bounds_identify': bounds_identify
|
||||
}, to=self.sid)
|
||||
# await self._update_history_state_id_after_internal_change()
|
||||
return result
|
||||
@@ -49,8 +54,8 @@ class PhotoshopInstance:
|
||||
current_id = await self.get_active_history_state_id()
|
||||
return self.get_img_state_id != current_id and self.get_img_state_id < current_id
|
||||
|
||||
async def check_layer_bounds_combo_changed(self, layer, use_layer_bounds):
|
||||
layer_bounds_combo = f"{layer}{use_layer_bounds}"
|
||||
async def check_layer_bounds_combo_changed(self, layer, bounds):
|
||||
layer_bounds_combo = f"{layer}{bounds}"
|
||||
layer_bounds_history_state_id = self.change_tracker.get(layer_bounds_combo, None)
|
||||
if layer_bounds_history_state_id is None:
|
||||
return True
|
||||
@@ -63,8 +68,8 @@ class PhotoshopInstance:
|
||||
|
||||
# have to track this value because comfyui determines if the value is changed by comparing it with the last value.
|
||||
# can't use the real history id because sending images changes the history id, and comfyui will think the value is changed when it's not
|
||||
def update_comfyui_last_value(self, layer, use_layer_bounds, value):
|
||||
layer_bounds_combo = f"{layer}{use_layer_bounds}"
|
||||
def update_comfyui_last_value(self, layer, bounds, value):
|
||||
layer_bounds_combo = f"{layer}{bounds}"
|
||||
self.comfyui_last_value_tracker[layer_bounds_combo] = value
|
||||
|
||||
# need to update history id after internal operation otherwise it might cause infinite change loop
|
||||
@@ -75,8 +80,8 @@ class PhotoshopInstance:
|
||||
self.change_tracker = {k: history_state_id for k, v in self.change_tracker.items() if v == self.get_img_state_id}
|
||||
self.get_img_state_id = history_state_id # it gets into a loop if get img state is not updated
|
||||
|
||||
async def _update_layer_bounds_history_state_id(self, layer, use_layer_bounds):
|
||||
layer_bounds_combo = f"{layer}{use_layer_bounds}"
|
||||
async def _update_layer_bounds_history_state_id(self, layer, bounds):
|
||||
layer_bounds_combo = f"{layer}{bounds}"
|
||||
latest_state_id = await self.get_active_history_state_id()
|
||||
self.change_tracker[layer_bounds_combo] = latest_state_id
|
||||
return latest_state_id
|
||||
|
||||
Reference in New Issue
Block a user