ó
    /j-jØ  ã                   ó–   • % S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  \\\
S.r\\\\   4   \S	'    " S
 S\5      r " S S5      rg)z>Classes and functions for the ImageConversionBackend backends.é    )ÚAnyé   )ÚConversionBackend)ÚGhostscriptBackend)ÚPdfiumBackend)ÚPopplerBackend)ÚpdfiumÚghostscriptÚpopplerÚBACKENDSc                   ó   • \ rS rSrSrg)ÚImageConversionErroré   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    Ú^/home/mande/repo/quber/.venv/lib/python3.13/site-packages/camelot/backends/image_conversion.pyr   r      s   † Úr   r   c            	       ól   • \ rS rSrSrSS\S\SS4S jjrS rSS	\	S
\	S\
SS4S jjrSS	\	S\
4S jjrSrg)ÚImageConversionBackendé   z+Classes the ImageConversionBackend backend.ÚbackendÚuse_fallbackÚreturnNc                 óž   ^• U R                  T5      U l        X l        [        [	        U4S j[
        R                  5       5      5      U l        g)a5  Initialize the conversion backend .

Parameters
----------
backend : Any, optional
    Backend for image conversion, by default "pdfium"
use_fallback : bool, optional
    Fallback to another backend if unavailable, by default True

Raises
------
ValueError
    Raise an error if the backend is not supported.
c                 ó<   >• [        T[        5      =(       a    U T:g  $ )N)Ú
isinstanceÚstr)Úxr   s    €r   Ú<lambda>Ú1ImageConversionBackend.__init__.<locals>.<lambda>*   s   ø€ œZ¨´Ó5×F¸!¸w¹,ÐFr   N)Úget_backendr   r   ÚlistÚfilterr   ÚkeysÚ	fallbacks)Úselfr   r   s    ` r   Ú__init__ÚImageConversionBackend.__init__   s:   ø€ ð +/×*:Ñ*:¸7Ó*CˆŒØ".ÔÜ$(ÜÔFÌÏÉËÓXó%
ˆ�r   c                 óà   ^• U4S jn[        T[        5      (       a6  T[        R                  5       ;  a  [	        ST< S35      e[        T   " 5       $ U" 5       (       d  [	        T< S35      eT$ )aÄ  Retrieve the specified backend for processing.

This method checks if the provided backend is a string representing
a known backend or an object implementing a 'convert' method. It
returns an instance of the backend if valid.

Parameters
----------
backend : str or object
    The backend to retrieve. This can be:
        - A string ('poppler' or 'ghostscript') corresponding to a pre-defined backend.
        - An object that must implement a 'convert' method.

Returns
-------
object
    An instance of the specified backend.

Raises
------
NotImplementedError
    If the backend is a string that is not recognized or if it is an
    object that does not implement the 'convert' method.

Examples
--------
>> backend_instance = get_backend('poppler')
>> backend_instance = get_backend(my_custom_backend)

Notes
-----
The valid backends are defined in the BACKENDS dictionary. The
method verifies the backend type and raises exceptions for
unsupported backends.
c                  óx   >• [        T5       V s/ s H  o R                  S5      SL d  M  U PM     nn SU;   $ s  sn f )NÚ__FÚconvert)ÚdirÚ
startswith)ÚmethodÚmethodsr   s     €r   Úimplements_convertÚ>ImageConversionBackend.get_backend.<locals>.implements_convertR   sF   ø€ ä%(¨¤\óÚ%1˜6×5FÑ5FÀtÓ5LÐPUÐ5U—¡\ð ð ð  Ñ'Ð'ùòs   �7ª7zUnknown backend z< specified. Please use 'pdfium', 'poppler' or 'ghostscript'.z" must implement a 'convert' method)r    r!   r   r(   ÚNotImplementedError)r*   r   r5   s    ` r   r%   Ú"ImageConversionBackend.get_backend-   sx   ø€ õJ	(ô �gœs×#Ñ#ØœhŸm™m›oÓ-Ü)Ø& w¡kÐ1mÐnóð ô ˜GÒ$Ó&Ð&á%×'Ñ'Ü)Ø‘kÐ!CÐDóð ð ˆNr   Úpdf_pathÚpng_pathÚpagec                 ó‚  •  U R                   R                  XUS9  g! [         a—  nU R                  (       ab  U R                   HM  n [
        U   " 5       nUR                  XUS9     SnAg! [         a  nSU< SU 3n[        U5      UeSnAff = f    SnAgSU R                   < SU 3n[        U5      UeSnAff = f)a  Convert PDF to png_path.

