mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-23 23:21:05 +01:00
Added sharpen and batch mode
This commit is contained in:
parent
956f96481a
commit
fca812aabe
@ -4,6 +4,8 @@ const commands = {
|
||||
UPSCAYL: "Upscale the Image",
|
||||
UPSCAYL_DONE: "Upscaling Done",
|
||||
UPSCAYL_PROGRESS: "Send Progress from Main to Renderer",
|
||||
SHARPEN: "Sharpen the Image First",
|
||||
SHARPEN_PROGRESS: "Send Sharpening Progress from Main to Renderer",
|
||||
};
|
||||
|
||||
module.exports = commands;
|
||||
|
@ -105,12 +105,85 @@ ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
||||
ipcMain.on(commands.SHARPEN, async (event, payload) => {
|
||||
const model = payload.model;
|
||||
const scale = payload.scaleFactor;
|
||||
|
||||
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
|
||||
let outputDir = "./sharpened";
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir);
|
||||
}
|
||||
|
||||
// COPY IMAGE TO TMP FOLDER
|
||||
const platform = getPlatform();
|
||||
const fullfileName =
|
||||
platform === "win"
|
||||
? payload.imagePath.split("\\").slice(-1)[0]
|
||||
: payload.imagePath.split("/").slice(-1)[0];
|
||||
const fileName = parse(fullfileName).name;
|
||||
const fileExt = parse(fullfileName).ext;
|
||||
|
||||
const inputFile = inputDir + "/" + fullfileName;
|
||||
const outFile = outputDir + "/" + fileName + "_sharpen" + fileExt;
|
||||
|
||||
fs.copyFile(inputFile, outFile, (err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
// UPSCALE
|
||||
if (fs.existsSync(outFile)) {
|
||||
// If already upscayled, just output that file
|
||||
return outFile;
|
||||
} else {
|
||||
let upscayl = spawn(
|
||||
execPath + "-realesr",
|
||||
[
|
||||
"-i",
|
||||
inputDir + "/" + fullfileName,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
4,
|
||||
"-x",
|
||||
"-m",
|
||||
modelsPath + "/" + model,
|
||||
],
|
||||
{
|
||||
cwd: null,
|
||||
detached: false,
|
||||
}
|
||||
);
|
||||
|
||||
let failed = false;
|
||||
upscayl.stderr.on("data", (stderr) => {
|
||||
console.log(stderr.toString());
|
||||
stderr = stderr.toString();
|
||||
mainWindow.webContents.send(commands.SHARPEN_PROGRESS, stderr.toString());
|
||||
if (stderr.includes("invalid gpu") || stderr.includes("failed")) {
|
||||
failed = true;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// Send done comamnd when
|
||||
upscayl.on("close", (code) => {
|
||||
if (failed !== true) {
|
||||
console.log("Done upscaling");
|
||||
return outFile;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
||||
const model = payload.model;
|
||||
const scale = payload.scaleFactor;
|
||||
const sharpen = payload.sharpen;
|
||||
|
||||
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
|
||||
let outputDir = payload.outputPath;
|
||||
|
||||
console.log("🚀 => ipcMain => outputDir", outputDir);
|
||||
|
||||
// COPY IMAGE TO TMP FOLDER
|
||||
|
@ -49,16 +49,30 @@ function LeftPaneSteps(props) {
|
||||
<p className="mb-2 text-sm text-neutral-400">
|
||||
Select Upscaling Type
|
||||
</p>
|
||||
<div className="mb-2 flex items-center gap-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="h-4 w-4 cursor-pointer appearance-none rounded-sm bg-neutral-500 transition duration-200 checked:bg-green-400 focus:outline-none focus-visible:border focus-visible:border-green-400"
|
||||
onChange={(e) => {
|
||||
props.setSharpen(e.target.checked);
|
||||
}}
|
||||
/>
|
||||
<p
|
||||
className={`inline-block text-sm font-medium ${
|
||||
props.sharpen ? "text-green-400" : "text-neutral-500"
|
||||
}`}
|
||||
>
|
||||
Sharpen Image
|
||||
</p>
|
||||
</div>
|
||||
<select
|
||||
name="select-model"
|
||||
onDrop={(e) => props.handleDrop(e)}
|
||||
className="rounded-lg bg-slate-300 p-3 hover:bg-slate-200"
|
||||
className="block rounded-lg bg-slate-300 p-3 hover:bg-slate-200"
|
||||
onChange={props.handleModelChange}
|
||||
>
|
||||
<option value="realesrgan-x4plus">General Photo</option>
|
||||
<option value="realesrgan-x4plus-anime">Digital Art</option>
|
||||
<option value="models-DF2K">Sharpen</option>
|
||||
<option value="models-DF2K_JPEG">Sharpen JPEG</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@ -124,7 +138,7 @@ function LeftPaneSteps(props) {
|
||||
<div className="animate-step-in">
|
||||
<p className="font-medium text-neutral-100">Step 3</p>
|
||||
<p className="mb-2 text-sm text-neutral-400">
|
||||
Defaults to Folder's Path
|
||||
Defaults to Folder's path
|
||||
</p>
|
||||
<button
|
||||
className="mt-1 rounded-lg bg-teal-400 p-3 transition-colors hover:bg-teal-300"
|
||||
|
@ -21,6 +21,7 @@ const Home = () => {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [version, setVersion] = useState("");
|
||||
const [batchMode, setBatchMode] = useState(false);
|
||||
const [sharpen, setSharpen] = useState(false);
|
||||
|
||||
const resetImagePaths = () => {
|
||||
setProgress("");
|
||||
@ -32,7 +33,7 @@ const Home = () => {
|
||||
setLoaded(true);
|
||||
setVersion(navigator.userAgent.match(/Upscayl\/([\d\.]+\d+)/)[1]);
|
||||
|
||||
window.electron.on(commands.UPSCAYL_PROGRESS, (_, data) => {
|
||||
const handleErrors = (data) => {
|
||||
if (data.includes("invalid gpu")) {
|
||||
alert(
|
||||
"Error. Please make sure you have a Vulkan compatible GPU (Most modern GPUs support Vulkan). Upscayl does not work with CPU or iGPU sadly."
|
||||
@ -45,6 +46,14 @@ const Home = () => {
|
||||
);
|
||||
resetImagePaths();
|
||||
} else if (data.length > 0 && data.length < 10) setProgress(data);
|
||||
};
|
||||
|
||||
window.electron.on(commands.UPSCAYL_PROGRESS, (_, data) => {
|
||||
handleErrors(data);
|
||||
});
|
||||
|
||||
window.electron.on(commands.SHARPEN_PROGRESS, (_, data) => {
|
||||
handleErrors(data);
|
||||
});
|
||||
|
||||
window.electron.on(commands.UPSCAYL_DONE, (_, data) => {
|
||||
@ -140,12 +149,24 @@ const Home = () => {
|
||||
setUpscaledImagePath("");
|
||||
if (imagePath !== "") {
|
||||
setProgress("Hold on...");
|
||||
await window.electron.send(commands.UPSCAYL, {
|
||||
scaleFactor,
|
||||
imagePath,
|
||||
outputPath,
|
||||
model,
|
||||
});
|
||||
|
||||
if (sharpen) {
|
||||
const sharpenedImage = await window.electron.send(commands.SHARPEN, {
|
||||
scaleFactor: 4,
|
||||
imagePath,
|
||||
outputPath,
|
||||
model: "sharpen",
|
||||
});
|
||||
console.log("🚀 => upscaylHandler => sharpenedImage", sharpenedImage);
|
||||
} else {
|
||||
await window.electron.send(commands.UPSCAYL, {
|
||||
scaleFactor,
|
||||
imagePath,
|
||||
outputPath,
|
||||
model,
|
||||
sharpen,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
alert("Please select an image to upscale");
|
||||
}
|
||||
@ -172,6 +193,8 @@ const Home = () => {
|
||||
setBatchMode={setBatchMode}
|
||||
imagePath={imagePath}
|
||||
outputPath={outputPath}
|
||||
sharpen={sharpen}
|
||||
setSharpen={setSharpen}
|
||||
/>
|
||||
|
||||
<Footer />
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
sharpened/to_upscale_sharpen.jpeg
Normal file
BIN
sharpened/to_upscale_sharpen.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
Loading…
Reference in New Issue
Block a user