### Install SageAttention Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Installs the SageAttention library, recommended for long inference sequences. ```bash pip install sageattention ``` -------------------------------- ### Install SageAttention 3 Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Installs SageAttention version 3, an alternative for enhanced performance. ```bash pip install sageattn3 ``` -------------------------------- ### Install Dependencies Source: https://github.com/aining2022/comfyui_swwan/blob/main/INSTALLATION_CHECKLIST.md Install the required Python dependencies for the custom nodes using pip. ```bash cd ComfyUI_Swwan pip install -r requirements.txt ``` -------------------------------- ### Crop Video Face Region Example Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/03-CROP_AND_RESTORE.md Example demonstrating how to crop a video face region using consistent box settings. This utilizes ratio-based reserves and batch-first reuse for efficiency. ```python # Crop video face region with consistent box crop_result = CropByMaskV5.crop_by_mask_v5( detect='min_bounding_rect', reserve_mode='ratio', top_reserve_ratio=0.3, bottom_reserve_ratio=0.3, left_reserve_ratio=0.3, right_reserve_ratio=0.3, reserve_max=100, round_to_multiple='16', batch_mode='batch_first_reuse', device='GPU', image=video_batch, # [30, 1080, 1920, 3] mask_image=face_masks # [30, 1080, 1920, 1] ) cropped_image, cropped_mask, crop_box, preview = crop_result ``` -------------------------------- ### Example Cross-Reference Information Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/README.md This snippet shows an example of how cross-reference information, including source file paths, dependencies, and related nodes, is presented. ```text **Source**: `image_nodes.py:62-149` **Dependencies**: color-matcher library, torch, numpy **Related Nodes**: RGBA Safe Pre, Image Blend, Math Remap Data ``` -------------------------------- ### Install ComfyUI_Swwan Custom Nodes Source: https://github.com/aining2022/comfyui_swwan/blob/main/README.md Clone the repository into the ComfyUI custom nodes directory and install required dependencies. ```bash cd ComfyUI/custom_nodes git clone https://github.com/aining2022/ComfyUI_Swwan pip install -r ComfyUI_Swwan/requirements.txt ``` -------------------------------- ### Keyframe Scheduling Example (Linear Interpolation) Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/05-MATHEMATICAL_OPERATIONS.md Demonstrates linear interpolation between two values using a mathematical expression, suitable for keyframe scheduling. ```python # Interpolate between two values expression = "a + (b - a) * c" # Linear interpolation result = MathExpression_UTK.evaluate( expression, a=0, # start value b=100, # end value c=0.5 # progress (0 to 1) ) # Result: 50 ``` -------------------------------- ### Color Matching Example Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/QUICK_START.txt Use ColorMatch to match colors between a reference and target image. Specify the matching method. ```python ColorMatch(image_ref, image_target, method='hm-mvgd-hm') ``` -------------------------------- ### Install ComfyUI Swwan Requirements Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Installs the standard Python dependencies for the ComfyUI Swwan project. ```bash pip install -r ComfyUI_Swwan/requirements.txt ``` -------------------------------- ### ComfyUI External Libraries (requirements.txt) Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/10-MODULE_STRUCTURE_AND_EXPORTS.md Lists essential Python packages and their version constraints for ComfyUI. Ensure these are installed before running ComfyUI. ```text torch>=2.0.0 # PyTorch tensors and operations torchvision>=0.15.0 # Image transforms numpy>=1.20.0 # Numerical arrays Pillow>=9.0.0 # Image manipulation opencv-python>=4.5.0 # Computer vision operations color-matcher>=0.4.0 # Color matching algorithms onnxruntime>=1.14.0 # ONNX model inference scipy>=1.9.0 # Scientific computing ``` -------------------------------- ### Example Usage of RGBA_Safe_Pre Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/04-RGBA_NODES.md Demonstrates how to use the RGBA_Safe_Pre node to prepare a PNG image with transparency for RGB-only processing. It shows loading the image, extracting alpha, and the expected state of outputs based on the presence of alpha. ```python # Load PNG with transparency image, mask = load_image("icon.png") # Extract alpha and premultiply image_out, alpha, has_alpha = RGBA_Safe_Pre.prepare( image=image, mask=mask ) # If has_alpha=True: # - image_out contains: image * alpha # - alpha contains: 1 - ComfyUI_mask (real transparency) # - Can now pass image_out through RGB-only nodes ``` -------------------------------- ### ImageListToImageBatch Example: Combine Images into Batch Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/02-IMAGE_BATCH_UTILITIES.md Demonstrates combining preprocessed images into a batch for model inference using the ImageListToImageBatch class. Images are processed on the GPU. ```python # Combine preprocessed images into batch for model inference images = [img1, img2, img3] # each has shape [1, 512, 512, 3] batched = ImageListToImageBatch.doit( images=images, device='gpu' ) # Result: tensor of shape [3, 512, 512, 3] ``` -------------------------------- ### Conditional Routing Example Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/QUICK_START.txt Use AnySwitch for conditional routing. It takes a primary input and a backup input, outputting a boolean and the selected value. ```python AnySwitch(优先输入, 备用输入) → outputs (boolean, value) ``` -------------------------------- ### Conditional Logic Example with IIF Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/05-MATHEMATICAL_OPERATIONS.md Shows how to use the 'iif' function for conditional logic, returning an alternative value if the primary variable 'a' is zero. ```python # Use alternative value if primary is zero expression = "iif(a, a, b)" result = MathExpression_UTK.evaluate(expression, a=0, b=100) # Result: 100 ``` -------------------------------- ### AnySwitch Conditional Selection Example Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/06-SWITCH_AND_IO_NODES.md Demonstrates how to use the AnySwitch node to conditionally select between two inputs, such as images. The output includes a boolean flag indicating which input was chosen. ```python # Conditional image selection # If image_a is connected: use it (output True) # If image_a not connected: use image_b (output False) is_active, selected = AnySwitch.check( 优先输入=image_a, # May be None if not connected 备用输入=image_b # Fallback ) # is_active = True means image_a was used # is_active = False means image_b was used ``` -------------------------------- ### Easing Curve Example (Quadratic Ease-in) Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/05-MATHEMATICAL_OPERATIONS.md Demonstrates using a mathematical expression to create an ease-in effect for frame progress, specifically a quadratic curve. ```python # Ease-in function for frame progress (0 to 1) expression = "a * a" # Quadratic ease-in result = MathExpression_UTK.evaluate(expression, a=0.5) # Result: 0.25 ``` -------------------------------- ### Simple Arithmetic Example Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/05-MATHEMATICAL_OPERATIONS.md Evaluates a simple arithmetic expression involving addition and multiplication with variables 'a' and 'b'. ```python expression = "a + b * 2" result = MathExpression_UTK.evaluate(expression, a=10, b=5) # Result: 20 (10 + 5*2) ``` -------------------------------- ### ImageBatchToImageList Example: Unpack Batch for Saving Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/02-IMAGE_BATCH_UTILITIES.md Demonstrates unpacking a batched image tensor into a list of individual tensors using ImageBatchToImageList. The unpacked images can then be processed or saved individually. ```python # Unpack batch for individual processing/saving batch = torch.randn(4, 512, 512, 3) # 4 images images = ImageBatchToImageList.doit(batch) # Result: list of 4 tensors, each [1, 512, 512, 3] # Use in workflow: Save each image individually for img in images: save_image(img) ``` -------------------------------- ### ComfyUI Web Path Mapping Source: https://github.com/aining2022/comfyui_swwan/blob/main/web/js/README.md This example illustrates how ComfyUI maps the configured web directory to a specific URL path, allowing frontend JavaScript files to be accessed by the browser. ```text /extensions/ComfyUI_Swwan/fast_groups_muter_entry.js ``` -------------------------------- ### Complex Calculation Example (Aspect Ratio) Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/05-MATHEMATICAL_OPERATIONS.md Performs a complex calculation to determine an aspect-ratio adjusted dimension using ceiling division. ```python # Calculate aspect-ratio adjusted dimension expression = "ceil((a * b) / c)" result = MathExpression_UTK.evaluate( expression, a=1920, # width b=1080, # height c=16 # divisor ) ``` -------------------------------- ### ColorMatch Color Transfer Example Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/01-IMAGE_PROCESSING.md Example of using the ColorMatch node to transfer skin tones from a reference portrait to a target portrait with poor lighting. It specifies the 'hm-mvgd-hm' method and a strength of 0.8. ```python # Match skin tones from a reference to target portrait # image_ref: high-quality portrait with good color grading # image_target: same person but with poor lighting colored = ColorMatch.colormatch( image_ref=reference_portrait, image_target=target_portrait, method='hm-mvgd-hm', strength=0.8, multithread=True ) ``` -------------------------------- ### AnyBooleanSwitch Node Example Usage Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/06-SWITCH_AND_IO_NODES.md Demonstrates how to use the AnyBooleanSwitch node to conditionally process an image based on a boolean flag. If the switch is enabled, the input image is passed through; otherwise, it is set to None. ```python # Conditionally process image output = AnyBooleanSwitch.process( 输入=processed_image, 开关=enable_processing # True/False from UI widget ) # If enable_processing=True: output = processed_image # If enable_processing=False: output = None (stops pipeline) ``` -------------------------------- ### RgthreeSeed Examples Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/05-MATHEMATICAL_OPERATIONS.md Demonstrates how to use the RgthreeSeed node with different seed values. Use a fixed seed for reproducibility, -1 for random seeds, and -2 for incrementing seeds. ```python # Fixed seed for reproducible results seed1 = RgthreeSeed.main(seed=42) # Returns: (42,) # Random seed each run seed2 = RgthreeSeed.main(seed=-1) # Returns: (random_int,) each time # Increment from previous seed3 = RgthreeSeed.main(seed=-2) # Returns: (prev_seed + 1,) ``` -------------------------------- ### Save Image with Full Alpha Control (WebP) Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/04-RGBA_NODES.md Example of saving an image in WebP format, preserving alpha if available, with specific quality and lossless settings. Ensure `processed_image`, `final_alpha`, and `has_alpha` are defined. ```python # Save with full alpha control RGBA_Multi_Save.save( image=processed_image, # [2, 512, 512, 3] alpha=final_alpha, # [2, 512, 512] has_alpha=has_alpha, # True file_format='webp', alpha_mode='keep', filename_prefix='icon', webp_quality=90, webp_lossless=False ) ``` -------------------------------- ### Inference Provider Options Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/09-TYPES_AND_CONFIGURATION.md Selects the inference provider for the DetectorForNSFW node. Options include CPU (ONNX Runtime), CUDA (NVIDIA GPU), and ROCM (AMD GPU). Ensure the necessary hardware and drivers are installed for GPU options. ```python provider: STRING in ["CPU", "CUDA", "ROCM"] # DetectorForNSFW # CPU = ONNX Runtime CPU backend # CUDA = NVIDIA GPU (requires CUDA-capable GPU) # ROCM = AMD GPU (requires ROCm-capable GPU) ``` -------------------------------- ### DetectorForNSFW Strict Filtering with Alternative Image Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/07-NSFW_AND_MASK_OPERATIONS.md Performs strict NSFW detection and replaces any flagged images with a provided alternative. This example utilizes GPU acceleration for faster processing. ```python # Strict detection with replacement image output, detect_json, filtered = DetectorForNSFW.filter_exposure( image=user_uploads, alternative_image=safe_placeholder, # Safe replacement image detect_size=640, # Higher accuracy provider="CUDA", # GPU acceleration buttocks_exposed=0.5, # Stricter female_breast_exposed=0.5, female_genitalia_exposed=0.3, anus_exposed=0.5, male_genitalia_exposed=0.3 ) # Returns alternative for any flagged images ``` -------------------------------- ### Parameter Selection Advice for RGBA Multi Save Source: https://github.com/aining2022/comfyui_swwan/blob/main/README.md Provides guidance on selecting parameters like `epsilon` and `alpha_mode` for RGBA Multi Save to achieve desired output formats and prevent common issues. ```text - `epsilon`: Used for lower bound protection during unpremultiply to avoid division by zero and blown-out edges. The default value of `0.001` is usually sufficient. - `alpha_mode=auto`: Suitable for most workflows. Flattens automatically for `jpeg`, and preserves transparency for `png/webp` when alpha is present. - `alpha_mode=keep`: Use when you explicitly want to output transparent `png/webp` files. - `alpha_mode=flatten`: Use to consistently generate standard RGB files, such as for social media images, thumbnails, or JPEG training datasets. ``` -------------------------------- ### Transparent PNG to Transparent PNG Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/04-RGBA_NODES.md This pattern demonstrates loading a transparent PNG, preparing it for processing, applying an upscale operation, and then restoring and saving the result as a transparent PNG, keeping the alpha channel. ```python # Load transparent image image, mask = load_image("source.png") # Prepare for processing image_pre, alpha, has_alpha = RGBA_Safe_Pre.prepare(image, mask) # Apply RGB-only processing processed = apply_upscale(image_pre) # Restore and save image_post, alpha_post = RGBA_Safe_Post.restore(processed, alpha, has_alpha) RGBA_Multi_Save.save( image=image_post, alpha=alpha_post, has_alpha=has_alpha, file_format='png', alpha_mode='keep', filename_prefix='output' ) ``` -------------------------------- ### Workflow Pattern: Batch Processing with Device Selection Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/02-IMAGE_BATCH_UTILITIES.md Illustrates a common workflow pattern for loading multiple images, processing them as a batch on the GPU using ImageListToImageBatch, applying model inference, and then splitting the results back into individual images with ImageBatchToImageList. ```python # Load multiple images, process as batch on GPU images = [ load_image("img1.png"), load_image("img2.png"), load_image("img3.png"), ] batch = ImageListToImageBatch.doit(images, 'gpu') # Apply model inference on GPU... results = model(batch) # Split results for individual saving result_list = ImageBatchToImageList.doit(results) ``` -------------------------------- ### Transparent PNG to JPEG Thumbnail Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/04-RGBA_NODES.md This pattern shows how to load a transparent PNG, prepare it, apply a downscale operation, and then save the result as a JPEG. Transparency is automatically flattened onto a specified white background. ```python # Load transparent image image, mask = load_image("source.png") # Prepare for processing image_pre, alpha, has_alpha = RGBA_Safe_Pre.prepare(image, mask) # Apply processing processed = apply_downscale(image_pre) # Save as JPEG on white background (alpha automatically flattened) RGBA_Multi_Save.save( image=processed, alpha=alpha, has_alpha=has_alpha, file_format='jpeg', alpha_mode='flatten', filename_prefix='thumb', background_red=1.0, background_green=1.0, background_blue=1.0, jpeg_quality=88 ) ``` -------------------------------- ### PyTorch Device Management Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/10-MODULE_STRUCTURE_AND_EXPORTS.md Demonstrates how to move tensors to a specific device (CPU or GPU), retrieve the device a tensor is currently on, and auto-detect the available device. ```python # Move to device tensor = tensor.to(device) # Get device from tensor device = tensor.device # Auto-detect device if torch.cuda.is_available(): device = torch.device("cuda") else: device = torch.device("cpu") ``` -------------------------------- ### Recommended Workflow: Output JPEG/PNG/WebP without Transparency Source: https://github.com/aining2022/comfyui_swwan/blob/main/README.md This workflow is suitable for generating output files in JPEG, or PNG/WebP without transparency, by flattening the alpha channel. ```text Load Image ↓ RGBA Safe Pre ↓ Any IMAGE Node ↓ RGBA Multi Save (jpeg 或 alpha_mode=flatten) ``` -------------------------------- ### Save Transparent PNG with RGBA_Save Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/04-RGBA_NODES.md Example of using the save_rgba method to save processed images with an alpha channel as transparent PNG files. Ensure the alpha mask has the shape [batch, height, width]. ```python # Save transparent PNG after processing RGBA_Save.save_rgba( image=processed_image, # [2, 512, 512, 3] alpha=final_alpha, # [2, 512, 512] filename_prefix="processed_icon" ) # Outputs: # - output/processed_icon_00000.png # - output/processed_icon_00001.png ``` -------------------------------- ### Recommended Workflow: Retain Transparency Source: https://github.com/aining2022/comfyui_swwan/blob/main/README.md This workflow is recommended when you need to preserve the transparency of an image throughout the process and output it with alpha. ```text Load Image ↓ RGBA Safe Pre ↓ Any IMAGE Node ↓ RGBA Multi Save (png/webp, alpha_mode=auto 或 keep) ``` -------------------------------- ### Get Image Size and Count (Python) Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Analyzes an image batch tensor to extract its width, height, and the total number of images. Use this for metadata extraction, batch size validation, or dimension-dependent processing. ```python class Get_Image_Size_and_Count: RETURN_TYPES = ("INT", "INT", "INT") RETURN_NAMES = ("width", "height", "count") FUNCTION = "get_size_count" CATEGORY = "Swwan/utils" ``` ```python batch = load_image("image.png") # [3, 512, 1024, 3] width, height, count = Get_Image_Size_and_Count.get_size_count(batch) # width = 1024 # height = 512 # count = 3 ``` -------------------------------- ### Configure Model and Font Paths Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/09-TYPES_AND_CONFIGURATION.md Defines custom paths for NSFW models and font files by adding entries to `comfy_paths.folder_names_and_paths`. Ensure the specified directories exist and contain the expected file types. ```python # NSFW models comfy_paths.folder_names_and_paths["nsfw"] = ( [os.path.join(models_dir, "nsfw")], {'.pt', '.onnx'} ) # Fonts comfy_paths.folder_names_and_paths["swwan_fonts"] = ( [os.path.join(script_directory, "fonts")], {'.otf', '.ttf'} ) ``` -------------------------------- ### Video Face Crop with Restoration Workflow Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/03-CROP_AND_RESTORE.md This workflow demonstrates loading a video, detecting faces, cropping them using batch_first_reuse for efficiency, processing the cropped faces, and then restoring the processed faces back to the original canvas size. It's suitable for video processing tasks where consistent face detection and restoration are needed. ```python # Load video batch video_frames = load_batch("video.mp4") # [120, 1080, 1920, 3] # Detect faces once, reuse box for entire video crop_result = CropByMaskV5.crop_by_mask_v5( detect='min_bounding_rect', reserve_mode='ratio', top_reserve_ratio=0.2, batch_mode='batch_first_reuse', device='GPU', image=video_frames, mask_image=face_detection_masks ) cropped_video = crop_result[0] # Process cropped video processed_video = apply_model(cropped_video) # Restore to original frame restored_video = RestoreCropBox.restore( cropped_image=processed_video, crop_box=crop_result[2], canvas_size=(1920, 1080) ) ``` -------------------------------- ### Restoring Alpha and Unpremultiplying RGB Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/04-RGBA_NODES.md Example of using the RGBA_Safe_Post.restore method after RGB-only processing. Ensures alpha is restored and RGB channels are unpremultiplied for correct downstream usage. The alpha channel is resized to match the processed image dimensions. ```python # After RGB-only processing (scaling, effects, etc.) processed = apply_upscale_model(image_out) # [1, 2048, 2048, 3] # Restore alpha and unpremultiply image_restored, alpha_restored = RGBA_Safe_Post.restore( image=processed, alpha=alpha, # [1, 1024, 1024] (original size) has_alpha=has_alpha, epsilon=0.001 ) # Result: image_restored [1, 2048, 2048, 3], alpha_restored [1, 2048, 2048] ``` -------------------------------- ### Get Latent Size and Count (Python) Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Analyzes a latent representation batch to extract its width, height, and the total number of latent vectors. This is useful for understanding the dimensions of encoded data, typically 8x downsampled from the original image. ```python class Get_Latent_Size_and_Count: RETURN_TYPES = ("INT", "INT", "INT") RETURN_NAMES = ("width", "height", "count") FUNCTION = "get_size_count" CATEGORY = "Swwan/utils" ``` ```python latent = encoder(image) # [3, 64, 128, 4] width, height, count = Get_Latent_Size_and_Count.get_size_count(latent) # width = 128 # height = 64 # count = 3 ``` -------------------------------- ### Auto-Select SageAttention Mode Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Automatically chooses the best SageAttention mode for the current GPU. Ensures optimal performance and compatibility. ```python # Automatically choose best mode for GPU model_patched = Patch_Sage_Attention_KJ.patch_attention( model=model, mode='auto' ) # GPU automatically detected and optimal mode selected ``` -------------------------------- ### Save Image as JPEG with Flattened Alpha Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/04-RGBA_NODES.md Example of saving an image as JPEG, which always flattens alpha. The background color is specified, and JPEG quality is set. Alpha-related parameters are ignored for JPEG. Ensure `processed_image`, `final_alpha`, and `has_alpha` are defined. ```python # Save as JPG on white background RGBA_Multi_Save.save( image=processed_image, alpha=final_alpha, has_alpha=has_alpha, file_format='jpeg', alpha_mode='flatten', # Ignored for JPEG anyway filename_prefix='thumbnail', background_red=1.0, background_green=1.0, background_blue=1.0, jpeg_quality=88 ) ``` -------------------------------- ### Workflow Pattern: Mixed Resolution Handling Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/02-IMAGE_BATCH_UTILITIES.md Shows how to combine images of different resolutions into a single batch using ImageListToImageBatch. The utility automatically rescales images to match the dimensions of the first image in the list. ```python # Combine images of different sizes images = [ tensor_512x512, # [1, 512, 512, 3] tensor_256x256, # [1, 256, 256, 3] tensor_1024x768, # [1, 1024, 768, 3] ] # All will be rescaled to 512x512 (first image's resolution) batch = ImageListToImageBatch.doit(images, 'auto') ``` -------------------------------- ### Preview_Animation Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Generates an animation preview from a batch of images. Supports GIF, WebP, and MP4 formats with configurable frame rate and loop count. ```APIDOC ## Preview_Animation Generates animation preview from batch of images. ### Method `generate_preview(image, format="gif", fps=8, loop=0)` ### Input Parameters - **image** (IMAGE) - Required - Batch of image frames - **format** (STRING) - Optional - Default: "gif" - Preview format: `gif`, `webp`, `mp4` - **fps** (INT) - Optional - Default: 8 - Playback frame rate [1, 60] - **loop** (INT) - Optional - Default: 0 - Loop count (0 = infinite) ### Supported Formats | Format | Size | Browser Support | Quality | |--------|--------|-----------------|-----------| | GIF | Large | Excellent | Good | | WebP | Medium | Modern | Excellent | | MP4 | Small | Good | Excellent | ``` -------------------------------- ### Recommended Workflow: Pass Modified RGB and Alpha Source: https://github.com/aining2022/comfyui_swwan/blob/main/README.md Use this workflow when you need to pass the corrected RGB and alpha channels to subsequent nodes for further processing. ```text Load Image ↓ RGBA Safe Pre ↓ Any IMAGE Node ↓ RGBA Safe Post ↓ More Nodes ↓ RGBA Save / RGBA Multi Save ``` -------------------------------- ### Clone the Repository Source: https://github.com/aining2022/comfyui_swwan/blob/main/INSTALLATION_CHECKLIST.md Clone the ComfyUI Swwan custom nodes repository into your ComfyUI custom_nodes directory. ```bash cd ComfyUI/custom_nodes git clone https://github.com/YOUR_USERNAME/ComfyUI_Swwan ``` -------------------------------- ### Fast_Preview Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md A quick single-frame preview node that immediately displays an image in the ComfyUI preview window without slowing down processing. ```APIDOC ## Fast_Preview Quick single-frame preview node. ### Method `preview(image)` ### Input Parameters - **image** (IMAGE) - Required - Single image to preview ### Behavior - Immediately displays image in ComfyUI preview window - Non-blocking (doesn't slow down processing) - Shows first frame of batch only ``` -------------------------------- ### Verify JavaScript File Structure Source: https://github.com/aining2022/comfyui_swwan/blob/main/INSTALLATION_CHECKLIST.md Check if the expected JavaScript files for the custom nodes are present in the web/js directory. ```bash ls -la web/js/*.js ``` -------------------------------- ### Verify Python File Structure Source: https://github.com/aining2022/comfyui_swwan/blob/main/INSTALLATION_CHECKLIST.md Check if the expected Python files for the custom nodes are present in the root directory. ```bash ls -la *.py | grep -E "(fast_|seed|image_comparer)" ``` -------------------------------- ### Specific Quantization SageAttention Mode Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/08-SAGE_ATTENTION_AND_UTILITIES.md Applies a specific SageAttention mode using INT8 QK with FP8 PV for maximum inference speed. Suitable when minimal quality loss is acceptable. ```python # Use INT8 QK with FP8 PV for maximum speed model_patched = Patch_Sage_Attention_KJ.patch_attention( model=model, mode='sageattn_qk_int8_pv_fp8_cuda' ) # Faster inference with minimal quality loss ``` -------------------------------- ### RGBA Safe Workflow for Regular RGB Export Source: https://github.com/aining2022/comfyui_swwan/blob/main/README.md Utilize RGBA Safe Pre and RGBA Multi Save nodes with JPEG export or alpha_mode=flatten to output regular RGB files, discarding transparency. ```text Load Image ↓ RGBA Safe Pre ↓ Any IMAGE Node ↓ RGBA Multi Save (jpeg or alpha_mode=flatten) ``` -------------------------------- ### Verify Service Module Directory Source: https://github.com/aining2022/comfyui_swwan/blob/main/INSTALLATION_CHECKLIST.md Check if the service module JavaScript files are present in the web/js/services/ directory. ```bash ls -la web/js/services/ ``` -------------------------------- ### Image Save Format Presets Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/09-TYPES_AND_CONFIGURATION.md Defines default settings for fast image saving, including JPEG quality, PNG compression level, and WebP encoding method. Adjust these for desired balance between save speed, file size, and quality. ```python FAST_DEFAULTS = { "quality": 88, # JPEG quality "png_compress_level": 1, # PNG: 0=fastest, 9=best "webp_method": 2, # WebP: 0-6, higher=slower/smaller } ``` -------------------------------- ### Node Class and Display Name Mappings Source: https://github.com/aining2022/comfyui_swwan/blob/main/_autodocs/09-TYPES_AND_CONFIGURATION.md Maps internal class names to user-friendly display names for nodes. This ensures nodes are correctly identified and presented in the ComfyUI interface. Both mappings are required for proper node registration. ```python NODE_CLASS_MAPPINGS = { "SwwanImageListToImageBatch": ImageListToImageBatch, "AnySwitch (Swwan)": AnySwitch, "NSFW_Detector": DetectorForNSFW, } NODE_DISPLAY_NAME_MAPPINGS = { "SwwanImageListToImageBatch": "Image List to Image Batch", "AnySwitch (Swwan)": "Any Switch (Swwan)", "NSFW_Detector": "NSFW Detector V2", } ```