
    _eS                     H   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 Zej$                  j'                  i ej(                  d	ej*                  d	ej,                  d	ej.                  d	ej0                  d	ej2                  d	ej4                  d	ej6                  d	ej8                  d	ej:                  d	ej<                  d
ej>                  d	ej@                  d	ejB                  d	ejD                  dejF                  dejH                  di ejJ                  dejL                  dejN                  dejP                  dejR                  dejT                  dejV                  dejX                  dejZ                  dej\                  dej^                  dej`                  dejb                  dejd                  dejf                  dejh                  dejj                  dejl                  dejn                  dejp                  di       ejr                  j'                  i ejt                  ejt                  ejv                  ejx                  ejz                  ejx                  ej|                  ej~                  ej                  ej~                  ej                  ej~                  ej                  ej~                  ej                  ej~                  ej                  ej~                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ejx                  ejx                  ej                  ej                  ej~                  ej~                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej(                  ejx                  i       ej                  j'                  ejv                  dejz                  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i       ej                  j'                  ej                  ej                  d	fgej                  ej                  dfej                  ej                  dfej                  ej                  d	fgej                  ej                  dfej                  ej                  dfej                  ej                  d	fgej                  ej                  dfej                  ej                  d	fgd       dZXd ZYdej                  fdej                  fdej                  fdej                  fdej                  fdejx                  fdej                  fdej~                  ffD ]0  \  ZZZ[e[defdZ\e\ e]       deZ<   e[defdZ^e^ e]       deZ<   	 [Z[[2 defdZ\defdZ^g dZad  Zbd! Zcd" Zd G d# d$ee      Zf G d% d&ef      Zg G d' d(ee      Zhd)Zid*Zjd+Zkdeid,dfd-Zl ed elej                              Zm ed elej                              Zn ed elej                              Zo ed elej                              Zp ed elej                              Zqd. Zrd+d/Zsd0 Ztdej                  fdej                  fdej                  fdej                  fdejx                  fdej                  fdej~                  ffD ]0  \  ZZZud1D ]#  Zv ereZeu eweev            \  ZvZxex e]       ev<   	 [x[v% 	 [Z[u2 y# e_$ rZ`Y dZ`[`dZ`[`ww xY w# e_$ r
Z`Y dZ`[`IdZ`[`ww xY w# e_$ r
Z`Y dZ`[`cdZ`[`ww xY w)2aZ  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                 P    t        | t              rt        t        | d            S | S Nr   
isinstancefloatintroundvalues    2/usr/lib/python3/dist-packages/OpenGL/GL/images.pyasIntr      "    5%!5q>""L                   )r   r   r   r   ):glReadPixelsglReadPixelsbglReadPixelsdglReadPixelsfglReadPixelsiglReadPixelssglReadPixelsubglReadPixelsuiglReadPixelsusglGetTexImageglDrawPixelsglDrawPixelsbglDrawPixelsfglDrawPixelsiglDrawPixelssglDrawPixelsubglDrawPixelsuiglDrawPixelsusglTexSubImage2DglTexSubImage1DglTexImage1DglTexImage2DglGetTexImagebglGetTexImagedglGetTexImagefglGetTexImageiglGetTexImagesglGetTexImageubglGetTexImageuiglGetTexImageusglTexImage1DbglTexImage2DbglTexSubImage1DbglTexSubImage2DbglTexImage1DfglTexImage2DfglTexSubImage1DfglTexSubImage2DfglTexImage1DiglTexImage2DiglTexSubImage1DiglTexSubImage2DiglTexImage1DsglTexImage2DsglTexSubImage1DsglTexSubImage2DsglTexImage1DubglTexImage2DubglTexSubImage1DubglTexSubImage2DubglTexImage1DuiglTexImage2DuiglTexSubImage1DuiglTexSubImage2DuiglTexImage1DusglTexImage2DusglTexSubImage1DusglTexSubImage2Dusc                    g }t        j                         }t        j                  | |t        j                  |       |j
                  g}| t        j                  k7  rt        j                  | |t        j                  |       |j                  |j
                         | t        j                  k7  rAt        j                  | |t        j                  |       |j                  |j
                         |S )z0Retrieve texture dims for given level and target)r   GLuintr   glGetTexLevelParameterivGL_TEXTURE_WIDTHr   GL_TEXTURE_1DGL_TEXTURE_HEIGHTappendGL_TEXTURE_2Dr   GL_TEXTURE_DEPTH)targetleveldimsdims       r   _get_texture_level_dimsrf      s    D
