o
    ٷiD                     @   sP   d Z ddlZddlZddlZdedeeef fddZdej	j	defdd	Z
dS )
z
Shared helper utilities for OpenAI-compatible image generation API.

This module provides common helper functions for the image generation endpoint.
All functions work with plain Python types to maintain separation from the
FastAPI HTTP layer.
    Nsize_strreturnc                 C   s   | rt | tstd|  | d}t|dkr!td|  dzt|d }t|d }W n ty>   td|  dw |dksG|dkrRtd	| d| d
||fS )zParse size string to width and height tuple.

    Args:
        size_str: Size in format "WIDTHxHEIGHT" (e.g., "1024x1024")

    Returns:
        Tuple of (width, height)

    Raises:
        ValueError: If size format is invalid
    zSSize must be a non-empty string in format 'WIDTHxHEIGHT' (e.g., '1024x1024'), got: x   zInvalid size format: 'z]'. Expected format: 'WIDTHxHEIGHT' (e.g., '1024x1024'). Did you mean to use 'x' as separator?r      z%'. Width and height must be integers.zInvalid size: z-. Width and height must be positive integers.)
isinstancestr
ValueErrorsplitlenint)r   partswidthheight r   `/home/ubuntu/.local/lib/python3.10/site-packages/vllm_omni/entrypoints/openai/image_api_utils.py
parse_size   s$   

r   imagec                 C   s4   t  }| j|dd |d t| dS )zEncode PIL Image to base64 PNG string.

    Args:
        image: PIL Image object

    Returns:
        Base64-encoded PNG image as string
    PNG)formatr   zutf-8)ioBytesIOsaveseekbase64	b64encodereaddecode)r   bufferr   r   r   encode_image_base645   s   	
r   )__doc__r   r   	PIL.ImagePILr   tupler   r   Imager   r   r   r   r   <module>   s   $