
    /~h64                        d Z ddlmZmZmZ ddlZddlZddlmZm	Z	m
Z
 ddlmZ 	 ddlmZ 	 ddlmZ dZ	 ddlZd	Zd
Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZd ZesddZyy# e$ r	 ddlmZ Y ?w xY w# e$ r eZY Ew xY w# e$ r Y Gw xY w)z~Segno writer plugin to convert a (Micro) QR code into a Pillow Image and
and to add (animated) background images to QR codes.
    )absolute_importunicode_literalsdivisionN)Image	ImageDrawImageSequence)consts)LANCZOS)UnidentifiedImageErrorFTz3.0.0c                     t        j                         }| j                  |d|||||||||	|
|||||||||       |j                  d       t	        j
                  |      S )a	      Converts the provided `qrcode` into a Pillow image.

    If any color is ``None`` use the Image.info dict to detect which
    pixel / palette entry represents a transparent value.

    See `Colorful QR Codes <https://segno.readthedocs.io/en/stable/colorful-qrcodes.html>`_
    for a detailed description of all module colors.

    :param segno.QRCode qrcode: The QR code.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :param border: Integer indicating the size of the quiet zone.
            If set to ``None`` (default), the recommended border size
            will be used (``4`` for QR Codes, ``2`` for Micro QR Codes).
    :param dark: Color of the dark modules (default: black). The
            color can be provided as ``(R, G, B)`` tuple, as hexadecimal
            format (``#RGB``, ``#RRGGBB`` ``RRGGBBAA``), or web color
            name (i.e. ``red``).
    :param light: Color of the light modules (default: white).
            See `color` for valid values. If light is set to ``None`` the
            light modules will be transparent.
    :param finder_dark: Color of the dark finder modules (default: same as ``dark``)
    :param finder_light: Color of the light finder modules (default: same as ``light``)
    :param data_dark: Color of the dark data modules (default: same as ``dark``)
    :param data_light: Color of the light data modules (default: same as ``light``)
    :param version_dark: Color of the dark version modules (default: same as ``dark``)
    :param version_light: Color of the light version modules (default: same as ``light``)
    :param format_dark: Color of the dark format modules (default: same as ``dark``)
    :param format_light: Color of the light format modules (default: same as ``light``)
    :param alignment_dark: Color of the dark alignment modules (default: same as ``dark``)
    :param alignment_light: Color of the light alignment modules (default: same as ``light``)
    :param timing_dark: Color of the dark timing pattern modules (default: same as ``dark``)
    :param timing_light: Color of the light timing pattern modules (default: same as ``light``)
    :param separator: Color of the separator (default: same as ``light``)
    :param dark_module: Color of the dark module (default: same as ``dark``)
    :param quiet_zone: Color of the quiet zone modules (default: same as ``light``)
    png)kindscaleborderdarklightfinder_darkfinder_light	data_dark
data_lightversion_darkversion_lightformat_darkformat_lightalignment_darkalignment_lighttiming_darktiming_light	separatordark_module
quiet_zoner   )ioBytesIOsaveseekr   open)qrcoder   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   buffs                        X/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/qrcode_artistic.py	write_pilr*   #   so    ^ ::<D
KK5f4<#
)'l-'l#  U 	IIaL::d    c           	      
  89 t        |      }|}|dz  r|dz  }|dz  rt        | fi d|d|d|d|	d|
