
    .~hS$                         d Z ddlmZmZ ddlmZmZ 	 eZddl
mZ dZd Zd Zdd
Zd Zd ZddZddZddZy	# e	$ r Y ,w xY w)z]Utility functions useful for writers or QR Code objects.

DOES NOT belong to the public API.
    )absolute_importunicode_literals)chainrepeat   )consts)get_default_border_size
get_borderget_symbol_sizecheck_valid_scalecheck_valid_bordermatrix_to_linesmatrix_itermatrix_iter_verbosec                 (    | \  }}|dkD  r||k(  rdS dS )z    Returns the default border size (quiet zone) for the provided version.

    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :rtype: int
              )matrix_sizewidthheights      T/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/segno/utils.pyr	   r	      s$      ME6
u15A5    c                      ||S t        |       S )a&      Returns `border` if not ``None``, otherwise the default border size for
    the provided QR Code.

    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param border: The size of the quiet zone or ``None``.
    :type border: int or None

    :rtype: int
    r	   )r   borders     r   r
   r
   &   s     '6Q-D[-QQr   Nc                 Z    |t        |       }| \  }}|d|z  z  }|d|z  z  }||z  ||z  fS )a      Returns the symbol size (width x height) with the provided border and
    scaling factor.

    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param scale: Indicates the size of a single module (default: 1).
            The size of a module depends on the used output format; i.e.
            in a PNG context, a scaling factor of 2 indicates that a module
            has a size of 2 x 2 pixel. Some outputs (i.e. SVG) accept
            floating point values.
    :type scale: int or float
    :param int border: The border size or ``None`` to specify the
            default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
    :rtype: tuple (width, height)
    r   r   )r   scaler   r   r   s        r   r   r   4   sK      ~(5ME6	QZE
a&jF5=&5.((r   c                 B    | dk  rt        dj                  |             y)z    Raises a :py:exc:`ValueError` iff `scale` is negative or zero.

    :param scale: Scaling factor.
    :type scale: float or int
    r   z2The scale must not be negative or zero. Got: "{0}"N)
ValueErrorformat)r   s    r   r   r   L   s(     zMTTUZ[\\ r   c                 d    | .t        |       | k7  s| dk  rt        dj                  |             yy)z    Raises a :py:exc:`ValueError` iff `border` is negative.

    :param int border: Indicating the size of the quiet zone.
    Nr   z<The border must not a non-negative integer value. Got: "{0}")intr!   r"   )r   s    r   r   r   W   s<     s6{f4
W^^_efgg 9Cr   c              #      K   ||z  }d}| D ]B  }||}}||z  }|D ]#  }||k7  r|s||f||ff |}|dz  }|s|dz  }|}% |s7||f||ff d}D yw)a      Converts the `matrix` into an iterable of ((x1, y1), (x2, y2)) tuples which
    represent a sequence (horizontal line) of dark modules.

    The path starts at the 1st row of the matrix and moves down to the last row.

    :param matrix: An iterable of bytearrays.
    :param x: Initial position on the x-axis.
    :param y: Initial position on the y-axis.
    :param incby: Value to move along the y-axis (default: 1).
    :rtype: iterable of (x1, y1), (x2, y2) tuples
    r   r   Nr   )	matrixxyincbylast_bitrowx1x2bits	            r   r   r   a   s      JAH AB	U
 	C3s1gAw&&!GBaH	 q'B7""Hs   A AAc              #   v  K   t        |       t              t               t        ||      }|\  }dgz  }t	        | |z         t	        | ||z         }}|D ]U  }d|cxk  r|k  rn n| |   n|t        t        j                  fd|D                    }	t        d      D ]  }
|	  W yw)al      Returns an iterator / generator over the provided matrix which includes
    the border and the scaling factor.

    If either the `scale` or `border` value is invalid, a :py:exc:`ValueError`
    is raised.

    :param matrix: An iterable of bytearrays.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param int scale: The scaling factor (default: ``1``).
    :param int border: The border size or ``None`` to specify the
            default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
    :raises: :py:exc:`ValueError` if an illegal scale or border value is provided
    r   c              3   \   K   | ]#  }t        d |cxk  rk  rn n|   nd        % yw)r   Nr   ).0jrr   r   s     r   	<genexpr>zmatrix_iter.<locals>.<genexpr>   s*     'l[\qA~~qt3PU(V'ls   ),N)	r   r$   r   r
   rangetupler   from_iterabler   )r&   r   r   r   r   