--/C
##VUF4K4KSRII;D%%%''8P8PRUWSYY V)))++VUF<S<SUXZKK$Kr   bdfisubuiusc           	         t        |       t        |      t        |      t        |      f\  } }}}t        j                  t        j                  j                  ||         }|t        j                  |||f|      x}}	d}
nJt        |t              rt        j                  |      }	n"|j                  |      }|j                  |      }	d}
t        j                  | ||||||	       |
r|t        u rt        j                   ||      S |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.
        TF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owneds              r   r   r      s     !8E!HU5\%-G!E&44f6N6N6R6RSWX\6]_	= & 5 5vf~t UUEIE5-0"OOU4	!))52%55u>	Ea64		
 Z5(&&t55Lr   r   c                    t         j                  t        j                  j	                  ||         }|1t        | |      }t        j                  |t        |      |      x}}d}	nJt        |t              rt        j                  |      }n"|j                  |      }|j                  |      }d}	t        j                  | ||||       |	r|t         u rt        j"                  ||      S |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
        TFr   rq   r   rr   rs   rf   rt   tupler   r   ru   rv   rw   rx   r   r(   r
   ry   )
rb   rc   r   r   r   r   r   rd   r   r   s
             r   r(   r(     s    " 44f6N6N6R6RSWX\6]_	=*6%8D & 5 5vuT{D RREIE5-0"OOU4	!))52%55u>	EE64	
 Z5(&&t55Lr   r(   c           	         t        |       t        |      t        |      t        |      f\  } }}}t        j                  t        j                  j                  ||         }|t        j                  |||f|      x}}	d}
nJt        |t              rt        j                  |      }	n"|j                  |      }|j                  |      }	d}
t        j                  | ||||||	       |
r|t        u rt        j                   ||      S |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
    TFrp   rz   s              r   r   r   T  s      QxaueFmCAaf00&2J2J2N2NtTX2Y[I}"116E&>4QQ	um,0I%%u.E!115:I
	!E&t
 u$""E411r   c                    t         j                  t        j                  j	                  ||         }|/t        | |      }t        j                  |t        |      |      x}}nHt        |t              rt        j                  |      }n"|j                  |      }|j                  |      }t        j                  | ||||       |t         u rt        j"                  ||      S |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
    r   )	rb   rc   r   r   r   r   r   rd   r   s	            r   r(   r(   |  s    " 00&2J2J2N2NtTX2Y[I}&ve4"1165;NN	um,0I%%u.E!115:I
vtY U""E411r   )r}   r~   depthr{   r|   zxoffsetyoffsetzoffsetstartcountc                 d    t        | t        j                        st        j                  |       S | S N)r   r   Wrapperr   s    r   	asWrapperr     s$    ugoo/''Lr   c                 P    t        | t              rt        t        | d            S | S r   r   )r   argss     r   asIntConverterr     r   r   c                     t        |       } t        | d| j                        }t        |      D ]$  \  }}|t        v s| j                  |t               & | S )zCSet arguments with names in INT_DIMENSION_NAMES to asInt processingpyConverterNames)r   getattrargNames	enumerateINT_DIMENSION_NAMESsetPyConverterr   )baseOperationr   rj   argNames       r   setDimensionsAsIntsr     s\    }.M'9=;Q;QSHx( D	'))(('>CD r   c                        e Zd ZddZd Zd Zy)ImageInputConverterNc                 .    || _         || _        || _        y r   )ranktypeName
pixelsName)selfr   r   r   s       r   __init__zImageInputConverter.__init__  s    	 $r   c                      |j                   | j                        | _         |j                   | j                        | _        y$Get our pixel index from the wrapperN)
pyArgIndexr   	typeIndexr   pixelsIndexr   r   s     r   finalisezImageInputConverter.finalise  s3    +++T]]<-7--t@r   c                     t        j                          t        j                  | j                         || j                     }t
        j                  t         j                  |      }|j                  |      S )z#pyConverter for the pixels argument)	r   setupDefaultTransferModerankPackingr   r   r   rq   rr   rw   )r   argr   pyArgsr   r   s         r   __call__zImageInputConverter.__call__  s[    '')DII't~~'44f6N6NPT6VX	  #''r   )Nr   )__name__