d|d	|d
|d|d|d|d|d|d|d|d|d|d|d|j                  d      }| j                  |d      \  }}|rddl}|j                  dt               |}	 t        j                  |      }|j                  }|g} d}!|3	 |j                  }"|"|"j                  d      dz   d j                         }#n|j                         }#|#dv }$	 |$xr |j                   }!d}%d}&|!r|j"                  j%                  dd      }&| j'                  t)        j*                  |      D 'cg c]  }'|'j-                          c}'       | D (cg c]  }(|(j"                  j%                  d d        }%}(||n| j.                  }| d   j0                  \  98t3        |9z  |8z        })t        9|)z        t        8|)z        c98t        j4                  d||fd!      }*g }+89fd"| D        D ]  }(|*j-                         }|+j7                  |       t        t9        j:                  ||(j0                  d   z
  d#z              t        t9        j:                  ||(j0                  d   z
  d#z              f},|j=                  |(|,        |+} |g}-|-j'                  |j-                         gt?        |       dz
  z         |-D (cg c]!  }(tA        jB                  |(      jD                  # }.}(tF        jH                  tF        jJ                  tF        jL                  tF        jN                  tF        jP                  tF        jR                  tF        jT                  f}/||z  }0|dz  }1tW        | jY                  |dd$%            D ]t  \  }2}3tW        |3      D ]a  \  }4}5|5|/v r|2|1z  dz  dk(  r|4|1z  dz  dk(  r"tW        |       D ]2  \  }6}(|(j[                  |2|4f      }7|7d   s |.|6   |2|0z   |4|0z   f|7       4 c v ||k7  ro||c98| j                  ||      \  }}t3        |9z  |8z        })t        9|)z        t        8|)z        c98|-D (cg c]  }(|(j]                  98ft^               }-}(|$|dk7  r|-D (cg c]  }(|(j                  |       }-}(n ||-D (cg c]  }(|(j                  |       }-}(|!r|-d   ja                  |||%d$|-dd |&&       y|-d   ja                  ||'       y# t        $ r t        |||      }Y |w xY w# t        $ r |}"Y nw xY w# t        $ r Y 3w xY wc c}'w c c}(w c c}(w c c}(w c c}(w c c}(w )(a5      Saves the QR code with the background image into target.

    :param segno.QRCode qrcode: The QR code.
    :param background: Path to the background image.
    :param target: A filename or a writable file-like object with a
                    ``name`` attribute. Use the ``kind`` parameter if
                    `target` is a :py:class:`io.BytesIO` stream which does not
                    have ``name`` attribute.
    :param str mode: `Image mode <https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes>`_
    :param str kind: Optional image format (i.e. 'PNG') if the target provides no
            information about the image format.
    :param int scale: The scale. A minimum scale of 3 (default) is recommended.
            The best results are achieved with a scaling of more than 3 and a
            scaling divisible by 3. If a floating number is provided it is converted to an integer (1.5 becomes 1)
    :param int border: Number indicating the size of the quiet zone.
            If set to ``None`` (default), the recommended border size
            will be used (``4`` for QR Codes, ``2`` for Micro QR Codes).
    :param dark: Color of the dark modules (default: black). The
            color can be provided as ``(R, G, B)`` tuple, as hexadecimal
            format (``#RGB``, ``#RRGGBB`` ``RRGGBBAA``), or web color
            name (i.e. ``red``).
    :param light: Color of the light modules (default: white).
            See `color` for valid values. If light is set to ``None`` the
            light modules will be transparent.
    :param finder_dark: Color of the dark finder modules (default: same as ``dark``)
    :param finder_light: Color of the light finder modules (default: same as ``light``)
    :param data_dark: Color of the dark data modules (default: same as ``dark``)
    :param data_light: Color of the light data modules (default: same as ``light``)
    :param version_dark: Color of the dark version modules (default: same as ``dark``)
    :param version_light: Color of the light version modules (default: same as ``light``)
    :param format_dark: Color of the dark format modules (default: same as ``dark``)
    :param format_light: Color of the light format modules (default: same as ``light``)
    :param alignment_dark: Color of the dark alignment modules (default: same as ``dark``)
    :param alignment_light: Color of the light alignment modules (default: same as ``light``)
    :param timing_dark: Color of the dark timing pattern modules (default: same as ``dark``)
    :param timing_light: Color of the light timing pattern modules (default: same as ``light``)
    :param separator: Color of the separator (default: same as ``light``)
    :param dark_module: Color of the dark module (default: same as ``dark``)
    :param quiet_zone: Color of the quiet zone modules (default: same as ``light``)
          r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   RGBAr   )r   r   Nz&Using format is deprecated, use "kind")widthheightF.)gifr   webploopduration)   r   r   r   c              3   N   K   | ]  }|j                  ft                y w)N)resizer
   ).0img	bg_heightbg_widths     r)   	<genexpr>z!write_artistic.<locals>.<genexpr>   s!     Ps