border_rowwidth_rangeheight_rangeir+   sr4   r   s     `        @@r   r   r      s      vJEeV,FME6J %vguv~ >vgvX^@_K a&F1IjE'''l`k'llme$ 	AI	s   B4B9c              #      	
K   ddl m} t        |       t              t	               t        ||      }|\  k(  xr dk  |j                  dd      	|j                  	|       	 fd
t        | |z         t        | |z         }}|D ]@  t        t        j                  
fd|D                    }t        d      D ]  }|  B yw)	a      Returns an iterator / generator over the provided matrix which includes
    the border and the scaling factor.

    This iterator / generator returns different values for dark / light modules
    and therefor the different parts (like the finder patterns, alignment patterns etc.)
    are distinguishable. If this information isn't necessary, use the
    :py:func:`matrix_iter()` function because it is much cheaper and faster.

    If either the `scale` or `border` value is invalid, a py:exc:`ValueError`
    is raised.

    :param matrix: An iterable of bytearrays.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param int scale: The scaling factor (default: ``1``).
    :param int border: The border size or ``None`` to specify the
            default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
    :raises: :py:exc:`ValueError` if an illegal scale or border value is provided
    r   )encoder   F)reserve_regions
add_timingc                    d| cxk  rk  r.n t         j                  S d|cxk  r	k  rn t         j                  S |    |   }s|    |   }|dk7  r#t         j                  t         j                  f|   S rY	dkD  rT| dk  r	dz
  |cxk  r	dz
  k  sn dz
  | cxk  rdz
  k  r+n n(|dk  r#t         j                  t         j                  f|   S | dz
  k(  r|dk(  rt         j
                  S s*| dk(  rd|cxk  r	dz
  k  s-n |dk(  rd| cxk  rdz
  k  sn r7| dk(  r|dkD  s
|dk(  r(| dkD  r#t         j                  t         j                  f|   S | dk(  r|dk  ss|	d	z
  kD  s|dk(  r2| dk  s
s+| dz
  kD  r#t         j                  t         j                  f|   S | dk  r|dk  ss|	dz
  kD  ss0| dz
  kD  r(|dk  r#t         j                  t         j                  f|   S | dk  r|dk  ss|	dz
  kD  ss| dz
  kD  r|dk  rt         j                  S t         j                  t         j                  f|   S t         j                  S )
Nr   r   )               	   
   )r   TYPE_ALIGNMENT_PATTERN_LIGHTTYPE_ALIGNMENT_PATTERN_DARKTYPE_VERSION_LIGHTTYPE_VERSION_DARKTYPE_DARKMODULETYPE_TIMING_LIGHTTYPE_TIMING_DARKTYPE_FORMAT_LIGHTTYPE_FORMAT_DARKTYPE_FINDER_PATTERN_LIGHTTYPE_FINDER_PATTERN_DARKTYPE_SEPARATORTYPE_DATA_LIGHTTYPE_DATA_DARKTYPE_QUIET_ZONE)
r<   r3   valalignment_valalignment_matrixr   is_micro	is_squarer&   r   s
       r   get_bitz$matrix_iter_verbose.<locals>.get_bit   s_   ?F?D )))E  !A~~D )))C )A,C 0 3A 6 C'"??AcAcderss1ua!;%!)!;%{Q;!;A & 9 96;S;STUXYY
?qAv!111!q&Q->UQY->AFqSTOaW]`aWaOaQ!VAaAE00&2I2IJ3OOAv1q5a%"*nAv1q5Q!^00&2I2IJ3OO 1u!a%Q]#FQJ1q588&:Y:YZ[^__ 1u!a%Q]#VaZAE,,,**F,A,AB3GG)))r   c              3   D   K   | ]  }t         |              y w)Nr1   )r2   r3   r_   r<   r   s     r   r5   z&matrix_iter_verbose.<locals>.<genexpr>   s     'Zwq!}e(D'Zs    N)segnor?   r   r$   r   r
   make_matrixadd_alignment_patternsr6   r7   r   r8   r   )r&   r   r   r   r?   r:   r;   r+   r=   r\   r_   r   r<   r]   r^   r   s   ` `      @@@@@@@r   r   r      s     ( vJEeV,FME6I'URZH**5&%\a*b""#3[A$* $*L !&vguv~ >vgvX^@_K E'''Zk'ZZ[e$ 	AI	s   CC))r   N)r   )__doc__
__future__r   r   	itertoolsr   r   xranger6   	NameError r   __all__r	   r
   r   r   r   r   r   r   r   r   r   <module>rk      si   
 9 #	E 1
6R)0]h>:JW  		s   ; AA