
    %^g                     @    d dl mZ d dlmZ d dlmZmZ  G d d      Zy)    )settings)toint)
parse_cropparse_cropboxc                       e Zd ZdZd Zd Zd Zd!dZd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd"dZd Zd Zd Z d  Z!y)#
EngineBasez7
    ABC for Thumbnail engines, methods are static
    c                 Z   | j                  |||      }| j                  |||      }| j                  |||      }| j                  ||      }| j	                  |||      }| j                  |||      }| j                  |||      }| j                  |||      }| j                  |||      }|S )zY
        Processing conductor, returns the thumbnail as an image engine instance
        )	cropboxorientation
colorspaceremove_borderscalecroproundedblurpaddingselfimagegeometryoptionss       _/var/www/html/webapps/promises/venv/lib/python3.12/site-packages/sorl/thumbnail/engines/base.pycreatezEngineBase.create   s     UHg6  ':x9""5'2

5(G4		%73UHg6		%73UHg6    c                 ^    |d   }|s|S t        |      \  }}}}| j                  |||||      S )z*
        Wrapper for ``_cropbox``
        r
   )r   _cropbox)	r   r   r   r   r
   xyx2y2s	            r   r
   zEngineBase.cropbox   s?     )$L$W-1b"}}UAq"b11r   c                 v    |j                  dt        j                        r| j                  |      S d| _        |S )z.
        Wrapper for ``_orientation``
        r   T)getr   THUMBNAIL_ORIENTATION_orientation
reorientedr   s       r   r   zEngineBase.orientation$   s5     ;;}h&D&DE$$U++r   Nc                     |xs i }t        | d      }|j                  dt        j                        r|s| j	                  |      S y)Nr%   r   F)hasattrr"   r   r#   _flip_dimensions)r   r   r   r   r%   s        r   flip_dimensionszEngineBase.flip_dimensions-   sA    -RT<0
;;}h&D&DEj((//r   c                 0    |d   }| j                  ||      S )z-
        Wrapper for ``_colorspace``
        r   )_colorspace)r   r   r   r   r   s        r   r   zEngineBase.colorspace4   s!     \*
z22r   c                 x    |j                  dd      r'| j                  |      \  }}| j                  |||      }|S )Nr   F)r"   get_image_size_remove_border)r   r   r   x_imagey_images        r   r   zEngineBase.remove_border;   s>    ;;.#2259GW''w@Er   c                 \    |d   }|d   |z  |d   |z  f}|rt        |      S t        |      S )Nr   r      )maxmin)r   r/   r0   r   r   r   factorss          r   _calculate_scaling_factorz$EngineBase._calculate_scaling_factorC   s<    vA;((1+*?@#s7|5W5r   c                    |d   }t        t        | j                  |            \  }}| j                  |      r||}}| j	                  ||||      }|dk  s|r/t        ||z        }t        ||z        }	| j                  |||	      }|S )z(
        Wrapper for ``_scale``
        upscaler2   )mapfloatr-   r)   r6   r   _scale)
r   r   r   r   r8   r/   r0   factorwidthheights
             r   r   zEngineBase.scaleH   s     )$ud&9&9%&@A&&WG//(GTA:'F*+E7V+,FKKuf5Er   c                    |d   }| j                  |      \  }}|r|dk(  r|S |dk(  r| j                  ||d   |d   ||      S t        ||d         t        ||d         f}t        |||f|      \  }}| j	                  ||d   |d   ||      S )z'
        Wrapper for ``_crop``
        r   noopsmartr   r2   )r-   _entropy_cropr4   r   _crop)	r   r   r   r   r   r/   r0   x_offsety_offsets	            r   r   zEngineBase.cropY   s     v..u5tv~LW_ %%eXa[(1+wPWXX !-s7HQK/HI'w.@(K(zz%!hqk8XNNr   c                 J    |d   }|s|S | j                  |t        |            S )z*
        Wrapper for ``_rounded``
        r   )_roundedint)r   r   r   r   rs        r   r   zEngineBase.roundedl   s+     IL}}UCF++r   c                 |    |j                  d      r*| j                  |t        |j                  d                  S |S )z'
        Wrapper for ``_blur``
        r   )r"   _blurrH   r   s       r   r   zEngineBase.bluru   s4     ;;v::eSV)<%=>>r   c                 v    |j                  d      r'| j                  |      |k7  r| j                  |||      S |S )z*
        Wrapper for ``_padding``
        r   )r"   r-   _paddingr   s       r   r   zEngineBase.padding}   s:     ;;y!d&9&9%&@H&L=='::r   c                     |d   }|d   }|j                  di       }|j                  dt        j                        }| j                  |||||      }|j	                  |       y)z(
        Wrapper for ``_write``
        formatquality
