Files
Raykosan-ComfyUI_RaykoStudio/Rayko_RGB2RGBA.py
T

65 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SPDX-License-Identifier: Apache-2.0
# Copyright 2025-2026 Raykosan (RaykoStudio)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch
import numpy as np
import os
import folder_paths
from PIL import Image
class LoadImageRGBA:
@classmethod
def INPUT_TYPES(cls):
input_dir = folder_paths.get_input_directory()
files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))]
return {
"required": {
"image": (sorted(files), {"image_upload": True}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("rgba",)
FUNCTION = "load_image"
CATEGORY = "🦊 RaykoStudio"
DESCRIPTION = "Загружает изображение с сохранением альфа-канала (RGBA). Поддерживает PNG, WEBP, TIFF с прозрачностью."
def load_image(self, image):
image_path = os.path.join(folder_paths.get_input_directory(), image)
# Загружаем изображение в PIL
img = Image.open(image_path)
# Принудительно конвертируем в RGBA, чтобы гарантировать 4 канала
if img.mode != 'RGBA':
img = img.convert('RGBA')
# Конвертируем в numpy array (нормализуем 0-1)
img_array = np.array(img).astype(np.float32) / 255.0
# Добавляем размерность батча [1, H, W, C]
tensor = torch.from_numpy(img_array).unsqueeze(0)
print(f"[rgb2rgba ] Loaded {image}: {img.size}, mode={img.mode}")
return (tensor,)
@classmethod
def IS_CHANGED(cls, image):
image_path = os.path.join(folder_paths.get_input_directory(), image)
return os.path.getmtime(image_path)
NODE_CLASS_MAPPINGS = {"LoadImageRGBA": LoadImageRGBA}
NODE_DISPLAY_NAME_MAPPINGS = {"LoadImageRGBA": "🦊 RS rgb2rgba"}