fix: preserve single-channel scale adjust masks after blur

This commit is contained in:
134 2026-07-06 03:41:56 +08:00
parent 7640e6b5ca
commit c79da3e1d0
2 changed files with 12 additions and 0 deletions

View File

@ -2132,7 +2132,9 @@ async function buildScaleAdjustMaskWashPatch(params: {
const alpha = await sharp(maskBuffer, { const alpha = await sharp(maskBuffer, {
raw: { channels: 1, height: box.height, width: box.width }, raw: { channels: 1, height: box.height, width: box.width },
}) })
.greyscale()
.blur(Math.max(1.2, Math.min(box.width, box.height) * 0.018)) .blur(Math.max(1.2, Math.min(box.width, box.height) * 0.018))
.greyscale()
.raw() .raw()
.toBuffer(); .toBuffer();
const rgba = Buffer.alloc(box.width * box.height * 4); const rgba = Buffer.alloc(box.width * box.height * 4);
@ -2158,7 +2160,9 @@ async function buildScaleAdjustCompositeClipMaskPatch(params: {
const alpha = await sharp(Buffer.from(maskBuffer), { const alpha = await sharp(Buffer.from(maskBuffer), {
raw: { channels: 1, height: box.height, width: box.width }, raw: { channels: 1, height: box.height, width: box.width },
}) })
.greyscale()
.blur(Math.max(0.8, Math.min(box.width, box.height) * 0.006)) .blur(Math.max(0.8, Math.min(box.width, box.height) * 0.006))
.greyscale()
.raw() .raw()
.toBuffer(); .toBuffer();
const rgba = Buffer.alloc(box.width * box.height * 4); const rgba = Buffer.alloc(box.width * box.height * 4);
@ -2183,7 +2187,9 @@ async function buildScaleAdjustOverlayClipMaskPatch(imageBuffer: Buffer) {
const alpha = await sharp(imageBuffer, { failOn: "none" }) const alpha = await sharp(imageBuffer, { failOn: "none" })
.ensureAlpha() .ensureAlpha()
.extractChannel(3) .extractChannel(3)
.greyscale()
.blur(Math.max(0.8, Math.min(width, height) * 0.006)) .blur(Math.max(0.8, Math.min(width, height) * 0.006))
.greyscale()
.raw() .raw()
.toBuffer(); .toBuffer();
const rgba = Buffer.alloc(width * height * 4); const rgba = Buffer.alloc(width * height * 4);
@ -2297,7 +2303,9 @@ async function applyScaleAdjustAlphaMaskToRgba(params: {
const softenedAlpha = await sharp(Buffer.from(alphaMask), { const softenedAlpha = await sharp(Buffer.from(alphaMask), {
raw: { channels: 1, height, width }, raw: { channels: 1, height, width },
}) })
.greyscale()
.blur(blur) .blur(blur)
.greyscale()
.raw() .raw()
.toBuffer(); .toBuffer();
const output = Buffer.from(rawRgba); const output = Buffer.from(rawRgba);
@ -3184,7 +3192,9 @@ async function buildScaleAdjustStructureLockedComposite(params: {
const subjectAlpha = await sharp(alphaMaskForSubject, { const subjectAlpha = await sharp(alphaMaskForSubject, {
raw: { channels: 1, height: bbox.height, width: bbox.width }, raw: { channels: 1, height: bbox.height, width: bbox.width },
}) })
.greyscale()
.blur(Math.max(0.7, Math.min(bbox.width, bbox.height) * 0.006)) .blur(Math.max(0.7, Math.min(bbox.width, bbox.height) * 0.006))
.greyscale()
.png({ compressionLevel: 6 }) .png({ compressionLevel: 6 })
.toBuffer(); .toBuffer();
const widthFactor = const widthFactor =

View File

@ -2314,7 +2314,9 @@ async function buildScaleAdjustFallbackObjectPng(params: {
const alphaBuffer = await sharp(mask, { const alphaBuffer = await sharp(mask, {
raw: { channels: 1, height: box.height, width: box.width }, raw: { channels: 1, height: box.height, width: box.width },
}) })
.greyscale()
.blur(Math.max(0.7, Math.min(box.width, box.height) * 0.012)) .blur(Math.max(0.7, Math.min(box.width, box.height) * 0.012))
.greyscale()
.png({ compressionLevel: 6 }) .png({ compressionLevel: 6 })
.toBuffer(); .toBuffer();