
    Mf*                         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BJNEb[1_FIeW----5'***1 IeW---- Yug....)E7+++1 Yug....
 
5)	$	$	)	)y/H/HA/M/M%++q00iw6O6OST6T6T	U2YY5)444t;	<	<B	U2YY5)444s:	;	;B	U5\\IeW555<	=	=B	U6]]Yug666<	=	=Br9b'2w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- &eS#q!UFKKAL>	2y"gr7B	 			
		D$T2T2T5!!!T4   T3T3T3T4   T3T3T3T7###T9%%%T9%%%T7###T7###T3T5!!!T3T3T3T6"""T3T2T9%%%T:&&&T9%%%T6"""T9%%%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 )zConvert 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     
fd		 rwwyy                %%%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 )N6   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   
4yyD=>>>RaRENOOO8D $RaR!!!$DTMDTMD8D9D5$rr(++ME68DGHHHHIIIeT"1"X..FH8DBABBB!IJJJtBQBx((+K8DqLMMM9D(FE64>>FD=D64&&r   c                       e Zd ZdZd Zd ZdS )ImRawDataBmpRecord   c                     t          j        |            t          |          \  | _        | _        | _        }|                     |           dS zInsert 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3M3M0
DK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fb#s33d: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!!!3B83L3L0
DK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   