From aa192e34d43cbffac167b29fad5e6803f856f60d Mon Sep 17 00:00:00 2001 From: Sergey Luzyanin Date: Thu, 19 Feb 2026 13:48:54 +0300 Subject: [PATCH] [bug] fix bug 80141 --- word/apiCommon.js | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/word/apiCommon.js b/word/apiCommon.js index 4a2f34658d..55568b7fdc 100644 --- a/word/apiCommon.js +++ b/word/apiCommon.js @@ -2878,24 +2878,38 @@ this.ProcessedCanvas.width = nW; this.ProcessedCanvas.height = nH; const ctx = this.ProcessedCanvas.getContext('2d'); - ctx.drawImage(_img.Image, 0, 0, nW, nH); + + try + { + ctx.drawImage(_img.Image, 0, 0, nW, nH); + } + catch (e) + { + return; + } if (this.RemoveBackground) { - const oData = ctx.getImageData(0, 0, nW, nH); - const px = oData.data; - const nLow = 50; - const nHigh = 230; - const nRange = nHigh - nLow; - for (let i = 0; i < px.length; i += 4) + try + { + const oData = ctx.getImageData(0, 0, nW, nH); + const px = oData.data; + const nLow = 50; + const nHigh = 230; + const nRange = nHigh - nLow; + for (let i = 0; i < px.length; i += 4) + { + const nLum = (px[i] * 299 + px[i + 1] * 587 + px[i + 2] * 114) / 1000; + if (nLum >= nHigh) + px[i + 3] = 0; + else if (nLum > nLow) + px[i + 3] = Math.min(px[i + 3], Math.round(255 * (nHigh - nLum) / nRange)); + } + ctx.putImageData(oData, 0, 0); + } + catch (e) { - const nLum = (px[i] * 299 + px[i + 1] * 587 + px[i + 2] * 114) / 1000; - if (nLum >= nHigh) - px[i + 3] = 0; - else if (nLum > nLow) - px[i + 3] = Math.min(px[i + 3], Math.round(255 * (nHigh - nLum) / nRange)); } - ctx.putImageData(oData, 0, 0); } };