|
import os,io |
|
from PIL import Image, ImageOps |
|
import numpy as np |
|
import torch |
|
import folder_paths |
|
import base64 |
|
from io import BytesIO |
|
|
|
|
|
|
|
def tensor2pil(image): |
|
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)) |
|
|
|
|
|
def base64_save(base64_data): |
|
|
|
data = base64_data.split(",")[1] |
|
decoded_data = base64.b64decode(data) |
|
|
|
|
|
image = Image.open(BytesIO(decoded_data)) |
|
|
|
image,mask=load_image(image) |
|
return (image,mask) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_image(i,white_bg=False): |
|
|
|
image = i.convert("RGB") |
|
|
|
image = np.array(image).astype(np.float32) / 255.0 |
|
image = torch.from_numpy(image)[None,] |
|
if 'A' in i.getbands(): |
|
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0 |
|
mask = 1. - torch.from_numpy(mask) |
|
if white_bg==True: |
|
nw = mask.unsqueeze(0).unsqueeze(-1).repeat(1, 1, 1, 3) |
|
|
|
image[nw == 1] = 1.0 |
|
else: |
|
mask = torch.zeros((64,64), dtype=torch.float32, device="cpu") |
|
return (image,mask) |
|
|
|
|
|
class ScreenShareNode: |
|
@classmethod |
|
def INPUT_TYPES(s): |
|
return { "required":{ |
|
"image_base64": ("CHEESE",), |
|
"refresh_rate": ("INT", {"default": 500, "min": 0,"step": 50, "max": 0xffffffffffffffff}), |
|
}, |
|
"optional":{ |
|
"prompt": ("PROMPT",), |
|
"slide": ("SLIDE",), |
|
"seed": ("SEED",), |
|
|
|
|
|
} } |
|
|
|
RETURN_TYPES = ('IMAGE','STRING','FLOAT',"INT") |
|
RETURN_NAMES = ("current frame (image)","prompt","denoise (float)","seed (int)") |
|
FUNCTION = "run" |
|
|
|
CATEGORY = "♾️Mixlab/Screen" |
|
|
|
|
|
OUTPUT_IS_LIST = (False,False,False,False) |
|
|
|
|
|
def run(self,image_base64,refresh_rate ,prompt,slide,seed): |
|
im,mask=base64_save(image_base64) |
|
|
|
return {"ui":{"refresh_rate": [refresh_rate]},"result": (im,prompt,slide,seed,)} |
|
|
|
|
|
class FloatingVideo: |
|
@classmethod |
|
def INPUT_TYPES(s): |
|
return { "required":{ |
|
"image": ("IMAGE",) |
|
}, } |
|
|
|
|
|
RETURN_TYPES = () |
|
|
|
OUTPUT_NODE = True |
|
FUNCTION = "run" |
|
|
|
CATEGORY = "♾️Mixlab/Screen" |
|
|
|
|
|
|
|
|
|
|
|
def run(self,image): |
|
|
|
results = list() |
|
|
|
for im in image: |
|
im=tensor2pil(im) |
|
|
|
|
|
buffered = BytesIO() |
|
im.save(buffered, format="JPEG") |
|
image_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8") |
|
|
|
results.append(image_base64) |
|
|
|
|
|
return { "ui": { "images_": results } } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|