image_infoprogressive)rQ   rR   N)r"   r   THUMBNAIL_PROGRESSIVE_get_raw_datawrite)	r   r   r   	thumbnailformat_rP   rQ   rR   raw_datas	            r   rU   zEngineBase.write   sn     (#)$[[r2
kk-1O1OP%%7G!# & 

 	!r   c                      y)zCSome backends need to manually cleanup after thumbnails are createdN r   r   s     r   cleanupzEngineBase.cleanup   s    r   c                     |d   }|rt        |      \  }}}}||z
  }||z
  }n| j                  |      \  }}t        |      |z  }| j                  |      rd|z  }|S )zl
        Calculates the image ratio. If cropbox option is used, the ratio
        may have changed.
        r
   g      ?)r   r-   r:   r)   )	r   r   r   r
   r   r   r   r    ratios	            r   get_image_ratiozEngineBase.get_image_ratio   sr    
 )$(1LAq"bQAQA&&u-DAqa1&%KEr   c                     i S )z;
        Returns metadata of an ImageFile instance
        rZ   r[   s     r   get_image_infozEngineBase.get_image_info   s	     	r   c                     t               )zN
        Returns the backend image objects from an ImageFile instance
        NotImplementedError)r   sources     r   	get_imagezEngineBase.get_image        "##r   c                     t               )z?
        Returns the image width and height as a tuple
        rc   r[   s     r   r-   zEngineBase.get_image_size   rg   r   c                     t               )zE
        Checks if the supplied raw data is valid image data
        rc   )r   rX   s     r   is_valid_imagezEngineBase.is_valid_image   rg   r   c                     |S )zP
        Read orientation exif data and orientate the image accordingly
        rZ   r[   s     r   r$   zEngineBase._orientation   s	     r   c                     t               )z
        `Valid colorspaces
        <http://www.graphicsmagick.org/GraphicsMagick.html#details-colorspace>`_.
        Backends need to implement the following::

            RGB, GRAY
        rc   )r   r   r   s      r   r+   zEngineBase._colorspace   s     "##r   c                     t               )z.
        Remove borders around images
        rc   )r   r   image_widthimage_heights       r   r.   zEngineBase._remove_border   rg   r   c                     t               )zi
        Crop the image to the correct aspect ratio
        by removing the lowest entropy parts
        rc   )r   r   geometry_widthgeometry_heightrn   ro   s         r   rB   zEngineBase._entropy_crop       
 "##r   c                     t               )z0
        Does the resizing of the image
        rc   )r   r   r=   r>   s       r   r;   zEngineBase._scale   rg   r   c                     t               )z!
        Crops the image
        rc   )r   r   r=   r>   rD   rE   s         r   rC   zEngineBase._crop   rg   r   c                     t               )zu
        Gets raw data given the image, format and quality. This method is
        called from :meth:`write`
        rc   )r   r   rW   rP   rQ   rR   s         r   rT   zEngineBase._get_raw_data   rs   r   c                     t               )z 
        Pads the image
        rc   r   s       r   rM   zEngineBase._padding   rg   r   c                     t               Nrc   )r   r   r   r   r   r    s         r   r   zEngineBase._cropbox       !##r   c                     t               ry   rc   )r   r   rI   s      r   rG   zEngineBase._rounded  rz   r   c                     t               ry   rc   )r   r   radiuss      r   rK   zEngineBase._blur  rz   r   )NN)NF)"__name__
__module____qualname____doc__r   r
   r   r)   r   r   r6   r   r   r   r   r   rU   r\   r_   ra   rf   r-   rj   r$   r+   r.   rB   r;   rC   rT   rM   r   rG   rK   rZ   r   r   r   r      s    236
"O&," *$$$$$$$$$$$$$r   r   N)sorl.thumbnail.confr   sorl.thumbnail.helpersr   sorl.thumbnail.parsersr   r   r   rZ   r   r   <module>r      s    ( ( <$ $r   