diff --git a/packages/stablestudio-ui/src/Comfy/index.tsx b/packages/stablestudio-ui/src/Comfy/index.tsx index f95dfe8..38aab55 100644 --- a/packages/stablestudio-ui/src/Comfy/index.tsx +++ b/packages/stablestudio-ui/src/Comfy/index.tsx @@ -226,10 +226,13 @@ export namespace Comfy { id: inputID, }; - const cropped = await cropImage(image, newInput); - if (!cropped) continue; - - responses.push(cropped); + responses.push({ + id: image.id, + inputID: newInput.id, + created: new Date(), + src: URL.createObjectURL(image.blob), + finishReason: 0, + }); newInputs[inputID] = newInput; } @@ -292,51 +295,3 @@ export namespace Comfy { ); }; } - -function cropImage( - image: StableStudio.StableDiffusionImage, - input: Generation.Image.Input -) { - return new Promise((resolve) => { - const id = image.id; - const blob = image.blob; - if (!blob || !id) return resolve(); - - // crop image to box size - const croppedCanvas = document.createElement("canvas"); - croppedCanvas.width = input.width; - croppedCanvas.height = input.height; - - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const croppedCtx = croppedCanvas.getContext("2d")!; - - const img = new window.Image(); - img.src = URL.createObjectURL(blob); - img.onload = () => { - croppedCtx.drawImage( - img, - 0, - 0, - input.width, - input.height, - 0, - 0, - input.width, - input.height - ); - - croppedCanvas.toBlob((blob) => { - if (blob) { - const objectURL = URL.createObjectURL(blob); - resolve({ - id, - inputID: input.id, - created: new Date(), - src: objectURL, - finishReason: 0, - }); - } - }); - }; - }); -} diff --git a/packages/stablestudio-ui/src/Generation/Image/Output/index.tsx b/packages/stablestudio-ui/src/Generation/Image/Output/index.tsx index 44fcd71..2971e0c 100644 --- a/packages/stablestudio-ui/src/Generation/Image/Output/index.tsx +++ b/packages/stablestudio-ui/src/Generation/Image/Output/index.tsx @@ -63,6 +63,7 @@ export function Output({ outputID, placeholder, divider }: Props) { key={keys("image", images.length, images.length - index)} placeholder={placeholder} image={image} + outputID={output?.id} progress={output?.progress} scale={1} example={ diff --git a/packages/stablestudio-ui/src/Generation/Image/SpecialEffects/index.tsx b/packages/stablestudio-ui/src/Generation/Image/SpecialEffects/index.tsx index 0624adc..c59b9f1 100644 --- a/packages/stablestudio-ui/src/Generation/Image/SpecialEffects/index.tsx +++ b/packages/stablestudio-ui/src/Generation/Image/SpecialEffects/index.tsx @@ -12,6 +12,7 @@ export function SpecialEffects({ example, onClick, input, + output, progress, }: { showing?: boolean; @@ -23,10 +24,26 @@ export function SpecialEffects({ }; onClick?: () => void; input?: ID; + output?: ID; border?: boolean; progress?: number; }) { if (!showing) return null; + const [starting] = useState( + output ? Generation.Image.Output.get(output).requestedAt : undefined + ); + const [eta, setETA] = useState(); + + useEffect(() => { + if (!loading) return; + if (typeof progress !== "number") return; + if (!starting) return; + + const seconds = (Date.now() - starting.getTime()) / 1000; + const eta = seconds / progress - seconds; + setETA(eta); + }, [loading, progress, starting]); + return (
{loading && (typeof progress === "number" ? ( -
- +
+
+ +
+

+ {(eta ?? 0) > 0 && ( + + {Math.round(eta ?? 0)}s + + )} +

) : ( void; onDelete?: () => void; @@ -53,6 +54,7 @@ export function Image({ hideControls, placeholder, progress, + outputID, scale, preserveAspectRatio, @@ -158,6 +160,7 @@ export function Image({ showing={shouldShowSpecialEffects} loading={!placeholder && shouldShowSpecialEffects} progress={progress} + output={outputID} variant={(style.height ?? 512) < 48 ? "small" : undefined} // example={example} // onClick={example ? onTryTemplate : undefined}