__module____qualname__r   r   r    r   r   r   r     s    %A(r   r   c                   8    e Zd Zd	dZd Zd Zd Zd Zd Zd Z	y)
TypedImageInputConverterNc                 <    || _         || _        || _        || _        y r   )r   r   r   r   )r   r   r   r   r   s        r   r   z!TypedImageInputConverter.__init__  s    	"$ r   c                     t        j                          t        j                  | j                         | j                  j                  |      S )zThe pyConverter for the pixels)r   r   r   r   r   rw   )r   r   r   r   s       r   r   z!TypedImageInputConverter.__call__  s5    '')DII'~~%%s,,r   c                 F     |j                   | j                        | _        yr   )r   r   r   r   s     r   r   z!TypedImageInputConverter.finalise  s    -7--t@r   c                 X    | j                   j                  || j                           d   S )z*Extract the width from the pixels argumentr   r   
dimensionsr   r   r   indexwrappedOperations       r   r}   zTypedImageInputConverter.width  '    ~~((&1A1A*BDQGGr   c                 X    | j                   j                  || j                           d   S )z+Extract the height from the pixels argumentr   r   r   s       r   r~   zTypedImageInputConverter.height  r   r   c                 X    | j                   j                  || j                           d   S )z*Extract the depth from the pixels argumentr   r   r   s       r   r   zTypedImageInputConverter.depth  r   r   c                     | 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...
        r   r   s       r   r   zTypedImageInputConverter.type  s     }}r   r   )
r   r   r   r   r   r   r}   r~   r   r   r   r   r   r   r     s)    !
-
AHHHr   r   c                       e Zd Zd Zd Zy)CompressedImageConverterc                 2     |j                   d      | _        y)r   dataN)r   	dataIndexr   s     r   r   z!CompressedImageConverter.finalise  s    +++V5r   c                 ^    || j                      }t        j                  j                  |      S )z,Create a data-size measurement for our image)r   r	   ArrayDatatypearrayByteCount)r   r   r   r   r   s        r   r   z!CompressedImageConverter.__call__  s'    dnn&**99#>>r   N)r   r   r   r   r   r   r   r   r   r     s    6?r   r   )r}   r~   r   )pixelsrowcolumn)	imageSizer   c                 ~   t        |       } t        | j                  D cg c]  }||v r|
 c}      dz   }|rt        ||||      }t	        | j                        D ]m  \  }}||v r.| j                  |       | j                  |t        ||             8|dk(  s>|A| j                  |       | j                  ||j                         o nt        |||xs d      }| j                  D ]8  }|t        v s| j                  |       | j                  ||j                         : | j                  ||       | S c c}w )zCDetermine how to convert "pixels" into an image-compatible argumentr   r   r   )r   r   )r   lenr   r   r   r   setCConverterr   r   r   DATA_SIZE_NAMESimageDataSize)	r   r   dimNames	pixelNamer   r   r   	converterrj   s	            r   setImageInputr     sS   
 }.M,55h 	  
	D
 ,dIyS[]	"=#9#9: 	GIAg(",,g7++Wgi6PRF"x';,,g7++WinnF	G ()hN`Z`b	 )) Lo%(('3'')2I2IKL   9 5s   D:c                     |j                   }dt               z  }t        j                  |   }t	        t        |||            }||fS )z3Produce a typed version of the given image functionz%(functionName)s%(suffix)sr   )r   localsr   rq   r   r   )suffixarrayConstantbaseFunctionfunctionNamer   functions         r   typedImageFunctionr   ?  sQ    ((L/8L00-AI"$	
