+
    jl                     L    R t ^ RIt^ RItR tR tR tR tR t ! R R4      tR# )	a	  Minimal RGBA / indexed PNG reader and writer.

Only what the theme's assets need: 8-bit truecolour-alpha (type 6) and indexed
(type 3) images, non-interlaced. Written against zlib from the stdlib so the
theme can be rebuilt without Pillow or ImageMagick installed.
Nc                 B   V R ,          R8X  g   Q R4       h^p. pV\        V 4      8  dv   \        P                  ! RWV^,            4      w  pVP                  W^,           V^,            W^,           V^,           V,            .4       V^V,           ^,           ,          pK  V# ):N   N   PNG

z	not a PNG>I)lenstructunpackappend)dataioutlns   &   7/home/stevedylandev/Developer/Darkmatter/src/lib/png.py_chunksr      s    8++8[8+	A
C
c$i-dD1q5M2

DQq1u%tE!a%"*'=>?	QVaZJ    c           	      ,   \        R 4      pV  Fy  w  r#V\        P                  ! R\        V4      4      V,           V,           ,          pV\        P                  ! R\        P
                  ! W#,           4      R,          4      ,          pK{  	  \        V4      # )r   r   l    )	bytearrayr   packr   zlibcrc32bytes)chunksr   typbodys   &   r   _packr      sm    
(
)C	v{{4T+c1D88v{{4CJ!7*!DEE  :r   c                     W,           V,
          p\        W0,
          4      \        W1,
          4      \        W2,
          4      repWE8:  d	   WF8:  d   V # WV8:  d   V# T# N)abs)abcppapbpcs   &&&    r   _paethr%      sG    		AQUSZQUBB	xBH1ar   c                8   W,          p\        WB,          4      p^ p\        V4       EF  pW,          pV^,          p\        WWd,            4      p	Wd,          pWt,          p
W,
          pV^ 8X  d   EMV^8X  d:   \        W44       F(  pW,          WV,
          ,          ,           ^,          W&   K*  	  EM[V^8X  dB   V'       d8   \        V4       F(  pW,          W[V,           ,          ,           ^,          W&   K*  	  EMV^8X  di   \        V4       FX  pW8  d   WV,
          ,          M^ pV'       d   W[V,           ,          M^ pW,          W,           ^,	          ,           ^,          W&   KZ  	  MV^8X  d   \        V4       F{  pW8  d   WV,
          ,          M^ pV'       d   W[V,           ,          M^ pV'       d   W8  d   W[V,           V,
          ,          M^ pW,          \        WV4      ,           ^,          W&   K}  	  M\        RV,          4      hWWV,           % EK  	  V# )z>Reverse the per-scanline filters, returning flat sample bytes.zunknown filter %d)r   ranger%   
ValueError)rawwidthheightbppstrider   posyftlinebaseprevxr   r   r    s   &&&&            r   	_unfilterr5   '   s   [F
FO
$C
C6]Xq./z}71W3'7Tc']2d: (1WvA#wAX6$>DG '1W6]%&XDSM1%&CqMA7qul3t; # 1W6]%&XDSM1%&CqMA,-!(Cq3'7VA!_4<	 # 02566"&D; < Jr   c                R  aa	 W,          p\        4       p\        V4       Fz  pWd,          pWWt,            oV^ 8X  d   VP                  ^ 4       VS,          pK8  WV,
          V o	VP                  ^4       V\        VV	3R l\        V4       4       4      ,          pK|  	  \        V4      # )zERe-encode with the Up filter; cheap and compresses these assets well.c              3   `   <"   T F#  pSV,          SV,          ,
          ^,          x  K%  	  R# 5i)   N ).0r4   r1   r3   s   & r   	<genexpr>_filter_up.<locals>.<genexpr>Z   s&     K]$q'DG+t33]s   +.)r   r'   r	   r   )
flatr*   r+   r,   r-   r   r/   r2   r1   r3   s
   &&&&    @@r   
_filter_upr>   M   s    [F
+C6]z'6JJqM4KCvd+DJJqM5KU6]KKKC  :r   c                   T   a  ] tR t^^t o R tR tR tR tR tR t	R t
RR	 ltR
tV tR# )Pngc                F   Wn         \        \        VR 4      P                  4       4      V n        \        R V P                   4       4      R,          p\        P                  ! RV4      w  V n        V n	        V n
        V n         q0n        V P                  ^ 8X  g   Q R4       hR# )rbc              3   ,   "   T F
  w  rW3x  K  	  R # 5ir   r9   r:   tr   s   &  r   r;   Png.__init__.<locals>.<genexpr>b   s     3{tqQF{s   s   IHDRz>IIBBBBBzinterlaced PNGs unsupportedN)pathr   openreadr   dictr   r   r*   r+   depth
color_type	interlace)selfrG   ihdr_s   &&  r   __init__Png.__init___   s~    	d4.33563t{{33G<!'z4!@	T[$*do	
A~~~"A$AA"r   c                D    V P                    F  w  r#W!8X  g   K  Vu # 	  R # r   )r   )rN   r   rE   r   s   &&  r   _getPng._getg   s!    KKDAx   r   c                h    V P                    F  pV^ ,          V8X  g   K  W#^&    R# 	  \        V4      h)    N)r   KeyError)rN   r   r   r    s   &&& r   _setPng._setm   s1    Ats{!  smr   c           	         V P                  R 4      p\        ^ \        V4      ^4       Uu. uF  p\        WV^,            4      NK  	  up# u upi )   PLTE)rT   r'   r   tuple)rN   r!   r   s   &  r   palettePng.paletteu   sD    IIg+0CFA+>?+>aa!a%j!+>???s   A
c                V    V P                  R RP                  R V 4       4      4       R# )r\   r   c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   )r   )r:   r    s   & r   r;   "Png.set_palette.<locals>.<genexpr>z   s     #:cE!HHcs   N)rY   join)rN   pals   &&r   set_palettePng.set_palettey   s    		'388#:c#::;r   c           	     ~   V P                   ^8X  d   V P                  ^8X  g   Q R4       hRP                  R V P                   4       4      p\	        \
        P                  ! V4      V P                  V P                  ^4      p\        ^ \        V4      ^4       Uu. uF  p\        W#V^,            4      NK  	  up# u upi )   zexpected 8-bit RGBAr   c              3   <   "   T F  w  rVR 8X  g   K  Vx  K  	  R# 5i)   IDATNr9   rD   s   &  r   r;   Png.rgba.<locals>.<genexpr>   s     BkdaQ'\ks   
)rL   rK   rc   r   r5   r   
decompressr*   r+   r'   r   r]   )rN   idatr=   r   s   &   r   rgbaPng.rgba}   s    !#

aN9NN7xxBdkkBB.

DKKK.3As4y!.DE.DdQUm$.DEEEs   B:c                   \        4       pV F  pV\        V4      ,          pK  	  \        W P                  V P                  ^4      p\
        P                  ! V^	4      pV P                   Uu. uF  qf^ ,          R8w  g   K  VNK  	  upV n        \        R \        V P                  4       4       4      pV P                  P                  VRV.4       R# u upi )   rj   c              3   J   "   T F  w  rV^ ,          R8X  g   K  Vx  K  	  R# 5i)rW   s   IENDNr9   )r:   r   r    s   &  r   r;   Png.set_rgba.<locals>.<genexpr>   s      K!71Q47?11!7s   #
#N)r   r   r>   r*   r+   r   compressr   next	enumerateinsert)rN   pixelsr=   pxr)   r   r    ends   &&      r   set_rgbaPng.set_rgba   s    {BE"ID zz4;;:}}S!$"&++A+Q1qq+AK4;;!7KK3$0 Bs   ,C CNc                    \        T;'       g    V P                  R 4      P                  \        V P                  4      4       R# )wbN)rH   rG   writer   r   )rN   rG   s   &&r   savePng.save   s,    TTYY%++E$++,>?r   )r   rL   rK   r+   rM   rG   r*   r   )__name__
__module____qualname____firstlineno__rQ   rT   rY   r^   re   rn   r{   r   __static_attributes____classdictcell__)__classdict__s   @r   r@   r@   ^   s7     B@<F	1@ @r   r@   )	__doc__r   r   r   r   r%   r5   r>   r@   r9   r   r   <module>r      s8      #L"1@ 1@r   