Parameters
----------
pdf_path : str
    Path where to read the pdf file.
png_path : str
    Path where to save png file.
page: int, optional
    Single page to convert.

Raises
------
type
    [description]
type
    [description]
©r;   z6Image conversion failed with image conversion backend ú	
 error: N)r   r0   Ú	Exceptionr   r)   r   r   )	r*   r9   r:   r;   ÚfÚfallbackÚ	converterÚeÚmsgs	            r   r0   ÚImageConversionBackend.convertg   sÏ   € ð&	7Ø�L‰L× Ñ  ¸$Ð Ò?øÜó 	7Ø× × Ø $§¤�HðÜ$,¨XÒ$6Ó$8˜	Ø!×)Ñ)¨(À4Ð)ÑHõ
 øô	 %ó ?Ø VÐW_ÑVbÐblÐmnÐloÐp˜Ü2°3Ó7¸QÐ>ûð?úö	 !/ð OÈtÏ|É|ÑN^Ð^hÐijÐhkÐl�Ü*¨3Ó/°QÐ6ûð	7ús>   ‚ �
B>§ B9ÁA,Á&B9Á,
BÁ6BÂBÂB9ÂB9Â9B>c                 ób  • [        U R                  S5      (       a   U R                  R                  XS9$ SSKnSSKJn  U" S	S
5      nU R                  XUS9  UR                  U5      $ ! [         a:  nU R                  (       d  SU R                  < SU 3n[        U5      Ue SnANsSnAff = f)u°  Render a page to an in-memory BGR ndarray, skipping the PNG file.

Uses the backend's native in-memory render (``to_array``) when it
has one â€” pdfium does, which avoids the PNG encode+decode that
``convert`` + ``cv2.imread`` would otherwise pay. Backends that can
only write files (ghostscript/poppler) transparently fall back to
``convert`` into a temp PNG and read it back, so behaviour is
identical, just without the speed-up.
Úto_arrayr=   z%Image conversion failed with backend r>   Nr   é   )Úbuild_file_path_in_temp_dirÚicb_to_arrayz.png)Úhasattrr   rG   r?   r   r   Úcv2ÚutilsrI   r0   Úimread)r*   r9   r;   r@   rD   rL   rI   r:   s           r   rG   ÚImageConversionBackend.to_array‹   s¬   € ô �4—<‘< ×,Ñ,ð;Ø—|‘|×,Ñ,¨XÐ,ÐAÐAó 	å7á.¨~¸vÓFˆØ�‰�X¨dˆÑ3Ø�z‰z˜(Ó#Ð#øô ó ;Ø×(×(ØAÀ$Ç,Á,ÑAQÐQ[Ð\]Ð[^Ð_�CÜ.¨sÓ3¸Ð:ô )ûð;ús   �A* Á*
B.Á40B)Â)B.)r   r)   r   )r	   T)r   )r   r   r   r   Ú__doc__r   Úboolr+   r%   r!   Úintr0   rG   r   r   r   r   r   r      s_   † Ù5ñ
 ð 
¸dð 
Èdõ 
ò*8ñt"7 ð "7¨sð "7¸#ð "7Àdõ "7ñH$ ð $¨C÷ $ð $r   r   N)rP   Útypingr   Úbaser   Úghostscript_backendr   Úpdfium_backendr   Úpoppler_backendr   r   Údictr!   ÚtypeÚ__annotations__Ú
ValueErrorr   r   r   r   r   Ú<module>r\      sX   ðÚ Då å #Ý 3Ý )Ý +ð Ø%Øñ0€ˆ$ˆs�DÐ*Ñ+Ð+Ñ
,ó ô	˜:ô 	÷O$ò O$r   