
    Z j                         S r SSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJrJrJr  SSKJrJr  SSKJrJr  \R*                  " \5      r\ " S	 S
\
5      5       rS
/rg)z$Image processor class for Chameleon.    N)
functional   )TorchvisionBackend)
ImageInputPILImageResamplingSizeDict)ImagesKwargsUnpack)auto_docstringloggingc                      ^  \ rS rSrSr\R                  r/ SQr/ SQr	SS0r
SrSSS.rSrSrSrS	rSrSrS
\\   4U 4S jjrS\S\4S jr        SU 4S jjrSrU =r$ )ChameleonImageProcessor"   z=Torchvision backend for Chameleon with custom convert_to_rgb.)      ?r   r   shortest_edgei   F)heightwidthTgq?kwargsc                 &   > [         TU ]  " S0 UD6  g )N )super__init__)selfr   	__class__s     ډ/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/chameleon/image_processing_chameleon.pyr    ChameleonImageProcessor.__init__3   s    "6"    imagereturnc                 <   [        U[        R                  R                  5      (       d  U$ UR                  S:X  a  U$ [        R
                  " UR                  S5      5      nUSS2SS2S4   S:  R                  5       (       d  UR                  S5      $ USS2SS2S4   S-  nSUSS2SS2[        R                  4   -
  S-  USS2SS2[        R                  4   USS2SS2SS24   -  -   n[        R                  R                  UR                  S5      S5      $ )	z
Convert image to RGB by blending the transparency layer if it's in RGBA format.
If image is not `PIL.Image`, it is simply returned without modifications.
RGBRGBANr      g     o@   uint8)
isinstancePILImagemodenparrayconvertanynewaxis	fromarrayastype)r   r   img_rgbaalphaimg_rgbs        r   convert_to_rgb&ChameleonImageProcessor.convert_to_rgb6   s    
 %11LZZ5 L88EMM&12 Aq!C',,..=='' Aq!E)uQ2::-..#5aBJJ>N8ORZ[\^_acbcac[cRd8ddyy""7>>'#:EBBr   c                   > [        U[        R                  [        45      (       a  UO[        R                  R                  nUc  [        R                  R                  nOc[        U[
        5      (       aN  U[
        R                  :X  a0  [        R                  S5        [        R                  R                  nO
SSK
Jn  Xc   n[        TU ]4  " SXUS.UD6$ )z(Resize with LANCZOS fallback to BICUBIC.zYou have used fast image processor with LANCZOS resample which not yet supported for torch.Tensor. BICUBIC resample will be used as an alternative. Please fall back to slow image processor if you want full consistency with the original model.r   )pil_torch_interpolation_mapping)r   sizeresampler   )r&   tvFInterpolationModeintBILINEARr   LANCZOSloggerwarning_onceBICUBICimage_utilsr7   r   resize)r   r   r8   r9   r   interpolationr7   r   s          r   rC   ChameleonImageProcessor.resizeK   s     #8c.C.CS-IJJHPSPePePnPn 	 11::M"455-555##E
 !$ 5 5 = =J ? Iw~WE}WPVWWr   r   )r   torch.Tensorr8   r   r9   z7PILImageResampling | tvF.InterpolationMode | int | Noner   rF   )__name__
__module____qualname____firstlineno____doc__r   r>   r9   
image_mean	image_stdr8   default_to_square	crop_size	do_resizedo_center_crop
do_rescalerescale_factordo_normalizedo_convert_rgbr
   r	   r   r   r4   rC   __static_attributes____classcell__)r   s   @r   r   r   "   s    G!))H JIS!D-IINJNLN#!5 #CJ C: C*XX X L	X 
X Xr   r   )rK   numpyr*   	PIL.Imager'   torchtorchvision.transforms.v2r   r:   image_processing_backendsr   rB   r   r   r   processing_utilsr	   r
   utilsr   r   
get_loggerrG   r?   r   __all__r   r   r   <module>ra      sj    +    7 ; 
 5 , 
		H	% BX0 BX BXJ %
%r   