H !!r   c                 j    t               }t        |       j                  |      j                  ||      S )z3Set the data-size value to come from the data field)r   r   r   r   )r   argumentr   s      r   _setDataSizer   M  s1    (*Il$33mXy*+r   c                 .    t        t        | d            S )zDSet the imageSize and dimensions-as-ints converters for baseFunctionr   )r   )r   r   )r   s    r   compressedImageFunctionr   T  s    ;	
 r   )r3   r4   r2   r1   r)   )y__doc__OpenGL.raw.GL.VERSIONr   r   r   OpenGLr   r   r   OpenGL.arraysr	   OpenGL._bytesr
   r   OpenGL.raw.GLr   ru   r   COMPONENT_COUNTSupdate	GL_BITMAPGL_REDGL_GREENGL_BLUEGL_ALPHAGL_RED_INTEGERGL_GREEN_INTEGERGL_BLUE_INTEGERGL_ALPHA_INTEGERGL_LUMINANCEGL_LUMINANCE_ALPHAGL_COLOR_INDEXGL_STENCIL_INDEXGL_DEPTH_COMPONENTGL_RGBGL_BGR	GL_RGB16F	GL_RGB16I
GL_RGB16UI	GL_RGB32F	GL_RGB32I
GL_RGB32UIGL_RGB8I	GL_RGB8UI
GL_RGB9_E5GL_RGB_INTEGERGL_RGBAGL_BGRA
GL_RGBA16F
GL_RGBA16IGL_RGBA16UI
GL_RGBA32F
GL_RGBA32IGL_RGBA32UI	GL_RGBA8I
GL_RGBA8UIGL_RGBA_INTEGERrr   GL_HALF_FLOATGL_UNSIGNED_BYTE_3_3_2GL_UNSIGNED_BYTEGL_UNSIGNED_BYTE_2_3_3_REVGL_UNSIGNED_SHORT_4_4_4_4GL_UNSIGNED_SHORTGL_UNSIGNED_SHORT_4_4_4_4_REVGL_UNSIGNED_SHORT_5_5_5_1GL_UNSIGNED_SHORT_1_5_5_5_REVGL_UNSIGNED_SHORT_5_6_5GL_UNSIGNED_SHORT_5_6_5_REVGL_UNSIGNED_INT_8_8_8_8GL_UNSIGNED_INTGL_UNSIGNED_INT_8_8_8_8_REVGL_UNSIGNED_INT_10_10_10_2GL_UNSIGNED_INT_2_10_10_10_REVGL_BYTEGL_SHORTGL_INTGL_FLOAT	GL_DOUBLETIGHT_PACK_FORMATSRANK_PACKINGSglPixelStoreiGL_PACK_ALIGNMENTGL_PACK_SKIP_IMAGESGL_PACK_IMAGE_HEIGHTGL_PACK_ROW_LENGTHGL_PACK_SKIP_ROWSGL_PACK_SKIP_PIXELS__all__rf   r   r   r   globalsr(   	NameErrorerrr   r   r   r   objectr   r   r   DIMENSION_NAMESPIXEL_NAMESr   r   r)   r1   r2   r4   r3   r   r   r   r   r   r   r   r   r   r   <module>rA     sf	   8 7 * * ' -         )!
q)! MMA)! OOa	)!
 NNQ)! OOa)! A)! a)! Q)! a)! !)! )! A)! a)! )!" MMA#)!$ MMA%)!& q')!( q))!* +)!, q-)!. q/)!0 1)!2 OOa3)!4 q5)!6 7)!8 A9)!< NNQ=)!> NNQ?)!@ A)!B C)!D E)!F G)!H I)!J K)!L q

QQ)! )V      "
6//"
!!F$;$;" %%(?(?" $$v'?'?	"
 ((6+C+C" $$v'?'?" ((6+C+C" ""V%=%=" &&)A)A" ""V%;%;" &&)?)?" %%(>(>" ))F,B,B" f55" NNFNN"  v77!"" OOv#"$ V33
MMFMM
OOfoo
v''
v..-" 0       
!!A
%%
$$q
((1
$$q
((1
""Q
&&
""Q
&&
%%
))A
a"        
		f66: 
		f88!<			f991=			f66: 
		f77;			f66:			f66: 
		f88!<			f66:! .]~ 				&
!
!"	&
 
 !	&
"
"#	 _KF4 48tPU < -9GI()15Te #H .;GI)*4{_B 7;u &P 59U !H 


(6 (( 3 >? ?
 "O!F #
 &
 &
 #
 #"+ 	&..&//&--&//	6""#	6!!"	6##$ F=  "4M76,#?"
h #+	,	,=1W  @	  		  s6   _-#` (`-_=8_= `
``!`!