Hi0':Ps   "%   T)r   r   verbose)formaturationsave_allappend_imagesr5   )rA   )1intr*   convertsymbol_sizewarningswarnDeprecationWarningr   r&   r   _svg_to_pngmodenameAttributeErrorrfindloweris_animatedinfogetextendr   Iteratorcopydefault_border_sizesizeminnewappendmathceilpastelenr   Drawpointr	   TYPE_FINDER_PATTERN_DARKTYPE_FINDER_PATTERN_LIGHTTYPE_SEPARATORTYPE_ALIGNMENT_PATTERN_DARKTYPE_ALIGNMENT_PATTERN_LIGHTTYPE_TIMING_DARKTYPE_TIMING_LIGHT	enumeratematrix_itergetpixelr9   r
   r$   ):r'   
backgroundtargetrL   rA   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   requested_scaleqr_imgmax_bg_widthmax_bg_heightrH   bg_img
input_mode	bg_imagesrQ   fnameexttarget_supports_animation	durationsr5   framer;   ratiobg_tpltmp_bg_imagespos
res_imagesdraw_functionskeep_modulesborder_offsetdirowjmimg_idxfillr<   r=   s:                                                           @@r)   write_artisticr   _   s   ` JEO
!)
 !)v .U .6 . .E ._j .$0.<E.R\.kw.%2.@K.Zf. '5. GV. do. %1	. =F	. T_	.
 #-.
 /6gfo  #)"4"45"4"KL->@RSSJ' JIK|	KKE EKK$q()*002jjl #'= =/FF4F4F ID{{vq)M4J4J64RS5%**,ST<EFSSXX\\*a0F	F)Vv/I/IF#A,++Hix')BCEh./Y5F1GHiYYvm<nMFMPiP V$499lSXXa[8A=>?TYYP]`c`h`hij`kPkopOpEqArsS#	
 IJv{{}oY!);<=;EFCinnS)//FNF33V5U5UW]WlWl668[8[]c]t]t,,.L UNM
AF..U1d.ST ^3cN 	^DAqL 1f\Q&a1f\Q->$-i$8 ^LGS<<A/DAw/w/]1BADU0VX\]^		^^ *M)&,&8&8W]&8&^#mL8+]Y-FG!(U"23SU9J5K)LVWScjj(I!6@W
W|
f,9CD#ckk*-D
D		3=>Cckk$'>
>16$	D`jklkm`n $ 	 	& 	16$/I " SZ|MRS  	E	   TF  G( XD>sZ   'T T< U +U#U#<&U( U-,U2U7T98T9<U
U	UUc                    t        j                         }	 | j                   t	        | d      5 }t        j                  ||       ddd       |j                  d       t        j                  |      }|j                  \  }}t        ||z  ||z        }t        ||z        t        ||z        }
}	t        j                         }t	        | d      5 }t        j                  |||	|
       ddd       |j                  d       t        j                  |      S # t        $ r Y w xY w# 1 sw Y   xY w# 1 sw Y   KxY w)z    Converts the SVG source into a PNG and returns a PIL.Image

    :param source: The SVG source.
    :param width: The target width.
    :param height: The target height.
    :return: Image.
    rb)file_objwrite_toNr   )r   r   output_widthoutput_height)r"   r#   rM   rN   r&   cairosvgsvg2pngr%   r   rX   rY   rE   )sourcer0   r1   outfr;   	svg_width
svg_heightrz   whs              r)   rK   rK      s    **,C 
fd	 3q!c23HHQK
**S/CHHIz	!6J#67Ey5 !3zE'9#:qA
**,C	fd	 Tq!cQRSTHHQK::c?  3 3T Ts(   D D)D5	D&%D&)D25D>c                     t        d      )Nz$cairosvg is required for SVG support)
ValueError)r   r0   r1   s      r)   rK   rK     s    ?@@r+   )r.   N#000#fffFFFFFFFFFFFFFFF)NNNr-   Nr   r   FFFFFFFFFFFFFFF)NN)__doc__
__future__r   r   r   r"   r\   PILr   r   r   segnor	   PIL.Image.Resamplingr
   ImportError	PIL.Imager   IOError_SVG_SUPPORTr   __version__r*   r   rK    r+   r)   <module>r      s    C B 	  / / ",%* 	L  @F?DBGDIEJ=B9x MQ<BDIGLINJOBGG0T8 A e  "!"  %$%  		s3   A A/ A< A,+A,/A98A9<BB