From 8d4c4c1945b8eeee3e96f8f7eb297e99b19d044e Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:40:37 +0200 Subject: [PATCH] Only snap resolution if pixel counts change --- .../extensions/stable-diffusion/index.js | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index e48950742..2a0f92089 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -1799,18 +1799,21 @@ function setTypeSpecificDimensions(generationType) { // Force to use roughly the same pixel count as before rescaling const prevPixelCount = prevSDHeight * prevSDWidth; const newPixelCount = extension_settings.sd.height * extension_settings.sd.width; - const ratio = Math.sqrt(prevPixelCount / newPixelCount); - extension_settings.sd.height = Math.round(extension_settings.sd.height * ratio / 64) * 64; - extension_settings.sd.width = Math.round(extension_settings.sd.width * ratio / 64) * 64; - console.log(`Pixel counts after rescaling: ${prevPixelCount} -> ${newPixelCount} (ratio: ${ratio})`); - const resolution = resolutionOptions[getClosestKnownResolution()]; - if (resolution) { - extension_settings.sd.height = resolution.height; - extension_settings.sd.width = resolution.width; - console.log('Snap to resolution', JSON.stringify(resolution)); - } else { - console.warn('Snap to resolution failed, using custom dimensions'); + if (prevPixelCount !== newPixelCount) { + const ratio = Math.sqrt(prevPixelCount / newPixelCount); + extension_settings.sd.height = Math.round(extension_settings.sd.height * ratio / 64) * 64; + extension_settings.sd.width = Math.round(extension_settings.sd.width * ratio / 64) * 64; + console.log(`Pixel counts after rescaling: ${prevPixelCount} -> ${newPixelCount} (ratio: ${ratio})`); + + const resolution = resolutionOptions[getClosestKnownResolution()]; + if (resolution) { + extension_settings.sd.height = resolution.height; + extension_settings.sd.width = resolution.width; + console.log('Snap to resolution', JSON.stringify(resolution)); + } else { + console.warn('Snap to resolution failed, using custom dimensions'); + } } }