# Copyright 2023 Lincoln D. Stein and the InvokeAI Team """ Common classes used by .image and .controlnet; avoids circular import issues """ from pydantic import BaseModel, Field from typing import Literal from ..models.image import ImageField from .baseinvocation import ( BaseInvocationOutput, InvocationConfig, ) class PILInvocationConfig(BaseModel): """Helper class to provide all PIL invocations with additional config""" class Config(InvocationConfig): schema_extra = { "ui": { "tags": ["PIL", "image"], }, } class ImageOutput(BaseInvocationOutput): """Base class for invocations that output an image""" # fmt: off type: Literal["image_output"] = "image_output" image: ImageField = Field(default=None, description="The output image") width: int = Field(description="The width of the image in pixels") height: int = Field(description="The height of the image in pixels") # fmt: on class Config: schema_extra = {"required": ["type", "image", "width", "height"]} class MaskOutput(BaseInvocationOutput): """Base class for invocations that output a mask""" # fmt: off type: Literal["mask"] = "mask" mask: ImageField = Field(default=None, description="The output mask") width: int = Field(description="The width of the mask in pixels") height: int = Field(description="The height of the mask in pixels") # fmt: on class Config: schema_extra = { "required": [ "type", "mask", ] }