§
    ‘Mºf²*  ã                   ó”   — d dl mZ ddlmZmZ d„ Zd„ Zd„ Z G d„ de¦  «        Zd	„ Z	d
„ Z
 G d„ de¦  «        Z G d„ de¦  «        ZdS )é   )Ú
BiffRecordé    )ÚpackÚunpackc                 ó,   — |                       |¦  «        S ©N)Ú	col_width)ÚsheetÚcols     úJ/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/xlwt/Bitmap.pyÚ	_size_colr      s   € Ø�?Š?˜3ÑÔÐó    c                 ó,   — |                       |¦  «        S r   )Ú
row_height)r
   Úrows     r   Ú	_size_rowr      s   € Ø×Ò˜CÑ Ô Ð r   c                 ób  — |t          | |¦  «        k    r,|t          | |¦  «        z  }|dz  }|t          | |¦  «        k    °,|t          | |¦  «        k    r,|t          | |¦  «        z  }|dz  }|t          | |¦  «        k    °,|}|}||z   dz
  }||z   dz
  }|t          | |¦  «        k    r,|t          | |¦  «        z  }|dz  }|t          | |¦  «        k    °,|t          | |¦  «        k    r,|t          | |¦  «        z  }|dz  }|t          | |¦  «        k    °,t          | |¦  «        dk    s<t          | |¦  «        dk    s(t          | |¦  «        dk    st          | |¦  «        dk    rdS t          t          |¦  «        t          | |¦  «        z  dz  ¦  «        }t          t          |¦  «        t          | |¦  «        z  dz  ¦  «        }t          t          |¦  «        t          | |¦  «        z  dz  ¦  «        }	t          t          |¦  «        t          | |¦  «        z  dz  ¦  «        }
