image quality

This commit is contained in:
zombieyang
2025-04-28 21:24:51 +08:00
parent 4010cd6527
commit 900ef4175b
9 changed files with 63 additions and 33 deletions
+20 -5
View File
@@ -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))
+3 -2
View File
@@ -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
+1 -1
View File
@@ -1 +1 @@
502
504
@@ -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) {
+3 -1
View File
@@ -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();
}
}
+1
View File
@@ -87,6 +87,7 @@ export default {
'sample .psd': '示例.psd',
'mask': '遮罩',
'name': '名称',
'quality': '图像质量',
// photoshop UI
'timeout': '超时',
@@ -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
}
}
+11 -11
View File
@@ -63,17 +63,17 @@ export function PhotoshopCallerSocket(SocketClass: SocketConstructor<Socket>) {
});
}
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) => {
@@ -3,7 +3,7 @@ import { PhotoshopCalleeActions } from "./PhotoshopCalleeInterface.mjs";
export interface PhotoshopCaller {
importPSDDataURLFromPhotoshop(sid: string, document_identify: string, fromSSID: string): Promise<string>;
exportPSDDataURLToPhotoshop(sid: string, document_identify: string, dataURL: string, fromSSID: string): Promise<void>;
getImage(sid: string, payload: PhotoshopCalleeActions['getImage']['params']): Promise<any>;
// getImage(sid: string, payload: PhotoshopCalleeActions['getImage']['params']): Promise<any>;
sendImage(sid: string, payload: PhotoshopCalleeActions['sendImages']['params']): Promise<any>;
getSpecialIdentifierValue(sid: string, payload: PhotoshopCalleeActions['getSpecialIdentifierValue']['params']): Promise<any>;
}