a
    ijS                  L   @   st  d Z ddlmZmZmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlZdd	 Zejejd
ejd
ejd
ejd
ejd
ejd
ejd
ejd
ejd
ejd
ejdejd
ej d
ej!d
ej"dej#dej$dej%dej&dej'dej(dej)dej*dej+dej,dej-dej.dej/dej0dej1dej2dej3dej4dej5dej6dej7dej8di% ej9ej:ej:ej;ej<ej=ej<ej>ej?ej@ej?ejAej?ejBej?ejCej?ejDej?ejEejFejGejFejHejFejIejFej<ej<ejJejJej?ej?ejKejKejFejFejLejLejMejMejNejNejej<i ejOej;dej=dej>dej@dejAdejBdejCdejDdejEdejGdejHdejIdejdi ejPejQejRd
fgejQejSdfejQejTdfejQejRd
fgejQejUdfejQejVdfejQejRd
fgejQejWdfejQejRd
fgd dZXdd ZYdejJfdejNfdejMfdejLfdejKfdej<fdejFfdej?ffD ]z\ZZZ[e[defddZ\e\e] deZf < e[defddZ^e^e] d eZf < z[Z[[W n& e_y Z` zW Y dZ`[`n
dZ`[`0 0 q6defd!dZ\defd"dZ^g d#Zad$d% Zbd&d' Zcd(d) ZdG d*d+ d+eeZfG d,d- d-efZgG d.d/ d/eeZhd0Zid1Zjd2Zkdeid3dfd4d5ZledelejmZmedelejnZnedelejoZoedelejpZpedelejqZqd6d7 Zrd>d9d:Zsd;d< ZtdejJfdejMfdejLfdejKfdej<fdejFfdej?ffD ]\ZZZud=D ]VZvereZeueweev\ZvZxexe] ev< z[x[vW n& e_y6 Z` zW Y dZ`[`n
dZ`[`0 0 qz[Z[uW n& e_yj Z` zW Y dZ`[`n
dZ`[`0 0 qdS )?aZ  Image-handling routines

### Unresolved:

    Following methods are not yet resolved due to my not being sure how the
    function should be wrapped:

        glCompressedTexImage3D
        glCompressedTexImage2D
        glCompressedTexImage1D
        glCompressedTexSubImage3D
        glCompressedTexSubImage2D
        glCompressedTexSubImage1D
    )GL_1_1GL_1_2GL_3_0)imagesarrayswrapper)arraydatatype)bytesinteger_types)_typesNc                 C   s   t | trtt| dS | S Nr   
isinstancefloatintroundvalue r   N/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/GL/images.pyasInt   s    
r                  )r   r   r   r   ):glReadPixelsZglReadPixelsbZglReadPixelsdZglReadPixelsfZglReadPixelsiZglReadPixelssZglReadPixelsubZglReadPixelsuiZglReadPixelsusglGetTexImageglDrawPixelsZglDrawPixelsbZglDrawPixelsfZglDrawPixelsiZglDrawPixelssZglDrawPixelsubZglDrawPixelsuiZglDrawPixelsusglTexSubImage2DglTexSubImage1DglTexImage1DglTexImage2DZglGetTexImagebZglGetTexImagedZglGetTexImagefZglGetTexImageiZglGetTexImagesZglGetTexImageubZglGetTexImageuiZglGetTexImageusZglTexImage1DbZglTexImage2DbZglTexSubImage1DbZglTexSubImage2DbZglTexImage1DfZglTexImage2DfZglTexSubImage1DfZglTexSubImage2DfZglTexImage1DiZglTexImage2DiZglTexSubImage1DiZglTexSubImage2DiZglTexImage1DsZglTexImage2DsZglTexSubImage1DsZglTexSubImage2DsZglTexImage1DubZglTexImage2DubZglTexSubImage1DubZglTexSubImage2DubZglTexImage1DuiZglTexImage2DuiZglTexSubImage1DuiZglTexSubImage2DuiZglTexImage1DusZglTexImage2DusZglTexSubImage1DusZglTexSubImage2Dusc                 C   sz   g }t  }t| |tj| |jg}| tjkrvt| |tj| ||j | tj	krvt| |t
j| ||j |S )z0Retrieve texture dims for given level and target)r   ZGLuintr   ZglGetTexLevelParameterivZGL_TEXTURE_WIDTHr   ZGL_TEXTURE_1DZGL_TEXTURE_HEIGHTappendZGL_TEXTURE_2Dr   ZGL_TEXTURE_DEPTH)targetleveldimsdimr   r   r   _get_texture_level_dims   s    

r(   bdfisZubZuiusc              	   C   s   t | t |t |t |f\} }}}tjtj|| }|du r\t|||f| }}	d}
n.t|trrt	
|}	n||}||}	d}
t| ||||||	 |
r|tu rt||S |S dS )a  Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        NTFr   r   GL_CONSTANT_TO_ARRAY_TYPEr   TYPE_TO_ARRAYTYPEgetSetupPixelReadr   r
   ctypesc_void_pasArrayvoidDataPointerr   r   r	   returnFormatxywidthheightformattypearray
outputType	arrayType	imageDataownedr   r   r   r      s&    $


r   zglReadPixels%sc           
      C   s   t jtj|| }|du rBt| |}t|t|| }}d}	n.t|t	rXt
|}n||}||}d}	t| |||| |	r|tu rt||S |S dS )a  Get a texture-level as an image
        
        target -- enum constant for the texture engine to be read
        level -- the mip-map level to read
        format -- image format to read out the data
        type -- data-type into which to read the data
        array -- optional array/offset into which to store the value

        outputType -- default (bytes) provides string output of the
            results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
            and type == GL_UNSIGNED_BYTE.  Any other value will cause
            output in the default array output format.

        returns the pixel data array in the format defined by the
        format, type and outputType
        NTFr   r0   r   r1   r2   r(   r3   tupler   r
   r4   r5   r6   r7   r   r   r	   r8   )
r$   r%   r>   r?   r@   rA   rB   r&   rC   rD   r   r   r   r     s     




r   zglGetTexImage%sc              	   C   s   t | t |t |t |f\} }}}tjtj|| }|du r\t|||f| }}	d}
n.t|trrt	
|}	n||}||}	d}
t| ||||||	 |
r|tu rt||S |S dS )a  Read specified pixels from the current display buffer

    x,y,width,height -- location and dimensions of the image to read
        from the buffer
    format -- pixel format for the resulting data
    type -- data-format for the resulting data
    array -- optional array/offset into which to store the value
    outputType -- default (bytes) provides string output of the
        results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
        and type == GL_UNSIGNED_BYTE.  Any other value will cause
        output in the default array output format.

    returns the pixel data array in the format defined by the
    format, type and outputType
    NTFr/   r9   r   r   r   r   T  s$    $


c           	      C   s   t jtj|| }|du r>t| |}t|t|| }}n*t|t	rTt
|}n||}||}t| |||| |tu rt||S |S dS )a  Get a texture-level as an image

    target -- enum constant for the texture engine to be read
    level -- the mip-map level to read
    format -- image format to read out the data
    type -- data-type into which to read the data
    array -- optional array/offset into which to store the value

    outputType -- default (bytes) provides string output of the
        results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
        and type == GL_UNSIGNED_BYTE.  Any other value will cause
        output in the default array output format.

    returns the pixel data array in the format defined by the
    format, type and outputType
    NrE   )	r$   r%   r>   r?   r@   rA   rB   r&   rC   r   r   r   r   |  s    




)r<   r=   depthr:   r;   zZxoffsetZyoffsetZzoffsetstartcountc                 C   s   t | tjst| S | S N)r   r   ZWrapperr   r   r   r   	asWrapper  s    
rL   c                 G   s   t | trtt| dS | S r   r   )r   argsr   r   r   asIntConverter  s    
rN   c                 C   s@   t | } t| d| j}t|D ]\}}|tv r| |t q| S )zCSet arguments with names in INT_DIMENSION_NAMES to asInt processingZpyConverterNames)rL   getattrargNames	enumerateINT_DIMENSION_NAMESsetPyConverterrN   )baseOperationrP   r,   argNamer   r   r   setDimensionsAsInts  s    rV   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
ImageInputConverterNr?   c                 C   s   || _ || _|| _d S rK   )ranktypeName
pixelsName)selfrX   rZ   rY   r   r   r   __init__  s    zImageInputConverter.__init__c                 C   s    | | j| _| | j| _dS $Get our pixel index from the wrapperN)
pyArgIndexrY   	typeIndexrZ   pixelsIndexr[   r   r   r   r   finalise  s    zImageInputConverter.finalisec                 C   s8   t   t | j || j }tjt j|  }||S )z#pyConverter for the pixels argument)	r   setupDefaultTransferModerankPackingrX   r`   r   r0   r1   r6   )r[   argrT   pyArgsr?   rB   r   r   r   __call__  s
    
zImageInputConverter.__call__)Nr?   )__name__
__module____qualname__r\   rc   rh   r   r   r   r   rW     s   
rW   c                   @   sF   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dS )TypedImageInputConverterNc                 C   s   || _ || _|| _|| _d S rK   )rX   rB   rZ   rY   )r[   rX   rZ   rB   rY   r   r   r   r\     s    z!TypedImageInputConverter.__init__c                 C   s    t   t | j | j|S )zThe pyConverter for the pixels)r   rd   re   rX   rB   r6   )r[   rf   rT   rg   r   r   r   rh     s    z!TypedImageInputConverter.__call__c                 C   s   | | j| _dS r]   )r_   rZ   ra   rb   r   r   r   rc     s    z!TypedImageInputConverter.finalisec                 C   s   | j || j d S )z*Extract the width from the pixels argumentr   rB   
dimensionsra   r[   rg   indexwrappedOperationr   r   r   r<     s    zTypedImageInputConverter.widthc                 C   s   | j || j d S )z+Extract the height from the pixels argumentr   rm   ro   r   r   r   r=     s    zTypedImageInputConverter.heightc                 C   s   | j || j d S )z*Extract the depth from the pixels argumentr   rm   ro   r   r   r   rG     s    zTypedImageInputConverter.depthc                 C   s   | j S )zProvide the item-type argument from our stored value

        This is used for pre-bound processing where we want to provide
        the type by implication...
        rY   ro   r   r   r   r?     s    zTypedImageInputConverter.type)N)
