diff --git a/sdppp_python/comfy/nodes.py b/sdppp_python/comfy/nodes.py index c6fa98c..a89a1ad 100644 --- a/sdppp_python/comfy/nodes.py +++ b/sdppp_python/comfy/nodes.py @@ -5,7 +5,7 @@ import json from ..protocols.photoshop import ProtocolPhotoshop from PIL import Image, ImageOps, ImageSequence, ImageFile, ImageDraw -def sdppp_is_changed(sdppp, sdppp_arg, document_arg, key = ''): +def sdppp_is_changed(sdppp, sdppp_arg, document_arg, key): document_instance_id = None try: sdppp_values = json.loads(sdppp_arg) @@ -14,10 +14,7 @@ def sdppp_is_changed(sdppp, sdppp_arg, document_arg, key = ''): document_instance_id = document['instance_id'] else: document_instance_id = sdppp_values['document']['instance_id'] - if key == '': - return f"{sdppp.ppp_instances[document_instance_id].store.data['canvasStateID']}_{sdppp.ppp_instances[document_instance_id].store.data['selectionStateID']}" - else: - return sdppp.ppp_instances[document_instance_id].store.data[key] + return sdppp.ppp_instances[document_instance_id].store.data[key] except Exception as e: print('=============sdppp_is_changed error============', e) # print(sdppp_arg) diff --git a/sdppp_python/comfy/nodes_legacy.py b/sdppp_python/comfy/nodes_legacy.py index a0094a7..90a7166 100644 --- a/sdppp_python/comfy/nodes_legacy.py +++ b/sdppp_python/comfy/nodes_legacy.py @@ -8,7 +8,7 @@ from PIL import Image, ImageOps, ImageSequence, ImageFile from nodes import CLIPTextEncode, ConditioningConcat, ConditioningSetMask from ..apis import addImageCache from ..protocols.photoshop import ProtocolPhotoshop -from .nodes import check_linked_in_prompt, sdppp_get_prompt_item_from_list, convert_mask_to_boundary, SDPPPOptional, sdppp_is_changed +from .nodes import check_linked_in_prompt, sdppp_get_prompt_item_from_list, convert_mask_to_boundary, SDPPPOptional def define_comfyui_nodes_legacy(sdppp): def call_async_func_in_server_thread(coro, dontwait = False): @@ -186,11 +186,13 @@ def define_comfyui_nodes_legacy(sdppp): def send_image(self, unique_id, prompt, images, layer_or_group, bound="", document="", **kwargs): sdppp.has_ps_instance(throw_error=True) + total_start_time = time.time() linked_style, document = parse_params(unique_id, prompt, layer_or_group, document) sdppp_arg = kwargs['sdppp'] sdppp_arg_item = json.loads(sdppp_get_prompt_item_from_list(sdppp_arg, 0)) + is_local = sdppp_arg_item.get('isLocal', False) # dont check here, some python cannot read the data in this thread. # if document['instance_id'] not in sdppp.ppp_instances: # raise ValueError(f'Photoshop instance {document["instance_id"]} not found') @@ -216,19 +218,29 @@ def define_comfyui_nodes_legacy(sdppp): if img.mode != "RGBA": img = img.convert("RGBA") - # 使用BytesIO而不是tobytes来获取PNG数据 - buffer = BytesIO() - img.save(buffer, format="PNG") - png_data = buffer.getvalue() + if (is_local): + buffer = img.tobytes('raw') + blob = { + 'buffer': buffer, + 'width': img.width, + 'height': img.height + } + + else: + buffer = BytesIO() + img.save(buffer, format="PNG") + png_data = buffer.getvalue() + blob = { + 'pngData': png_data, + } params.append({ 'layer_identify': item_layer, 'boundary': convert_mask_to_boundary(item_bound), - 'image_blob': { - 'pngData': png_data - } + 'image_blob': blob }) + start_time = time.time() call_async_func_in_server_thread(ProtocolPhotoshop.send_images( instance_id=document['instance_id'], document_identify=document['identify'], @@ -236,8 +248,8 @@ def define_comfyui_nodes_legacy(sdppp): layer_identifies=[p['layer_identify'] for p in params], boundaries=[p['boundary'] for p in params], new_layer_name=sdppp_arg_item['lastOpenedWorkflow'] - ), True) - ret_layer_or_group = None if not linked_style else layer_or_group + )) + ret_layer_or_group = [None] if not linked_style else layer_or_group return (ret_layer_or_group,) class CLIPTextEncodePSRegional: diff --git a/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts b/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts index d588fa8..31506b9 100644 --- a/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts +++ b/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts @@ -128,6 +128,7 @@ export class SendImageToLayerNode extends SDPPPDownloadableNode { this.node.inputs[0].label = i18n(this.node.inputs[0].name) this.node.inputs[1].label = i18n(this.node.inputs[1].name) this.node.inputs[2].label = i18n(this.node.inputs[2].name) + this.node.outputs[0].label = i18n(this.node.outputs[0].name) } private layerLinked: boolean = false; protected inputConnectionChange(index: number, connected: boolean) { diff --git a/typescripts/modules/comfy/src/comfy-nodes/nodes.mts b/typescripts/modules/comfy/src/comfy-nodes/nodes.mts index f1b754d..e1e793d 100644 --- a/typescripts/modules/comfy/src/comfy-nodes/nodes.mts +++ b/typescripts/modules/comfy/src/comfy-nodes/nodes.mts @@ -39,6 +39,7 @@ export class GetLayersInGroupNode extends SDPPPNodeWithInput implements NodeWith super.update(); this.node.inputs.forEach((i: any) => i.label = i18n(i.name)); this.node.outputs.forEach((i: any) => i.label = i18n(i.name)); + this.node.widgets[0].label = i18n(this.node.widgets[0].name) } } export class GetLinkedLayersNode extends SDPPPNodeWithInput implements NodeWithLayerOutput { @@ -49,6 +50,7 @@ export class GetLinkedLayersNode extends SDPPPNodeWithInput implements NodeWithL super.update(); this.node.inputs.forEach((i: any) => i.label = i18n(i.name)); this.node.outputs.forEach((i: any) => i.label = i18n(i.name)); + this.node.widgets[0].label = i18n(this.node.widgets[0].name) } } @@ -69,6 +71,11 @@ export class GetTextFromLayerNode extends SDPPPDownloadableNode { constructor(node: any) { super(node); } + async update() { + super.update(); + this.node.inputs[0].label = i18n(this.node.inputs[0].name) + this.node.outputs[0] && (this.node.outputs[0].label = i18n(this.node.outputs[0].name)) + } } export class GetDocumentNode extends SDPPPNodeWithInput implements NodeWithDocumentOutput { diff --git a/typescripts/modules/comfy/src/litegraph/fe-widgets.mts b/typescripts/modules/comfy/src/litegraph/fe-widgets.mts index b51c6b9..66def02 100644 --- a/typescripts/modules/comfy/src/litegraph/fe-widgets.mts +++ b/typescripts/modules/comfy/src/litegraph/fe-widgets.mts @@ -333,6 +333,7 @@ export class DownloadWidget extends SDPPPWidget { const val = await documentNode.widgets[0].serializeValue(); try { ret.document = JSON.parse(val); + ret.isLocal = pagePhotoshopStoreMap.getStore(ret.document.instance_id)?.data.isLocal || false; } catch (e) { return ''; } diff --git a/typescripts/modules/photoshop-internal b/typescripts/modules/photoshop-internal index a1b8ec5..1cde498 160000 --- a/typescripts/modules/photoshop-internal +++ b/typescripts/modules/photoshop-internal @@ -1 +1 @@ -Subproject commit a1b8ec54d9a5d6c132534c325679f3262052c06c +Subproject commit 1cde4981dfaff07b04adf87b4269795b6e0fa14a diff --git a/typescripts/src/socket/PhotoshopCalleeInterface.mts b/typescripts/src/socket/PhotoshopCalleeInterface.mts index ccd7586..eac8682 100644 --- a/typescripts/src/socket/PhotoshopCalleeInterface.mts +++ b/typescripts/src/socket/PhotoshopCalleeInterface.mts @@ -46,9 +46,14 @@ export interface getImageActions { } // =========== sendImages Interfaces =========== -export interface ImageBlobParams { +export type ImageBlobParams = { components: number, pngData: Blob +} | { + components: number, + buffer: Uint8Array, + width: number, + height: number } export interface sendImagesActions { diff --git a/typescripts/src/store/photoshop.mts b/typescripts/src/store/photoshop.mts index 0c4e25f..1271c80 100644 --- a/typescripts/src/store/photoshop.mts +++ b/typescripts/src/store/photoshop.mts @@ -23,8 +23,9 @@ export interface PhotoshopDataDocument { [id: number]: DocumentData } export interface PhotoshopStoreData { - uname: string // userpath name + uname: string // random string instance name comfyUserToken: string + isLocal: boolean activeDocumentID: number // active document name documents: PhotoshopDataDocument @@ -40,6 +41,7 @@ export class PhotoshopStore extends MainStore { super(data || { uname: '', comfyUserToken: '', + isLocal: false, activeDocumentID: 0, documents: {}, @@ -51,6 +53,11 @@ export class PhotoshopStore extends MainStore { this._version = version || 0; } + @StoreMutation + setIsLocal(isLocal: boolean) { + this._data.isLocal = isLocal; + } + @StoreMutation setUName(uid: string) { this._data.uname = 'PS_' + uid;