Skip to main content
Glama
ext-sakamoro

Aseprite MCP Tools

by ext-sakamoro

remap_colors

Modify color schemes in Aseprite pixel art files by mapping specific colors to new values for consistent palette adjustments.

Instructions

Remap colors in an Aseprite file.

Args: filename: Name of the Aseprite file to modify color_map: Dictionary mapping old colors to new colors (e.g., {"FF0000": "00FF00"})

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
color_mapYes

Implementation Reference

  • The remap_colors tool implementation which performs color mapping using Aseprite scripting.
    async def remap_colors(
        filename: str,
        color_map: Dict[str, str]
    ) -> str:
        """Remap colors in an Aseprite file.
    
        Args:
            filename: Name of the Aseprite file to modify
            color_map: Dictionary mapping old colors to new colors (e.g., {"FF0000": "00FF00"})
        """
        try:
            # Validate inputs
            file_path = validate_file_path(filename, must_exist=True)
            
            if not color_map:
                raise ValidationError("color_map", color_map, "Color map cannot be empty")
            
            # Validate all colors
            validated_map = {}
            for old_color, new_color in color_map.items():
                old_validated = validate_color(old_color)
                new_validated = validate_color(new_color)
                validated_map[old_validated] = new_validated
            
            # Build Lua script
            builder = LuaBuilder()
            builder.open_sprite(str(file_path))
            builder.add_line('local spr = app.activeSprite')
            builder.if_condition('not spr')
            builder.add_line('error("No active sprite")')
            builder.end_if()
            builder.add_line()
            
            # Create color mapping table
            builder.add_line('local colorMap = {}')
            for old_color, new_color in validated_map.items():
                old_r, old_g, old_b = int(old_color[0:2], 16), int(old_color[2:4], 16), int(old_color[4:6], 16)
                new_r, new_g, new_b = int(new_color[0:2], 16), int(new_color[2:4], 16), int(new_color[4:6], 16)
                builder.add_line(f'colorMap[Color{{r={old_r}, g={old_g}, b={old_b}, a=255}}.rgbaPixel] = Color{{r={new_r}, g={new_g}, b={new_b}, a=255}}')
            builder.add_line()
            
            # Remap colors in all cels
            builder.begin_transaction()
            builder.for_loop('_, cel', 'ipairs(spr.cels)')
            builder.add_line('local img = cel.image:clone()')
            builder.add_line('local changed = false')
            builder.for_loop('y', 0, 'img.height - 1')
            builder.for_loop('x', 0, 'img.width - 1')
            builder.add_line('local pixel = img:getPixel(x, y)')
            builder.add_line('local newColor = colorMap[pixel]')
            builder.if_condition('newColor')
            builder.add_line('img:putPixel(x, y, newColor.rgbaPixel)')
            builder.add_line('changed = true')
            builder.end_if()
            builder.end_loop()
            builder.end_loop()
            builder.if_condition('changed')
            builder.add_line('cel.image = img')
            builder.end_if()
            builder.end_loop()
            builder.end_transaction()
            
            builder.save_sprite()
            
            # Execute script
            cmd = get_command()
            success, output = cmd.execute_lua_script(builder.build())
            
            return f"Successfully remapped {len(validated_map)} colors in {file_path}"
            
        except (ValidationError, AsepriteError) as e:
            return f"Failed to remap colors: {e}"
        except Exception as e:
            return f"Unexpected error: {e}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ext-sakamoro/AsepriteMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server