diff --git a/sdppp_python/comfy/nodes_legacy.py b/sdppp_python/comfy/nodes_legacy.py index 35233a1..b10c63e 100644 --- a/sdppp_python/comfy/nodes_legacy.py +++ b/sdppp_python/comfy/nodes_legacy.py @@ -68,6 +68,7 @@ def define_comfyui_nodes_legacy(sdppp): }, "optional": SDPPPOptional({ "bound": ('MASK', {"default": None}), + "quality": ('FLOAT', {"default": 100.0, "min": 0.0, "max": 100.0, "step": 1.0, "forceInput": True}), }, { # compat combo selection type "document": ("STRING", {"default": "", "sdppp_type": "DOCUMENT_nameid"}), @@ -79,7 +80,7 @@ def define_comfyui_nodes_legacy(sdppp): } } - def get_image(self, unique_id, prompt, layer_or_group, bound="", document="", **kwargs): + def get_image(self, unique_id, prompt, layer_or_group, bound="", document="", quality=100.0, **kwargs): sdppp_arg = kwargs['sdppp'] sdppp.has_ps_instance(throw_error=True) @@ -104,19 +105,33 @@ def define_comfyui_nodes_legacy(sdppp): document_identify=document['identify'], layer_identify=item_layer, boundary=convert_mask_to_boundary(item_bound), - max_wh=sdppp_arg_item['ps_maxGetImageWH'] + max_wh=sdppp_arg_item['ps_maxGetImageWH'], + quality=sdppp_get_prompt_item_from_list(quality, i) ) ) # change to use result['pngData']. a .png data - (output_image, output_mask) = self._load_image_from_png( - result['pngData'] - ) + # (output_image, output_mask) = self._load_image_from_png( + # result['pngData'] + # ) + output_image = self._load_image_from_jpeg(result['jpegData']) + (_, output_mask) = self._load_image_from_png(result['alphaData']) res_image.append(output_image) res_mask.append(output_mask) return (res_image, res_mask,) + def _load_image_from_jpeg(self, jpeg_data): + # Load the JPEG data using PIL + image = Image.open(BytesIO(jpeg_data)) + + # Convert to RGB for the output image + rgb_image = image.convert("RGB") + rgb_array = np.array(rgb_image).astype(np.float32) / 255.0 + output_image = torch.from_numpy(rgb_array)[None,] + return output_image + + def _load_image_from_png(self, png_data): # Load the PNG data using PIL image = Image.open(BytesIO(png_data)) diff --git a/sdppp_python/protocols/photoshop.py b/sdppp_python/protocols/photoshop.py index 7262743..258c09b 100644 --- a/sdppp_python/protocols/photoshop.py +++ b/sdppp_python/protocols/photoshop.py @@ -17,7 +17,7 @@ class ProtocolPhotoshop: cls.sdpppServer = sdpppServer @classmethod - async def get_image(cls, instance_id, document_identify, layer_identify, boundary, max_wh=60606): + async def get_image(cls, instance_id, document_identify, layer_identify, boundary, max_wh=60606, quality=100.0): ppp_instance = cls.sdpppServer.ppp_instances[instance_id] result = await protocol_call(ppp_instance, 'B_photoshop', data={ 'action': 'getImage', @@ -25,7 +25,8 @@ class ProtocolPhotoshop: 'document_identify': document_identify, 'layer_identify': layer_identify, 'boundary': boundary, - 'max_wh': max_wh + 'max_wh': max_wh, + 'quality': quality } }) return result diff --git a/sdppp_python/version.txt b/sdppp_python/version.txt index cc5027e..3091e8e 100644 --- a/sdppp_python/version.txt +++ b/sdppp_python/version.txt @@ -1 +1 @@ -502 +504 diff --git a/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts b/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts index 68910df..027e0c1 100644 --- a/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts +++ b/typescripts/modules/comfy/src/comfy-nodes/legacy-nodes.mts @@ -20,13 +20,13 @@ export class GetImageFromLayerNode extends SDPPPDownloadableNode { documentWidgetInNode: documentWidget, extraOptions: SpeicialIDManager.getSpecialLayerForGet() }); + super(node); this.documentWidget = documentWidget this.layerWidget = layerWidget - this.node.widgets[0] = documentWidget.widget - this.node.widgets[1] = layerWidget.widget - + this.node.widgets[1] = documentWidget.widget + this.node.widgets[2] = layerWidget.widget } protected onConfigure(nodeData: any): void { if (!nodeData.properties['sdppp-version']) { @@ -54,6 +54,10 @@ export class GetImageFromLayerNode extends SDPPPDownloadableNode { this.node.widgets[0].value = nodeData.widgets_values[1]; this.node.widgets[1].value = nodeData.widgets_values[2]; + } else if (+nodeData.properties['sdppp-version'] < 504) { + this.node.widgets[0].value = 100; + this.node.widgets[1].value = nodeData.widgets_values[0]; + this.node.widgets[2].value = nodeData.widgets_values[1]; } super.onConfigure(nodeData); } @@ -65,14 +69,18 @@ export class GetImageFromLayerNode extends SDPPPDownloadableNode { this.documentWidget.update(); this.layerWidget.update(); super.update(); - if (!this.node.widgets[0].label) - this.node.widgets[0].label = i18n(this.node.widgets[0].name) - if (!this.node.widgets[1].label) - this.node.widgets[1].label = i18n(this.node.widgets[1].name) - this.node.inputs[0].label = i18n(this.node.inputs[0].name) - this.node.inputs[1].label = i18n(this.node.inputs[1].name) - this.node.outputs[0].label = i18n(this.node.outputs[0].name) - this.node.outputs[1].label = i18n(this.node.outputs[1].name) + this.node.widgets.forEach((i: any) => { + if (i.label) return + try { i.label = i18n(i.name) } catch (e) { } + }) + this.node.inputs.forEach((i: any) => { + if (i.label) return + try { i.label = i18n(i.name) } catch (e) { } + }) + this.node.outputs.forEach((i: any) => { + if (i.label) return + try { i.label = i18n(i.name) } catch (e) { } + }) } private layerLinked: boolean = false; protected inputConnectionChange(index: number, connected: boolean) { diff --git a/typescripts/src/common/socket/Socket.mts b/typescripts/src/common/socket/Socket.mts index a0495da..3a3fc73 100644 --- a/typescripts/src/common/socket/Socket.mts +++ b/typescripts/src/common/socket/Socket.mts @@ -1,8 +1,9 @@ import { io } from 'socket.io-client'; import { __GLOBAL_API_LEVEL__ } from '../version.mjs'; +import { Socket as SocketIOClient } from 'socket.io-client'; export class Socket { - protected readonly socket: any; + protected readonly socket: SocketIOClient; constructor(url: string) { const path = '/' + [url.split('/').slice(3).filter(p => p).join('/'), 'sd-ppp/'].filter(p => p).join('/'); url = url.split('/').slice(0, 3).join('/'); @@ -32,6 +33,7 @@ export class Socket { public close() { this.socket.close(); + this.socket.removeAllListeners(); } } diff --git a/typescripts/src/common/zh-cn.mts b/typescripts/src/common/zh-cn.mts index d2092a3..87a9c8d 100644 --- a/typescripts/src/common/zh-cn.mts +++ b/typescripts/src/common/zh-cn.mts @@ -87,6 +87,7 @@ export default { 'sample .psd': '示例.psd', 'mask': '遮罩', 'name': '名称', + 'quality': '图像质量', // photoshop UI 'timeout': '超时', diff --git a/typescripts/src/socket/PhotoshopCalleeInterface.mts b/typescripts/src/socket/PhotoshopCalleeInterface.mts index 3a663f9..6a2d341 100644 --- a/typescripts/src/socket/PhotoshopCalleeInterface.mts +++ b/typescripts/src/socket/PhotoshopCalleeInterface.mts @@ -36,9 +36,12 @@ export interface getImageActions { layer_identify: string, boundary?: SDPPPBounds, max_wh?: number, + quality?: number, }, result: { - pngData: Uint8Array | null + // pngData: Uint8Array | null, + jpegData: Uint8Array | null, + alphaData: Uint8Array | null } } diff --git a/typescripts/src/socket/PhotoshopCaller.mts b/typescripts/src/socket/PhotoshopCaller.mts index ce841ad..6417150 100644 --- a/typescripts/src/socket/PhotoshopCaller.mts +++ b/typescripts/src/socket/PhotoshopCaller.mts @@ -63,17 +63,17 @@ export function PhotoshopCallerSocket(SocketClass: SocketConstructor) { }); } - public async getImage(sid: string, payload: PhotoshopCalleeActions['getImage']['params']) { - return new Promise((resolve, reject) => { - this.socket.emit('B_photoshop', { - action: 'getImage', - sid: sid, - params: payload - }, (data: any) => { - data && data.error ? reject(new Error(data.error)) : resolve(data); - }); - }); - } + // public async getImage(sid: string, payload: PhotoshopCalleeActions['getImage']['params']) { + // return new Promise((resolve, reject) => { + // this.socket.emit('B_photoshop', { + // action: 'getImage', + // sid: sid, + // params: payload + // }, (data: any) => { + // data && data.error ? reject(new Error(data.error)) : resolve(data); + // }); + // }); + // } public async sendImage(sid: string, payload: PhotoshopCalleeActions['sendImages']['params']) { return new Promise((resolve, reject) => { diff --git a/typescripts/src/socket/PhotoshopCallerInterface.mts b/typescripts/src/socket/PhotoshopCallerInterface.mts index a931bd1..b18c818 100644 --- a/typescripts/src/socket/PhotoshopCallerInterface.mts +++ b/typescripts/src/socket/PhotoshopCallerInterface.mts @@ -3,7 +3,7 @@ import { PhotoshopCalleeActions } from "./PhotoshopCalleeInterface.mjs"; export interface PhotoshopCaller { importPSDDataURLFromPhotoshop(sid: string, document_identify: string, fromSSID: string): Promise; exportPSDDataURLToPhotoshop(sid: string, document_identify: string, dataURL: string, fromSSID: string): Promise; - getImage(sid: string, payload: PhotoshopCalleeActions['getImage']['params']): Promise; + // getImage(sid: string, payload: PhotoshopCalleeActions['getImage']['params']): Promise; sendImage(sid: string, payload: PhotoshopCalleeActions['sendImages']['params']): Promise; getSpecialIdentifierValue(sid: string, payload: PhotoshopCalleeActions['getSpecialIdentifierValue']['params']): Promise; }