@pilio/gemini-watermark-remover 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -188,6 +188,49 @@ function calculateAllenkPaddedRoi({ imageWidth, imageHeight, region, padding = A
|
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
function calculateAllenkRuntimeRoi({
|
|
192
|
+
imageWidth,
|
|
193
|
+
imageHeight,
|
|
194
|
+
region,
|
|
195
|
+
padding = ALLENK_FDNCNN_MODEL.defaultPadding,
|
|
196
|
+
targetWidth = null,
|
|
197
|
+
targetHeight = null
|
|
198
|
+
} = {}) {
|
|
199
|
+
const padded = calculateAllenkPaddedRoi({ imageWidth, imageHeight, region, padding });
|
|
200
|
+
if (!padded) return null;
|
|
201
|
+
|
|
202
|
+
const safeTargetWidth = Number.isInteger(targetWidth) && targetWidth > 0 ? targetWidth : null;
|
|
203
|
+
const safeTargetHeight = Number.isInteger(targetHeight) && targetHeight > 0 ? targetHeight : null;
|
|
204
|
+
if (
|
|
205
|
+
!safeTargetWidth ||
|
|
206
|
+
!safeTargetHeight ||
|
|
207
|
+
imageWidth < safeTargetWidth ||
|
|
208
|
+
imageHeight < safeTargetHeight ||
|
|
209
|
+
padded.width > safeTargetWidth ||
|
|
210
|
+
padded.height > safeTargetHeight
|
|
211
|
+
) {
|
|
212
|
+
return padded;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const centerX = region.x + region.width / 2;
|
|
216
|
+
const centerY = region.y + region.height / 2;
|
|
217
|
+
const x = clamp(Math.round(centerX - safeTargetWidth / 2), 0, imageWidth - safeTargetWidth);
|
|
218
|
+
const y = clamp(Math.round(centerY - safeTargetHeight / 2), 0, imageHeight - safeTargetHeight);
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
x,
|
|
222
|
+
y,
|
|
223
|
+
width: safeTargetWidth,
|
|
224
|
+
height: safeTargetHeight,
|
|
225
|
+
inner: {
|
|
226
|
+
x: clamp(Math.round(region.x - x), 0, safeTargetWidth),
|
|
227
|
+
y: clamp(Math.round(region.y - y), 0, safeTargetHeight),
|
|
228
|
+
width: clamp(Math.round(region.width), 0, safeTargetWidth),
|
|
229
|
+
height: clamp(Math.round(region.height), 0, safeTargetHeight)
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
191
234
|
function embedAllenkRoiWeights({ roiWeights, roiWidth, roiHeight, paddedRoi, blurSigma = 1 } = {}) {
|
|
192
235
|
if (!roiWeights || !paddedRoi?.inner || roiWidth <= 0 || roiHeight <= 0) {
|
|
193
236
|
return new Float32Array(0);
|
|
@@ -319,6 +362,7 @@ export {
|
|
|
319
362
|
blendAllenkDenoisedRoi,
|
|
320
363
|
buildAllenkFdncnnInput,
|
|
321
364
|
calculateAllenkPaddedRoi,
|
|
365
|
+
calculateAllenkRuntimeRoi,
|
|
322
366
|
convertAllenkFdncnnOutputToRgba,
|
|
323
367
|
createAllenkGradientMask,
|
|
324
368
|
embedAllenkRoiWeights,
|