ri   rj   rk   r\   rh   rc   r<   r=   rG   r?   r   r   r   r   rl     s   
rl   c                   @   s   e Zd Zdd Zdd ZdS )CompressedImageConverterc                 C   s   | d| _dS )r^   dataN)r_   	dataIndexrb   r   r   r   rc     s    z!CompressedImageConverter.finalisec                 C   s   || j  }tj|S )z,Create a data-size measurement for our image)ru   r   ZArrayDatatypeZarrayByteCount)r[   rg   rp   rq   rf   r   r   r   rh     s    
z!CompressedImageConverter.__call__N)ri   rj   rk   rc   rh   r   r   r   r   rs     s   rs   )r<   r=   rG   )pixelsrowcolumn)	imageSizerv   c           	         s   t | } t fdd| jD d }|rt||||d}t| jD ]V\}}| v rp| | | |t|| qB|dkrB|durB| | | ||j qBnt	|||pdd}| jD ]$}|t
v r| | | ||j q| || | S )zCDetermine how to convert "pixels" into an image-compatible argumentc                    s   g | ]}| v r|qS r   r   ).0rU   dimNamesr   r   
<listcomp>	  s   z!setImageInput.<locals>.<listcomp>r   rr   r?   N)rZ   rY   )rL   lenrP   rl   rQ   rS   setCConverterrO   r?   rW   DATA_SIZE_NAMESZimageDataSize)	rT   rB   r|   Z	pixelNamerY   rX   	converterr,   rU   r   r{   r   setImageInput  s0    



r   c                 C   s4   |j }dt  }tj| }tt|||d}||fS )z3Produce a typed version of the given image functionz%(functionName)s%(suffix)srr   )ri   localsr   r0   rV   r   )suffixarrayConstantbaseFunctionfunctionNamerB   functionr   r   r   typedImageFunction?  s    