||||||	||
fS )aú  Calculate the vertices that define the position of the image as required by
    the OBJ record.

             +------------+------------+
             |     A      |      B     |
       +-----+------------+------------+
       |     |(x1,y1)     |            |
       |  1  |(A1)._______|______      |
       |     |    |              |     |
       |     |    |              |     |
       +-----+----|    BITMAP    |-----+
       |     |    |              |     |
       |  2  |    |______________.     |
       |     |            |        (B2)|
       |     |            |     (x2,y2)|
       +---- +------------+------------+

    Example of a bitmap that covers some of the area from cell A1 to cell B2.

    Based on the width and height of the bitmap we need to calculate 8 vars:
        col_start, row_start, col_end, row_end, x1, y1, x2, y2.
    The width and height of the cells are also variable and have to be taken into
    account.
    The values of col_start and row_start are passed in from the calling
    function. The values of col_end and row_end are calculated by subtracting
    the width and height of the bitmap from the width and height of the
    underlying cells.
    The vertices are expressed as a percentage of the underlying cell width as
    follows (rhs values are in pixels):

           x1 = X / W *1024
           y1 = Y / H *256
           x2 = (X-1) / W *1024
           y2 = (Y-1) / H *256

           Where:  X is distance from the left side of the underlying cell
                   Y is distance from the top of the underlying cell
                   W is the width of the cell
                   H is the height of the cell

    Note: the SDK incorrectly states that the height should be expressed as a
    percentage of 1024.

    col_start  - Col containing upper left corner of object
    row_start  - Row containing top left corner of object
    x1  - Distance to left side of object
    y1  - Distance to top of object
    width  - Width of image frame
    height  - Height of image frame

    r   r   Ni   é   )r   r   ÚintÚfloat)r
   Ú	row_startÚ	col_startÚx1Úy1ÚwidthÚheightÚrow_endÚcol_endÚx2Úy2s              r   Ú_position_imager!      s`  € ðj •	˜% Ñ+Ô+Ò
+Ð
+Ø
�i˜˜yÑ)Ô)Ñ)ˆØ�Q‰ˆ	ð •	˜% Ñ+Ô+Ò
+Ð
+ð •	˜% Ñ+Ô+Ò
+Ð
+Ø
�i˜˜yÑ)Ô)Ñ)ˆØ�Q‰ˆ	ð •	˜% Ñ+Ô+Ò
+Ð
+ð €GØ€GØ�B‰J˜‰N€EØ�b‰[˜1‰_€Fà•I˜e WÑ-Ô-Ò-Ð-Ø•˜5 'Ñ*Ô*Ñ*ˆØ�1‰ˆð •I˜e WÑ-Ô-Ò-Ð-ð •Y˜u gÑ.Ô.Ò.Ð.Ø•)˜E 7Ñ+Ô+Ñ+ˆØ�1‰ˆð •Y˜u gÑ.Ô.Ò.Ð.õ
 
�5˜)Ñ	$Ô	$¨Ò	)Ð	)­y¸ÀÑ/HÔ/HÈAÒ/MÐ/MÝ˜% Ñ+Ô+¨qÒ0Ð0µiÀÀwÑ6OÔ6OÐSTÒ6TÐ6TØˆå	�U�2‰YŒY� 5¨)Ñ4Ô4Ñ4°tÑ;Ñ	<Ô	<€BÝ	�U�2‰YŒY� 5¨)Ñ4Ô4Ñ4°sÑ:Ñ	;Ô	;€Bå	�U�5‰\Œ\�I e¨WÑ5Ô5Ñ5¸Ñ<Ñ	=Ô	=€Bå	�U�6‰]Œ]�Y u¨gÑ6Ô6Ñ6¸Ñ<Ñ	=Ô	=€BØ�r˜9 b¨'°2°wÀÐCÐCr   c                   ó   — e Zd ZdZd„ ZdS )ÚObjBmpRecordé]   c	           	      ód  — |j         |z  }	|j        |z  }
t          ||||||	|
¦  «        }|\  }}}}}}}}	 d}d}d}d}|}|}|}|}|}|}|}|}d} d}!d}"d}#d}$d}%d}&d}'d}(d})d}*d}+d},d}-d}.d}/d}0d}1t          d|¦  «        }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d|¦  «        z  }2|2t          d| ¦  «        z  }2|2t          d|!¦  «        z  }2|2t          d|"¦  «        z  }2|2t          d	|#¦  «        z  }2|2t          d	|$¦  «        z  }2|2t          d	|%¦  «        z  }2|2t          d	|&¦  «        z  }2|2t          d	|'¦  «        z  }2|2t          d	|(¦  «        z  }2|2t          d	|)¦  «        z  }2|2t          d	|*¦  «        z  }2|2t          d|+¦  «        z  }2|2t          d|,¦  «        z  }2|2t          d|-¦  «        z  }2|2t          d|.¦  «        z  }2|2t          d|/¦  «        z  }2|2t          d|0¦  «        z  }2|2t          d|1¦  «        z  }2|2| _        d S )
Nr   é   i  r   é	   éÿ   ú<Lz<Hz<B)r   r   r!   r   Ú	_rec_data)3Úselfr   r   r
   Úim_data_bmpÚxÚyÚscale_xÚscale_yr   r   Úcoordinatesr   r   r   r   r   r   r   r    ÚcObjÚOTÚidÚgrbitÚcolLÚdxLÚrwTÚdyTÚcolRÚdxRÚrwBÚdyBÚcbMacroÚ	Reserved1Ú	Reserved2ÚicvBackÚicvForeÚflsÚfAutoÚicvÚlnsÚlnwÚfAutoBÚfrsÚcfÚ	Reserved3Ú
cbPictFmlaÚ	Reserved4Úgrbit2Ú	Reserved5Údatas3                                                      r   Ú__init__zObjBmpRecord.__init__n   s,  € àÔ! GÑ+ˆØÔ# gÑ-ˆõ & e¨S°#°q¸!¸UÀFÑKÔKˆàALÑ>ˆ	�2�y " g¨r°7¸Bð	ð ˆØˆØˆØˆØˆØˆØˆØˆØˆØˆØˆØˆØˆØˆ	Øˆ	ØˆØˆØˆØˆØˆØˆØˆØˆØˆØˆØˆ	Øˆ
Øˆ	ØˆØˆ	å�D˜$ÑÔˆØ•�T˜2‘”ÑˆØ•�T˜2‘”ÑˆØ•�T˜5Ñ!Ô!Ñ!ˆØ•�T˜4Ñ Ô Ñ ˆØ•�T˜3‘”ÑˆØ•�T˜3‘”ÑˆØ•�T˜3‘”ÑˆØ•�T˜4Ñ Ô Ñ ˆØ•�T˜3‘”ÑˆØ•�T˜3‘”ÑˆØ•�T˜3‘”ÑˆØ•�T˜7Ñ#Ô#Ñ#ˆØ•�T˜9Ñ%Ô%Ñ%ˆØ•�T˜9Ñ%Ô%Ñ%ˆØ•�T˜7Ñ#Ô#Ñ#ˆØ•�T˜7Ñ#Ô#Ñ#ˆØ•�T˜3‘”ÑˆØ•�T˜5Ñ!Ô!Ñ!ˆØ•�T˜3‘”ÑˆØ•�T˜3‘”ÑˆØ•�T˜3‘”ÑˆØ•�T˜6Ñ"Ô"Ñ"ˆØ•�T˜3‘”ÑˆØ•�T˜2‘”ÑˆØ•�T˜9Ñ%Ô%Ñ%ˆØ•�T˜:Ñ&Ô&Ñ&ˆØ•�T˜9Ñ%Ô%Ñ%ˆØ•�T˜6Ñ"Ô"Ñ"ˆØ•�T˜9Ñ%Ô%Ñ%ˆàˆŒˆˆr   N)Ú__name__Ú
__module__Ú__qualname__Ú_REC_IDrQ   © r   r   r#   r#   k   s-   € € € € € Ø€GðLð Lð Lð Lð Lr   r#   c                 ó˜   — t          | d¦  «        5 }|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   t          |¦  «        S )z±Convert a 24 bit bitmap into the modified internal format used by Windows.
    This is described in BITMAPCOREHEADER and BITMAPCOREINFO structures in the
    MSDN library.

    ÚrbN)ÚopenÚreadÚ_process_bitmap_data)ÚbitmapÚfhrP   s      r   Ú_process_bitmapr^   ¼   sƒ   € õ 
ˆf�dÑ	Ô	ð ˜rà�wŠw‰yŒyˆðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð õ   Ñ%Ô%Ð%s   ‘2²6¹6c                 ó  — t          | ¦  «        dk    rt          d¦  «        ‚| d d…         dk    rt          d¦  «        ‚| dd …         } t          d| d d…         ¦  «        d         }|dz  }|d	z  }| dd …         } | d	d …         } t          d
| d d…         ¦  «        \  }}| dd …         } |dk    rt          d¦  «        ‚|dk    rt          d¦  «        ‚t          d| d d…         ¦  «        \  }}| dd …         } |dk    rt          d¦  «        ‚|dk    rt          d¦  «        ‚t          d| d d…         ¦  «        d         }| dd …         } |dk    rt          d¦  «        ‚| dd …         } t          dd	||dd¦  «        }|| z   } |||| fS )Né6   z#bitmap doesn't contain enough data.é   s   BMz4bitmap doesn't appear to to be a valid bitmap image.r)   é   r   é   z<LLr&   iÿÿ  z-bitmap: largest image width supported is 65k.z.bitmap: largest image height supported is 65k.z<HHé   z'bitmap isn't a 24bit true color bitmap.r   z/bitmap: only 1 plane supported in bitmap image.z2bitmap: compression not supported in bitmap image.é   z<LHHHH)ÚlenÚ	Exceptionr   r   )rP   Úsizer   r   ÚplanesÚbitcountÚcompressionÚheaders           r   r[   r[   È   sË  € å
ˆ4�y„y�DÒÐÝÐ=Ñ>Ô>Ð>àˆRˆaˆRŒ�EÒÐÝÐNÑOÔOÐOà���Œ8€Dõ �$˜˜R˜a˜RœÑ!Ô! !Ô$€DØˆT�M€DØˆT�M€DØ���Œ8€Dà���Œ9€Då˜5 $ r¨ r¤(Ñ+Ô+�M€Eˆ6Ø���Œ8€DØ�ŠˆÝÐGÑHÔHÐHØ�ŠˆÝÐHÑIÔIÐIå˜e T¨"¨1¨"¤XÑ.Ô.Ñ€FˆHØ���Œ8€DØ�BŠˆÝÐAÑBÔBÐBØ�!ŠˆÝÐIÑJÔJÐJå˜˜t B Q BœxÑ(Ô(¨Ô+€KØ���Œ8€DØ�qÒÐÝÐLÑMÔMÐMà���Œ9€Då�(˜F E¨6°4¸Ñ>Ô>€FØ�D‰=€DØ�6˜4 Ð&Ð&r   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚImRawDataBmpRecordé   c                 óž   — t          j        | ¦  «         t          |¦  «        \  | _        | _        | _        }|                      |¦  «         dS ©z¡Insert a 24bit bitmap image in a worksheet. The main record required is
        IMDATA but it must be proceeded by a OBJ record to define its position.

        N)r   rQ   r[   r   r   rh   Ú_write_imdata)r+   rP   s     r   rQ   zImRawDataBmpRecord.__init__ø   sK   € õ
 	Ô˜DÑ!Ô!Ð!å3GÈÑ3MÔ3MÑ0ˆŒ
�D”K ¤¨DØ×Ò˜4Ñ Ô Ð Ð Ð r   c                 óP   — d}d}| j         }t          d|||¦  «        |z   | _        d S )Nr'   r   z<HHL)rh   r   r*   )r+   rP   rJ   ÚenvÚlcbs        r   rr   z ImRawDataBmpRecord._write_imdata  s1   € àˆØˆØŒiˆÝ˜f b¨#¨sÑ3Ô3°dÑ:ˆŒˆˆr   N)rR   rS   rT   rU   rQ   rr   rV   r   r   rn   rn   õ   s7   € € € € € Ø€Gð!ð !ð !ð;ð ;ð ;ð ;ð ;r   rn   c                   ó   — e Zd Zd„ ZdS )ÚImDataBmpRecordc                 óž   — t          j        | ¦  «         t          |¦  «        \  | _        | _        | _        }|                      |¦  «         dS rq   )r   rQ   r^   r   r   rh   rr   )r+   ÚfilenamerP   s      r   rQ   zImDataBmpRecord.__init__
  sK   € õ
 	Ô˜DÑ!Ô!Ð!å3BÀ8Ñ3LÔ3LÑ0ˆŒ
�D”K ¤¨DØ×Ò˜4Ñ Ô Ð Ð Ð r   N)rR   rS   rT   rQ   rV   r   r   rw   rw   	  s#   € € € € € ð!ð !ð !ð !ð !r   rw   N)ÚBIFFRecordsr   Ústructr   r   r   r   r!   r#   r^   r[   rn   rw   rV   r   r   ú<module>r|      s  ðð $Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ð Ð ð ð  ð  ð!ð !ð !ðUDð UDð UDðpOð Oð Oð Oð O�:ñ Oô Oð Oðb
&ð 
&ð 
&ð*'ð *'ð *'ðZ;ð ;ð ;ð ;ð ;˜ñ ;ô ;ð ;ð(	!ð 	!ð 	!ð 	!ð 	!Ð(ñ 	!ô 	!ð 	!ð 	!ð 	!r   