@@ -324,6 +324,24 @@ async function channelToSelectionExe(channel_name = 'mask') {
324
324
}
325
325
}
326
326
327
+ function keepRatio ( selectionInfo , offset ) {
328
+ // Calculate the current width and height
329
+ let width = selectionInfo . right - selectionInfo . left
330
+ let height = selectionInfo . bottom - selectionInfo . top
331
+
332
+ // Calculate the new coordinates with the offset
333
+ selectionInfo . right += offset
334
+ selectionInfo . left -= offset
335
+ selectionInfo . bottom += offset
336
+ selectionInfo . top -= offset
337
+
338
+ // Update width and height
339
+ selectionInfo . width = width + 2 * offset
340
+ selectionInfo . height = height + 2 * offset
341
+
342
+ return selectionInfo
343
+ }
344
+
327
345
function makeSquare ( selectionInfo , offset ) {
328
346
// Calculate the current width and height
329
347
let width = selectionInfo . right - selectionInfo . left
@@ -349,12 +367,20 @@ function makeSquare(selectionInfo, offset) {
349
367
return selectionInfo
350
368
}
351
369
352
- async function inpaintLassoInitImageAndMask ( channel_name = 'mask' , offset = 0 ) {
370
+ async function inpaintLassoInitImageAndMask (
371
+ channel_name = 'mask' ,
372
+ offset = 0 ,
373
+ make_square = true
374
+ ) {
353
375
const selectionInfo = await psapi . getSelectionInfoExe ( )
354
376
//convert the selection box into square box so that you have best output results
355
- const squareSelection = makeSquare ( selectionInfo , offset )
377
+
378
+ const newSelection = make_square
379
+ ? makeSquare ( selectionInfo , offset )
380
+ : keepRatio ( selectionInfo , offset )
381
+
356
382
//correct width and height sliders, since this is lasso mode.
357
- await calcWidthHeightFromSelection ( squareSelection )
383
+ await calcWidthHeightFromSelection ( newSelection )
358
384
359
385
async function getImageFromCanvas ( ) {
360
386
const width = html_manip . getWidth ( )
@@ -363,7 +389,7 @@ async function inpaintLassoInitImageAndMask(channel_name = 'mask', offset = 0) {
363
389
const base64 = await io . IO . getSelectionFromCanvasAsBase64Interface_New (
364
390
width ,
365
391
height ,
366
- squareSelection ,
392
+ newSelection ,
367
393
true
368
394
)
369
395
return base64
@@ -396,7 +422,7 @@ async function inpaintLassoInitImageAndMask(channel_name = 'mask', offset = 0) {
396
422
synchronousExecution : true ,
397
423
} )
398
424
// const selection_info = await psapi.getSelectionInfoExe()
399
- mask_base64 = await fillSelectionWhiteOutsideBlack ( squareSelection )
425
+ mask_base64 = await fillSelectionWhiteOutsideBlack ( newSelection )
400
426
} )
401
427
402
428
//save laso selection to channel
0 commit comments