r   ry   c                 C   s   t  }t| |||S )z3Set the data-size value to come from the data field)rs   rL   rS   r   )r   argumentr   r   r   r   _setDataSizeM  s    r   c                 C   s   t t| ddS )zDSet the imageSize and dimensions-as-ints converters for baseFunctionry   )r   )rV   r   )r   r   r   r   compressedImageFunctionT  s
    r   )r!   r"   r    r   r   )ry   )y__doc__ZOpenGL.raw.GL.VERSIONr   r   r   ZOpenGLr   r   r   ZOpenGL.arraysr   ZOpenGL._bytesr	   r
   ZOpenGL.raw.GLr   r4   r   ZCOMPONENT_COUNTSupdateZ	GL_BITMAPZGL_REDZGL_GREENZGL_BLUEZGL_ALPHAZGL_RED_INTEGERZGL_GREEN_INTEGERZGL_BLUE_INTEGERZGL_ALPHA_INTEGERZGL_LUMINANCEZGL_LUMINANCE_ALPHAZGL_COLOR_INDEXZGL_STENCIL_INDEXZGL_DEPTH_COMPONENTZGL_RGBZGL_BGRZ	GL_RGB16FZ	GL_RGB16IZ
GL_RGB16UIZ	GL_RGB32FZ	GL_RGB32IZ
GL_RGB32UIZGL_RGB8IZ	GL_RGB8UIZ
GL_RGB9_E5ZGL_RGB_INTEGERZGL_RGBAZGL_BGRAZ
GL_RGBA16FZ
GL_RGBA16IZGL_RGBA16UIZ
GL_RGBA32FZ
GL_RGBA32IZGL_RGBA32UIZ	GL_RGBA8IZ
GL_RGBA8UIZGL_RGBA_INTEGERr1   ZGL_HALF_FLOATZGL_UNSIGNED_BYTE_3_3_2ZGL_UNSIGNED_BYTEZGL_UNSIGNED_BYTE_2_3_3_REVZGL_UNSIGNED_SHORT_4_4_4_4ZGL_UNSIGNED_SHORTZGL_UNSIGNED_SHORT_4_4_4_4_REVZGL_UNSIGNED_SHORT_5_5_5_1ZGL_UNSIGNED_SHORT_1_5_5_5_REVZGL_UNSIGNED_SHORT_5_6_5ZGL_UNSIGNED_SHORT_5_6_5_REVZGL_UNSIGNED_INT_8_8_8_8ZGL_UNSIGNED_INTZGL_UNSIGNED_INT_8_8_8_8_REVZGL_UNSIGNED_INT_10_10_10_2ZGL_UNSIGNED_INT_2_10_10_10_REVZGL_BYTEZGL_SHORTZGL_INTZGL_FLOATZ	GL_DOUBLEZTIGHT_PACK_FORMATSZRANK_PACKINGSZglPixelStoreiZGL_PACK_ALIGNMENTZGL_PACK_SKIP_IMAGESZGL_PACK_IMAGE_HEIGHTZGL_PACK_ROW_LENGTHZGL_PACK_SKIP_ROWSZGL_PACK_SKIP_PIXELS__all__r(   r   r?   r   globalsr   	NameErrorerrrR   rL   rN   rV   objectrW   rl   rs   ZDIMENSION_NAMESZPIXEL_NAMESr   r   r   r   r    r"   r!   r   r   r   r   r   rO   r   r   r   r   r   <module>   sn  +_
$($
#
		
