forked from extern/easydiffusion
Redo button for image filters, limit undo buffer size to 5
This commit is contained in:
parent
8301cafb37
commit
ed84a23f36
@ -1763,7 +1763,7 @@ body.wait-pause {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
background: var(--background-color3);
|
background: var(--background-color3);
|
||||||
opacity: 0.8;
|
opacity: 0.95;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
padding: 4pt;
|
padding: 4pt;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,7 @@ let imagePreviewContent = document.querySelector("#preview-content")
|
|||||||
let undoButton = document.querySelector("#undo")
|
let undoButton = document.querySelector("#undo")
|
||||||
let undoBuffer = []
|
let undoBuffer = []
|
||||||
const UNDO_LIMIT = 20
|
const UNDO_LIMIT = 20
|
||||||
|
const MAX_IMG_UNDO_ENTRIES = 5
|
||||||
|
|
||||||
let loraModels = []
|
let loraModels = []
|
||||||
|
|
||||||
@ -493,6 +494,7 @@ function showImages(reqBody, res, outputContainer, livePreview) {
|
|||||||
imageSeedLabel.innerText = "Seed: " + req.seed
|
imageSeedLabel.innerText = "Seed: " + req.seed
|
||||||
|
|
||||||
const imageUndoBuffer = []
|
const imageUndoBuffer = []
|
||||||
|
const imageRedoBuffer = []
|
||||||
let buttons = [
|
let buttons = [
|
||||||
{ text: "Use as Input", on_click: onUseAsInputClick },
|
{ text: "Use as Input", on_click: onUseAsInputClick },
|
||||||
[
|
[
|
||||||
@ -510,7 +512,8 @@ function showImages(reqBody, res, outputContainer, livePreview) {
|
|||||||
{ text: "Make Similar Images", on_click: onMakeSimilarClick },
|
{ text: "Make Similar Images", on_click: onMakeSimilarClick },
|
||||||
{ text: "Draw another 25 steps", on_click: onContinueDrawingClick },
|
{ text: "Draw another 25 steps", on_click: onContinueDrawingClick },
|
||||||
[
|
[
|
||||||
{ text: "Undo", on_click: onUndoFilter },
|
{ html: '<i class="fa-solid fa-undo"></i> Undo', on_click: onUndoFilter },
|
||||||
|
{ html: '<i class="fa-solid fa-redo"></i> Redo', on_click: onRedoFilter },
|
||||||
{ text: "Upscale", on_click: onUpscaleClick },
|
{ text: "Upscale", on_click: onUpscaleClick },
|
||||||
{ text: "Fix Faces", on_click: onFixFacesClick },
|
{ text: "Fix Faces", on_click: onFixFacesClick },
|
||||||
],
|
],
|
||||||
@ -527,6 +530,7 @@ function showImages(reqBody, res, outputContainer, livePreview) {
|
|||||||
spinner: spinner,
|
spinner: spinner,
|
||||||
spinnerStatus: spinnerStatus,
|
spinnerStatus: spinnerStatus,
|
||||||
undoBuffer: imageUndoBuffer,
|
undoBuffer: imageUndoBuffer,
|
||||||
|
redoBuffer: imageRedoBuffer,
|
||||||
}
|
}
|
||||||
const createButton = function(btnInfo) {
|
const createButton = function(btnInfo) {
|
||||||
if (Array.isArray(btnInfo)) {
|
if (Array.isArray(btnInfo)) {
|
||||||
@ -559,6 +563,10 @@ function showImages(reqBody, res, outputContainer, livePreview) {
|
|||||||
tools["undoButton"] = newButton
|
tools["undoButton"] = newButton
|
||||||
newButton.classList.add("displayNone")
|
newButton.classList.add("displayNone")
|
||||||
}
|
}
|
||||||
|
if (btnInfo.on_click === onRedoFilter) {
|
||||||
|
tools["redoButton"] = newButton
|
||||||
|
newButton.classList.add("displayNone")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (btnInfo.class !== undefined) {
|
if (btnInfo.class !== undefined) {
|
||||||
@ -690,10 +698,18 @@ function applyInlineFilter(filterName, path, filterParams, img, statusText, tool
|
|||||||
let prevImg = img.src
|
let prevImg = img.src
|
||||||
img.src = e.output[0]
|
img.src = e.output[0]
|
||||||
tools.spinner.classList.add("displayNone")
|
tools.spinner.classList.add("displayNone")
|
||||||
tools.undoButton.classList.remove("displayNone")
|
|
||||||
|
|
||||||
if (prevImg.length > 0) {
|
if (prevImg.length > 0) {
|
||||||
tools.undoBuffer.push(prevImg)
|
tools.undoBuffer.push(prevImg)
|
||||||
|
tools.redoBuffer = []
|
||||||
|
|
||||||
|
if (tools.undoBuffer.length > MAX_IMG_UNDO_ENTRIES) {
|
||||||
|
let n = tools.undoBuffer.length
|
||||||
|
tools.undoBuffer.splice(0, n - MAX_IMG_UNDO_ENTRIES)
|
||||||
|
}
|
||||||
|
|
||||||
|
tools.undoButton.classList.remove("displayNone")
|
||||||
|
tools.redoButton.classList.add("displayNone")
|
||||||
}
|
}
|
||||||
} else if (e.status == "failed") {
|
} else if (e.status == "failed") {
|
||||||
alert("Error running upscale: " + e.detail)
|
alert("Error running upscale: " + e.detail)
|
||||||
@ -702,20 +718,31 @@ function applyInlineFilter(filterName, path, filterParams, img, statusText, tool
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function onUndoFilter(req, img, e, tools) {
|
function moveImageBetweenBuffers(img, fromBuffer, toBuffer, fromButton, toButton) {
|
||||||
if (tools.undoBuffer.length === 0) {
|
if (fromBuffer.length === 0) {
|
||||||
this.classList.add("displayNone")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = tools.undoBuffer.pop()
|
let src = fromBuffer.pop()
|
||||||
if (src.length > 0) {
|
if (src.length > 0) {
|
||||||
|
toBuffer.push(img.src)
|
||||||
img.src = src
|
img.src = src
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tools.undoBuffer.length === 0) {
|
if (fromBuffer.length === 0) {
|
||||||
this.classList.add("displayNone")
|
fromButton.classList.add("displayNone")
|
||||||
}
|
}
|
||||||
|
if (toBuffer.length > 0) {
|
||||||
|
toButton.classList.remove("displayNone")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUndoFilter(req, img, e, tools) {
|
||||||
|
moveImageBetweenBuffers(img, tools.undoBuffer, tools.redoBuffer, tools.undoButton, tools.redoButton)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onRedoFilter(req, img, e, tools) {
|
||||||
|
moveImageBetweenBuffers(img, tools.redoBuffer, tools.undoBuffer, tools.redoButton, tools.undoButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onUpscaleClick(req, img, e, tools) {
|
function onUpscaleClick(req, img, e, tools) {
|
||||||
|
Loading…
Reference in New Issue
Block a user