saliacoel commited on
Commit
79976d3
·
verified ·
1 Parent(s): 1dd16f2

Upload Salia_RGB_Mouth_Patch_Blender.py

Browse files
Files changed (1) hide show
  1. Salia_RGB_Mouth_Patch_Blender.py +25 -4
Salia_RGB_Mouth_Patch_Blender.py CHANGED
@@ -17,6 +17,14 @@ Outputs, in order:
17
  image_3_mouth_2: Full-size RGB lead with alternate mouth 2 blended in.
18
  mouth_1_rgba: square_size x square_size RGBA alternate-mouth patch.
19
  mouth_2_rgba: square_size x square_size RGBA alternate-mouth patch.
 
 
 
 
 
 
 
 
20
 
21
  The RGBA inspection patches are the exact RGB/alpha data used for pasting.
22
  Outside the patch, the full-size results remain bit-for-bit equal to the lead.
@@ -207,10 +215,10 @@ class SaliaRGBMouthPatchBlender:
207
  },
208
  }
209
 
210
- RETURN_TYPES = ("IMAGE", "IMAGE", "IMAGE", "IMAGE", "IMAGE")
211
  RETURN_NAMES = (
212
  "image_1_lead", "image_2_mouth_1", "image_3_mouth_2",
213
- "mouth_1_rgba", "mouth_2_rgba",
214
  )
215
  OUTPUT_TOOLTIPS = (
216
  "Original full-resolution RGB lead, unchanged.",
@@ -218,6 +226,8 @@ class SaliaRGBMouthPatchBlender:
218
  "Full-resolution RGB lead with alternate mouth 2 blended in.",
219
  "Exact square-sized RGBA mouth patch 1 used for pasting, including extra_mask.",
220
  "Exact square-sized RGBA mouth patch 2 used for pasting, including extra_mask.",
 
 
221
  )
222
  FUNCTION = "blend_mouths"
223
  CATEGORY = "Salia/Image/Mouth"
@@ -226,7 +236,7 @@ class SaliaRGBMouthPatchBlender:
226
  "Combine rounded feather alpha with optional extra_mask: toggle OFF = MIN, ON = MAX. "
227
  "Output the squares for inspection, "
228
  "and paste each onto its own copy of the lead. Returns three separate full RGB frames "
229
- "and two RGBA mouth patches."
230
  )
231
 
232
  def __init__(self):
@@ -348,6 +358,8 @@ class SaliaRGBMouthPatchBlender:
348
  patch_2 = torch.zeros_like(patch_1)
349
  alpha = _rounded_feather(feather_pixels, corner_radius, lead.device, square_size).to(dtype=lead.dtype)
350
  centers = {}
 
 
351
  model_name = (bbox_detector_model_name or "").strip()
352
 
353
  for index in range(batch_size):
@@ -356,6 +368,10 @@ class SaliaRGBMouthPatchBlender:
356
  centers[lead_index] = self._mouth_center(lead[index], model_name)
357
  center = centers[lead_index]
358
  origin, placement = _square_placement(center, width, height, square_size)
 
 
 
 
359
  if placement is None:
360
  continue
361
  (x1, y1, x2, y2), (px1, py1, px2, py2) = placement
@@ -390,7 +406,12 @@ class SaliaRGBMouthPatchBlender:
390
  lead_index + 1, center, square_size, square_size, origin, (x1, y1, x2, y2),
391
  )
392
 
393
- return image_1, image_2, image_3, patch_1, patch_2
 
 
 
 
 
394
 
395
 
396
  NODE_CLASS_MAPPINGS = {"SaliaRGBMouthPatchBlender": SaliaRGBMouthPatchBlender}
 
17
  image_3_mouth_2: Full-size RGB lead with alternate mouth 2 blended in.
18
  mouth_1_rgba: square_size x square_size RGBA alternate-mouth patch.
19
  mouth_2_rgba: square_size x square_size RGBA alternate-mouth patch.
20
+ X: Shared square's top-left X in the original image (pixels).
21
+ Y: Shared square's top-left Y in the original image (pixels).
22
+
23
+ Place either RGBA mouth patch at (X, Y) to reproduce its full-size blend.
24
+ These are the actual patch origin, including any transparent padding, so X
25
+ or Y can be negative when the square extends beyond the image. For batches,
26
+ X/Y describe the first image's patches; a warning is logged if later origins
27
+ differ. Process separate leads individually when their positions differ.
28
 
29
  The RGBA inspection patches are the exact RGB/alpha data used for pasting.
30
  Outside the patch, the full-size results remain bit-for-bit equal to the lead.
 
215
  },
216
  }
217
 
218
+ RETURN_TYPES = ("IMAGE", "IMAGE", "IMAGE", "IMAGE", "IMAGE", "INT", "INT")
219
  RETURN_NAMES = (
220
  "image_1_lead", "image_2_mouth_1", "image_3_mouth_2",
221
+ "mouth_1_rgba", "mouth_2_rgba", "X", "Y",
222
  )
223
  OUTPUT_TOOLTIPS = (
224
  "Original full-resolution RGB lead, unchanged.",
 
226
  "Full-resolution RGB lead with alternate mouth 2 blended in.",
227
  "Exact square-sized RGBA mouth patch 1 used for pasting, including extra_mask.",
228
  "Exact square-sized RGBA mouth patch 2 used for pasting, including extra_mask.",
229
+ "Shared top-left X of both RGBA overlay squares in original-image pixels. Can be negative; first image for batches.",
230
+ "Shared top-left Y of both RGBA overlay squares in original-image pixels. Can be negative; first image for batches.",
231
  )
232
  FUNCTION = "blend_mouths"
233
  CATEGORY = "Salia/Image/Mouth"
 
236
  "Combine rounded feather alpha with optional extra_mask: toggle OFF = MIN, ON = MAX. "
237
  "Output the squares for inspection, "
238
  "and paste each onto its own copy of the lead. Returns three separate full RGB frames "
239
+ "and two RGBA mouth patches plus their shared top-left X/Y coordinates (first image for batches)."
240
  )
241
 
242
  def __init__(self):
 
358
  patch_2 = torch.zeros_like(patch_1)
359
  alpha = _rounded_feather(feather_pixels, corner_radius, lead.device, square_size).to(dtype=lead.dtype)
360
  centers = {}
361
+ square_origin = None
362
+ coordinates_vary = False
363
  model_name = (bbox_detector_model_name or "").strip()
364
 
365
  for index in range(batch_size):
 
368
  centers[lead_index] = self._mouth_center(lead[index], model_name)
369
  center = centers[lead_index]
370
  origin, placement = _square_placement(center, width, height, square_size)
371
+ if square_origin is None:
372
+ square_origin = origin
373
+ elif origin != square_origin:
374
+ coordinates_vary = True
375
  if placement is None:
376
  continue
377
  (x1, y1, x2, y2), (px1, py1, px2, py2) = placement
 
406
  lead_index + 1, center, square_size, square_size, origin, (x1, y1, x2, y2),
407
  )
408
 
409
+ if coordinates_vary:
410
+ LOGGER.warning(
411
+ "[Salia RGB Mouth Patch] Batch overlay positions differ; X/Y outputs describe only "
412
+ "the first image's patches. Process leads individually for each pair's coordinates."
413
+ )
414
+ return image_1, image_2, image_3, patch_1, patch_2, square_origin[0], square_origin[1]
415
 
416
 
417
  NODE_CLASS_MAPPINGS = {"SaliaRGBMouthPatchBlender": SaliaRGBMouthPatchBlender}