e57da2f6d5
Tres funciones CPU-only del lote gamedev 2D + 2 helpers puros + grupo de capacidad: - comfyui_pixelize_image_py_ml (impure): Fase 2 pixelart — downscale nearest + cuantizacion a N colores / paleta fija (game-boy/pico-8/nes) + re-upscale nearest. - comfyui_matting_luma_to_alpha_py_ml (impure): frame VFX sobre negro -> RGBA por luminancia ponderada (translucidos con additive blend). - comfyui_export_asset_to_godot_py_pipelines (impure): puente ComfyUI -> Godot 4 — copia a res://assets/<dir> por kind + .import por tipo + filtro Nearest si pixelart + reimport headless best-effort. Compone los 2 helpers puros. - godot_map_asset_dir_py_core, godot_clean_asset_name_py_core (pure): nucleos reutilizables del pipeline. - docs/capabilities/gamedev-2d.md + INDEX: grupo nuevo gamedev. Tests 33/33 verdes (offline PIL/numpy). Golden real verificado: asset de ~/ComfyUI/output -> /tmp/godot_test_proj con .import correcto y reimport headless real de Godot 4.7. Sin GPU, sin red, sin tocar proyectos del usuario. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4.5 KiB
4.5 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | |||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| comfyui_pixelize_image | function | py | ml | 1.0.0 | impure | def comfyui_pixelize_image(src_path: str, dst_path: str, *, downscale: int = 8, colors: int = 16, palette=None, dither: bool = False, upscale_back: bool = True) -> dict | Post-proceso pixel-perfect (Fase 2 pixelart): imagen -> downscale nearest-neighbor por factor (colapsa cada bloque borroso a un pixel duro) -> cuantizacion a N colores (MEDIANCUT) o a una paleta fija embebida (game-boy / pico-8 / nes / lista de hex) -> opcional re-upscale nearest conservando los pixeles duros. Convierte el 'pixelart borroso de IA' en pixelart de verdad. Nucleo PIL puro, CPU-only: sin GPU, sin red. Devuelve {ok, out_path, size, n_colors_final, error}. Impura solo por la lectura/escritura de disco. |
|
false | error_py_core |
|
dict con ok (bool), out_path (str), size ([w,h] de la imagen final), n_colors_final (int, colores distintos del resultado), error (str, vacio si OK). | true |
|
python/functions/ml/comfyui_pixelize_image_test.py | python/functions/ml/comfyui_pixelize_image.py |
Ejemplo
import sys, os
sys.path.insert(0, os.path.join(os.environ["HOME"], "fn_registry", "python", "functions"))
from ml.comfyui_pixelize_image import comfyui_pixelize_image
# Crudo SDXL+pixel-art-xl 1024x1024 -> pixelart 16 colores, grid de 128
res = comfyui_pixelize_image(
os.path.expanduser("~/ComfyUI/output/pixelart_00001_.png"),
"/tmp/hero_pixel.png",
downscale=8, colors=16,
)
# {'ok': True, 'out_path': '/tmp/hero_pixel.png', 'size': [1024, 1024], 'n_colors_final': 16, 'error': ''}
# Forzar la paleta retro Game Boy (4 colores) y dejar la imagen pequena (sin upscale)
comfyui_pixelize_image("/tmp/hero_pixel.png", "/tmp/hero_gb.png",
palette="game-boy", upscale_back=False)
Cuando usarla
Fase 2 del pipeline pixelart: tras generar el crudo (SDXL + LoRA pixel-art-xl),
para colapsar el grid borroso a pixeles duros y limitar la paleta. Tambien sirve
para "pixelizar" cualquier imagen (sprite, render, foto) a estetica retro sin
tocar la GPU. Para llevar el resultado a Godot con filtro Nearest:
comfyui_export_asset_to_godot(out, "pixelart", proj).
Gotchas
- nearest, no lanczos: el downscale usa NEAREST a proposito; interpolar suave re-difumina el grid. No lo cambies por "calidad".
palettefija (game-boy/pico-8/nes o lista de hex) ignoracolors. La paleta se rellena internamente repitiendo su ultimo color para quequantizeno introduzca un negro extra por entradas vacias (bug arreglado en v1.0.0).downscaleconupscale_back=Falsedeja la imagen dew//downscale x h//downscale: util para spritesheets compactos; conTruevuelve al tamano original con bordes duros (preview).- Todo error es dict
ok=False(no excepcion):src_pathinexistente,downscale<1, paleta desconocida ->errorexplica. No crashea ni borra nada. n_colors_finalcuenta colores distintos reales del PNG escrito; con paleta fija puede ser menor que el tamano de la paleta si la imagen no usa todos.- CPU-only: no toca la GPU ni el servidor ComfyUI; corre en cualquier interprete con Pillow.